Hide hotkeys on devices without keyboard (#3350)

* Hide hotkeys on devices without keyboard

* Test for peripheral keyboard
This commit is contained in:
jnecus 2020-11-19 21:43:29 +00:00 committed by GitHub
parent c33793cf81
commit c338afc7f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,7 @@
package com.unciv.ui.worldscreen.unit package com.unciv.ui.worldscreen.unit
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
@ -15,7 +17,7 @@ import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import kotlin.concurrent.thread import kotlin.concurrent.thread
private data class UnitIconAndKey (val Icon: Actor, val key: Char = 0.toChar()) private data class UnitIconAndKey(val Icon: Actor, var key: Char = 0.toChar())
class UnitActionsTable(val worldScreen: WorldScreen) : Table() { class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
@ -71,6 +73,11 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
private fun getUnitActionButton(unitAction: UnitAction): Button { private fun getUnitActionButton(unitAction: UnitAction): Button {
val iconAndKey = getIconAndKeyForUnitAction(unitAction.title) val iconAndKey = getIconAndKeyForUnitAction(unitAction.title)
// If peripheral keyboard not detected, hotkeys will not be displayed
val keyboardAvailable = Gdx.input.isPeripheralAvailable(Input.Peripheral.HardwareKeyboard)
if (!keyboardAvailable){iconAndKey.key = 0.toChar()}
val actionButton = Button(CameraStageBaseScreen.skin) val actionButton = Button(CameraStageBaseScreen.skin)
actionButton.add(iconAndKey.Icon).size(20f).pad(5f) actionButton.add(iconAndKey.Icon).size(20f).pad(5f)
val fontColor = if (unitAction.isCurrentAction) Color.YELLOW else Color.WHITE val fontColor = if (unitAction.isCurrentAction) Color.YELLOW else Color.WHITE