From dfa65f6236c226eb88f4e3761e10e80e5f37c22b Mon Sep 17 00:00:00 2001 From: nextdaydelivery <12willettsh@gmail.com> Date: Sun, 20 Feb 2022 12:13:58 +0000 Subject: package moves and a split string renderer --- .../java/io/polyfrost/oneconfig/gui/Window.java | 14 +++- .../polyfrost/oneconfig/gui/elements/OCBlock.java | 11 +-- .../oneconfig/gui/elements/OCStoreBlock.java | 18 +++- .../polyfrost/oneconfig/renderer/TrueTypeFont.java | 40 ++++++++- .../polyfrost/oneconfig/themes/TextureManager.java | 97 --------------------- .../java/io/polyfrost/oneconfig/themes/Theme.java | 1 + .../polyfrost/oneconfig/themes/ThemeElement.java | 48 ----------- .../oneconfig/themes/TickableTexture.java | 90 -------------------- .../oneconfig/themes/textures/TextureManager.java | 98 ++++++++++++++++++++++ .../oneconfig/themes/textures/ThemeElement.java | 48 +++++++++++ .../oneconfig/themes/textures/TickableTexture.java | 91 ++++++++++++++++++++ 11 files changed, 312 insertions(+), 244 deletions(-) delete mode 100644 src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java create mode 100644 src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java create mode 100644 src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java create mode 100644 src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java (limited to 'src/main') diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java index 8dd0138..7671578 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java @@ -1,13 +1,20 @@ package io.polyfrost.oneconfig.gui; import io.polyfrost.oneconfig.gui.elements.OCBlock; +import io.polyfrost.oneconfig.gui.elements.OCStoreBlock; import io.polyfrost.oneconfig.themes.Theme; -import io.polyfrost.oneconfig.themes.ThemeElement; +import io.polyfrost.oneconfig.themes.textures.ThemeElement; import io.polyfrost.oneconfig.themes.Themes; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.util.ResourceLocation; +import javax.imageio.ImageIO; import java.awt.*; +import java.io.IOException; +import java.net.URL; import static io.polyfrost.oneconfig.renderer.Renderer.clamp; import static io.polyfrost.oneconfig.renderer.Renderer.easeOut; @@ -18,6 +25,9 @@ public class Window extends GuiScreen { private final Theme t = Themes.getActiveTheme(); private final int guiScaleToRestore; OCBlock block = new OCBlock(-1, 100, 200); + ResourceLocation example = new ResourceLocation("oneconfig", "textures/hudsettings.png"); + OCStoreBlock storeBlock = new OCStoreBlock("OneConfig Theme", "OneConfig default theme with the default look you love.", example, new Color(27,27,27,255).getRGB()); + public static ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); public Window() { super.initGui(); @@ -31,6 +41,7 @@ public class Window extends GuiScreen { } public void drawScreen(int mouseX, int mouseY, float partialTicks) { + resolution = new ScaledResolution(Minecraft.getMinecraft()); super.drawScreen(mouseX, mouseY, partialTicks); currentProgress = clamp(easeOut(currentProgress, 1f)); int alphaVal = (int) (50 * currentProgress); @@ -57,6 +68,7 @@ public class Window extends GuiScreen { t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1424, top + 32, 64, 64); t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1344, top + 32, 64, 64); block.draw(200, 300); + storeBlock.draw(500,300); //t.getTextureManager().draw(ThemeElement.CLOSE, left + 1504, top + 32, 64, 64); //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 100, top + 100, 296, 64); //t.getTextureManager().draw(ThemeElement.CLOSE); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java index 7a5c8f3..fcce48b 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java @@ -2,7 +2,7 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.renderer.Renderer; import io.polyfrost.oneconfig.themes.Theme; -import io.polyfrost.oneconfig.themes.ThemeElement; +import io.polyfrost.oneconfig.themes.textures.ThemeElement; import io.polyfrost.oneconfig.themes.Themes; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -14,15 +14,16 @@ import org.lwjgl.input.Mouse; import java.awt.*; +import static io.polyfrost.oneconfig.gui.Window.resolution; + @SuppressWarnings("unused") public class OCBlock { - private static final Theme theme = Themes.getActiveTheme(); + public static final Theme theme = Themes.getActiveTheme(); private static final Minecraft mc = Minecraft.getMinecraft(); - public static ScaledResolution resolution = new ScaledResolution(mc); private Color color; private String text; private final boolean bold; - private int width, height; + protected int width, height; private ThemeElement element; private boolean clicked = false; private boolean rightClicked = false; @@ -103,7 +104,7 @@ public class OCBlock { } /** - * Update this elements click, key and hover status. Call this method at the end of your 'draw' function, if overrided. + * Update this elements click, key and hover status. Call this method at the end of your 'draw' function, if overridden. */ public void update() { resolution = new ScaledResolution(mc); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java index 6d9d8c1..7a87f77 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java @@ -1,17 +1,33 @@ package io.polyfrost.oneconfig.gui.elements; +import io.polyfrost.oneconfig.renderer.Renderer; import net.minecraft.util.ResourceLocation; -public class OCStoreBlock extends OCBlock { +import java.awt.*; +public class OCStoreBlock extends OCBlock { + private ResourceLocation image; + private String description, title; + private Color color; public OCStoreBlock(String title, String description, ResourceLocation image, int color) { super(color, 200, 400); + this.color = Renderer.getColorFromInt(color); + this.description = description; + this.title = title; + this.image = image; } public void draw(int x, int y) { + super.draw(x, y); + Renderer.drawScaledImage(image, x, y, 200, 100); + super.theme.getFont().drawSplitString("i like fish", x + 2, y + 102, 200, -1); super.update(); } + + public void draw(int x, int y, int width, int height) { + draw(x,y); + } } diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java index 452bc48..01901eb 100644 --- a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java +++ b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java @@ -13,7 +13,9 @@ import java.awt.image.DataBufferInt; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; @@ -248,8 +250,8 @@ public class TrueTypeFont { public int getWidth(String text) { int totalWidth = 0; - IntObject intObject = null; - int currentChar = 0; + IntObject intObject; + int currentChar; for (int i = 0; i < text.length(); i++) { currentChar = text.charAt(i); if (currentChar < 256) { @@ -272,6 +274,40 @@ public class TrueTypeFont { drawString(text, x, y, scaleX, scaleY, ALIGN_LEFT, color); } + public void drawSplitString(String text, float x, float y, int wrapWidth, int color) { + try { // time taken: 0.035ms to do complete cycle + wrapWidth += 140; // it needs this extra to work properly (why?) + List splitString = new ArrayList<>(); + String[] words = text.split("\\W+"); + int totalWidth = 0; + String line = ""; + for(String word : words) { + int width = getWidth(word); + word += " "; // add the space + totalWidth += width; + line += word; + if(totalWidth >= wrapWidth) { // wrap line if it is too long + splitString.add(line); + totalWidth = 0; + line = ""; + } + } + if(!line.equals("")) { // add extra if there is any (last line) + splitString.add(line); + } + int i1 = 0; + for (String string : splitString) { + drawString(string, x, y + i1, 1f, 1f, color); // draw it + i1 += getHeight(); + } + } catch (Exception e) { // be safe kids + e.printStackTrace(); + } + } + + + + public void drawString(String text, float x, float y, float scaleX, float scaleY, int format, int color) { float f = (float) (color >> 16 & 255) / 255.0F; diff --git a/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java deleted file mode 100644 index f436a7b..0000000 --- a/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java +++ /dev/null @@ -1,97 +0,0 @@ -package io.polyfrost.oneconfig.themes; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.crash.CrashReport; -import net.minecraft.util.ReportedException; -import net.minecraft.util.ResourceLocation; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import static io.polyfrost.oneconfig.themes.Themes.themeLog; - -public class TextureManager { - private static final Minecraft mc = Minecraft.getMinecraft(); - private final List resources = new ArrayList<>(); - private final List tickableTextures = new ArrayList<>(); - - /** - * Create a new texture manager for this theme, used for drawing of icons, etc. - */ - public TextureManager(Theme theme) { - for (ThemeElement element : ThemeElement.values()) { - BufferedImage img; - try { - img = ImageIO.read(theme.getResource(element.location)); - } catch (Exception e) { - themeLog.error("failed to get themed texture: " + element.location + ", having to fallback to default one. Is pack invalid?"); - try { - img = ImageIO.read(mc.getResourceManager().getResource(new ResourceLocation("oneconfig", element.location)).getInputStream()); - } catch (IOException ex) { - themeLog.fatal("failed to get fallback texture: " + element.location + ", game will crash :("); - throw new ReportedException(new CrashReport("TextureManager failure: FALLBACK_ERROR_OR_MISSING", ex)); - } - } - ResourceLocation location = mc.getTextureManager().getDynamicTextureLocation(element.location, new DynamicTexture(img)); - resources.add(location); - if (img.getWidth() != element.size) { - themeLog.warn("Theme element " + element.name() + " with size " + img.getWidth() + "px is not recommended, expected " + element.size + "px. Continuing anyway."); - } - if(element.ordinal() < 26) { - if (img.getWidth() != img.getHeight()) { - themeLog.info("found tickable animated texture (" + element.name() + "). Loading texture"); - try { - tickableTextures.add(new TickableTexture(element)); - } catch (IOException e) { - themeLog.error("failed to create TickableTexture " + element.location + ". Just going to load it as a normal texture, this may break things!"); - e.printStackTrace(); - } - } - } else { - if(element.ordinal() < 29) { - if(img.getHeight() != 144 || img.getWidth() != 758) { - themeLog.warn("found badly sized button texture " + element.location); - } - } - } - } - } - - /** - * Draw the specified icon at the coordinates, scaled to the width and height. - * - * @param element element to draw - * @param x x coordinate (top left) - * @param y y coordinate (top left) - * @param width width of the image - * @param height height of the image - */ - public void draw(ThemeElement element, int x, int y, int width, int height) { - GlStateManager.enableBlend(); - GlStateManager.color(1f, 1f, 1f, 1f); - ResourceLocation location = resources.get(element.ordinal()); - mc.getTextureManager().bindTexture(location); - try { - if(!tickableTextures.isEmpty()) { - for (TickableTexture texture : tickableTextures) { - if (texture.getElement().equals(element)) { - texture.draw(x, y); - } else { - Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); - } - } - } else { - Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); - } - GlStateManager.disableBlend(); - } catch (Exception e) { - themeLog.error("Error occurred drawing texture " + element.name() + ", is theme invalid?", e); - } - } -} diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java index 4647397..63450da 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.polyfrost.oneconfig.renderer.Renderer; import io.polyfrost.oneconfig.renderer.TrueTypeFont; +import io.polyfrost.oneconfig.themes.textures.TextureManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.resources.FileResourcePack; diff --git a/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java deleted file mode 100644 index 9e8e061..0000000 --- a/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.polyfrost.oneconfig.themes; - -public enum ThemeElement { - DISCORD("textures/icons/discord.png", 128), - DOCS("textures/icons/docs.png", 128), - FEEDBACK("textures/icons/feedback.png", 128), - GUIDE("textures/icons/guide.png", 128), - HUD_SETTINGS("textures/icons/hudsettings.png", 128), - MOD_SETTINGS("textures/icons/modsettings.png", 128), - STORE("textures/icons/store.png", 128), - THEMES("textures/icons/themes.png", 128), - UPDATE("textures/icons/update.png", 128), - - BACK_ARROW("textures/smallicons/backarrow.png", 32), - FORWARD_ARROW("textures/smallicons/forward.png", 32), - HOME("textures/smallicons/home.png", 32), - SEARCH("textures/smallicons/search.png", 32), - MAGNIFY("textures/smallicons/magnify.png", 64), - MINIMIZE("textures/smallicons/minimize.png", 64), - CLOSE("textures/smallicons/close.png", 64), - - ALL_MODS("textures/mod/allmods.png", 32), - HUD_MODS("textures/mod/hudmods.png", 32), - QOL_MODS("textures/mod/qolmods.png", 32), - HYPIXEL("textures/mod/hypixel.png", 32), - PERFORMANCE("textures/mod/performance.png", 32), - PVP("textures/mod/pvp.png", 32), - SKYBLOCK("textures/mod/skyblock.png", 32), - UTILITIES("textures/mod/utilities.png", 32), - - LOGO("textures/logos/logo.png", 128), - SMALL_LOGO("textures/logos/logo_small.png", 64), - - BUTTON_OFF("textures/window/button_off.png", 758), - BUTTON_HOVER("textures/window/button_hover.png", 758), - BUTTON_CLICK("textures/window/button_click.png", 758), - - BACKGROUND("textures/window/background.png", 1600); - - - public final String location; - public final int size; - - ThemeElement(String location, int size) { - this.location = location; - this.size = size; - } -} diff --git a/src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java b/src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java deleted file mode 100644 index 86022fb..0000000 --- a/src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java +++ /dev/null @@ -1,90 +0,0 @@ -package io.polyfrost.oneconfig.themes; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.util.ResourceLocation; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import static io.polyfrost.oneconfig.themes.Themes.getActiveTheme; -import static io.polyfrost.oneconfig.themes.Themes.themeLog; - -@SuppressWarnings("unused") -public class TickableTexture { - private final int framesToSkip; - private final BufferedImage image; - private final int sizeX, sizeY, frames; - private int tick; - private int tick2; - private final ThemeElement thisElement; - private final ResourceLocation location; - - public TickableTexture(ThemeElement element) throws IOException { - thisElement = element; - InputStream inputStream = getActiveTheme().getResource(element.location); - image = ImageIO.read(inputStream); - location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation(element.location, new DynamicTexture(image)); - sizeX = image.getWidth(); - sizeY = image.getHeight(); - frames = sizeY / sizeX; - int frametime; - try { - JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(getActiveTheme().getResource(element.location + ".json"))).getAsJsonObject(); - frametime = jsonObject.get("frametime").getAsInt(); - if (frametime == 0) { - frametime = 1; - themeLog.warn("You cannot have a frame tick time of 0. This will mean there is no animation as it will happen way too fast. Defaulting to 1, as we assume you wanted it fast."); - } - } catch (Exception e) { - themeLog.error("failed to load metadata for tickable texture (" + element.location + "). Setting default (5)"); - frametime = 5; - } - framesToSkip = frametime; - } - - public void draw(int x, int y) { - GlStateManager.enableBlend(); - GlStateManager.color(1f,1f,1f,1f); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - if (tick < frames) { - Gui.drawModalRectWithCustomSizedTexture(x, y, 0, (tick * sizeX), sizeX, sizeX, sizeX, sizeX); - tick2++; - if (tick2 == framesToSkip) { - tick2 = 0; - tick++; - } - } - if (tick == frames) { - tick = 0; - } - GlStateManager.disableBlend(); - } - - public BufferedImage getImage() { - return image; - } - - public int getFrameTime() { - return framesToSkip; - } - - public int getSizeX() { - return sizeX; - } - - public int getSizeY() { - return sizeY; - } - - public ThemeElement getElement() { - return thisElement; - } -} diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java new file mode 100644 index 0000000..5825fb1 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java @@ -0,0 +1,98 @@ +package io.polyfrost.oneconfig.themes.textures; + +import io.polyfrost.oneconfig.themes.Theme; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.crash.CrashReport; +import net.minecraft.util.ReportedException; +import net.minecraft.util.ResourceLocation; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static io.polyfrost.oneconfig.themes.Themes.themeLog; + +public class TextureManager { + private static final Minecraft mc = Minecraft.getMinecraft(); + private final List resources = new ArrayList<>(); + private final List tickableTextures = new ArrayList<>(); + + /** + * Create a new texture manager for this theme, used for drawing of icons, etc. + */ + public TextureManager(Theme theme) { + for (ThemeElement element : ThemeElement.values()) { + BufferedImage img; + try { + img = ImageIO.read(theme.getResource(element.location)); + } catch (Exception e) { + themeLog.error("failed to get themed texture: " + element.location + ", having to fallback to default one. Is pack invalid?"); + try { + img = ImageIO.read(mc.getResourceManager().getResource(new ResourceLocation("oneconfig", element.location)).getInputStream()); + } catch (IOException ex) { + themeLog.fatal("failed to get fallback texture: " + element.location + ", game will crash :("); + throw new ReportedException(new CrashReport("TextureManager failure: FALLBACK_ERROR_OR_MISSING", ex)); + } + } + ResourceLocation location = mc.getTextureManager().getDynamicTextureLocation(element.location, new DynamicTexture(img)); + resources.add(location); + if (img.getWidth() != element.size) { + themeLog.warn("Theme element " + element.name() + " with size " + img.getWidth() + "px is not recommended, expected " + element.size + "px. Continuing anyway."); + } + if(element.ordinal() < 26) { + if (img.getWidth() != img.getHeight()) { + themeLog.info("found tickable animated texture (" + element.name() + "). Loading texture"); + try { + tickableTextures.add(new TickableTexture(element)); + } catch (IOException e) { + themeLog.error("failed to create TickableTexture " + element.location + ". Just going to load it as a normal texture, this may break things!"); + e.printStackTrace(); + } + } + } else { + if(element.ordinal() < 29) { + if(img.getHeight() != 144 || img.getWidth() != 758) { + themeLog.warn("found badly sized button texture " + element.location); + } + } + } + } + } + + /** + * Draw the specified icon at the coordinates, scaled to the width and height. + * + * @param element element to draw + * @param x x coordinate (top left) + * @param y y coordinate (top left) + * @param width width of the image + * @param height height of the image + */ + public void draw(ThemeElement element, int x, int y, int width, int height) { + GlStateManager.enableBlend(); + GlStateManager.color(1f, 1f, 1f, 1f); + ResourceLocation location = resources.get(element.ordinal()); + mc.getTextureManager().bindTexture(location); + try { + if(!tickableTextures.isEmpty()) { + for (TickableTexture texture : tickableTextures) { + if (texture.getElement().equals(element)) { + texture.draw(x, y); + } else { + Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); + } + } + } else { + Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); + } + GlStateManager.disableBlend(); + } catch (Exception e) { + themeLog.error("Error occurred drawing texture " + element.name() + ", is theme invalid?", e); + } + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java new file mode 100644 index 0000000..096b2aa --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java @@ -0,0 +1,48 @@ +package io.polyfrost.oneconfig.themes.textures; + +public enum ThemeElement { + DISCORD("textures/icons/discord.png", 128), + DOCS("textures/icons/docs.png", 128), + FEEDBACK("textures/icons/feedback.png", 128), + GUIDE("textures/icons/guide.png", 128), + HUD_SETTINGS("textures/icons/hudsettings.png", 128), + MOD_SETTINGS("textures/icons/modsettings.png", 128), + STORE("textures/icons/store.png", 128), + THEMES("textures/icons/themes.png", 128), + UPDATE("textures/icons/update.png", 128), + + BACK_ARROW("textures/smallicons/backarrow.png", 32), + FORWARD_ARROW("textures/smallicons/forward.png", 32), + HOME("textures/smallicons/home.png", 32), + SEARCH("textures/smallicons/search.png", 32), + MAGNIFY("textures/smallicons/magnify.png", 64), + MINIMIZE("textures/smallicons/minimize.png", 64), + CLOSE("textures/smallicons/close.png", 64), + + ALL_MODS("textures/mod/allmods.png", 32), + HUD_MODS("textures/mod/hudmods.png", 32), + QOL_MODS("textures/mod/qolmods.png", 32), + HYPIXEL("textures/mod/hypixel.png", 32), + PERFORMANCE("textures/mod/performance.png", 32), + PVP("textures/mod/pvp.png", 32), + SKYBLOCK("textures/mod/skyblock.png", 32), + UTILITIES("textures/mod/utilities.png", 32), + + LOGO("textures/logos/logo.png", 128), + SMALL_LOGO("textures/logos/logo_small.png", 64), + + BUTTON_OFF("textures/window/button_off.png", 758), + BUTTON_HOVER("textures/window/button_hover.png", 758), + BUTTON_CLICK("textures/window/button_click.png", 758), + + BACKGROUND("textures/window/background.png", 1600); + + + public final String location; + public final int size; + + ThemeElement(String location, int size) { + this.location = location; + this.size = size; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java new file mode 100644 index 0000000..b9882d0 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java @@ -0,0 +1,91 @@ +package io.polyfrost.oneconfig.themes.textures; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import io.polyfrost.oneconfig.themes.textures.ThemeElement; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.util.ResourceLocation; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import static io.polyfrost.oneconfig.themes.Themes.getActiveTheme; +import static io.polyfrost.oneconfig.themes.Themes.themeLog; + +@SuppressWarnings("unused") +public class TickableTexture { + private final int framesToSkip; + private final BufferedImage image; + private final int sizeX, sizeY, frames; + private int tick; + private int tick2; + private final ThemeElement thisElement; + private final ResourceLocation location; + + public TickableTexture(ThemeElement element) throws IOException { + thisElement = element; + InputStream inputStream = getActiveTheme().getResource(element.location); + image = ImageIO.read(inputStream); + location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation(element.location, new DynamicTexture(image)); + sizeX = image.getWidth(); + sizeY = image.getHeight(); + frames = sizeY / sizeX; + int frametime; + try { + JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(getActiveTheme().getResource(element.location + ".json"))).getAsJsonObject(); + frametime = jsonObject.get("frametime").getAsInt(); + if (frametime == 0) { + frametime = 1; + themeLog.warn("You cannot have a frame tick time of 0. This will mean there is no animation as it will happen way too fast. Defaulting to 1, as we assume you wanted it fast."); + } + } catch (Exception e) { + themeLog.error("failed to load metadata for tickable texture (" + element.location + "). Setting default (5)"); + frametime = 5; + } + framesToSkip = frametime; + } + + public void draw(int x, int y) { + GlStateManager.enableBlend(); + GlStateManager.color(1f,1f,1f,1f); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + if (tick < frames) { + Gui.drawModalRectWithCustomSizedTexture(x, y, 0, (tick * sizeX), sizeX, sizeX, sizeX, sizeX); + tick2++; + if (tick2 == framesToSkip) { + tick2 = 0; + tick++; + } + } + if (tick == frames) { + tick = 0; + } + GlStateManager.disableBlend(); + } + + public BufferedImage getImage() { + return image; + } + + public int getFrameTime() { + return framesToSkip; + } + + public int getSizeX() { + return sizeX; + } + + public int getSizeY() { + return sizeY; + } + + public ThemeElement getElement() { + return thisElement; + } +} -- cgit