Fixed bug where scrollbar didn't scroll correctly and thus hiding some items, fixes #245

This commit is contained in:
Raoul Van den Berge
2016-08-10 21:22:40 +02:00
parent 8bfc73d9a0
commit 11b429e28c
7 changed files with 55 additions and 86 deletions

View File

@@ -3,6 +3,7 @@
### 0.8.18 ### 0.8.18
**Bugfixes** **Bugfixes**
- Fixed detector mode not persisting - Fixed detector mode not persisting
- Fixed bug where scrollbar didn't scroll correctly and thus hiding some items
### 0.8.17 ### 0.8.17
**Bugfixes** **Bugfixes**

View File

@@ -34,8 +34,8 @@ public class GuiController extends GuiBase {
@Override @Override
public void update(int x, int y) { public void update(int x, int y) {
getScrollbar().setCanScroll(getRows() > VISIBLE_ROWS); getScrollbar().setEnabled(getRows() > VISIBLE_ROWS);
getScrollbar().setScrollDelta((float) getScrollbar().getScrollbarHeight() / (float) getRows()); getScrollbar().setMaxOffset(getRows() - VISIBLE_ROWS);
} }
@Override @Override
@@ -57,7 +57,7 @@ public class GuiController extends GuiBase {
int x = 33; int x = 33;
int y = 26; int y = 26;
int slot = getOffset() * 2; int slot = getScrollbar().getOffset() * 2;
RenderHelper.enableGUIStandardItemLighting(); RenderHelper.enableGUIStandardItemLighting();
@@ -105,13 +105,7 @@ public class GuiController extends GuiBase {
} }
} }
private int getOffset() {
return (int) Math.ceil(getScrollbar().getCurrentScroll() / 59f * (float) getRows());
}
private int getRows() { private int getRows() {
int max = (int) Math.ceil((float) TileController.NODES.getValue().size() / (float) 2); return Math.max(0, (int) Math.ceil((float) TileController.NODES.getValue().size() / 2F));
return max < 0 ? 0 : max;
} }
} }

View File

