diff --git a/core/src/com/unciv/logic/civilization/Notification.kt b/core/src/com/unciv/logic/civilization/Notification.kt index 48d5def01f..f7d2ccd14b 100644 --- a/core/src/com/unciv/logic/civilization/Notification.kt +++ b/core/src/com/unciv/logic/civilization/Notification.kt @@ -11,7 +11,7 @@ import com.unciv.ui.worldscreen.WorldScreen * [action] is not realized as lambda, as it would be too easy to introduce references to objects * there that should not be serialized to the saved game. */ -open class Notification( +open class Notification ( // default parameters necessary for json deserialization var text: String = "", var color: Color = Color.BLACK, diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 18c84ea28b..36dc3ce11c 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -12,7 +12,7 @@ class GameSettings { var checkForDueUnits: Boolean = true var singleTapMove: Boolean = false var language: String = "English" - var resolution: String = "900x600" + var resolution: String = "900x600" // Aut-detecting resolution was a BAD IDEA since it needs to be based on DPI AND resolution. var tutorialsShown = HashSet() var tutorialTasksCompleted = HashSet() var hasCrashedRecently = false diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 40ba5e762a..1ed6900630 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -20,6 +20,7 @@ import com.unciv.models.Tutorial import com.unciv.models.UncivSound import com.unciv.models.translations.tr import com.unciv.ui.tutorials.TutorialController +import java.util.HashMap import kotlin.concurrent.thread import kotlin.random.Random @@ -30,18 +31,32 @@ open class CameraStageBaseScreen : Screen { protected val tutorialController by lazy { TutorialController(this) } + // An initialized val always turned out to illegally be null... + var keyPressDispatcher: HashMap Unit)> + init { - val width:Float - val height:Float - if(game.settings.resolution=="Auto") { // Aut-detecting resolution was a BAD IDEA since it needs to be based on DPI AND resolution. - game.settings.resolution = "900x600" - game.settings.save() - } + keyPressDispatcher = hashMapOf() val resolutions: List = game.settings.resolution.split("x").map { it.toInt().toFloat() } - width = resolutions[0] - height = resolutions[1] + val width = resolutions[0] + val height = resolutions[1] stage = Stage(ExtendViewport(width, height), batch) + + + stage.addListener( + object : InputListener() { + override fun keyTyped(event: InputEvent?, character: Char): Boolean { + if (character.toLowerCase() in keyPressDispatcher && !hasOpenPopups()) { + //try-catch mainly for debugging. Breakpoints in the vicinity can make the event fire twice in rapid succession, second time the context can be invalid + try { + keyPressDispatcher[character.toLowerCase()]?.invoke() + } catch (ex: Exception) {} + return true + } + return super.keyTyped(event, character) + } + } + ) } override fun show() {} @@ -66,7 +81,7 @@ open class CameraStageBaseScreen : Screen { override fun dispose() {} - fun displayTutorial( tutorial: Tutorial, test: (()->Boolean)? = null ) { + fun displayTutorial(tutorial: Tutorial, test: (() -> Boolean)? = null) { if (!game.settings.showTutorials) return if (game.settings.tutorialsShown.contains(tutorial.name)) return if (test != null && !test()) return @@ -95,7 +110,7 @@ open class CameraStageBaseScreen : Screen { } /** It returns the assigned [InputListener] */ - fun onBackButtonClicked(action:()->Unit): InputListener { + fun onBackButtonClicked(action: () -> Unit): InputListener { val listener = object : InputListener() { override fun keyDown(event: InputEvent?, keycode: Int): Boolean { if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) { diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 85009fa5dc..46e2b5c9e2 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -70,8 +70,6 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { private var backButtonListener : InputListener - // An initialized val always turned out to illegally be null... - lateinit var keyPressDispatcher: HashMap Unit)> init { @@ -226,19 +224,9 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { } return true } - - override fun keyTyped(event: InputEvent?, character: Char): Boolean { - if (character.toLowerCase() in keyPressDispatcher && !hasOpenPopups()) { - //try-catch mainly for debugging. Breakpoints in the vicinity can make the event fire twice in rapid succession, second time the context can be invalid - try { - keyPressDispatcher[character.toLowerCase()]?.invoke() - } catch (ex: Exception) {} - return true - } - return super.keyTyped(event, character) - } } ) + } private fun loadLatestMultiplayerState(){ @@ -488,7 +476,6 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { nextTurnButton.labelCell.pad(10f) val nextTurnActionWrapped = { nextTurnAction() } nextTurnButton.onClick (nextTurnActionWrapped) - if (!::keyPressDispatcher.isInitialized) keyPressDispatcher = hashMapOf() keyPressDispatcher[' '] = nextTurnActionWrapped keyPressDispatcher['n'] = nextTurnActionWrapped