Jump to content

[1.7.10] How to render a gui over another gui?


HappyKiller1O1

Recommended Posts

The title says it all. I want to render a gui over another gui that is already displayed. I went to the Minecraft.displayGuiScreen to see if there is a work around but it seems to always close the gui if another is going to be displayed. Any way around this?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

If you are opening GUIs using Minecraft.getMinecraft().displayGuiScreen(GuiScreen) your mod becomes multiplayer inpompatible. If you try to play multiplayer with that, it always opens the gui to server's owner. For example, server owner has his server and you are it's admin and you installed your mod to this server. And when you open the gui, the gui opens to admin. I think you don't want this.

Use:

player.openGui(ModInstance, GuiID, world, x, y, z);

And I recommend to watch diesieben07's tutorial about simple packet handling. It's very usefull if you are changing something like tile entity that is on server side.

Tutorial link http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

I didn't know using displayGuiScreen did that, but thanks. I already know how to make a gui handler, just thought that way was easier. xD And, how would I use those events to display a Gui over another? Maybe just a simple example would be nice. :)

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Main idea is:

You save fields inside your own storage (event class for example).

Initialize them inside GuiScreenEvent.InitGuiEvent by checking if event.gui is instance of gui desired.

And then draw those elements in GuiScreenEvent.DrawScreenEvent, do button actions in GuiScreenEvent.ActionPerformedEvent.

 

 

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

That is so much work. ;-; I think I'll just have to deal with not having it drawn over. I have way too many gui's to display over. xD

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

So, I am trying to do what you told me Ernio but, this happens. ;-;

 

http://i.imgur.com/Lqfv5jY.png

http://i.imgur.com/eWQHSBh.png

 

Here's where I render it in my EventForgeClient Class:

 

@SubscribeEvent
public void onGuiScreenDrawn(DrawScreenEvent event) {
	int width = event.gui.width;
	int height = event.gui.height;

	int xSize = 80;
	int ySize = 40;

	if(event.gui instanceof GuiShopBlock) {
		if(GuiShopBlock.getDisplayE()) {
			this.drawPurchaseOverlay("Emerald", Items.emerald, 500, width, height, xSize, ySize, event.gui.mc, event.gui);
			System.out.println("Emerald is True");
		}
	}
}

private void drawPurchaseOverlay(String title, Item itemForRender, int price, int width, int height, int xSize, int ySize, Minecraft mc, GuiScreen gui) {
	GL11.glPushMatrix();

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        int k = (width - xSize) / 2;
        int l = (height - ySize) / 2;

	mc.getTextureManager().bindTexture(crewShopPurchase);

	gui.drawTexturedModalRect(k, l, 0, 0, width, height);

	gui.drawCenteredString(mc.fontRenderer, "Purchase: " + title + "'s", k, l, 0xFFFFFF);

	RenderHelper.enableGUIStandardItemLighting();
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glEnable(GL11.GL_COLOR_MATERIAL);
        GL11.glEnable(GL11.GL_LIGHTING);
        
        //GL11.glScalef(2.00F, 2.00F, 2.00F);
        
        renderedItem.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.getTextureManager(), new ItemStack(itemForRender), k + 25, l + 25);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDepthMask(true);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        
        GL11.glPopMatrix();
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Since the Gui is yours, You can just draw the overlay Gui after the main Gui is drawn, in the method 'drawScreen'.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

That works but, it's still doing what was shown above. Am I doing something wrong with OpenGL?

 

public class GuiShopBlock extends GuiScreen {

public static final ResourceLocation texture = new ResourceLocation(MR.TNAME + "textures/gui/crew_shop.png");
private static final ResourceLocation crewShopPurchase = new ResourceLocation(MR.TNAME + "textures/gui/crew_shop_purchase.png");

private int xSize;
private int ySize;

RenderItem renderedItem;

private static boolean displayE;

public GuiShopBlock() {
	this.xSize = 176;
	this.ySize = 166;

	renderedItem = new RenderItem();

	displayE = false;
}

public void initGui() {
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        
	buttonList.clear();
	//buttonList.add(new GuiSlider(0, k + 25, l + 25, 30, 20, "", "", 1, 64, 1, false, true));
}

public void actionPerformed(GuiButton button) {

}

public void drawScreen(int x, int y, float f) { //Add buttons for shop
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;

	mc.getTextureManager().bindTexture(texture);

	this.drawTexturedModalRect(k, l, 0, 0, xSize, ySize);

	this.drawString(mc.fontRenderer, "Crew Shop", k + 60, l + 4, 0xFFFFFF);

	this.renderItemOnGui(Items.emerald, 0, 0);
	this.renderItemOnGui(Items.diamond, 100, 0);

	this.drawToolTips(x, y);

	if(this.getDisplayE()) {
		this.drawPurchaseOverlay("Emerald", Items.emerald, 500);
	}

	super.drawScreen(x, y, f);
}

public void drawToolTips(int mouseX, int mouseY) {
    int boxX = (this.width - this.xSize) / 2 + 25;
    int boxY = (this.height - this.ySize) / 2 + 25;

	int defaultX = 16;
	int defaultY = 16;

	if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY && mouseY < boxY + defaultY) {
		List list = new ArrayList();
		list.add("DEAFULT TEXT");
		this.drawHoveringText(list, mouseX, mouseY, fontRendererObj);
		//System.out.println("SHOULD DRAW THE TEXT");
	}
}

