aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-16 17:48:07 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-16 17:48:07 +0200
commit82ce1a72e26a3ced45949ab459592b97b39b334f (patch)
treed8c0eeb981a231227d3633b4a3c5a7ee682f2fde /src/main/java/cc
parenta5ec40e505207841162ab406f60ec46985db7235 (diff)
downloadOneConfig-82ce1a72e26a3ced45949ab459592b97b39b334f.tar.gz
OneConfig-82ce1a72e26a3ced45949ab459592b97b39b334f.tar.bz2
OneConfig-82ce1a72e26a3ced45949ab459592b97b39b334f.zip
block clicks system
Diffstat (limited to 'src/main/java/cc')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java27
4 files changed, 38 insertions, 9 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 8becc0c..22b5455 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -261,7 +261,7 @@ public class OneConfigGui extends UScreen {
@Override
public void onScreenClose() {
currentPage.finishUpAndClose();
- //instanceToRestore = this;
+ instanceToRestore = this;
INSTANCE = null;
super.onScreenClose();
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
index 199e0f0..1ae585a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
@@ -36,10 +36,12 @@ public class ConfigDropdown extends BasicOption { // TODO: chose where dividers
if (size == 1) hovered = InputUtils.isAreaHovered(x + 224, y, 256, 32) && isEnabled();
else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32) && isEnabled();
- if (hovered && InputUtils.isClicked() || opened && InputUtils.isClicked() &&
+ if (hovered && InputUtils.isClicked() || opened && InputUtils.isClicked(true) &&
(size == 1 && !InputUtils.isAreaHovered(x + 224, y + 40, 256, options.length * 32 + 4) ||
- size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32 + 4)))
+ size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32 + 4))) {
opened = !opened;
+ InputUtils.blockClicks(opened);
+ }
if (opened) return;
backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100);
@@ -97,12 +99,13 @@ public class ConfigDropdown extends BasicOption { // TODO: chose where dividers
RenderManager.drawRoundedRect(vg, x + 228, optionY - 12, 248, 28, OneConfigConfig.BLUE_700, 8);
color = OneConfigConfig.WHITE;
}
- if (optionHovered && InputUtils.isClicked()) {
+ if (optionHovered && InputUtils.isClicked(true)) {
try {
set(Arrays.asList(options).indexOf(option));
} catch (IllegalAccessException ignored) {
}
opened = false;
+ InputUtils.blockClicks(false);
}
RenderManager.drawString(vg, option, x + 240, optionY + 4, color, 14, Fonts.MEDIUM);
@@ -135,12 +138,13 @@ public class ConfigDropdown extends BasicOption { // TODO: chose where dividers
if (!options[options.length - 1].equals(option))
RenderManager.drawLine(vg, x + 360, optionY + 18, x + 984, optionY + 18, 1, new Color(204, 204, 204, 77).getRGB());
- if (optionHovered && InputUtils.isClicked()) {
+ if (optionHovered && InputUtils.isClicked(true)) {
try {
set(Arrays.asList(options).indexOf(option));
} catch (IllegalAccessException ignored) {
}
opened = false;
+ InputUtils.blockClicks(false);
}
optionY += 32;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
index 29d132a..c9f2691 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
@@ -18,6 +18,7 @@ public class ConfigSlider extends BasicOption {
private boolean isFloat = true;
private final int step;
private boolean dragging = false;
+ private boolean mouseWasDown = false;
public ConfigSlider(Field field, Object parent, String name, int size, float min, float max, int step) {
super(field, parent, name, size);
@@ -34,9 +35,12 @@ public class ConfigSlider extends BasicOption {
boolean hovered = InputUtils.isAreaHovered(x + 352, y, 512, 32) && isEnabled();
inputField.disable(!isEnabled());
if (!isEnabled()) NanoVG.nvgGlobalAlpha(vg, 0.5f);
- if (hovered && Mouse.isButtonDown(0)) dragging = true;
+ boolean isMouseDown = Mouse.isButtonDown(0);
+ if (hovered && isMouseDown && !mouseWasDown) dragging = true;
+ mouseWasDown = isMouseDown;
if (dragging) {
xCoordinate = (int) MathUtils.clamp(InputUtils.mouseX(), x + 352, x + 864);
+ if (step > 0) xCoordinate = getStepCoordinate(xCoordinate, x);
value = MathUtils.map(xCoordinate, x + 352, x + 864, min, max);
} else if (inputField.isToggled() || inputField.arrowsClicked()) {
value = inputField.getCurrentValue();
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
index ee0bafd..6053a99 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
@@ -5,6 +5,8 @@ import gg.essential.universal.UResolution;
import org.lwjgl.input.Mouse;
public class InputUtils {
+ private static boolean blockClicks = false;
+
/**
* function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale.
*
@@ -13,15 +15,23 @@ public class InputUtils {
public static boolean isAreaHovered(int x, int y, int width, int height) {
int mouseX = mouseX();
int mouseY = mouseY();
- return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info
+ return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height;
+ }
+
+ public static boolean isAreaClicked(int x, int y, int width, int height, boolean ignoreBlock) {
+ return isAreaHovered(x, y, width, height) && isClicked(ignoreBlock);
}
public static boolean isAreaClicked(int x, int y, int width, int height) {
- return isAreaHovered(x, y, width, height) && isClicked();
+ return isAreaClicked(x, y, width, height, false);
+ }
+
+ public static boolean isClicked(boolean ignoreBlock) {
+ return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0) && (!blockClicks || ignoreBlock);
}
public static boolean isClicked() {
- return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0);
+ return isClicked(false);
}
public static int mouseX() {
@@ -33,4 +43,15 @@ public class InputUtils {
if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Mouse.getY());
return (int) ((UResolution.getWindowHeight() - Math.abs(Mouse.getY())) / OneConfigGui.INSTANCE.getScaleFactor());
}
+
+ /**
+ * Should be used if there is something above other components and you don't want it clicking trough
+ */
+ public static void blockClicks(boolean value) {
+ blockClicks = value;
+ }
+
+ public static boolean isBlockingClicks() {
+ return blockClicks;
+ }
}