From c466240003b130b43c17da9e585b80380154e4c4 Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Wed, 24 Nov 2021 21:58:26 -0500 Subject: Add custom alerts based on chat Also move some other stuff around --- src/main/java/me/Danker/DankersSkyblockMod.java | 25 +--- .../java/me/Danker/commands/ToggleCommand.java | 11 +- src/main/java/me/Danker/features/Alerts.java | 81 ++++++++++++ .../me/Danker/gui/CrystalHollowAddWaypointGui.java | 118 ----------------- .../Danker/gui/CrystalHollowWaypointActionGui.java | 94 ------------- .../me/Danker/gui/CrystalHollowWaypointsGui.java | 144 -------------------- src/main/java/me/Danker/gui/CustomMusicGui.java | 2 +- src/main/java/me/Danker/gui/DankerGui.java | 23 ++-- src/main/java/me/Danker/gui/DisplayGui.java | 2 +- src/main/java/me/Danker/gui/ExperimentsGui.java | 2 +- src/main/java/me/Danker/gui/OnlySlayerGui.java | 2 +- src/main/java/me/Danker/gui/PuzzleSolversGui.java | 2 +- src/main/java/me/Danker/gui/SkillTrackerGui.java | 2 +- .../java/me/Danker/gui/alerts/AlertActionGui.java | 82 ++++++++++++ .../java/me/Danker/gui/alerts/AlertAddGui.java | 130 ++++++++++++++++++ src/main/java/me/Danker/gui/alerts/AlertsGui.java | 104 +++++++++++++++ .../CrystalHollowAddWaypointGui.java | 118 +++++++++++++++++ .../CrystalHollowWaypointActionGui.java | 95 ++++++++++++++ .../CrystalHollowWaypointsGui.java | 145 +++++++++++++++++++++ .../java/me/Danker/handlers/ConfigHandler.java | 42 ++++-- 20 files changed, 820 insertions(+), 404 deletions(-) create mode 100644 src/main/java/me/Danker/features/Alerts.java delete mode 100644 src/main/java/me/Danker/gui/CrystalHollowAddWaypointGui.java delete mode 100644 src/main/java/me/Danker/gui/CrystalHollowWaypointActionGui.java delete mode 100644 src/main/java/me/Danker/gui/CrystalHollowWaypointsGui.java create mode 100644 src/main/java/me/Danker/gui/alerts/AlertActionGui.java create mode 100644 src/main/java/me/Danker/gui/alerts/AlertAddGui.java create mode 100644 src/main/java/me/Danker/gui/alerts/AlertsGui.java create mode 100644 src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowAddWaypointGui.java create mode 100644 src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointActionGui.java create mode 100644 src/main/java/me/Danker/gui/crystalhollowwaypoints/CrystalHollowWaypointsGui.java (limited to 'src/main/java/me/Danker') diff --git a/src/main/java/me/Danker/DankersSkyblockMod.java b/src/main/java/me/Danker/DankersSkyblockMod.java index 9fb7876..2ad5141 100644 --- a/src/main/java/me/Danker/DankersSkyblockMod.java +++ b/src/main/java/me/Danker/DankersSkyblockMod.java @@ -9,6 +9,7 @@ import me.Danker.features.*; import me.Danker.features.loot.*; import me.Danker.features.puzzlesolvers.*; import me.Danker.gui.*; +import me.Danker.gui.crystalhollowwaypoints.CrystalHollowWaypointsGui; import me.Danker.handlers.ConfigHandler; import me.Danker.handlers.PacketHandler; import me.Danker.utils.RenderUtils; @@ -101,6 +102,7 @@ public class DankersSkyblockMod { public void init(FMLInitializationEvent event) throws UnsupportedAudioFileException, IOException, LineUnavailableException { MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new AbilityCooldowns()); + MinecraftForge.EVENT_BUS.register(new Alerts()); MinecraftForge.EVENT_BUS.register(new ArachneESP()); MinecraftForge.EVENT_BUS.register(new ArrowTerminalSolver()); MinecraftForge.EVENT_BUS.register(new AutoAcceptReparty()); @@ -170,6 +172,8 @@ public class DankersSkyblockMod { MinecraftForge.EVENT_BUS.register(new WolfTracker()); MinecraftForge.EVENT_BUS.register(new ZombieTracker()); + Alerts.configFile = configDirectory + "/dsmalerts.json"; + ConfigHandler.reloadConfig(); GoldenEnchants.init(); TriviaSolver.init(); @@ -434,27 +438,6 @@ public class DankersSkyblockMod { case "displaygui": mc.displayGuiScreen(new DisplayGui()); break; - case "onlyslayergui": - mc.displayGuiScreen(new OnlySlayerGui()); - break; - case "editlocations": - mc.displayGuiScreen(new EditLocationsGui()); - break; - case "puzzlesolvers": - mc.displayGuiScreen(new PuzzleSolversGui(1)); - break; - case "experimentsolvers": - mc.displayGuiScreen(new ExperimentsGui()); - break; - case "skilltracker": - mc.displayGuiScreen(new SkillTrackerGui()); - break; - case "custommusic": - mc.displayGuiScreen(new CustomMusicGui(1)); - break; - case "crystalwaypoints": - mc.displayGuiScreen(new CrystalHollowWaypointsGui(1)); - break; case "inventory": mc.displayGuiScreen(InventoryCommand.chest); break; diff --git a/src/main/java/me/Danker/commands/ToggleCommand.java b/src/main/java/me/Danker/commands/ToggleCommand.java index 321458e..d9ef9b3 100644 --- a/src/main/java/me/Danker/commands/ToggleCommand.java +++ b/src/main/java/me/Danker/commands/ToggleCommand.java @@ -46,6 +46,7 @@ public class ToggleCommand extends CommandBase implements ICommand { public static boolean crystalAutoWaypoints; public static boolean autoAcceptReparty; public static boolean abilityCooldowns; + public static boolean alerts; // Chat Messages public static boolean sceptreMessages; public static boolean midasStaffMessages; @@ -144,7 +145,7 @@ public class ToggleCommand extends CommandBase implements ICommand { "gemstonelore", "crystalhollowwaypoints", "crystalautowaypoints", "autoacceptreparty", "itemcooldowns", "hubmusic", "islandmusic", "dungeonhubmusic", "farmingislandsmusic", "goldminemusic", "deepcavernsmusic", "dwarvenminesmusic", "crystalhollowsmusic", "spidersdenmusic", "blazingfortressmusic", - "endmusic", "parkmusic", "list"); + "endmusic", "parkmusic", "alerts", "list"); } return null; } @@ -586,6 +587,11 @@ public class ToggleCommand extends CommandBase implements ICommand { ConfigHandler.writeBooleanConfig("toggles", "DungeonMusic", parkMusic); player.addChatMessage(new ChatComponentText(DankersSkyblockMod.MAIN_COLOUR + "Custom park music has been set to " + DankersSkyblockMod.SECONDARY_COLOUR + parkMusic + DankersSkyblockMod.MAIN_COLOUR + ".")); break; + case "alert": + alerts = !alerts; + ConfigHandler.writeBooleanConfig("toggles", "Alerts", alerts); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.MAIN_COLOUR + "Alerts has been set to " + DankersSkyblockMod.SECONDARY_COLOUR + alerts + DankersSkyblockMod.MAIN_COLOUR + ".")); + break; case "list": player.addChatMessage(new ChatComponentText(DankersSkyblockMod.TYPE_COLOUR + "Guild party notifications: " + DankersSkyblockMod.VALUE_COLOUR + gpartyToggled + "\n" + DankersSkyblockMod.TYPE_COLOUR + " Coord/Angle display: " + DankersSkyblockMod.VALUE_COLOUR + coordsToggled + "\n" + @@ -659,7 +665,8 @@ public class ToggleCommand extends CommandBase implements ICommand { DankersSkyblockMod.TYPE_COLOUR + " Custom spider's den music: " + DankersSkyblockMod.VALUE_COLOUR + spidersDenMusic + "\n" + DankersSkyblockMod.TYPE_COLOUR + " Custom blazing fortress music: " + DankersSkyblockMod.VALUE_COLOUR + blazingFortressMusic + "\n" + DankersSkyblockMod.TYPE_COLOUR + " Custom end music: " + DankersSkyblockMod.VALUE_COLOUR + endMusic + "\n" + - DankersSkyblockMod.TYPE_COLOUR + " Custom park music: " + DankersSkyblockMod.VALUE_COLOUR + parkMusic + DankersSkyblockMod.TYPE_COLOUR + " Custom park music: " + DankersSkyblockMod.VALUE_COLOUR + parkMusic + "\n" + + DankersSkyblockMod.TYPE_COLOUR + " Alerts: " + DankersSkyblockMod.VALUE_COLOUR + alerts )); break; default: diff --git a/src/main/java/me/Danker/features/Alerts.java b/src/main/java/me/Danker/features/Alerts.java new file mode 100644 index 0000000..2a00fef --- /dev/null +++ b/src/main/java/me/Danker/features/Alerts.java @@ -0,0 +1,81 @@ +package me.Danker.features; + +import com.google.gson.GsonBuilder; +import me.Danker.commands.ToggleCommand; +import me.Danker.utils.Utils; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StringUtils; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Alerts { + + public static List alerts = new ArrayList<>(); + public static String configFile; + + @SubscribeEvent + public void onChat(ClientChatReceivedEvent event) { + if (!ToggleCommand.alerts || !Utils.inSkyblock || event.type == 2) return; + + String message = StringUtils.stripControlCodes(event.message.getUnformattedText()); + + for (Alert alert : alerts) { + if (!alert.toggled) continue; + + boolean trigger; + switch (alert.mode) { + case "Starts With": + trigger = message.startsWith(alert.message); + break; + case "Contains": + trigger = message.contains(alert.message); + break; + case "Ends With": + trigger = message.endsWith(alert.message); + break; + default: + continue; + } + + if (trigger) { + Utils.createTitle(EnumChatFormatting.RED + alert.alert.replace("&", "ยง"), 2); + return; + } + } + } + + public static void saveToFile() { + try (FileWriter writer = new FileWriter(configFile)) { + new GsonBuilder().create().toJson(alerts, writer); + writer.flush(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public static class Alert { + + public String mode; + public String message; + public String alert; + public boolean toggled; + + public Alert(String mode, String message, String alert, boolean toggled) { + this.mode = mode; + this.message = message; + this.alert = alert; + this.toggled = toggled; + } + + public void toggle() { + toggled = !toggled; + } + + } + +} diff --git a/src/main/java/me/Danker/gui/CrystalHollowAddWaypointGui.java b/src/main/java/me/Danker/gui/CrystalHollowAddWaypointGui.java deleted file mode 100644 index 7bb26cf..0000000 --- a/src/main/java/me/Danker/gui/CrystalHollowAddWaypointGui.java +++ /dev/null @@ -1,118 +0,0 @@ -package me.Danker.gui; - -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/CrystalHollowWaypointActionGui.java b/src/main/java/me/Danker/gui/CrystalHollowWaypointActionGui.java deleted file mode 100644 index 1575c18..0000000 --- a/src/main/java/me/Danker/gui/CrystalHollowWaypointActionGui.java +++ /dev/null @@ -1,94 +0,0 @@ -package me.Danker.gui; - -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) { - 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/CrystalHollowWaypointsGui.java b/src/main/java/me/Danker/gui/CrystalHollowWaypointsGui.java deleted file mode 100644 index de20cf1..0000000 --- a/src/main/java/me/Danker/gui/CrystalHollowWaypointsGui.java +++ /dev/null @@ -1,144 +0,0 @@ -package me.Danker.gui; - -import me.Danker.DankersSkyblockMod; -import me.Danker.commands.ToggleCommand; -import me.Danker.features.CrystalHollowWaypoints; -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 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) { - DankersSkyblockMod.guiToOpen = "dankergui1"; - } 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)); - } - } - -} diff --git a/src/main/java/me/Danker/gui/CustomMusicGui.java b/src/main/java/me/Danker/gui/CustomMusicGui.java index 83bed09..6695b9a 100644 --- a/src/main/java/me/Danker/gui/CustomMusicGui.java +++ b/src/main/java/me/Danker/gui/CustomMusicGui.java @@ -111,7 +111,7 @@ public class CustomMusicGui extends GuiScreen { @Override public void actionPerformed(GuiButton button) { if (button == goBack) { - DankersSkyblockMod.guiToOpen = "dankergui1"; + mc.displayGuiScreen(new DankerGui(1, "")); } else if (button == backPage) { Minecraft.getMinecraft().displayGuiScreen(new CustomMusicGui(page - 1)); } else if (button == nextPage) { diff --git a/src/main/java/me/Danker/gui/DankerGui.java b/src/main/java/me/Danker/gui/DankerGui.java index acd997e..2a081e1 100644 --- a/src/main/java/me/Danker/gui/DankerGui.java +++ b/src/main/java/me/Danker/gui/DankerGui.java @@ -2,7 +2,9 @@ package me.Danker.gui; import me.Danker.DankersSkyblockMod; import me.Danker.commands.ToggleCommand; +import me.Danker.gui.alerts.AlertsGui; import me.Danker.gui.buttons.FeatureButton; +import me.Danker.gui.crystalhollowwaypoints.CrystalHollowWaypointsGui; import me.Danker.handlers.ConfigHandler; import me.Danker.handlers.TextRenderer; import me.Danker.utils.Utils; @@ -43,6 +45,7 @@ public class DankerGui extends GuiScreen { private GuiButton skillTracker; private GuiButton customMusic; private GuiButton crystalHollowWaypoints; + private GuiButton alerts; // Toggles private GuiButton gparty; private GuiButton coords; @@ -124,6 +127,7 @@ public class DankerGui extends GuiScreen { skillTracker = new GuiButton(0, 0, 0, "Toggle Skill XP/Hour Tracking"); customMusic = new GuiButton(0, 0, 0, "Custom Music"); crystalHollowWaypoints = new GuiButton(0, 0, 0, "Crystal Hollows Waypoints"); + alerts = new GuiButton(0, 0, 0, "Alerts"); outlineText = new FeatureButton("Outline Displayed Text: " + Utils.getColouredBoolean(ToggleCommand.outlineTextToggled), "Adds bold outline to on-screen text."); pickBlock = new FeatureButton("Auto-Swap to Pick Block: " + Utils.getColouredBoolean(ToggleCommand.swapToPickBlockToggled), "Automatically changes left clicks to middle clicks.\nHelpful when lagging."); coords = new FeatureButton("Coordinate/Angle Display: " + Utils.getColouredBoolean(ToggleCommand.coordsToggled), "Displays coordinates and angle."); @@ -177,6 +181,7 @@ public class DankerGui extends GuiScreen { allButtons.add(skillTracker); allButtons.add(customMusic); allButtons.add(crystalHollowWaypoints); + allButtons.add(alerts); allButtons.add(outlineText); allButtons.add(pickBlock); allButtons.add(coords); @@ -288,7 +293,7 @@ public class DankerGui extends GuiScreen { } else if (button == backPage) { mc.displayGuiScreen(new DankerGui(page - 1, search.getText())); } else if (button == editLocations) { - DankersSkyblockMod.guiToOpen = "editlocations"; + mc.displayGuiScreen(new EditLocationsGui()); } else if (button == githubLink) { try { Desktop.getDesktop().browse(new URI("https://github.com/bowser0000/SkyblockMod")); @@ -302,19 +307,21 @@ public class DankerGui extends GuiScreen { ex.printStackTrace(); } } else if (button == changeDisplay) { - DankersSkyblockMod.guiToOpen = "displaygui"; + mc.displayGuiScreen(new DisplayGui()); } else if (button == onlySlayer) { - DankersSkyblockMod.guiToOpen = "onlyslayergui"; + mc.displayGuiScreen(new OnlySlayerGui()); } else if (button == puzzleSolvers) { - DankersSkyblockMod.guiToOpen = "puzzlesolvers"; + mc.displayGuiScreen(new PuzzleSolversGui(1)); } else if (button == experimentationTableSolvers) { - DankersSkyblockMod.guiToOpen = "experimentsolvers"; + mc.displayGuiScreen(new ExperimentsGui()); } else if (button == skillTracker) { - DankersSkyblockMod.guiToOpen = "skilltracker"; + mc.displayGuiScreen(new SkillTrackerGui()); } else if (button == customMusic) { - DankersSkyblockMod.guiToOpen = "custommusic"; + mc.displayGuiScreen(new CustomMusicGui(1)); } else if (button == crystalHollowWaypoints) { - DankersSkyblockMod.guiToOpen = "crystalwaypoints"; + mc.displayGuiScreen(new CrystalHollowWaypointsGui(1)); + } else if (button == alerts) { + mc.displayGuiScreen(new AlertsGui(1)); } else if (button == outlineText) { ToggleCommand.outlineTextToggled = !ToggleCommand.outlineTextToggled; ConfigHandler.writeBooleanConfig("toggles", "OutlineText", ToggleCommand.outlineTextToggled); diff --git a/src/main/java/me/Danker/gui/DisplayGui.java b/src/main/java/me/Danker/gui/DisplayGui.java index e5a6641..c6b1381 100644 --- a/src/main/java/me/Danker/gui/DisplayGui.java +++ b/src/main/java/me/Danker/gui/DisplayGui.java @@ -118,7 +118,7 @@ public class DisplayGui extends GuiScreen { @Override public void actionPerformed(GuiButton button) { if (button == goBack) { - DankersSkyblockMod.guiToOpen = "dankergui1"; + mc.displayGuiScreen(new DankerGui(1, "")); } else if (button == showSession) { addSession = !addSession; showSession.displayString = "Current Session Only: " + Utils.getColouredBoolean(addSession); diff --git a/src/main/java/me/Danker/gui/ExperimentsGui.java b/src/main/java/me/Danker/gui/ExperimentsGui.java index c3f4f47..3cc4929 100644 --- a/src/main/java/me/Danker/gui/ExperimentsGui.java +++ b/src/main/java/me/Danker/gui/ExperimentsGui.java @@ -52,7 +52,7 @@ public class ExperimentsGui extends GuiScreen { @Override public void actionPerformed(GuiButton button) { if (button == goBack) { - DankersSkyblockMod.guiToOpen = "dankergui1"; + mc.displayGuiScreen(new DankerGui(1, "")); } else if (button == ultrasequencer) { ToggleCommand.ultrasequencerToggled = !ToggleCommand.ultrasequencerToggled; ConfigHandler.writeBooleanConfig("toggles", "UltraSequencer", ToggleCommand.ultrasequencerToggled); diff --git a/src/main/java/me/Danker/gui/OnlySlayerGui.java b/src/main/java/me/Danker/gui/OnlySlayerGui.java index 8d56156..c203b8a 100644 --- a/src/main/java/me/Danker/gui/OnlySlayerGui.java +++ b/src/main/java/me/Danker/gui/OnlySlayerGui.java @@ -106,7 +106,7 @@ public class OnlySlayerGui extends GuiScreen { @Override public void actionPerformed(GuiButton button) { if (button == goBack) { - DankersSkyblockMod.guiToOpen = "dankergui1"; + mc.displayGuiScreen(new DankerGui(1, "")); return; } else if (button == off) { BlockWrongSlayer.onlySlayerName = ""; diff --git a/src/main/java/me/Danker/gui/PuzzleSolversGui.java b/src/main/java/me/Danker/gui/PuzzleSolversGui.java index 27233d8..3356ead 100644 --- a/src/main/java/me/Danker/gui/PuzzleSolversGui.java +++ b/src/main/java/me/Danker/gui/PuzzleSolversGui.java @@ -110,7 +110,7 @@ public class PuzzleSolversGui extends GuiScreen { @Override public void actionPerformed(GuiButton button) { if (button == goBack) { - DankersSkyblockMod.guiToOpen = "dankergui1"; + mc.displayGuiScreen(new DankerGui(1, "")); } else if (button == backPage) { Minecraft.getMinecraft().displayGuiScreen(new PuzzleSolversGui(page - 1)); } else if (button == nextPage) { diff --git a/src/main/java/me/Danker/gui/SkillTrackerGui.java b/src/main/java/me/Danker/gui/SkillTrackerGui.java index fb7a7c9..290310f 100644 --- a/src/main/java/me/Danker/gui/SkillTrackerGui.java +++ b/src/main/java/me/Danker/gui/SkillTrackerGui.java @@ -67,7 +67,7 @@ public class SkillTrackerGui extends GuiScreen { @Override public void actionPerformed(GuiButton button) { if (button == goBack) { - DankersSkyblockMod.guiToOpen = "dankergui1"; + mc.displayGuiScreen(new DankerGui(1, "")); } else if (button == start) { if (SkillTracker.skillStopwatch.isStarted() && SkillTracker.skillStopwatch.isSuspended()) { SkillTracker.skillStopwatch.resume(); diff --git a/src/main/java/me/Danker/gui/alerts/AlertActionGui.java b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java new file mode 100644 index 0000000..06dfd91 --- /dev/null +++ b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java @@ -0,0 +1,82 @@ +package me.Danker.gui.alerts; + +import me.Danker.features.Alerts; +import me.Danker.handlers.TextRenderer; +import me.Danker.utils.Utils; +import net.minecraft.client.Minecraft; +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 AlertActionGui extends GuiScreen { + + private final int id; + + private GuiButton goBack; + private GuiButton toggle; + private GuiButton edit; + private GuiButton delete; + + public AlertActionGui(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(); + + Alerts.Alert alert = Alerts.alerts.get(id); + + goBack = new GuiButton(0, 2, height - 30, 100, 20, "Go Back"); + toggle = new GuiButton(0, width / 2 - 100, (int) (height * 0.1), "Enabled: " + Utils.getColouredBoolean(alert.toggled)); + edit = new GuiButton(0, width / 2 - 100, (int) (height * 0.2), "Edit >"); + delete = new GuiButton(0, width / 2 - 100, (int) (height * 0.8), EnumChatFormatting.RED + "Delete Alert"); + + this.buttonList.add(toggle); + this.buttonList.add(edit); + 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); + + Alerts.Alert alert = Alerts.alerts.get(id); + + String alertText = alert.alert; + int textWidth = mc.fontRendererObj.getStringWidth(alertText); + new TextRenderer(mc, alertText, width / 2 - textWidth / 2, 10, 1D); + } + + @Override + public void actionPerformed(GuiButton button) { + Alerts.Alert alert = Alerts.alerts.get(id); + if (button == goBack) { + mc.displayGuiScreen(new AlertsGui(1)); + } else if (button == toggle) { + alert.toggle(); + toggle.displayString = "Enabled: " + Utils.getColouredBoolean(alert.toggled); + } else if (button == edit) { + mc.displayGuiScreen(new AlertAddGui(alert, id)); + } else if (button == delete) { + Alerts.alerts.remove(id); + Alerts.saveToFile(); + mc.displayGuiScreen(new AlertsGui(1)); + return; + } + Alerts.alerts.set(id, alert); + } + +} diff --git a/src/main/java/me/Danker/gui/alerts/AlertAddGui.java b/src/main/java/me/Danker/gui/alerts/AlertAddGui.java new file mode 100644 index 0000000..9014ea1 --- /dev/null +++ b/src/main/java/me/Danker/gui/alerts/AlertAddGui.java @@ -0,0 +1,130 @@ +package me.Danker.gui.alerts; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import me.Danker.features.Alerts; +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.minecraftforge.fml.client.config.GuiCheckBox; + +import java.io.FileWriter; +import java.io.IOException; + +public class AlertAddGui extends GuiScreen { + + private boolean editing; + private Alerts.Alert base = null; + private int id; + + private GuiButton cancel; + + private String mode = "Contains"; + private GuiButton startsWith; + private GuiButton contains; + private GuiButton endsWith; + private GuiTextField message; + private GuiTextField alert; + private GuiCheckBox toggled; + private GuiButton add; + + public AlertAddGui() {} + + public AlertAddGui(Alerts.Alert alert, int id) { + editing = true; + base = alert; + 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(); + + cancel = new GuiButton(0, 2, height - 30, 100, 20, "Cancel"); + + startsWith = new GuiButton(0, width / 2 - 200, (int) (height * 0.2), 120, 20, "Starts With"); + contains = new GuiButton(0, width / 2 - 60, (int) (height * 0.2), 120, 20, "Contains"); + endsWith = new GuiButton(0, width / 2 + 80, (int) (height * 0.2), 120, 20, "Ends With"); + message = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.3), 200, 20); + alert = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.4), 200, 20); + toggled = new GuiCheckBox(0, width / 2 - 26, (int) (height * 0.5), "Toggled", true); + add = new GuiButton(0, width / 2 - 25, (int) (height * 0.7), 50, 20, "Add"); + + if (editing) { + mode = base.mode; + message.setText(base.message); + alert.setText(base.alert); + toggled.setIsChecked(base.toggled); + } + + message.setVisible(true); + message.setEnabled(true); + alert.setVisible(true); + alert.setEnabled(true); + + this.buttonList.add(cancel); + this.buttonList.add(startsWith); + this.buttonList.add(contains); + this.buttonList.add(endsWith); + this.buttonList.add(toggled); + this.buttonList.add(add); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + + message.drawTextBox(); + alert.drawTextBox(); + + new TextRenderer(mc, "Mode: " + mode, width / 2 - 35, (int) (height * 0.15), 1D); + new TextRenderer(mc, "Trigger:", width / 2 - 145, (int) (height * 0.32), 1D); + new TextRenderer(mc, "Alert Text:", width / 2 - 158, (int) (height * 0.42), 1D); + } + + @Override + public void actionPerformed(GuiButton button) { + if (button == cancel) { + mc.displayGuiScreen(new AlertsGui(1)); + } else if (button == startsWith) { + mode = "Starts With"; + } else if (button == contains) { + mode = "Contains"; + } else if (button == endsWith) { + mode = "Ends With"; + } else if (button == add) { + Alerts.alerts.add(new Alerts.Alert(mode, message.getText(), alert.getText(), toggled.isChecked())); + if (editing) Alerts.alerts.remove(id); + Alerts.saveToFile(); + mc.displayGuiScreen(new AlertsGui(1)); + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + message.mouseClicked(mouseX, mouseY, mouseButton); + alert.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + super.keyTyped(typedChar, keyCode); + message.textboxKeyTyped(typedChar, keyCode); + alert.textboxKeyTyped(typedChar, keyCode); + } + +} diff --git a/src/main/java/me/Danker/gui/alerts/AlertsGui.java b/src/main/java/me/Danker/gui/alerts/AlertsGui.java new file mode 100644 index 0000000..3ccd869 --- /dev/null +++ b/src/main/java/me/Danker/gui/alerts/AlertsGui.java @@ -0,0 +1,104 @@ +package me.Danker.gui.alerts; + +import me.Danker.commands.ToggleCommand; +import me.Danker.features.Alerts; +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.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; + +import java.util.ArrayList; +import java.util.List; + +public class AlertsGui extends GuiScreen { + + private final int page; + private final List allButtons = new ArrayList<>(); + + private GuiButton goBack; + private GuiButton backPage; + private GuiButton nextPage; + private GuiButton add; + private GuiButton alerts; + + public AlertsGui(int page) { + this.page = page; + } + + @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 >"); + alerts = new FeatureButton("Alerts: " + Utils.getColouredBoolean(ToggleCommand.alerts), "Sends custom alert when a message is recieved"); + add = new GuiButton(0, 0, 0, "Add Alert"); + + allButtons.clear(); + allButtons.add(alerts); + allButtons.add(add); + for (int i = 0; i < Alerts.alerts.size(); i++) { + Alerts.Alert alert = Alerts.alerts.get(i); + GuiButton button = new GuiButton(i, 0, 0, alert.alert + " >"); + 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); + } + + @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) { + if (button == goBack) { + mc.displayGuiScreen(new DankerGui(1, "")); + } else if (button == nextPage) { + mc.displayGuiScreen(new AlertsGui(page + 1)); + } else if (button == backPage) { + mc.displayGuiScreen(new AlertsGui(page - 1)); + } else if (button == add) { + mc.displayGuiScreen(new AlertAddGui()); + } else if (button == alerts) { + ToggleCommand.alerts = !ToggleCommand.alerts; + ConfigHandler.writeBooleanConfig("toggles", "Alerts", ToggleCommand.alerts); + alerts.displayString = "Alerts: " + Utils.getColouredBoolean(ToggleCommand.alerts); + } else { + mc.displayGuiScreen(new AlertActionGui(button.id)); + } + } + +} 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 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)); + } + } + +} diff --git a/src/main/java/me/Danker/handlers/ConfigHandler.java b/src/main/java/me/Danker/handlers/ConfigHandler.java index 2a765ad..28f22fe 100644 --- a/src/main/java/me/Danker/handlers/ConfigHandler.java +++ b/src/main/java/me/Danker/handlers/ConfigHandler.java @@ -1,5 +1,8 @@ package me.Danker.handlers; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import me.Danker.DankersSkyblockMod; import me.Danker.commands.MoveCommand; import me.Danker.commands.ScaleCommand; @@ -13,7 +16,9 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.common.config.Configuration; -import java.io.File; +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; public class ConfigHandler { public static Configuration config; @@ -220,15 +225,6 @@ public class ConfigHandler { ToggleCommand.crystalAutoWaypoints = initBoolean("toggles", "CrystalAutoWaypoints", true); // enabled by default ToggleCommand.autoAcceptReparty = initBoolean("toggles", "AutoAcceptReparty", false); ToggleCommand.abilityCooldowns = initBoolean("toggles", "AbilityCooldowns", false); - // Chat Messages - ToggleCommand.sceptreMessages = initBoolean("toggles", "SceptreMessages", true); - ToggleCommand.midasStaffMessages = initBoolean("toggles", "MidasStaffMessages", true); - ToggleCommand.implosionMessages = initBoolean("toggles", "ImplosionMessages", true); - ToggleCommand.healMessages = initBoolean("toggles", "HealMessages", true); - ToggleCommand.cooldownMessages = initBoolean("toggles", "CooldownMessages", true); - ToggleCommand.manaMessages = initBoolean("toggles", "ManaMessages", true); - ToggleCommand.killComboMessages = initBoolean("toggles", "KillComboMessages", true); - // Dungeons ToggleCommand.dungeonTimerToggled = initBoolean("toggles", "DungeonTimer", false); ToggleCommand.lowHealthNotifyToggled = initBoolean("toggles", "LowHealthNotify", false); ToggleCommand.lividSolverToggled = initBoolean("toggles", "LividSolver", false); @@ -239,7 +235,16 @@ public class ConfigHandler { ToggleCommand.bonzoTimerToggled = initBoolean("toggles", "BonzoTimer", false); ToggleCommand.swapToPickBlockToggled = initBoolean("toggles", "PickBlock", false); ToggleCommand.flowerWeaponsToggled = initBoolean("toggles", "FlowerWeapons", false); - ToggleCommand.autoSkillTrackerToggled = initBoolean("toggles", "AutoSkillTracker", false); + ToggleCommand.autoSkillTrackerToggled = initBoolean("toggles", "AutoSkillTracker", false); + ToggleCommand.alerts = initBoolean("toggles", "Alerts", false); + // Chat Messages + ToggleCommand.sceptreMessages = initBoolean("toggles", "SceptreMessages", true); + ToggleCommand.midasStaffMessages = initBoolean("toggles", "MidasStaffMessages", true); + ToggleCommand.implosionMessages = initBoolean("toggles", "ImplosionMessages", true); + ToggleCommand.healMessages = initBoolean("toggles", "HealMessages", true); + ToggleCommand.cooldownMessages = initBoolean("toggles", "CooldownMessages", true); + ToggleCommand.manaMessages = initBoolean("toggles", "ManaMessages", true); + ToggleCommand.killComboMessages = initBoolean("toggles", "KillComboMessages", true); // Puzzle Solvers ToggleCommand.threeManToggled = initBoolean("toggles", "ThreeManPuzzle", false); ToggleCommand.oruoToggled = initBoolean("toggles", "OruoPuzzle", false); @@ -616,6 +621,21 @@ public class ConfigHandler { // Commands if (!hasKey("commands", "reparty")) writeBooleanConfig("commands", "reparty", false); + + // JSON + Gson gson = new Gson(); + + try { + if (!(new File(Alerts.configFile).exists())) { + FileWriter file = new FileWriter(Alerts.configFile); + file.write(new JsonArray().toString()); + file.close(); + } + Alerts.Alert[] alerts = gson.fromJson(new FileReader(Alerts.configFile), Alerts.Alert[].class); + if (alerts != null) Alerts.alerts = new ArrayList<>(Arrays.asList(alerts)); + } catch (IOException ex) { + ex.printStackTrace(); + } } } -- cgit