mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-03-14 05:35:35 +00:00
175 lines
6.1 KiB
Java
175 lines
6.1 KiB
Java
package com.hbm.inventory.gui;
|
|
|
|
import org.lwjgl.input.Keyboard;
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
import com.hbm.lib.RefStrings;
|
|
import com.hbm.packet.PacketDispatcher;
|
|
import com.hbm.packet.toserver.NBTControlPacket;
|
|
import com.hbm.tileentity.machine.rbmk.TileEntityRBMKKeyPad;
|
|
import com.hbm.util.i18n.I18nUtil;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
|
import net.minecraft.client.gui.GuiScreen;
|
|
import net.minecraft.client.gui.GuiTextField;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
public class GUIScreenRBMKKeyPad extends GuiScreen {
|
|
|
|
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rbmk_keypad.png");
|
|
public TileEntityRBMKKeyPad keypad;
|
|
protected int xSize = 256;
|
|
protected int ySize = 204;
|
|
protected int guiLeft;
|
|
protected int guiTop;
|
|
|
|
protected GuiTextField[] color = new GuiTextField[4];
|
|
protected GuiTextField[] label = new GuiTextField[4];
|
|
protected GuiTextField[] rtty = new GuiTextField[4];
|
|
protected GuiTextField[] cmd = new GuiTextField[4];
|
|
protected boolean[] active = new boolean[4];
|
|
protected boolean[] polling = new boolean[4];
|
|
|
|
public GUIScreenRBMKKeyPad(TileEntityRBMKKeyPad keypad) {
|
|
this.keypad = keypad;
|
|
|
|
this.xSize = 256;
|
|
this.ySize = 204;
|
|
}
|
|
|
|
public static void setupTextFieldStandard(GuiTextField field, int length, String def) {
|
|
field.setTextColor(0x00ff00);
|
|
field.setDisabledTextColour(0x00ff00);
|
|
field.setEnableBackgroundDrawing(false);
|
|
field.setMaxStringLength(length);
|
|
field.setText(def != null ? def : "");
|
|
}
|
|
|
|
@Override
|
|
public void initGui() {
|
|
super.initGui();
|
|
this.guiLeft = (this.width - this.xSize) / 2;
|
|
this.guiTop = (this.height - this.ySize) / 2;
|
|
|
|
Keyboard.enableRepeatEvents(true);
|
|
|
|
int oX = 4;
|
|
int oY = 4;
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
String col = Integer.toHexString(keypad.keys[i].color);
|
|
while(col.length() < 6) col = "0" + col;
|
|
color[i] = new GuiTextField(this.fontRendererObj, guiLeft + 27 + oX, guiTop + 55 + oY + i * 36, 72 - oX * 2, 14);
|
|
setupTextFieldStandard(color[i], 6, col);
|
|
label[i] = new GuiTextField(this.fontRendererObj, guiLeft + 175 + oX, guiTop + 55 + oY + i * 36, 72 - oX * 2, 14);
|
|
setupTextFieldStandard(label[i], 15, keypad.keys[i].label);
|
|
rtty[i] = new GuiTextField(this.fontRendererObj, guiLeft + 27 + oX, guiTop + 73 + oY + i * 36, 72 - oX * 2, 14);
|
|
setupTextFieldStandard(rtty[i], 10, keypad.keys[i].rtty);
|
|
cmd[i] = new GuiTextField(this.fontRendererObj, guiLeft + 121 + oX, guiTop + 73 + oY + i * 36, 126 - oX * 2, 14);
|
|
setupTextFieldStandard(cmd[i], 32, keypad.keys[i].command);
|
|
|
|
active[i] = keypad.keys[i].active;
|
|
polling[i] = keypad.keys[i].polling;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void drawScreen(int mouseX, int mouseY, float f) {
|
|
this.drawDefaultBackground();
|
|
this.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
this.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
|
}
|
|
|
|
private void drawGuiContainerForegroundLayer(int x, int y) {
|
|
String name = I18nUtil.resolveKey("container.rbmkKeyPad");
|
|
this.fontRendererObj.drawString(name, this.guiLeft + this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, this.guiTop + 6, 4210752);
|
|
}
|
|
|
|
private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
|
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
if(this.active[i]) drawTexturedModalRect(guiLeft + 111, guiTop + i * 36 + 54, 18, 204, 16, 16);
|
|
if(this.polling[i]) drawTexturedModalRect(guiLeft + 128, guiTop + i * 36 + 53, 0, 204, 18, 18);
|
|
}
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
this.color[i].drawTextBox();
|
|
this.label[i].drawTextBox();
|
|
this.rtty[i].drawTextBox();
|
|
this.cmd[i].drawTextBox();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void mouseClicked(int x, int y, int b) {
|
|
super.mouseClicked(x, y, b);
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
if(guiLeft + 111 <= x && guiLeft + 111 + 16 > x && guiTop + i * 36 + 54 < y && guiTop + i * 36 + 54 + 16 >= y) {
|
|
this.active[i] = !this.active[i];
|
|
return;
|
|
}
|
|
|
|
if(guiLeft + 128 <= x && guiLeft + 128 + 18 > x && guiTop + i * 36 + 53 < y && guiTop + i * 36 + 53 + 18 >= y) {
|
|
this.polling[i] = !this.polling[i];
|
|
return;
|
|
}
|
|
}
|
|
|
|
if(guiLeft + 209 <= x && guiLeft + 209 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) {
|
|
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
|
NBTTagCompound data = new NBTTagCompound();
|
|
byte active = 0;
|
|
byte polling = 0;
|
|
for(int i = 0; i < 4; i++) {
|
|
if(this.active[i]) active |= 1 << i;
|
|
if(this.polling[i]) polling |= 1 << i;
|
|
}
|
|
data.setByte("active", active);
|
|
data.setByte("polling", polling);
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
try { data.setInteger("color" + i, Integer.parseInt(this.color[i].getText(), 16)); } catch(Exception ex) { }
|
|
data.setString("label" + i, this.label[i].getText());
|
|
data.setString("rtty" + i, this.rtty[i].getText());
|
|
data.setString("cmd" + i, this.cmd[i].getText());
|
|
}
|
|
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, keypad.xCoord, keypad.yCoord, keypad.zCoord));
|
|
return;
|
|
}
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
this.color[i].mouseClicked(x, y, b);
|
|
this.label[i].mouseClicked(x, y, b);
|
|
this.rtty[i].mouseClicked(x, y, b);
|
|
this.cmd[i].mouseClicked(x, y, b);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void keyTyped(char c, int b) {
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
if(this.color[i].textboxKeyTyped(c, b)) return;
|
|
if(this.label[i].textboxKeyTyped(c, b)) return;
|
|
if(this.rtty[i].textboxKeyTyped(c, b)) return;
|
|
if(this.cmd[i].textboxKeyTyped(c, b)) return;
|
|
}
|
|
|
|
if(b == 1 || b == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
|
this.mc.thePlayer.closeScreen();
|
|
this.mc.setIngameFocus();
|
|
}
|
|
}
|
|
|
|
@Override public void onGuiClosed() { Keyboard.enableRepeatEvents(false); }
|
|
@Override public boolean doesGuiPauseGame() { return false; }
|
|
}
|