mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
uis won't open or close when console is up
This commit is contained in:
@@ -25,6 +25,8 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
|||||||
open var consoleHandler: ConsoleWindow = ConsoleWindow()
|
open var consoleHandler: ConsoleWindow = ConsoleWindow()
|
||||||
|
|
||||||
var paused: Boolean = false
|
var paused: Boolean = false
|
||||||
|
val consoleOpened: Boolean
|
||||||
|
get() = consoleHandler.isOpened || consoleHandler.isOpening
|
||||||
|
|
||||||
init {
|
init {
|
||||||
consoleHandler.setPosition(0, 0)
|
consoleHandler.setPosition(0, 0)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import net.torvald.terrarum.floorInt
|
|||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.toInt
|
|
||||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
|
|
||||||
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
|
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
|
||||||
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
|
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
|
||||||
if (terrarumIngame.canPlayerControl) {
|
if (!terrarumIngame.paused) {
|
||||||
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
||||||
if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||||
|
|
||||||
@@ -81,8 +80,11 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
// KEYBOARD CONTROL //
|
// KEYBOARD CONTROL //
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
|
//KeyToggler.update(terrarumIngame.canPlayerControl)
|
||||||
|
//printdbg(this, terrarumIngame.canPlayerControl)
|
||||||
|
|
||||||
// FIXME temporarily make zoom work with 'Z' key
|
// FIXME temporarily make zoom work with 'Z' key
|
||||||
terrarumIngame.screenZoom = 1f + KeyToggler.isOn(AppLoader.getConfigInt("keyzoom")).toInt()
|
//terrarumIngame.screenZoom = 1f + KeyToggler.isOn(AppLoader.getConfigInt("keyzoom")).toInt()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +92,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
|
|
||||||
override fun keyDown(keycode: Int): Boolean {
|
override fun keyDown(keycode: Int): Boolean {
|
||||||
|
|
||||||
if (terrarumIngame.canPlayerControl) {
|
if (!terrarumIngame.paused) {
|
||||||
terrarumIngame.actorNowPlaying?.keyDown(keycode)
|
terrarumIngame.actorNowPlaying?.keyDown(keycode)
|
||||||
|
|
||||||
// quickslot by number keys
|
// quickslot by number keys
|
||||||
@@ -155,7 +157,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
|
|
||||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
|
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
|
||||||
if (terrarumIngame.canPlayerControl) {
|
if (!terrarumIngame.paused) {
|
||||||
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
||||||
if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||||
|
|
||||||
@@ -177,7 +179,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun scrolled(amount: Int): Boolean {
|
override fun scrolled(amount: Int): Boolean {
|
||||||
if (terrarumIngame.canPlayerControl) {
|
if (!terrarumIngame.paused) {
|
||||||
// quickslot by wheel
|
// quickslot by wheel
|
||||||
if (terrarumIngame.actorNowPlaying != null) {
|
if (terrarumIngame.actorNowPlaying != null) {
|
||||||
terrarumIngame.actorNowPlaying!!.actorValue.set(
|
terrarumIngame.actorNowPlaying!!.actorValue.set(
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package net.torvald.terrarum.gamecontroller
|
package net.torvald.terrarum.gamecontroller
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import net.torvald.terrarum.Terrarum
|
import com.badlogic.gdx.Input
|
||||||
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
|
import net.torvald.util.sortedArrayListOf
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object KeyToggler {
|
object KeyToggler {
|
||||||
@@ -13,7 +15,13 @@ object KeyToggler {
|
|||||||
/**
|
/**
|
||||||
* Keys that won't be updated when console is opened
|
* Keys that won't be updated when console is opened
|
||||||
*/
|
*/
|
||||||
private val gameKeys = (16..27) + (30..40) + (43..53)
|
private val gameKeys = sortedArrayListOf(
|
||||||
|
Input.Keys.NUM_1, Input.Keys.NUM_2, Input.Keys.NUM_3, Input.Keys.NUM_4, Input.Keys.NUM_5, Input.Keys.NUM_6, Input.Keys.NUM_7, Input.Keys.NUM_8, Input.Keys.NUM_9, Input.Keys.NUM_0, Input.Keys.MINUS, Input.Keys.EQUALS,
|
||||||
|
Input.Keys.Q, Input.Keys.W, Input.Keys.E, Input.Keys.R, Input.Keys.T, Input.Keys.Y, Input.Keys.U, Input.Keys.I, Input.Keys.O, Input.Keys.P, Input.Keys.LEFT_BRACKET, Input.Keys.RIGHT_BRACKET,
|
||||||
|
Input.Keys.A, Input.Keys.S, Input.Keys.D, Input.Keys.F, Input.Keys.G, Input.Keys.H, Input.Keys.J, Input.Keys.K, Input.Keys.L, Input.Keys.SEMICOLON, Input.Keys.APOSTROPHE,
|
||||||
|
Input.Keys.Z, Input.Keys.X, Input.Keys.C, Input.Keys.V, Input.Keys.B, Input.Keys.N, Input.Keys.M, Input.Keys.COMMA, Input.Keys.PERIOD, Input.Keys.SLASH,
|
||||||
|
Input.Keys.NUMPAD_0, Input.Keys.NUMPAD_1, Input.Keys.NUMPAD_2, Input.Keys.NUMPAD_3, Input.Keys.NUMPAD_4, Input.Keys.NUMPAD_5, Input.Keys.NUMPAD_6, Input.Keys.NUMPAD_7, Input.Keys.NUMPAD_8, Input.Keys.NUMPAD_9
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
fun isOn(key: Int): Boolean {
|
fun isOn(key: Int): Boolean {
|
||||||
@@ -22,11 +30,15 @@ object KeyToggler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Put this into the each scene's update/render method.
|
* Put this into the each scene's update/render method.
|
||||||
|
*
|
||||||
|
* Set ```toggleGameKeys = true``` to make toggling work for keys like Q, W, E, ...; otherwise only F1-F12 keys will be toggled
|
||||||
*/
|
*/
|
||||||
fun update(gameMode: Boolean = true) {
|
fun update(toggleGameKeys: Boolean) {
|
||||||
for (it in 0..255) {
|
for (it in 0..255) {
|
||||||
if (gameMode && it in gameKeys &&
|
if (!toggleGameKeys && gameKeys.contains(it)) {
|
||||||
(Terrarum.ingame!!.consoleHandler.isOpening || Terrarum.ingame!!.consoleHandler.isOpened)) {
|
if (Gdx.input.isKeyPressed(it))
|
||||||
|
printdbg(this, "Disallowed key: $it")
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,11 +144,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
//var paused: Boolean = false
|
//var paused: Boolean = false
|
||||||
//get() = uiAliasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmpty is always false, which we want
|
//get() = uiAliasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmpty is always false, which we want
|
||||||
/**
|
|
||||||
* Set to false if UI is opened; set to true if UI is closed.
|
|
||||||
*/
|
|
||||||
inline val canPlayerControl: Boolean
|
|
||||||
get() = !paused // FIXME temporary behab (block movement if the game is paused or paused by UIs)
|
|
||||||
|
|
||||||
var particlesActive = 0
|
var particlesActive = 0
|
||||||
private set
|
private set
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import net.torvald.util.HistoryArray
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Don't let the debug console have the ```toggleKeyLiteral```, this must open even when the game is paused
|
||||||
|
*
|
||||||
* Created by minjaesong on 2015-12-31.
|
* Created by minjaesong on 2015-12-31.
|
||||||
*/
|
*/
|
||||||
class ConsoleWindow : UICanvas() {
|
class ConsoleWindow : UICanvas() {
|
||||||
@@ -203,11 +205,13 @@ class ConsoleWindow : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun endOpening(delta: Float) {
|
override fun endOpening(delta: Float) {
|
||||||
|
Terrarum.ingame?.paused = true
|
||||||
drawOffY = 0f
|
drawOffY = 0f
|
||||||
openingTimeCounter = 0f
|
openingTimeCounter = 0f
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endClosing(delta: Float) {
|
override fun endClosing(delta: Float) {
|
||||||
|
Terrarum.ingame?.paused = false
|
||||||
drawOffY = -height.toFloat()
|
drawOffY = -height.toFloat()
|
||||||
openingTimeCounter = 0f
|
openingTimeCounter = 0f
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Camera
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
|
||||||
@@ -105,23 +106,25 @@ class UIHandler(//var UI: UICanvas,
|
|||||||
|
|
||||||
fun update(ui: UICanvas, delta: Float) {
|
fun update(ui: UICanvas, delta: Float) {
|
||||||
// open/close UI by key pressed
|
// open/close UI by key pressed
|
||||||
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!)) {
|
// some UIs will pause the game, and they still need to be closed
|
||||||
if (isClosed)
|
if (Terrarum.ingame?.consoleOpened == false && (Terrarum.ingame?.paused == false || isOpened)) {
|
||||||
setAsOpen()
|
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!)) {
|
||||||
else if (isOpened)
|
if (isClosed)
|
||||||
|
setAsOpen()
|
||||||
|
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()
|
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 (openFired && openCloseCounter > 9) openFired = false
|
||||||
//if (closeFired && openCloseCounter > 9) closeFired = false
|
//if (closeFired && openCloseCounter > 9) closeFired = false
|
||||||
|
|||||||
@@ -153,3 +153,12 @@ class SortedArrayList<T: Comparable<T>>(initialSize: Int = 10) {
|
|||||||
*/
|
*/
|
||||||
fun toArrayList() = arrayList
|
fun toArrayList() = arrayList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T: Comparable<T>> sortedArrayListOf(vararg elements: T): SortedArrayList<T> {
|
||||||
|
val a = SortedArrayList<T>(elements.size + 1)
|
||||||
|
ReentrantLock().lock {
|
||||||
|
a.arrayList.addAll(elements)
|
||||||
|
a.arrayList.sort()
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user