Jump to content

Custom GUI buttons


Vert3xo

Recommended Posts

Hello

so I've been interested in creating custom Minecraft main menu but I don't have much experience with mod programming. So I started with custom buttons and so far I've almost managed to do what I wanted and I created button with white background and transparency and added colored text. My problem is that when I try to position the button no matter where it is, it's "hitbox" stays where the original button was. I did it on singleplayer button like this: First I disabled the original button and made it invisible (pretty sure it's enough to make it invisible but I also disabled it just to be sure you can't click it) then I added my button using buttonList.add() and to change it's color, shape, etc. I made my own drawButton() method and used drawRect() and drawCentredString() inside this method. Here's my code:

    @SubscribeEvent
    public void onInitGui(final GuiScreenEvent.InitGuiEvent e) {
        if (e.gui instanceof GuiMainMenu) {
            for (Object b : e.buttonList) {
                if (((GuiButton) b).id == 14 || ((GuiButton) b).id == 1) {
                    ((GuiButton) b).enabled = false;
                    ((GuiButton) b).visible = false;
                }
            }

            int i = e.gui.height / 4 + 48;
            e.buttonList.add(new GuiButton(1, e.gui.width / 2 - 100, e.gui.height / 2 - 12, "Test") {
                @Override
                public void drawButton(Minecraft mc, int mouseX, int mouseY) {
                    final Color color = new Color(255, 255, 255, 127);
                    final FontRenderer font = mc.fontRendererObj;
                    Gui.drawRect(e.gui.width / 4, 500, e.gui.width / 2, 100, color.getRGB());
                    drawCenteredString(font, "Singleplayer", this.yPosition, this.yPosition, 0x0145D5);
                }
            });
    }
}

In this code I disabled Singleplayer and Realms button. Of course events are registered and I see every change I make. I just have that one problem I described above.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.