diff options
Diffstat (limited to 'src/main/java')
15 files changed, 187 insertions, 62 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java index 07b7bfc..69faf06 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java @@ -29,11 +29,6 @@ public class GuiTextures { public static final ResourceLocation slider_on_segment = new ResourceLocation("skyblockhud:core/slider/slider_on_segment.png"); public static final ResourceLocation slider_button_new = new ResourceLocation("skyblockhud:core/slider/slider_button.png"); - public static final ResourceLocation overlay = new ResourceLocation("skyblockhud", "stats.png"); - public static final ResourceLocation dungeon = new ResourceLocation("skyblockhud", "dungeon.png"); - public static final ResourceLocation playerStat = new ResourceLocation("skyblockhud", "playerstats.png"); public static final ResourceLocation mapOverlay = new ResourceLocation("skyblockhud", "maps/map_overlay.png"); - public static final ResourceLocation mining = new ResourceLocation("skyblockhud", "mines.png"); - public static final ResourceLocation dialogue = new ResourceLocation("skyblockhud", "dialogue.png"); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java index 763e5fc..74e82eb 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java @@ -18,6 +18,7 @@ import com.thatgravyboat.skyblockhud.overlay.OverlayHud; import com.thatgravyboat.skyblockhud.overlay.RPGHud; import com.thatgravyboat.skyblockhud.playerstats.ActionBarParsing; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import com.thatgravyboat.skyblockhud.textures.Textures; import com.thatgravyboat.skyblockhud.tracker.TrackerFileLoader; import com.thatgravyboat.skyblockhud.tracker.TrackerHandler; import java.awt.*; @@ -89,6 +90,7 @@ public class SkyblockHud { Commands.init(); ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(new NpcDialogue()); + ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(new Textures()); configFile = new File(event.getModConfigurationDirectory(), "sbh-config.json"); @@ -103,6 +105,8 @@ public class SkyblockHud { saveConfig(); } + Textures.setTexture(config.misc.style); + configDirectory = event.getModConfigurationDirectory(); Runtime.getRuntime().addShutdownHook(new Thread(this::saveConfig)); @@ -130,8 +134,6 @@ public class SkyblockHud { MinecraftForge.EVENT_BUS.register(new NpcDialogue()); } - // DISABLE UNTIL NEW SYSTEM - @EventHandler public void loadComplete(FMLLoadCompleteEvent event) { TrackerFileLoader.loadTrackersFile(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java index 5a6acfc..74ccc0e 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java @@ -108,9 +108,9 @@ public class SBHConfig extends Config { public boolean hideScoreboard = false; @Expose - @ConfigOption(name = "Bar Textures", desc = "Change the style of bars. Dont change this unless the pack ur using tells you can.") - @ConfigEditorDropdown(values = { "Style 1", "Style 2" }) - public int barTexture = 0; + @ConfigOption(name = "Texture Styles", desc = "If this list only contains 1 thing that means your texture pack doesnt support styles") + @ConfigEditorStyle() + public int style = 0; @Expose @ConfigOption(name = "Hide Dialogue Box", desc = "Hides the Dialogue Box.") diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorStyle.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorStyle.java new file mode 100644 index 0000000..2a208a0 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorStyle.java @@ -0,0 +1,10 @@ +package com.thatgravyboat.skyblockhud.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorStyle {} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java index 92c1a0f..6b703cd 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java @@ -10,10 +10,10 @@ import org.lwjgl.input.Mouse; public class GuiOptionEditorDropdown extends GuiOptionEditor { - private final String[] values; + protected final String[] values; private final boolean useOrdinal; - private int selected; - private boolean open = false; + protected int selected; + protected boolean open = false; public GuiOptionEditorDropdown(ConfigProcessor.ProcessedOption option, String[] values, int selected, boolean useOrdinal) { super(option); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorStyle.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorStyle.java new file mode 100644 index 0000000..e383db2 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorStyle.java @@ -0,0 +1,43 @@ +package com.thatgravyboat.skyblockhud.core.config.gui; + +import com.thatgravyboat.skyblockhud.core.config.struct.ConfigProcessor; +import com.thatgravyboat.skyblockhud.textures.Textures; +import java.util.stream.Collectors; +import org.lwjgl.input.Mouse; + +public class GuiOptionEditorStyle extends GuiOptionEditorDropdown { + + public GuiOptionEditorStyle(ConfigProcessor.ProcessedOption option, int selected) { + super(option, Textures.styles.stream().map(t ->t.displayName).collect(Collectors.toList()).toArray(new String[]{}), selected, true); + } + + @Override + public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int left = x + width / 6 - 40; + int top = y + height - 7 - 14; + + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (!(mouseX >= left && mouseX <= left + 80 && mouseY >= top && mouseY <= top + 14) && open) { + this.open = false; + if (mouseX >= left && mouseX <= left + 80) { + int dropdownY = 13; + for (int ordinal = 0; ordinal < values.length; ordinal++) { + if (mouseY >= top + 3 + dropdownY && mouseY <= top + 3 + dropdownY + 12) { + selected = ordinal; + option.set(selected); + Textures.setTexture(selected); + return true; + } + dropdownY += 12; + } + } + return true; + } + } + + return false; + } + +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java index 50cb894..9e0a9d8 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java @@ -117,6 +117,8 @@ public class ConfigProcessor { if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), (int) option.get(), true); + } else if (optionField.isAnnotationPresent(ConfigEditorStyle.class)) { + editor = new GuiOptionEditorStyle(option, (int) option.get()); } } if (optionType.isAssignableFrom(List.class)) { diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java index 1f56526..0e7ccdc 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java @@ -1,13 +1,12 @@ package com.thatgravyboat.skyblockhud.handlers; -import static com.thatgravyboat.skyblockhud.GuiTextures.dialogue; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.Utils; +import com.thatgravyboat.skyblockhud.textures.Textures; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -80,7 +79,7 @@ public class NpcDialogue implements IResourceManagerReloadListener { public void renderOverlay(RenderGameOverlayEvent.Post event) { if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), showDialogue, !SkyblockHud.config.misc.hideDialogueBox)) { Minecraft mc = Minecraft.getMinecraft(); - mc.renderEngine.bindTexture(dialogue); + mc.renderEngine.bindTexture(Textures.texture.dialogue); GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); int x = SkyblockHud.config.misc.dialoguePos.getAbsX(event.resolution, 182) - 91; @@ -111,8 +110,8 @@ public class NpcDialogue implements IResourceManagerReloadListener { public void onResourceManagerReload(IResourceManager resourceManager) { NPCS.clear(); try { - ResourceLocation trackers = new ResourceLocation("skyblockhud:data/npc_textures.json"); - InputStream is = resourceManager.getResource(trackers).getInputStream(); + ResourceLocation npcs = new ResourceLocation("skyblockhud:data/npc_textures.json"); + InputStream is = resourceManager.getResource(npcs).getInputStream(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { for (JsonElement npc : gson.fromJson(reader, JsonObject.class).getAsJsonArray("npcs")) { diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java index f8a2e0d..a1dd5a1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java @@ -1,6 +1,5 @@ package com.thatgravyboat.skyblockhud.overlay; -import com.thatgravyboat.skyblockhud.GuiTextures; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.SpecialColour; import com.thatgravyboat.skyblockhud.Utils; @@ -12,6 +11,7 @@ import com.thatgravyboat.skyblockhud.dungeons.DungeonPlayer; import com.thatgravyboat.skyblockhud.handlers.BossbarHandler; import com.thatgravyboat.skyblockhud.location.LocationHandler; import com.thatgravyboat.skyblockhud.location.Locations; +import com.thatgravyboat.skyblockhud.textures.Textures; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -31,7 +31,7 @@ public class DungeonOverlay extends Gui { if (!SkyblockHud.config.dungeon.hideDeadDungeonPlayers || !isDead) { GlStateManager.enableBlend(); Minecraft mc = Minecraft.getMinecraft(); - mc.renderEngine.bindTexture(GuiTextures.dungeon); + mc.renderEngine.bindTexture(Textures.texture.dungeon); String healthString = isDead ? "DEAD" : Integer.toString(health); GlStateManager.color(1.0F, 1.0F, 1.0F, (float) SkyblockHud.config.dungeon.dungeonPlayerOpacity / 100); @@ -46,12 +46,12 @@ public class DungeonOverlay extends Gui { public void drawDungeonClock(int width, int offset, Minecraft mc) { GlStateManager.enableBlend(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int dungeonTime = DungeonHandler.getDungeonTime(); int dungeonTimeMin = dungeonTime / 60; int dungeonTimeSec = dungeonTime - dungeonTimeMin * 60; drawTexturedModalRect((width / 2) - 17, offset + (bossBarVisible ? 17 : 0), 0, 0, 34, 34); - mc.renderEngine.bindTexture(GuiTextures.dungeon); + mc.renderEngine.bindTexture(Textures.texture.dungeon); drawTexturedModalRect((width / 2) - 7, offset + (bossBarVisible ? 20 : 3), 16, 50, 3, 8); drawTexturedModalRect((width / 2) - 7, offset + (bossBarVisible ? 30 : 13), 19, 50, 3, 8); String dungeonTimeElapsed = (dungeonTimeMin > 9 ? String.valueOf(dungeonTimeMin) : "0" + dungeonTimeMin) + ":" + (dungeonTimeSec > 9 ? String.valueOf(dungeonTimeSec) : "0" + dungeonTimeSec); @@ -61,7 +61,7 @@ public class DungeonOverlay extends Gui { drawString(font, DungeonHandler.getWitherKeys() + "x", (width / 2), offset + (bossBarVisible ? 30 : 13), 0x555555); //CLEARED PERCENTAGE GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int clearPercent = DungeonHandler.getDungeonCleared(); String clearPercentage = "Dungeon Cleared: \u00A7" + (clearPercent <= 20 ? "4" : clearPercent <= 50 ? "6" : clearPercent <= 80 ? "e" : "a") + clearPercent + "%"; drawTexturedModalRect((width / 2) + 17, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(clearPercentage) + 3, 14); @@ -70,7 +70,7 @@ public class DungeonOverlay extends Gui { //DEATHS GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int deaths = DungeonHandler.getDeaths(); String deathText = "Deaths: " + deaths; drawTexturedModalRect((width / 2) + 17, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(deathText) + 3, 14); @@ -79,7 +79,7 @@ public class DungeonOverlay extends Gui { //SECRETS GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int maxSecrets = DungeonHandler.getMaxSecrets(); int secrets = DungeonHandler.getSecrets(); int totalSecrets = DungeonHandler.getTotalSecrets(); @@ -90,7 +90,7 @@ public class DungeonOverlay extends Gui { //CRYPTS GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int crypts = DungeonHandler.getCrypts(); String cryptText = "Crypts: " + crypts; drawTexturedModalRect((width / 2) - 17 - (font.getStringWidth(cryptText)) - 4, offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java index 880e2ea..daf3ec0 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java @@ -2,21 +2,17 @@ package com.thatgravyboat.skyblockhud.overlay; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; +import com.thatgravyboat.skyblockhud.textures.Textures; import java.awt.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.ResourceLocation; public class GenericOverlays extends Gui { - public static int lastBar = 0; - public static ResourceLocation bars = new ResourceLocation("skyblockhud", "bars.png"); - public static void drawLargeBar(Minecraft mc, int x, int y, float percentage, float max, int fullColor, int loadingColor, int barStyle) { if (SkyblockHud.hasSkyblockScoreboard()) { - updateBar(); - mc.renderEngine.bindTexture(bars); + mc.renderEngine.bindTexture(Textures.texture.bars); Color color = new Color(percentage == max ? fullColor : loadingColor); RenderUtils.drawTexturedModalRect(x, y, 0, 0, 182, 5); @@ -31,8 +27,7 @@ public class GenericOverlays extends Gui { public static void drawSmallBar(Minecraft mc, int x, int y, double percentage, double max, int fullColor, int loadingColor, int barStyle) { if (SkyblockHud.hasSkyblockScoreboard()) { - updateBar(); - mc.renderEngine.bindTexture(bars); + mc.renderEngine.bindTexture(Textures.texture.bars); Color color = new Color(percentage == max ? fullColor : loadingColor); GlStateManager.enableBlend(); RenderUtils.drawTexturedModalRect(x, y, 0, 35, 62, 5); @@ -44,11 +39,4 @@ public class GenericOverlays extends Gui { } } } - - public static void updateBar() { - if (lastBar != SkyblockHud.config.misc.barTexture) { - lastBar = SkyblockHud.config.misc.barTexture; - if (lastBar == 0) bars = new ResourceLocation("skyblockhud", "bars.png"); else bars = new ResourceLocation("skyblockhud", "bars_" + lastBar + ".png"); - } - } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/MiningHud.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/MiningHud.java index fa4136f..8f4ec82 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/MiningHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/MiningHud.java @@ -1,9 +1,9 @@ package com.thatgravyboat.skyblockhud.overlay; -import com.thatgravyboat.skyblockhud.GuiTextures; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.core.config.Position; +import com.thatgravyboat.skyblockhud.textures.Textures; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; @@ -59,7 +59,7 @@ public class MiningHud extends Gui { if (maxFuel == 0) return; GlStateManager.enableBlend(); GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); - mc.renderEngine.bindTexture(GuiTextures.mining); + mc.renderEngine.bindTexture(Textures.texture.mines); drawTexturedModalRect(x, y, 0, 0, 136, 7); drawTexturedModalRect(x, y, 0, 7, Utils.lerp((float) fuel / (float) maxFuel, 0, 136), 7); String percentageText = Math.round(((float) fuel / (float) maxFuel) * 100) + "%"; @@ -69,7 +69,7 @@ public class MiningHud extends Gui { private void renderHeatBar(Minecraft mc, int x, int y) { GlStateManager.enableBlend(); GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); - mc.renderEngine.bindTexture(GuiTextures.mining); + mc.renderEngine.bindTexture(Textures.texture.mines); drawTexturedModalRect(x, y, 137, 0, 45, 7); drawTexturedModalRect(x, y, 137, 7, Utils.lerp(heat / 100f, 0, 45), 7); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java index 5ed0285..1259298 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java @@ -1,6 +1,5 @@ package com.thatgravyboat.skyblockhud.overlay; -import com.thatgravyboat.skyblockhud.GuiTextures; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.handlers.BossbarHandler; @@ -10,6 +9,7 @@ import com.thatgravyboat.skyblockhud.handlers.TimeHandler; import com.thatgravyboat.skyblockhud.location.*; import com.thatgravyboat.skyblockhud.seasons.Season; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import com.thatgravyboat.skyblockhud.textures.Textures; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; @@ -35,7 +35,7 @@ public class OverlayHud extends Gui { public void drawClock(int width, int offset, Minecraft mc) { GlStateManager.enableBlend(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); //CLOCK int timeMin = (int) (TimeHandler.time / 60); int timeHour = timeMin / 60; @@ -87,7 +87,7 @@ public class OverlayHud extends Gui { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); if (mc.thePlayer.ticksExisted % 100 == 0 && eventToggle) eventToggle = false; if (mc.thePlayer.ticksExisted % 600 == 0) eventToggle = true; - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); String dateText = SeasonDateHandler.getFancySeasonAndDate(); if (eventToggle && !SeasonDateHandler.getCurrentEvent().isEmpty() && !SeasonDateHandler.getCurrentEventTime().isEmpty()) dateText = SeasonDateHandler.getCurrentEvent().trim() + " " + SeasonDateHandler.getCurrentEventTime().trim(); drawTexturedModalRect((width / 2) + 17, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(dateText) + 9, 14); @@ -99,7 +99,7 @@ public class OverlayHud extends Gui { public void drawLocation(int width, int offset, Minecraft mc) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName())), offset + (bossBarVisible ? 20 : 3), 0, 34, 2, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()))) + 2, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()) + 14, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()))) + 4, offset + (bossBarVisible ? 23 : 6), LocationHandler.getCurrentLocation().getCategory().getTexturePos(), 8, 8, 8); @@ -108,7 +108,7 @@ public class OverlayHud extends Gui { public void drawRedstone(int width, int offset, Minecraft mc) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int redstoneColor = IslandHandler.redstone > 90 ? 0xFF0000 : IslandHandler.redstone > 75 ? 0xC45B00 : IslandHandler.redstone > 50 ? 0xFFFF55 : 0x55FF55; if (IslandHandler.redstone > 0 && Utils.isPlayerHoldingRedstone(mc.thePlayer)) { drawTexturedModalRect((width / 2) - 15, offset + (bossBarVisible ? 51 : 34), 0, 48, 30, 18); @@ -119,7 +119,7 @@ public class OverlayHud extends Gui { public void drawPurseAndBits(int width, int offset, Minecraft mc) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int xPos = (width / 2) + 17; //COINS @@ -127,7 +127,7 @@ public class OverlayHud extends Gui { drawTexturedModalRect(xPos + 1, offset + (bossBarVisible ? 37 : 20), 34, 0, 8, 8); drawString(font, CurrencyHandler.getCoinsFormatted(), xPos + 10, offset + (bossBarVisible ? 38 : 21), 0xFFAA00); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); xPos += font.getStringWidth(CurrencyHandler.getCoinsFormatted()) + 11; //BITS @@ -136,7 +136,7 @@ public class OverlayHud extends Gui { drawTexturedModalRect(xPos + 1, offset + (bossBarVisible ? 37 : 20), 75, 0, 8, 8); drawString(font, CurrencyHandler.getBitsFormatted(), xPos + 10, offset + (bossBarVisible ? 38 : 21), 0x55FFFF); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); xPos += font.getStringWidth(CurrencyHandler.getBitsFormatted()) + 11; } @@ -149,7 +149,7 @@ public class OverlayHud extends Gui { DecimalFormat flightFormat = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); String duration; if (IslandHandler.flightTime < 60) duration = IslandHandler.flightTime + "s"; else if (IslandHandler.flightTime < 3600) duration = flightFormat.format((double) IslandHandler.flightTime / 60) + "m"; else if (IslandHandler.flightTime < 86400) duration = flightFormat.format((double) IslandHandler.flightTime / 3600) + "hr"; else if (IslandHandler.flightTime < 86460) duration = flightFormat.format((double) IslandHandler.flightTime / 86400) + "day"; else duration = flightFormat.format((double) IslandHandler.flightTime / 86400) + "days"; - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), 67, 0, 8, 8); @@ -160,7 +160,7 @@ public class OverlayHud extends Gui { public void drawRainDuration(int width, int offset, Minecraft mc) { if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); String duration = "Rain: " + ParkIslandHandler.getRainTime(); drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); @@ -177,7 +177,7 @@ public class OverlayHud extends Gui { SlayerHandler.slayerTypes slayerType = SlayerHandler.currentSlayer; if (slayerType != SlayerHandler.slayerTypes.NONE) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(EnumChatFormatting.GREEN); stringBuilder.append(Utils.intToRomanNumeral(tier)); @@ -211,7 +211,7 @@ public class OverlayHud extends Gui { public void drawMiningPowders(int width, int offset, Minecraft mc) { if (MinesHandler.gemstone == 0) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); String mithril = MinesHandler.getMithrilFormatted(); drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(mithril)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(mithril))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(mithril) + 14, 14); @@ -222,7 +222,7 @@ public class OverlayHud extends Gui { String mithril = locationCategory == LocationCategory.DWARVENMINES ? MinesHandler.getMithrilFormatted() : MinesHandler.getMithrilShortFormatted(); String gemstone = locationCategory == LocationCategory.CRYSTALHOLLOWS ? MinesHandler.getGemstoneFormatted() : MinesHandler.getGemstoneShortFormatted(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int edge = (width / 2) - 33; @@ -246,7 +246,7 @@ public class OverlayHud extends Gui { public void drawTrapperOrPelts(int width, int offset, Minecraft mc) { if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.MUSHROOMDESERT)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); String duration = FarmingIslandHandler.location != Locations.NONE ? FarmingIslandHandler.location.getDisplayName() : "" + FarmingIslandHandler.pelts; drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); @@ -258,7 +258,7 @@ public class OverlayHud extends Gui { public void drawDwarvenEvent(int width, int offset, Minecraft mc) { if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); if (MinesHandler.eventMax > 0 || !MinesHandler.currentEvent.needsMax) { String duration = MinesHandler.currentEvent.needsMax ? MinesHandler.eventProgress + "/" + MinesHandler.eventMax : String.valueOf(MinesHandler.eventProgress); drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); @@ -313,7 +313,7 @@ public class OverlayHud extends Gui { public int drawLeftBottomBar(int width, int offset, int barWidth, Minecraft mc) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(GuiTextures.overlay); + mc.renderEngine.bindTexture(Textures.texture.stats); int edge = (width / 2) - 17; drawTexturedModalRect(edge - barWidth, offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java index ef19553..f082a47 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java @@ -1,11 +1,11 @@ package com.thatgravyboat.skyblockhud.overlay; import com.mojang.realmsclient.gui.ChatFormatting; -import com.thatgravyboat.skyblockhud.GuiTextures; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.core.config.Position; import com.thatgravyboat.skyblockhud.handlers.HeldItemHandler; +import com.thatgravyboat.skyblockhud.textures.Textures; import java.text.DecimalFormat; import java.text.NumberFormat; import net.minecraft.client.Minecraft; @@ -61,7 +61,7 @@ public class RPGHud extends Gui { health = Math.max((int) (maxHealth * (mc.thePlayer.getHealth() / mc.thePlayer.getMaxHealth())), health); } - mc.renderEngine.bindTexture(GuiTextures.playerStat); + mc.renderEngine.bindTexture(Textures.texture.playerStats); Position position = SkyblockHud.config.rpg.rpgHudPosition; int x = position.getAbsX(event.resolution, 120); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java b/src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java new file mode 100644 index 0000000..10495f5 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java @@ -0,0 +1,37 @@ +package com.thatgravyboat.skyblockhud.textures; + +import com.google.gson.JsonObject; +import java.util.Arrays; +import net.minecraft.util.ResourceLocation; + +public class TextureObject { + + public String displayName; + public ResourceLocation bars = resource("bars.png"); + public ResourceLocation mines = resource("mines.png"); + public ResourceLocation playerStats = resource("playerstats.png"); + public ResourceLocation stats = resource("stats.png"); + public ResourceLocation dungeon = resource("dungeon.png"); + public ResourceLocation dialogue = resource("dialogue.png"); + + public TextureObject(String displayName){ + this.displayName = displayName; + } + + public static TextureObject decode(JsonObject json) { + TextureObject textureObject = new TextureObject(json.get("displayName").getAsString()); + Arrays.stream(textureObject.getClass().getDeclaredFields()) + .filter(field -> field.getType().equals(ResourceLocation.class)).forEach(field -> { + try { + field.set(textureObject, new ResourceLocation(json.get(field.getName()).getAsString())); + } catch (Exception ignored) {} + } + ); + return textureObject; + } + + + private static ResourceLocation resource(String path){ + return new ResourceLocation("skyblockhud", path); + } +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/textures/Textures.java b/src/main/java/com/thatgravyboat/skyblockhud/textures/Textures.java new file mode 100644 index 0000000..61b19b7 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/textures/Textures.java @@ -0,0 +1,49 @@ +package com.thatgravyboat.skyblockhud.textures; + +import com.google.common.collect.Lists; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.thatgravyboat.skyblockhud.SkyblockHud; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.List; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.util.ResourceLocation; + +public class Textures implements IResourceManagerReloadListener { + private static final TextureObject DEFAULT_TEXTURE = new TextureObject("Default"); + + private static final Gson gson = new GsonBuilder().create(); + public static final List<TextureObject> styles = Lists.newArrayList(DEFAULT_TEXTURE); + public static TextureObject texture = DEFAULT_TEXTURE; + + public static void setTexture(int selected){ + if (selected >= styles.size() || selected < 0) { + texture = DEFAULT_TEXTURE; + SkyblockHud.config.misc.style = 0; + } else { + texture = styles.get(selected); + } + } + + @Override + public void onResourceManagerReload(IResourceManager resourceManager) { + styles.clear(); + styles.add(DEFAULT_TEXTURE); + try { + ResourceLocation stylesData = new ResourceLocation("skyblockhud:data/styles.json"); + InputStream is = resourceManager.getResource(stylesData).getInputStream(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { + for (JsonElement json : gson.fromJson(reader, JsonObject.class).getAsJsonArray("styles")) { + styles.add(TextureObject.decode((JsonObject) json)); + } + } + } catch (Exception ignored) {} + } + +} |