Jump to content

Recommended Posts

Posted

I have a GUI and I need button functionality, and I need to draw an icon over the button. I have two options:

1) draw a rectangle with the texture of a button, and handle the mouse clicks in the area myself. Draw my texture over the button.

2) Use GuiButton and draw the texture over the button.

 

The first option works, but I don't have click sounds and for some reason, mouseover detection doesn't work. But it does register clicks and drawing the texture over it also works.

 

The second option also works to register button clicks. It also does produce sound when I click it, and mouseover detection works. However, for some reason, the icon is drawn on a completely different offset when I draw the icon using drawTexturedModalRect() in the drawGuiContainerForegroundLayer() method. It works fine when I do it in the background method, but the icon will be drawn before the button, making it invisible.

 

Here's what I'm talking about:

 

  Reveal hidden contents

 

 

My code to draw the icon is this:

int i = (this.width - this.xSize) / 2;
	int j = (this.height - this.ySize) / 2;

	switch (this.te.getMode()) {
		case 0: this.drawTexturedModalRect(i + 30, j + 50, 176, 71,  20, 20);
			break;
		case 1: this.drawTexturedModalRect(i + 30, j + 50, 176, 91,  20, 20);
			break;
		case 2: this.drawTexturedModalRect(i + 30, j + 50, 176, 111, 20, 20);
			break;
	}

When I switch between approaches for testing, I just cut/paste the above code between the background and the foreground methods. Background for manual button, and foreground for GuiButton.

 

My code to create the GuiButton is this:

public void initGui() {
	super.initGui();
	//this.buttonList.add(this.modeButton = new GuiButton(0, this.guiLeft + 30, this.guiTop + 50, 20, 20, "Hi!"));
}

@Override
public void actionPerformed(GuiButton button) throws IOException {
	if (button == this.modeButton) {
		switch (te.getMode()) {
			case 0: this.te.setMode(1);
					break;
			case 1: this.te.setMode(2);
					break;
			case 2: this.te.setMode(0);
					break;
		}
	}
}

 

Should it be useful, here is the entire class I'm working on:

 

  Reveal hidden contents

 

 

I could continue using the first approach, but I think it's better to use the GuiButton.

Posted

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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