Row count controls in regular inventory
This commit is contained in:
parent
81001a8736
commit
2dd4d60be1
@ -20,6 +20,18 @@ fun setMousePos(x: Double, y: Double) {
|
||||
GLFW.glfwSetCursorPos(minecraft.window.window, x, y)
|
||||
}
|
||||
|
||||
fun setMousePosScaled(x: Double, y: Double) {
|
||||
GLFW.glfwSetCursorPos(minecraft.window.window, x * minecraft.window.guiScale, y * minecraft.window.guiScale)
|
||||
}
|
||||
|
||||
fun setMousePos(x: Float, y: Float) {
|
||||
GLFW.glfwSetCursorPos(minecraft.window.window, x.toDouble(), y.toDouble())
|
||||
}
|
||||
|
||||
fun setMousePosScaled(x: Float, y: Float) {
|
||||
GLFW.glfwSetCursorPos(minecraft.window.window, x * minecraft.window.guiScale, y * minecraft.window.guiScale)
|
||||
}
|
||||
|
||||
private val cursorXPosBuf = ByteBuffer.allocateDirect(8).also { it.order(ByteOrder.LITTLE_ENDIAN) }.asDoubleBuffer()
|
||||
private val cursorYPosBuf = ByteBuffer.allocateDirect(8).also { it.order(ByteOrder.LITTLE_ENDIAN) }.asDoubleBuffer()
|
||||
|
||||
|
@ -19,28 +19,14 @@ import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak
|
||||
|
||||
@MouseTweaksDisableWheelTweak
|
||||
class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuitInventoryMenu>(menu, TranslatableComponent("otm.gui.exosuit")) {
|
||||
var inventoryRows = 3
|
||||
set(value) {
|
||||
val newValue = value.coerceAtLeast(3).coerceAtMost(6)
|
||||
val old = field
|
||||
|
||||
if (field != newValue) {
|
||||
field = newValue
|
||||
|
||||
if (mainFrame != null) {
|
||||
updateInventoryRows(old)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var mainInventoryLine: EditablePanel<ExoSuitInventoryScreen>
|
||||
private lateinit var scrollPanel: DiscreteScrollBarPanel<ExoSuitInventoryScreen>
|
||||
|
||||
private fun updateInventoryRows(old: Int) {
|
||||
override fun updateInventoryRows(old: Int) {
|
||||
mainFrame!!.height = FRAME_BASE_HEIGHT + inventoryRows * AbstractSlotPanel.SIZE
|
||||
mainInventoryLine.height = AbstractSlotPanel.SIZE * inventoryRows
|
||||
|
||||
for (i in scrollPanel.scroll until scrollPanel.scroll + old) {
|
||||
for (i in scrollPanel.scroll + inventoryRows until scrollPanel.scroll + old) {
|
||||
getInventorySlotsRow(i).visible = false
|
||||
}
|
||||
|
||||
@ -78,7 +64,7 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
|
||||
row.parent = mainInventoryLine
|
||||
}
|
||||
|
||||
menu.lastScroll = new
|
||||
lastScroll = new
|
||||
})
|
||||
|
||||
mainInventoryLine = object : EditablePanel<ExoSuitInventoryScreen>(this@ExoSuitInventoryScreen, frame, height = AbstractSlotPanel.SIZE * inventoryRows) {
|
||||
@ -87,7 +73,7 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
|
||||
}
|
||||
}
|
||||
|
||||
scrollPanel.scroll = menu.lastScroll
|
||||
scrollPanel.scroll = lastScroll
|
||||
scrollPanel.parent = mainInventoryLine
|
||||
|
||||
mainInventoryLine.dock = Dock.BOTTOM
|
||||
@ -177,17 +163,9 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
|
||||
setMousePos(mouseX, mouseY)
|
||||
}).also { it.tooltip = TranslatableComponent("otm.gui.exosuit.go_back") }
|
||||
|
||||
HeightControls(this, frame, frame.width + 2f, frame.height.coerceAtMost(95f)) {
|
||||
inventoryRows += if (it) 1 else -1
|
||||
|
||||
val movePixels = if (it) -AbstractSlotPanel.SIZE / 2f else AbstractSlotPanel.SIZE / 2f
|
||||
|
||||
makeInventoryRowsControls(frame, frame.width + 2f, frame.height.coerceAtMost(95f)) { movePixels ->
|
||||
frame.y += movePixels
|
||||
moveMousePosScaled(y = movePixels)
|
||||
|
||||
HeightControls.Status.of(inventoryRows < 6, inventoryRows > 3)
|
||||
}.also {
|
||||
it.controlStatus = HeightControls.Status.of(inventoryRows < 6, inventoryRows > 3)
|
||||
}
|
||||
|
||||
return frame
|
||||
|
@ -16,7 +16,7 @@ import net.minecraftforge.client.event.ContainerScreenEvent.Render.Foreground
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.lwjgl.opengl.GL13
|
||||
import ru.dbotthepony.mc.otm.capability.matteryPlayer
|
||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
|
||||
@ -34,8 +34,8 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
|
||||
protected val panels = ArrayDeque<EditablePanel<*>>()
|
||||
|
||||
var inventoryFrame: FramePanel<out MatteryScreen<*>>? = null
|
||||
var mainFrame: FramePanel<out MatteryScreen<*>>? = null
|
||||
var inventoryFrame: FramePanel<MatteryScreen<*>>? = null
|
||||
var mainFrame: FramePanel<MatteryScreen<*>>? = null
|
||||
private var madeMainFrame = false
|
||||
|
||||
var itemRenderer: ItemRenderer
|
||||
@ -52,6 +52,53 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
val isQuickCrafting get() = isQuickCrafting
|
||||
|
||||
private val inventorySlotsRows = Int2ObjectAVLTreeMap<EditablePanel<MatteryScreen<*>>>()
|
||||
private lateinit var slotListCanvas: EditablePanel<MatteryScreen<*>>
|
||||
private lateinit var inventoryScrollbar: DiscreteScrollBarPanel<MatteryScreen<*>>
|
||||
|
||||
var inventoryRows = lastRows
|
||||
set(value) {
|
||||
val newValue = value.coerceAtLeast(MIN_ROWS).coerceAtMost(MAX_ROWS)
|
||||
val old = field
|
||||
|
||||
if (field != newValue) {
|
||||
field = newValue
|
||||
updateInventoryRows(old)
|
||||
lastRows = newValue
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun updateInventoryRows(old: Int) {
|
||||
if (inventoryFrame == null) {
|
||||
return
|
||||
}
|
||||
|
||||
slotListCanvas.height = AbstractSlotPanel.SIZE * inventoryRows
|
||||
inventoryFrame!!.height = BASE_INVENTORY_FRAME_HEIGHT + slotListCanvas.height
|
||||
|
||||
for (i in inventoryScrollbar.scroll + inventoryRows until inventoryScrollbar.scroll + old) {
|
||||
getInventorySlotsRow(i).visible = false
|
||||
}
|
||||
|
||||
for (i in inventoryScrollbar.scroll until inventoryScrollbar.scroll + inventoryRows) {
|
||||
getInventorySlotsRow(i).also {
|
||||
it.visible = true
|
||||
it.parent = slotListCanvas
|
||||
it.y = (i - inventoryScrollbar.scroll) * AbstractSlotPanel.SIZE
|
||||
}
|
||||
}
|
||||
|
||||
inventoryScrollbar.scroll = inventoryScrollbar.scroll
|
||||
}
|
||||
|
||||
protected fun makeInventoryRowsControls(parent: EditablePanel<*>, x: Float, y: Float, callback: (Float) -> Unit): HeightControls<*> {
|
||||
return HeightControls(this, parent, x, y) {
|
||||
inventoryRows += if (it) 1 else -1
|
||||
callback.invoke(if (it) -AbstractSlotPanel.SIZE / 2f else AbstractSlotPanel.SIZE / 2f)
|
||||
HeightControls.Status.of(inventoryRows < 6, inventoryRows > 3)
|
||||
}.also {
|
||||
it.controlStatus = HeightControls.Status.of(inventoryRows < 6, inventoryRows > 3)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
if (menu.playerInventorySlots.isNotEmpty() && menu.autoCreateInventoryFrame) {
|
||||
@ -77,18 +124,16 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inventoryFrame = FramePanel<MatteryScreen<*>>(this, null, 0f, 0f, INVENTORY_FRAME_WIDTH_EXTENDED, INVENTORY_FRAME_HEIGHT, 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)
|
||||
|
||||
var slotListCanvas: EditablePanel<MatteryScreen<*>>? = null
|
||||
|
||||
val scrollbar = DiscreteScrollBarPanel(this, inventoryFrame, { ((menu.playerCombinedInventorySlots.size - 27) + 8) / 9 }, {
|
||||
inventoryScrollbar = DiscreteScrollBarPanel(this, inventoryFrame, { ((menu.playerCombinedInventorySlots.size - inventoryRows * 9) + 8) / 9 }, {
|
||||
_, old, new ->
|
||||
|
||||
for (i in old .. old + 2) {
|
||||
for (i in old until old + inventoryRows) {
|
||||
getInventorySlotsRow(i).visible = false
|
||||
}
|
||||
|
||||
for (i in new .. new + 2) {
|
||||
for (i in new until new + inventoryRows) {
|
||||
getInventorySlotsRow(i).also {
|
||||
it.visible = true
|
||||
it.parent = slotListCanvas
|
||||
@ -96,12 +141,12 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
}
|
||||
}
|
||||
|
||||
menu.ply.matteryPlayer?.exoSuitMenu?.lastScroll = new
|
||||
lastScroll = new
|
||||
})
|
||||
|
||||
slotListCanvas = object : EditablePanel<MatteryScreen<*>>(this@MatteryScreen, inventoryFrame, height = AbstractSlotPanel.SIZE * 3f) {
|
||||
slotListCanvas = object : EditablePanel<MatteryScreen<*>>(this@MatteryScreen, inventoryFrame, height = AbstractSlotPanel.SIZE * inventoryRows) {
|
||||
override fun mouseScrolledInner(x: Double, y: Double, scroll: Double): Boolean {
|
||||
scrollbar.mouseScrolledInner(x, y, scroll)
|
||||
inventoryScrollbar.mouseScrolledInner(x, y, scroll)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -115,17 +160,23 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
SlotPanel(this, hotbarStrip, slot).also { it.dock = Dock.LEFT }
|
||||
}
|
||||
|
||||
scrollbar.parent = slotListCanvas
|
||||
scrollbar.dock = Dock.RIGHT
|
||||
inventoryScrollbar.parent = slotListCanvas
|
||||
inventoryScrollbar.dock = Dock.RIGHT
|
||||
|
||||
scrollbar.scroll = menu.ply.matteryPlayer?.exoSuitMenu?.lastScroll ?: 0
|
||||
inventoryScrollbar.scroll = lastScroll
|
||||
|
||||
for (i in scrollbar.scroll .. scrollbar.scroll + 2) {
|
||||
for (i in inventoryScrollbar.scroll until inventoryScrollbar.scroll + inventoryRows) {
|
||||
getInventorySlotsRow(i).also {
|
||||
it.parent = slotListCanvas
|
||||
it.y = (i - scrollbar.scroll) * AbstractSlotPanel.SIZE
|
||||
it.y = (i - inventoryScrollbar.scroll) * AbstractSlotPanel.SIZE
|
||||
}
|
||||
}
|
||||
|
||||
makeInventoryRowsControls(inventoryFrame!!, inventoryFrame!!.width + 2f, 0f) { movePixels ->
|
||||
mainFrame?.let { it.y += movePixels }
|
||||
inventoryFrame?.let { it.y += movePixels }
|
||||
moveMousePosScaled(y = movePixels)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,7 +221,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
movePanels()
|
||||
}
|
||||
|
||||
fun addPanel(panel: EditablePanel<out MatteryScreen<*>>): Boolean {
|
||||
fun addPanel(panel: EditablePanel<MatteryScreen<*>>): Boolean {
|
||||
if (!panels.contains(panel)) {
|
||||
panels.addFirst(panel)
|
||||
return true
|
||||
@ -179,7 +230,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
return false
|
||||
}
|
||||
|
||||
fun removePanel(panel: EditablePanel<out MatteryScreen<*>>): Boolean {
|
||||
fun removePanel(panel: EditablePanel<MatteryScreen<*>>): Boolean {
|
||||
val indexOf = panels.indexOf(panel)
|
||||
|
||||
if (indexOf != -1) {
|
||||
@ -195,7 +246,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
*
|
||||
* @param panel panel to be pushed up
|
||||
*/
|
||||
fun popup(panel: EditablePanel<out MatteryScreen<*>>) {
|
||||
fun popup(panel: EditablePanel<MatteryScreen<*>>) {
|
||||
val indexOf = panels.indexOf(panel)
|
||||
|
||||
require(indexOf != -1) { "No such panel $panel" }
|
||||
@ -215,7 +266,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
*
|
||||
* @return FramePanel created, or null
|
||||
*/
|
||||
protected open fun makeMainFrame(): FramePanel<out MatteryScreen<*>>? {
|
||||
protected open fun makeMainFrame(): FramePanel<MatteryScreen<*>>? {
|
||||
return FramePanel(this, null, 0f, 0f, DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HEIGHT, getTitle())
|
||||
}
|
||||
|
||||
@ -473,6 +524,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
const val INVENTORY_FRAME_WIDTH = DEFAULT_FRAME_WIDTH
|
||||
const val INVENTORY_FRAME_WIDTH_EXTENDED = DEFAULT_FRAME_WIDTH + ScrollBarConstants.WIDTH + 2f
|
||||
const val INVENTORY_FRAME_HEIGHT = 3f * AbstractSlotPanel.SIZE + AbstractSlotPanel.SIZE + 24f
|
||||
const val BASE_INVENTORY_FRAME_HEIGHT = AbstractSlotPanel.SIZE + 24f
|
||||
|
||||
const val GAUGE_TOP_WITH_SLOT = 17f
|
||||
const val GAUGE_TOP_WITHOUT_SLOT = 26f
|
||||
@ -480,5 +532,11 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
const val PROGRESS_ARROW_TOP = 42f
|
||||
const val PROGRESS_SLOT_TOP = 41f
|
||||
const val LEFT_MARGIN = 8f
|
||||
|
||||
const val MIN_ROWS = 3
|
||||
const val MAX_ROWS = 6
|
||||
|
||||
var lastScroll = 0
|
||||
var lastRows = 3
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.mc.otm.client.minecraft
|
||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||
import ru.dbotthepony.mc.otm.client.render.popScissorRect
|
||||
import ru.dbotthepony.mc.otm.client.render.pushScissorRect
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
@ -1207,4 +1208,8 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
setDockMargin(0f, 0f, 0f, 0f)
|
||||
return grid
|
||||
}
|
||||
|
||||
fun mouseToCenter() {
|
||||
moveMousePosScaled(absoluteX + width / 2f, absoluteY + height / 2f)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import ru.dbotthepony.mc.otm.network.ExoSuitSlotPacket
|
||||
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel
|
||||
|
||||
class ExoSuitInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMenu(null, CONTAINER_ID, capability.ply.inventory) {
|
||||
var lastScroll = 0
|
||||
override val storageSlots: Collection<Slot> get() = listOf()
|
||||
|
||||
val craftingGrid: CraftingContainer
|
||||
|
Loading…
Reference in New Issue
Block a user