public void initGUI(int x, int y) { this.x = x; this.y = y; section = new GuiCharacterButton((byte) 0, x + WIDTH - 1, y + 34); newLine = new GuiCharacterButton((byte) 1, x + WIDTH - 1, y + 50); String sKey = (key == null) ? node.getObject().getName() : key.getText(); String sValue = (value == null) ? getValue(nbt) : value.getText(); this.key = new GuiTextField(mc.fontRendererObj, x + 46, y + 18, 116, 15, false); this.value = new GuiTextField(mc.fontRendererObj, x + 46, y + 44, 116, 15, true); key.setText(sKey); key.setEnableBackgroundDrawing(false); key.func_82265_c(canEditText); value.setMaxStringLength(256); value.setText(sValue); value.setEnableBackgroundDrawing(false); value.func_82265_c(canEditValue); save = new GuiButton(1, x + 9, y + 62, 75, 20, "Save"); if (!key.isFocused() && !value.isFocused()) { if (canEditText) key.setFocused(true); else if (canEditValue) value.setFocused(true); } section.setEnabled(value.isFocused()); newLine.setEnabled(value.isFocused()); cancel = new GuiButton(0, x + 93, y + 62, 75, 20, "Cancel"); }
public void click(int mx, int my) { if (newLine.inBounds(mx, my) && value.isFocused()) { value.writeText("\n"); checkValidInput(); } else if (section.inBounds(mx, my) && value.isFocused()) { value.writeText("" + NBTStringHelper.SECTION_SIGN); checkValidInput(); } else { key.mouseClicked(mx, my, 0); value.mouseClicked(mx, my, 0); if (save.mousePressed(mc, mx, my)) saveAndQuit(); if (cancel.mousePressed(mc, mx, my)) parent.closeWindow(); section.setEnabled(value.isFocused()); newLine.setEnabled(value.isFocused()); } }
public void keyTyped(char c, int i) { if (i == Keyboard.KEY_ESCAPE) { parent.closeWindow(); } else if (i == Keyboard.KEY_TAB) { if (key.isFocused() && canEditValue) { key.setFocused(false); value.setFocused(true); } else if (value.isFocused() && canEditText) { key.setFocused(true); value.setFocused(false); } section.setEnabled(value.isFocused()); newLine.setEnabled(value.isFocused()); } else if (i == Keyboard.KEY_RETURN) { checkValidInput(); if (save.enabled) saveAndQuit(); } else { key.textboxKeyTyped(c, i); value.textboxKeyTyped(c, i); checkValidInput(); } }
public void draw(int mx, int my) { // GL11.glBindTexture(GL11.GL_TEXTURE_2D, // mc.renderEngine.getTexture("/nbtedit_textures/nbteditwindow.png")); mc.renderEngine.bindTexture(WINDOW_TEXTURE); GL11.glColor4f(1, 1, 1, 1); drawTexturedModalRect(x, y, 0, 0, WIDTH, HEIGHT); if (!canEditText) drawRect(x + 42, y + 15, x + 169, y + 31, 0x80000000); if (!canEditValue) drawRect(x + 42, y + 41, x + 169, y + 57, 0x80000000); key.drawTextBox(); value.drawTextBox(); save.drawButton(mc, mx, my); cancel.drawButton(mc, mx, my); if (kError != null) drawCenteredString(mc.fontRendererObj, kError, x + WIDTH / 2, y + 4, 0xFF0000); if (vError != null) drawCenteredString(mc.fontRendererObj, vError, x + WIDTH / 2, y + 32, 0xFF0000); newLine.draw(mx, my); section.draw(mx, my); }