aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-13 21:17:51 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-13 21:17:51 +0200
commitd246278dfe0ad7816d5a8db6ff04c1e8501e8125 (patch)
treed1eed5eae773b3d25a44fd323c8a7f2772079a93 /src
parent1500cf9ad6bdb8240f2b01c117c06944ec30651a (diff)
downloadOneConfig-d246278dfe0ad7816d5a8db6ff04c1e8501e8125.tar.gz
OneConfig-d246278dfe0ad7816d5a8db6ff04c1e8501e8125.tar.bz2
OneConfig-d246278dfe0ad7816d5a8db6ff04c1e8501e8125.zip
lots of input stuff
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java41
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java17
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java68
11 files changed, 118 insertions, 51 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index c15940d..1f7e621 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -35,7 +35,6 @@ public class OneConfigGui extends UScreen {
private final ArrayList<Page> nextPages = new ArrayList<>();
private final BasicElement backArrow = new BasicElement(40, 40, new ColorPalette(Colors.GRAY_700, Colors.GRAY_500, Colors.GRAY_500_80), true);
private final BasicElement forwardArrow = new BasicElement(40, 40, new ColorPalette(Colors.GRAY_700, Colors.GRAY_500, Colors.GRAY_500_80), true);
- private final ArrayList<Page> parents = new ArrayList<>();
public ColorSelector currentColorSelector;
public boolean mouseDown;
public boolean allowClose = true;
@@ -70,7 +69,8 @@ public class OneConfigGui extends UScreen {
RenderManager.setupAndDraw((vg) -> {
if (currentPage == null) {
currentPage = new ModsPage();
- parents.add(currentPage);
+ currentPage.parents = new ArrayList<>();
+ currentPage.parents.add(currentPage);
}
if (OneConfigConfig.australia) {
NanoVG.nvgTranslate(vg, UResolution.getWindowWidth(), UResolution.getWindowHeight());
@@ -154,17 +154,17 @@ public class OneConfigGui extends UScreen {
ScissorManager.clearScissors(vg);
float breadcrumbX = x + 352;
- for (int i = 0; i < parents.size(); i++) {
- String title = parents.get(i).getTitle();
+ for (int i = 0; i < currentPage.parents.size(); i++) {
+ String title = currentPage.parents.get(i).getTitle();
float width = RenderManager.getTextWidth(vg, title, 24f, Fonts.SEMIBOLD);
boolean hovered = InputUtils.isAreaHovered((int) breadcrumbX, y + 24, (int) width, 36);
int color = Colors.WHITE_60;
- if (i == parents.size() - 1) color = Colors.WHITE;
+ if (i == currentPage.parents.size() - 1) color = Colors.WHITE;
else if (hovered && !Mouse.isButtonDown(0)) color = Colors.WHITE_80;
RenderManager.drawText(vg, title, breadcrumbX, y + 38, color, 24f, Fonts.SEMIBOLD);
if (i != 0)
RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, breadcrumbX - 28, y + 25, 24, 24, color);
- if (hovered && InputUtils.isClicked()) openPage(parents.get(i));
+ if (hovered && InputUtils.isClicked()) openPage(currentPage.parents.get(i));
breadcrumbX += width + 32;
}
@@ -203,20 +203,23 @@ public class OneConfigGui extends UScreen {
if (page == currentPage) return;
currentPage.finishUpAndClose();
textInputField.setInput("");
- if (!page.isBase()) {
- boolean alreadyInParents = false;
- for (int i = 0; i < parents.size(); i++) {
- Page parent = parents.get(i);
- if (parent == page) {
- alreadyInParents = true;
- parents.subList(i + 1, parents.size()).clear();
- break;
+ if (page.parents == null) {
+ page.parents = new ArrayList<>(currentPage.parents);
+ if (!page.isBase()) {
+ boolean alreadyInParents = false;
+ for (int i = 0; i < page.parents.size(); i++) {
+ Page parent = page.parents.get(i);
+ if (parent == page) {
+ alreadyInParents = true;
+ page.parents.subList(i + 1, page.parents.size()).clear();
+ break;
+ }
}
+ if (!alreadyInParents) page.parents.add(page);
+ } else {
+ page.parents.clear();
+ page.parents.add(page);
}
- if (!alreadyInParents) parents.add(page);
- } else {
- parents.clear();
- parents.add(page);
}
if (addToPrevious) {
previousPages.add(0, currentPage);
@@ -235,7 +238,7 @@ public class OneConfigGui extends UScreen {
* Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));</code>
*/
public void initColorSelector(ColorSelector colorSelector) {
- InputUtils.blockClicks(true);
+ if (currentColorSelector != null) closeColorSelector();
currentColorSelector = colorSelector;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java
index a4a3321..56eac2d 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java
@@ -44,7 +44,7 @@ public class BasicElement {
public int currentColor;
protected final float radius;
/**
- * Boolean to determine if this element is allowed to be clicked when {@link InputUtils#isBlockingClicks()} is true.
+ * Boolean to determine if this element is allowed to be clicked when {@link InputUtils#isBlockingInput()} is true.
*/
private boolean block = false;
/**
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java
index f331fd9..4103bca 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java
@@ -54,6 +54,7 @@ public class ColorSelector {
private int mode = 0;
private boolean dragging, mouseWasDown;
private final boolean hasAlpha;
+ private Scissor inputScissor = null;
public ColorSelector(OneColor color, int mouseX, int mouseY) {
this(color, mouseX, mouseY, true);
@@ -106,7 +107,7 @@ public class ColorSelector {
}
public void draw(long vg) {
- InputUtils.blockClicks(false);
+ if (inputScissor != null) InputUtils.stopBlock(inputScissor);
doDrag();
int width = 416;
int height = 768;
@@ -201,11 +202,12 @@ public class ColorSelector {
RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x + 20, y + 492, 376, 32, 8f);
RenderManager.drawRoundedRect(vg, x + 20, y + 492, 376, 32, color.getRGB(), 8f);
- InputUtils.blockClicks(true);
- if (closeBtn.isClicked() || Mouse.isButtonDown(0) && !mouseWasDown && !InputUtils.isAreaHovered(x - 3, y - 3, width + 6, height + 6))
- OneConfigGui.INSTANCE.closeColorSelector();
+ inputScissor = InputUtils.blockInputArea(x - 3, y - 3, width + 6, height + 6);
ScissorManager.resetScissor(vg, scissor);
mouseWasDown = Mouse.isButtonDown(0);
+ if (closeBtn.isClicked()) {
+ OneConfigGui.INSTANCE.closeColorSelector();
+ }
}
private void drawColorSelector(long vg, int mode, int x, int y) {
@@ -392,7 +394,7 @@ public class ColorSelector {
}
public void onClose() {
- InputUtils.blockClicks(false);
+ if (inputScissor != null) InputUtils.stopBlock(inputScissor);
/*for (int i = 0; i < OneConfigConfig.recentColors.size(); i++) {
OneColor color1 = OneConfigConfig.recentColors.get(i);
if (color1.getRGB() == color.getRGB()) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
index 67488d7..16796e9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
@@ -85,14 +85,12 @@ public class ConfigColorElement extends BasicOption {
RenderManager.drawHollowRoundRect(vg, x1 + 415, y - 1, 64, 32, Colors.GRAY_300, 12f, 2f);
RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x1 + 420, y + 4, 56, 24, 8f);
RenderManager.drawRoundedRect(vg, x1 + 420, y + 4, 56, 24, color.getRGB(), 8f);
- if (element.isClicked() && !element.isToggled()) {
- open = !open;
+ if (element.isClicked() && !open) {
+ open = true;
OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY(), allowAlpha));
}
if (OneConfigGui.INSTANCE.currentColorSelector == null) open = false;
- if (OneConfigGui.INSTANCE.currentColorSelector != null && open) {
- color = (OneConfigGui.INSTANCE.getColor());
- }
+ else if (open) color = (OneConfigGui.INSTANCE.getColor());
setColor(color);
RenderManager.setAlpha(vg, 1f);
}
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 657cf99..26d7348 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
@@ -7,6 +7,7 @@ import cc.polyfrost.oneconfig.gui.animations.ColorAnimation;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.internal.assets.SVGs;
+import cc.polyfrost.oneconfig.renderer.scissor.Scissor;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import org.lwjgl.input.Mouse;
@@ -20,6 +21,7 @@ public class ConfigDropdown extends BasicOption {
private final ColorAnimation backgroundColor = new ColorAnimation(ColorPalette.SECONDARY);
private final ColorAnimation atomColor = new ColorAnimation(new ColorPalette(Colors.PRIMARY_600, Colors.PRIMARY_500, Colors.PRIMARY_500));
private boolean opened = false;
+ private Scissor inputScissor = null;
public ConfigDropdown(Field field, Object parent, String name, String category, String subcategory, int size, String[] options) {
super(field, parent, name, category, subcategory, size);
@@ -45,7 +47,8 @@ public class ConfigDropdown extends BasicOption {
size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32))) {
opened = !opened;
backgroundColor.setPalette(opened ? ColorPalette.PRIMARY : ColorPalette.SECONDARY);
- InputUtils.blockClicks(opened);
+ if (opened) inputScissor = InputUtils.blockAllInput();
+ else if (inputScissor != null) InputUtils.stopBlock(inputScissor);
}
if (opened) return;
@@ -75,8 +78,8 @@ public class ConfigDropdown extends BasicOption {
if (!opened) return;
boolean hovered;
- if (size == 1) hovered = InputUtils.isAreaHovered(x + 224, y, 256, 32);
- else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32);
+ if (size == 1) hovered = InputUtils.isAreaHovered(x + 224, y, 256, 32, true);
+ else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32, true);
int selected = 0;
try {
@@ -98,7 +101,7 @@ public class ConfigDropdown extends BasicOption {
int optionY = y + 44;
for (String option : options) {
int color = Colors.WHITE_80;
- boolean optionHovered = InputUtils.isAreaHovered(x + 224, optionY, 252, 32);
+ boolean optionHovered = InputUtils.isAreaHovered(x + 224, optionY, 252, 32, true);
if (optionHovered && Mouse.isButtonDown(0)) {
RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, Colors.PRIMARY_700_80, 8);
} else if (optionHovered) {
@@ -112,7 +115,7 @@ public class ConfigDropdown extends BasicOption {
}
opened = false;
backgroundColor.setPalette(ColorPalette.SECONDARY);
- InputUtils.blockClicks(false);
+ if (inputScissor != null) InputUtils.stopBlock(inputScissor);
}
RenderManager.drawText(vg, option, x + 240, optionY + 18, color, 14, Fonts.MEDIUM);
@@ -131,7 +134,7 @@ public class ConfigDropdown extends BasicOption {
int optionY = y + 44;
for (String option : options) {
int color = Colors.WHITE_80;
- boolean optionHovered = InputUtils.isAreaHovered(x + 352, optionY, 640, 36);
+ boolean optionHovered = InputUtils.isAreaHovered(x + 352, optionY, 640, 36, true);
if (optionHovered && Mouse.isButtonDown(0)) {
RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, Colors.PRIMARY_700_80, 8);
} else if (optionHovered) {
@@ -148,7 +151,7 @@ public class ConfigDropdown extends BasicOption {
}
opened = false;
backgroundColor.setPalette(ColorPalette.SECONDARY);
- InputUtils.blockClicks(false);
+ if (inputScissor != null) InputUtils.stopBlock(inputScissor);
}
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 066fdd3..bd02d21 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
@@ -41,7 +41,7 @@ public class ConfigSlider extends BasicOption {
inputField.disable(!isEnabled());
if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f);
boolean isMouseDown = Mouse.isButtonDown(0);
- if (hovered && isMouseDown && !mouseWasDown && !InputUtils.isBlockingClicks()) dragging = true;
+ if (hovered && isMouseDown && !mouseWasDown) dragging = true;
mouseWasDown = isMouseDown;
if (dragging) {
xCoordinate = (int) MathUtils.clamp(InputUtils.mouseX(), x + 352, x + 864);
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
index 17f9498..8ec270c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
@@ -11,6 +11,8 @@ import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import org.lwjgl.input.Mouse;
+import java.util.ArrayList;
+
/**
* A page is a 1056x728 rectangle of the GUI. It is the main content of the gui, and can be switched back and forwards easily. All the content of OneConfig is in a page.
*/
@@ -22,6 +24,7 @@ public abstract class Page {
private long scrollTime;
private boolean mouseWasDown, dragging;
private float yStart;
+ public ArrayList<Page> parents = null;
public Page(String title) {
this.title = title;
@@ -47,6 +50,7 @@ public abstract class Page {
float scroll = scrollAnimation == null ? scrollTarget : scrollAnimation.get();
final float scrollBarLength = (728f / maxScroll) * 728f;
Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset);
+ Scissor inputScissor = InputUtils.blockInputArea(x, y, x + 1056, y + scissorOffset);
int dWheel = Mouse.getDWheel();
if (dWheel != 0) {
scrollTarget += dWheel;
@@ -60,6 +64,7 @@ public abstract class Page {
if (maxScroll <= 728) {
draw(vg, x, y);
ScissorManager.resetScissor(vg, scissor);
+ InputUtils.stopBlock(inputScissor);
return;
}
draw(vg, x, (int) (y + scroll));
@@ -68,6 +73,7 @@ public abstract class Page {
}
ScissorManager.resetScissor(vg, scissor);
+ InputUtils.stopBlock(inputScissor);
if (!(scrollBarLength > 727f)) {
final float scrollBarY = (scroll / maxScroll) * 720f;
final boolean isMouseDown = Mouse.isButtonDown(0);
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java
index 82d040a..7f38721 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java
@@ -32,7 +32,7 @@ public class OneConfigCommand {
@Main
private static void main() {
OneConfigGui.instanceToRestore = null;
- InputUtils.blockClicks(false);
+ InputUtils.stopBlockingInput();
}
}
} \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java
index 179a260..62854ef 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java
@@ -24,4 +24,8 @@ public class Scissor {
this.width = scissor.width;
this.height = scissor.height;
}
+
+ public boolean isInScissor(int x, int y) {
+ return x >= this.x && x <= this.x + this.width && y >= this.y && y <= this.y + this.height;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java
index 1f7801b..bfafedf 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java
@@ -54,6 +54,11 @@ public class ScissorManager {
private static void applyScissors(long vg) {
NanoVG.nvgResetScissor(vg);
if (scissors.size() <= 0) return;
+ Scissor finalScissor = getFinalScissor(scissors);
+ NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height);
+ }
+
+ public static Scissor getFinalScissor(ArrayList<Scissor> scissors) {
Scissor finalScissor = new Scissor(scissors.get(0));
for (int i = 1; i < scissors.size(); i++) {
Scissor scissor = scissors.get(i);
@@ -64,6 +69,6 @@ public class ScissorManager {
finalScissor.width = rightX - finalScissor.x;
finalScissor.height = rightY - finalScissor.y;
}
- NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height);
+ return finalScissor;
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
index 0f50a33..0e342a2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
@@ -2,8 +2,12 @@ package cc.polyfrost.oneconfig.utils;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
+import cc.polyfrost.oneconfig.renderer.scissor.Scissor;
+import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager;
import org.lwjgl.input.Mouse;
+import java.util.ArrayList;
+
/**
* Various utility methods for input.
* <p>
@@ -12,17 +16,27 @@ import org.lwjgl.input.Mouse;
* </p>
*/
public final class InputUtils {
- private static boolean blockClicks = false;
+ private static final ArrayList<Scissor> blockScissors = new ArrayList<>();
+ private static Scissor finalScissor = new Scissor(0, 0, 0, 0);
/**
* function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale.
*
* @return true if mouse is over region, false if not.
*/
- public static boolean isAreaHovered(int x, int y, int width, int height) {
+ public static boolean isAreaHovered(int x, int y, int width, int height, boolean ignoreBlock) {
int mouseX = mouseX();
int mouseY = mouseY();
- return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height;
+ return (ignoreBlock || blockScissors.size() == 0 || !finalScissor.isInScissor(mouseX, mouseY)) && mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height;
+ }
+
+ /**
+ * function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale.
+ *
+ * @return true if mouse is over region, false if not.
+ */
+ public static boolean isAreaHovered(int x, int y, int width, int height) {
+ return isAreaHovered(x, y, width, height, false);
}
/**
@@ -32,12 +46,12 @@ public final class InputUtils {
* @param y the y position of the region
* @param width the width of the region
* @param height the height of the region
- * @param ignoreBlock if true, will ignore {@link InputUtils#blockClicks(boolean)}
+ * @param ignoreBlock if true, will ignore
* @return true if the mouse is clicked and is over the region, false if not
* @see InputUtils#isAreaHovered(int, int, int, int)
*/
public static boolean isAreaClicked(int x, int y, int width, int height, boolean ignoreBlock) {
- return isAreaHovered(x, y, width, height) && isClicked(ignoreBlock);
+ return isAreaHovered(x, y, width, height, ignoreBlock) && isClicked(false);
}
/**
@@ -57,11 +71,11 @@ public final class InputUtils {
/**
* Checks whether the mouse is clicked or not.
*
- * @param ignoreBlock if true, will ignore {@link InputUtils#blockClicks(boolean)}
+ * @param ignoreBlock if true, will ignore
* @return true if the mouse is clicked, false if not
*/
public static boolean isClicked(boolean ignoreBlock) {
- return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0) && (!blockClicks || ignoreBlock);
+ return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0) && (ignoreBlock || blockScissors.size() == 0 || !finalScissor.isInScissor(mouseX(), mouseY()));
}
/**
@@ -103,10 +117,42 @@ public final class InputUtils {
}
/**
+ * Block all clicks outside an area
+ *
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @param width Width
+ * @param height Height
+ */
+ public static Scissor blockInputArea(int x, int y, int width, int height) {
+ Scissor scissor = new Scissor(new Scissor(x, y, width, height));
+ blockScissors.add(scissor);
+ finalScissor = ScissorManager.getFinalScissor(blockScissors);
+ return scissor;
+ }
+
+ /**
* 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 Scissor blockAllInput() {
+ return blockInputArea(0, 0, 1920, 1080);
+ }
+
+ /**
+ * Stop blocking an area from being interacted with
+ *
+ * @param scissor The scissor area
+ */
+ public static void stopBlock(Scissor scissor) {
+ blockScissors.remove(scissor);
+ if (blockScissors.size() > 0) finalScissor = ScissorManager.getFinalScissor(blockScissors);
+ }
+
+ /**
+ * Clears all blocking areas
+ */
+ public static void stopBlockingInput() {
+ blockScissors.clear();
}
/**
@@ -114,7 +160,7 @@ public final class InputUtils {
*
* @return true if clicks are blocked, false if not
*/
- public static boolean isBlockingClicks() {
- return blockClicks;
+ public static boolean isBlockingInput() {
+ return blockScissors.size() > 0;
}
}