aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/themes/textures
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-04-16 14:51:58 +0900
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-04-16 14:51:58 +0900
commitcf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02 (patch)
treec3f2cbfe39919941b9bb04f6de2e3cec103509fd /src/main/java/io/polyfrost/oneconfig/themes/textures
parentf10f1165a7c2ea88ce7bb265d51b52eeaa64d8f8 (diff)
downloadOneConfig-cf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02.tar.gz
OneConfig-cf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02.tar.bz2
OneConfig-cf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02.zip
merge rendering files + remove themes
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/themes/textures')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java113
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java48
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java90
3 files changed, 0 insertions, 251 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java
deleted file mode 100644
index a2e96d4..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java
+++ /dev/null
@@ -1,113 +0,0 @@
-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 org.jetbrains.annotations.NotNull;
-
-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.activeTheme;
-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<TickableTexture> 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 {@link ThemeElement} 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(@NotNull ThemeElement element, int x, int y, int width, int height) {
- if (activeTheme.isReady()) {
- ResourceLocation location = resources.get(element.ordinal());
- mc.getTextureManager().bindTexture(location);
- GlStateManager.enableBlend();
- 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();
- GlStateManager.color(1f, 1f, 1f, 1f);
- } catch (Exception e) {
- themeLog.error("Error occurred drawing texture " + element.name() + ", is theme invalid?", e);
- }
- }
- }
-
- /**
- * Draw the specified {@link ThemeElement} at the coordinates, using its recommended width and height.
- *
- * @param element element to draw
- * @param x x coordinate (top left)
- * @param y y coordinate (top left)
- */
- public void draw(@NotNull ThemeElement element, int x, int y) {
- this.draw(element, x, y, element.size, element.size);
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java
deleted file mode 100644
index 2ab3bc9..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java
+++ /dev/null
@@ -1,48 +0,0 @@
-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("textures/window/button.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
deleted file mode 100644
index 5fe1242..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package io.polyfrost.oneconfig.themes.textures;
-
-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 final ThemeElement thisElement;
- private final ResourceLocation location;
- private int tick;
- private int tick2;
-
- 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 impossibly 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;
- }
-}