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.*
|
import net.torvald.unicode.*
|
||||||
|
|
||||||
internal class UIHomeComputer : UICanvas(
|
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
|
toggleKeyLiteral = null,
|
||||||
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
|
toggleButtonLiteral = "control_gamepad_start",
|
||||||
) {
|
) {
|
||||||
override var width = 640
|
override var width = 640
|
||||||
override var height = 480
|
override var height = 480
|
||||||
|
|||||||
@@ -1378,6 +1378,8 @@ public class App implements ApplicationListener {
|
|||||||
* @throws NullPointerException if the specified config simply does not exist.
|
* @throws NullPointerException if the specified config simply does not exist.
|
||||||
*/
|
*/
|
||||||
public static int getConfigInt(String key) {
|
public static int getConfigInt(String key) {
|
||||||
|
if (key == null) return -1;
|
||||||
|
|
||||||
Object cfg = getConfigMaster(key);
|
Object cfg = getConfigMaster(key);
|
||||||
|
|
||||||
if (cfg instanceof Integer) return ((int) cfg);
|
if (cfg instanceof Integer) return ((int) cfg);
|
||||||
|
|||||||
@@ -531,6 +531,9 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
|||||||
else
|
else
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onConfigChange() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun Lock.lock(body: () -> Unit) {
|
inline fun Lock.lock(body: () -> Unit) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import net.torvald.unicode.*
|
|||||||
* Created by minjaesong on 2017-10-21.
|
* Created by minjaesong on 2017-10-21.
|
||||||
*/
|
*/
|
||||||
class UIInventoryFull(
|
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))
|
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||||
customPositioning: Boolean = false, // mainly used by vital meter
|
customPositioning: Boolean = false, // mainly used by vital meter
|
||||||
doNotWarnConstant: Boolean = false
|
doNotWarnConstant: Boolean = false
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.DefaultConfig
|
import net.torvald.terrarum.DefaultConfig
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.ui.*
|
import net.torvald.terrarum.ui.*
|
||||||
|
|
||||||
@@ -108,13 +109,13 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
|||||||
private val buttonReset = UIItemTextButton(this,
|
private val buttonReset = UIItemTextButton(this,
|
||||||
{ Lang["MENU_LABEL_RESET"] },
|
{ Lang["MENU_LABEL_RESET"] },
|
||||||
kbx + (width - resetButtonWidth) / 2,
|
kbx + (width - resetButtonWidth) / 2,
|
||||||
kby + 162 + 12,
|
kby + 162 + 16,
|
||||||
resetButtonWidth,
|
resetButtonWidth,
|
||||||
hasBorder = true,
|
hasBorder = true,
|
||||||
alignment = UIItemTextButton.Companion.Alignment.CENTRE
|
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 {
|
init {
|
||||||
|
|
||||||
@@ -216,9 +217,34 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
|||||||
|
|
||||||
fun setControlOf(key: Int, control: Int) {
|
fun setControlOf(key: Int, control: Int) {
|
||||||
if (control >= 0) {
|
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()
|
updateKeycaps()
|
||||||
|
|
||||||
|
Terrarum.ingame?.let {
|
||||||
|
it.onConfigChange()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
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.
|
* Created by minjaesong on 2019-08-11.
|
||||||
*/
|
*/
|
||||||
class UIScreenZoom : UICanvas(
|
class UIScreenZoom : UICanvas(
|
||||||
App.getConfigInt("control_key_zoom")
|
"control_key_zoom"
|
||||||
) {
|
) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
handler.allowESCtoClose = false
|
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 width = App.fontGame.getWidth(zoomText)
|
||||||
override var height = App.fontGame.lineHeight.toInt()
|
override var height = App.fontGame.lineHeight.toInt()
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import kotlin.math.min
|
|||||||
* Created by minjaesong on 2019-07-08.
|
* Created by minjaesong on 2019-07-08.
|
||||||
*/
|
*/
|
||||||
internal class UIStorageChest : UICanvas(
|
internal class UIStorageChest : UICanvas(
|
||||||
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
|
toggleKeyLiteral = "control_key_inventory",
|
||||||
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
|
toggleButtonLiteral = "control_gamepad_start",
|
||||||
), HasInventory {
|
), HasInventory {
|
||||||
|
|
||||||
lateinit var chestInventory: FixtureInventory
|
lateinit var chestInventory: FixtureInventory
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ import net.torvald.unicode.getKeycapPC
|
|||||||
* Created by minjaesong on 2023-08-15.
|
* Created by minjaesong on 2023-08-15.
|
||||||
*/
|
*/
|
||||||
class UIWallCalendar : UICanvas(
|
class UIWallCalendar : UICanvas(
|
||||||
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
|
toggleKeyLiteral = "control_key_inventory",
|
||||||
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
|
toggleButtonLiteral = "control_gamepad_start",
|
||||||
) {
|
) {
|
||||||
private val yearCellWidth = 200
|
private val yearCellWidth = 200
|
||||||
private val cellWidth = 80
|
private val cellWidth = 80
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ import java.util.UUID
|
|||||||
* Created by minjaesong on 2023-05-19.
|
* Created by minjaesong on 2023-05-19.
|
||||||
*/
|
*/
|
||||||
class UIWorldPortal : UICanvas(
|
class UIWorldPortal : UICanvas(
|
||||||
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
|
toggleKeyLiteral = "control_key_inventory",
|
||||||
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
|
toggleButtonLiteral = "control_gamepad_start",
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override var width: Int = Toolkit.drawWidth
|
override var width: Int = Toolkit.drawWidth
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ import kotlin.math.roundToInt
|
|||||||
* Created by minjaesong on 2015-12-31.
|
* Created by minjaesong on 2015-12-31.
|
||||||
*/
|
*/
|
||||||
abstract class UICanvas(
|
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))
|
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||||
customPositioning: Boolean = false, // mainly used by vital meter
|
customPositioning: Boolean = false, // mainly used by vital meter
|
||||||
doNotWarnConstant: Boolean = false
|
doNotWarnConstant: Boolean = false
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
|||||||
* Created by minjaesong on 2015-12-31.
|
* Created by minjaesong on 2015-12-31.
|
||||||
*/
|
*/
|
||||||
class UIHandler(//var UI: UICanvas,
|
class UIHandler(//var UI: UICanvas,
|
||||||
var toggleKeyLiteral: Int? = null,
|
var toggleKeyLiteral: String? = null, // string key of the config
|
||||||
var toggleButtonLiteral: Int? = null,
|
var toggleButtonLiteral: String? = null, // string key of the config
|
||||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||||
var customPositioning: Boolean = false, // mainly used by vital meter
|
var customPositioning: Boolean = false, // mainly used by vital meter
|
||||||
var doNotWarnConstant: Boolean = false,
|
var doNotWarnConstant: Boolean = false,
|
||||||
@@ -130,9 +130,10 @@ void main() {
|
|||||||
//UI.handler = this
|
//UI.handler = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getConfigInt(toggleKeyLiteral)
|
||||||
private val toggleKey: Int?; get() = toggleKeyLiteral // to support in-screen keybind changing
|
val toggleKey: Int?; get() = App.getConfigInt(toggleKeyLiteral).let { if (it == -1) null else it } // to support in-screen keybind changing
|
||||||
private val toggleButton: Int?; get() = toggleButtonLiteral // 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()
|
val toggleKeyExtra: ArrayList<() -> Int> = arrayListOf()
|
||||||
|
|||||||
@@ -237,13 +237,13 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
|
|
||||||
val currentWindDir = FastMath.interpolateCatmullRom(windDirStep, windDirWindow)
|
val currentWindDir = FastMath.interpolateCatmullRom(windDirStep, windDirWindow)
|
||||||
val currentWindSpeed = FastMath.interpolateCatmullRom(windSpeedStep, windSpeedWindow)
|
val currentWindSpeed = FastMath.interpolateCatmullRom(windSpeedStep, windSpeedWindow)
|
||||||
|
/*
|
||||||
printdbg(this,
|
printdbg(this,
|
||||||
"dir ${Math.toDegrees(currentWindDir.toDouble()).roundToInt()}\t" +
|
"dir ${Math.toDegrees(currentWindDir.toDouble()).roundToInt()}\t" +
|
||||||
"spd ${currentWindSpeed.times(10f).roundToInt().div(10f)}\t " +
|
"spd ${currentWindSpeed.times(10f).roundToInt().div(10f)}\t " +
|
||||||
"dirs ${windDirWindow!!.map { Math.toDegrees(it.toDouble()).roundToInt() }} ${windDirStep.times(100).roundToInt()}\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()}"
|
"spds ${windSpeedWindow!!.map { it.times(10f).roundToInt().div(10f) }} ${windSpeedStep.times(100).roundToInt()}"
|
||||||
)
|
)*/
|
||||||
|
|
||||||
if (currentWeather.forceWindVec != null) {
|
if (currentWeather.forceWindVec != null) {
|
||||||
windVector.set(currentWeather.forceWindVec)
|
windVector.set(currentWeather.forceWindVec)
|
||||||
|
|||||||
Reference in New Issue
Block a user