diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt index ff36cd941..60a8acc37 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt @@ -3,12 +3,12 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button import net.minecraft.client.gui.screens.Screen import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel -import ru.dbotthepony.mc.otm.menu.input.NetworkedBooleanInput +import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback open class CheckBoxInputPanel @JvmOverloads constructor( screen: S, parent: EditablePanel<*>?, - val widget: NetworkedBooleanInput, + val widget: BooleanInputWithFeedback, x: Float = 0f, y: Float = 0f, width: Float = REGULAR_DIMENSIONS + 120f, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt index 578354830..1fc7b8709 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt @@ -4,12 +4,12 @@ import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.Label -import ru.dbotthepony.mc.otm.menu.input.NetworkedBooleanInput +import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback open class CheckBoxLabelInputPanel @JvmOverloads constructor( screen: S, parent: EditablePanel<*>?, - widget: NetworkedBooleanInput, + widget: BooleanInputWithFeedback, text: Component, x: Float = 0f, y: Float = 0f, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt index 5c548a493..960f69ae2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt @@ -2,13 +2,13 @@ package ru.dbotthepony.mc.otm.client.screen.panels.input import net.minecraft.client.gui.screens.Screen import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel -import ru.dbotthepony.mc.otm.menu.input.AbstractNetworkedInput +import ru.dbotthepony.mc.otm.menu.input.AbstractPlayerInputWithFeedback import ru.dbotthepony.mc.otm.milliTime open class NetworkedStringInputPanel( screen: S, parent: EditablePanel<*>?, - val backend: AbstractNetworkedInput, + val backend: AbstractPlayerInputWithFeedback, x: Float = 0f, y: Float = 0f, width: Float = 60f, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt index ef06105ad..b09a3e120 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt @@ -3,9 +3,8 @@ package ru.dbotthepony.mc.otm.menu.decorative import net.minecraft.world.entity.player.Inventory import net.minecraft.world.inventory.Slot import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity -import ru.dbotthepony.mc.otm.client.screen.panels.input.TextInputPanel import ru.dbotthepony.mc.otm.menu.MatteryMenu -import ru.dbotthepony.mc.otm.menu.input.NetworkedStringInput +import ru.dbotthepony.mc.otm.menu.input.StringInputWithFeedback import ru.dbotthepony.mc.otm.registry.MMenus class HoloSignMenu @JvmOverloads constructor( @@ -14,7 +13,7 @@ class HoloSignMenu @JvmOverloads constructor( tile: HoloSignBlockEntity? = null ) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) { val text = if (tile != null) - NetworkedStringInput(this).withConsumer { + StringInputWithFeedback(this).withConsumer { val lines = it.split(NEWLINES) val result = ArrayList(lines.size.coerceAtMost(HoloSignBlockEntity.DEFAULT_MAX_NEWLINES)) @@ -29,7 +28,7 @@ class HoloSignMenu @JvmOverloads constructor( tile.text = result.joinToString("\n") }.withSupplier(tile::text) else - NetworkedStringInput(this) + StringInputWithFeedback(this) override val storageSlots: Collection get() = listOf() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractNetworkedInput.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractPlayerInputWithFeedback.kt similarity index 74% rename from src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractNetworkedInput.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractPlayerInputWithFeedback.kt index 6ad53fa17..bf3704012 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractNetworkedInput.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractPlayerInputWithFeedback.kt @@ -9,7 +9,7 @@ import kotlin.reflect.KMutableProperty0 /** * Getting and setting values should ONLY be done clientside */ -abstract class AbstractNetworkedInput : GetterSetter { +abstract class AbstractPlayerInputWithFeedback : GetterSetter { abstract val input: MatteryMenu.PlayerInput abstract val value: V @@ -24,29 +24,29 @@ abstract class AbstractNetworkedInput : GetterSetter { var supplier: (() -> V)? = null var consumer: ((V) -> Unit)? = null - fun withSupplier(func: () -> V): AbstractNetworkedInput { + fun withSupplier(func: () -> V): AbstractPlayerInputWithFeedback { supplier = func return this } - fun withConsumer(func: (V) -> Unit): AbstractNetworkedInput { + fun withConsumer(func: (V) -> Unit): AbstractPlayerInputWithFeedback { consumer = func return this } - fun with(state: KMutableProperty0): AbstractNetworkedInput { + fun with(state: KMutableProperty0): AbstractPlayerInputWithFeedback { withConsumer { state.set(it) } withSupplier { state.get() } return this } - fun with(state: GetterSetter): AbstractNetworkedInput { + fun with(state: GetterSetter): AbstractPlayerInputWithFeedback { withConsumer(state::accept) withSupplier(state::get) return this } - fun clear(): AbstractNetworkedInput { + fun clear(): AbstractPlayerInputWithFeedback { supplier = null consumer = null return this diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedBooleanInput.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/BooleanInputWithFeedback.kt similarity index 64% rename from src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedBooleanInput.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/BooleanInputWithFeedback.kt index 57a26fa77..65bf20706 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedBooleanInput.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/BooleanInputWithFeedback.kt @@ -1,10 +1,10 @@ package ru.dbotthepony.mc.otm.menu.input -import net.minecraft.world.entity.player.Player +import ru.dbotthepony.mc.otm.core.GetterSetter import ru.dbotthepony.mc.otm.menu.MatteryMenu import kotlin.reflect.KMutableProperty0 -class NetworkedBooleanInput(menu: MatteryMenu) : AbstractNetworkedInput() { +class BooleanInputWithFeedback(menu: MatteryMenu) : AbstractPlayerInputWithFeedback() { override val input = menu.booleanInput { consumer?.invoke(it) } override val value by menu.mSynchronizer.bool(getter = { supplier?.invoke() ?: false }) @@ -12,6 +12,10 @@ class NetworkedBooleanInput(menu: MatteryMenu) : AbstractNetworkedInput with(state) } + constructor(menu: MatteryMenu, state: GetterSetter) : this(menu) { + with(state) + } + fun switchValue() { input(!value) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedStringInput.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/StringInputWithFeedback.kt similarity index 63% rename from src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedStringInput.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/StringInputWithFeedback.kt index de365c103..891ba3021 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedStringInput.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/StringInputWithFeedback.kt @@ -1,13 +1,18 @@ package ru.dbotthepony.mc.otm.menu.input +import ru.dbotthepony.mc.otm.core.GetterSetter import ru.dbotthepony.mc.otm.menu.MatteryMenu import kotlin.reflect.KMutableProperty0 -class NetworkedStringInput(menu: MatteryMenu) : AbstractNetworkedInput() { +class StringInputWithFeedback(menu: MatteryMenu) : AbstractPlayerInputWithFeedback() { override val input = menu.stringInput { consumer?.invoke(it.replace('\u0000', ' ')) } override val value by menu.mSynchronizer.string(getter = { supplier?.invoke() ?: "" }) constructor(menu: MatteryMenu, state: KMutableProperty0) : this(menu) { with(state) } + + constructor(menu: MatteryMenu, state: GetterSetter) : this(menu) { + with(state) + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt index bfcc044d2..f1b061dfb 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt @@ -8,7 +8,7 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.matter.canExtractMatter import ru.dbotthepony.mc.otm.capability.matter.canReceiveMatter -import ru.dbotthepony.mc.otm.menu.input.NetworkedBooleanInput +import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget import ru.dbotthepony.mc.otm.core.orNull @@ -23,7 +23,7 @@ class MatterBottlerMenu @JvmOverloads constructor( ) : MatteryPoweredMenu( MMenus.MATTER_BOTTLER, p_38852_, inventory, tile ) { - val workFlow: NetworkedBooleanInput + val workFlow: BooleanInputWithFeedback val progressWidget: ProgressGaugeWidget val matterWidget: LevelGaugeWidget @@ -36,11 +36,11 @@ class MatterBottlerMenu @JvmOverloads constructor( if (tile == null) { progressWidget = ProgressGaugeWidget(this) matterWidget = LevelGaugeWidget(this) - workFlow = NetworkedBooleanInput(this) + workFlow = BooleanInputWithFeedback(this) } else { progressWidget = ProgressGaugeWidget(this) { tile.getWorkProgress() } matterWidget = LevelGaugeWidget(this, tile.matter) - workFlow = NetworkedBooleanInput(this, tile::isBottling) + workFlow = BooleanInputWithFeedback(this, tile::isBottling) } storageSlots = ImmutableList(6) { index -> diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt index f30c08c7b..cc0502f73 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt @@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.data.INetworkedItemViewProvider import ru.dbotthepony.mc.otm.menu.data.NetworkedItemView -import ru.dbotthepony.mc.otm.menu.input.NetworkedBooleanInput +import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.registry.MMenus import ru.dbotthepony.mc.otm.storage.ITEM_STORAGE import ru.dbotthepony.mc.otm.storage.ItemStackWrapper @@ -70,9 +70,9 @@ class DriveViewerMenu @JvmOverloads constructor( val driveFilterSlots = addFilterSlots(driveFilter) - val isWhitelist = NetworkedBooleanInput(this) - val matchTag = NetworkedBooleanInput(this) - val matchNBT = NetworkedBooleanInput(this) + val isWhitelist = BooleanInputWithFeedback(this) + val matchTag = BooleanInputWithFeedback(this) + val matchNBT = BooleanInputWithFeedback(this) override fun broadcastChanges() { super.broadcastChanges() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageBusMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageBusMenu.kt index 8cfa1a5f3..e29d7526e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageBusMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageBusMenu.kt @@ -5,7 +5,7 @@ import net.minecraft.world.inventory.Slot import ru.dbotthepony.mc.otm.block.entity.storage.StorageBusBlockEntity import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu -import ru.dbotthepony.mc.otm.menu.input.NetworkedBooleanInput +import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.registry.MMenus class StorageBusMenu @JvmOverloads constructor( @@ -16,15 +16,15 @@ class StorageBusMenu @JvmOverloads constructor( MMenus.STORAGE_BUS, p_38852_, inventory, tile ) { val busFilterSlots: List - val busFilterState: NetworkedBooleanInput + val busFilterState: BooleanInputWithFeedback init { if (tile != null) { busFilterSlots = addFilterSlots(tile.filter) - busFilterState = NetworkedBooleanInput(this, tile.filter::isWhitelist) + busFilterState = BooleanInputWithFeedback(this, tile.filter::isWhitelist) } else { busFilterSlots = addFilterSlots(StorageBusBlockEntity.MAX_FILTERS) - busFilterState = NetworkedBooleanInput(this) + busFilterState = BooleanInputWithFeedback(this) } addInventorySlots() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageExporterMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageExporterMenu.kt index 840ee3fd4..391633a96 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageExporterMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageExporterMenu.kt @@ -5,7 +5,7 @@ import net.minecraft.world.inventory.Slot import ru.dbotthepony.mc.otm.block.entity.storage.StorageExporterBlockEntity import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu -import ru.dbotthepony.mc.otm.menu.input.NetworkedBooleanInput +import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.registry.MMenus class StorageExporterMenu @JvmOverloads constructor( @@ -16,15 +16,15 @@ class StorageExporterMenu @JvmOverloads constructor( MMenus.STORAGE_EXPORTER, p_38852_, inventory, tile ) { val busFilterSlots: List - val busFilterState: NetworkedBooleanInput + val busFilterState: BooleanInputWithFeedback init { if (tile != null) { busFilterSlots = addFilterSlots(tile.filter) - busFilterState = NetworkedBooleanInput(this, tile.filter::isWhitelist) + busFilterState = BooleanInputWithFeedback(this, tile.filter::isWhitelist) } else { busFilterSlots = addFilterSlots(StorageExporterBlockEntity.MAX_FILTERS) - busFilterState = NetworkedBooleanInput(this) + busFilterState = BooleanInputWithFeedback(this) } addInventorySlots() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageImporterMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageImporterMenu.kt index bc41f66ac..e568a0a8f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageImporterMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/StorageImporterMenu.kt @@ -5,7 +5,7 @@ import net.minecraft.world.inventory.Slot import ru.dbotthepony.mc.otm.block.entity.storage.StorageImporterBlockEntity import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu -import ru.dbotthepony.mc.otm.menu.input.NetworkedBooleanInput +import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.registry.MMenus class StorageImporterMenu @JvmOverloads constructor( @@ -16,15 +16,15 @@ class StorageImporterMenu @JvmOverloads constructor( MMenus.STORAGE_IMPORTER, p_38852_, inventory, tile ) { val busFilterSlots: List - val busFilterState: NetworkedBooleanInput + val busFilterState: BooleanInputWithFeedback init { if (tile != null) { busFilterSlots = addFilterSlots(tile.filter) - busFilterState = NetworkedBooleanInput(this, tile.filter::isWhitelist) + busFilterState = BooleanInputWithFeedback(this, tile.filter::isWhitelist) } else { busFilterSlots = addFilterSlots(StorageImporterBlockEntity.MAX_FILTERS) - busFilterState = NetworkedBooleanInput(this) + busFilterState = BooleanInputWithFeedback(this) } addInventorySlots()