aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/example/MyGuiScreen.java
blob: 331e21d4386fb551bc79c860dfe74b12aa895166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.example;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

import java.io.IOException;

public class MyGuiScreen extends GuiScreen {

    int lastClickedButton = 0;

    @Override
    public void initGui() {
        super.initGui();
        this.buttonList.add(new GuiButton(0, width / 2 - 55, height / 2 - 10, 30, 20, "§cRED"));
        this.buttonList.add(new GuiButton(1, width / 2 - 15, height / 2 - 10, 30, 20, "§9BLUE"));
        this.buttonList.add(new GuiButton(2, width / 2 + 25, height / 2 - 10, 30, 20, "§2GREEN"));
    }

    @Override
    protected void actionPerformed(GuiButton button) throws IOException {
        lastClickedButton = button.id;
    }

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        // Draw tinted background
        drawDefaultBackground();

        Minecraft minecraft = Minecraft.getMinecraft();

        // First we need to bind the texture
        minecraft.getTextureManager().bindTexture(new ResourceLocation("examplemod"/* or your modid */, "textures/gui/background.png"));

        // Render from your texture.
        drawModalRectWithCustomSizedTexture(
                // The first two arguments are the position on the screen
                width / 2 - 100, height / 2 - 20,
                // The next arguments are the starting u and v
                0, 0,
                // The next arguments are the size on the screen
                200, 40,
                // The last two arguments are the size of the texture
                200, 40
        );

        FontRenderer fr = minecraft.fontRendererObj;
        String text = "Hello, World!";
        int textWidth = fr.getStringWidth(text);

        // Draw a string left aligned
        fr.drawString(text, width / 2 - 95, height / 2 - 15, 0xFF000000);

        // Draw a string center aligned
        GlStateManager.pushMatrix();
        GlStateManager.translate(width / 2, height / 2 - 5 + fr.FONT_HEIGHT / 2, 0);
        GlStateManager.rotate((float) ((System.currentTimeMillis() / 200.0) % (360)), 0, 0, 1);
        fr.drawString(text, -textWidth / 2, -fr.FONT_HEIGHT / 2, 0xFF000000);
        GlStateManager.popMatrix();

        // Draw a string right aligned
        fr.drawString(text, width / 2 + 95 - textWidth, height / 2 + 5, 0xFF000000);
    }

    @Override
    protected void keyTyped(char typedChar, int keyCode) throws IOException {
        super.keyTyped(typedChar, keyCode);
    }

    int lastMouseButton = -1;

    @Override
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
        super.mouseClicked(mouseX, mouseY, mouseButton);
        lastMouseButton = mouseButton;
    }
}