Add sorting buttons to ender chest inside exopack menu

This commit is contained in:
DBotThePony 2023-08-21 00:10:31 +07:00
parent c760348f72
commit dd91bd2f17
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 71 additions and 39 deletions

View File

@ -404,10 +404,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
return _exoPackMenu!!
}
val sortingSettings = object : IItemStackSortingSettings {
override var isAscending: Boolean = true
override var sorting: ItemStackSorter = ItemStackSorter.DEFAULT
}
val sortingSettings = IItemStackSortingSettings.Impl()
val enderSortingSettings = IItemStackSortingSettings.Impl()
fun recreateExoPackMenu() {
_exoPackMenu = ExopackInventoryMenu(this)
@ -600,6 +598,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
savetables.bool(::exopackGlows)
savetables.stateful(::sortingSettings)
savetables.stateful(::enderSortingSettings)
}
fun invalidateNetworkState() {

View File

@ -6,6 +6,7 @@ import net.minecraft.world.item.Items
import ru.dbotthepony.mc.otm.client.mousePos
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
import ru.dbotthepony.mc.otm.client.render.ItemStackIcon
import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.client.render.sprites.sprite
@ -16,6 +17,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.InventorySlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.DiscreteScrollBarPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.client.setMousePos
import ru.dbotthepony.mc.otm.client.shouldOpenVanillaInventory
@ -205,11 +207,9 @@ class ExopackInventoryScreen(menu: ExopackInventoryMenu) : MatteryScreen<Exopack
tab.activeIcon = ItemStackIcon(ItemStack(Items.ENDER_CHEST))
tab.inactiveIcon = tab.activeIcon
val enderCanvas = EditablePanel(this, topLine, height = AbstractSlotPanel.SIZE * 3f, width = AbstractSlotPanel.SIZE * 9f)
enderCanvas.dock = Dock.LEFT
val enderCanvas = EditablePanel(this, topLine)
enderCanvas.dock = Dock.FILL
enderCanvas.visible = false
enderCanvas.dockTop = 8f
enderCanvas.dockLeft = 8f
tab.onOpen = Runnable {
enderCanvas.visible = true
@ -223,15 +223,17 @@ class ExopackInventoryScreen(menu: ExopackInventoryMenu) : MatteryScreen<Exopack
menu.enderChestOpenState.accept(false)
}
for (row in 0 .. 2) {
val rowPanel = EditablePanel(this, enderCanvas, height = AbstractSlotPanel.SIZE)
rowPanel.dock = Dock.TOP
val grid = GridPanel.slots(this, enderCanvas, 9, 3)
grid.gravity = RenderGravity.CENTER_LEFT
grid.dock = Dock.LEFT
for (column in 0 .. 8) {
SlotPanel(this, rowPanel, menu.enderChestSlots[row * 9 + column]).also {
it.dock = Dock.LEFT
}
}
val enderControls = DeviceControls(this, enderCanvas)
enderControls.dock = Dock.RIGHT
enderControls.sortingButtons(menu.sortEnderChest!!, false)
enderControls.dockTop = 6f
menu.enderChestSlots.forEach {
SlotPanel(this, grid, it)
}
if (menu.enderChestOpenState.get()) {

View File

@ -301,7 +301,7 @@ private fun <S : MatteryScreen<*>> makeFluidConfigPanel(
class DeviceControls<out S : MatteryScreen<*>>(
screen: S,
parent: FramePanel<S>,
parent: EditablePanel<*>,
extra: Iterable<EditablePanel<S>> = listOf(),
val redstoneConfig: IPlayerInputWithFeedback<RedstoneSetting>? = null,
val itemConfig: ItemConfigPlayerInput? = null,
@ -409,48 +409,61 @@ class DeviceControls<out S : MatteryScreen<*>>(
return result
}
fun sortingButtons(input: MatteryMenu.SortInput) {
addButton(object : LargeRectangleButtonPanel<S>(screen, this@DeviceControls) {
fun sortingButtons(input: MatteryMenu.SortInput, unfoldableSettings: Boolean = true) {
object : LargeRectangleButtonPanel<S>(screen, this@DeviceControls) {
var buttons: List<EditablePanel<*>>? = null
init {
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_now"))
tooltips.add(TextComponent(""))
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_settings").withStyle(ChatFormatting.GRAY))
if (unfoldableSettings) {
tooltips.add(TextComponent(""))
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_settings").withStyle(ChatFormatting.GRAY))
}
icon = Widgets18.SORT_NOW
addButton(this)
if (!unfoldableSettings) {
makeButtons()
}
}
override fun test(value: Int): Boolean {
return value == InputConstants.MOUSE_BUTTON_LEFT || value == InputConstants.MOUSE_BUTTON_RIGHT
return value == InputConstants.MOUSE_BUTTON_LEFT || unfoldableSettings && value == InputConstants.MOUSE_BUTTON_RIGHT
}
override var isDisabled: Boolean
get() = !input.input.test(minecraft.player)
set(value) {}
private fun makeButtons() {
buttons = sortingButtons(input.settings::isAscending.asGetterSetter(), input.settings::sorting.asGetterSetter(), ItemStackSorter.DEFAULT) {
for (v in ItemStackSorter.entries) {
add(v, v.icon, v.title)
}
finish()
}
buttons!!.forEach { removeButton(it) }
buttons!!.forEach { addButton(it as EditablePanel<S>, this) }
}
override fun onClick(mouseButton: Int) {
if (mouseButton == InputConstants.MOUSE_BUTTON_LEFT) {
input.clientInput()
} else {
if (buttons == null) {
buttons = sortingButtons(input.settings::isAscending.asGetterSetter(), input.settings::sorting.asGetterSetter(), ItemStackSorter.DEFAULT) {
for (v in ItemStackSorter.entries) {
add(v, v.icon, v.title)
}
finish()
}
buttons!!.forEach { removeButton(it) }
buttons!!.forEach { addButton(it as EditablePanel<S>, this) }
makeButtons()
} else {
buttons!!.forEach { it.remove() }
buttons = null
}
}
}
})
}
}
init {
@ -612,14 +625,19 @@ class DeviceControls<out S : MatteryScreen<*>>(
}
override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
x = (parent?.width ?: 0f) + 3f
y = dockTop
if (parent is FramePanel<*>) {
x = parent!!.width + 3f
y = dockTop
}
}
override fun tickInner() {
super.tickInner()
x = (parent?.width ?: 0f) + 3f
y = dockTop
if (parent is FramePanel<*>) {
x = parent!!.width + 3f
y = dockTop
}
}
// не съедаем ввод мыши

View File

@ -11,8 +11,6 @@ import net.minecraft.world.inventory.*
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.compat.curios.curiosSlots
import ru.dbotthepony.mc.otm.capability.iterator
import ru.dbotthepony.mc.otm.container.util.iterator
import ru.dbotthepony.mc.otm.container.util.slotIterator
import ru.dbotthepony.mc.otm.menu.input.InstantBooleanInput
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
@ -119,6 +117,8 @@ class ExopackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
val enderChestSlots: List<MatterySlot>
val enderChestOpenState = InstantBooleanInput(this)
val playerEnderSortSettings = IItemStackSortingSettings.inputs(this, capability.enderSortingSettings)
val sortEnderChest: SortInput?
init {
if (capability.isExopackEnderAccessInstalled) {
@ -127,8 +127,11 @@ class ExopackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
addStorageSlot(it, condition = enderChestOpenState)
}
}
sortEnderChest = SortInput(player.enderChestInventory, playerEnderSortSettings)
} else {
enderChestSlots = listOf()
sortEnderChest = null
}
}

View File

@ -28,6 +28,11 @@ interface IBaseSortingSettings : INBTSerializable<CompoundTag?> {
}
interface IItemStackSortingSettings : IBaseSortingSettings {
data class Impl(
override var isAscending: Boolean = true,
override var sorting: ItemStackSorter = ItemStackSorter.DEFAULT,
) : IItemStackSortingSettings
var sorting: ItemStackSorter
override fun serializeNBT(): CompoundTag {
@ -71,6 +76,11 @@ interface IItemStackSortingSettings : IBaseSortingSettings {
}
interface IItemSortingSettings : IBaseSortingSettings {
data class Impl(
override var isAscending: Boolean = true,
override var sorting: ItemSorter = ItemSorter.DEFAULT,
) : IItemSortingSettings
var sorting: ItemSorter
override fun serializeNBT(): CompoundTag {