aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/gui/alerts
diff options
context:
space:
mode:
authorCuzImClicks <bruno778.whiteelfie@gmail.com>2022-04-22 17:46:57 +0200
committerCuzImClicks <bruno778.whiteelfie@gmail.com>2022-04-22 17:46:57 +0200
commitbe49b91e35d939fc4afff8179af6c3405964c35c (patch)
tree08df99fad8c211a85a17f5b05c86e10501ec7f67 /src/main/java/me/Danker/gui/alerts
parentb443b1840760300d6a58951829911025b57f1bfb (diff)
parentc9c0ea6a3e3382fd236345b89bd0991c8b8cbb17 (diff)
downloadSkyblockMod-be49b91e35d939fc4afff8179af6c3405964c35c.tar.gz
SkyblockMod-be49b91e35d939fc4afff8179af6c3405964c35c.tar.bz2
SkyblockMod-be49b91e35d939fc4afff8179af6c3405964c35c.zip
Merge remote-tracking branch 'upstream/development' into development
Diffstat (limited to 'src/main/java/me/Danker/gui/alerts')
-rw-r--r--src/main/java/me/Danker/gui/alerts/AlertActionGui.java91
-rw-r--r--src/main/java/me/Danker/gui/alerts/AlertAddGui.java154
-rw-r--r--src/main/java/me/Danker/gui/alerts/AlertsGui.java103
3 files changed, 348 insertions, 0 deletions
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..7a73f5a
--- /dev/null
+++ b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java
@@ -0,0 +1,91 @@
+package me.Danker.gui.alerts;
+
+import me.Danker.features.Alerts;
+import me.Danker.handlers.TextRenderer;
+import me.Danker.utils.RenderUtils;
+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 toggleDesktop;
+ 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));
+ toggleDesktop = new GuiButton(0, width / 2 - 100, (int) (height * 0.2), "Desktop Notification: " + Utils.getColouredBoolean(alert.desktop));
+ edit = new GuiButton(0, width / 2 - 100, (int) (height * 0.3), "Edit >");
+ delete = new GuiButton(0, width / 2 - 100, (int) (height * 0.8), EnumChatFormatting.RED + "Delete Alert");
+
+ this.buttonList.add(toggle);
+ this.buttonList.add(toggleDesktop);
+ 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);
+
+ RenderUtils.drawCenteredText(alert.alert, width, 10, 1D);
+ 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 == toggleDesktop) {
+ alert.toggleDesktop();
+ toggleDesktop.displayString = "Desktop Notification: " + Utils.getColouredBoolean(alert.desktop);
+ } 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);
+ Alerts.saveToFile();
+ }
+
+}
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..5f01d6d
--- /dev/null
+++ b/src/main/java/me/Danker/gui/alerts/AlertAddGui.java
@@ -0,0 +1,154 @@
+package me.Danker.gui.alerts;
+
+import me.Danker.features.Alerts;
+import me.Danker.handlers.TextRenderer;
+import me.Danker.utils.RenderUtils;
+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.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 String location = "Skyblock";
+ private GuiButton startsWith;
+ private GuiButton contains;
+ private GuiButton endsWith;
+ private GuiButton everywhere;
+ private GuiButton skyblock;
+ private GuiButton dungeons;
+ private GuiTextField message;
+ private GuiTextField alert;
+ private GuiCheckBox desktop;
+ 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");
+ everywhere = new GuiButton(0, width / 2 - 200, (int) (height * 0.3), 120, 20, "Everywhere");
+ skyblock = new GuiButton(0, width / 2 - 60, (int) (height * 0.3), 120, 20, "Skyblock");
+ dungeons = new GuiButton(0, width / 2 + 80, (int) (height * 0.3), 120, 20, "Dungeons");
+ message = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.4), 200, 20);
+ alert = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.5), 200, 20);
+ desktop = new GuiCheckBox(0, width / 2 - 58, (int) (height * 0.6), "Desktop Notification", false);
+ toggled = new GuiCheckBox(0, width / 2 - 26, (int) (height * 0.65), "Toggled", true);
+ add = new GuiButton(0, width / 2 - 25, (int) (height * 0.8), 50, 20, "Add");
+
+ if (editing) {
+ mode = base.mode;
+ location = base.location;
+ message.setText(base.message);
+ alert.setText(base.alert);
+ desktop.setIsChecked(base.desktop);
+ 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(everywhere);
+ this.buttonList.add(skyblock);
+ this.buttonList.add(dungeons);
+ this.buttonList.add(desktop);
+ 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();
+
+ RenderUtils.drawCenteredText("Mode: " + mode, width, (int) (height * 0.1), 1D);
+ RenderUtils.drawCenteredText("Location: " + location, width, (int) (height * 0.15), 1D);
+ new TextRenderer(mc, "Trigger:", width / 2 - 145, (int) (height * 0.42), 1D);
+ new TextRenderer(mc, "Alert Text:", width / 2 - 158, (int) (height * 0.52), 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 == everywhere) {
+ location = "Everywhere";
+ } else if (button == skyblock) {
+ location = "Skyblock";
+ } else if (button == dungeons) {
+ location = "Dungeons";
+ } else if (button == add) {
+ Alerts.Alert newAlert = new Alerts.Alert(mode, location, message.getText(), alert.getText(), desktop.isChecked(), toggled.isChecked());
+ if (editing) {
+ Alerts.alerts.set(id, newAlert);
+ } else {
+ Alerts.alerts.add(newAlert);
+ }
+ 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..d73d56a
--- /dev/null
+++ b/src/main/java/me/Danker/gui/alerts/AlertsGui.java
@@ -0,0 +1,103 @@
+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.utils.RenderUtils;
+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<GuiButton> 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);
+ RenderUtils.drawCenteredText(pageText, width, 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));
+ }
+ }
+
+}