some UIs can be closed with ESC key

This commit is contained in:
minjaesong
2019-07-08 21:50:35 +09:00
parent f95ea1ab0f
commit e4974025a0
3 changed files with 24 additions and 15 deletions

View File

@@ -1,7 +1,5 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -38,7 +36,11 @@ internal class FixtureCraftingTable : FixtureBase(
internal object UICraftingTable : UICanvas() {
override var width = 512
override var height = 512
override var openCloseTime: Second = 0.05f
override var openCloseTime: Second = 0.0f
init {
handler.allowESCtoClose = true
}
override fun updateUI(delta: Float) {
@@ -49,10 +51,6 @@ internal object UICraftingTable : UICanvas() {
batch.color = Color.WHITE
batch.draw(AppLoader.resourcePool.getAsTextureRegion("test_texture"), 0f, 0f)
if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) {
handler.setAsClose()
}
}
override fun doOpening(delta: Float) {

View File

@@ -43,7 +43,9 @@ class UIInventoryFull(
val internalWidth: Int = UIItemInventoryDynamicList.WIDTH + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap
val internalHeight: Int = 166 + UIItemInventoryDynamicList.HEIGHT // grad_begin..grad_end..contents..grad_begin..grad_end
init {
handler.allowESCtoClose = true
}
internal val catIcons: TextureRegionPack = TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20)
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -17,10 +19,12 @@ 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: Int? = null,
var toggleButtonLiteral: Int? = null,
// 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
var doNotWarnConstant: Boolean = false,
internal var allowESCtoClose: Boolean = false
): Disposable {
// X/Y Position relative to the game window.
@@ -101,18 +105,23 @@ class UIHandler(//var UI: UICanvas,
fun update(ui: UICanvas, delta: Float) {
// open/close UI by key pressed
if (toggleKey != null) {
if (KeyToggler.isOn(toggleKey!!)) {
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!)) {
if (isClosed)
setAsOpen()
}
else {
else if (isOpened)
setAsClose()
}
// for the case of intermediate states, do nothing.
}
if (toggleButton != null) {
/* */
}
// ESC is a master key for closing
if (allowESCtoClose && Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE) && isOpened) {
setAsClose()
}
//if (openFired && openCloseCounter > 9) openFired = false
//if (closeFired && openCloseCounter > 9) closeFired = false