mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
changing ui toggle keys in-world should work now
This commit is contained in:
@@ -18,8 +18,8 @@ import net.torvald.tsvm.peripheral.GraphicsAdapter
|
||||
import net.torvald.unicode.*
|
||||
|
||||
internal class UIHomeComputer : UICanvas(
|
||||
toggleKeyLiteral = Input.Keys.ESCAPE, // FIXME why do I have specify ESC for it to function? ESC should be work as the default key
|
||||
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
|
||||
toggleKeyLiteral = null,
|
||||
toggleButtonLiteral = "control_gamepad_start",
|
||||
) {
|
||||
override var width = 640
|
||||
override var height = 480
|
||||
|
||||
@@ -1378,6 +1378,8 @@ public class App implements ApplicationListener {
|
||||
* @throws NullPointerException if the specified config simply does not exist.
|
||||
*/
|
||||
public static int getConfigInt(String key) {
|
||||
if (key == null) return -1;
|
||||
|
||||
Object cfg = getConfigMaster(key);
|
||||
|
||||
if (cfg instanceof Integer) return ((int) cfg);
|
||||
|
||||
@@ -531,6 +531,9 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
fun onConfigChange() {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun Lock.lock(body: () -> Unit) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -59,7 +59,7 @@ import kotlin.math.roundToInt
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
abstract class UICanvas(
|
||||
toggleKeyLiteral: Int? = null, toggleButtonLiteral: Int? = null,
|
||||
toggleKeyLiteral: String? = null, toggleButtonLiteral: String? = null,
|
||||
// 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
|
||||
|
||||
@@ -25,8 +25,8 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
class UIHandler(//var UI: UICanvas,
|
||||
var toggleKeyLiteral: Int? = null,
|
||||
var toggleButtonLiteral: Int? = null,
|
||||
var toggleKeyLiteral: String? = null, // string key of the config
|
||||
var toggleButtonLiteral: String? = null, // string key of the config
|
||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||
var customPositioning: Boolean = false, // mainly used by vital meter
|
||||
var doNotWarnConstant: Boolean = false,
|
||||
@@ -130,9 +130,10 @@ void main() {
|
||||
//UI.handler = this
|
||||
}
|
||||
|
||||
|
||||
private val toggleKey: Int?; get() = toggleKeyLiteral // to support in-screen keybind changing
|
||||
private val toggleButton: Int?; get() = toggleButtonLiteral // to support in-screen keybind changing
|
||||
// getConfigInt(toggleKeyLiteral)
|
||||
val toggleKey: Int?; get() = App.getConfigInt(toggleKeyLiteral).let { if (it == -1) null else it } // to support in-screen keybind changing
|
||||
// getConfigInt(toggleButtonLiteral)
|
||||
val toggleButton: Int?; get() = App.getConfigInt(toggleButtonLiteral).let { if (it == -1) null else it } // to support in-screen keybind changing
|
||||
|
||||
|
||||
val toggleKeyExtra: ArrayList<() -> Int> = arrayListOf()
|
||||
|
||||
@@ -237,13 +237,13 @@ internal object WeatherMixer : RNGConsumer {
|
||||
|
||||
val currentWindDir = FastMath.interpolateCatmullRom(windDirStep, windDirWindow)
|
||||
val currentWindSpeed = FastMath.interpolateCatmullRom(windSpeedStep, windSpeedWindow)
|
||||
|
||||
/*
|
||||
printdbg(this,
|
||||
"dir ${Math.toDegrees(currentWindDir.toDouble()).roundToInt()}\t" +
|
||||
"spd ${currentWindSpeed.times(10f).roundToInt().div(10f)}\t " +
|
||||
"dirs ${windDirWindow!!.map { Math.toDegrees(it.toDouble()).roundToInt() }} ${windDirStep.times(100).roundToInt()}\t" +
|
||||
"spds ${windSpeedWindow!!.map { it.times(10f).roundToInt().div(10f) }} ${windSpeedStep.times(100).roundToInt()}"
|
||||
)
|
||||
)*/
|
||||
|
||||
if (currentWeather.forceWindVec != null) {
|
||||
windVector.set(currentWeather.forceWindVec)
|
||||
|
||||
Reference in New Issue
Block a user