changing ui toggle keys in-world should work now

This commit is contained in:
minjaesong
2023-08-24 16:08:18 +09:00
parent 45af955488
commit b2454e4ca2
12 changed files with 54 additions and 22 deletions

View File

@@ -19,7 +19,7 @@ import net.torvald.unicode.*
* Created by minjaesong on 2017-10-21.
*/
class UIInventoryFull(
toggleKeyLiteral: Int? = App.getConfigInt("control_key_inventory"), toggleButtonLiteral: Int? = App.getConfigInt("control_gamepad_start"),
toggleKeyLiteral: String? = "control_key_inventory", toggleButtonLiteral: String? = "control_gamepad_start",
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
customPositioning: Boolean = false, // mainly used by vital meter
doNotWarnConstant: Boolean = false

View File

@@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.DefaultConfig
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.*
@@ -108,13 +109,13 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
private val buttonReset = UIItemTextButton(this,
{ Lang["MENU_LABEL_RESET"] },
kbx + (width - resetButtonWidth) / 2,
kby + 162 + 12,
kby + 162 + 16,
resetButtonWidth,
hasBorder = true,
alignment = UIItemTextButton.Companion.Alignment.CENTRE
)
private val controlPalette = UIItemControlPaletteBaloon(this, (Toolkit.drawWidth - 500) / 2, kby + 219)
private val controlPalette = UIItemControlPaletteBaloon(this, (Toolkit.drawWidth - 500) / 2, kby + 227)
init {
@@ -216,9 +217,34 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
fun setControlOf(key: Int, control: Int) {
if (control >= 0) {
App.setConfig(UIItemControlPaletteBaloon.indexToConfigKey[control]!!, key)
val controlName = UIItemControlPaletteBaloon.indexToConfigKey[control]!!
val conflicts = App.gameConfig.keySet.filter {
(it as String).startsWith("control_key_")
}.map {
(it as String).let { it to
try { (App.getConfigInt(it) == key) }
catch (_: ClassCastException) { false }
}
}.filter { it.second }.map { it.first }.firstOrNull()
println("[UIKeyboardControlPanel] key=$key, control=$controlName")
if (conflicts != null) {
val oldValue = App.getConfigInt(controlName)
App.setConfig(conflicts, oldValue)
println("[UIKeyboardControlPanel] set config $conflicts=$oldValue")
}
App.setConfig(controlName, key)
println("[UIKeyboardControlPanel] set config $controlName=$key")
}
updateKeycaps()
Terrarum.ingame?.let {
it.onConfigChange()
}
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {

View File

@@ -18,14 +18,14 @@ import kotlin.math.roundToInt
* Created by minjaesong on 2019-08-11.
*/
class UIScreenZoom : UICanvas(
App.getConfigInt("control_key_zoom")
"control_key_zoom"
) {
init {
handler.allowESCtoClose = false
}
val zoomText = "${getKeycapPC(handler.toggleKeyLiteral!!)} $EMDASH Zoom Out"
val zoomText = "${getKeycapPC(handler.toggleKey!!)} $EMDASH Zoom Out"
override var width = App.fontGame.getWidth(zoomText)
override var height = App.fontGame.lineHeight.toInt()

View File

@@ -19,8 +19,8 @@ import kotlin.math.min
* Created by minjaesong on 2019-07-08.
*/
internal class UIStorageChest : UICanvas(
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
toggleKeyLiteral = "control_key_inventory",
toggleButtonLiteral = "control_gamepad_start",
), HasInventory {
lateinit var chestInventory: FixtureInventory

View File

@@ -18,8 +18,8 @@ import net.torvald.unicode.getKeycapPC
* Created by minjaesong on 2023-08-15.
*/
class UIWallCalendar : UICanvas(
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
toggleKeyLiteral = "control_key_inventory",
toggleButtonLiteral = "control_gamepad_start",
) {
private val yearCellWidth = 200
private val cellWidth = 80

View File

@@ -31,8 +31,8 @@ import java.util.UUID
* Created by minjaesong on 2023-05-19.
*/
class UIWorldPortal : UICanvas(
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
toggleKeyLiteral = "control_key_inventory",
toggleButtonLiteral = "control_gamepad_start",
) {
override var width: Int = Toolkit.drawWidth