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/elements/OCBlock.java79
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java22
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java11
3 files changed, 58 insertions, 54 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 7b4fd99..abcd5ca 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
@@ -21,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.
*/
@@ -32,6 +33,8 @@ 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;
@@ -41,9 +44,6 @@ public class OCBlock {
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.
@@ -54,11 +54,11 @@ public class OCBlock {
/**
* 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 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) {
@@ -67,8 +67,9 @@ 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 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) {
@@ -77,8 +78,9 @@ 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 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) {
@@ -92,7 +94,8 @@ 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) {
@@ -106,6 +109,7 @@ 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) {
@@ -126,20 +130,19 @@ public class OCBlock {
percentHoveredAlpha = smooth(percentHoveredAlpha, elementColor.getAlpha() / 255f, hoverColor.getAlpha() / 255f);
GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha);
update(x, y);
- if(draw != null) {
+ if (draw != null) {
draw.run();
}
- if(element != null) {
+ 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) {
+ if (text == null) {
theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
- }
- else {
+ } else {
theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
- if(bold) {
+ 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, color.getRGB());
@@ -157,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);
@@ -170,10 +173,10 @@ public class OCBlock {
rightClicked = Mouse.isButtonDown(1);
onKeyPress(Keyboard.getEventKey());
}
- if(clicked) {
+ if (clicked) {
Renderer.color(theme.getClickColor());
}
- if(!hovered && clicked) clicked = false;
+ if (!hovered && clicked) clicked = false;
}
/**
@@ -188,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) {
@@ -196,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) {
@@ -213,46 +218,46 @@ public class 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;
}
- public void setText(String text) {
- this.text = text;
- }
-
- public void setWidth(int width) {
- this.width = width;
+ public int getHeight() {
+ return height;
}
public void setHeight(int height) {
this.height = height;
}
- public int getHeight() {
- return 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 298690f..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()) {
+ 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);
}
}