From e2afdd744942da2a4272a97752eef5367f0b0774 Mon Sep 17 00:00:00 2001 From: boomboompower Date: Fri, 6 Mar 2020 21:43:30 +1100 Subject: [PATCH] Cleanup old code #4 --- gradlew | 34 +- .../skinchanger/SkinChangerModOld.java | 5 +- .../skinchanger/gui/ExperimentalGui.java | 29 +- .../skinchanger/gui/SettingsGui.java | 55 +- .../GuiExperimentalAllPlayers.java | 22 +- .../experimental/GuiExperimentalOptifine.java | 18 +- .../skinchanger/gui/utils/ModernButton.java | 158 ---- .../skinchanger/gui/utils/ModernGui.java | 219 ------ .../skinchanger/gui/utils/ModernTextBox.java | 733 ------------------ .../skinchanger/run/JavaMain.java | 43 - .../boomboompower/skinchanger/run/RunGui.java | 105 --- .../skinchanger/utils/ChatColor.java | 108 --- .../skinchanger/utils/gui/UISkeleton.java | 70 +- .../skinchanger/utils/gui/impl/ModernGui.java | 11 +- .../skinchanger/utils/gui/lock/UILock.java | 2 +- .../utils/updater/WebsiteUtils.java | 13 +- 16 files changed, 152 insertions(+), 1473 deletions(-) delete mode 100644 src/main/java/me/boomboompower/skinchanger/gui/utils/ModernButton.java delete mode 100644 src/main/java/me/boomboompower/skinchanger/gui/utils/ModernGui.java delete mode 100644 src/main/java/me/boomboompower/skinchanger/gui/utils/ModernTextBox.java delete mode 100644 src/main/java/me/boomboompower/skinchanger/run/JavaMain.java delete mode 100644 src/main/java/me/boomboompower/skinchanger/run/RunGui.java delete mode 100644 src/main/java/me/boomboompower/skinchanger/utils/ChatColor.java diff --git a/gradlew b/gradlew index 91a7e26..bd03f91 100644 --- a/gradlew +++ b/gradlew @@ -44,14 +44,14 @@ esac # For Cygwin, ensure paths are in UNIX format before anything is touched. if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [[ -n "$JAVA_HOME" ]] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` fi # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. -while [ -h "$PRG" ] ; do +while [[ -h "$PRG" ]] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then @@ -65,17 +65,17 @@ cd "`dirname \"$PRG\"`/" >&- APP_HOME="`pwd -P`" cd "$SAVED" >&- -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH=${APP_HOME}/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +if [[ -n "$JAVA_HOME" ]] ; then + if [[ -x "$JAVA_HOME/jre/sh/java" ]] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi - if [ ! -x "$JAVACMD" ] ; then + if [[ ! -x "$JAVACMD" ]] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the @@ -90,14 +90,14 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [[ "$cygwin" = "false" && "$darwin" = "false" ]] ; then MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + if [[ $? -eq 0 ]] ; then + if [[ "$MAX_FD" = "maximum" || "$MAX_FD" = "max" ]] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then + if [[ $? -ne 0 ]] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else @@ -106,7 +106,7 @@ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then fi # For Darwin, add options to specify how the application appears in the dock -if $darwin; then +if ${darwin}; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi @@ -118,13 +118,13 @@ if $cygwin ; then # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" - for dir in $ROOTDIRSRAW ; do + for dir in ${ROOTDIRSRAW} ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then + if [[ "$GRADLE_CYGPATTERN" != "" ]] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh @@ -133,10 +133,10 @@ if $cygwin ; then CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + if [[ ${CHECK} -ne 0 ]] && [[ ${CHECK2} -eq 0 ]] ; then ### Added a condition + eval `echo args${i}` = `cygpath --path --ignore --mixed "$arg"` else - eval `echo args$i`="\"$arg\"" + eval `echo args${i}` = "\"$arg\"" fi i=$((i+1)) done @@ -158,7 +158,7 @@ fi function splitJvmOpts() { JVM_OPTS=("$@") } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +eval splitJvmOpts ${DEFAULT_JVM_OPTS} ${JAVA_OPTS} ${GRADLE_OPTS} JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/src/main/java/me/boomboompower/skinchanger/SkinChangerModOld.java b/src/main/java/me/boomboompower/skinchanger/SkinChangerModOld.java index fdb9b71..ae757cc 100644 --- a/src/main/java/me/boomboompower/skinchanger/SkinChangerModOld.java +++ b/src/main/java/me/boomboompower/skinchanger/SkinChangerModOld.java @@ -17,6 +17,7 @@ package me.boomboompower.skinchanger; +import java.util.Random; import me.boomboompower.skinchanger.utils.models.capes.CapeManager; import me.boomboompower.skinchanger.config.ConfigLoader; import me.boomboompower.skinchanger.utils.models.skins.SkinManager; @@ -79,13 +80,13 @@ public ConfigLoader getLoader() { } public static SkinChangerModOld getInstance() { - return null; + return new SkinChangerModOld(); } public void setRenderingEnabled(boolean toggledIn) { } public boolean isRenderingEnabled() { - return false; + return new Random().nextBoolean(); } } diff --git a/src/main/java/me/boomboompower/skinchanger/gui/ExperimentalGui.java b/src/main/java/me/boomboompower/skinchanger/gui/ExperimentalGui.java index 244a587..04130ac 100644 --- a/src/main/java/me/boomboompower/skinchanger/gui/ExperimentalGui.java +++ b/src/main/java/me/boomboompower/skinchanger/gui/ExperimentalGui.java @@ -20,10 +20,10 @@ import me.boomboompower.skinchanger.SkinChangerModOld; import me.boomboompower.skinchanger.gui.experimental.GuiExperimentalAllPlayers; import me.boomboompower.skinchanger.gui.experimental.GuiExperimentalOptifine; -import me.boomboompower.skinchanger.gui.utils.ModernButton; -import me.boomboompower.skinchanger.gui.utils.ModernGui; -import me.boomboompower.skinchanger.utils.ChatColor; +import me.do_you_like.mods.skinchanger.utils.game.ChatColor; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernButton; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernGui; import org.apache.commons.io.FileUtils; import java.awt.*; @@ -31,6 +31,15 @@ import java.util.Arrays; public class ExperimentalGui extends ModernGui { + + + + + + + + + private final SkinChangerModOld mod; @@ -39,32 +48,32 @@ public class ExperimentalGui extends ModernGui { public ExperimentalGui(SkinChangerModOld mod) { this.mod = mod; } - + @Override - public void initGui() { + public void onGuiOpen() { this.buttonList.add(new ModernButton(0, this.width / 2 - 75, this.height / 2 - 22, 150, 20, - "Rending: " + (SkinChangerModOld.getInstance().isRenderingEnabled() ? ChatColor.GREEN + "On" : ChatColor.GRAY + "Off"))); + "Rending: " + (SkinChangerModOld.getInstance().isRenderingEnabled() ? ChatColor.GREEN + "On" : ChatColor.GRAY + "Off"))); this.buttonList.add(new ModernButton(1, this.width / 2 - 75, this.height / 2 + 2, 150, 20, "All player utils")); this.buttonList.add(new ModernButton(2, this.width / 2 - 75, this.height / 2 + 26, 150, 20, "Optifine utils")); this.buttonList.add(this.skinCache = new ModernButton(3, this.width / 2 - 75, this.height / 2 + 50, 150, 20, "Delete skin cache")); - this.skinCache.setBackEnabled(new Color(255, 0, 0, 75)); + this.skinCache.setEnabledColor(new Color(255, 0, 0, 75)); } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { + public void onRender(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); super.drawScreen(mouseX, mouseY, partialTicks); - if (this.skinCache.isMouseOver()) { + if (this.skinCache.isHovered()) { drawHoveringText(Arrays.asList("This button is dangerous and", ChatColor.DARK_RED.toString() + ChatColor.BOLD + "may" + ChatColor.RESET + " be bad for your game"), mouseX, mouseY); } } @Override public void buttonPressed(ModernButton button) { - switch (button.id) { + switch (button.getId()) { case 0: SkinChangerModOld .getInstance().setRenderingEnabled(!SkinChangerModOld.getInstance().isRenderingEnabled()); diff --git a/src/main/java/me/boomboompower/skinchanger/gui/SettingsGui.java b/src/main/java/me/boomboompower/skinchanger/gui/SettingsGui.java index 0a5f707..c64ec9d 100644 --- a/src/main/java/me/boomboompower/skinchanger/gui/SettingsGui.java +++ b/src/main/java/me/boomboompower/skinchanger/gui/SettingsGui.java @@ -19,12 +19,12 @@ import me.boomboompower.skinchanger.SkinChangerModOld; import me.boomboompower.skinchanger.utils.fake.FakePlayer; -import me.boomboompower.skinchanger.gui.utils.ModernButton; -import me.boomboompower.skinchanger.gui.utils.ModernGui; -import me.boomboompower.skinchanger.gui.utils.ModernTextBox; -import me.boomboompower.skinchanger.utils.ChatColor; import me.boomboompower.skinchanger.utils.models.skins.PlayerSkinType; +import me.do_you_like.mods.skinchanger.utils.game.ChatColor; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernButton; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernGui; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernTextBox; import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; @@ -59,7 +59,7 @@ public SettingsGui(SkinChangerModOld modIn, String message) { } @Override - public void initGui() { + public void onGuiOpen() { Keyboard.enableRepeatEvents(true); this.textList.add(textField = new ModernTextBox(0, this.width / 2 - 150, this.height / 2 - 22, 300, 20)); @@ -80,7 +80,7 @@ public void initGui() { } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { + public void onRender(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); this.fontRendererObj.drawString("Skin Settings", this.width / 2 - 118, this.height / 2 + 8, Color.WHITE.getRGB(), false); @@ -95,7 +95,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { } if (this.previewCape) { - drawCenteredString(this.mc.fontRendererObj,ChatColor.WHITE + "Hold Left-Alt to flip the cape!", this.width / 2, this.height / 2 + 100, Color.WHITE.getRGB()); + drawCenteredString(this.mc.fontRendererObj, ChatColor.WHITE + "Hold Left-Alt to flip the cape!", this.width / 2, this.height / 2 + 100, Color.WHITE.getRGB()); } super.drawScreen(mouseX, mouseY, partialTicks); @@ -103,34 +103,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { @Override public void buttonPressed(ModernButton button) { - if (button.id == 8) { - System.out.println(String.format("Current index: %s / %s", this.mod.getSkinManager().getSkinType().ordinal(), PlayerSkinType.values().length)); - - this.mod.getSkinManager().setSkinType(this.mod.getSkinManager().getSkinType().getNextSkin()); - - PlayerSkinType type = this.mod.getSkinManager().getSkinType(); - button.setText("Skin Type: " + type.getDisplayName()); - - return; - } - -// if (!textField.getText().isEmpty()) { -// this.mod.getWebsiteUtils().runAsync(() -> { -// if (button.id == 1) { -// String id = this.mod.getMojangHooker().getIdFromUsername(textField.getText()); -// -// textField.setText(this.mod.getMojangHooker().hasSlimSkin(id) + ""); -// } else if (button.id == 2) { -// String id = this.mod.getMojangHooker().getIdFromUsername(textField.getText()); -// -// textField.setText(this.mod.getMojangHooker().getIdFromUsername(id)); -// } else if (button.id == 3) { -// fakePlayer.getPlayerInfo().setLocationCape(this.mod.getMojangHooker().getSkinFromId(this.mod.getMojangHooker().getIdFromUsername("boomboompower"))); -// } -// }); -// } - - switch (button.id) { + switch (button.getId()) { case 1: this.previewCape = false; fakePlayer.getPlayerInfo().setLocationCape(null); @@ -177,13 +150,23 @@ public void buttonPressed(ModernButton button) { break; case 7: this.mc.displayGuiScreen(new ExperimentalGui(this.mod)); + break; + case 8: + System.out.println(String.format("Current index: %s / %s", this.mod.getSkinManager().getSkinType().ordinal(), PlayerSkinType.values().length)); + + this.mod.getSkinManager().setSkinType(this.mod.getSkinManager().getSkinType().getNextSkin()); + + PlayerSkinType type = this.mod.getSkinManager().getSkinType(); + button.setText("Skin Type: " + type.getDisplayName()); + break; } } @Override - public void onGuiClosed() { + public void onGuiClose() { Keyboard.enableRepeatEvents(false); + this.mod.getLoader().save(); } } diff --git a/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalAllPlayers.java b/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalAllPlayers.java index 805bd7f..e97d5c3 100644 --- a/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalAllPlayers.java +++ b/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalAllPlayers.java @@ -18,13 +18,13 @@ package me.boomboompower.skinchanger.gui.experimental; import me.boomboompower.skinchanger.SkinChangerModOld; -import me.boomboompower.skinchanger.gui.utils.ModernButton; -import me.boomboompower.skinchanger.gui.utils.ModernGui; -import me.boomboompower.skinchanger.gui.utils.ModernTextBox; -import me.boomboompower.skinchanger.utils.ChatColor; import me.do_you_like.mods.skinchanger.methods.impl.mixins.SkinChangerTweaker; +import me.do_you_like.mods.skinchanger.utils.game.ChatColor; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernButton; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernGui; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernTextBox; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityOtherPlayerMP; import net.minecraft.entity.Entity; @@ -50,9 +50,9 @@ public class GuiExperimentalAllPlayers extends ModernGui { public GuiExperimentalAllPlayers(SkinChangerModOld theMod) { this.mod = theMod; } - + @Override - public void initGui() { + public void onGuiOpen() { Keyboard.enableRepeatEvents(true); this.textList.add(this.textField = new ModernTextBox(0, this.width / 2 - 150, this.height / 2 - 22, 300, 20)); @@ -60,23 +60,23 @@ public void initGui() { this.buttonList.add(new ModernButton(0, this.width / 2 - 75, this.height / 2 + 26, 150, 20, "Give skin to everyone")); this.buttonList.add(this.resetButton = new ModernButton(2, this.width / 2 - 75, this.height / 2 + 74, 150, 20, "Reset all skins")); - this.resetButton.setBackEnabled(new Color(255, 0, 0, 75)); + this.resetButton.setEnabledColor(new Color(255, 0, 0, 75)); } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { + public void onRender(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); super.drawScreen(mouseX, mouseY, partialTicks); - if (this.resetButton.isMouseOver()) { + if (this.resetButton.isHovered()) { drawHoveringText(Arrays.asList("This button is dangerous and", ChatColor.DARK_RED.toString() + ChatColor.BOLD + "may" + ChatColor.RESET + " be bad for your game"), mouseX, mouseY); } } @Override public void buttonPressed(ModernButton button) { - switch (button.id) { + switch (button.getId()) { case 0: if (SkinChangerTweaker.MIXINS_ENABLED) { forcedAllSkins = this.mod.getSkinManager().getSkin(this.textField.getText()); @@ -108,7 +108,7 @@ public void buttonPressed(ModernButton button) { } @Override - public void onGuiClosed() { + public void onGuiClose() { Keyboard.enableRepeatEvents(false); SkinChangerModOld.getInstance().getLoader().save(); } diff --git a/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalOptifine.java b/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalOptifine.java index bcc3347..79c590f 100644 --- a/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalOptifine.java +++ b/src/main/java/me/boomboompower/skinchanger/gui/experimental/GuiExperimentalOptifine.java @@ -20,11 +20,11 @@ import me.boomboompower.skinchanger.SkinChangerModOld; import me.boomboompower.skinchanger.utils.models.capes.CapeManager; import me.boomboompower.skinchanger.utils.fake.FakePlayer; -import me.boomboompower.skinchanger.gui.utils.ModernButton; -import me.boomboompower.skinchanger.gui.utils.ModernGui; -import me.boomboompower.skinchanger.gui.utils.ModernTextBox; -import me.boomboompower.skinchanger.utils.ChatColor; +import me.do_you_like.mods.skinchanger.utils.game.ChatColor; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernButton; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernGui; +import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernTextBox; import org.lwjgl.input.Keyboard; import java.awt.*; @@ -41,7 +41,7 @@ public GuiExperimentalOptifine() { } @Override - public void initGui() { + public void onGuiOpen() { Keyboard.enableRepeatEvents(true); this.textList.add(this.textField = new ModernTextBox(0, this.width / 2 - 150, this.height / 2 - 22, 300, 20)); @@ -52,21 +52,21 @@ public void initGui() { } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { + public void onRender(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); drawCenteredString(this.mc.fontRendererObj,"Names are case sensitive! Ensure you are using the correct name", this.width / 2, this.height / 2 + 8, Color.WHITE.getRGB()); drawEntityOnScreen(this.width / 2, this.height / 2 - 45, 35, this.width / 2 - mouseX, (this.height / 2 - 90) - mouseY, this.fakePlayer, true); - drawCenteredString(this.mc.fontRendererObj,ChatColor.WHITE + "Hold Left-Alt to flip the cape!", this.width / 2, this.height / 2 + 100, Color.WHITE.getRGB()); + drawCenteredString(this.mc.fontRendererObj, ChatColor.WHITE + "Hold Left-Alt to flip the cape!", this.width / 2, this.height / 2 + 100, Color.WHITE.getRGB()); super.drawScreen(mouseX, mouseY, partialTicks); } @Override public void buttonPressed(ModernButton button) { - switch (button.id) { + switch (button.getId()) { case 0: //this.fakePlayer.getPlayerInfo().setLocationCape(); @@ -91,7 +91,7 @@ public void buttonPressed(ModernButton button) { } @Override - public void onGuiClosed() { + public void onGuiClose() { Keyboard.enableRepeatEvents(false); SkinChangerModOld.getInstance().getLoader().save(); } diff --git a/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernButton.java b/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernButton.java deleted file mode 100644 index 2a6c296..0000000 --- a/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernButton.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2020 boomboompower - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package me.boomboompower.skinchanger.gui.utils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.audio.SoundHandler; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.ResourceLocation; - -import java.awt.*; - -public class ModernButton extends GuiButton { - - private Color backgroundColorEnabled = null; - private Color backgroundColorDisabled = null; - - public int id; - public int width; - public int height; - public int xPosition; - public int yPosition; - public boolean enabled; - public boolean visible; - public boolean hovered; - public String displayString; - - public ModernButton(int buttonId, int x, int y, String buttonText) - { - this(buttonId, x, y, 200, 20, buttonText); - } - - public ModernButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) { - super(buttonId, x, y, widthIn, heightIn, buttonText != null ? buttonText : ""); - this.width = 200; - this.height = 20; - this.enabled = true; - this.visible = true; - this.id = buttonId; - this.xPosition = x; - this.yPosition = y; - this.width = widthIn; - this.height = heightIn; - this.displayString = buttonText != null ? buttonText : ""; - } - - /** - * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over - * this button. - */ - @Override - protected int getHoverState(boolean mouseOver) { - int i = 1; - - if (!this.enabled) { - i = 0; - } else if (mouseOver) { - i = 2; - } - return i; - } - - /** - * Draws this button to the screen. - */ - @Override - public void drawButton(Minecraft mc, int mouseX, int mouseY) { - if (this.visible) { - FontRenderer fontrenderer = mc.fontRendererObj; - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; - int i = this.getHoverState(this.hovered); - - if (this.enabled) { - drawRect(this.xPosition, this.yPosition, this.xPosition + width, this.yPosition + height, this.backgroundColorEnabled == null ? new Color(255, 255, 255, 75).getRGB() : this.backgroundColorEnabled.getRGB()); - } else { - drawRect(this.xPosition, this.yPosition, this.xPosition + width, this.yPosition + height, this.backgroundColorDisabled == null ? new Color(100, 100, 100, 75).getRGB() : this.backgroundColorDisabled.getRGB()); - } - - this.mouseDragged(mc, mouseX, mouseY); - int j = 14737632; - - if (!this.enabled) { - j = Color.WHITE.getRGB(); - } else if (this.hovered) { - j = 16777120; - } - fontrenderer.drawString(this.displayString, (this.xPosition + this.width / 2 - fontrenderer.getStringWidth(this.displayString) / 2), this.yPosition + (this.height - 8) / 2, j, false); - } - } - - /** - * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent - * e). - */ - @Override - public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { - return this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; - } - - /** - * Whether the mouse cursor is currently over the button. - */ - @Override - public boolean isMouseOver() { - return this.hovered; - } - - @Override - public void playPressSound(SoundHandler soundHandlerIn) { - soundHandlerIn.playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); - } - - @Override - public int getButtonWidth() - { - return this.width; - } - - @Override - public void setWidth(int width) - { - this.width = width; - } - - public String getText() { - return this.displayString; - } - - public void setText(String text) { - this.displayString = text != null ? text : ""; - } - - public void setBackEnabled(Color color) { - this.backgroundColorEnabled = color; - } - - public void setBackDisabled(Color color) { - this.backgroundColorDisabled = color; - } -} \ No newline at end of file diff --git a/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernGui.java b/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernGui.java deleted file mode 100644 index ca6c8de..0000000 --- a/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernGui.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) 2020 boomboompower - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package me.boomboompower.skinchanger.gui.utils; - -import com.google.common.collect.Lists; - -import java.awt.Color; - -import me.boomboompower.skinchanger.utils.ChatColor; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.*; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.entity.EntityLivingBase; - -import java.util.List; -import net.minecraft.util.ChatComponentText; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -/** - * ModernGui, a better-looking GuiScreen which has more optimizations and features than the normal GuiScreen - * - * @author boomboompower - * @version 3.1 - */ -public abstract class ModernGui extends GuiScreen { - - protected final Minecraft mc = Minecraft.getMinecraft(); - - protected List textList = Lists.newArrayList(); - - private GuiButton selectedButton; - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - for (GuiButton button : this.buttonList) { - button.drawButton(this.mc, mouseX, mouseY); - } - - for (GuiLabel label : this.labelList) { - label.drawLabel(this.mc, mouseX, mouseY); - } - - for (ModernTextBox text : this.textList) { - text.drawTextBox(); - } - } - - @Override - protected void keyTyped(char typedChar, int keyCode) { - if (keyCode == 1) { - this.mc.displayGuiScreen(null); - - if (this.mc.currentScreen == null) { - this.mc.setIngameFocus(); - } - } else { - for (ModernTextBox text : textList) { - text.textboxKeyTyped(typedChar, keyCode); - } - } - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { - if (mouseButton == 0) { - for (int i = 0; i < this.buttonList.size(); ++i) { - GuiButton guibutton = this.buttonList.get(i); - - if (guibutton.mousePressed(this.mc, mouseX, mouseY)) { - net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Pre event = new net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList); - if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) break; - guibutton = event.button; - this.selectedButton = guibutton; - guibutton.playPressSound(this.mc.getSoundHandler()); - this.actionPerformed(guibutton); - if (this.equals(this.mc.currentScreen)) - net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList)); - } - } - } - - // Renders all textboxes - for (ModernTextBox text : this.textList) { - text.mouseClicked(mouseX, mouseY, mouseButton); - } - } - - @Override - protected void mouseReleased(int mouseX, int mouseY, int state) { - if (this.selectedButton != null && state == 0) { - this.selectedButton.mouseReleased(mouseX, mouseY); - this.selectedButton = null; - } - } - - @Override - public void drawDefaultBackground() { - Gui.drawRect(0, 0, this.width, this.height, new Color(2, 2, 2, 120).getRGB()); - } - - @Override - public void drawCenteredString(FontRenderer fontRendererIn, String text, int x, int y, int color) { - fontRendererIn.drawString(text, (float) (x - fontRendererIn.getStringWidth(text) / 2), (float) y, color, false); - } - - public void drawCenteredString(FontRenderer fontRendererIn, String text, int x, int y, int color, boolean shadow) { - fontRendererIn.drawString(text, (float) (x - fontRendererIn.getStringWidth(text) / 2), (float) y, color, shadow); - } - - @Override - public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color) { - fontRendererIn.drawString(text, (float) x, (float) y, color, false); - } - - @Override - public boolean doesGuiPauseGame() { - return false; - } - - @Override - protected void actionPerformed(GuiButton button) { - if (button instanceof ModernButton) { - buttonPressed((ModernButton) button); - } - } - - @Override - public void sendChatMessage(String msg) { - this.mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(ChatColor.AQUA + "SkinChanger" + ChatColor.GOLD + " > " + ChatColor.GRAY + msg)); - } - - public final void display() { - MinecraftForge.EVENT_BUS.register(this); - } - - @SubscribeEvent - public final void onTick(TickEvent.ClientTickEvent event) { - MinecraftForge.EVENT_BUS.unregister(this); - Minecraft.getMinecraft().displayGuiScreen(this); - } - - public void buttonPressed(ModernButton button) { - } - - /** - * Code used to draw an entity on screen, stolen from the Inventory code - * - * @param posX the x position of the entity - * @param posY the y position of the entity - * @param scale the scale the entity should be rendered at - * @param mouseX the x location of the mouse - * @param mouseY the y location of the mouse - * @param entity the entity to render on screen - * @param previewCape true if the entities cape is being previewed - */ - protected void drawEntityOnScreen(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase entity, boolean previewCape) { - GlStateManager.enableColorMaterial(); - GlStateManager.pushMatrix(); - GlStateManager.translate((float) posX, (float) posY, 50.0F); - GlStateManager.scale((float) (-scale), (float) scale, (float) scale); - GlStateManager.rotate(180.0F, 0.0F, 0.0F , 1.0F); - if (previewCape) { - GlStateManager.rotate(180F, 0F, 360F, 0F); - } - float prevYawOffset = entity.renderYawOffset; - float prevYaw = entity.rotationYaw; - float prevPitch = entity.rotationPitch; - float prevYawRotation = entity.prevRotationYawHead; - float prevHeadRotation = entity.rotationYawHead; - GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); - RenderHelper.enableStandardItemLighting(); - GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(-((float) Math.atan((double) (mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); - entity.renderYawOffset = previewCape ? -(float) Math.atan((double) (mouseX / 40.0F)) * 20.0F : (float) Math.atan((double) (mouseX / 40.0F)) * 20.0F; - entity.rotationYaw = previewCape ? -(float) Math.atan((double) (mouseX / 40.0F)) * 40.0F : (float) Math.atan((double) (mouseX / 40.0F)) * 40.0F; - entity.rotationPitch = -((float) Math.atan((double) (mouseY / 40.0F))) * 20.0F; - entity.rotationYawHead = entity.rotationYaw; - entity.prevRotationYawHead = entity.rotationYaw; - GlStateManager.translate(0.0F, 0.0F, 0.0F); - RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); - rendermanager.setPlayerViewY(previewCape ? 180.0F : 0.0F); - rendermanager.setRenderShadow(false); - rendermanager.doRenderEntity(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, true); - rendermanager.setRenderShadow(true); - entity.renderYawOffset = prevYawOffset; - entity.rotationYaw = prevYaw; - entity.rotationPitch = prevPitch; - entity.prevRotationYawHead = prevYawRotation; - entity.rotationYawHead = prevHeadRotation; - - GlStateManager.popMatrix(); - RenderHelper.disableStandardItemLighting(); - GlStateManager.disableRescaleNormal(); - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - GlStateManager.disableTexture2D(); - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); - } -} diff --git a/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernTextBox.java b/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernTextBox.java deleted file mode 100644 index cd474f1..0000000 --- a/src/main/java/me/boomboompower/skinchanger/gui/utils/ModernTextBox.java +++ /dev/null @@ -1,733 +0,0 @@ -/* - * Copyright (C) 2020 boomboompower - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package me.boomboompower.skinchanger.gui.utils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiPageButtonList; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.util.ChatAllowedCharacters; -import net.minecraft.util.MathHelper; - -import java.awt.*; -import java.util.Timer; -import java.util.TimerTask; - -public class ModernTextBox extends Gui { - - private String alertMessage = ""; - - private final int id; - private final FontRenderer fontRendererInstance; - public int xPosition; - public int yPosition; - /** The width of this text field. */ - public int width; - public int height; - /** Has the current text being edited on the textbox. */ - private String text = ""; - private int maxStringLength = 16; - private int cursorCounter; - private boolean enableBackgroundDrawing = true; - /** if true the textbox can lose focus by clicking elsewhere on the screen */ - private boolean canLoseFocus = true; - /** If this value is true along with isEnabled, keyTyped will process the keys. */ - private boolean isFocused = false; - /** If this value is true along with isFocused, keyTyped will process the keys. */ - private boolean isEnabled = true; - /** The current character index that should be used as start of the rendered text. */ - private int lineScrollOffset; - private int cursorPosition; - /** other selection position, maybe the same as the cursor */ - private int selectionEnd; - private int enabledColor = 14737632; - private int disabledColor = 7368816; - /** True if this textbox is visible */ - private boolean visible = true; - private GuiPageButtonList.GuiResponder guiResponder; - - private boolean onlyAllowNumbers = false; - private String noTextMessage = "Write here!"; - - private boolean running = false; - - public ModernTextBox(int componentId, int x, int y, int width, int height) { - this(componentId, x, y, width, height, false); - } - - public ModernTextBox(int componentId, int x, int y, int width, int height, boolean onlyAllowNumbers) { - this(componentId, x, y, width, height, "Write Here!", onlyAllowNumbers); - } - - public ModernTextBox(int componentId, int x, int y, int width, int height, String noTextMessage, boolean onlyAllowNumbers) { - this.id = componentId; - this.fontRendererInstance = Minecraft.getMinecraft().fontRendererObj; - this.xPosition = x; - this.yPosition = y; - this.width = width; - this.height = height; - this.noTextMessage = noTextMessage; - this.onlyAllowNumbers = onlyAllowNumbers; - } - - public void setGuiResponder(GuiPageButtonList.GuiResponder guiResponder) { - this.guiResponder = guiResponder; - } - - /** - * Increments the cursor counter - */ - public void updateCursorCounter() { - ++this.cursorCounter; - } - - /** - * Sets the text of the textbox - */ - public void setText(String text) { - if (text == null) { - this.text = ""; - this.setCursorPositionEnd(); - return; - } - - if (format(text).length() > this.maxStringLength) { - this.text = format(text).substring(0, this.maxStringLength); - } else { - this.text = format(text); - } - this.setCursorPositionEnd(); - } - - /** - * Returns the contents of the textbox - */ - public String getText() { - return this.text; - } - - /** - * returns the text between the cursor and selectionEnd - */ - public String getSelectedText() { - int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition: this.selectionEnd; - int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd: this.cursorPosition; - return this.text.substring(i, j); - } - - /** - * replaces selected text, or inserts text at the position on the cursor - */ - public void writeText(String text) { - String s = ""; - String s1 = ChatAllowedCharacters.filterAllowedCharacters(text); - int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition: this.selectionEnd; - int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd: this.cursorPosition; - int k = this.maxStringLength - this.text.length() - (i - j); - int l; - - if (this.text.length() > 0) { - s = s + this.text.substring(0, i); - } - - if (k < s1.length()) { - s = s + s1.substring(0, k); - l = k; - } else { - s = s + s1; - l = s1.length(); - } - - if (this.text.length() > 0 && j < this.text.length()) { - s = s + this.text.substring(j); - } - - this.text = s; - this.moveCursorBy(i - this.selectionEnd + l); - - if (this.guiResponder != null) { - this.guiResponder.func_175319_a(this.id, this.text); - } - } - - /** - * Deletes the specified number of words starting at the cursor position. Negative numbers will delete words left of - * the cursor. - */ - public void deleteWords(int words) { - if (this.text.length() != 0) { - if (this.selectionEnd != this.cursorPosition) { - this.writeText(""); - } else { - this.deleteFromCursor(this.getNthWordFromCursor(words) - this.cursorPosition); - } - } - } - - /** - * delete the selected text, otherwsie deletes characters from either side of the cursor. params: delete num - */ - public void deleteFromCursor(int num) { - if (this.text.length() != 0) { - if (this.selectionEnd != this.cursorPosition) { - this.writeText(""); - } else { - boolean flag = num < 0; - int i = flag ? this.cursorPosition + num: this.cursorPosition; - int j = flag ? this.cursorPosition: this.cursorPosition + num; - String s = ""; - - if (i >= 0) { - s = this.text.substring(0, i); - } - - if (j < this.text.length()) { - s = s + this.text.substring(j); - } - - this.text = s; - - if (flag) { - this.moveCursorBy(num); - } - - if (this.guiResponder != null) { - this.guiResponder.func_175319_a(this.id, this.text); - } - } - } - } - - public int getId() { - return this.id; - } - - /** - * see @getNthNextWordFromPos() params: N, position - */ - public int getNthWordFromCursor(int position) { - return this.getNthWordFromPos(position, this.getCursorPosition()); - } - - /** - * gets the position of the nth word. N may be negative, then it looks backwards. params: N, position - */ - public int getNthWordFromPos(int number, int position) { - return this.getNthWordFromPos(number, position, true); - } - - public int getNthWordFromPos(int number, int position, boolean something) { - int i = position; - boolean flag = number < 0; - int j = Math.abs(number); - - for (int k = 0; k < j; ++k) { - if (!flag) { - int l = this.text.length(); - i = this.text.indexOf(32, i); - - if (i == -1) { - i = l; - } else { - while (something && i < l && this.text.charAt(i) == 32) { - ++i; - } - } - } else { - while (something && i > 0 && this.text.charAt(i -1) == 32) { - --i; - } - - while (i > 0 && this.text.charAt(i -1) != 32) { - --i; - } - } - } - - return i; - } - - /** - * Moves the text cursor by a specified number of characters and clears the selection - */ - public void moveCursorBy(int moveBy) { - this.setCursorPosition(this.selectionEnd + moveBy); - } - - /** - * sets the position of the cursor to the provided index - */ - public void setCursorPosition(int position) { - this.cursorPosition = position; - int i = this.text.length(); - this.cursorPosition = MathHelper.clamp_int(this.cursorPosition, 0, i); - this.setSelectionPos(this.cursorPosition); - } - - /** - * sets the cursors position to the beginning - */ - public void setCursorPositionZero() { - this.setCursorPosition(0); - } - - /** - * sets the cursors position to after the text - */ - public void setCursorPositionEnd() { - this.setCursorPosition(this.text.length()); - } - - /** - * Call this method from your GuiScreen to process the keys into the textbox - */ - public boolean textboxKeyTyped(char c, int keyCode) { - if (!this.isFocused || this.running) { - return false; - } else if (GuiScreen.isKeyComboCtrlA(keyCode)) { - this.setCursorPositionEnd(); - this.setSelectionPos(0); - return true; - } else if (GuiScreen.isKeyComboCtrlC(keyCode)) { - GuiScreen.setClipboardString(this.getSelectedText()); - return true; - } else if (GuiScreen.isKeyComboCtrlV(keyCode)) { - if (this.isEnabled) { - this.writeText(format(GuiScreen.getClipboardString())); - } - - return true; - } else if (GuiScreen.isKeyComboCtrlX(keyCode)) { - GuiScreen.setClipboardString(this.getSelectedText()); - - if (this.isEnabled) { - this.writeText(""); - } - return true; - } else { - switch (keyCode) { - case 14: - if (GuiScreen.isCtrlKeyDown()) { - if (this.isEnabled) { - this.deleteWords( -1); - } - } - else if (this.isEnabled) { - this.deleteFromCursor( -1); - } - - return true; - case 199: - if (GuiScreen.isShiftKeyDown()) { - this.setSelectionPos(0); - } else { - this.setCursorPositionZero(); - } - return true; - case 203: - if (GuiScreen.isShiftKeyDown()) { - if (GuiScreen.isCtrlKeyDown()) { - this.setSelectionPos(this.getNthWordFromPos( -1, this.getSelectionEnd())); - } - else { - this.setSelectionPos(this.getSelectionEnd() -1); - } - } - else if (GuiScreen.isCtrlKeyDown()) { - this.setCursorPosition(this.getNthWordFromCursor( -1)); - } - else { - this.moveCursorBy( -1); - } - - return true; - case 205: - if (GuiScreen.isShiftKeyDown()) { - if (GuiScreen.isCtrlKeyDown()) { - this.setSelectionPos(this.getNthWordFromPos(1, this.getSelectionEnd())); - } else { - this.setSelectionPos(this.getSelectionEnd() + 1); - } - } else if (GuiScreen.isCtrlKeyDown()) { - this.setCursorPosition(this.getNthWordFromCursor(1)); - } else { - this.moveCursorBy(1); - } - return true; - case 207: - if (GuiScreen.isShiftKeyDown()) { - this.setSelectionPos(this.text.length()); - } else { - this.setCursorPositionEnd(); - } - return true; - case 211: - if (GuiScreen.isCtrlKeyDown()) { - if (this.isEnabled) { - this.deleteWords(1); - } - } else if (this.isEnabled) { - this.deleteFromCursor(1); - } - return true; - default: - if (ChatAllowedCharacters.isAllowedCharacter(c)) { - if (onlyAllowNumbers) { - if (Character.isDigit(c)) { - if (this.isEnabled) { - this.writeText(Character.toString(c)); - } - } else if (!running) { - alert("Only numbers can be used!", 1250); - } - } else { - if (this.isEnabled) { - this.writeText(Character.toString(c)); - } - } - return true; - } else { - return false; - } - } - } - } - - /** - * Args: x, y, buttonClicked - */ - public void mouseClicked(int x, int y, int buttonClicked) { - boolean flag = x >= this.xPosition && x < this.xPosition + this.width && y >= this.yPosition && y < this.yPosition + this.height; - - if (this.canLoseFocus && this.isEnabled && !this.running) { - this.setFocused(flag); - } - - if (this.isFocused && flag && buttonClicked == 0) { - int i = x - this.xPosition; - - if (this.enableBackgroundDrawing) { - i -= 4; - } - - String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth()); - this.setCursorPosition(this.fontRendererInstance.trimStringToWidth(s, i).length() + this.lineScrollOffset); - } - } - - /** - * Draws the textbox - */ - public void drawTextBox() { - if (this.getVisible()) { - if (this.getEnableBackgroundDrawing()) { - if (this.isEnabled) { - drawRect(this.xPosition, this.yPosition, this.xPosition + width, this.yPosition + height, new Color(0, 148, 255, 75).getRGB()); - } else { - drawRect(this.xPosition, this.yPosition, this.xPosition + width, this.yPosition + height, new Color(0, 125, 215, 75).getRGB()); - } - } - - int i = this.isEnabled ? this.enabledColor : this.disabledColor; - int j = this.cursorPosition - this.lineScrollOffset; - int k = this.selectionEnd - this.lineScrollOffset; - String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth()); - boolean flag = j >= 0 && j <= s.length(); - boolean flag1 = this.isFocused && this.cursorCounter / 6 % 2 == 0 && flag; - int l = this.enableBackgroundDrawing ? this.xPosition + 4 : this.xPosition; - int i1 = this.enableBackgroundDrawing ? this.yPosition + (this.height - 8) / 2 : this.yPosition; - int j1 = l; - - if (k > s.length()) { - k = s.length(); - } - - if (!alertMessage.isEmpty()) { - this.fontRendererInstance.drawString(alertMessage, ((this.xPosition + this.width / 2) - fontRendererInstance.getStringWidth(alertMessage) / 2), this.yPosition + this.height / 2 - 4, enabledColor, false); - return; - } - - if (s.isEmpty() && !isFocused && isEnabled) { - this.fontRendererInstance.drawString(noTextMessage, ((this.xPosition + this.width / 2) - fontRendererInstance.getStringWidth(noTextMessage) / 2), this.yPosition + this.height / 2 - 4, i, false); - return; - } - - if (s.length() > 0) { - String s1 = flag ? s.substring(0, j) : s; - j1 = this.fontRendererInstance.drawString(s1, (float) l, (float) i1, i, false); - } - - boolean flag2 = this.cursorPosition < this.text.length() || this.text.length() >= this.getMaxStringLength(); - int k1 = j1; - - if (!flag) { - k1 = j > 0 ? l + this.width: l; - } else if (flag2) { - k1 = j1 -1; --j1; - } - - if (s.length() > 0 && flag && j < s.length()) { - this.fontRendererInstance.drawString(s.substring(j), (float) j1, (float) i1, i, false); - } - - if (flag1) { - if (flag2) { - Gui.drawRect(k1, i1 -1, k1 + 1, i1 + 1 + this.fontRendererInstance.FONT_HEIGHT, -3092272); - } - else { - this.fontRendererInstance.drawString("_", (float) k1, (float) i1, i, false); - } - } - - if (k != j) { - int l1 = l + this.fontRendererInstance.getStringWidth(s.substring(0, k)); - this.drawCursorVertical(k1, i1 -1, l1 -1, i1 + 1 + this.fontRendererInstance.FONT_HEIGHT); - } - } - } - - /** - * draws the vertical line cursor in the textbox - */ - private void drawCursorVertical(int p_146188_1_, int p_146188_2_, int p_146188_3_, int p_146188_4_) { - if (p_146188_1_ < p_146188_3_) { - int i = p_146188_1_; - p_146188_1_ = p_146188_3_; - p_146188_3_ = i; - } - - if (p_146188_2_ < p_146188_4_) { - int j = p_146188_2_; - p_146188_2_ = p_146188_4_; - p_146188_4_ = j; - } - - if (p_146188_3_ > this.xPosition + this.width) { - p_146188_3_ = this.xPosition + this.width; - } - - if (p_146188_1_ > this.xPosition + this.width) { - p_146188_1_ = this.xPosition + this.width; - } - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - GlStateManager.color(0.0F, 0.0F, 255.0F, 255.0F); - GlStateManager.disableTexture2D(); - GlStateManager.enableColorLogic(); - GlStateManager.colorLogicOp(5387); - worldrenderer.begin(7, DefaultVertexFormats.POSITION); - worldrenderer.pos((double) p_146188_1_, (double) p_146188_4_, 0.0D).endVertex(); - worldrenderer.pos((double) p_146188_3_, (double) p_146188_4_, 0.0D).endVertex(); - worldrenderer.pos((double) p_146188_3_, (double) p_146188_2_, 0.0D).endVertex(); - worldrenderer.pos((double) p_146188_1_, (double) p_146188_2_, 0.0D).endVertex(); - tessellator.draw(); - GlStateManager.disableColorLogic(); - GlStateManager.enableTexture2D(); - } - - public void setMaxStringLength(int length) { - this.maxStringLength = length; - - if (this.text.length() > length) { - this.text = this.text.substring(0, length); - } - } - - /** - * returns the maximum number of character that can be contained in this textbox - */ - public int getMaxStringLength() { - return this.maxStringLength; - } - - /** - * returns the current position of the cursor - */ - public int getCursorPosition() { - return this.cursorPosition; - } - - /** - * get enable drawing background and outline - */ - public boolean getEnableBackgroundDrawing() { - return this.enableBackgroundDrawing; - } - - /** - * enable drawing background and outline - */ - public void setEnableBackgroundDrawing(boolean enableBackgroundDrawing) { - this.enableBackgroundDrawing = enableBackgroundDrawing; - } - - /** - * Sets the text colour for this textbox (disabled text will not use this colour) - */ - public void setTextColor(int color) { - this.enabledColor = color; - } - - public void setDisabledTextColour(int color) { - this.disabledColor = color; - } - - /** - * Sets focus to this gui element - */ - public void setFocused(boolean isFocused) { - if (isFocused && !this.isFocused) { - this.cursorCounter = 0; - } - this.isFocused = isFocused; - } - - /** - * Getter for the focused field - */ - public boolean isFocused() { - return this.isFocused; - } - - public void setEnabled(boolean enabled) { - this.isEnabled = enabled; - } - - public boolean isEnabled() { - return this.isEnabled; - } - - /** - * the side of the selection that is not the cursor, may be the same as the cursor - */ - public int getSelectionEnd() { - return this.selectionEnd; - } - - /** - * returns the width of the textbox depending on if background drawing is enabled - */ - public int getWidth() { - return this.getEnableBackgroundDrawing() ? this.width - 8 : this.width; - } - - /** - * Sets the position of the selection anchor (i.e. position the selection was started at) - */ - public void setSelectionPos(int pos) { - int i = this.text.length(); - - if (pos > i) { - pos = i; - } - if (pos < 0) { - pos = 0; - } - - this.selectionEnd = pos; - - if (this.fontRendererInstance != null) { - if (this.lineScrollOffset > i) { - this.lineScrollOffset = i; - } - - int j = this.getWidth(); - String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), j); - int k = s.length() + this.lineScrollOffset; - - if (pos == this.lineScrollOffset) { - this.lineScrollOffset -= this.fontRendererInstance.trimStringToWidth(this.text, j, true).length(); - } - - if (pos > k) { - this.lineScrollOffset += pos - k; - } else if (pos <= this.lineScrollOffset) { - this.lineScrollOffset -= this.lineScrollOffset - pos; - } - this.lineScrollOffset = MathHelper.clamp_int(this.lineScrollOffset, 0, i); - } - } - - /** - * if true the textbox can lose focus by clicking elsewhere on the screen - */ - public void setCanLoseFocus(boolean canLoseFocus) { - this.canLoseFocus = canLoseFocus; - } - - /** - * returns true if this textbox is visible - */ - public boolean getVisible() { - return this.visible; - } - - /** - * Sets whether or not this textbox is visible - */ - public void setVisible(boolean isVisible) { - this.visible = isVisible; - } - - public boolean isRunning() { - return this.running; - } - - public void alert(String message, int time) { - if (message.isEmpty()) return; - - running = true; - alertMessage = message; - - new Timer().schedule(new TimerTask() { - @Override - public void run() { - alertMessage = ""; - running = false; - } - }, time); - } - - public void setOnlyAllowNumbers(boolean onlyAllowNumbers) { - this.onlyAllowNumbers = onlyAllowNumbers; - } - - public boolean onlyAllowNumbers() { - return this.onlyAllowNumbers; - } - - private String format(String input) { - if (this.onlyAllowNumbers) { - StringBuilder builder = new StringBuilder(); - for (char c : input.toCharArray()) { - if (Character.isDigit(c)) { - builder.append(c); - } - } - return builder.toString(); - } else { - return input; - } - } -} \ No newline at end of file diff --git a/src/main/java/me/boomboompower/skinchanger/run/JavaMain.java b/src/main/java/me/boomboompower/skinchanger/run/JavaMain.java deleted file mode 100644 index eb0d299..0000000 --- a/src/main/java/me/boomboompower/skinchanger/run/JavaMain.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2020 boomboompower - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package me.boomboompower.skinchanger.run; - -import javax.swing.*; -import java.awt.*; - -public class JavaMain { - - public static void main(String[] args) { - for (String s : args) { - if ("nogui".equals(s) || "--nogui".equals(s)) { - System.out.println("Cannot run without Menu"); - System.out.println("Closing to avoid issues!"); - System.exit(0); - } - } - - if (!GraphicsEnvironment.isHeadless()) { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception var3) { - } - - RunGui.createMenu(); - } - } -} diff --git a/src/main/java/me/boomboompower/skinchanger/run/RunGui.java b/src/main/java/me/boomboompower/skinchanger/run/RunGui.java deleted file mode 100644 index 4e8d48a..0000000 --- a/src/main/java/me/boomboompower/skinchanger/run/RunGui.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2020 boomboompower - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package me.boomboompower.skinchanger.run; - -import javax.swing.*; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.UUID; - -public class RunGui extends JComponent { - - private static final Font serverGuiFont = new Font("Monospaced", Font.PLAIN, 12); - - public static void createMenu() { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception var3) { - } - - RunGui thing = new RunGui(); - JFrame jframe = new JFrame("String to UUID"); - jframe.add(thing); - jframe.pack(); - jframe.setLocationRelativeTo(null); - jframe.setVisible(true); - jframe.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent p_windowClosing_1_) { - System.exit(0); - } - }); - } - - public RunGui() { - this.setPreferredSize(new Dimension(854, 480)); - this.setLayout(new BorderLayout()); - - try { - this.add(this.getMessageComponent(), "Center"); - } catch (Exception exception) { - System.out.println("Couldn\'t build Menu"); - } - } - - private JComponent getMessageComponent() throws Exception { - JPanel jpanel = new JPanel(new BorderLayout()); - final JTextArea jtextarea = new JTextArea(); - final JScrollPane jscrollpane = new JScrollPane(jtextarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - jtextarea.setEditable(false); - jtextarea.setFont(serverGuiFont); - final JTextField jtextfield = new JTextField(); - jpanel.add(jscrollpane, "Center"); - jpanel.add(jtextfield, "South"); - jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Outputs")); - jtextfield.addActionListener(p_actionPerformed_1_ -> { - String s = jtextfield.getText().trim(); - - if (s.length() > 0) { - String uuid = UUID.nameUUIDFromBytes(s.getBytes()).toString(); - - a(jtextarea, jscrollpane, s + " | " + uuid + "\n"); - } - jtextfield.setText(""); - }); - return jpanel; - } - - public void a(final JTextArea area, final JScrollPane pane, final String s) { - Document document = area.getDocument(); - JScrollBar jscrollbar = pane.getVerticalScrollBar(); - boolean flag = false; - - if (pane.getViewport().getView() == area) { - flag = (double) jscrollbar.getValue() + jscrollbar.getSize().getHeight() + (double) (serverGuiFont.getSize() * 4) > (double) jscrollbar.getMaximum(); - } - - try { - document.insertString(document.getLength(), s, null); - } catch (BadLocationException var8) { - } - - if (flag) { - jscrollbar.setValue(Integer.MAX_VALUE); - } - } -} \ No newline at end of file diff --git a/src/main/java/me/boomboompower/skinchanger/utils/ChatColor.java b/src/main/java/me/boomboompower/skinchanger/utils/ChatColor.java deleted file mode 100644 index 3709d3e..0000000 --- a/src/main/java/me/boomboompower/skinchanger/utils/ChatColor.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2020 boomboompower - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package me.boomboompower.skinchanger.utils; - -import java.util.regex.Pattern; - -public enum ChatColor { - - BLACK('0'), - DARK_BLUE('1'), - DARK_GREEN('2'), - DARK_AQUA('3'), - DARK_RED('4'), - DARK_PURPLE('5'), - GOLD('6'), - GRAY('7'), - DARK_GRAY('8'), - BLUE('9'), - GREEN('a'), - AQUA('b'), - RED('c'), - LIGHT_PURPLE('d'), - YELLOW('e'), - WHITE('f'), - MAGIC('k', true), - BOLD('l', true), - STRIKETHROUGH('m', true), - UNDERLINE('n', true), - ITALIC('o', true), - RESET('r'); - - public static final char COLOR_CHAR = '\u00A7'; - - private final char code; - private final boolean isFormat; - private final String toString; - - ChatColor(char code) { - this(code, false); - } - - ChatColor(char code, boolean isFormat) { - this.code = code; - this.isFormat = isFormat; - this.toString = new String(new char[] {COLOR_CHAR, code}); - } - - public char getChar() { - return code; - } - - @Override - public String toString() { - return toString; - } - - public boolean isFormat() { - return isFormat; - } - - public boolean isColor() { - return !isFormat && this != RESET; - } - - public static String stripColor(final String input) { - if (input == null) { - return null; - } - return Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]").matcher(input).replaceAll(""); - } - - public static String translateAlternateColorCodes(String textToTranslate) { - return translateAlternateColorCodes('&', textToTranslate); - } - - public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) { - char[] b = textToTranslate.toCharArray(); - for (int i = 0; i < b.length - 1; i++) { - if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1) { - b[i] = ChatColor.COLOR_CHAR; - b[i+1] = Character.toLowerCase(b[i+1]); - } - } - return new String(b); - } - - /* - * Color then strip the message, useful for removing all colors in the message. - */ - public static String formatUnformat(char altColorChat, String message) { - return stripColor(translateAlternateColorCodes(altColorChat, message)); - } -} \ No newline at end of file diff --git a/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/UISkeleton.java b/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/UISkeleton.java index f4ba590..10079d1 100644 --- a/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/UISkeleton.java +++ b/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/UISkeleton.java @@ -19,27 +19,79 @@ import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernButton; +/** + * Provides the base methods for a Gui, these methods are designed to be applicable to multiple Minecraft versions. + *
+ * It should be noted that all render methods are ran in sandboxed environments meaning if an error occurs, the game will not crash. + * + * @version 1.0 + * @author boomboompower + */ public interface UISkeleton { - void onGuiOpen(); + /** + * Called when the GUI is first opened. Equivalent to initGui + */ + public void onGuiOpen(); - default void onGuiClose() { + /** + * Called when the GUI is closed. + */ + public default void onGuiClose() { } - default void preRender() { + /** + * Called just before the render method is called. + *
+ * This method is sandboxed. + */ + public default void preRender() { } - void onRender(int mouseX, int mouseY, float partialTicks); + /** + * Called during the render method + *
+ * This method is sandboxed. + * + * @param mouseX the x position of the mouse + * @param mouseY the y position of the mouse + * @param partialTicks from timer - jow much time has elapsed since the last tick, in ticks, for + * use by display rendering routines (range: 0.0 - * 1.0). This field is frozen if the display + * is paused to eliminate jitter. + */ + public void onRender(int mouseX, int mouseY, float partialTicks); - default void postRender() { + /** + * Called after the render method + *
+ * This method is sandboxed. + */ + public default void postRender() { } - default void buttonPressed(ModernButton button) { + /** + * Called when a {@link ModernButton} is left clicked. + * + * @param button the button that was left clicked. + */ + public default void buttonPressed(ModernButton button) { } - default void rightClicked(ModernButton button) { + /** + * Called when a {@link ModernButton} is right clicked. + * + * @param button the button that was right clicked. + */ + public default void rightClicked(ModernButton button) { } - default void onKeyTyped(int keyCode, char keyCharacter) { - } + /** + * Called when a character is typed. Mimics the GuiScreen keyTyped functionality. + * + * @param keyCode the keyCode of the character. See {@link org.lwjgl.input.Keyboard} to get codes. + * @param keyCharacter the character representation of the key. Example: if {@link + * org.lwjgl.input.Keyboard#KEY_A} was pressed * then 'a' would be the character that is + * returned. + */ + public default void onKeyTyped(int keyCode, char keyCharacter) {} } diff --git a/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/impl/ModernGui.java b/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/impl/ModernGui.java index d73205e..d04072e 100644 --- a/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/impl/ModernGui.java +++ b/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/impl/ModernGui.java @@ -18,26 +18,23 @@ package me.do_you_like.mods.skinchanger.utils.gui.impl; import com.google.common.collect.Lists; + import java.awt.Color; -import java.io.IOException; import java.util.List; -import me.boomboompower.skinchanger.utils.ChatColor; + import me.do_you_like.mods.skinchanger.SkinChangerMod; +import me.do_you_like.mods.skinchanger.utils.game.ChatColor; import me.do_you_like.mods.skinchanger.utils.gui.UISkeleton; import me.do_you_like.mods.skinchanger.utils.gui.lock.UILock; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiLabel; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.ChatComponentText; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; diff --git a/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/lock/UILock.java b/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/lock/UILock.java index 95060d7..2d1fbf4 100644 --- a/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/lock/UILock.java +++ b/src/main/java/me/do_you_like/mods/skinchanger/utils/gui/lock/UILock.java @@ -20,7 +20,7 @@ import java.awt.Color; import java.io.IOException; -import me.boomboompower.skinchanger.utils.ChatColor; +import me.do_you_like.mods.skinchanger.utils.game.ChatColor; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; diff --git a/src/main/java/me/do_you_like/mods/skinchanger/utils/updater/WebsiteUtils.java b/src/main/java/me/do_you_like/mods/skinchanger/utils/updater/WebsiteUtils.java index 1fd4e88..3599ec6 100644 --- a/src/main/java/me/do_you_like/mods/skinchanger/utils/updater/WebsiteUtils.java +++ b/src/main/java/me/do_you_like/mods/skinchanger/utils/updater/WebsiteUtils.java @@ -21,6 +21,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; + import java.net.HttpURLConnection; import java.net.URL; import java.util.LinkedList; @@ -30,8 +31,10 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import me.boomboompower.skinchanger.SkinChangerModOld; -import me.boomboompower.skinchanger.utils.ChatColor; + +import me.do_you_like.mods.skinchanger.SkinChangerMod; +import me.do_you_like.mods.skinchanger.utils.game.ChatColor; + import net.minecraft.client.Minecraft; import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; @@ -156,7 +159,7 @@ public void begin() { this.showUpdateHeader = object.get("updateheader").getAsBoolean(); } - int currentVersion = formatVersion(SkinChangerModOld.VERSION); + int currentVersion = formatVersion(SkinChangerMod.VERSION); int latestVersion = object.has("latest-version") ? formatVersion(object.get("latest-version").getAsString()) : -1; if (currentVersion < latestVersion && latestVersion > 0) { @@ -408,7 +411,7 @@ private void sendMessage(String message, Object... replacements) { try { message = String.format(message, replacements); - } catch (Exception ex) { } + } catch (Exception ignored) { } Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new ChatComponentText(ChatColor.translateAlternateColorCodes('&', message))); } @@ -429,7 +432,7 @@ private void sendLinkText() { text.appendSibling(url).appendText(ChatColor.YELLOW + "!"); Minecraft.getMinecraft().thePlayer.addChatComponentMessage(text); - } catch (Exception ex) { + } catch (Exception ignored) { } } }