Remove widget2panel text input wrapper
This commit is contained in:
parent
b80da0e214
commit
876c6180cb
@ -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<out S : Screen>(
|
||||
screen: S,
|
||||
parent: EditablePanel<*>?,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 0f,
|
||||
height: Float = 20f,
|
||||
val defaultText: Component = TextComponent("")
|
||||
) : Widget2Panel<S, EditBox>(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)
|
||||
}
|
||||
}
|
@ -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<out S : Screen> @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<S>(screen, parent, x, y, width, height, defaultText) {
|
||||
constructor(
|
||||
screen: S,
|
||||
parent: EditablePanel<*>?,
|
||||
widget: MatteryMenu.PlayerInput<Decimal>,
|
||||
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) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user