diff --git a/src/main/java/refinedstorage/gui/GuiGrid.java b/src/main/java/refinedstorage/gui/GuiGrid.java index aff7fa99a..15c1b2773 100644 --- a/src/main/java/refinedstorage/gui/GuiGrid.java +++ b/src/main/java/refinedstorage/gui/GuiGrid.java @@ -36,9 +36,7 @@ public class GuiGrid extends GuiBase private int hoveringSlotId; private int hoveringId; - private float currentScroll; - private boolean wasClicking = false; - private boolean isScrolling = false; + private Scrollbar scrollbar = new Scrollbar(174, 20, 12, 70); public GuiGrid(ContainerGrid container, TileGrid grid) { @@ -67,7 +65,9 @@ public class GuiGrid extends GuiBase @Override public void update(int x, int y) { - if (canScroll()) + scrollbar.setCanScroll(getRows() > getVisibleRows()); + + if (scrollbar.canScroll()) { int wheel = Mouse.getDWheel(); @@ -77,74 +77,18 @@ public class GuiGrid extends GuiBase if (wheel == -1) { - setCurrentScroll(currentScroll - delta); + scrollbar.setCurrentScroll(scrollbar.getCurrentScroll() - delta); } else if (wheel == 1) { - setCurrentScroll(currentScroll + delta); + scrollbar.setCurrentScroll(scrollbar.getCurrentScroll() + delta); } } } - private boolean inBoundsOfScrollbar(int x, int y) - { - return inBounds(174, 20, 12, 70, x, y); - } - - public void handleScrolling(int mouseX, int mouseY) - { - if (!canScroll()) - { - isScrolling = false; - wasClicking = false; - currentScroll = 0; - } - else - { - boolean down = Mouse.isButtonDown(0); - - if (!wasClicking && down && inBoundsOfScrollbar(mouseX, mouseY)) - { - isScrolling = true; - } - - if (!down) - { - isScrolling = false; - } - - wasClicking = down; - - if (isScrolling) - { - setCurrentScroll(mouseY - 20); - } - } - } - - public void setCurrentScroll(float newCurrentScroll) - { - if (newCurrentScroll < 0) - { - newCurrentScroll = 0; - } - - if (newCurrentScroll > (89 - 20 - 12 - 2)) - { - newCurrentScroll = 89 - 20 - 12 - 2; - } - - currentScroll = newCurrentScroll; - } - - public boolean canScroll() - { - return getRows() > getVisibleRows(); - } - public int getOffset() { - return (int) (currentScroll / 70f * (float) getRows()); + return (int) (scrollbar.getCurrentScroll() / 70f * (float) getRows()); } public int getVisibleRows() @@ -198,7 +142,7 @@ public class GuiGrid extends GuiBase drawTexture(x, y, 0, 0, width, height); - drawTexture(x + 174, y + 20 + (int) currentScroll, canScroll() ? 232 : 244, 0, 12, 15); + scrollbar.draw(this); searchField.drawTextBox(); } @@ -206,7 +150,7 @@ public class GuiGrid extends GuiBase @Override public void drawForeground(int mouseX, int mouseY) { - handleScrolling(mouseX, mouseY); + scrollbar.update(this, mouseX, mouseY); drawString(7, 7, t("gui.refinedstorage:grid")); diff --git a/src/main/java/refinedstorage/gui/Scrollbar.java b/src/main/java/refinedstorage/gui/Scrollbar.java new file mode 100644 index 000000000..694f43513 --- /dev/null +++ b/src/main/java/refinedstorage/gui/Scrollbar.java @@ -0,0 +1,96 @@ +package refinedstorage.gui; + +import org.lwjgl.input.Mouse; + +public class Scrollbar +{ + private boolean canScroll = true; + + private int x; + private int y; + private int scrollbarWidth; + private int scrollbarHeight; + + private float currentScroll; + private boolean wasClicking = false; + private boolean isScrolling = false; + + public Scrollbar(int x, int y, int scrollbarWidth, int scrollbarHeight) + { + this.x = x; + this.y = y; + this.scrollbarWidth = scrollbarWidth; + this.scrollbarHeight = scrollbarHeight; + } + + public void setCanScroll(boolean canScroll) + { + this.canScroll = canScroll; + } + + public boolean canScroll() + { + return canScroll; + } + + public float getCurrentScroll() + { + return currentScroll; + } + + public void setCurrentScroll(float newCurrentScroll) + { + if (newCurrentScroll < 0) + { + newCurrentScroll = 0; + } + + int scrollbarItselfHeight = 12; + + int max = scrollbarHeight - scrollbarItselfHeight - 3; + + if (newCurrentScroll > max) + { + newCurrentScroll = max; + } + + currentScroll = newCurrentScroll; + } + + public void draw(GuiBase gui) + { + gui.bindTexture("icons.png"); + gui.drawTexture(gui.guiLeft + x, gui.guiTop + y + (int) currentScroll, canScroll() ? 232 : 244, 0, 12, 15); + } + + public void update(GuiBase gui, int mouseX, int mouseY) + { + if (!canScroll()) + { + isScrolling = false; + wasClicking = false; + currentScroll = 0; + } + else + { + boolean down = Mouse.isButtonDown(0); + + if (!wasClicking && down && gui.inBounds(x, y, scrollbarWidth, scrollbarHeight, mouseX, mouseY)) + { + isScrolling = true; + } + + if (!down) + { + isScrolling = false; + } + + wasClicking = down; + + if (isScrolling) + { + setCurrentScroll(mouseY - 20); + } + } + } +} diff --git a/src/main/java/refinedstorage/jei/PluginRefinedStorage.java b/src/main/java/refinedstorage/jei/PluginRefinedStorage.java index cf9898e12..678d28d28 100644 --- a/src/main/java/refinedstorage/jei/PluginRefinedStorage.java +++ b/src/main/java/refinedstorage/jei/PluginRefinedStorage.java @@ -15,6 +15,7 @@ public class PluginRefinedStorage extends BlankModPlugin @Override public void register(IModRegistry registry) { + // @TODO: JEI transfer handler registry.addRecipeCategories(new SoldererRecipeCategory(registry.getJeiHelpers().getGuiHelper())); registry.addRecipeHandlers(new SoldererRecipeHandler()); diff --git a/src/main/resources/assets/refinedstorage/textures/gui/crafting_grid.png b/src/main/resources/assets/refinedstorage/textures/gui/crafting_grid.png index 522b89053..d10eaab81 100644 Binary files a/src/main/resources/assets/refinedstorage/textures/gui/crafting_grid.png and b/src/main/resources/assets/refinedstorage/textures/gui/crafting_grid.png differ diff --git a/src/main/resources/assets/refinedstorage/textures/gui/grid.png b/src/main/resources/assets/refinedstorage/textures/gui/grid.png index 1af3f3491..2d6a3bb86 100644 Binary files a/src/main/resources/assets/refinedstorage/textures/gui/grid.png and b/src/main/resources/assets/refinedstorage/textures/gui/grid.png differ diff --git a/src/main/resources/assets/refinedstorage/textures/icons.png b/src/main/resources/assets/refinedstorage/textures/icons.png index c1e2e651c..19f326da4 100644 Binary files a/src/main/resources/assets/refinedstorage/textures/icons.png and b/src/main/resources/assets/refinedstorage/textures/icons.png differ