aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/Window.java16
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java69
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java2
3 files changed, 68 insertions, 19 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);