From dd91bd2f178aadbabc533493fd364e7423180247 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 21 Aug 2023 00:10:31 +0700 Subject: [PATCH] Add sorting buttons to ender chest inside exopack menu --- .../otm/capability/MatteryPlayerCapability.kt | 7 +-- .../client/screen/ExopackInventoryScreen.kt | 26 ++++---- .../client/screen/panels/button/Buttons.kt | 60 ++++++++++++------- .../mc/otm/menu/ExopackInventoryMenu.kt | 7 ++- .../mc/otm/menu/ISortingSettings.kt | 10 ++++ 5 files changed, 71 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt index 5fa18e795..94965416b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt @@ -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() { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt index ad9426d39..ca3de74ea 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt @@ -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> makeFluidConfigPanel( class DeviceControls>( screen: S, - parent: FramePanel, + parent: EditablePanel<*>, extra: Iterable> = listOf(), val redstoneConfig: IPlayerInputWithFeedback? = null, val itemConfig: ItemConfigPlayerInput? = null, @@ -409,48 +409,61 @@ class DeviceControls>( return result } - fun sortingButtons(input: MatteryMenu.SortInput) { - addButton(object : LargeRectangleButtonPanel(screen, this@DeviceControls) { + fun sortingButtons(input: MatteryMenu.SortInput, unfoldableSettings: Boolean = true) { + object : LargeRectangleButtonPanel(screen, this@DeviceControls) { var buttons: List>? = 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, 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, this) } + makeButtons() } else { buttons!!.forEach { it.remove() } buttons = null } } } - }) + } } init { @@ -612,14 +625,19 @@ class DeviceControls>( } 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 + } } // не съедаем ввод мыши diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExopackInventoryMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExopackInventoryMenu.kt index 21d2562cf..d93732cb3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExopackInventoryMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExopackInventoryMenu.kt @@ -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 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 } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ISortingSettings.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ISortingSettings.kt index fa9a9552d..8a6a4fe87 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ISortingSettings.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ISortingSettings.kt @@ -28,6 +28,11 @@ interface IBaseSortingSettings : INBTSerializable { } 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 {