aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/themes
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/themes')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java82
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/Theme.java136
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java42
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/Themes.java1
4 files changed, 134 insertions, 127 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java
new file mode 100644
index 0000000..749dea6
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java
@@ -0,0 +1,82 @@
+package io.polyfrost.oneconfig.themes;
+
+import javafx.util.Pair;
+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.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<ResourceLocation> resources = new ArrayList<>();
+ private final List<ThemeElement> tickableTextureLocations = new ArrayList<>();
+ private final List<Pair<Integer, Integer>> tickableTextures = new ArrayList<>();
+ private int tick = 0;
+
+ /**
+ * 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?");
+ img = new BufferedImage(128,128,BufferedImage.TYPE_INT_ARGB);
+ // TODO add fallback
+ }
+ 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(img.getWidth() != img.getHeight()) {
+ themeLog.info("found tickable animated texture (" + element.name() + "). Loading texture");
+ tickableTextureLocations.add(element);
+ tickableTextures.add(new Pair<>(img.getWidth(), img.getHeight()));
+ }
+ }
+ }
+
+ /**
+ * 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(tickableTextureLocations.contains(element)) {
+ int texWidth = tickableTextures.get(0).getKey(); // TODO unsure if this works safe
+ int texHeight = tickableTextures.get(0).getValue();
+ int frames = texHeight / texWidth;
+ while(tick < frames) {
+ Gui.drawModalRectWithCustomSizedTexture(x, y, 0, (tick * texWidth), texWidth, texWidth, texWidth, texWidth);
+ tick++;
+ if(tick == frames) {
+ tick = 0;
+ }
+ }
+ } else {
+ Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height);
+ }
+ } 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 cc88e4a..bd6ee80 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
@@ -7,14 +7,11 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.resources.FileResourcePack;
import net.minecraft.util.ResourceLocation;
-import org.jetbrains.annotations.NotNull;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
@SuppressWarnings("unused")
public class Theme extends FileResourcePack {
@@ -36,11 +33,7 @@ public class Theme extends FileResourcePack {
private final String description;
private final String title;
private final int version;
- private final ResourceLocation iconsLoc;
- private final ResourceLocation modIconsLoc;
- private final ResourceLocation smallIconsLoc;
- private final ResourceLocation logoLoc;
- private final ResourceLocation logoLocSmall;
+ private final TextureManager manager;
@@ -89,12 +82,11 @@ public class Theme extends FileResourcePack {
this.description = description;
this.version = version;
- iconsLoc = createLargeIconAtlas();
- smallIconsLoc = createSmallIconAtlas();
- modIconsLoc = createModIconsAtlas();
- logoLoc = getLocationFromName("textures/logos/logo.png");
- logoLocSmall = getLocationFromName("textures/logos/logo_small.png");
- Themes.themeLog.info("Successfully loaded theme and created atlases in " + ((float) (System.nanoTime() - start)) / 1000000f + "ms");
+ manager = new TextureManager(this);
+ if(Themes.VERSION != version) {
+ Themes.themeLog.warn("Theme was made for a different version of OneConfig! This may cause issues in the GUI.");
+ }
+ Themes.themeLog.info("Successfully loaded theme in " + ((float) (System.nanoTime() - start)) / 1000000f + "ms");
}
@@ -116,88 +108,6 @@ public class Theme extends FileResourcePack {
}
- /**
- * Create the large icon atlas from this theme.
- */
- private ResourceLocation createLargeIconAtlas() {
- try {
- List<BufferedImage> icons = new ArrayList<>();
- icons.add(ImageIO.read(getResource("textures/icons/discord.png")));
- icons.add(ImageIO.read(getResource("textures/icons/docs.png")));
- icons.add(ImageIO.read(getResource("textures/icons/feedback.png")));
- icons.add(ImageIO.read(getResource("textures/icons/guide.png")));
- icons.add(ImageIO.read(getResource("textures/icons/hudsettings.png")));
- icons.add(ImageIO.read(getResource("textures/icons/modsettings.png")));
- icons.add(ImageIO.read(getResource("textures/icons/store.png")));
- icons.add(ImageIO.read(getResource("textures/icons/themes.png")));
- icons.add(ImageIO.read(getResource("textures/icons/update.png")));
- return createAtlasFromList(icons, 128);
- } catch (Exception e) {
- Themes.themeLog.error("Failed to create large icon atlas, is pack invalid?", e);
- return null;
- }
- }
-
- /**
- * Create the small icon atlas for this theme.
- */
- private ResourceLocation createSmallIconAtlas() {
- try {
- List<BufferedImage> icons = new ArrayList<>();
- icons.add(ImageIO.read(getResource("textures/smallicons/backarrow.png")));
- icons.add(ImageIO.read(getResource("textures/smallicons/close.png")));
- icons.add(ImageIO.read(getResource("textures/smallicons/forward.png")));
- icons.add(ImageIO.read(getResource("textures/smallicons/home.png")));
- icons.add(ImageIO.read(getResource("textures/smallicons/magnify.png")));
- icons.add(ImageIO.read(getResource("textures/smallicons/minimize.png")));
- icons.add(ImageIO.read(getResource("textures/smallicons/search.png")));
- return createAtlasFromList(icons, 32);
- } catch (Exception e) {
- Themes.themeLog.error("Failed to create small icon atlas, is pack invalid?", e);
- return null;
- }
- }
-
- /**
- * Create mod icon atlas for this theme.
- */
- private ResourceLocation createModIconsAtlas() {
- try {
- List<BufferedImage> icons = new ArrayList<>();
- icons.add(ImageIO.read(getResource("textures/mod/allmods.png")));
- icons.add(ImageIO.read(getResource("textures/mod/hudmods.png")));
- icons.add(ImageIO.read(getResource("textures/mod/hypixel.png")));
- icons.add(ImageIO.read(getResource("textures/mod/performance.png")));
- icons.add(ImageIO.read(getResource("textures/mod/pvp.png")));
- icons.add(ImageIO.read(getResource("textures/mod/qolmods.png")));
- icons.add(ImageIO.read(getResource("textures/mod/skyblock.png")));
- icons.add(ImageIO.read(getResource("textures/mod/utilities.png")));
- return createAtlasFromList(icons, 32);
- } catch (Exception e) {
- Themes.themeLog.error("Failed to create mod icon atlas, is pack invalid?", e);
- return null;
- }
- }
-
-
- /**
- * Create a texture atlas from the given list of images, vertically stacked.
- * @param images List of BufferedImages to use
- * @param imageSize image size in pixels (note: images must be square)
- * @return ResourceLocation of the atlas
- */
- public static ResourceLocation createAtlasFromList(@NotNull List<BufferedImage> images, int imageSize) {
- BufferedImage out = new BufferedImage(imageSize, (images.size() * imageSize), BufferedImage.TYPE_INT_ARGB);
- Graphics2D graphics2D = out.createGraphics();
- int i = 0;
- for (BufferedImage img : images) {
- graphics2D.drawImage(img, null, 0, i);
- i += imageSize;
- }
- graphics2D.dispose();
- return mc.getTextureManager().getDynamicTextureLocation(String.valueOf(i), new DynamicTexture(out));
- }
-
/**
* get a ResourceLocation of an image in the current theme.
@@ -337,38 +247,10 @@ public class Theme extends FileResourcePack {
}
/**
- * Get the large icon atlas.
- */
- public ResourceLocation getLargeIconAtlas() {
- return iconsLoc;
- }
-
- /**
- * Get the small icon atlas.
- */
- public ResourceLocation getSmallIconAtlas() {
- return smallIconsLoc;
- }
-
- /**
- * Get the mod icon atlas.
- */
- public ResourceLocation getModIconsAtlas() {
- return modIconsLoc;
- }
-
- /**
- * Get the logo for OneConfig as specified by this theme.
- */
- public ResourceLocation getOneConfigLogo() {
- return logoLoc;
- }
-
- /**
- * Get the small logo for OneConfig as specified by this theme.
+ * Get the texture manager for this theme, with all drawing utilities.
*/
- public ResourceLocation getSmallOneConfigLogo() {
- return logoLocSmall;
+ public TextureManager getTextureManager() {
+ return manager;
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
new file mode 100644
index 0000000..f0be82a
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
@@ -0,0 +1,42 @@
+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),
+ CLOSE("textures/smallicons/close.png", 32),
+ FORWARD_ARROW("textures/smallicons/forward.png", 32),
+ HOME("textures/smallicons/home.png", 32),
+ MAGNIFY("textures/smallicons/magnify.png", 32),
+ MINIMIZE("textures/smallicons/minimize.png", 32),
+ SEARCH("textures/smallicons/backarrow.png", 32),
+
+ 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", 32);
+
+
+ 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/Themes.java b/src/main/java/io/polyfrost/oneconfig/themes/Themes.java
index 7bff29c..38e5df7 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/Themes.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/Themes.java
@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Objects;
public class Themes {
+ public static final int VERSION = 0;
public static Theme activeTheme;
public static final Logger themeLog = LogManager.getLogger("OneConfig Themes");