Jump to content

[1.12.2][GUI] Popup text element when hovered over a GUI location


Recommended Posts

Posted (edited)

Hello!

 

So my block needs water to run (ex. raining/water buckets, etc) and I have a popup next to the gui inventory that shows that it needs one:

f9d9489d0a1a75d1dffc61751e041381.png

 

I want it to have the functionality for when you hover over it, it creates a text box saying "Needs water!" or something like that. I want the text box to be similar to the ones found when you hover over an item.

 

Thank you!

Edited by Lambda
The issue has not actually been solved

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

drawHoveringText

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.

Posted

Buttons do this already. Just make that area a button.

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.

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.

Posted (edited)

Okay, so I got the button half working. Its there and it clicks, but no hovering text. Aswell, how would I make the button go away when x condition is met:

 

Here is what I have so far:

Spoiler

@SideOnly(Side.CLIENT)
public class GuiVoidInfuser extends GuiContainerMod {

	private static final ResourceLocation RES_LOC = ResourceUtil.getGuiLocation("gui_voidInfuser");

    private final TileEntityVoidInfuser tileVoidInfuser;
    public static GuiVoidInfuser self;
        
    private float tickTime;
    private HintButton needsWater;
	
    public GuiVoidInfuser(InventoryPlayer inventoryPlayer, TileEntityBase tile){
        this(inventoryPlayer, tile, false);
    }

    private GuiVoidInfuser(InventoryPlayer inventory, TileEntityBase tile, boolean isDouble){
        super(new ContainerVoidInfuser(inventory, tile));
        this.tileVoidInfuser = (TileEntityVoidInfuser)tile;
        this.xSize = 176;
        this.ySize = 179;
        self = this;
    }

    @Override
    public void initGui(){
        super.initGui();
        
        this.needsWater = new HintButton(0, this.guiLeft+148, this.guiTop+42);
       	this.buttonList.add(this.needsWater);
    }
    
    @Override
    public void updateScreen(){
        super.updateScreen();
    }
    
    @Override
    public void drawScreen(int x, int y, float f){
        super.drawScreen(x, y, f);
    }

    @Override
    public void drawGuiContainerForegroundLayer(int x, int y){
        ResourceUtil.displayNameString(this.fontRenderer, this.xSize, -10, this.tileVoidInfuser);
    }
    
    @Override
    public void drawGuiContainerBackgroundLayer(float f, int x, int y){
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

        this.mc.getTextureManager().bindTexture(ResourceUtil.GUI_INVENTORY_LOCATION);
        this.drawTexturedModalRect(this.guiLeft, this.guiTop+93, 0, 0, 176, 86);
        
        this.mc.getTextureManager().bindTexture(RES_LOC);
        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93);
        
        if(this.tileVoidInfuser.hasWater == false){
            this.drawTexturedModalRect(this.guiLeft+148, this.guiTop+42, 180, 0, 19, 18);
        }else {
            this.tickTime = (55.00F / (float)this.tileVoidInfuser.runtime) * 100.00F; //55 ticks being MOST efficient
            this.fontRenderer.drawString((int)(this.tickTime) + "%", this.guiLeft+142, this.guiTop+75, StringUtil.COLOR_WHITE);
        }
    }
    
    public void drawText(List text, int x, int y) {
    	this.drawHoveringText(text, x, y);
    }
    
    @SideOnly(Side.CLIENT)
	static class HintButton extends GuiButton {

		protected HintButton(int buttonID, int posx, int posy) {
			super(buttonID, posx, posy, 18, 19, "");
		}

		@Override
		public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
			if (this.visible) {
				mc.getTextureManager().bindTexture(RES_LOC);
				GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
				this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
				this.drawTexturedModalRect(this.x, this.y, 0, 182, this.width, this.height);
			}
		}

		@Override
		public void drawButtonForegroundLayer(int x, int y) {
			List list = new ArrayList<String>();
			list.add(I18n.format("ce:voidIF_water"));
			GuiVoidInfuser.self.drawText(list, x, y);
		}
	}
    
}

 

It follows your code's basic principal and it still doesn't work; as well, what I mean by condition x is this:

        if(this.tileVoidInfuser.hasWater == false){
            this.drawTexturedModalRect(this.guiLeft+148, this.guiTop+42, 180, 0, 19, 18);
        }else {
            this.tickTime = (55.00F / (float)this.tileVoidInfuser.runtime) * 100.00F; //55 ticks being MOST efficient
            this.fontRenderer.drawString((int)(this.tickTime) + "%", this.guiLeft+142, this.guiTop+75, StringUtil.COLOR_WHITE);
        }

If hasWater is false, it displays that little icon -- I want the button to also appear/disappear with that.

 

Thanks

 

-- Nevermind! I found my error, I didn't iterate through the ubttons to check if the mouse is over!

 

Thanks for my help.


and this is the fix:

Spoiler



		Iterator<GuiButton> iterator = this.buttonList.iterator();

		while (iterator.hasNext())
		{
			GuiButton guibutton = iterator.next();

			if (guibutton.isMouseOver())
			{
				guibutton.drawButtonForegroundLayer(x- this.guiLeft, y - this.guiTop);
				break;
			}
		}


 

 

Edited by Lambda
fixed

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

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.