press tab to bring up the game menu

This commit is contained in:
minjaesong
2021-09-26 15:34:24 +09:00
parent 3680047e9a
commit 0e5c86ad04
10 changed files with 120 additions and 50 deletions

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.jme3.math.FastMath
import net.torvald.terrarum.sqr
/**
* Created by minjaesong on 2016-03-22.
@@ -26,5 +27,19 @@ object Movement{
if (scale < 0f) start
else if (scale > 1f) end
else (start - end) * FastMath.cos2(0.5f * FastMath.PI * scale) + end
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
(start - end) * ((timer / duration) - 1).sqr() + end
fun moveLinear(start: Float, end: Float, timer: Float, duration: Float): Float {
val scale = timer / duration
if (start == end) {
return start
}
if (scale <= 0f) {
return start
}
if (scale >= 1f) {
return end
}
return ((1f - scale) * start) + (scale * end)
}
}

View File

@@ -24,12 +24,13 @@ 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,
internal var allowESCtoClose: Boolean = false
var customPositioning: Boolean = false, // mainly used by vital meter
var doNotWarnConstant: Boolean = false,
internal var allowESCtoClose: Boolean = false,
var uiTogglerFunctionDefault: ((UIHandler) -> Unit)? = null
): Disposable {
companion object {
@@ -128,6 +129,21 @@ void main() {
private val toggleButton: Int?; get() = toggleButtonLiteral // to support in-screen keybind changing
val toggleKeyExtra: ArrayList<() -> Int> = arrayListOf()
/**
* Takes a function that works with UIHandler.
* For the function, try starting from the:
* ```
* if (it.isClosed)
* it.setAsOpen()
* else if (it.isOpened)
* setAsClose()
* ```
*/
val toggleKeyExtraAction: ArrayList<(UIHandler) -> Unit> = arrayListOf()
val subUIs = ArrayList<UICanvas>()
val mouseUp: Boolean
@@ -165,15 +181,30 @@ void main() {
// some UIs will pause the game, and they still need to be closed
if (!uiToggleLocked && (Terrarum.ingame?.consoleOpened == false && (Terrarum.ingame?.paused == false || isOpened))) {
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!)) {
if (isClosed)
setAsOpen()
else if (isOpened)
setAsClose()
if (uiTogglerFunctionDefault == null) {
if (isClosed)
setAsOpen()
else if (isOpened)
setAsClose()
}
else uiTogglerFunctionDefault!!.invoke(this)
// for the case of intermediate states, do nothing.
}
if (toggleButton != null) {
/* */
if (toggleButton != null && Gdx.input.isButtonJustPressed(toggleButton!!)) {
if (uiTogglerFunctionDefault == null) {
if (isClosed)
setAsOpen()
else if (isOpened)
setAsClose()
}
else uiTogglerFunctionDefault!!.invoke(this)
}
toggleKeyExtra.forEachIndexed { index, getKey ->
if (Gdx.input.isKeyJustPressed(getKey())) {
toggleKeyExtraAction[0].invoke(this)
}
}
// ESC is a master key for closing

View File

@@ -63,7 +63,7 @@ class UIItemList<Item: UIItem>(
highlighterMoveTimer += delta
if (selectedIndex != null) {
highlightY = UIUtils.moveQuick(
highlightY = Movement.moveQuick(
highlighterYStart!!,
highlighterYEnd!!,
highlighterMoveTimer,

View File

@@ -183,7 +183,7 @@ class UIItemTextButtonList(
highlighterMoveTimer += delta
if (selectedIndex != null) {
highlightY = UIUtils.moveQuick(
highlightY = Movement.moveQuick(
highlighterYStart!!,
highlighterYEnd!!,
highlighterMoveTimer.toFloat(),

View File

@@ -37,6 +37,14 @@ open class UIItemTransitionContainer(
}
}
fun forcePosition(target: Int) {
transitionOngoing = false
transitionRequested = false
transitionTimer = 0f
currentPosition = target.toFloat()
onTransition(currentPosition, uis)
}
override fun update(delta: Float) {
super.update(delta)
uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.update(delta) }
@@ -56,7 +64,7 @@ open class UIItemTransitionContainer(
if (transitionOngoing) {
transitionTimer += Gdx.graphics.deltaTime
currentPosition = UIUtils.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
currentPosition = Movement.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
if (transitionTimer > transitionLength) {
transitionOngoing = false

View File

@@ -1,24 +0,0 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.sqr
/**
* Created by minjaesong on 2017-03-14.
*/
object UIUtils {
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
(start - end) * ((timer / duration) - 1).sqr() + end
fun moveLinear(start: Float, end: Float, timer: Float, duration: Float): Float {
val scale = timer / duration
if (start == end) {
return start
}
if (scale <= 0f) {
return start
}
if (scale >= 1f) {
return end
}
return ((1f - scale) * start) + (scale * end)
}
}