Add sorting buttons to ender chest inside exopack menu
This commit is contained in:
parent
c760348f72
commit
dd91bd2f17
@ -404,10 +404,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
|||||||
return _exoPackMenu!!
|
return _exoPackMenu!!
|
||||||
}
|
}
|
||||||
|
|
||||||
val sortingSettings = object : IItemStackSortingSettings {
|
val sortingSettings = IItemStackSortingSettings.Impl()
|
||||||
override var isAscending: Boolean = true
|
val enderSortingSettings = IItemStackSortingSettings.Impl()
|
||||||
override var sorting: ItemStackSorter = ItemStackSorter.DEFAULT
|
|
||||||
}
|
|
||||||
|
|
||||||
fun recreateExoPackMenu() {
|
fun recreateExoPackMenu() {
|
||||||
_exoPackMenu = ExopackInventoryMenu(this)
|
_exoPackMenu = ExopackInventoryMenu(this)
|
||||||
@ -600,6 +598,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
|||||||
savetables.bool(::exopackGlows)
|
savetables.bool(::exopackGlows)
|
||||||
|
|
||||||
savetables.stateful(::sortingSettings)
|
savetables.stateful(::sortingSettings)
|
||||||
|
savetables.stateful(::enderSortingSettings)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun invalidateNetworkState() {
|
fun invalidateNetworkState() {
|
||||||
|
@ -6,6 +6,7 @@ import net.minecraft.world.item.Items
|
|||||||
import ru.dbotthepony.mc.otm.client.mousePos
|
import ru.dbotthepony.mc.otm.client.mousePos
|
||||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||||
import ru.dbotthepony.mc.otm.client.render.ItemStackIcon
|
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.client.render.Widgets18
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.render.sprites.sprite
|
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.InventorySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
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.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.screen.widget.ProgressGaugePanel
|
||||||
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
|
||||||
@ -205,11 +207,9 @@ class ExopackInventoryScreen(menu: ExopackInventoryMenu) : MatteryScreen<Exopack
|
|||||||
tab.activeIcon = ItemStackIcon(ItemStack(Items.ENDER_CHEST))
|
tab.activeIcon = ItemStackIcon(ItemStack(Items.ENDER_CHEST))
|
||||||
tab.inactiveIcon = tab.activeIcon
|
tab.inactiveIcon = tab.activeIcon
|
||||||
|
|
||||||
val enderCanvas = EditablePanel(this, topLine, height = AbstractSlotPanel.SIZE * 3f, width = AbstractSlotPanel.SIZE * 9f)
|
val enderCanvas = EditablePanel(this, topLine)
|
||||||
enderCanvas.dock = Dock.LEFT
|
enderCanvas.dock = Dock.FILL
|
||||||
enderCanvas.visible = false
|
enderCanvas.visible = false
|
||||||
enderCanvas.dockTop = 8f
|
|
||||||
enderCanvas.dockLeft = 8f
|
|
||||||
|
|
||||||
tab.onOpen = Runnable {
|
tab.onOpen = Runnable {
|
||||||
enderCanvas.visible = true
|
enderCanvas.visible = true
|
||||||
@ -223,15 +223,17 @@ class ExopackInventoryScreen(menu: ExopackInventoryMenu) : MatteryScreen<Exopack
|
|||||||
menu.enderChestOpenState.accept(false)
|
menu.enderChestOpenState.accept(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (row in 0 .. 2) {
|
val grid = GridPanel.slots(this, enderCanvas, 9, 3)
|
||||||
val rowPanel = EditablePanel(this, enderCanvas, height = AbstractSlotPanel.SIZE)
|
grid.gravity = RenderGravity.CENTER_LEFT
|
||||||
rowPanel.dock = Dock.TOP
|
grid.dock = Dock.LEFT
|
||||||
|
|
||||||
for (column in 0 .. 8) {
|
val enderControls = DeviceControls(this, enderCanvas)
|
||||||
SlotPanel(this, rowPanel, menu.enderChestSlots[row * 9 + column]).also {
|
enderControls.dock = Dock.RIGHT
|
||||||
it.dock = Dock.LEFT
|
enderControls.sortingButtons(menu.sortEnderChest!!, false)
|
||||||
}
|
enderControls.dockTop = 6f
|
||||||
}
|
|
||||||
|
menu.enderChestSlots.forEach {
|
||||||
|
SlotPanel(this, grid, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menu.enderChestOpenState.get()) {
|
if (menu.enderChestOpenState.get()) {
|
||||||
|
@ -301,7 +301,7 @@ private fun <S : MatteryScreen<*>> makeFluidConfigPanel(
|
|||||||
|
|
||||||
class DeviceControls<out S : MatteryScreen<*>>(
|
class DeviceControls<out S : MatteryScreen<*>>(
|
||||||
screen: S,
|
screen: S,
|
||||||
parent: FramePanel<S>,
|
parent: EditablePanel<*>,
|
||||||
extra: Iterable<EditablePanel<S>> = listOf(),
|
extra: Iterable<EditablePanel<S>> = listOf(),
|
||||||
val redstoneConfig: IPlayerInputWithFeedback<RedstoneSetting>? = null,
|
val redstoneConfig: IPlayerInputWithFeedback<RedstoneSetting>? = null,
|
||||||
val itemConfig: ItemConfigPlayerInput? = null,
|
val itemConfig: ItemConfigPlayerInput? = null,
|
||||||
@ -409,31 +409,36 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sortingButtons(input: MatteryMenu.SortInput) {
|
fun sortingButtons(input: MatteryMenu.SortInput, unfoldableSettings: Boolean = true) {
|
||||||
addButton(object : LargeRectangleButtonPanel<S>(screen, this@DeviceControls) {
|
object : LargeRectangleButtonPanel<S>(screen, this@DeviceControls) {
|
||||||
var buttons: List<EditablePanel<*>>? = null
|
var buttons: List<EditablePanel<*>>? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_now"))
|
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_now"))
|
||||||
|
|
||||||
|
if (unfoldableSettings) {
|
||||||
tooltips.add(TextComponent(""))
|
tooltips.add(TextComponent(""))
|
||||||
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_settings").withStyle(ChatFormatting.GRAY))
|
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_settings").withStyle(ChatFormatting.GRAY))
|
||||||
|
}
|
||||||
|
|
||||||
icon = Widgets18.SORT_NOW
|
icon = Widgets18.SORT_NOW
|
||||||
|
|
||||||
|
addButton(this)
|
||||||
|
|
||||||
|
if (!unfoldableSettings) {
|
||||||
|
makeButtons()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun test(value: Int): Boolean {
|
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
|
override var isDisabled: Boolean
|
||||||
get() = !input.input.test(minecraft.player)
|
get() = !input.input.test(minecraft.player)
|
||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
override fun onClick(mouseButton: Int) {
|
private fun makeButtons() {
|
||||||
if (mouseButton == InputConstants.MOUSE_BUTTON_LEFT) {
|
|
||||||
input.clientInput()
|
|
||||||
} else {
|
|
||||||
if (buttons == null) {
|
|
||||||
buttons = sortingButtons(input.settings::isAscending.asGetterSetter(), input.settings::sorting.asGetterSetter(), ItemStackSorter.DEFAULT) {
|
buttons = sortingButtons(input.settings::isAscending.asGetterSetter(), input.settings::sorting.asGetterSetter(), ItemStackSorter.DEFAULT) {
|
||||||
for (v in ItemStackSorter.entries) {
|
for (v in ItemStackSorter.entries) {
|
||||||
add(v, v.icon, v.title)
|
add(v, v.icon, v.title)
|
||||||
@ -444,13 +449,21 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
|||||||
|
|
||||||
buttons!!.forEach { removeButton(it) }
|
buttons!!.forEach { removeButton(it) }
|
||||||
buttons!!.forEach { addButton(it as EditablePanel<S>, this) }
|
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) {
|
||||||
|
makeButtons()
|
||||||
} else {
|
} else {
|
||||||
buttons!!.forEach { it.remove() }
|
buttons!!.forEach { it.remove() }
|
||||||
buttons = null
|
buttons = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -612,15 +625,20 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
x = (parent?.width ?: 0f) + 3f
|
if (parent is FramePanel<*>) {
|
||||||
|
x = parent!!.width + 3f
|
||||||
y = dockTop
|
y = dockTop
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun tickInner() {
|
override fun tickInner() {
|
||||||
super.tickInner()
|
super.tickInner()
|
||||||
x = (parent?.width ?: 0f) + 3f
|
|
||||||
|
if (parent is FramePanel<*>) {
|
||||||
|
x = parent!!.width + 3f
|
||||||
y = dockTop
|
y = dockTop
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// не съедаем ввод мыши
|
// не съедаем ввод мыши
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
|
@ -11,8 +11,6 @@ import net.minecraft.world.inventory.*
|
|||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
||||||
import ru.dbotthepony.mc.otm.compat.curios.curiosSlots
|
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.container.util.slotIterator
|
||||||
import ru.dbotthepony.mc.otm.menu.input.InstantBooleanInput
|
import ru.dbotthepony.mc.otm.menu.input.InstantBooleanInput
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||||
@ -119,6 +117,8 @@ class ExopackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
|
|||||||
|
|
||||||
val enderChestSlots: List<MatterySlot>
|
val enderChestSlots: List<MatterySlot>
|
||||||
val enderChestOpenState = InstantBooleanInput(this)
|
val enderChestOpenState = InstantBooleanInput(this)
|
||||||
|
val playerEnderSortSettings = IItemStackSortingSettings.inputs(this, capability.enderSortingSettings)
|
||||||
|
val sortEnderChest: SortInput?
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (capability.isExopackEnderAccessInstalled) {
|
if (capability.isExopackEnderAccessInstalled) {
|
||||||
@ -127,8 +127,11 @@ class ExopackInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
|
|||||||
addStorageSlot(it, condition = enderChestOpenState)
|
addStorageSlot(it, condition = enderChestOpenState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortEnderChest = SortInput(player.enderChestInventory, playerEnderSortSettings)
|
||||||
} else {
|
} else {
|
||||||
enderChestSlots = listOf()
|
enderChestSlots = listOf()
|
||||||
|
sortEnderChest = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,11 @@ interface IBaseSortingSettings : INBTSerializable<CompoundTag?> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IItemStackSortingSettings : IBaseSortingSettings {
|
interface IItemStackSortingSettings : IBaseSortingSettings {
|
||||||
|
data class Impl(
|
||||||
|
override var isAscending: Boolean = true,
|
||||||
|
override var sorting: ItemStackSorter = ItemStackSorter.DEFAULT,
|
||||||
|
) : IItemStackSortingSettings
|
||||||
|
|
||||||
var sorting: ItemStackSorter
|
var sorting: ItemStackSorter
|
||||||
|
|
||||||
override fun serializeNBT(): CompoundTag {
|
override fun serializeNBT(): CompoundTag {
|
||||||
@ -71,6 +76,11 @@ interface IItemStackSortingSettings : IBaseSortingSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IItemSortingSettings : IBaseSortingSettings {
|
interface IItemSortingSettings : IBaseSortingSettings {
|
||||||
|
data class Impl(
|
||||||
|
override var isAscending: Boolean = true,
|
||||||
|
override var sorting: ItemSorter = ItemSorter.DEFAULT,
|
||||||
|
) : IItemSortingSettings
|
||||||
|
|
||||||
var sorting: ItemSorter
|
var sorting: ItemSorter
|
||||||
|
|
||||||
override fun serializeNBT(): CompoundTag {
|
override fun serializeNBT(): CompoundTag {
|
||||||
|
Loading…
Reference in New Issue
Block a user