TechReborn/src/main/java/techreborn/client/gui/GuiIDSU.java

105 lines
3.1 KiB
Java
Raw Normal View History

2015-06-16 14:38:46 +02:00
package techreborn.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.Core;
2015-06-16 14:38:46 +02:00
import techreborn.client.container.ContainerIDSU;
import techreborn.cofhLib.gui.GuiBase;
import techreborn.cofhLib.gui.element.ElementListBox;
2015-06-17 18:33:57 +02:00
import techreborn.cofhLib.gui.element.ElementTextField;
2015-06-17 12:14:46 +02:00
import techreborn.cofhLib.gui.element.ElementTextFieldLimited;
import techreborn.packets.PacketHandler;
import techreborn.packets.PacketIdsu;
import techreborn.tiles.idsu.TileIDSU;
2015-06-17 18:33:57 +02:00
import techreborn.util.LogHelper;
2015-06-16 14:38:46 +02:00
public class GuiIDSU extends GuiBase {
2015-06-16 14:38:46 +02:00
TileIDSU idsu;
ContainerIDSU containerIDSU;
public static ElementListBox listBox = new ElementListBox(null, 10, 28, 80, 60);
2015-06-16 14:38:46 +02:00
2015-06-17 12:14:46 +02:00
ElementTextFieldLimited idFeild;
2015-06-17 18:33:57 +02:00
ElementTextField nameFeild;
2015-06-17 12:14:46 +02:00
2015-06-16 14:38:46 +02:00
public GuiIDSU(EntityPlayer player,
2015-06-21 15:17:47 +02:00
TileIDSU tileIDSU) {
2015-06-16 14:38:46 +02:00
super(new ContainerIDSU(tileIDSU, player));
this.xSize = 156;
this.ySize = 200;
idsu = tileIDSU;
2015-06-21 15:17:47 +02:00
this.containerIDSU = (ContainerIDSU) this.inventorySlots;
texture = new ResourceLocation(
"techreborn", "textures/gui/aesu.png");
drawTitle = false;
drawInventory = false;
name = StatCollector.translateToLocal("tile.techreborn.aesu.name");
2015-06-16 14:38:46 +02:00
}
@Override
public void initGui() {
super.initGui();
this.buttonList.clear();
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++"));
this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+"));
2015-06-21 15:17:47 +02:00
this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22 * 2), 18, 20, "-"));
this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22 * 3), 18, 20, "--"));
this.buttonList.add(new GuiButton(4, k + 40, l + 10, 10, 10, "+"));
listBox.gui = this;
2015-06-21 15:17:47 +02:00
listBox.setSelectedIndex(containerIDSU.channel);
// listBox.borderColor = new GuiColor(120, 120, 120, 0).getColor();
// listBox.backgroundColor = new GuiColor(0, 0, 0, 32).getColor();
addElement(listBox);
2015-06-17 12:14:46 +02:00
2015-06-21 15:17:47 +02:00
idFeild = new ElementTextFieldLimited(this, 10, 10, 30, 10, (short) 4);
2015-06-17 12:14:46 +02:00
idFeild.setFilter("1234567890", false);
2015-06-17 12:14:46 +02:00
addElement(idFeild);
2015-06-17 18:33:57 +02:00
nameFeild = new ElementTextField(this, 10, 100, 50, 10);
addElement(nameFeild);
// tabs.add(new TabIDConfig(this));
}
@Override
protected void actionPerformed(GuiButton button) {
super.actionPerformed(button);
2015-06-21 15:17:47 +02:00
if (isInteger(idFeild.getText())) {
Core.packetPipeline.sendToServer(new PacketIdsu(button.id, idsu, Integer.parseInt(idFeild.getText()), nameFeild.getText()));
} else {
2015-06-17 18:33:57 +02:00
LogHelper.info("There was an issue in the gui!, Please report this to the TechReborn Devs");
}
}
public static boolean isInteger(String s) {
2015-06-21 15:17:47 +02:00
return isInteger(s, 10);
2015-06-17 18:33:57 +02:00
}
public static boolean isInteger(String s, int radix) {
2015-06-21 15:17:47 +02:00
if (s.isEmpty()) return false;
for (int i = 0; i < s.length(); i++) {
if (i == 0 && s.charAt(i) == '-') {
if (s.length() == 1) return false;
2015-06-17 18:33:57 +02:00
else continue;
}
2015-06-21 15:17:47 +02:00
if (Character.digit(s.charAt(i), radix) < 0) return false;
2015-06-17 18:33:57 +02:00
}
return true;
2015-06-16 14:38:46 +02:00
}
}