From 876c6180cb92b13ee3822cf234b2bb9ad812993d Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 10 Oct 2024 12:12:11 +0700 Subject: [PATCH] Remove widget2panel text input wrapper --- .../screen/panels/input/EditBoxPanel.kt | 58 ------------- .../panels/input/NetworkNumberInputPanel.kt | 85 ------------------- .../client/screen/tech/EnergyCounterScreen.kt | 1 - 3 files changed, 144 deletions(-) delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/EditBoxPanel.kt delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkNumberInputPanel.kt diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/EditBoxPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/EditBoxPanel.kt deleted file mode 100644 index 5ddbc95f2..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/EditBoxPanel.kt +++ /dev/null @@ -1,58 +0,0 @@ -package ru.dbotthepony.mc.otm.client.screen.panels.input - -import com.mojang.blaze3d.platform.InputConstants -import net.minecraft.client.gui.components.EditBox -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.Widget2Panel -import ru.dbotthepony.mc.otm.core.TextComponent - -open class EditBoxPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = 0f, - height: Float = 20f, - val defaultText: Component = TextComponent("") -) : Widget2Panel(screen, parent, x, y, width, height) { - override fun makeNew(): EditBox { - return object : EditBox(font, 0, 0, width.toInt(), height.toInt().coerceAtMost(20), defaultText) { - override fun isHoveredOrFocused(): Boolean { - return this@EditBoxPanel.isHovered - } - - override fun isFocused(): Boolean { - return this@EditBoxPanel.isFocusedThis - } - } - } - - override fun copyValues(new_widget: EditBox, old_widget: EditBox) { - new_widget.value = old_widget.value - } - - override fun configureNew(widget: EditBox, recreation: Boolean) { - widget.isFocused = isFocusedThis - } - - override fun onFocusChanged() { - widget?.isFocused = isFocusedThis - } - - override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { - super.mouseClickedInner(x, y, button) - requestFocus() - return true - } - - override fun keyPressedInternal(key: Int, scancode: Int, mods: Int): Boolean { - if (key == InputConstants.KEY_ESCAPE && widget?.isActive == true) { - widget?.isFocused = false - return true - } - - return super.keyPressedInternal(key, scancode, mods) - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkNumberInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkNumberInputPanel.kt deleted file mode 100644 index 5d21db32a..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkNumberInputPanel.kt +++ /dev/null @@ -1,85 +0,0 @@ -package ru.dbotthepony.mc.otm.client.screen.panels.input - -import net.minecraft.client.gui.screens.Screen -import net.minecraft.network.chat.Component -import ru.dbotthepony.mc.otm.client.CursorType -import ru.dbotthepony.mc.otm.client.minecraft -import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel -import ru.dbotthepony.mc.otm.core.TextComponent -import ru.dbotthepony.mc.otm.core.math.Decimal -import ru.dbotthepony.mc.otm.menu.MatteryMenu -import java.math.BigDecimal -import java.util.function.BooleanSupplier - -open class NetworkNumberInputPanel @JvmOverloads constructor( - screen: S, - parent: EditablePanel<*>?, - val networkValue: () -> Decimal, - val callback: (Decimal) -> Unit, - val isEnabled: BooleanSupplier = BooleanSupplier { true }, - x: Float = 0f, - y: Float = 0f, - width: Float = 0f, - height: Float = 20f, - defaultText: Component = TextComponent("") -) : EditBoxPanel(screen, parent, x, y, width, height, defaultText) { - constructor( - screen: S, - parent: EditablePanel<*>?, - widget: MatteryMenu.PlayerInput, - networkValue: () -> Decimal, - x: Float = 0f, - y: Float = 0f, - width: Float = 0f, - height: Float = 20f, - defaultText: Component = TextComponent("") - ) : this( - screen = screen, - parent = parent, - callback = widget::accept, - isEnabled = { widget.allowSpectators || minecraft.player?.isSpectator != true }, - networkValue = networkValue, - x = x, - y = y, - width = width, - height = height, - defaultText = defaultText, - ) - - protected var nextUpdateFromServer = 0L - protected var inputStr = "" - - override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { - if (!isEnabled.asBoolean) { - return true - } - - return super.mouseClickedInner(x, y, button) - } - - override fun tickInner() { - super.tickInner() - - if (isFocusedThis) { - if (!isEnabled.asBoolean) { - killFocus() - return - } - - nextUpdateFromServer = System.currentTimeMillis() + 2000L - } - - if (nextUpdateFromServer < System.currentTimeMillis()) { - getOrCreateWidget().value = networkValue.invoke().toString() - inputStr = getOrCreateWidget().value - } else if (isEnabled.asBoolean) { - if (inputStr != getOrCreateWidget().value) { - inputStr = getOrCreateWidget().value - - try { - callback.invoke(Decimal(inputStr)) - } catch (_: Throwable) { } - } - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt index 7a8770f14..fcb4c43d8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt @@ -12,7 +12,6 @@ import ru.dbotthepony.mc.otm.client.screen.panels.* import ru.dbotthepony.mc.otm.client.screen.panels.button.ButtonPanel import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls -import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkNumberInputPanel import ru.dbotthepony.mc.otm.client.screen.panels.input.TextInputPanel import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.util.formatPower