aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/gui/elements
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java30
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java105
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java13
3 files changed, 135 insertions, 13 deletions
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 fcce48b..180215c 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
@@ -2,11 +2,10 @@ package io.polyfrost.oneconfig.gui.elements;
import io.polyfrost.oneconfig.renderer.Renderer;
import io.polyfrost.oneconfig.themes.Theme;
-import io.polyfrost.oneconfig.themes.textures.ThemeElement;
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.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
@@ -16,6 +15,9 @@ import java.awt.*;
import static io.polyfrost.oneconfig.gui.Window.resolution;
+/**
+ * Default simple block for all the GUI elements. If you are making custom ones, your class should extend this one.
+ */
@SuppressWarnings("unused")
public class OCBlock {
public static final Theme theme = Themes.getActiveTheme();
@@ -23,13 +25,26 @@ public class OCBlock {
private Color color;
private String text;
private final boolean bold;
- protected int width, height;
+ /**
+ * Width of the element in pixels.
+ */
+ public int width;
+ /**
+ * Height of the element in pixels.
+ */
+ public int height;
private ThemeElement element;
private boolean clicked = false;
private boolean rightClicked = false;
private int mouseX, mouseY;
private boolean hovered;
- private int x, y;
+
+ /**
+ * Create a basic element with nothing. Used for extended classes.
+ */
+ public OCBlock(int width, int height) {
+ this(null, false, -1, width, height);
+ }
/**
* Create a new basic element.
@@ -82,8 +97,7 @@ public class OCBlock {
* Draw the element at the specified coordinates.
*/
public void draw(int x, int y) {
- this.x = x;
- this.y = y;
+ update(x, y);
if(element != null) {
Gui.drawRect(x, y, x + width, y + height, color.getRGB());
GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
@@ -106,8 +120,7 @@ public class OCBlock {
/**
* Update this elements click, key and hover status. Call this method at the end of your 'draw' function, if overridden.
*/
- public void update() {
- resolution = new ScaledResolution(mc);
+ public void update(int x, int y) {
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;
@@ -124,6 +137,7 @@ public class OCBlock {
rightClicked = Mouse.isButtonDown(1);
onKeyPress(Keyboard.getEventKey());
}
+ if(!hovered && clicked) clicked = false;
}
/**
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
new file mode 100644
index 0000000..2ffeaf7
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
@@ -0,0 +1,105 @@
+package io.polyfrost.oneconfig.gui.elements;
+
+import io.polyfrost.oneconfig.renderer.Renderer;
+import io.polyfrost.oneconfig.themes.textures.ThemeElement;
+import net.minecraft.client.renderer.GlStateManager;
+import org.jetbrains.annotations.NotNull;
+
+import java.awt.*;
+
+public class OCButton extends OCBlock {
+ 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;
+
+ /**
+ * Create an empty button.
+ */
+ public OCButton(int width, int height) {
+ super(width, height);
+ }
+
+ /**
+ * Create a new button with the specified texture.
+ */
+ public OCButton(ThemeElement element) {
+ super(element.size + 2, element.size + 2);
+ this.element = element;
+ }
+
+ public OCButton(@NotNull String title, @NotNull String description, ThemeElement icon, boolean alwaysShowDesc) {
+ super(icon.size + theme.getBoldFont().getWidth(title) + 20, icon.size + 10);
+ this.element = icon;
+ this.title = title;
+ this.description = description;
+ this.alwaysShowDesc = alwaysShowDesc;
+ }
+
+
+ public OCButton(@NotNull String title, @NotNull String description, ThemeElement icon, boolean alwaysShowDesc, int width, int height) {
+ super(width, height);
+ this.element = icon;
+ this.title = title;
+ this.description = description;
+ this.alwaysShowDesc = alwaysShowDesc;
+ }
+
+ public void draw(int x, int y) {
+ super.update(x, y);
+
+ 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);
+ if(!alwaysShowDesc) {
+ percentDescription = Renderer.clamp(Renderer.easeOut(percentDescription, isHovered() ? 1f : 0f));
+ }
+ GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha);
+ 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);
+ theme.getTextureManager().draw(element, x + 19, y + 8, element.size, element.size);
+ 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));
+ 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());
+ }
+ }
+ }
+ }
+
+
+ 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 onHover() {
+
+ }
+}
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 7a87f77..3d23b2f 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
@@ -1,6 +1,8 @@
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.*;
@@ -11,7 +13,7 @@ public class OCStoreBlock extends OCBlock {
private Color color;
public OCStoreBlock(String title, String description, ResourceLocation image, int color) {
- super(color, 200, 400);
+ super(color, 300, 400);
this.color = Renderer.getColorFromInt(color);
this.description = description;
this.title = title;
@@ -19,12 +21,13 @@ public class OCStoreBlock extends OCBlock {
}
public void draw(int x, int y) {
- super.draw(x, y);
- Renderer.drawScaledImage(image, x, y, 200, 100);
- super.theme.getFont().drawSplitString("i like fish", x + 2, y + 102, 200, -1);
+ //super.draw(x, y);
+ Renderer.drawScaledImage(image, x, y, 300, 150);
+ //Gui.drawRect(x,y,x + 300, y + 150, -1);
+ theme.getBoldFont().drawSplitString(title, x + 2, y + 152, 200, -1);
- super.update();
+ //super.update();
}
public void draw(int x, int y, int width, int height) {