Add take all, restock, full restock buttons

This commit is contained in:
DBotThePony 2025-03-17 21:07:30 +07:00
parent d41d331e0f
commit 03c64425a9
Signed by: DBot
GPG Key ID: DCC23B5715498507
10 changed files with 207 additions and 40 deletions

View File

@ -987,6 +987,16 @@ private fun androidFeatures(provider: MatteryLanguageProvider) {
private fun gui(provider: MatteryLanguageProvider) {
with(provider.english) {
gui("quickmove_from.restock", "Restock from storage")
gui("quickmove_from.restock_with_move", "Full restock from storage")
gui("quickmove_from.move", "Take all")
gui("quickmove_to.restock", "Restock to storage")
gui("quickmove_to.restock_with_move", "Full restock to storage")
gui("quickmove_to.move", "Deposit all")
gui("quickmove_hint", "Right click to show all variants")
gui("exopack.accept_wireless_charge", "Accept wireless charging")
gui("exopack.dont_accept_wireless_charge", "Do not accept wireless charging")

View File

@ -980,6 +980,16 @@ private fun androidFeatures(provider: MatteryLanguageProvider) {
private fun gui(provider: MatteryLanguageProvider) {
with(provider.russian) {
gui("quickmove_from.restock", "Быстрое пополнение из хранилища")
gui("quickmove_from.restock_with_move", "Быстрое перемещение из хранилища")
gui("quickmove_from.move", "Взять всё")
gui("quickmove_to.restock", "Быстрое пополнение в хранилище")
gui("quickmove_to.restock_with_move", "Быстрое перемещение в хранилище")
gui("quickmove_to.move", "Переместить всё")
gui("quickmove_hint", "Правый клик чтоб увидеть все варианты")
gui("exopack.accept_wireless_charge", "Принимать заряд от беспроводных зарядников")
gui("exopack.dont_accept_wireless_charge", "Не принимать заряд от беспроводных зарядников")

View File

@ -7,6 +7,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.button.DeviceControls
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.UserFilteredSlotPanel
import ru.dbotthepony.mc.otm.menu.QuickMoveInput
import ru.dbotthepony.mc.otm.menu.decorative.CargoCrateMenu
class CargoCrateScreen(menu: CargoCrateMenu, inventory: Inventory, title: Component) : MatteryScreen<CargoCrateMenu>(menu, inventory, title) {
@ -23,9 +24,16 @@ class CargoCrateScreen(menu: CargoCrateMenu, inventory: Inventory, title: Compon
UserFilteredSlotPanel(this, grid, slot)
val controls = DeviceControls(this, frame)
controls.sortingButtons(menu.sort)
val leftControls = DeviceControls(this, frame)
leftControls.dockOnLeft = true
leftControls.quickMoveButtons(menu.quickMoveFromStorage, QuickMoveInput.Mode.RESTOCK, true)
val leftInventoryControls = DeviceControls(this, inventoryFrame!!)
leftInventoryControls.dockOnLeft = true
leftInventoryControls.quickMoveButtons(menu.quickMoveToStorage, QuickMoveInput.Mode.RESTOCK_WITH_MOVE, false)
return frame
}
}

View File

@ -36,6 +36,7 @@ import ru.dbotthepony.mc.otm.core.math.RelativeSide
import ru.dbotthepony.mc.otm.core.util.ItemStackSorter
import ru.dbotthepony.mc.otm.core.util.getLevelFromXp
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.QuickMoveInput
import ru.dbotthepony.mc.otm.menu.SortInput
import ru.dbotthepony.mc.otm.menu.UpgradeSlots
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
@ -385,13 +386,17 @@ class DeviceControls<out S : MatteryScreen<*>>(
}
fun <P : EditablePanel<@UnsafeVariance S>> addButton(button: P): P {
buttons.add(button)
button.parent = this
alignButtons()
if (button !in buttons) {
buttons.add(button)
button.parent = this
alignButtons()
}
return button
}
fun <P : EditablePanel<@UnsafeVariance S>> addButton(button: P, after: EditablePanel<*>): P {
buttons.remove(button)
val index = buttons.indexOf(after)
if (index == -1) throw NoSuchElementException("Unknown panel to add button after: $after")
buttons.add(index + 1, button)
@ -401,9 +406,12 @@ class DeviceControls<out S : MatteryScreen<*>>(
}
fun <P : EditablePanel<@UnsafeVariance S>> prependButton(button: P): P {
buttons.add(0, button)
button.parent = this
alignButtons()
if (button !in buttons) {
buttons.add(0, button)
button.parent = this
alignButtons()
}
return button
}
@ -449,9 +457,75 @@ class DeviceControls<out S : MatteryScreen<*>>(
return result
}
private abstract inner class FoldableButtonPanel() : ButtonPanel<S>(screen, this@DeviceControls, width = 18f, height = 18f) {
init {
addButton(this)
}
private var buttons: List<EditablePanel<S>>? = null
fun makeButtons() {
if (buttons == null) {
buttons = doMakeButtons().also {
it.forEach { addButton(it, this) }
}
}
}
fun removeButtons() {
if (buttons != null) {
buttons!!.forEach { it.remove() }
buttons = null
}
}
override fun test(value: Int): Boolean {
return value == InputConstants.MOUSE_BUTTON_LEFT || hasExtraButtons && value == InputConstants.MOUSE_BUTTON_RIGHT
}
fun switchButtons() {
if (buttons == null)
makeButtons()
else
removeButtons()
}
protected abstract val hasExtraButtons: Boolean
protected abstract fun performAction()
protected abstract fun doMakeButtons(): List<EditablePanel<S>>
final override fun onClick(mouseButton: Int) {
if (mouseButton == InputConstants.MOUSE_BUTTON_LEFT) {
performAction()
} else {
switchButtons()
}
}
}
fun sortingButtons(input: SortInput, unfoldableSettings: Boolean = true) {
object : ButtonPanel<S>(screen, this@DeviceControls, width = 18f, height = 18f) {
var buttons: List<EditablePanel<*>>? = null
object : FoldableButtonPanel() {
override fun performAction() {
input.clientInput()
}
override var isDisabled: Boolean
get() { return !input.input.test(minecraft.player ?: return false) }
set(value) {}
override val hasExtraButtons: Boolean
get() = unfoldableSettings
override fun doMakeButtons(): List<EditablePanel<S>> {
return sortingButtons(Delegate.Of(input.settings::isAscending), Delegate.Of(input.settings::sorting), ItemStackSorter.DEFAULT) {
for (v in ItemStackSorter.entries) {
add(v, v.icon, v.title)
}
finish()
}
}
init {
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_now"))
@ -459,50 +533,67 @@ class DeviceControls<out S : MatteryScreen<*>>(
if (unfoldableSettings) {
tooltips.add(TextComponent(""))
tooltips.add(TranslatableComponent("otm.gui.sorting.sort_settings").withStyle(ChatFormatting.GRAY))
}
addButton(this)
if (!unfoldableSettings) {
} else {
makeButtons()
}
}
override val icon: IGUIRenderable
get() = Widgets18.SORT_NOW
}
}
override fun test(value: Int): Boolean {
return value == InputConstants.MOUSE_BUTTON_LEFT || unfoldableSettings && value == InputConstants.MOUSE_BUTTON_RIGHT
fun quickMoveButtons(buttons: Map<QuickMoveInput.Mode, QuickMoveInput>, mainMode: QuickMoveInput.Mode, isFromStorage: Boolean, unfoldableSettings: Boolean = true) {
object : FoldableButtonPanel() {
private val input = buttons[mainMode]!!
override fun performAction() {
input.clientInput()
}
override var isDisabled: Boolean
get() { return !input.input.test(minecraft.player ?: return false) }
set(value) {}
private fun makeButtons() {
buttons = sortingButtons(Delegate.Of(input.settings::isAscending), Delegate.Of(input.settings::sorting), ItemStackSorter.DEFAULT) {
for (v in ItemStackSorter.entries) {
add(v, v.icon, v.title)
override val hasExtraButtons: Boolean
get() = unfoldableSettings
override fun doMakeButtons(): List<EditablePanel<S>> {
return buttons.entries
.stream()
.filter { (m, _) -> m != input.mode }
.map { (m, b) ->
square18(
screen,
this,
icon = if (isFromStorage) m.iconFromStorage else m.iconToStorage,
onPress = { b.clientInput() }
).also {
if (isFromStorage)
it.tooltips.add(m.textFromStorage)
else
it.tooltips.add(m.textToStorage)
}
}
finish()
}
buttons!!.forEach { removeButton(it) }
buttons!!.forEach { addButton(it as EditablePanel<S>, this) }
.toList()
}
override fun onClick(mouseButton: Int) {
if (mouseButton == InputConstants.MOUSE_BUTTON_LEFT) {
input.clientInput()
init {
if (isFromStorage)
tooltips.add(input.mode.textFromStorage)
else
tooltips.add(input.mode.textToStorage)
if (unfoldableSettings) {
tooltips.add(TextComponent(""))
tooltips.add(TranslatableComponent("otm.gui.quickmove_hint").withStyle(ChatFormatting.GRAY))
} else {
if (buttons == null) {
makeButtons()
} else {
buttons!!.forEach { it.remove() }
buttons = null
}
makeButtons()
}
}
override val icon: IGUIRenderable
get() = if (isFromStorage) input.mode.iconFromStorage else input.mode.iconToStorage
}
}

View File

@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.MenuType
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.QuickMoveInput
import ru.dbotthepony.mc.otm.menu.SortInput
abstract class AbstractVanillaChestMenu(
@ -18,6 +19,8 @@ abstract class AbstractVanillaChestMenu(
abstract val columns: Int
abstract val containerSlots: List<MatteryMenuSlot>
abstract val quickMoveToStorage: Map<QuickMoveInput.Mode, QuickMoveInput>
abstract val quickMoveFromStorage: Map<QuickMoveInput.Mode, QuickMoveInput>
val sort = SortInput(this, container, playerSortSettings)
override fun stillValid(player: Player): Boolean {

View File

@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.inventory.MenuType
import ru.dbotthepony.mc.otm.container.EnhancedContainer
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.QuickMoveInput
import ru.dbotthepony.mc.otm.menu.makeSlots
class MatteryChestMenu(
@ -22,6 +23,9 @@ class MatteryChestMenu(
addInventorySlots()
}
override val quickMoveToStorage = QuickMoveInput.create(this, playerCombinedInventorySlots, containerSlots)
override val quickMoveFromStorage = QuickMoveInput.create(this, containerSlots, playerInventorySlots)
companion object {
@JvmStatic
@JvmOverloads

View File

@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.container.EnhancedContainer
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.QuickMoveInput
import ru.dbotthepony.mc.otm.menu.makeSlots
class MatteryShulkerBoxMenu(
@ -24,6 +25,9 @@ class MatteryShulkerBoxMenu(
addInventorySlots()
}
override val quickMoveToStorage = QuickMoveInput.create(this, playerCombinedInventorySlots, containerSlots)
override val quickMoveFromStorage = QuickMoveInput.create(this, containerSlots, playerInventorySlots)
class Slot(container: Container, slot: Int) : MatteryMenuSlot(container, slot) {
override fun mayPlace(stack: ItemStack): Boolean {
return super.mayPlace(stack) && stack.item.canFitInsideContainerItems()

View File

@ -10,6 +10,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.DeviceControls
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
import ru.dbotthepony.mc.otm.menu.QuickMoveInput
class VanillaChestScreen(menu: AbstractVanillaChestMenu, inventory: Inventory, title: Component) : MatteryScreen<AbstractVanillaChestMenu>(menu, inventory, title) {
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
@ -28,6 +29,14 @@ class VanillaChestScreen(menu: AbstractVanillaChestMenu, inventory: Inventory, t
val controls = DeviceControls(this, frame)
controls.sortingButtons(menu.sort)
val leftControls = DeviceControls(this, frame)
leftControls.dockOnLeft = true
leftControls.quickMoveButtons(menu.quickMoveFromStorage, QuickMoveInput.Mode.RESTOCK, true)
val leftInventoryControls = DeviceControls(this, inventoryFrame!!)
leftInventoryControls.dockOnLeft = true
leftInventoryControls.quickMoveButtons(menu.quickMoveToStorage, QuickMoveInput.Mode.RESTOCK_WITH_MOVE, false)
return frame
}
}

View File

@ -1,19 +1,26 @@
package ru.dbotthepony.mc.otm.menu
import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.Slot
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.render.sprites.AbstractMatterySprite
import ru.dbotthepony.mc.otm.container.IFilteredContainerSlot
import ru.dbotthepony.mc.otm.container.util.containerSlotOrNull
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.isNotEmpty
import ru.dbotthepony.mc.otm.core.util.ItemStackKey
import ru.dbotthepony.mc.otm.core.util.asKey
import ru.dbotthepony.mc.otm.core.util.asKeyOrNull
class QuickMoveInput(private val menu: MatteryMenu, val from: Collection<Slot>, val to: Collection<Slot>, val mode: Mode) {
enum class Mode {
RESTOCK {
enum class Mode(val iconFromStorage: AbstractMatterySprite, val iconToStorage: AbstractMatterySprite) {
RESTOCK(
Widgets18.RESTOCK_FROM_STORAGE,
Widgets18.RESTOCK_TO_STORAGE
) {
override fun move(from: Collection<Slot>, to: Collection<Slot>, player: Player) {
val (_, itemsFrom) = computeSlotLists(from, true)
val (_, itemsTo) = computeSlotLists(to, false)
@ -27,7 +34,10 @@ class QuickMoveInput(private val menu: MatteryMenu, val from: Collection<Slot>,
}
},
RESTOCK_WITH_MOVE {
RESTOCK_WITH_MOVE(
Widgets18.RESTOCK_WITH_MOVE_FROM_STORAGE,
Widgets18.RESTOCK_WITH_MOVE_TO_STORAGE
) {
override fun move(from: Collection<Slot>, to: Collection<Slot>, player: Player) {
val (_, itemsFrom) = computeSlotLists(from, true)
val (emptyTo, itemsTo) = computeSlotLists(to, false)
@ -45,7 +55,10 @@ class QuickMoveInput(private val menu: MatteryMenu, val from: Collection<Slot>,
}
},
MOVE {
MOVE(
Widgets18.MOVE_EVERYTHING_FROM_STORAGE,
Widgets18.MOVE_EVERYTHING_TO_STORAGE
) {
override fun move(from: Collection<Slot>, to: Collection<Slot>, player: Player) {
val toSorted = prioritySortSlots(to)
@ -59,11 +72,19 @@ class QuickMoveInput(private val menu: MatteryMenu, val from: Collection<Slot>,
};
abstract fun move(from: Collection<Slot>, to: Collection<Slot>, player: Player)
val textFromStorage: Component get() {
return TranslatableComponent("otm.gui.quickmove_from.${name.lowercase()}")
}
val textToStorage: Component get() {
return TranslatableComponent("otm.gui.quickmove_to.${name.lowercase()}")
}
}
private val input = menu.oneWayInput(handler = ::handle)
val input = menu.oneWayInput(handler = ::handle)
fun trigger() {
fun clientInput() {
input.accept(null)
}
@ -72,6 +93,10 @@ class QuickMoveInput(private val menu: MatteryMenu, val from: Collection<Slot>,
}
companion object {
fun create(menu: MatteryMenu, from: Collection<Slot>, to: Collection<Slot>): Map<Mode, QuickMoveInput> {
return Mode.entries.associateWith { QuickMoveInput(menu, from, to, it) }
}
private fun computeSlotLists(slots: Collection<Slot>, skipFilteredSlots: Boolean): Pair<MutableList<Slot>, MutableMap<ItemStackKey, MutableList<Slot>>> {
val emptySlots = ArrayList<Slot>()
val filledSlots = HashMap<ItemStackKey, MutableList<Slot>>()

View File

@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Player
import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.QuickMoveInput
import ru.dbotthepony.mc.otm.menu.SortInput
import ru.dbotthepony.mc.otm.menu.UserFilteredMenuSlot
import ru.dbotthepony.mc.otm.menu.makeSlots
@ -20,6 +21,8 @@ class CargoCrateMenu(
private val trackedPlayerOpen = !inventory.player.isSpectator
val sort = SortInput(this, actualContainer, playerSortSettings)
val quickMoveToStorage = QuickMoveInput.create(this, playerCombinedInventorySlots, storageSlots)
val quickMoveFromStorage = QuickMoveInput.create(this, storageSlots, playerInventorySlots)
init {
if (trackedPlayerOpen) {