Fix inventory scrollbar in regular guis
This commit is contained in:
parent
4f64733981
commit
667553fb3d
@ -23,7 +23,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.Panel2Widget
|
|||||||
import ru.dbotthepony.mc.otm.compat.InventoryScrollPacket
|
import ru.dbotthepony.mc.otm.compat.InventoryScrollPacket
|
||||||
import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorScreen
|
import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorScreen
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
import ru.dbotthepony.mc.otm.core.integerDivisionUp
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel
|
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel
|
||||||
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
||||||
@ -146,7 +146,7 @@ private fun exosuitInventoryLogic(event: ScreenEvent.Init.Post) {
|
|||||||
.max { o1, o2 -> o1.x.compareTo(o2.x) }
|
.max { o1, o2 -> o1.x.compareTo(o2.x) }
|
||||||
.get().x.toFloat() + 26f
|
.get().x.toFloat() + 26f
|
||||||
|
|
||||||
val scrollbar = DiscreteScrollBarPanel(screen, null, { maxScrollDivision(matteryPlayer.exoSuitContainer.containerSize, 9) }, { _, _, newScroll ->
|
val scrollbar = DiscreteScrollBarPanel(screen, null, { integerDivisionUp(matteryPlayer.exoSuitContainer.containerSize, 9) }, { _, _, newScroll ->
|
||||||
inventoryScroll = newScroll
|
inventoryScroll = newScroll
|
||||||
MenuNetworkChannel.sendToServer(InventoryScrollPacket(newScroll).also { it.play(player) })
|
MenuNetworkChannel.sendToServer(InventoryScrollPacket(newScroll).also { it.play(player) })
|
||||||
}, isSlim = true)
|
}, isSlim = true)
|
||||||
|
@ -8,7 +8,7 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.buttons.CheckBoxLabelInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.buttons.CheckBoxLabelInputPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
import ru.dbotthepony.mc.otm.core.integerDivisionDown
|
||||||
import ru.dbotthepony.mc.otm.item.PortableCondensationDriveItem
|
import ru.dbotthepony.mc.otm.item.PortableCondensationDriveItem
|
||||||
import ru.dbotthepony.mc.otm.menu.DriveViewerMenu
|
import ru.dbotthepony.mc.otm.menu.DriveViewerMenu
|
||||||
import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak
|
import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak
|
||||||
@ -49,7 +49,7 @@ class DriveViewerScreen(menu: DriveViewerMenu, inventory: Inventory, title: Comp
|
|||||||
|
|
||||||
val grid = GridPanel(this, frame, 28f, 16f, GRID_WIDTH * 18f, GRID_HEIGHT * 18f, GRID_WIDTH, GRID_HEIGHT)
|
val grid = GridPanel(this, frame, 28f, 16f, GRID_WIDTH * 18f, GRID_HEIGHT * 18f, GRID_WIDTH, GRID_HEIGHT)
|
||||||
|
|
||||||
val scrollBar = DiscreteScrollBarPanel(this, frame, { maxScrollDivision(menu.networkedItemView.itemCount, GRID_WIDTH) }, { _, _, _ -> }, 192f, 14f, 92f)
|
val scrollBar = DiscreteScrollBarPanel(this, frame, { integerDivisionDown(menu.networkedItemView.itemCount, GRID_WIDTH) }, { _, _, _ -> }, 192f, 14f, 92f)
|
||||||
|
|
||||||
views.add(grid)
|
views.add(grid)
|
||||||
views.add(scrollBar)
|
views.add(scrollBar)
|
||||||
|
@ -11,7 +11,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.*
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.panels.buttons.LargeRectangleButtonPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.buttons.LargeRectangleButtonPanel
|
||||||
import ru.dbotthepony.mc.otm.client.setMousePos
|
import ru.dbotthepony.mc.otm.client.setMousePos
|
||||||
import ru.dbotthepony.mc.otm.client.shouldOpenVanillaInventory
|
import ru.dbotthepony.mc.otm.client.shouldOpenVanillaInventory
|
||||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
import ru.dbotthepony.mc.otm.core.integerDivisionDown
|
||||||
import ru.dbotthepony.mc.otm.menu.ExoSuitInventoryMenu
|
import ru.dbotthepony.mc.otm.menu.ExoSuitInventoryMenu
|
||||||
import ru.dbotthepony.mc.otm.network.ExoSuitMenuOpen
|
import ru.dbotthepony.mc.otm.network.ExoSuitMenuOpen
|
||||||
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel
|
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel
|
||||||
@ -49,7 +49,7 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
|
|||||||
|
|
||||||
toolbeltLine.setDockMargin(top = 3f)
|
toolbeltLine.setDockMargin(top = 3f)
|
||||||
|
|
||||||
scrollPanel = DiscreteScrollBarPanel(this, null, maxScroll = { maxScrollDivision(menu.playerCombinedInventorySlots.size, 9) },
|
scrollPanel = DiscreteScrollBarPanel(this, null, maxScroll = { integerDivisionDown(menu.playerCombinedInventorySlots.size, 9) },
|
||||||
scrollCallback = {
|
scrollCallback = {
|
||||||
_, old, new ->
|
_, old, new ->
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.buttons.SmallEnumRectangleButt
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.core.asGetterSetter
|
import ru.dbotthepony.mc.otm.core.asGetterSetter
|
||||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
import ru.dbotthepony.mc.otm.core.integerDivisionDown
|
||||||
import ru.dbotthepony.mc.otm.core.formatReadableNumber
|
import ru.dbotthepony.mc.otm.core.formatReadableNumber
|
||||||
import ru.dbotthepony.mc.otm.core.formatSiComponent
|
import ru.dbotthepony.mc.otm.core.formatSiComponent
|
||||||
import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu
|
import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu
|
||||||
@ -44,7 +44,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
|
|||||||
frame.width = 178f + frame.dockPadding.left + frame.dockPadding.right
|
frame.width = 178f + frame.dockPadding.left + frame.dockPadding.right
|
||||||
|
|
||||||
val viewScrollBar = DiscreteScrollBarPanel(this, topPanel,
|
val viewScrollBar = DiscreteScrollBarPanel(this, topPanel,
|
||||||
{ maxScrollDivision(menu.networkedItemView.itemCount, ITEM_GRID_WIDTH) },
|
{ integerDivisionDown(menu.networkedItemView.itemCount, ITEM_GRID_WIDTH) },
|
||||||
{ _, _, _ -> },
|
{ _, _, _ -> },
|
||||||
28f + ITEM_GRID_WIDTH * 18f + 2f, 16f, ITEM_GRID_HEIGHT * 18f)
|
28f + ITEM_GRID_WIDTH * 18f + 2f, 16f, ITEM_GRID_HEIGHT * 18f)
|
||||||
|
|
||||||
|
@ -8,12 +8,11 @@ import net.minecraft.world.item.ItemStack
|
|||||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternState
|
import ru.dbotthepony.mc.otm.capability.matter.IPatternState
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IReplicationTask
|
import ru.dbotthepony.mc.otm.capability.matter.IReplicationTask
|
||||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||||
import ru.dbotthepony.mc.otm.client.render.element
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.subElement
|
import ru.dbotthepony.mc.otm.client.render.subElement
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.buttons.ButtonPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.buttons.ButtonPanel
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
import ru.dbotthepony.mc.otm.core.integerDivisionDown
|
||||||
import ru.dbotthepony.mc.otm.menu.MatterPanelMenu
|
import ru.dbotthepony.mc.otm.menu.MatterPanelMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.ReplicationRequestPacket
|
import ru.dbotthepony.mc.otm.menu.ReplicationRequestPacket
|
||||||
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel
|
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel
|
||||||
@ -32,9 +31,9 @@ class MatterPanelScreen(
|
|||||||
|
|
||||||
val scrollBar = DiscreteScrollBarPanel(this, frame, {
|
val scrollBar = DiscreteScrollBarPanel(this, frame, {
|
||||||
if (isPatternView) {
|
if (isPatternView) {
|
||||||
maxScrollDivision(menu.patterns.size, GRID_WIDTH)
|
integerDivisionDown(menu.patterns.size, GRID_WIDTH)
|
||||||
} else {
|
} else {
|
||||||
maxScrollDivision(menu.tasks.size, GRID_WIDTH)
|
integerDivisionDown(menu.tasks.size, GRID_WIDTH)
|
||||||
}
|
}
|
||||||
}, { _, _, _ -> })
|
}, { _, _, _ -> })
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import ru.dbotthepony.mc.otm.ClientConfig
|
|||||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton
|
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton
|
||||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
import ru.dbotthepony.mc.otm.core.integerDivisionDown
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
|||||||
} else {
|
} else {
|
||||||
inventoryFrame = FramePanel<MatteryScreen<*>>(this, null, 0f, 0f, INVENTORY_FRAME_WIDTH_EXTENDED, BASE_INVENTORY_FRAME_HEIGHT + AbstractSlotPanel.SIZE * inventoryRows, inventory.displayName).also(this::addPanel)
|
inventoryFrame = FramePanel<MatteryScreen<*>>(this, null, 0f, 0f, INVENTORY_FRAME_WIDTH_EXTENDED, BASE_INVENTORY_FRAME_HEIGHT + AbstractSlotPanel.SIZE * inventoryRows, inventory.displayName).also(this::addPanel)
|
||||||
|
|
||||||
inventoryScrollbar = DiscreteScrollBarPanel(this, inventoryFrame, { maxScrollDivision(menu.playerCombinedInventorySlots.size, 9) }, {
|
inventoryScrollbar = DiscreteScrollBarPanel(this, inventoryFrame, { integerDivisionDown(menu.playerCombinedInventorySlots.size, 9) }, {
|
||||||
_, old, new ->
|
_, old, new ->
|
||||||
|
|
||||||
for (i in old until old + inventoryRows) {
|
for (i in old until old + inventoryRows) {
|
||||||
|
@ -8,7 +8,6 @@ import net.minecraft.client.gui.screens.Screen
|
|||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
|
||||||
import net.minecraft.world.effect.MobEffect
|
import net.minecraft.world.effect.MobEffect
|
||||||
import net.minecraft.world.effect.MobEffectInstance
|
import net.minecraft.world.effect.MobEffectInstance
|
||||||
import net.minecraft.world.effect.MobEffectUtil
|
|
||||||
import net.minecraft.world.entity.LivingEntity
|
import net.minecraft.world.entity.LivingEntity
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.render.TextAlign
|
import ru.dbotthepony.mc.otm.client.render.TextAlign
|
||||||
@ -20,7 +19,7 @@ import ru.dbotthepony.mc.otm.client.render.render
|
|||||||
import ru.dbotthepony.mc.otm.core.RGBAColor
|
import ru.dbotthepony.mc.otm.core.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.core.formatTickDuration
|
import ru.dbotthepony.mc.otm.core.formatTickDuration
|
||||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
import ru.dbotthepony.mc.otm.core.integerDivisionDown
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
|
|
||||||
open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
|
open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
|
||||||
@ -156,7 +155,7 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
protected val effectButtons: MutableMap<MobEffect, EffectSquare> = Object2ObjectArrayMap()
|
protected val effectButtons: MutableMap<MobEffect, EffectSquare> = Object2ObjectArrayMap()
|
||||||
|
|
||||||
fun calculateMaxScroll(scrollBarPanel: DiscreteScrollBarPanel<*>): Int {
|
fun calculateMaxScroll(scrollBarPanel: DiscreteScrollBarPanel<*>): Int {
|
||||||
return maxScrollDivision(entity.activeEffects.size, gridWidth)
|
return integerDivisionDown(entity.activeEffects.size, gridWidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onScrolled(scrollBarPanel: DiscreteScrollBarPanel<*>, oldScroll: Int, newScroll: Int) {
|
fun onScrolled(scrollBarPanel: DiscreteScrollBarPanel<*>, oldScroll: Int, newScroll: Int) {
|
||||||
|
@ -31,11 +31,52 @@ fun BigInteger.toIntSafe(): Int {
|
|||||||
return toInt()
|
return toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0, 9 -> 0
|
||||||
|
* 1, 9 -> 0
|
||||||
|
* 8, 9 -> 0
|
||||||
|
* 9, 9 -> 0
|
||||||
|
* 10, 9 -> 1
|
||||||
|
* 17, 9 -> 1
|
||||||
|
* 18, 9 -> 1
|
||||||
|
* 19, 9 -> 2
|
||||||
|
*/
|
||||||
@Suppress("SameParameterValue")
|
@Suppress("SameParameterValue")
|
||||||
fun maxScrollDivision(elements: Int, elementsPerRow: Int): Int {
|
fun integerDivisionDown(elements: Int, elementsPerRow: Int): Int {
|
||||||
|
require(elements >= 0) { "Invalid amount of elements $elements" }
|
||||||
|
|
||||||
|
if (elements == 0) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
if (elements % elementsPerRow == 0) {
|
if (elements % elementsPerRow == 0) {
|
||||||
return elements / elementsPerRow - 1
|
return elements / elementsPerRow - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return elements / elementsPerRow
|
return elements / elementsPerRow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0, 9 -> 0
|
||||||
|
* 1, 9 -> 1
|
||||||
|
* 8, 9 -> 1
|
||||||
|
* 9, 9 -> 1
|
||||||
|
* 10, 9 -> 2
|
||||||
|
* 17, 9 -> 2
|
||||||
|
* 18, 9 -> 2
|
||||||
|
* 19, 9 -> 3
|
||||||
|
*/
|
||||||
|
@Suppress("SameParameterValue")
|
||||||
|
fun integerDivisionUp(elements: Int, elementsPerRow: Int): Int {
|
||||||
|
require(elements >= 0) { "Invalid amount of elements $elements" }
|
||||||
|
|
||||||
|
if (elements == 0) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elements % elementsPerRow == 0) {
|
||||||
|
return elements / elementsPerRow
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements / elementsPerRow + 1
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user