Fix scrol values on item monitor
This commit is contained in:
parent
0facae6ce4
commit
c89ff117ac
@ -15,6 +15,14 @@ import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu
|
||||
import ru.dbotthepony.mc.otm.next
|
||||
import ru.dbotthepony.mc.otm.prev
|
||||
|
||||
private fun div(a: Int, b: Int): Int {
|
||||
if (a % b == 0) {
|
||||
return a / b - 1
|
||||
}
|
||||
|
||||
return a / b
|
||||
}
|
||||
|
||||
class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Component) :
|
||||
MatteryScreen<ItemMonitorMenu>(menu, inventory, title) {
|
||||
|
||||
@ -34,7 +42,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
|
||||
frame.width = 178f + frame.dockPadding.left + frame.dockPadding.right
|
||||
|
||||
val viewScrollBar = ScrollBarPanel(this, topPanel, 28f + ITEM_GRID_WIDTH * 18f + 2f, 16f, ITEM_GRID_HEIGHT * 18f)
|
||||
viewScrollBar.setupRowMultiplier { menu.view.itemCount / ITEM_GRID_WIDTH }
|
||||
viewScrollBar.setupRowMultiplier { div(menu.view.itemCount, ITEM_GRID_WIDTH) }
|
||||
|
||||
viewScrollBar.dock = Dock.RIGHT
|
||||
viewScrollBar.setDockMargin(left = 2f)
|
||||
@ -45,7 +53,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
|
||||
for (i in 0 until ITEM_GRID_WIDTH * ITEM_GRID_HEIGHT) {
|
||||
object : AbstractSlotPanel(this@ItemMonitorScreen, gridPanel) {
|
||||
override fun getItemStack(): ItemStack {
|
||||
val index = i + viewScrollBar.getScroll(menu.view.itemCount / ITEM_GRID_WIDTH) * ITEM_GRID_WIDTH
|
||||
val index = i + viewScrollBar.getScroll(div(menu.view.itemCount, ITEM_GRID_WIDTH)) * ITEM_GRID_WIDTH
|
||||
return menu.view.sortedView.getOrNull(index)?.stack ?: ItemStack.EMPTY
|
||||
}
|
||||
|
||||
@ -54,7 +62,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
|
||||
}
|
||||
|
||||
override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, mouse_click_type: Int): Boolean {
|
||||
val index = i + viewScrollBar.getScroll(menu.view.itemCount / ITEM_GRID_WIDTH) * ITEM_GRID_WIDTH
|
||||
val index = i + viewScrollBar.getScroll(div(menu.view.itemCount, ITEM_GRID_WIDTH)) * ITEM_GRID_WIDTH
|
||||
menu.view.mouseClick(index, mouse_click_type)
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user