aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/Window.java28
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java21
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java61
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/Theme.java38
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java8
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java90
6 files changed, 201 insertions, 45 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
index d20a203..aea1851 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
@@ -1,5 +1,6 @@
package io.polyfrost.oneconfig.gui;
+import io.polyfrost.oneconfig.renderer.Renderer;
import io.polyfrost.oneconfig.renderer.TrueTypeFont;
import io.polyfrost.oneconfig.themes.Theme;
import io.polyfrost.oneconfig.themes.ThemeElement;
@@ -10,6 +11,7 @@ import net.minecraft.client.gui.GuiScreen;
import java.awt.*;
import java.io.IOException;
+import java.util.Objects;
import static io.polyfrost.oneconfig.renderer.Renderer.clamp;
import static io.polyfrost.oneconfig.renderer.Renderer.easeOut;
@@ -23,7 +25,7 @@ public class Window extends GuiScreen {
public Window() {
try {
- Font tempFont = Font.createFont(Font.TRUETYPE_FONT, Window.class.getResourceAsStream("/assets/oneconfig/fonts/font.ttf"));
+ Font tempFont = Font.createFont(Font.TRUETYPE_FONT, Objects.requireNonNull(Window.class.getResourceAsStream("/assets/oneconfig/fonts/font.ttf")));
font = new TrueTypeFont(tempFont.deriveFont(30f), true);
} catch (FontFormatException | IOException e) {
e.printStackTrace();
@@ -51,19 +53,23 @@ public class Window extends GuiScreen {
//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());
+ int left = middleX - 800;
+ int right = (int) (1600 * currentProgress);
+ int top = middleY - 512;
+ int bottom = (int) (1024 * currentProgress);
+ //Gui.drawRect(left - 1, top - 1, right + 1, bottom + 1, testingColor.getRGB());
+ //new Color(16, 17, 19, 255).getRGB()
+ Renderer.drawRoundRect(left,top,right,bottom,30, testingColor.getRGB());
+ Renderer.drawRoundRect(left + 1,top + 1,right - 2,bottom - 2,30, t.getBaseColor().getRGB());
+ t.getTextureManager().draw(ThemeElement.LOGO, left + 24, top + 24, 64, 64); // 0.875
+ font.drawString("OneConfig", left + 93f, top + 25, 1f,1f);
+ //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());
+ //Gui.drawRect(left, top, right, top + 100, t.getTitleBarColor().getRGB());
+ //Gui.drawRect(left, top + 100, right, top + 101, testingColor.getRGB());
- t.getTextureManager().draw(ThemeElement.ALL_MODS, 10, 10, 32, 32);
- font.drawString("OneConfig is pog!\nWow, this font renderer actually works :D", 50, 50, 1, 1);
+ //font.drawString("OneConfig is pog!\nWow, this font renderer actually works :D", 50, 50, 1f, 1f);
}
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 235371f..d5febec 100644
--- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
+++ b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
@@ -1,5 +1,6 @@
package io.polyfrost.oneconfig.renderer;
+import gg.essential.universal.UGraphics;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
@@ -10,7 +11,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.*;
import java.awt.*;
@@ -52,9 +53,14 @@ public class Renderer extends Gui {
GlStateManager.disableAlpha();
worldRenderer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION);
worldRenderer.pos(x, y, 0).endVertex();
- GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST);
- GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
+ //GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST);
+ //GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
+ //GL11.glCullFace(GL11.GL_FRONT);
+ //GL11.glCullFace(GL11.GL_FRONT_AND_BACK);
+ //GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
+ //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
+ //GL11.glEnable(ARBMultisample.GL_MULTISAMPLE_ARB);
+
for (int i = 0; i <= sides; i++) {
double angle = ((Math.PI * 2) * i / sides) + Math.toRadians(180);
@@ -64,12 +70,12 @@ public class Renderer extends Gui {
}
tessellator.draw();
GlStateManager.disableBlend();
- GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
+ //GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
public static void drawRegularPolygon(double x, double y, int radius, int sides, int color) {
- drawRegularPolygon(x, y, radius, sides, color, 0d, 10d);
+ drawRegularPolygon(x, y, radius, sides, color, 0d, 10000d);
}
/**
@@ -79,7 +85,7 @@ public class Renderer extends Gui {
*/
public static void drawRoundRect(double x, double y, double width, double height, int radius, int color) {
GL11.glEnable(GL11.GL_BLEND);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
+ //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
Gui.drawRect((int) x + radius, (int) y, (int) (x + width - radius), (int) (y + radius), color); // top
Gui.drawRect((int) x + radius, (int) (y + height - radius), (int) (x + width - radius), (int) (y + height), color); // bottom
Gui.drawRect((int) x, (int) y + radius, (int) (x + width), (int) (y + height - radius), color); // main
@@ -88,6 +94,7 @@ public class Renderer extends Gui {
drawRegularPolygon(x + radius, y + height - radius, radius, 80, color, 4.7d, 6.3d); // bottom left
drawRegularPolygon(x + width - radius, y + height - radius, radius, 80, color, 6.25d, 7.9d); // bottom right
GL11.glDisable(GL11.GL_BLEND);
+ GL11.glColor4f(1f,1f,1f,1f);
}
public static float clamp(float number) {
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java
index fd636f2..6406e1b 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/TextureManager.java
@@ -4,12 +4,14 @@ 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.HashMap;
import java.util.List;
import static io.polyfrost.oneconfig.themes.Themes.themeLog;
@@ -17,43 +19,54 @@ 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 HashMap<Integer, Integer> tickableTextures = new HashMap<>();
- private int tick = 0;
+ 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()) {
+ 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
+ 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) {
+ 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.put(img.getWidth(), img.getHeight());
+ 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 {
+
}
}
}
/**
* 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
+ * @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();
@@ -61,20 +74,18 @@ public class TextureManager {
ResourceLocation location = resources.get(element.ordinal());
mc.getTextureManager().bindTexture(location);
try {
- if(tickableTextureLocations.contains(element)) {
- int texWidth = tickableTextures.keySet().stream().findFirst().get(); // TODO unsure if this works safe
- int texHeight = tickableTextures.values().stream().findFirst().get();
- int frames = texHeight / texWidth;
- while(tick < frames) {
- Gui.drawModalRectWithCustomSizedTexture(x, y, 0, (tick * texWidth), texWidth, texWidth, texWidth, texWidth);
- tick++;
- if(tick == frames) {
- tick = 0;
+ 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 bd6ee80..9e67799 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
@@ -3,9 +3,12 @@ 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 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;
@@ -34,6 +37,8 @@ public class Theme extends FileResourcePack {
private final String title;
private final int version;
private final TextureManager manager;
+ private final TrueTypeFont boldFont;
+ private final TrueTypeFont normalFont;
@@ -81,7 +86,24 @@ public class Theme extends FileResourcePack {
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(12f), 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.");
@@ -253,4 +275,18 @@ public class Theme extends FileResourcePack {
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;
+ }
+
}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
index f0be82a..818bfdf 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
@@ -29,7 +29,13 @@ public enum ThemeElement {
UTILITIES("textures/mod/utilities.png", 32),
LOGO("textures/logos/logo.png", 128),
- SMALL_LOGO("textures/logos/logo_small.png", 32);
+ SMALL_LOGO("textures/logos/logo_small.png", 64),
+
+ BUTTON_OFF("textures/window/button_off.png", 512),
+ BUTTON_HOVER("textures/window/button_hover.png", 512),
+ BUTTON_CLICK("textures/window/button_click.png", 512),
+
+ BACKGROUND("textures/window/background.png", 1600);
public final String location;
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java b/src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java
new file mode 100644
index 0000000..86022fb
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/themes/TickableTexture.java
@@ -0,0 +1,90 @@
+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;
+ }
+}