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.java34
-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
4 files changed, 159 insertions, 23 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
index 7671578..62576a9 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
@@ -1,6 +1,7 @@
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;
@@ -8,13 +9,9 @@ import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
-import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
-import javax.imageio.ImageIO;
import java.awt.*;
-import java.io.IOException;
-import java.net.URL;
import static io.polyfrost.oneconfig.renderer.Renderer.clamp;
import static io.polyfrost.oneconfig.renderer.Renderer.easeOut;
@@ -24,9 +21,13 @@ public class Window extends GuiScreen {
public static Window currentWindow;
private final Theme t = Themes.getActiveTheme();
private final int guiScaleToRestore;
+ long secondCounter = System.currentTimeMillis();
+ long prevTime = System.currentTimeMillis();
+ int frames = 0;
OCBlock block = new OCBlock(-1, 100, 200);
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() {
@@ -46,6 +47,19 @@ public class Window extends GuiScreen {
currentProgress = clamp(easeOut(currentProgress, 1f));
int alphaVal = (int) (50 * currentProgress);
drawGradientRect(0, 0, super.width, super.height, new Color(80, 80, 80, alphaVal).getRGB(), new Color(80, 80, 80, alphaVal + 10).getRGB());
+ long secondDelta = System.currentTimeMillis() - secondCounter;
+ long deltaTime = System.currentTimeMillis() - prevTime;
+ //if(deltaTime >= 15) {
+ // prevTime = System.currentTimeMillis();
+ // frames++;
+ // drawWindow();
+ //}
+ if(secondDelta >= 1000) {
+ secondCounter = System.currentTimeMillis();
+ //System.out.println(frames + "FPS");
+ //Minecraft.getMinecraft().thePlayer.sendChatMessage(frames + "FPS");
+ frames = 0;
+ }
drawWindow();
}
@@ -61,14 +75,14 @@ public class Window extends GuiScreen {
//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.BUTTON_OFF, left + 480, top + 40, 640, 48);
+ //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.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);
- storeBlock.draw(500,300);
+ //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);
//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 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) {