aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authornextdaydelivery <12willettsh@gmail.com>2022-02-12 13:02:02 +0000
committernextdaydelivery <12willettsh@gmail.com>2022-02-12 13:02:02 +0000
commitaba637fd14fbcbda7e036874d164ddba8236e739 (patch)
tree57fcded0100b95bb6f6c0cae86c142c57c46edb7 /src/main/java/io
parent2231da6af9982840fa9d3bd24c4333bdbbe19cc2 (diff)
downloadOneConfig-aba637fd14fbcbda7e036874d164ddba8236e739.tar.gz
OneConfig-aba637fd14fbcbda7e036874d164ddba8236e739.tar.bz2
OneConfig-aba637fd14fbcbda7e036874d164ddba8236e739.zip
more theme stuff
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java7
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/Window.java28
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java14
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/Theme.java151
5 files changed, 150 insertions, 52 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index 6f58f52..1816427 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -1,6 +1,7 @@
package io.polyfrost.oneconfig;
import io.polyfrost.oneconfig.command.OneConfigCommand;
+import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
@@ -29,5 +30,6 @@ public class OneConfig {
public void onFMLInitialization(FMLInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new OneConfigCommand());
MinecraftForge.EVENT_BUS.register(this);
+ Themes.openTheme(new File("C:\\Users\\Harry\\Documents\\Coding\\Minecraft\\Forge1.8.9\\OneConfig\\run\\OneConfig\\Themes\\one.zip"));
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
index 3433c56..d462c5e 100644
--- a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
+++ b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
@@ -1,14 +1,17 @@
package io.polyfrost.oneconfig.command;
import io.polyfrost.oneconfig.gui.Window;
+import io.polyfrost.oneconfig.themes.Themes;
import io.polyfrost.oneconfig.utils.TickDelay;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
+import net.minecraft.util.ChatComponentText;
import org.jetbrains.annotations.NotNull;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -41,6 +44,10 @@ public class OneConfigCommand implements ICommand {
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
new TickDelay(() -> mc.displayGuiScreen(new Window()), 1);
+ if(args != null) {
+ mc.thePlayer.addChatMessage(new ChatComponentText("hi"));
+ Themes.openTheme(new File("C:\\Users\\Harry\\Documents\\Coding\\Minecraft\\Forge1.8.9\\OneConfig\\run\\OneConfig\\Themes\\one.zip"));
+ }
}
@Override
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
index ed4e0cd..c15356c 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
@@ -1,19 +1,20 @@
package io.polyfrost.oneconfig.gui;
import io.polyfrost.oneconfig.renderer.Renderer;
+import io.polyfrost.oneconfig.themes.Theme;
+import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.renderer.GlStateManager;
-import net.minecraft.util.ResourceLocation;
import java.awt.*;
+import static io.polyfrost.oneconfig.renderer.Renderer.clamp;
import static io.polyfrost.oneconfig.renderer.Renderer.easeOut;
public class Window extends GuiScreen {
- private static ResourceLocation location = new ResourceLocation("oneconfig", "textures/hudsettings128.png");
private float currentProgress = 0f;
public static Window currentWindow;
+ private final Theme t = Themes.getActiveTheme();
public Window() {
super.initGui();
@@ -26,15 +27,30 @@ public class Window extends GuiScreen {
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
- currentProgress = easeOut(currentProgress, 1f);
+ currentProgress = clamp(easeOut(currentProgress, 1f));
int alphaVal = (int) (50 * currentProgress);
- //drawGradientRect(0, 0, super.width, super.height, new Color(80, 80, 80, alphaVal).getRGB(), new Color(80, 80, 80, alphaVal + 10).getRGB());
+ drawGradientRect(0, 0, super.width, super.height, new Color(80, 80, 80, alphaVal).getRGB(), new Color(80, 80, 80, alphaVal + 10).getRGB());
drawWindow();
}
public void drawWindow() {
-
+ Color testingColor = new Color(127, 144, 155, 255);
+ //System.out.println(testingColor.getRGB());
+ int middleX = this.width / 2;
+ int middleY = this.height / 2;
+ int left = middleX - 600;
+ int right = (int) (left + 1200 * currentProgress);
+ int top = middleY - 350;
+ int bottom = (int) (top + 700 * currentProgress);
+ Gui.drawRect(left -1, top - 1, right + 1, bottom + 1, testingColor.getRGB());
+ Gui.drawRect(left,top,right,bottom,t.getBaseColor().getRGB());
+
+ Gui.drawRect(left, top, right, top + 100, t.getTitleBarColor().getRGB());
+ Gui.drawRect(left, top + 100, right, top + 101, testingColor.getRGB());
+
+ //ResourceLocation location = mc.getRenderManager().renderEngine.getDynamicTextureLocation("oneconfig",new DynamicTexture(ImageIO.read(t.getResource("assets/textures/icons/hudsettings128.png"))));
+ Renderer.drawScaledImage(t.getIcons(), left + 10, top + 10, 128, 1152);
}
public static Window getWindow() {
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
index 19d8710..f8612b7 100644
--- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
+++ b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
@@ -3,6 +3,7 @@ package io.polyfrost.oneconfig.renderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
+import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import java.awt.*;
@@ -15,12 +16,16 @@ public class Renderer extends Gui {
Gui.drawRect(left, top, right, bottom, color);
}
- public static void drawString(String text, int x, int y, int color, boolean shadow) {
- fr.drawString(text, x, y, color, shadow);
+ public static void drawTextScale(String text, float x, float y, int color, boolean shadow, float scale) {
+ GlStateManager.pushMatrix();
+ GlStateManager.scale(scale, scale, 1);
+ mc.fontRendererObj.drawString(text, x * (1 / scale), y * (1 / scale), color, shadow);
+ GlStateManager.popMatrix();
}
public static void drawScaledImage(ResourceLocation location, int x, int y, int targetX, int targetY) {
- //GlStateManager.color(1f, 1f, 1f, 1f);
+ GlStateManager.enableBlend();
+ GlStateManager.color(1f, 1f, 1f, 1f);
mc.getTextureManager().bindTexture(location);
Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, targetX, targetY, targetX, targetY, targetX, targetY);
}
@@ -29,6 +34,9 @@ public class Renderer extends Gui {
}
+ public static float clamp(float number) {
+ return number < (float) 0.0 ? (float) 0.0 : Math.min(number, (float) 1.0);
+ }
public static float easeOut(float current, float goal) {
if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) {
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
index 59b5767..a9b31a9 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
@@ -4,11 +4,16 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.polyfrost.oneconfig.renderer.Renderer;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.resources.FileResourcePack;
+import net.minecraft.util.ResourceLocation;
+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 {
@@ -17,6 +22,20 @@ public class Theme extends FileResourcePack {
private static final Minecraft mc = Minecraft.getMinecraft();
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 ResourceLocation iconsLoc;
/**
* Create a new theme instance for the window.
@@ -35,6 +54,34 @@ public class Theme extends FileResourcePack {
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;
+
+ iconsLoc = createIconAtlas();
}
/**
@@ -55,75 +102,101 @@ public class Theme extends FileResourcePack {
}
+ // TIME CALC
+ // long start = System.nanoTime();
+ // System.out.println(((float) (System.nanoTime() - start)) / 1000000f + "ms");
+
+ /**
+ * Create the large icon atlas from this theme.
+ */
+ private ResourceLocation createIconAtlas() { // TODO finish for all atlases
+ try {
+ List<BufferedImage> icons = new ArrayList<>();
+ BufferedImage out = new BufferedImage(128, 1152, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D graphics2D = out.createGraphics();
+ int i = 0;
+ 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")));
+ for (BufferedImage img : icons) {
+ graphics2D.drawImage(img, null, 0, i);
+ i += 128;
+ }
+ graphics2D.dispose();
+ return mc.getTextureManager().getDynamicTextureLocation("OneConfigIconAtlas", new DynamicTexture(out));
+ } catch (Exception e) {
+ Themes.themeLog.error("Failed to create large icon atlas", e);
+ return null;
+ }
+ }
+
+
+
/**
* Get the accent color for the window, used on separators, lines, etc.
*/
public Color getAccentColor() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("accent_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ return accentColor;
}
/**
* Get the base color for the window, used for the main background.
*/
public Color getBaseColor() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("base_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ 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() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("element_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ return elementColor;
}
/**
* Get the accent color for elements when they are hovered.
*/
public Color getHoverColor() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("hover_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ return hoverColor;
}
/**
* Get the accent color for elements when they are clicked.
*/
public Color getClickColor() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("click_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ return clickColor;
}
/**
* Get the color for the close/destroy buttons.
*/
public Color getCloseColor() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("base_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ return closeColor;
}
/**
* Get the color for the main text, like titles, config element items, etc.
*/
public Color getTextColor() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("title_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ return titleColor;
}
/**
* Get the accent color for the text, used for subtitles, etc.
*/
public Color getAccentTextColor() {
- JsonObject colors = packConfig.getAsJsonObject("colors");
- int accentColor = colors.get("subtitle_color").getAsInt();
- return Renderer.getColorFromInt(accentColor);
+ return subTitleColor;
}
/**
* Weather or not to round off the corners of pretty much every element.
*/
public boolean shouldRoundCorners() {
- return packConfig.get("round_corners").getAsBoolean();
+ return roundCorners;
}
@@ -154,24 +227,14 @@ public class Theme extends FileResourcePack {
* Get the pack's description.
*/
public String getDescription() {
- try {
- return packMetadata.get("description").getAsString();
- } catch (Exception e) {
- Themes.themeLog.error("Failed to get pack name. Defaulting to 'error occurred', is pack invalid??");
- }
- return "Couldn't get description!";
+ return description;
}
/**
* Get the friendly name of the pack.
*/
public String getName() {
- try {
- return packMetadata.get("name").getAsString();
- } catch (Exception e) {
- Themes.themeLog.error("Failed to get pack name. Defaulting to 'null', is pack invalid??");
- }
- return "null";
+ return title;
}
@@ -189,15 +252,17 @@ public class Theme extends FileResourcePack {
}
/**
+ * Get the large icon atlas.
+ */
+ public ResourceLocation getIcons() {
+ return iconsLoc;
+ }
+
+ /**
* Get the pack's version. Not used yet, but will be when more features are added for theme compatability.
*/
public int getVersion() {
- try {
- return packMetadata.get("version").getAsInt();
- } catch (Exception e) {
- Themes.themeLog.error("Failed to get pack version. Is pack invalid?");
- }
- return 0;
+ return version;
}
/**