diff options
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/themes')
5 files changed, 0 insertions, 614 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java deleted file mode 100644 index 5f2bfac..0000000 --- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java +++ /dev/null @@ -1,310 +0,0 @@ -package io.polyfrost.oneconfig.themes; - -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; -import net.minecraft.crash.CrashReport; -import net.minecraft.util.ReportedException; -import net.minecraft.util.ResourceLocation; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.*; - -@SuppressWarnings("unused") -public class Theme extends FileResourcePack { - private final File themeFile; - private final File themeConfigFile; - private static final Minecraft mc = Minecraft.getMinecraft(); - private final long loadedTime = System.currentTimeMillis(); - private final JsonObject packMetadata; - private final JsonObject packConfig; - private final Color accentColor; - private final Color elementColor; - private final Color titleBarColor; - private final Color baseColor; - private final Color hoverColor; - private final Color clickColor; - private final Color closeColor; - private final Color titleColor; - private final Color subTitleColor; - private final boolean roundCorners; - private final String description; - private final String title; - private final int version; - private final TextureManager manager; - private final TrueTypeFont boldFont; - private final TrueTypeFont normalFont; - private boolean ready; - - - - /** - * Create a new theme instance for the window. - * @param themePack file of the pack - * @throws IOException if an error occurs reading metadata or unpacking, etc. - */ - protected Theme(File themePack) throws IOException { - super(themePack); - ready = false; - long start = System.nanoTime(); - themeFile = themePack; - themeConfigFile = new File(themeFile.getPath() + ".json"); - packMetadata = new JsonParser().parse(new InputStreamReader(getInputStreamByName("pack.json"))).getAsJsonObject(); - try { - unpackConfig(); - } catch (Exception e) { - Themes.themeLog.error("failed to unpack config!", e); - unpackConfig(); - } - packConfig = new JsonParser().parse(new FileReader(themeConfigFile)).getAsJsonObject(); - JsonObject colors = packConfig.getAsJsonObject("colors"); - accentColor = Renderer.getColorFromInt(colors.get("accent_color").getAsInt()); - baseColor = Renderer.getColorFromInt(colors.get("base_color").getAsInt()); - titleBarColor = Renderer.getColorFromInt(colors.get("title_bar").getAsInt()); - elementColor = Renderer.getColorFromInt(colors.get("element_color").getAsInt()); - clickColor = Renderer.getColorFromInt(colors.get("click_color").getAsInt()); - closeColor = Renderer.getColorFromInt(colors.get("close_color").getAsInt()); - titleColor = Renderer.getColorFromInt(colors.get("title_color").getAsInt()); - hoverColor = Renderer.getColorFromInt(colors.get("hover_color").getAsInt()); - subTitleColor = Renderer.getColorFromInt(colors.get("subtitle_color").getAsInt()); - roundCorners = packConfig.get("round_corners").getAsBoolean(); - String title, description; - int version; - try { - title = packMetadata.get("name").getAsString(); - description = packMetadata.get("description").getAsString(); - version = packMetadata.get("version").getAsInt(); - } catch (Exception e) { - title = "null"; - description = "no valid pack.json found!"; - version = -1; - Themes.themeLog.error("pack has invalid metadata! Using default values."); - } - this.title = title; - this.description = description; - this.version = version; - TrueTypeFont normalFontTemp; - TrueTypeFont boldFontTemp; - try { - boldFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, getResource("textures/fonts/font_bold.ttf")).deriveFont(30f), true); - normalFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, getResource("textures/fonts/font.ttf")).deriveFont(18f), true); - } catch (FontFormatException e) { - Themes.themeLog.error("failed to derive fonts, is theme invalid?",e); - e.printStackTrace(); - try { - normalFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, mc.getResourceManager().getResource(new ResourceLocation("oneconfig", "textures/fonts/font.ttf")).getInputStream()).deriveFont(12f), true); - boldFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, mc.getResourceManager().getResource(new ResourceLocation("oneconfig", "textures/fonts/font_bold.ttf")).getInputStream()).deriveFont(30f), true); - } catch (FontFormatException ex) { - ex.printStackTrace(); - throw new ReportedException(new CrashReport("Failed to get fallback fonts! game will crash :(", ex)); - } - } - normalFont = normalFontTemp; - boldFont = boldFontTemp; - 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"); - ready = true; - - } - - /** - * Attempt to unpack the theme default config if it doesn't already exist. - */ - private void unpackConfig() throws IOException { - if (themeConfigFile.createNewFile()) { - Themes.themeLog.warn("Creating config file for theme " + themeFile.getName() + ", assuming it has never been opened before."); - BufferedReader streamReader = new BufferedReader(new InputStreamReader(getInputStreamByName("default_config.json"))); - StringBuilder responseStrBuilder = new StringBuilder(); - String inputStr; - while ((inputStr = streamReader.readLine()) != null) - responseStrBuilder.append(inputStr); - FileWriter fileWriter = new FileWriter(themeConfigFile); - fileWriter.write(responseStrBuilder.toString()); - fileWriter.close(); - } - - } - - - /** - * get a ResourceLocation of an image in the current theme. - * @param name path of the resource (e.g. textures/logos/logo.png) - * @throws IOException if the item cannot be located or pack is corrupt. - */ - public ResourceLocation getLocationFromName(String name) throws IOException { - return mc.getTextureManager().getDynamicTextureLocation(name, new DynamicTexture(ImageIO.read(getInputStreamByName(name)))); - } - - - - /** - * Get the accent color for the window, used on separators, lines, etc. - */ - public Color getAccentColor() { - return accentColor; - } - /** - * Get the base color for the window, used for the main background. - */ - public Color getBaseColor() { - return baseColor; - } - /** - * Get the color used for the title bar. - */ - public Color getTitleBarColor() { - return titleBarColor; - } - /** - * Get the base color for the buttons, items, and most elements. - */ - public Color getElementColor() { - return elementColor; - } - /** - * Get the accent color for elements when they are hovered. - */ - public Color getHoverColor() { - return hoverColor; - } - /** - * Get the accent color for elements when they are clicked. - */ - public Color getClickColor() { - return clickColor; - } - /** - * Get the color for the close/destroy buttons. - */ - public Color getCloseColor() { - return closeColor; - } - /** - * Get the color for the main text, like titles, config element items, etc. - */ - public Color getTextColor() { - return titleColor; - } - /** - * Get the accent color for the text, used for subtitles, etc. - */ - public Color getAccentTextColor() { - return subTitleColor; - } - /** - * Weather or not to round off the corners of pretty much every element. - */ - public boolean shouldRoundCorners() { - return roundCorners; - } - - - /** - * Get the InputStream of a resource in the pack. - * @param name name of the resource - * @throws IOException an error occurs reading - */ - public InputStream getResource(String name) throws IOException { - return getInputStreamByName(name); - } - - /** - * Get this pack's metadata json. - */ - public JsonObject getPackMetaData() { - return packMetadata; - } - - /** - * Get the pack's config file. - */ - public JsonObject getPackConfig() { - return packConfig; - } - - /** - * Get the pack's description. - */ - public String getDescription() { - return description; - } - - /** - * Get the friendly name of the pack. - */ - public String getName() { - return title; - } - - /** - * Get the pack's title image. - */ - public BufferedImage getImage() { - try { - return getPackImage(); - } catch (IOException e) { - Themes.themeLog.error("Failed to parse pack image. Is pack invalid??"); - //e.printStackTrace(); - } - return null; - } - - /** - * Get the pack's version. Not used yet, but will be when more features are added for theme compatability. - */ - public int getVersion() { - return version; - } - - /** - * Get the source file of this theme. - */ - public File getThemeFile() { - return themeFile; - } - - /** - * Get the texture manager for this theme, with all drawing utilities. - */ - public TextureManager getTextureManager() { - return manager; - } - - /** - * Get the font from this theme. - */ - public TrueTypeFont getFont() { - return normalFont; - } - - /** - * Get the bold, larger font from this theme. - */ - public TrueTypeFont getBoldFont() { - return boldFont; - } - - /** - * Get the time this theme was loaded. (used for debugging) - */ - public long getLoadedTime() { - return loadedTime; - } - - /** - * Check if the theme is fully loaded or not. - */ - public boolean isReady() { - return ready; - } -} diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Themes.java b/src/main/java/io/polyfrost/oneconfig/themes/Themes.java deleted file mode 100644 index 240c97d..0000000 --- a/src/main/java/io/polyfrost/oneconfig/themes/Themes.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.polyfrost.oneconfig.themes; - -import io.polyfrost.oneconfig.OneConfig; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.Arrays; -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"); - - /** - * Return a list of all available themes in the directory. - * @return list of themes - */ - public static List<File> getThemes() { - FilenameFilter filter = (dir, name) -> name.endsWith(".zip"); - return Arrays.asList(Objects.requireNonNull(OneConfig.themesDir.listFiles(filter))); - } - - /** - * Return the active theme instance. - */ - public static Theme getActiveTheme() { - return activeTheme; - } - - /** - * Open a new theme in the window, and restart the GUI. - * @param theme Theme file to open - */ - public static void openTheme(File theme) { - try { - activeTheme = new Theme(theme); - } catch (IOException e) { - e.printStackTrace(); - } - // TODO restart gui - } - - - public String toString() { - return "OneConfig Theme {loaded=" + activeTheme.getLoadedTime() + ", name=" + activeTheme.getName() + ", desc=" + activeTheme.getDescription() + ", ready=" + activeTheme.isReady() + "}"; - } - -} 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; - } -} |