diff options
Diffstat (limited to 'src/main/java')
9 files changed, 113 insertions, 30 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java index 62576a9..fa672d5 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java @@ -1,10 +1,8 @@ package io.polyfrost.oneconfig.gui; import io.polyfrost.oneconfig.gui.elements.OCBlock; -import io.polyfrost.oneconfig.gui.elements.OCButton; import io.polyfrost.oneconfig.gui.elements.OCStoreBlock; import io.polyfrost.oneconfig.themes.Theme; -import io.polyfrost.oneconfig.themes.textures.ThemeElement; import io.polyfrost.oneconfig.themes.Themes; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -24,10 +22,11 @@ public class Window extends GuiScreen { long secondCounter = System.currentTimeMillis(); long prevTime = System.currentTimeMillis(); int frames = 0; - OCBlock block = new OCBlock(-1, 100, 200); + OCBlock block = new OCBlock(() -> { + t.getFont().drawString("hi", 10, 10, 1f, 1f, -1); + },750, 144); ResourceLocation example = new ResourceLocation("oneconfig", "textures/hudsettings.png"); OCStoreBlock storeBlock = new OCStoreBlock("OneConfig Theme", "OneConfig default theme with the default look you love.", example, new Color(27,27,27,255).getRGB()); - OCButton button = new OCButton("Mod Settings","Configure all supported mods",ThemeElement.MOD_SETTINGS,false,758, 144); public static ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); public Window() { @@ -74,15 +73,16 @@ public class Window extends GuiScreen { int bottom = (int) (1024 * currentProgress); //Gui.drawRect(left - 1, top - 1, right + 1, bottom + 1, testingColor.getRGB()); //new Color(16, 17, 19, 255).getRGB() - t.getTextureManager().draw(ThemeElement.BACKGROUND, left, top, right, bottom); + //t.getTextureManager().draw(ThemeElement.BACKGROUND, left, top, right, bottom); //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 480, top + 40, 640, 48); - t.getTextureManager().draw(ThemeElement.SEARCH, left + 504, top + 48, 32, 32); - t.getFont().drawString("Search all of OneConfig", left + 548, top + 48, 1.1f, 1f, new Color(242,242,242,255).getRGB()); + //t.getTextureManager().draw(ThemeElement.SEARCH, left + 504, top + 48, 32, 32); + //t.getFont().drawString("Search all of OneConfig", left + 548, top + 48, 1.1f, 1f, new Color(242,242,242,255).getRGB()); + //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1504, top + 32, 64, 64); //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1424, top + 32, 64, 64); //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1344, top + 32, 64, 64); //block.draw(200, 300); - button.draw(500,300); + block.draw(100,200); //t.getTextureManager().draw(ThemeElement.CLOSE, left + 1504, top + 32, 64, 64); //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 100, top + 100, 296, 64); //t.getTextureManager().draw(ThemeElement.CLOSE); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java index 180215c..7b4fd99 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java @@ -5,7 +5,6 @@ import io.polyfrost.oneconfig.themes.Theme; import io.polyfrost.oneconfig.themes.Themes; import io.polyfrost.oneconfig.themes.textures.ThemeElement; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; @@ -38,12 +37,19 @@ public class OCBlock { private boolean rightClicked = false; private int mouseX, mouseY; private boolean hovered; + private float percentHoveredRed = 0f; + private float percentHoveredGreen = 0f; + private float percentHoveredBlue = 0f; + private float percentHoveredAlpha = 0f; + private final Color elementColor = theme.getElementColor(); + private final Color hoverColor = theme.getHoverColor(); + private final Runnable draw; /** - * Create a basic element with nothing. Used for extended classes. + * Create a basic element. */ public OCBlock(int width, int height) { - this(null, false, -1, width, height); + this(null, false, theme.getElementColor().getRGB(), width, height); } /** @@ -51,7 +57,10 @@ public class OCBlock { * @param color color of the element * @param width width of the element * @param height height of the element + * @deprecated + * This method DOES NOT respect the theme colors for the element. Use of {@link #OCBlock(int, int)} is recommended instead. */ + @Deprecated() public OCBlock(int color, int width, int height) { this(null, false, color, width, height); } @@ -60,7 +69,7 @@ public class OCBlock { * Create a new element with the specified text, and automatic width/height + padding. * @param text text to use * @param bold weather or not to use bold text - * @param color color of the background to use + * @param color color for the text */ public OCBlock(@NotNull String text, boolean bold, int color) { this(text, bold, color, theme.getFont().getWidth(text) + 6, theme.getFont().getHeight() + 4); @@ -70,9 +79,10 @@ public class OCBlock { * Create a new element with the specified text, and custom width/height. * @param text text to use * @param bold weather or not to use bold text - * @param color color of the background to use + * @param color color for the text (use {@link Theme#getTextColor()} or {@link Theme#getAccentTextColor()} for default colors) */ public OCBlock(String text, boolean bold, int color, int width, int height) { + this.draw = null; this.text = text; this.bold = bold; this.color = Renderer.getColorFromInt(color); @@ -86,6 +96,7 @@ public class OCBlock { * @param colorMask color mast to use (-1 for default) */ public OCBlock(ThemeElement element, int colorMask, int width, int height) { + this.draw = null; this.element = element; this.color = Renderer.getColorFromInt(colorMask); this.width = width; @@ -94,26 +105,48 @@ public class OCBlock { } /** + * Create a new Element with a custom render script. The {@link Runnable} should ONLY contain #draw() calls or equivalent. + * @param whatToDraw a {@link Runnable}, containing draw scripts for elements. You will need to instantiate the objects first, if they are sub-elements. + */ + public OCBlock(Runnable whatToDraw, int width, int height) { + this.draw = whatToDraw; + this.bold = false; + this.width = width; + this.height = height; + } + + /** * Draw the element at the specified coordinates. */ public void draw(int x, int y) { + GlStateManager.enableBlend(); + percentHoveredRed = smooth(percentHoveredRed, elementColor.getRed() / 255f, hoverColor.getRed() / 255f); + percentHoveredGreen = smooth(percentHoveredGreen, elementColor.getGreen() / 255f, hoverColor.getGreen() / 255f); + percentHoveredBlue = smooth(percentHoveredBlue, elementColor.getBlue() / 255f, hoverColor.getBlue() / 255f); + percentHoveredAlpha = smooth(percentHoveredAlpha, elementColor.getAlpha() / 255f, hoverColor.getAlpha() / 255f); + GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha); update(x, y); + if(draw != null) { + draw.run(); + } if(element != null) { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); theme.getTextureManager().draw(element, x, y, width, height); } if(text == null) { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); } else { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); if(bold) { - theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, -1); + theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, color.getRGB()); } else { - theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, -1); + theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, color.getRGB()); } } + GlStateManager.disableBlend(); + } @@ -137,6 +170,9 @@ public class OCBlock { rightClicked = Mouse.isButtonDown(1); onKeyPress(Keyboard.getEventKey()); } + if(clicked) { + Renderer.color(theme.getClickColor()); + } if(!hovered && clicked) clicked = false; } @@ -174,6 +210,19 @@ public class OCBlock { } + + private float smooth(float current, float min, float max) { + current = Renderer.easeOut(current, isHovered() ? 1f : 0f); + if(current <= min) { + current = min; + } + + if(current >= max) { + current = max; + } + return current; + } + public void setText(String text) { this.text = text; } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java index 2ffeaf7..298690f 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java @@ -63,7 +63,7 @@ public class OCButton extends OCBlock { } GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha); if(isClicked()) { - Renderer.setGlColor(theme.getClickColor()); + //Renderer.setGlColor(theme.getClickColor()); } theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java index 33bbd79..77f5880 100644 --- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java +++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java @@ -72,7 +72,7 @@ public class TextHud extends BasicHud { private void drawText(List<String> lines, int x, int y, float scale) { for (int i = 0; i < lines.size(); i++) { - Renderer.drawTextScale(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale); + Renderer.drawScaledString(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale); } } diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java index 44e1b34..86c63f6 100644 --- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java +++ b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java @@ -1,5 +1,7 @@ package io.polyfrost.oneconfig.renderer; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParser; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -22,11 +24,33 @@ public class Renderer extends Gui { private static final WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - public static void drawRectangle(int left, int top, int right, int bottom, int color) { - Gui.drawRect(left, top, right, bottom, color); + + /** + * Draw a basic rectangle. Please note that this is to be used WITH a {@link net.minecraft.client.renderer.GlStateManager#color(float, float, float)} before to color it. + */ + public static void drawRectangle(int x, int y, int width, int height) { + int right = x + width; + int bottom = y + height; + if (x < right) { + x = right; + } + if (y < bottom) { + y = bottom; + } + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + worldRenderer.begin(7, DefaultVertexFormats.POSITION); + worldRenderer.pos(x, bottom, 0.0D).endVertex(); + worldRenderer.pos(right, bottom, 0.0D).endVertex(); + worldRenderer.pos(right, y, 0.0D).endVertex(); + worldRenderer.pos(x, y, 0.0D).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); } - public static void drawTextScale(String text, float x, float y, int color, boolean shadow, float scale) { + public static void drawScaledString(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); @@ -42,7 +66,7 @@ public class Renderer extends Gui { public static void drawRegularPolygon(double x, double y, int radius, int sides, int color, double lowerAngle, double upperAngle) { GL11.glDisable(GL11.GL_TEXTURE_2D); - setGlColor(color); + color(color); GlStateManager.enableBlend(); GlStateManager.disableAlpha(); worldRenderer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION); @@ -120,14 +144,14 @@ public class Renderer extends Gui { /** * Set GL color from the given Color variable. */ - public static void setGlColor(Color color) { + public static void color(Color color) { GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); } /** * Set GL color from the given color as an Integer. */ - public static void setGlColor(int color) { + public static void color(int color) { float f1 = (float) (color >> 8 & 255) / 255.0F; float f = (float) (color >> 16 & 255) / 255.0F; float f2 = (float) (color & 255) / 255.0F; diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java index 9a51e68..544a7d2 100644 --- a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java +++ b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java @@ -356,7 +356,7 @@ public class TrueTypeFont { GlStateManager.enableAlpha(); GlStateManager.enableBlend(); - Renderer.setGlColor(color); + Renderer.color(color); while (i >= startIndex && i <= endIndex) { charCurrent = text.charAt(i); if (charCurrent < 256) { diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestHud.java b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java index 0ce2984..67f0610 100644 --- a/src/main/java/io/polyfrost/oneconfig/test/TestHud.java +++ b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java @@ -18,6 +18,6 @@ public class TestHud extends BasicHud { @Override public void draw(int x, int y, float scale) { - Renderer.drawTextScale("FPS: " + Minecraft.getDebugFPS(), x, y, 0xffffff, false, scale); + Renderer.drawScaledString("FPS: " + Minecraft.getDebugFPS(), x, y, 0xffffff, false, scale); } } diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java index 9b583ef..4729d6c 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java @@ -67,7 +67,7 @@ public class TextureManager { } /** - * Draw the specified icon at the coordinates, scaled to the width and height. + * 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) @@ -99,4 +99,14 @@ public class TextureManager { } } } + + /** + * 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/TickableTexture.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java index b9882d0..e825be9 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java @@ -42,7 +42,7 @@ public class TickableTexture { 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."); + 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)"); |