aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/utils
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-08-24 22:51:58 +0200
committerGitHub <noreply@github.com>2022-08-24 22:51:58 +0200
commitdaed9569a0f1d2231c4f824f6cffd72d5f8ae8bd (patch)
tree6efee702c616d96e40a3e69ce89425f0936a7598 /src/main/java/cc/polyfrost/oneconfig/utils
parenta76b49be6dbeb0be3f88870e33d3e10e0e7f8e1c (diff)
downloadOneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.tar.gz
OneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.tar.bz2
OneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.zip
Notifs (#111)
* Start on notifications * Finish notifications (pog) * oop * internalizing * misc: set default duration to 4000ms * Scaling notifs stuff Co-authored-by: Wyvest <45589059+Wyvest@users.noreply.github.com>
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java15
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/Notifications.java238
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notification.java100
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notifications.java58
5 files changed, 255 insertions, 160 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java
index 6bd8207..809e55c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java
@@ -135,6 +135,21 @@ public class InputHandler {
}
/**
+ * @param button The button
+ * @return If the button is down
+ */
+ public boolean isMouseDown(int button) {
+ return Platform.getMousePlatform().isButtonDown(button);
+ }
+
+ /**
+ * @return If the left mouse button is down
+ */
+ public boolean isMouseDown() {
+ return isMouseDown(0);
+ }
+
+ /**
* Gets the current mouse X position.
* <p>
* All values returned from this class are not scaled to Minecraft's GUI scale.
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/Notifications.java b/src/main/java/cc/polyfrost/oneconfig/utils/Notifications.java
new file mode 100644
index 0000000..b1fb387
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/Notifications.java
@@ -0,0 +1,238 @@
+/*
+ * This file is part of OneConfig.
+ * OneConfig - Next Generation Config Library for Minecraft: Java Edition
+ * Copyright (C) 2021, 2022 Polyfrost.
+ * <https://polyfrost.cc> <https://github.com/Polyfrost/>
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * OneConfig is licensed under the terms of version 3 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation, AND
+ * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
+ * either version 1.0 of the Additional Terms, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License. If not, see <https://www.gnu.org/licenses/>. You should
+ * have also received a copy of the Additional Terms Applicable
+ * to OneConfig, as published by Polyfrost. If not, see
+ * <https://polyfrost.cc/legal/oneconfig/additional-terms>
+ */
+
+package cc.polyfrost.oneconfig.utils;
+
+import cc.polyfrost.oneconfig.events.event.HudRenderEvent;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.gui.animations.Animation;
+import cc.polyfrost.oneconfig.gui.animations.DummyAnimation;
+import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad;
+import cc.polyfrost.oneconfig.internal.utils.Notification;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
+import cc.polyfrost.oneconfig.libs.universal.UResolution;
+import cc.polyfrost.oneconfig.renderer.Icon;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+public final class Notifications {
+ public static final Notifications INSTANCE = new Notifications();
+ // animation stores the bottom y of the notification
+ private final LinkedHashMap<Notification, Animation> notifications = new LinkedHashMap<>();
+ private final float DEFAULT_DURATION = 4000;
+
+ private Notifications() {
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param icon The icon of the notification, null for none
+ * @param duration The duration the notification is on screen in ms
+ * @param progressbar A callable that returns the progress from 0-1
+ * @param action The action executed when the notification is pressed
+ */
+ public void send(String title, String message, @Nullable Icon icon, float duration, @Nullable Callable<Float> progressbar, @Nullable Runnable action) {
+ Notification notification = new Notification(title, message, icon, duration, progressbar, action);
+ notifications.put(notification, new DummyAnimation(-1));
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param duration The duration the notification is on screen in ms
+ * @param progressbar A callable that returns the progress from 0-1
+ * @param action The action executed when the notification is pressed
+ */
+ public void send(String title, String message, float duration, @Nullable Callable<Float> progressbar, @Nullable Runnable action) {
+ send(title, message, null, duration, progressbar, action);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param icon The icon of the notification, null for none
+ * @param duration The duration the notification is on screen in ms
+ * @param progressbar A callable that returns the progress from 0-1
+ */
+ public void send(String title, String message, @Nullable Icon icon, float duration, @Nullable Callable<Float> progressbar) {
+ send(title, message, icon, duration, progressbar, null);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param icon The icon of the notification, null for none
+ * @param duration The duration the notification is on screen in ms
+ * @param action The action executed when the notification is pressed
+ */
+ public void send(String title, String message, @Nullable Icon icon, float duration, @Nullable Runnable action) {
+ send(title, message, icon, duration, null, action);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param duration The duration the notification is on screen in ms
+ * @param progressbar A callable that returns the progress from 0-1
+ */
+ public void send(String title, String message, float duration, @Nullable Callable<Float> progressbar) {
+ send(title, message, duration, progressbar, null);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param duration The duration the notification is on screen in ms
+ * @param action The action executed when the notification is pressed
+ */
+ public void send(String title, String message, float duration, @Nullable Runnable action) {
+ send(title, message, duration, null, action);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param icon The icon of the notification, null for none
+ * @param progressbar A callable that returns the progress from 0-1
+ */
+ public void send(String title, String message, @Nullable Icon icon, @Nullable Callable<Float> progressbar) {
+ send(title, message, icon, DEFAULT_DURATION, progressbar);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param icon The icon of the notification, null for none
+ * @param action The action executed when the notification is pressed
+ */
+ public void send(String title, String message, @Nullable Icon icon, @Nullable Runnable action) {
+ send(title, message, icon, DEFAULT_DURATION, action);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param progressbar A callable that returns the progress from 0-1
+ */
+ public void send(String title, String message, @Nullable Callable<Float> progressbar) {
+ send(title, message, DEFAULT_DURATION, progressbar);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param icon The icon of the notification, null for none
+ * @param duration The duration the notification is on screen in ms
+ */
+ public void send(String title, String message, @Nullable Icon icon, float duration) {
+ send(title, message, icon, duration, (Callable<Float>) null);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param action The action executed when the notification is pressed
+ */
+ public void send(String title, String message, @Nullable Runnable action) {
+ send(title, message, DEFAULT_DURATION, action);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param duration The duration the notification is on screen in ms
+ */
+ public void send(String title, String message, float duration) {
+ send(title, message, duration, (Callable<Float>) null);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ * @param icon The icon of the notification, null for none
+ */
+ public void send(String title, String message, @Nullable Icon icon) {
+ send(title, message, icon, (Callable<Float>) null);
+ }
+
+ /**
+ * Send a notification to the user
+ *
+ * @param title The title of the notification
+ * @param message The message of the notification
+ */
+ public void send(String title, String message) {
+ send(title, message, (Callable<Float>) null);
+ }
+
+ @Subscribe
+ private void onHudRender(HudRenderEvent event) {
+ RenderManager.setupAndDraw((vg) -> {
+ float desiredPosition = -16f;
+ float scale = OneConfigGui.getScaleFactor();
+ for (Map.Entry<Notification, Animation> entry : notifications.entrySet()) {
+ if (entry.getValue().getEnd() == -1f)
+ entry.setValue(new DummyAnimation(desiredPosition));
+ else if (desiredPosition != entry.getValue().getEnd())
+ entry.setValue(new EaseInOutQuad(250, entry.getValue().get(0), desiredPosition, false));
+ float height = entry.getKey().draw(vg, UResolution.getWindowHeight() / scale + entry.getValue().get(), scale);
+ desiredPosition -= height + 16f;
+ }
+ notifications.entrySet().removeIf(entry -> entry.getKey().isFinished());
+ });
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
index 1fdd7e7..bc6e9c0 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
@@ -28,13 +28,13 @@ package cc.polyfrost.oneconfig.utils;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Font;
-import cc.polyfrost.oneconfig.renderer.font.Fonts;
import java.util.ArrayList;
/**
- * Simple text utility class for NanoVG text rendering.
+ * @deprecated Use RenderManager's functions for wrapping text and getting the height of it instead
*/
+@Deprecated
public final class TextUtils {
/**
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notification.java b/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notification.java
deleted file mode 100644
index 2e28c2c..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notification.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
- */
-
-package cc.polyfrost.oneconfig.utils.notifications;
-
-/**
- * @deprecated Reserved for future use, not implemented yet.
- */
-@Deprecated
-public final class Notification {
- private String title;
- private String message;
- private final float duration;
- private float x;
- private float y;
-
- private final Runnable action;
- private final Runnable onClose;
-
- Notification(String title, String message, float duration, float x, float y, Runnable action, Runnable onClose) {
- this.title = title;
- this.message = message;
- this.duration = duration;
- this.x = x;
- this.y = y;
- this.action = action;
- this.onClose = onClose;
- }
-
- void draw(final long vg) {
-
- }
-
- public String getTitle() {
- return title;
- }
-
- public String getMessage() {
- return message;
- }
-
- public float getDuration() {
- return duration;
- }
-
- public float getX() {
- return x;
- }
-
- public float getY() {
- return y;
- }
-
- public Runnable getAction() {
- return action;
- }
-
- public Runnable getOnClose() {
- return onClose;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- void setX(float x) {
- this.x = x;
- }
-
- void setY(float y) {
- this.y = y;
- }
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notifications.java b/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notifications.java
deleted file mode 100644
index 4038355..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notifications.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
- */
-
-package cc.polyfrost.oneconfig.utils.notifications;
-
-/**
- * @deprecated Reserved for future use, not implemented yet.
- */
-@Deprecated
-public final class Notifications {
- public static final Notifications INSTANCE = new Notifications();
- private Notifications() {
-
- }
-
- public void send(String title, String message) {
-
- }
-
- public void send(String title, String message, Runnable action) {
-
- }
-
- public void send(String title, String message, float duration) {
-
- }
-
- public void send(String title, String message, float duration, Runnable action) {
-
- }
-
- public void send(String title, String message, float duration, Runnable action, Runnable onClose) {
-
- }
-}