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;
|
2015-07-13 14:54:44 +02:00
|
|
|
import techreborn.Core;
|
2015-06-16 14:38:46 +02:00
|
|
|
import techreborn.client.container.ContainerIDSU;
|
2015-06-17 09:35:39 +02:00
|
|
|
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;
|
2015-06-17 18:01:26 +02:00
|
|
|
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
|
|
|
|
2015-06-17 09:35:39 +02:00
|
|
|
public class GuiIDSU extends GuiBase {
|
2015-06-16 14:38:46 +02:00
|
|
|
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
TileIDSU idsu;
|
2015-06-16 14:38:46 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
ContainerIDSU containerIDSU;
|
2015-06-16 14:38:46 +02:00
|
|
|
|
2015-10-09 23:31:26 +02:00
|
|
|
public static ElementListBox listBox = new ElementListBox(null, 10, 28, 100, 40);
|
2015-06-16 14:38:46 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
ElementTextFieldLimited idFeild;
|
|
|
|
ElementTextField nameFeild;
|
2015-06-17 12:14:46 +02:00
|
|
|
|
2015-10-09 23:31:26 +02:00
|
|
|
public GuiIDSU(EntityPlayer player, TileIDSU tileIDSU) {
|
2015-08-09 12:05:32 +02:00
|
|
|
super(new ContainerIDSU(tileIDSU, player));
|
2015-10-09 23:31:26 +02:00
|
|
|
this.xSize = 176;
|
|
|
|
this.ySize = 165;
|
2015-08-09 12:05:32 +02:00
|
|
|
idsu = tileIDSU;
|
|
|
|
this.containerIDSU = (ContainerIDSU) this.inventorySlots;
|
2015-10-09 23:31:26 +02:00
|
|
|
texture = new ResourceLocation("techreborn", "textures/gui/aesu.png");
|
2015-08-09 12:05:32 +02:00
|
|
|
drawTitle = false;
|
|
|
|
drawInventory = false;
|
|
|
|
name = StatCollector.translateToLocal("tile.techreborn.aesu.name");
|
|
|
|
}
|
2015-06-16 14:38:46 +02:00
|
|
|
|
2015-08-09 12:05:32 +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;
|
2015-10-09 23:31:26 +02:00
|
|
|
this.buttonList.add(new GuiButton(0, k + 128, l + 5, 15, 15, "++"));
|
|
|
|
this.buttonList.add(new GuiButton(1, k + 128, l + 5 + 20, 15, 15, "+"));
|
|
|
|
this.buttonList.add(new GuiButton(2, k + 128, l + 5 + (20 * 2), 15, 15, "-"));
|
|
|
|
this.buttonList.add(new GuiButton(3, k + 128, l + 5 + (20 * 3), 15, 15, "--"));
|
2015-08-09 12:05:32 +02:00
|
|
|
this.buttonList.add(new GuiButton(4, k + 40, l + 10, 10, 10, "+"));
|
2015-06-17 18:01:26 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
listBox.gui = this;
|
|
|
|
listBox.setSelectedIndex(containerIDSU.channel);
|
2015-06-18 22:10:26 +02:00
|
|
|
|
2015-06-17 18:01:26 +02:00
|
|
|
// listBox.borderColor = new GuiColor(120, 120, 120, 0).getColor();
|
|
|
|
// listBox.backgroundColor = new GuiColor(0, 0, 0, 32).getColor();
|
2015-08-09 12:05:32 +02:00
|
|
|
addElement(listBox);
|
2015-06-17 12:14:46 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
idFeild = new ElementTextFieldLimited(this, 10, 10, 30, 10, (short) 4);
|
|
|
|
idFeild.setFilter("1234567890", false);
|
2015-06-17 18:01:26 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
addElement(idFeild);
|
2015-06-17 12:14:46 +02:00
|
|
|
|
2015-10-09 23:31:26 +02:00
|
|
|
nameFeild = new ElementTextField(this, 70, 10, 50, 10);
|
2015-06-17 18:33:57 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
addElement(nameFeild);
|
2015-06-17 18:01:26 +02:00
|
|
|
|
2015-06-18 22:10:26 +02:00
|
|
|
// tabs.add(new TabIDConfig(this));
|
|
|
|
|
2015-06-17 18:01:26 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-06-17 18:01:26 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton button) {
|
|
|
|
super.actionPerformed(button);
|
|
|
|
if (isInteger(idFeild.getText())) {
|
2015-07-13 14:54:44 +02:00
|
|
|
Core.packetPipeline.sendToServer(new PacketIdsu(button.id, idsu, Integer.parseInt(idFeild.getText()), nameFeild.getText()));
|
|
|
|
} else {
|
2015-08-09 12:05:32 +02:00
|
|
|
LogHelper.info("There was an issue in the gui!, Please report this to the TechReborn Devs");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInteger(String s) {
|
|
|
|
return isInteger(s, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInteger(String s, int radix) {
|
|
|
|
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;
|
|
|
|
else continue;
|
|
|
|
}
|
|
|
|
if (Character.digit(s.charAt(i), radix) < 0) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-16 14:38:46 +02:00
|
|
|
|
|
|
|
}
|