diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-06 16:49:24 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-06 16:49:24 +0200 |
commit | 3c7d6a1a4d49ef40969bef2cb67825862c41407c (patch) | |
tree | ac25bfc89e8e853142c64222676f32b6c19dff90 /src/main/java | |
parent | 5c7f1f9e2613b0ca5efac351e2c5e15c9deb0069 (diff) | |
download | OneConfig-3c7d6a1a4d49ef40969bef2cb67825862c41407c.tar.gz OneConfig-3c7d6a1a4d49ef40969bef2cb67825862c41407c.tar.bz2 OneConfig-3c7d6a1a4d49ef40969bef2cb67825862c41407c.zip |
fix scrolling
Diffstat (limited to 'src/main/java')
7 files changed, 115 insertions, 33 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java index 99dfb8b..e8e469f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java @@ -31,6 +31,9 @@ public enum OptionType { * Type: int */ DROPDOWN, - MULTI_DROPDOWN, + //MULTI_DROPDOWN, + /** + * Type: String + */ INFO } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index febbfd0..44e019e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -123,24 +123,15 @@ public class OneConfigGui extends GuiScreen { Scissor scissor = ScissorManager.scissor(vg, x + 224, y + 88, 1056, 698); if (prevPage != null) { pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 220); - prevPage.draw(vg, (int) (x - pageProgress), y + 72); + prevPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); RenderManager.drawLine(vg, (int) (x - pageProgress + 1055), y + 72, (int) (x - pageProgress + 1057), y + 800, 2, OneConfigConfig.GRAY_700); // TODO might remove this - currentPage.draw(vg, (int) (x - pageProgress + 1056), y + 72); + currentPage.scrollWithDraw(vg, (int) (x - pageProgress + 1056), y + 72); if (pageProgress > 830f) { // this number is the 'snap' point of the page prevPage = null; pageProgress = -224f; } } else { - if(currentPage.getMaxScrollHeight() == 728) { - currentPage.draw(vg, (int) (x - pageProgress), y + 72); - } else { - ScissorManager.resetScissor(vg, scissor); - scissorExclusionHeight = currentPage.drawStatic(vg, (int) (x - pageProgress), y + 72); - Scissor scissor1 = ScissorManager.scissor(vg, x + 224, y + 72 + scissorExclusionHeight, 1056, 698 - scissorExclusionHeight); - currentPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); - ScissorManager.resetScissor(vg, scissor1); - } - + currentPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); } ScissorManager.resetScissor(vg, scissor); if (currentColorSelector != null) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java new file mode 100644 index 0000000..bd21ec3 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java @@ -0,0 +1,4 @@ +package cc.polyfrost.oneconfig.gui.elements.config; + +public class ConfigInfo { +} 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 dde6a2b..acd01a1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -1,20 +1,21 @@ 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; import cc.polyfrost.oneconfig.gui.elements.BasicButton; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import java.util.ArrayList; +import java.util.HashMap; public class ModConfigPage extends Page { private final OptionPage page; private final ArrayList<BasicButton> categories = new ArrayList<>(); private String selectedCategory; + private int totalSize = 724; public ModConfigPage(OptionPage page) { super(page.name); @@ -95,6 +96,7 @@ public class ModConfigPage extends Page { page.draw(vg, optionX, optionY); optionY += page.getHeight() + 16; } + totalSize = optionY - y; // Draw last options if (page.categories.get(selectedCategory).subcategories.keySet().size() > 0) { @@ -116,12 +118,12 @@ 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 + if(categories.size() <= 1) return 0; int buttonX = x + 16; for (BasicButton button : categories) { if (button.getWidth() == 0) @@ -158,6 +160,6 @@ public class ModConfigPage extends Page { @Override public int getMaxScrollHeight() { - return 1600; + return totalSize; } } 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 1eaf8dd..e8d48fe 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -1,5 +1,7 @@ package cc.polyfrost.oneconfig.gui.pages; +import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; +import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.input.Mouse; @@ -7,7 +9,7 @@ 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 currentScrollf = 0f; + private float currentScroll = 0f; private float scrollTarget; protected final String title; @@ -18,8 +20,11 @@ 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. */ + /** + * 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; } @@ -28,20 +33,23 @@ public abstract class Page { } public void scrollWithDraw(long vg, int x, int y) { - int currentScroll = (int) (currentScrollf * 100); - draw(vg, x, y + currentScroll); - int dWheel = Mouse.getDWheel(); - 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; + int maxScroll = getMaxScrollHeight(); + int scissorOffset = drawStatic(vg, x, y); + Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset); + if (maxScroll <= 728) { + draw(vg, x, y); + ScissorManager.resetScissor(vg, scissor); + return; } + draw(vg, x, (int) (y + currentScroll)); + int dWheel = Mouse.getDWheel(); + scrollTarget += dWheel; - currentScrollf = MathUtils.easeOut(currentScrollf, scrollTarget, 20f); - + if (scrollTarget > 0f) scrollTarget = 0f; + else if (scrollTarget < -maxScroll + 728) scrollTarget = -maxScroll + 728; + currentScroll = MathUtils.easeOut(currentScroll, scrollTarget, 10f); + ScissorManager.resetScissor(vg, scissor); } public String getTitle() { @@ -58,7 +66,9 @@ public abstract class Page { return false; } - /** Use this method to set the maximum scroll height of the page. */ + /** + * Use this method to set the maximum scroll height of the page. + */ public int getMaxScrollHeight() { return 728; } diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index b072f4c..475c68b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -43,6 +43,78 @@ public class TestConfig extends Config { ) public static int switchTest3; + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector1; + + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector2; + + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector3; + + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector4; + + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector5; + + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector6; + + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector7; + + @Option( + name = "Test option", + subcategory = "Test", + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR, + size = 2 + ) + public static int uniSelector8; + @ConfigPage( name = "Test Page", location = PageLocation.TOP diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java index 2faec69..7eb4944 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java @@ -6,7 +6,7 @@ public class MathUtils { } public static float easeOut(float current, float goal, float speed) { - if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) { + if (Math.floor(Math.abs(goal - current) * Math.abs(current - goal) * 3) > 0) { return current + (goal - current) / speed; } else { return goal; |