aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowAddWaypointGui.java
blob: df91f04e99c7570849cf86297d07b07e52e31894 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package me.Danker.gui.crystalhollowwaypoints;

import me.Danker.features.CrystalHollowWaypoints;
import me.Danker.handlers.TextRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;

import java.io.IOException;

public class CrystalHollowAddWaypointGui extends GuiScreen {

    private GuiButton cancel;

    private GuiTextField name;
    private GuiButton curPos;
    private GuiTextField x;
    private GuiTextField y;
    private GuiTextField z;
    private GuiButton add;

    @Override
    public boolean doesGuiPauseGame() {
        return false;
    }

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

        ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
        int height = sr.getScaledHeight();
        int width = sr.getScaledWidth();

        cancel = new GuiButton(0, 2, height - 30, 100, 20, "Cancel");

        name = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.1), 200, 20);
        curPos = new GuiButton(0, width / 2 - 50, (int) (height * 0.25), 100, 20, "Current Position");
        x = new GuiTextField(0, this.fontRendererObj, width / 2 - 85, (int) (height * 0.4), 50, 20);
        y = new GuiTextField(0, this.fontRendererObj, width / 2 - 25, (int) (height * 0.4), 50, 20);
        z = new GuiTextField(0, this.fontRendererObj, width / 2 + 35, (int) (height * 0.4), 50, 20);
        add = new GuiButton(0, width / 2 - 25, (int) (height * 0.6), 50, 20, "Add");

        name.setVisible(true);
        name.setEnabled(true);
        x.setVisible(true);
        x.setEnabled(true);
        y.setVisible(true);
        y.setEnabled(true);
        z.setVisible(true);
        z.setEnabled(true);

        this.buttonList.add(cancel);
        this.buttonList.add(curPos);
        this.buttonList.add(add);
    }

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

        name.drawTextBox();
        x.drawTextBox();
        y.drawTextBox();
        z.drawTextBox();

        new TextRenderer(mc, "X:", width / 2 - 85, (int) (height * 0.35), 1D);
        new TextRenderer(mc, "Y:", width / 2 - 25, (int) (height * 0.35), 1D);
        new TextRenderer(mc, "Z:", width / 2 + 35, (int) (height * 0.35), 1D);
    }

    @Override
    public void actionPerformed(GuiButton button) {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;

        if (button == cancel) {
            mc.displayGuiScreen(new CrystalHollowWaypointsGui(1));
        } else if (button == curPos) {
            x.setText(Integer.toString(player.getPosition().getX()));
            y.setText(Integer.toString(player.getPosition().getY()));
            z.setText(Integer.toString(player.getPosition().getZ()));
        } else if (button == add) {
            String loc = name.getText().length() == 0 ? Integer.toString(CrystalHollowWaypoints.waypoints.size()) : name.getText();
            int xPos = x.getText().matches("[-]?\\d+") ? Integer.parseInt(x.getText()) : player.getPosition().getX();
            int yPos = y.getText().matches("[-]?\\d+") ? Integer.parseInt(y.getText()) : player.getPosition().getY();
            int zPos = z.getText().matches("[-]?\\d+") ? Integer.parseInt(z.getText()) : player.getPosition().getZ();

            BlockPos pos = new BlockPos(xPos, yPos, zPos);
            CrystalHollowWaypoints.waypoints.add(new CrystalHollowWaypoints.Waypoint(loc, pos));

            mc.displayGuiScreen(new CrystalHollowWaypointsGui(1));
        }
    }

    @Override
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
        super.mouseClicked(mouseX, mouseY, mouseButton);
        name.mouseClicked(mouseX, mouseY, mouseButton);
        x.mouseClicked(mouseX, mouseY, mouseButton);
        y.mouseClicked(mouseX, mouseY, mouseButton);
        z.mouseClicked(mouseX, mouseY, mouseButton);
    }

    @Override
    protected void keyTyped(char typedChar, int keyCode) throws IOException {
        super.keyTyped(typedChar, keyCode);
        name.textboxKeyTyped(typedChar, keyCode);
        x.textboxKeyTyped(typedChar, keyCode);
        y.textboxKeyTyped(typedChar, keyCode);
        z.textboxKeyTyped(typedChar, keyCode);
    }

}