Jump to content

[1.12] [RESOLVED] Gui won't display properly


That_Martin_Guy

Recommended Posts

I have created a gui that will open when an item is right clicked. For some reason, however, the buttons, labels, text fields etc I give it don't work properly, and it doesn't even load the texture I give it. It also doesn't display any of these at all on my laptop, which has a lower resolution (I would estimate ~1400x900, but I'm just guessing).

 

In game preview

Edited by That_Martin_Guy
Fixed some links
Link to comment
Share on other sites

23 minutes ago, That_Martin_Guy said:

For some reason, however, the buttons, labels, text fields etc I give it don't work properly

See how vanilla does it at any of it's guis with buttons, like GuiIngameMenu. A couple of issues I can see:

 

question.drawTextBox();
answerA.drawTextBox();
answerB.drawTextBox();
answerC.drawTextBox();
answerD.drawTextBox();

In initGui? Drawing must happen each frame, not once the GUI is open and never again.

 

You are adding to your list but are never clearing it. Minecraft won't clear your lists for you, so every time the GUI is resized you will put "logical duplicates" into the list.

 

this.drawDefaultBackground();
this.mc.getTextureManager().bindTexture(BACKGROUND_TEXTURE);

You need to do something with the texture you are binding(hint: draw it). You can't just bind it and expect it to be drawn.

 

In your current call ordering everything you draw will be drawn over your buttons.

 

Your saveCard method shrinks the size of the item stack... on the client. You can't do that as the server still has different data. You need to use custom packets. After doing that it proceeds to create a new item, write a bunch of stuff into it's NBT and... discards it completely.

  • Like 1
Link to comment
Share on other sites

1 hour ago, V0idWa1k3r said:

See how vanilla does it at any of it's guis with buttons, like GuiIngameMenu

I did look immensely at vanilla code, mainly GuiScreenBook. If I didn't I would've been completely lost since there are few gui tutorials that I've found.

 

1 hour ago, V0idWa1k3r said:

Drawing must happen each frame, not once the GUI is open and never again.

Right. Their draw methods have been moved.

 

1 hour ago, V0idWa1k3r said:

You need to do something with the texture you are binding(hint: draw it). You can't just bind it and expect it to be drawn.

Added this underneath the bind:

this.drawTexturedModalRect((this.width - 256) / 2, 2, 0, 0, 256, 256);

. Actually displays in game now (great!). It's too small though, so I'll have to make it bigger somehow. I know enough photoshop to do this myself.

1 hour ago, V0idWa1k3r said:

In your current call ordering everything you draw will be drawn over your buttons.

Why? Just curious. In any game library I've worked with (not that many TBF) it draws the first thing drawn at the bottom, and the last thing drawn at the top.

1 hour ago, V0idWa1k3r said:

Your saveCard method shrinks the size of the item stack... on the client

Ah, didn't know that was a thing. I've worked with packets before, though, so this should be cake. If not I'll update here.

 

After all these changes, however, the display is still wonky. Preview (the language button turns up when I hover over the button above it).

 

EDIT: Also note that the text field should not show true as its text if the code works properly.

Edited by That_Martin_Guy
Link to comment
Share on other sites

18 minutes ago, That_Martin_Guy said:

Why? Just curious. In any game library I've worked with (not that many TBF) it draws the first thing drawn at the bottom, and the last thing drawn at the top.

MC works the same way, that is how rendering in 2d works. The thing is - you are drawing your buttons first. the super call in the drawScreen method is what draws the buttons.

 

18 minutes ago, That_Martin_Guy said:

the language button turns up when I hover over the button above it.

That happens because a GuiButton can only have a y size of 20 at most. I do not see where you are setting your button's size above 20 in your class though, have you changed that?

 

18 minutes ago, That_Martin_Guy said:

I did look immensely at vanilla code, mainly GuiScreenBook. If I didn't I would've been completely lost since there are few gui tutorials that I've found.

By that I ment to compare your button positioning with vanilla's. You are positioning your buttons based on the positioning of your text fields, and those are not really positioned all that well... they are positioned exactly in the way they are drawn. Some are positioned against the right boundry of the screen

answerB = new GuiTextField(9, this.fontRenderer, this.width - 50, 200, 200, 20);
answerD = new GuiTextField(11, this.fontRenderer, this.width - 50, this.height / 2 + 100, 200, 20);

 

Some are positioned agains left top corner of the screen

answerA = new GuiTextField(8, this.fontRenderer, 200, 200, 200, 20);

 

And this one is positioned agains the left x boundry and the middle of the screen

answerC = new GuiTextField(10, this.fontRenderer, 200, this.height / 2 + 100, 200, 20);

 

If you want the buttons to anchor to the middle of the screen position them agains it. The center is [width / 2, height / 2]. width and height here are scaled width and height of the screen. 

 

Edited by V0idWa1k3r
  • Like 1
Link to comment
Share on other sites

15 minutes ago, V0idWa1k3r said:

That happens because a GuiButton can only have a y size of 20 at most. I do not see where you are setting your button's size above 20 in your class though, have you changed that?

Yes, I really derped here. I wanted the answer buttons to be 50x50 squares instead of 200x20 rectangles until I realised that the buttons would then be taller than the text fields ¬¬. Currently they are 20x20 squares.

 

I updated the positioning on the buttons and text fields, but now it only shows the texture and a single text field! Preview

 

I know that my message is not registered, does nothing etc, but I'm very tired currently and need to go to sleep. Can therefore not work on it for the night.

Link to comment
Share on other sites

Your positioning is still of. Think about it - the coordinates you are giving to the text field/button are it's top left corner. If you say "Your position is at width / 2 - 200, height / 2 - 200 and your size is 200, 20" then you are going to see the box at [width / 2 - 200 => width / 2; height / 2 - 200 => height / 2 - 180]. When you are creating a text field at width / 2 + 200 it will go from that to width / 2 + 400. The one text field you are seing is most likely your question field, everything else is way up there or down there with their current y coordinates and some are way too offset to the right.

 

As your buttons take positions from your text fields the same is true for them.

  • Like 1
Link to comment
Share on other sites

So after a lot of number tweaking the buttons are finally aligned properly. The texture is too small still, but I can fix it myself.

 

Big problem however; I cannot type in any of the text fields. I see nothing in the GuiTextField class pointing at them being disabled, and I even tried manually enabling them with setEnabled, but to no avail.

 

New code is not really worth showing, since I literally did nothing but tweak positions of the elements.

 

EDIT: By "cannot type" I mean if I click on them it doesn't focus. However, even if I focus one text field with setFocused(true) it doesn't type anything at all.

Edited by That_Martin_Guy
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.