aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/pages
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-05 17:38:44 +0100
committernextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-05 17:38:44 +0100
commit5c7f1f9e2613b0ca5efac351e2c5e15c9deb0069 (patch)
treef68ad16f2f6b46c7b9ed8f14d1331fd357a01fbf /src/main/java/cc/polyfrost/oneconfig/gui/pages
parent77f8b7924ad61ebb8334d37a0a2ae2c8a297b400 (diff)
downloadOneConfig-5c7f1f9e2613b0ca5efac351e2c5e15c9deb0069.tar.gz
OneConfig-5c7f1f9e2613b0ca5efac351e2c5e15c9deb0069.tar.bz2
OneConfig-5c7f1f9e2613b0ca5efac351e2c5e15c9deb0069.zip
scrolling
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/pages')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java32
2 files changed, 34 insertions, 22 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
index d0e809e..dde6a2b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.gui.pages;
+import cc.polyfrost.oneconfig.OneConfig;
import cc.polyfrost.oneconfig.config.OneConfigConfig;
import cc.polyfrost.oneconfig.config.data.OptionPage;
import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
@@ -37,15 +38,6 @@ public class ModConfigPage extends Page {
int optionX = x + 30;
int optionY = y + (page.categories.size() == 1 ? 16 : 64);
- // Category buttons
- int buttonX = x + 16;
- for (BasicButton button : categories) {
- if (button.getWidth() == 0)
- button.setWidth((int) (Math.ceil(RenderManager.getTextWidth(vg, button.getText(), 14f, Fonts.INTER_MEDIUM) / 8f) * 8 + 16));
- button.draw(vg, buttonX, y + 16);
- buttonX += button.getWidth() + 16;
- }
-
// Top page buttons
for (ConfigPageButton page : page.categories.get(selectedCategory).topPages) {
page.draw(vg, optionX, optionY);
@@ -124,6 +116,20 @@ public class ModConfigPage extends Page {
}
}
}
+ RenderManager.drawRoundedRect(vg, x, y + 1500, 500, 100, OneConfigConfig.WHITE_90, 16);
+ }
+
+ @Override
+ public int drawStatic(long vg, int x, int y) {
+ // Category buttons
+ int buttonX = x + 16;
+ for (BasicButton button : categories) {
+ if (button.getWidth() == 0)
+ button.setWidth((int) (Math.ceil(RenderManager.getTextWidth(vg, button.getText(), 14f, Fonts.INTER_MEDIUM) / 8f) * 8 + 16));
+ button.draw(vg, buttonX, y + 16);
+ buttonX += button.getWidth() + 16;
+ }
+ return 60;
}
@Override
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 2f2fa36..1eaf8dd 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
@@ -1,7 +1,5 @@
package cc.polyfrost.oneconfig.gui.pages;
-import cc.polyfrost.oneconfig.config.OneConfigConfig;
-import cc.polyfrost.oneconfig.lwjgl.RenderManager;
import cc.polyfrost.oneconfig.utils.MathUtils;
import org.lwjgl.input.Mouse;
@@ -9,8 +7,8 @@ import org.lwjgl.input.Mouse;
* 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.
*/
public abstract class Page {
- private float scrollPercent = 0f;
- private float yDiff, scrollAmount;
+ private float currentScrollf = 0f;
+ private float scrollTarget;
protected final String title;
@@ -20,22 +18,30 @@ public abstract class Page {
public abstract void draw(long vg, int x, int y);
+ /** Use this method to draw elements that are static on the page (ignore the scrolling).
+ * @return the total height of the elements, so they are excluded from the scissor rectangle. */
+ public int drawStatic(long vg, int x, int y) {
+ return 0;
+ }
+
public void finishUpAndClose() {
}
public void scrollWithDraw(long vg, int x, int y) {
+ int currentScroll = (int) (currentScrollf * 100);
+ draw(vg, x, y + currentScroll);
int dWheel = Mouse.getDWheel();
- scrollAmount += dWheel / 120f;
- scrollPercent = MathUtils.easeOut(scrollPercent, scrollAmount, 20f);
+ if(dWheel > 120) dWheel = 120;
+ if(!(Math.abs((scrollTarget * 100) - 728) >= getMaxScrollHeight() && dWheel < 0)) {
+ scrollTarget += dWheel / 120f;
+ }
+ if(scrollTarget > 0f) { // fyi this is anti overscroll protection
+ scrollTarget = 0;
+ }
+
+ currentScrollf = MathUtils.easeOut(currentScrollf, scrollTarget, 20f);
- int currentScroll = (int) yDiff + (int) (scrollPercent * 100);
- if(currentScroll > 0) {
- currentScroll = 0;
- scrollPercent = 0;
- scrollAmount = 0;
- }
- draw(vg, x, y + currentScroll);
}
public String getTitle() {