@@ -56,8 +56,8 @@ public class GuiCraftingMonitor extends GuiBase {
@Override @Override
public void update(int x, int y) { public void update(int x, int y) {
getScrollbar().setCanScroll(getRows() > VISIBLE_ROWS); getScrollbar().setEnabled(getRows() > VISIBLE_ROWS);
getScrollbar().setScrollDelta((float) getScrollbar().getScrollbarHeight() / (float) getRows()); getScrollbar().setMaxOffset(getRows() - VISIBLE_ROWS);
if (itemSelected >= getTasks().size()) { if (itemSelected >= getTasks().size()) {
itemSelected = -1; itemSelected = -1;
@@ -86,7 +86,7 @@ public class GuiCraftingMonitor extends GuiBase {
int x = 8; int x = 8;
int y = 20; int y = 20;
int item = getOffset() * 2; int item = getScrollbar().getOffset() * 2;
RenderHelper.enableGUIStandardItemLighting(); RenderHelper.enableGUIStandardItemLighting();
@@ -147,14 +147,8 @@ public class GuiCraftingMonitor extends GuiBase {
} }
} }
private int getOffset() {
return (int) Math.ceil(getScrollbar().getCurrentScroll() / 89f * (float) getRows());
}
private int getRows() { private int getRows() {
int max = (int) Math.ceil((float) getTasks().size() / (float) 2); return Math.max(0, (int) Math.ceil((float) getTasks().size() / (float) 2));
return max < 0 ? 0 : max;
} }
@Override @Override
@@ -175,7 +169,7 @@ public class GuiCraftingMonitor extends GuiBase {
if (mouseButton == 0 && inBounds(8, 20, 144, 90, mouseX - guiLeft, mouseY - guiTop)) { if (mouseButton == 0 && inBounds(8, 20, 144, 90, mouseX - guiLeft, mouseY - guiTop)) {
itemSelected = -1; itemSelected = -1;
int item = getOffset() * 2; int item = getScrollbar().getOffset() * 2;
for (int y = 0; y < 3; ++y) { for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 2; ++x) { for (int x = 0; x < 2; ++x) {

View File

@@ -3,80 +3,56 @@ package refinedstorage.gui;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
public class Scrollbar { public class Scrollbar {
private boolean canScroll = true; private static final int SCROLLER_HEIGHT = 15;
private int x; private int x;
private int y; private int y;
private int scrollbarWidth; private int width;
private int scrollbarHeight; private int height;
private boolean enabled = false;
private float scrollDelta = 15f; private int offset;
private int maxOffset;
private float currentScroll;
private boolean wasClicking = false; private boolean wasClicking = false;
private boolean isScrolling = false; private boolean isScrolling = false;
public Scrollbar(int x, int y, int scrollbarWidth, int scrollbarHeight) { public Scrollbar(int x, int y, int width, int height) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.scrollbarWidth = scrollbarWidth; this.width = width;
this.scrollbarHeight = scrollbarHeight; this.height = height;
} }
public int getScrollbarWidth() { public int getWidth() {
return scrollbarWidth; return width;
} }
public int getScrollbarHeight() { public int getHeight() {
return scrollbarHeight; return height;
} }
public void setCanScroll(boolean canScroll) { public void setEnabled(boolean enabled) {
this.canScroll = canScroll; this.enabled = enabled;
} }
public boolean canScroll() { public boolean isEnabled() {
return canScroll; return enabled;
}
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 setScrollDelta(float delta) {
this.scrollDelta = delta;
} }
public void draw(GuiBase gui) { public void draw(GuiBase gui) {
gui.bindTexture("icons.png"); gui.bindTexture("icons.png");
gui.drawTexture(gui.getGuiLeft() + x, gui.getGuiTop() + y + (int) currentScroll, canScroll() ? 232 : 244, 0, 12, 15); gui.drawTexture(gui.getGuiLeft() + x, gui.getGuiTop() + y + (int) Math.min(height - SCROLLER_HEIGHT, (float) offset / (float) maxOffset * (float) (height - SCROLLER_HEIGHT)), isEnabled() ? 232 : 244, 0, 12, 15);
} }
public void update(GuiBase gui, int mouseX, int mouseY) { public void update(GuiBase gui, int mouseX, int mouseY) {
if (!canScroll()) { if (!isEnabled()) {
isScrolling = false; isScrolling = false;
wasClicking = false; wasClicking = false;
currentScroll = 0;
} else { } else {
boolean down = Mouse.isButtonDown(0); boolean down = Mouse.isButtonDown(0);
if (!wasClicking && down && gui.inBounds(x, y, scrollbarWidth, scrollbarHeight, mouseX, mouseY)) { if (!wasClicking && down && gui.inBounds(x, y, width, height, mouseX, mouseY)) {
isScrolling = true; isScrolling = true;
} }
@@ -87,20 +63,32 @@ public class Scrollbar {
wasClicking = down; wasClicking = down;
if (isScrolling) { if (isScrolling) {
setCurrentScroll(mouseY - 20); setOffset((int) Math.floor((float) (mouseY - SCROLLER_HEIGHT) / (float) (height - SCROLLER_HEIGHT) * (float) maxOffset));
} }
} }
} }
public void wheel(int delta) { public void wheel(int delta) {
if (canScroll()) { if (isEnabled()) {
delta = Math.max(Math.min(-delta, 1), -1); setOffset(offset + Math.max(Math.min(-delta, 1), -1));
}
}
if (delta == -1) { public void setMaxOffset(int maxOffset) {
setCurrentScroll(currentScroll - scrollDelta); this.maxOffset = maxOffset;
} else if (delta == 1) {
setCurrentScroll(currentScroll + scrollDelta); if (offset > maxOffset) {
} this.offset = Math.max(0, maxOffset);
}
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
if (offset >= 0 && offset <= maxOffset) {
this.offset = offset;
} }
} }
} }

View File

@@ -58,7 +58,6 @@ public class GuiGrid extends GuiBase {
super(container, 227, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 247 : 208); super(container, 227, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 247 : 208);
setScrollbar(new Scrollbar(174, 20, 12, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 70 : 88)); setScrollbar(new Scrollbar(174, 20, 12, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 70 : 88));
getScrollbar().setCanScroll(false);
this.container = container; this.container = container;
this.grid = grid; this.grid = grid;
@@ -178,8 +177,8 @@ public class GuiGrid extends GuiBase {
SORTED_ITEMS = sortedItems; SORTED_ITEMS = sortedItems;
getScrollbar().setCanScroll(getRows() > getVisibleRows()); getScrollbar().setEnabled(getRows() > getVisibleRows());
getScrollbar().setScrollDelta((float) getScrollbar().getScrollbarHeight() / (float) getRows()); getScrollbar().setMaxOffset(getRows() - getVisibleRows());
} }
@Override @Override
@@ -191,14 +190,8 @@ public class GuiGrid extends GuiBase {
} }
} }
private int getOffset() {
return (int) Math.ceil(getScrollbar().getCurrentScroll() / 70f * (float) getRows());
}
private int getRows() { private int getRows() {
int max = (int) Math.ceil((float) SORTED_ITEMS.size() / 9f); return Math.max(0, (int) Math.ceil((float) SORTED_ITEMS.size() / 9F));
return max < 0 ? 0 : max;
} }
private boolean isOverSlotWithItem() { private boolean isOverSlotWithItem() {
@@ -271,7 +264,7 @@ public class GuiGrid extends GuiBase {
this.slotNumber = -1; this.slotNumber = -1;
int slot = getOffset() * 9; int slot = getScrollbar().getOffset() * 9;
RenderHelper.enableGUIStandardItemLighting(); RenderHelper.enableGUIStandardItemLighting();

View File

@@ -50,7 +50,7 @@ public class ItemStorageDisk extends ItemBase {
super.onUpdate(stack, world, entity, slot, selected); super.onUpdate(stack, world, entity, slot, selected);
if (!stack.hasTagCompound()) { if (!stack.hasTagCompound()) {
if (stack.getItemDamage() == 5) { if (stack.getItemDamage() == TYPE_DEBUG) {
applyDebugDiskData(stack); applyDebugDiskData(stack);
} else { } else {
NBTStorage.createStackWithNBT(stack); NBTStorage.createStackWithNBT(stack);

View File

@@ -189,7 +189,6 @@ public class ClientProxy extends CommonProxy {
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_16K, new ModelResourceLocation("refinedstorage:16k_storage_disk", "inventory")); ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_16K, new ModelResourceLocation("refinedstorage:16k_storage_disk", "inventory"));
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_64K, new ModelResourceLocation("refinedstorage:64k_storage_disk", "inventory")); ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_64K, new ModelResourceLocation("refinedstorage:64k_storage_disk", "inventory"));
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_CREATIVE, new ModelResourceLocation("refinedstorage:creative_storage_disk", "inventory")); ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_CREATIVE, new ModelResourceLocation("refinedstorage:creative_storage_disk", "inventory"));
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_DEBUG, new ModelResourceLocation("refinedstorage:debug_storage_disk", "inventory"));
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_PART, ItemStoragePart.TYPE_1K, new ModelResourceLocation("refinedstorage:1k_storage_part", "inventory")); ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_PART, ItemStoragePart.TYPE_1K, new ModelResourceLocation("refinedstorage:1k_storage_part", "inventory"));
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_PART, ItemStoragePart.TYPE_4K, new ModelResourceLocation("refinedstorage:4k_storage_part", "inventory")); ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_PART, ItemStoragePart.TYPE_4K, new ModelResourceLocation("refinedstorage:4k_storage_part", "inventory"));