Jump to content

[1.7.10] Centering a gui?


Awesome_Spider

Recommended Posts

I copied some of the code, it centers, but now it's acting like a gui in my previous mod did:

i0CXWbI.png

Here is my code:

int guiWidth = 192;
    int guiHeight = 256;
    int top;
    int left;

    static int GUI_ID = 30;

    private static String[] titlePageUntranslated = {
        "lexicon.titlePage.title.text"
    };
    private static String[] titlePageLocalized;

    private static LexiconPage currentPage = null;

    @Override
    public void initGui(){
        super.initGui();

        left = width / 2 - guiWidth / 2;
        top = height / 2 - guiHeight / 2;
    }

    @Override
    public void drawScreen(int mouseX, int mouseY, float par3) {
        super.drawScreen(mouseX, mouseY, par3);

        ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayWidth);

        int backX = sr.getScaledWidth();
        int backY = sr.getScaledHeight();

        this.drawTexturedModalRect(left, top, 0, 0, guiWidth, guiHeight);

        int stringWidth = this.fontRendererObj.getStringWidth("Lexicon of Knowledge");

        ResourceLocation background = new ResourceLocation(SignificantAdvancements.MODID, "textures/guis/lexiconBackground.png");
        Minecraft.getMinecraft().renderEngine.bindTexture(background);

        this.fontRendererObj.drawString("Lexicon of Knowledge", guiWidth - stringWidth, 50, 0x00FFFF, true);
    }

Link to comment
Share on other sites

About they aren't there... Just add them and define in constructor!

And also, code for your gui, centered (just replace whole class GuiLexicon with that and it will work):

public class GuiLexicon extends GuiScreen {
    int guiWidth = 192;
    int guiHeight = 256;
    
    int guiLeft = 0;
    int guiTop = 0;
    
    public GuiLexicon() {
    	guiLeft = (width - guiWidth) / 2;
    	guiTop = (height - guiHeight) / 2;
    }

    static int GUI_ID = 30;

    @Override
    public void drawScreen(int mouseX, int mouseY, float par3) {
        super.drawScreen(mouseX, mouseY, par3);

        Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(SignificantAdvancements.MODID, "textures/guis/lexiconBackground.png"));
        this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, guiWidth, guiHeight);       
        
        int stringWidth = this.fontRendererObj.getStringWidth(I18n.format("lexiconOfKnowledge.lang"));

        this.fontRendererObj.drawString(I18n.format("lexiconOfKnowledge.lang"), guiWidth - stringWidth, 50, 0x00FFFF, true);
    }
}

 

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.