public void draw() { super.draw(); applyfont(); GraphicsDraw.centerText(centeredText); GraphicsDraw.smallBoldFont(); GraphicsDraw.text("[R]", new Vector2(position.x + size.x - 17, position.y + size.y - 7)); }
@Override public void mouseMoved(int x, int y) { super.mouseMoved(x, y); if (isHeld()) { updatePosition(x - dx, y - dy); sendSliderEvent(); } }
@Override public void render() { int width = App.getScreenWidth(); int height = App.getScreenHeight(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, width, 0, height); glScalef(1, -1, 1); glTranslatef(0, -height, 0); glMatrixMode(GL_MODELVIEW); glDisable(GL_DEPTH_TEST); // Draw background glBegin(GL_QUADS); { if (backgroundColor != null) GeneralUtils.glColorShortcut(backgroundColor); glVertex2f(0, 0); glVertex2f(0, height); glVertex2f(width, height); glVertex2f(width, 0); } glEnd(); for (GuiButton b : buttons) { b.render(); // System.out.println(b.isMouseOver()); } // I don't want to set the same opengl settings for every button. // We can reduce a least a tiny bit of overhead by doing it in one go font.renderBegin(); for (GuiButton b : buttons) { b.renderText(); } font.renderEnd(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); }
/** Creates the buttons that appear at the top of the Stats GUI. */ public void addHeaderButtons() { StringTranslate stringtranslate = StringTranslate.getInstance(); controlList.add( new GuiButton( 0, width / 2 + 4, height - 28, 150, 20, stringtranslate.translateKey("gui.done"))); controlList.add( new GuiButton( 1, width / 2 - 154, height - 52, 100, 20, stringtranslate.translateKey("stat.generalButton"))); GuiButton guibutton; controlList.add( guibutton = new GuiButton( 2, width / 2 - 46, height - 52, 100, 20, stringtranslate.translateKey("stat.blocksButton"))); GuiButton guibutton1; controlList.add( guibutton1 = new GuiButton( 3, width / 2 + 62, height - 52, 100, 20, stringtranslate.translateKey("stat.itemsButton"))); if (slotBlock.getSize() == 0) { guibutton.enabled = false; } if (slotItem.getSize() == 0) { guibutton1.enabled = false; } }
/** * Fired when a control is clicked. This is the equivalent of * ActionListener.actionPerformed(ActionEvent e). */ protected void actionPerformed(GuiButton var1) { if (var1.enabled) { if (var1.id < 100 && var1 instanceof GuiSmallButton) { this.settings.setOptionValue(((GuiSmallButton) var1).returnEnumOptions(), 1); var1.displayString = this.settings.getKeyBinding(EnumOptions.getEnumOptions(var1.id)); } if (var1.id == 200) { this.mc.gameSettings.saveOptions(); this.mc.displayGuiScreen(this.prevScreen); } if (var1.id != EnumOptions.CLOUD_HEIGHT.ordinal()) { ScaledResolution var2 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); int var3 = var2.getScaledWidth(); int var4 = var2.getScaledHeight(); this.setWorldAndResolution(this.mc, var3, var4); } } }
@Override public void handleInput(IGuiMouseState gui) { if ((gui.getState() == ButtonState.CLICKED)) { // Associate lua action file for this guiscreen with the lua engine App.getLua().get("dofile").call(LuaValue.valueOf(resourcePath + "buttonActions.lua")); // The function we call for clicks, within lua fine LuaValue clickAction = App.getLua().get("returnClick"); // Value we pass to lua function. Button ID in this case LuaValue returnValue = clickAction.call(LuaValue.valueOf(((GuiButton) gui).getID())); // Set the button's state to none/null so we don't grab it again ((GuiButton) gui).setState(ButtonState.NONE); // String value of returnValue String sReturnValue = returnValue.tojstring(); // Have App send the command to the proper place App.delegateLuaActionResponse(sReturnValue); } }
@Override public void mousePressed(int x, int y) { super.mousePressed(x, y); dx = x - bounds.x(); dy = y - bounds.y(); }
protected void initGui() { int centerX = (cc.screenWidth - GuiButton.getButtonWidth()) / 2; int startY = 30; elementsList.addElement( new GuiButton(cc, 0, centerX, startY, cc.langBundle.getText("GuiNewWorld.buttonCreate"))); elementsList.addElement( new GuiButtonSelect( cc, 2, centerX, startY + (GuiButton.getButtonHeight() + GuiButton.getButtonHeight() / 6) * 2, cc.langBundle.getText("GuiNewWorld.worldType"), new int[] {0, 1}, new String[] { cc.langBundle.getText("GuiNewWorld.worldType.normal"), cc.langBundle.getText("GuiNewWorld.worldType.flat") })); elementsList.addElement( new GuiButtonSelect( cc, 4, centerX, startY + (GuiButton.getButtonHeight() + GuiButton.getButtonHeight() / 6) * 3, cc.langBundle.getText("GuiNewWorld.size"), new int[] {16, 32, 64, 256}, new String[] { cc.langBundle.getText("GuiNewWorld.size.normal"), cc.langBundle.getText("GuiNewWorld.size.big"), cc.langBundle.getText("GuiNewWorld.size.bigger"), cc.langBundle.getText("GuiNewWorld.size.biggest") })); elementsList.addElement( new GuiButtonSelect( cc, 3, centerX, startY + (GuiButton.getButtonHeight() + GuiButton.getButtonHeight() / 6) * 4, cc.langBundle.getText("GuiNewWorld.level"), new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12 (default)", "13", "14", "15" }) .setCurrentValue(12) .setEnabled(false)); // elementsList.addElement(new GuiButtonOnOff(cc, 5, centerX, startY + // (GuiButton.getButtonHeight() + GuiButton.getButtonHeight() / 6) * 5, // cc.langBundle.getText("GuiNewWorld.generateTrees")).setValue(false).setEnabled(true)); elementsList.addElement( new GuiButton( cc, 1, centerX, startY + (GuiButton.getButtonHeight() + GuiButton.getButtonHeight() / 6) * 6, cc.langBundle.getText("GuiNewWorld.buttonClose")) .setEnabled(parentScreen != null)); // Close }
protected void handleGuiAction(GuiButton guiButton) { if (!guiButton.enabled) { return; } if (guiButton.getId() == 0) { genereateWorld(); cc.displayGuiScreen(new GuiSelectWorld(guiMainMenu)); } else if (guiButton.getId() == 1) { backToParentScreen(); } else if (guiButton.getId() == 2) { GuiButtonSelect guiButtonSelect = getButtonSelect(guiButton.getId()); guiButtonSelect.nextValue(); if (guiButtonSelect.getCurrentValue() == 1) { getButton(3).setEnabled(true); // getButton(5).setEnabled(false); } else { getButton(3).setEnabled(false); // getButton(5).setEnabled(true); } } else if (guiButton.getId() == 3) { GuiButtonSelect guiButtonSelect = getButtonSelect(guiButton.getId()); guiButtonSelect.nextValue(); } else if (guiButton.getId() == 4) { GuiButtonSelect guiButtonSelect = getButtonSelect(guiButton.getId()); guiButtonSelect.nextValue(); } else if (guiButton.getId() == 5) { boolean value = !getButtonOnOff(guiButton.getId()).getValue(); getButtonOnOff(guiButton.getId()).setValue(value); } }