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
**Bugfixes**
- Fixed detector mode not persisting
- Fixed bug where scrollbar didn't scroll correctly and thus hiding some items
### 0.8.17
**Bugfixes**

View File

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

View File

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

View File

@@ -3,80 +3,56 @@ package refinedstorage.gui;
import org.lwjgl.input.Mouse;
public class Scrollbar {
private boolean canScroll = true;
private static final int SCROLLER_HEIGHT = 15;
private int x;
private int y;
private int scrollbarWidth;
private int scrollbarHeight;
private int width;
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 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.y = y;
this.scrollbarWidth = scrollbarWidth;
this.scrollbarHeight = scrollbarHeight;
this.width = width;
this.height = height;
}
public int getScrollbarWidth() {
return scrollbarWidth;
public int getWidth() {
return width;
}
public int getScrollbarHeight() {
return scrollbarHeight;
public int getHeight() {
return height;
}
public void setCanScroll(boolean canScroll) {
this.canScroll = canScroll;
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
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 setScrollDelta(float delta) {
this.scrollDelta = delta;
public boolean isEnabled() {
return enabled;
}
public void draw(GuiBase gui) {
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) {
if (!canScroll()) {
if (!isEnabled()) {
isScrolling = false;
wasClicking = false;
currentScroll = 0;
} else {
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;
}
@@ -87,20 +63,32 @@ public class Scrollbar {
wasClicking = down;
if (isScrolling) {
setCurrentScroll(mouseY - 20);
setOffset((int) Math.floor((float) (mouseY - SCROLLER_HEIGHT) / (float) (height - SCROLLER_HEIGHT) * (float) maxOffset));
}
}
}
public void wheel(int delta) {
if (canScroll()) {
delta = Math.max(Math.min(-delta, 1), -1);
if (isEnabled()) {
setOffset(offset + Math.max(Math.min(-delta, 1), -1));
}
}
if (delta == -1) {
setCurrentScroll(currentScroll - scrollDelta);
} else if (delta == 1) {
setCurrentScroll(currentScroll + scrollDelta);
}
public void setMaxOffset(int maxOffset) {
this.maxOffset = maxOffset;
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);
setScrollbar(new Scrollbar(174, 20, 12, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 70 : 88));
getScrollbar().setCanScroll(false);
this.container = container;
this.grid = grid;
@@ -178,8 +177,8 @@ public class GuiGrid extends GuiBase {
SORTED_ITEMS = sortedItems;
getScrollbar().setCanScroll(getRows() > getVisibleRows());
getScrollbar().setScrollDelta((float) getScrollbar().getScrollbarHeight() / (float) getRows());
getScrollbar().setEnabled(getRows() > getVisibleRows());
getScrollbar().setMaxOffset(getRows() - getVisibleRows());
}
@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() {
int max = (int) Math.ceil((float) SORTED_ITEMS.size() / 9f);
return max < 0 ? 0 : max;
return Math.max(0, (int) Math.ceil((float) SORTED_ITEMS.size() / 9F));
}
private boolean isOverSlotWithItem() {
@@ -271,7 +264,7 @@ public class GuiGrid extends GuiBase {
this.slotNumber = -1;
int slot = getOffset() * 9;
int slot = getScrollbar().getOffset() * 9;
RenderHelper.enableGUIStandardItemLighting();

View File

@@ -50,7 +50,7 @@ public class ItemStorageDisk extends ItemBase {
super.onUpdate(stack, world, entity, slot, selected);
if (!stack.hasTagCompound()) {
if (stack.getItemDamage() == 5) {
if (stack.getItemDamage() == TYPE_DEBUG) {
applyDebugDiskData(stack);
} else {
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_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_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_4K, new ModelResourceLocation("refinedstorage:4k_storage_part", "inventory"));