diff options
author | bowser0000 <bowser0000@gmail.com> | 2022-04-28 22:10:18 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2022-04-28 22:10:18 -0400 |
commit | 276734f87ce984e634e74a9a203402a93c7f7f12 (patch) | |
tree | 85aa0bd1240747a5bec8eab20e4ea188480c01ac /src/main/java/me/Danker/gui | |
parent | 5586d4588c8d106a3b080bb45ba74b3c81113162 (diff) | |
download | SkyblockMod-276734f87ce984e634e74a9a203402a93c7f7f12.tar.gz SkyblockMod-276734f87ce984e634e74a9a203402a93c7f7f12.tar.bz2 SkyblockMod-276734f87ce984e634e74a9a203402a93c7f7f12.zip |
Add chat aliases
Diffstat (limited to 'src/main/java/me/Danker/gui')
5 files changed, 310 insertions, 3 deletions
diff --git a/src/main/java/me/Danker/gui/DankerGui.java b/src/main/java/me/Danker/gui/DankerGui.java index 156a3a9..abf9ffa 100644 --- a/src/main/java/me/Danker/gui/DankerGui.java +++ b/src/main/java/me/Danker/gui/DankerGui.java @@ -2,6 +2,7 @@ package me.Danker.gui; import me.Danker.commands.ToggleCommand; import me.Danker.gui.alerts.AlertsGui; +import me.Danker.gui.aliases.AliasesGui; import me.Danker.gui.buttons.FeatureButton; import me.Danker.gui.crystalhollowwaypoints.CrystalHollowWaypointsGui; import me.Danker.handlers.ConfigHandler; @@ -45,6 +46,7 @@ public class DankerGui extends GuiScreen { private GuiButton customMusic; private GuiButton crystalHollowWaypoints; private GuiButton alerts; + private GuiButton aliases; // Toggles private GuiButton gparty; private GuiButton coords; @@ -132,6 +134,7 @@ public class DankerGui extends GuiScreen { customMusic = new GuiButton(0, 0, 0, "Custom Music"); crystalHollowWaypoints = new GuiButton(0, 0, 0, "Crystal Hollows Waypoints"); alerts = new GuiButton(0, 0, 0, "Alerts"); + aliases = new GuiButton(0, 0, 0, "Aliases"); 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."); @@ -191,6 +194,7 @@ public class DankerGui extends GuiScreen { allButtons.add(customMusic); allButtons.add(crystalHollowWaypoints); allButtons.add(alerts); + allButtons.add(aliases); allButtons.add(outlineText); allButtons.add(pickBlock); allButtons.add(coords); @@ -335,6 +339,8 @@ public class DankerGui extends GuiScreen { mc.displayGuiScreen(new CrystalHollowWaypointsGui(1)); } else if (button == alerts) { mc.displayGuiScreen(new AlertsGui(1)); + } else if (button == aliases) { + mc.displayGuiScreen(new AliasesGui(1)); } else if (button == outlineText) { ToggleCommand.outlineTextToggled = !ToggleCommand.outlineTextToggled; ConfigHandler.writeBooleanConfig("toggles", "OutlineText", ToggleCommand.outlineTextToggled); diff --git a/src/main/java/me/Danker/gui/alerts/AlertActionGui.java b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java index 3d0eb90..4853ac1 100644 --- a/src/main/java/me/Danker/gui/alerts/AlertActionGui.java +++ b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java @@ -60,9 +60,6 @@ public class AlertActionGui extends GuiScreen { 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 diff --git a/src/main/java/me/Danker/gui/aliases/AliasesActionGui.java b/src/main/java/me/Danker/gui/aliases/AliasesActionGui.java new file mode 100644 index 0000000..d2c7a6a --- /dev/null +++ b/src/main/java/me/Danker/gui/aliases/AliasesActionGui.java @@ -0,0 +1,81 @@ +package me.Danker.gui.aliases; + +import me.Danker.features.ChatAliases; +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 AliasesActionGui extends GuiScreen { + + private final int id; + + private GuiButton goBack; + private GuiButton toggle; + private GuiButton edit; + private GuiButton delete; + + public AliasesActionGui(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(); + + ChatAliases.Alias alias = ChatAliases.aliases.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(alias.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 Alias"); + + 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); + + ChatAliases.Alias alias = ChatAliases.aliases.get(id); + + RenderUtils.drawCenteredText(alias.text, width, 10, 1D); + } + + @Override + public void actionPerformed(GuiButton button) { + ChatAliases.Alias alias = ChatAliases.aliases.get(id); + if (button == goBack) { + mc.displayGuiScreen(new AliasesGui(1)); + } else if (button == toggle) { + alias.toggle(); + toggle.displayString = "Enabled: " + Utils.getColouredBoolean(alias.toggled); + } else if (button == edit) { + mc.displayGuiScreen(new AliasesAddGui(alias, id)); + } else if (button == delete) { + ChatAliases.aliases.remove(id); + ChatAliases.save(); + mc.displayGuiScreen(new AliasesGui(1)); + return; + } + ChatAliases.aliases.set(id, alias); + ChatAliases.save(); + } + +} diff --git a/src/main/java/me/Danker/gui/aliases/AliasesAddGui.java b/src/main/java/me/Danker/gui/aliases/AliasesAddGui.java new file mode 100644 index 0000000..610354a --- /dev/null +++ b/src/main/java/me/Danker/gui/aliases/AliasesAddGui.java @@ -0,0 +1,115 @@ +package me.Danker.gui.aliases; + +import me.Danker.features.ChatAliases; +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.IOException; + +public class AliasesAddGui extends GuiScreen { + + private boolean editing; + private ChatAliases.Alias base = null; + private int id; + + private GuiButton cancel; + + private GuiTextField text; + private GuiTextField alias; + private GuiCheckBox toggled; + private GuiButton add; + + public AliasesAddGui() {} + + public AliasesAddGui(ChatAliases.Alias alias, int id) { + editing = true; + base = alias; + 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"); + + + text = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.2), 200, 20); + alias = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.3), 200, 20); + toggled = new GuiCheckBox(0, width / 2 - 26, (int) (height * 0.4), "Toggled", true); + add = new GuiButton(0, width / 2 - 25, (int) (height * 0.8), 50, 20, "Add"); + + if (editing) { + text.setText(base.text); + alias.setText(base.alias); + toggled.setIsChecked(base.toggled); + } + + text.setVisible(true); + text.setEnabled(true); + alias.setVisible(true); + alias.setEnabled(true); + alias.setMaxStringLength(100); + + this.buttonList.add(cancel); + 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); + + text.drawTextBox(); + alias.drawTextBox(); + + new TextRenderer(mc, "Text:", width / 2 - 135, (int) (height * 0.22), 1D); + new TextRenderer(mc, "Alias:", width / 2 - 137, (int) (height * 0.32), 1D); + } + + @Override + public void actionPerformed(GuiButton button) { + if (button == cancel) { + mc.displayGuiScreen(new AliasesGui(1)); + } else if (button == add) { + ChatAliases.Alias newAlias = new ChatAliases.Alias(text.getText(), alias.getText(), toggled.isChecked()); + if (editing) { + ChatAliases.aliases.set(id, newAlias); + } else { + ChatAliases.aliases.add(newAlias); + } + ChatAliases.save(); + mc.displayGuiScreen(new AliasesGui(1)); + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + text.mouseClicked(mouseX, mouseY, mouseButton); + alias.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + super.keyTyped(typedChar, keyCode); + text.textboxKeyTyped(typedChar, keyCode); + alias.textboxKeyTyped(typedChar, keyCode); + } + +} diff --git a/src/main/java/me/Danker/gui/aliases/AliasesGui.java b/src/main/java/me/Danker/gui/aliases/AliasesGui.java new file mode 100644 index 0000000..f5b863a --- /dev/null +++ b/src/main/java/me/Danker/gui/aliases/AliasesGui.java @@ -0,0 +1,108 @@ +package me.Danker.gui.aliases; + +import me.Danker.commands.ToggleCommand; +import me.Danker.features.ChatAliases; +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 AliasesGui 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 aliases; + + public AliasesGui(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 >"); + aliases = new FeatureButton("Aliases: " + Utils.getColouredBoolean(ToggleCommand.aliases), "Replaces text in chat with an alias"); + add = new GuiButton(0, 0, 0, "Add Alias"); + + allButtons.clear(); + allButtons.add(aliases); + allButtons.add(add); + for (int i = 0; i < ChatAliases.aliases.size(); i++) { + ChatAliases.Alias alias = ChatAliases.aliases.get(i); + GuiButton button = new GuiButton(i, 0, 0, alias.text + " >"); + 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 AliasesGui(page + 1)); + } else if (button == backPage) { + mc.displayGuiScreen(new AliasesGui(page - 1)); + } else if (button == add) { + mc.displayGuiScreen(new AliasesAddGui()); + } else if (button == aliases) { + ToggleCommand.aliases = !ToggleCommand.aliases; + ConfigHandler.writeBooleanConfig("toggles", "Aliases", ToggleCommand.aliases); + aliases.displayString = "Aliases: " + Utils.getColouredBoolean(ToggleCommand.aliases); + } else { + mc.displayGuiScreen(new AliasesActionGui(button.id)); + } + } + +} |