aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authornextdaydelivery <12willettsh@gmail.com>2022-02-19 17:52:07 +0000
committernextdaydelivery <12willettsh@gmail.com>2022-02-19 17:52:07 +0000
commit4f8e90571e3a270b54244d0fef985d5e0ca04b40 (patch)
treece21d07be4c27cace8c9c4d4fbd5ba5b205df7f0 /src/main/java/io
parent4c4f5cbeea2b8fe7a0572424e026277c824e0729 (diff)
downloadOneConfig-4f8e90571e3a270b54244d0fef985d5e0ca04b40.tar.gz
OneConfig-4f8e90571e3a270b54244d0fef985d5e0ca04b40.tar.bz2
OneConfig-4f8e90571e3a270b54244d0fef985d5e0ca04b40.zip
get started on the UI elements
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/Window.java8
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java197
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java17
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java6
5 files changed, 220 insertions, 12 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
index 245dbea..8dd0138 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
@@ -1,17 +1,13 @@
package io.polyfrost.oneconfig.gui;
-import io.polyfrost.oneconfig.renderer.Renderer;
-import io.polyfrost.oneconfig.renderer.TrueTypeFont;
+import io.polyfrost.oneconfig.gui.elements.OCBlock;
import io.polyfrost.oneconfig.themes.Theme;
import io.polyfrost.oneconfig.themes.ThemeElement;
import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import java.awt.*;
-import java.io.IOException;
-import java.util.Objects;
import static io.polyfrost.oneconfig.renderer.Renderer.clamp;
import static io.polyfrost.oneconfig.renderer.Renderer.easeOut;
@@ -21,6 +17,7 @@ public class Window extends GuiScreen {
public static Window currentWindow;
private final Theme t = Themes.getActiveTheme();
private final int guiScaleToRestore;
+ OCBlock block = new OCBlock(-1, 100, 200);
public Window() {
super.initGui();
@@ -59,6 +56,7 @@ public class Window extends GuiScreen {
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);
//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 774d936..7a5c8f3 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
@@ -1,4 +1,201 @@
package io.polyfrost.oneconfig.gui.elements;
+import io.polyfrost.oneconfig.renderer.Renderer;
+import io.polyfrost.oneconfig.themes.Theme;
+import io.polyfrost.oneconfig.themes.ThemeElement;
+import io.polyfrost.oneconfig.themes.Themes;
+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;
+import org.lwjgl.input.Mouse;
+
+import java.awt.*;
+
+@SuppressWarnings("unused")
public class OCBlock {
+ private static final Theme theme = Themes.getActiveTheme();
+ private static final Minecraft mc = Minecraft.getMinecraft();
+ public static ScaledResolution resolution = new ScaledResolution(mc);
+ private Color color;
+ private String text;
+ private final boolean bold;
+ private int width, 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 new basic element.
+ * @param color color of the element
+ * @param width width of the element
+ * @param height height of the element
+ */
+ 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
+ */
+ public OCBlock(@NotNull String text, boolean bold, int color) {
+ this(text, bold, color, theme.getFont().getWidth(text) + 6, theme.getFont().getHeight() + 4);
+ }
+
+ /**
+ * 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
+ */
+ public OCBlock(String text, boolean bold, int color, int width, int height) {
+ this.text = text;
+ this.bold = bold;
+ this.color = Renderer.getColorFromInt(color);
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
+ * Create a new Element with the specified image.
+ * @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.element = element;
+ this.color = Renderer.getColorFromInt(colorMask);
+ this.width = width;
+ this.height = height;
+ this.bold = false;
+ }
+
+ /**
+ * Draw the element at the specified coordinates.
+ */
+ public void draw(int x, int y) {
+ this.x = x;
+ this.y = 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);
+ 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);
+ } else {
+ theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, -1);
+ }
+ }
+
+ }
+
+ /**
+ * Update this elements click, key and hover status. Call this method at the end of your 'draw' function, if overrided.
+ */
+ public void update() {
+ resolution = new ScaledResolution(mc);
+ 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) {
+ onHover();
+ if (Mouse.isButtonDown(0) && !clicked) {
+ onClick(0);
+ }
+ clicked = Mouse.isButtonDown(0);
+
+ if (Mouse.isButtonDown(1) && !rightClicked) {
+ onClick(1);
+ }
+ rightClicked = Mouse.isButtonDown(1);
+ onKeyPress(Keyboard.getEventKey());
+ }
+ }
+
+ /**
+ * Draw the element with the specified coordinates, width and height.
+ */
+ public void draw(int x, int y, int width, int height) {
+ this.width = width;
+ this.height = height;
+ draw(x, y);
+ }
+
+
+ /**
+ * 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) {
+
+ }
+
+ /**
+ * 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) {
+
+ }
+
+
+ /**
+ * Override this method to set a function when the element is hovered.
+ */
+ public void onHover() {
+
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public boolean isHovered() {
+ return hovered;
+ }
+
+ public boolean isClicked() {
+ return clicked;
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
deleted file mode 100644
index 4df6f93..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements;
-
-public class OCButton {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
new file mode 100644
index 0000000..6d9d8c1
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
@@ -0,0 +1,17 @@
+package io.polyfrost.oneconfig.gui.elements;
+
+import net.minecraft.util.ResourceLocation;
+
+public class OCStoreBlock extends OCBlock {
+
+
+ public OCStoreBlock(String title, String description, ResourceLocation image, int color) {
+ super(color, 200, 400);
+ }
+
+ public void draw(int x, int y) {
+
+
+ super.update();
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
index 30451d7..9e8e061 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/ThemeElement.java
@@ -12,12 +12,12 @@ public enum ThemeElement {
UPDATE("textures/icons/update.png", 128),
BACK_ARROW("textures/smallicons/backarrow.png", 32),
- CLOSE("textures/smallicons/close.png", 32),
FORWARD_ARROW("textures/smallicons/forward.png", 32),
HOME("textures/smallicons/home.png", 32),
- MAGNIFY("textures/smallicons/magnify.png", 32),
- MINIMIZE("textures/smallicons/minimize.png", 32),
SEARCH("textures/smallicons/search.png", 32),
+ MAGNIFY("textures/smallicons/magnify.png", 64),
+ MINIMIZE("textures/smallicons/minimize.png", 64),
+ CLOSE("textures/smallicons/close.png", 64),
ALL_MODS("textures/mod/allmods.png", 32),
HUD_MODS("textures/mod/hudmods.png", 32),