public void mouseClicked(int mouseX, int mouseY, int which) {
    int boxX = (this.width - this.xSize) / 2 + 25;
    int boxY = (this.height - this.ySize) / 2 + 25;

	int defaultX = 16;
	int defaultY = 16;

	if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY && mouseY < boxY + defaultY) {
		this.displayE = true;
		//FMLNetworkHandler.openGui(this.mc.thePlayer, CrewMod.instance, GuiId.guiPurchase, this.mc.theWorld, (int)this.mc.thePlayer.posX, (int)this.mc.thePlayer.posY, (int)this.mc.thePlayer.posZ);
		//System.out.println("SHOULD DISPLAY EMERALD SCREEN");
	}

	super.mouseClicked(mouseX, mouseY, which);
}

public void renderItemOnGui(Item item, int mulX, int mulY) {
        int k = (this.width - this.xSize) / 2 + 25;
        int l = (this.height - this.ySize) / 2 + 25;
        
	GL11.glPushMatrix();

	RenderHelper.enableGUIStandardItemLighting();
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glEnable(GL11.GL_COLOR_MATERIAL);
        GL11.glEnable(GL11.GL_LIGHTING);
        
        //GL11.glScalef(2.00F, 2.00F, 2.00F);
        
        renderedItem.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.getTextureManager(), new ItemStack(item), k + mulX, l + mulY);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDepthMask(true);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        
        GL11.glPopMatrix();
}

private void drawPurchaseOverlay(String title, Item itemForRender, int price) {
	GL11.glPushMatrix();

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;

	mc.getTextureManager().bindTexture(crewShopPurchase);

	this.drawTexturedModalRect(k, l, 0, 0, this.width, this.height);

	this.drawCenteredString(mc.fontRenderer, "Purchase: " + title + "'s", k, l, 0xFFFFFF);

	RenderHelper.enableGUIStandardItemLighting();
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glEnable(GL11.GL_COLOR_MATERIAL);
        GL11.glEnable(GL11.GL_LIGHTING);
        
        //GL11.glScalef(2.00F, 2.00F, 2.00F);
        
        renderedItem.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.getTextureManager(), new ItemStack(itemForRender), k + 25, l + 25);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDepthMask(true);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        
        GL11.glPopMatrix();
}

public boolean doesGuiPauseGame() {
	return false;
}

public static boolean getDisplayE() {
	return displayE;
}
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

No, it doesn't. I fixed it by rendering the items on the gui after I rendered the overlay. But, the items overlap the overlay. How would I render the items behind the overlay?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

You should render the item after the overlay is rendered.. There is no other way for this.

+ It would be your UV problem. Don't use drawTexturedModalRect.

        since it uses fixed u/x rate, it would use wrong UV and might cause problems like yours.

  Instead make your own version for that. There you should set the (u,v) to (0,1),(1,1),(1,0),(0,0).

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

No, it will solve this problem: http://i.imgur.com/Lqfv5jY.png

+ I said this thing wrong: You should render the item after the overlay is rendered. You should render item before the overlay is rendered.

And, draw the tooltip after everything is rendered.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Well, when I render it after the items are rendered, I get quite a weird lighting glitch and, the items still overlap. xD

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Well, when I render it after the items are rendered, I get quite a weird lighting glitch and, the items still overlap. xD

Weird lighting glitch would be from tooltip rendering. As I said, render the Tooltip AFTER everything is rendered.

And item overlapping cannot happen if item is rendered before the overlay is rendered...

So, post your current code.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.