diff options
author | bowser0000 <bowser0000@gmail.com> | 2021-11-24 21:58:26 -0500 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2021-11-24 21:58:26 -0500 |
commit | c466240003b130b43c17da9e585b80380154e4c4 (patch) | |
tree | ba6a03498dac85027d853e535aea0c71542d1f2f /src/main/java/me/Danker/gui/crystalhollowwaypoints | |
parent | b733d88cb79942d4a260293d1bb1f2d27fcc61e2 (diff) | |
download | SkyblockMod-c466240003b130b43c17da9e585b80380154e4c4.tar.gz SkyblockMod-c466240003b130b43c17da9e585b80380154e4c4.tar.bz2 SkyblockMod-c466240003b130b43c17da9e585b80380154e4c4.zip |
Add custom alerts based on chat
Also move some other stuff around
Diffstat (limited to 'src/main/java/me/Danker/gui/crystalhollowwaypoints')
3 files changed, 358 insertions, 0 deletions
diff --git a/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowAddWaypointGui.java b/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowAddWaypointGui.java new file mode 100644 index 0000000..df91f04 --- /dev/null +++ b/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowAddWaypointGui.java @@ -0,0 +1,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); + } + +} diff --git a/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointActionGui.java b/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointActionGui.java new file mode 100644 index 0000000..f792892 --- /dev/null +++ b/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointActionGui.java @@ -0,0 +1,95 @@ +package me.Danker.gui.crystalhollowwaypoints; + +import me.Danker.DankersSkyblockMod; +import me.Danker.features.CrystalHollowWaypoints; +import me.Danker.handlers.TextRenderer; +import me.Danker.utils.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.EnumChatFormatting; + +public class CrystalHollowWaypointActionGui extends GuiScreen { + + private int id; + + private GuiButton goBack; + private GuiButton toggle; + private GuiButton sendNormal; + private GuiButton sendDSM; + private GuiButton sendSBE; + private GuiButton delete; + + public CrystalHollowWaypointActionGui(int id) { + this.id = id; + } + + @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(); + + CrystalHollowWaypoints.Waypoint waypoint = CrystalHollowWaypoints.waypoints.get(id); + + goBack = new GuiButton(0, 2, height - 30, 100, 20, "Go Back"); + toggle = new GuiButton(0, width / 2 - 100, (int) (height * 0.1), "Set Visibility: " + Utils.getColouredBoolean(waypoint.toggled)); + sendNormal = new GuiButton(0, width / 2 - 100, (int) (height * 0.2), "Send Location And Coordinates"); + sendDSM = new GuiButton(0, width / 2 - 100, (int) (height * 0.3), "Send DSM Formatted Waypoint"); + sendSBE = new GuiButton(0, width / 2 - 100, (int) (height * 0.4), "Send SBE Formatted Waypoint"); + delete = new GuiButton(0, width / 2 - 100, (int) (height * 0.8), EnumChatFormatting.RED + "Delete Waypoint"); + + this.buttonList.add(toggle); + this.buttonList.add(sendNormal); + this.buttonList.add(sendDSM); + this.buttonList.add(sendSBE); + this.buttonList.add(delete); + this.buttonList.add(goBack); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + + CrystalHollowWaypoints.Waypoint waypoint = CrystalHollowWaypoints.waypoints.get(id); + + String waypointText = waypoint.location + " @ " + waypoint.getPos(); + int pageWidth = mc.fontRendererObj.getStringWidth(waypointText); + new TextRenderer(mc, waypointText, width / 2 - pageWidth / 2, 10, 1D); + } + + @Override + public void actionPerformed(GuiButton button) { + CrystalHollowWaypoints.Waypoint waypoint = CrystalHollowWaypoints.waypoints.get(id); + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + if (button == goBack) { + mc.displayGuiScreen(new CrystalHollowWaypointsGui(1)); + DankersSkyblockMod.guiToOpen = "crystalwaypoints"; + } else if (button == toggle) { + waypoint.toggle(); + toggle.displayString = "Set Visibility: " + Utils.getColouredBoolean(waypoint.toggled); + } else if (button == sendNormal) { + player.sendChatMessage(waypoint.location + " @ " + waypoint.getPos()); + } else if (button == sendDSM) { + player.sendChatMessage("$DSMCHWP:" + waypoint.getFormattedWaypoint()); + } else if (button == sendSBE) { + player.sendChatMessage("$SBECHWP:" + waypoint.getFormattedWaypoint()); + } else if (button == delete) { + CrystalHollowWaypoints.waypoints.remove(id); + mc.displayGuiScreen(new CrystalHollowWaypointsGui(1)); + return; + } + CrystalHollowWaypoints.waypoints.set(id, waypoint); + } + +} diff --git a/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointsGui.java b/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointsGui.java new file mode 100644 index 0000000..a3d0452 --- /dev/null +++ b/src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointsGui.java @@ -0,0 +1,145 @@ +package me.Danker.gui.crystalhollowwaypoints; + +import me.Danker.DankersSkyblockMod; +import me.Danker.commands.ToggleCommand; +import me.Danker.features.CrystalHollowWaypoints; +import me.Danker.gui.DankerGui; +import me.Danker.gui.buttons.FeatureButton; +import me.Danker.handlers.ConfigHandler; +import me.Danker.handlers.TextRenderer; +import me.Danker.utils.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; + +import java.util.ArrayList; +import java.util.List; + +public class CrystalHollowWaypointsGui extends GuiScreen { + + private final int page; + private final List<GuiButton> allButtons = new ArrayList<>(); + + private GuiButton goBack; + private GuiButton backPage; + private GuiButton nextPage; + private GuiButton sendDSM; + private GuiButton sendSBE; + private GuiButton add; + private FeatureButton crystalHollowWaypoints; + private FeatureButton crystalAutoWaypoints; + + public CrystalHollowWaypointsGui(int page) { + this.page = page; + } + + @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(); + + goBack = new GuiButton(0, 2, height - 30, 100, 20, "Go Back"); + backPage = new GuiButton(0, width / 2 - 100, (int) (height * 0.8), 80, 20, "< Back"); + nextPage = new GuiButton(0, width / 2 + 20, (int) (height * 0.8), 80, 20, "Next >"); + sendDSM = new GuiButton(0, 2, 10, 175, 20, "Send DSM Formatted Waypoints"); + sendSBE = new GuiButton(0, 2, 40, 175, 20, "Send SBE Formatted Waypoints"); + add = new GuiButton(0, 0, 0, "Add Waypoint"); + crystalHollowWaypoints = new FeatureButton("Crystal Hollows Waypoints: " + Utils.getColouredBoolean(ToggleCommand.crystalHollowWaypoints), "Shows waypoints to various places in the Crystal Hollows."); + crystalAutoWaypoints = new FeatureButton("Auto Waypoints: " + Utils.getColouredBoolean(ToggleCommand.crystalAutoWaypoints), "Automatically creates waypoints when you visit a special place in the Crystal Hollows."); + + allButtons.clear(); + allButtons.add(add); + allButtons.add(crystalHollowWaypoints); + allButtons.add(crystalAutoWaypoints); + for (int i = 0; i < CrystalHollowWaypoints.waypoints.size(); i++) { + CrystalHollowWaypoints.Waypoint waypoint = CrystalHollowWaypoints.waypoints.get(i); + GuiButton button = new GuiButton(i, 0, 0, waypoint.location + " >"); + allButtons.add(button); + } + + reInit(); + } + + public void reInit() { + this.buttonList.clear(); + + for (int i = (page - 1) * 7, iteration = 0; iteration < 7 && i < allButtons.size(); i++, iteration++) { + GuiButton button = allButtons.get(i); + button.xPosition = width / 2 - 100; + button.yPosition = (int) (height * (0.1 * (iteration + 1))); + this.buttonList.add(button); + } + + if (page > 1) this.buttonList.add(backPage); + if (page < Math.ceil(allButtons.size() / 7D)) this.buttonList.add(nextPage); + + this.buttonList.add(goBack); + this.buttonList.add(sendDSM); + this.buttonList.add(sendSBE); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + + String pageText = "Page: " + page + "/" + (int) Math.ceil(allButtons.size() / 7D); + int pageWidth = mc.fontRendererObj.getStringWidth(pageText); + new TextRenderer(mc, pageText, width / 2 - pageWidth / 2, 10, 1D); + } + + @Override + public void actionPerformed(GuiButton button) { + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + if (button == goBack) { + mc.displayGuiScreen(new DankerGui(1, "")); + } else if (button == nextPage) { + mc.displayGuiScreen(new CrystalHollowWaypointsGui(page + 1)); + } else if (button == backPage) { + mc.displayGuiScreen(new CrystalHollowWaypointsGui(page - 1)); + } else if (button == sendDSM) { + if (CrystalHollowWaypoints.waypoints.size() > 0) { + StringBuilder message = new StringBuilder(); + for (CrystalHollowWaypoints.Waypoint waypoint : CrystalHollowWaypoints.waypoints) { + if (message.length() > 0) message.append("\\n"); + message.append(waypoint.getFormattedWaypoint()); + } + message.insert(0, "$DSMCHWP:"); + player.sendChatMessage(message.toString()); + } + } else if (button == sendSBE) { + if (CrystalHollowWaypoints.waypoints.size() > 0) { + StringBuilder message = new StringBuilder(); + for (CrystalHollowWaypoints.Waypoint waypoint : CrystalHollowWaypoints.waypoints) { + if (message.length() > 0) message.append("\\n"); + message.append(waypoint.getFormattedWaypoint()); + } + message.insert(0, "$SBECHWP:"); + player.sendChatMessage(message.toString()); + } + } else if (button == add) { + mc.displayGuiScreen(new CrystalHollowAddWaypointGui()); + } else if (button == crystalHollowWaypoints) { + ToggleCommand.crystalHollowWaypoints = !ToggleCommand.crystalHollowWaypoints; + ConfigHandler.writeBooleanConfig("toggles", "CrystalHollowWaypoints", ToggleCommand.crystalHollowWaypoints); + crystalHollowWaypoints.displayString = "Crystal Hollows Waypoints: " + Utils.getColouredBoolean(ToggleCommand.crystalHollowWaypoints); + } else if (button == crystalAutoWaypoints) { + ToggleCommand.crystalAutoWaypoints = !ToggleCommand.crystalAutoWaypoints; + ConfigHandler.writeBooleanConfig("toggles", "CrystalAutoWaypoints", ToggleCommand.crystalAutoWaypoints); + crystalAutoWaypoints.displayString = "Auto Waypoints: " + Utils.getColouredBoolean(ToggleCommand.crystalAutoWaypoints); + } else { + mc.displayGuiScreen(new CrystalHollowWaypointActionGui(button.id)); + } + } + +} |