mirror of
https://github.com/yairm210/Unciv.git
synced 2025-10-01 16:01:45 -04:00
Should be able to add key shortcuts in any screen now :)
This commit is contained in:
parent
55d0f7f1dd
commit
ae9a026201
@ -12,7 +12,7 @@ class GameSettings {
|
|||||||
var checkForDueUnits: Boolean = true
|
var checkForDueUnits: Boolean = true
|
||||||
var singleTapMove: Boolean = false
|
var singleTapMove: Boolean = false
|
||||||
var language: String = "English"
|
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<String>()
|
var tutorialsShown = HashSet<String>()
|
||||||
var tutorialTasksCompleted = HashSet<String>()
|
var tutorialTasksCompleted = HashSet<String>()
|
||||||
var hasCrashedRecently = false
|
var hasCrashedRecently = false
|
||||||
|
@ -20,6 +20,7 @@ import com.unciv.models.Tutorial
|
|||||||
import com.unciv.models.UncivSound
|
import com.unciv.models.UncivSound
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.tutorials.TutorialController
|
import com.unciv.ui.tutorials.TutorialController
|
||||||
|
import java.util.HashMap
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
@ -30,18 +31,32 @@ open class CameraStageBaseScreen : Screen {
|
|||||||
|
|
||||||
protected val tutorialController by lazy { TutorialController(this) }
|
protected val tutorialController by lazy { TutorialController(this) }
|
||||||
|
|
||||||
|
// An initialized val always turned out to illegally be null...
|
||||||
|
var keyPressDispatcher: HashMap<Char, (() -> Unit)>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val width:Float
|
keyPressDispatcher = hashMapOf()
|
||||||
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()
|
|
||||||
}
|
|
||||||
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
|
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
|
||||||
width = resolutions[0]
|
val width = resolutions[0]
|
||||||
height = resolutions[1]
|
val height = resolutions[1]
|
||||||
|
|
||||||
stage = Stage(ExtendViewport(width, height), batch)
|
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() {}
|
override fun show() {}
|
||||||
|
@ -70,8 +70,6 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
|
|
||||||
private var backButtonListener : InputListener
|
private var backButtonListener : InputListener
|
||||||
|
|
||||||
// An initialized val always turned out to illegally be null...
|
|
||||||
lateinit var keyPressDispatcher: HashMap<Char, (() -> Unit)>
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -226,19 +224,9 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
return true
|
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(){
|
private fun loadLatestMultiplayerState(){
|
||||||
@ -488,7 +476,6 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
nextTurnButton.labelCell.pad(10f)
|
nextTurnButton.labelCell.pad(10f)
|
||||||
val nextTurnActionWrapped = { nextTurnAction() }
|
val nextTurnActionWrapped = { nextTurnAction() }
|
||||||
nextTurnButton.onClick (nextTurnActionWrapped)
|
nextTurnButton.onClick (nextTurnActionWrapped)
|
||||||
if (!::keyPressDispatcher.isInitialized) keyPressDispatcher = hashMapOf()
|
|
||||||
keyPressDispatcher[' '] = nextTurnActionWrapped
|
keyPressDispatcher[' '] = nextTurnActionWrapped
|
||||||
keyPressDispatcher['n'] = nextTurnActionWrapped
|
keyPressDispatcher['n'] = nextTurnActionWrapped
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user