Jump to content

[1.10.2] Issue with GuiButtons / new GuiScreen


Gunmetal_Gears

Recommended Posts

Hey there, so I'm trying to figure out how to use GuiScreens for a mod 'guidebook.' (something similar to the Thaumonomicon, if you're familiar with Thaumcraft).

 

However, I can't get the closeScreen() or openGui() methods to work correctly. In my main gui class, I have the actionPerformed method with a switch case in it switching between the ID of the buttons; you can see this here. I've commented the openGui() line because it doesn't work. When I click on the 'update news' button, the screen becomes twice as dark and nothing renders. I know it's opening the new gui because the screen becomes darker, but the old one doesn't go away. 

 

What I don't get about this is that when I remove the openGui() line, like I have in my gui class, it closes the gui just fine. I have no idea why this happens this way.

My guihandler class and other gui classes are also present within this package.

Link to comment
Share on other sites

you need to us mc.displayGuiScreen(yourGui) to display the GUI, because this method handles for null variables, aswell as handing the closing of previously opened gui. When you did the mc.thePlayer.openGui you did just that, open a GUI, on top of another GUI that wasn't closed. The displayGuiScreen method handles for that. Look at the class I said, and then at the method I said, if you want to know how.

Edited by draganz
Link to comment
Share on other sites

On 6/7/2017 at 3:38 AM, draganz said:

you need to us mc.displayGuiScreen(yourGui) to display the GUI, because this method handles for null variables, aswell as handing the closing of previously opened gui. When you did the mc.thePlayer.openGui you did just that, open a GUI, on top of another GUI that wasn't closed. The displayGuiScreen method handles for that. Look at the class I said, and then at the method I said, if you want to know how.

Okay, so I got that working. But I have another issue now. My textured rectangle is placed on the screen with 'hard' coordinates; set numbers. Now I need to get it to always be in the center of the screen, regardless of monitor size. I've gotten the screen size using Dimension Toolkit, but I don't know how to make the rectangle always in the center, because changing the coordinates at which it renders seems to be rather random.

Link to comment
Share on other sites

You want to know what I did to find this answer, spend a minute looking at the minecraft source code, tends to have most of the answers...

Just do something along the lines of :

mc.getTextureManager().bindTexture(yourTexture);
//This is a VERY standard way of getting the center of the screen, like you cant miss this, if you google it, it will be the first result, I'm sure; its common code. 
final int x = (width - x_length_of_texture_you_want_to_draw) / 2;
final int y = (height - y_length_of_texture_you_want_to_draw) / 2;
/*
As a note, the width and height variables are provided  via the gui which are the screens width and height (they respond 
to screen rescaling), you can also use xSize and ySize  to get  176 and 166 (respectivly), those being the values for 
Minecraft's default gui sizes. Also, I make the ints x and y final, this isn't neccessary, just preference; stick to your 
own code style.
*/
drawTexturedModelRect(x, y, 0, 0, x_length_of_texture_you_want_to_draw, y_length_of_texture_you_want_to_draw);
// this method is also provided via the Gui class, look at it, if you want to understand the parameters

 

 

Link to comment
Share on other sites

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.