diff options
| author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-04 14:53:10 +0200 |
|---|---|---|
| committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-04 14:53:10 +0200 |
| commit | ddca3a3232eff15a7130efda03e7e5c408554412 (patch) | |
| tree | ef7678412590ca432bb2cd25aabfc3bf2ea4b7b0 /src/main/java/io/polyfrost/oneconfig/gui | |
| parent | 1210e38c2ff569a28b20d7d0182557fbf386d524 (diff) | |
| parent | 2696141f9790fd6c8d3df1148f46d298512c4902 (diff) | |
| download | OneConfig-ddca3a3232eff15a7130efda03e7e5c408554412.tar.gz OneConfig-ddca3a3232eff15a7130efda03e7e5c408554412.tar.bz2 OneConfig-ddca3a3232eff15a7130efda03e7e5c408554412.zip | |
merge
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui')
4 files changed, 115 insertions, 62 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..abcd5ca 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; @@ -22,9 +21,10 @@ import static io.polyfrost.oneconfig.gui.Window.resolution; public class OCBlock { public static final Theme theme = Themes.getActiveTheme(); private static final Minecraft mc = Minecraft.getMinecraft(); - private Color color; - private String text; private final boolean bold; + private final Color elementColor = theme.getElementColor(); + private final Color hoverColor = theme.getHoverColor(); + private final Runnable draw; /** * Width of the element in pixels. */ @@ -33,34 +33,44 @@ public class OCBlock { * Height of the element in pixels. */ public int height; + private Color color; + private String text; private ThemeElement element; private boolean clicked = false; 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; /** - * 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); } /** * Create a new basic element. - * @param color color of the element - * @param width width of the element + * + * @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); } /** * 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 text text to use + * @param bold weather or not to use bold text + * @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); @@ -68,11 +78,13 @@ 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 text text to use + * @param bold weather or not to use bold text + * @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); @@ -82,10 +94,12 @@ public class OCBlock { /** * Create a new Element with the specified image. - * @param element element to use + * + * @param element element to use * @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 +108,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(element != null) { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); + if (draw != null) { + draw.run(); + } + if (element != null) { + 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()); - } - else { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); - if(bold) { - theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, -1); + if (text == null) { + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); + } else { + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); + if (bold) { + 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(); + } @@ -124,7 +160,7 @@ public class OCBlock { int mouseX = Mouse.getX() / resolution.getScaleFactor(); int mouseY = Math.abs((Mouse.getY() / resolution.getScaleFactor()) - resolution.getScaledHeight()); hovered = mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; - if(hovered) { + if (hovered) { onHover(); if (Mouse.isButtonDown(0) && !clicked) { onClick(0); @@ -137,7 +173,10 @@ public class OCBlock { rightClicked = Mouse.isButtonDown(1); onKeyPress(Keyboard.getEventKey()); } - if(!hovered && clicked) clicked = false; + if (clicked) { + Renderer.color(theme.getClickColor()); + } + if (!hovered && clicked) clicked = false; } /** @@ -152,6 +191,7 @@ public class OCBlock { /** * Override this method to set a function when a key is pressed while this element is hovered. + * * @param keyCode key code that was pressed (check org.lwjgl.Keyboard for keymap) */ public void onKeyPress(int keyCode) { @@ -160,6 +200,7 @@ public class OCBlock { /** * Override this method to set a function when the element is hovered. + * * @param button the button that was pressed (0 is left, 1 is right) */ public void onClick(int button) { @@ -174,36 +215,49 @@ public class OCBlock { } - public void setText(String text) { - this.text = text; - } - public void setWidth(int width) { - this.width = width; - } + private float smooth(float current, float min, float max) { + current = Renderer.easeOut(current, isHovered() ? 1f : 0f); + if (current <= min) { + current = min; + } - public void setHeight(int height) { - this.height = height; + if (current >= max) { + current = max; + } + return current; } public int getHeight() { return height; } + public void setHeight(int height) { + this.height = height; + } + public Color getColor() { return color; } + public void setColor(Color color) { + this.color = color; + } + public int getWidth() { return width; } + public void setWidth(int width) { + this.width = width; + } + public String getText() { return text; } - public void setColor(Color color) { - this.color = color; + public void setText(String text) { + this.text = text; } public boolean isHovered() { 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..5f78baa 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java @@ -8,13 +8,13 @@ import org.jetbrains.annotations.NotNull; import java.awt.*; public class OCButton extends OCBlock { + private final Color elementColor = theme.getElementColor(); + private final Color hoverColor = theme.getHoverColor(); private float percentHoveredRed = 0f; private float percentHoveredGreen = 0f; private float percentHoveredBlue = 0f; private float percentHoveredAlpha = 0f; private float percentDescription = 0f; - private final Color elementColor = theme.getElementColor(); - private final Color hoverColor = theme.getHoverColor(); private ThemeElement element; private boolean alwaysShowDesc = true; private String title, description; @@ -58,27 +58,27 @@ public class OCButton extends OCBlock { 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); - if(!alwaysShowDesc) { + if (!alwaysShowDesc) { percentDescription = Renderer.clamp(Renderer.easeOut(percentDescription, isHovered() ? 1f : 0f)); } GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha); - if(isClicked()) { - Renderer.setGlColor(theme.getClickColor()); + if (isClicked()) { + //Renderer.setGlColor(theme.getClickColor()); } theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); - if(element != null) { - GlStateManager.color(1f,1f,1f, isClicked() ? 0.6f : 1f); + if (element != null) { + GlStateManager.color(1f, 1f, 1f, isClicked() ? 0.6f : 1f); theme.getTextureManager().draw(element, x + 19, y + 8, element.size, element.size); - if(title != null) { - if(alwaysShowDesc) { + if (title != null) { + if (alwaysShowDesc) { theme.getBoldFont().drawString(title, x + element.size + 25, y + 30, 1.2f, 1.2f, isClicked() ? theme.getTextColor().darker().getRGB() : theme.getTextColor().getRGB()); theme.getFont().drawString(description, x + element.size + 25, y + theme.getBoldFont().getHeight() + 37, 1.2f, 1.2f, isClicked() ? theme.getAccentTextColor().darker().getRGB() : theme.getAccentTextColor().getRGB()); } else { int titleY = y + 48; titleY -= (int) (percentDescription * 18); Color targetColor = theme.getAccentTextColor(); - Color currentColor = isClicked() ? targetColor.darker() : new Color(targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue(), (int) (targetColor.getAlpha() * percentDescription)); + Color currentColor = isClicked() ? targetColor.darker() : new Color(targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue(), (int) (targetColor.getAlpha() * percentDescription)); theme.getFont().drawString(description, x + element.size + 25, y + theme.getBoldFont().getHeight() + 37, 1.2f, 1.2f, currentColor.getRGB()); theme.getBoldFont().drawString(title, x + element.size + 25, titleY, 1.2f, 1.2f, isClicked() ? theme.getTextColor().darker().getRGB() : theme.getTextColor().getRGB()); } @@ -89,11 +89,11 @@ public class OCButton extends OCBlock { private float smooth(float current, float min, float max) { current = Renderer.easeOut(current, isHovered() ? 1f : 0f); - if(current <= min) { + if (current <= min) { current = min; } - if(current >= max) { + if (current >= max) { current = max; } return current; diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java index 3d23b2f..d7fa7e9 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java @@ -1,16 +1,15 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.renderer.Renderer; -import io.polyfrost.oneconfig.themes.textures.ThemeElement; -import net.minecraft.client.gui.Gui; import net.minecraft.util.ResourceLocation; import java.awt.*; public class OCStoreBlock extends OCBlock { - private ResourceLocation image; - private String description, title; - private Color color; + private final ResourceLocation image; + private final String description; + private final String title; + private final Color color; public OCStoreBlock(String title, String description, ResourceLocation image, int color) { super(color, 300, 400); @@ -31,6 +30,6 @@ public class OCStoreBlock extends OCBlock { } public void draw(int x, int y, int width, int height) { - draw(x,y); + draw(x, y); } } |
