mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
press tab to bring up the game menu
This commit is contained in:
@@ -58,6 +58,7 @@ object DefaultConfig {
|
|||||||
"control_key_down" to Input.Keys.D,
|
"control_key_down" to Input.Keys.D,
|
||||||
"control_key_right" to Input.Keys.F, // ESDF Masterrace
|
"control_key_right" to Input.Keys.F, // ESDF Masterrace
|
||||||
|
|
||||||
|
"control_key_jump" to Input.Keys.SPACE,
|
||||||
"control_key_movementaux" to Input.Keys.A, // movement-auxiliary, or hookshot
|
"control_key_movementaux" to Input.Keys.A, // movement-auxiliary, or hookshot
|
||||||
"control_key_inventory" to Input.Keys.Q,
|
"control_key_inventory" to Input.Keys.Q,
|
||||||
"control_key_interact" to Input.Keys.R,
|
"control_key_interact" to Input.Keys.R,
|
||||||
@@ -67,15 +68,14 @@ object DefaultConfig {
|
|||||||
|
|
||||||
"control_key_gamemenu" to Input.Keys.TAB,
|
"control_key_gamemenu" to Input.Keys.TAB,
|
||||||
"control_key_quicksel" to Input.Keys.SHIFT_LEFT, // pie menu is now LShift because GDX does not read CapsLock
|
"control_key_quicksel" to Input.Keys.SHIFT_LEFT, // pie menu is now LShift because GDX does not read CapsLock
|
||||||
|
"control_mouse_quicksel" to Input.Buttons.MIDDLE, // middle click to open pie menu
|
||||||
|
|
||||||
// Colemak, Workman and some typers use CapsLock as Backspace, Apple-JIS and HHKB has Control in place of CapsLock and often re-assigned to Command
|
// Colemak, Workman and some typers use CapsLock as Backspace, Apple-JIS and HHKB has Control in place of CapsLock and often re-assigned to Command
|
||||||
// so these keys are treated as the same.
|
// so these keys are treated as the same.
|
||||||
// FOR ~~FUCKS~~ERGONOMICS' SAKE DON'T USE CTRL AND ALT AS A KEY!
|
// FOR ~~FUCKS~~ERGONOMICS' SAKE DON'T USE CTRL AND ALT AS A KEY!
|
||||||
"control_key_quickselalt" to intArrayOf(Input.Keys.BACKSPACE, Input.Keys.CONTROL_LEFT, Input.Keys.BACKSLASH),
|
"control_key_quickslots" to (Input.Keys.NUM_0..Input.Keys.NUM_9).map { 1.0*it }.toDoubleArray(),
|
||||||
"control_mouse_quicksel" to Input.Buttons.MIDDLE, // middle click to open pie menu
|
"control_key_quickselalt" to intArrayOf(Input.Keys.BACKSPACE, Input.Keys.CONTROL_LEFT, Input.Keys.BACKSLASH).map { 1.0*it }.toDoubleArray(),
|
||||||
|
|
||||||
"control_key_jump" to Input.Keys.SPACE,
|
|
||||||
|
|
||||||
"control_key_quickslots" to (Input.Keys.NUM_0..Input.Keys.NUM_9).toList().toIntArray(),
|
|
||||||
|
|
||||||
"config_mouseprimary" to Input.Buttons.LEFT, // left mouse
|
"config_mouseprimary" to Input.Buttons.LEFT, // left mouse
|
||||||
"config_mousesecondary" to Input.Buttons.RIGHT, // right mouse
|
"config_mousesecondary" to Input.Buttons.RIGHT, // right mouse
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import com.badlogic.gdx.graphics.Pixmap
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
import net.torvald.terrarum.ui.Movement
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UIItem
|
import net.torvald.terrarum.ui.UIItem
|
||||||
import net.torvald.terrarum.ui.UIItemImageButton
|
import net.torvald.terrarum.ui.UIItemImageButton
|
||||||
import net.torvald.terrarum.ui.UIUtils
|
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@@ -136,8 +135,18 @@ class UIItemInventoryCatBar(
|
|||||||
/**
|
/**
|
||||||
* 0: map, 1: inventory caticons, 2: menu
|
* 0: map, 1: inventory caticons, 2: menu
|
||||||
*/
|
*/
|
||||||
var selectedPanel = 1
|
var selectedPanel = 1; private set
|
||||||
private set
|
|
||||||
|
|
||||||
|
fun setSelectedPanel(n: Int) {
|
||||||
|
if (n !in 0..2) throw IllegalArgumentException("$n")
|
||||||
|
selectedPanel = n
|
||||||
|
|
||||||
|
sideButtons[0].highlighted = (n == 0)
|
||||||
|
mainButtons[selectedIndex].highlighted = (n == 1)
|
||||||
|
sideButtons[3].highlighted = (n == 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// set up underlined indicator
|
// set up underlined indicator
|
||||||
init {
|
init {
|
||||||
@@ -171,7 +180,7 @@ class UIItemInventoryCatBar(
|
|||||||
if (highlighterMoving) {
|
if (highlighterMoving) {
|
||||||
highlighterMoveTimer += delta
|
highlighterMoveTimer += delta
|
||||||
|
|
||||||
highlighterXPos = UIUtils.moveQuick(
|
highlighterXPos = Movement.moveQuick(
|
||||||
highlighterXStart,
|
highlighterXStart,
|
||||||
highlighterXEnd,
|
highlighterXEnd,
|
||||||
highlighterMoveTimer,
|
highlighterMoveTimer,
|
||||||
|
|||||||
@@ -184,6 +184,30 @@ class UIInventoryFull(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// force position of things to UI when opened with "control_key_inventory"
|
||||||
|
this.handler.uiTogglerFunctionDefault = {
|
||||||
|
if (it.isClosed) {
|
||||||
|
transitionPanel.forcePosition(1)
|
||||||
|
catBar.setSelectedPanel(1)
|
||||||
|
it.setAsOpen()
|
||||||
|
}
|
||||||
|
else if (it.isOpened)
|
||||||
|
setAsClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow "control_key_gamemenu" to open this UI
|
||||||
|
this.handler.toggleKeyExtra.add { App.getConfigInt("control_key_gamemenu") }
|
||||||
|
this.handler.toggleKeyExtraAction.add {
|
||||||
|
if (it.isClosed) {
|
||||||
|
transitionPanel.forcePosition(2)
|
||||||
|
catBar.setSelectedPanel(2)
|
||||||
|
it.setAsOpen()
|
||||||
|
}
|
||||||
|
else if (it.isOpened)
|
||||||
|
setAsClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
rebuildList()
|
rebuildList()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,14 @@ object WriteConfig {
|
|||||||
override fun write(json: Json, obj: KVHashMap, knownType: Class<*>?) {
|
override fun write(json: Json, obj: KVHashMap, knownType: Class<*>?) {
|
||||||
json.writeObjectStart()
|
json.writeObjectStart()
|
||||||
obj.hashMap.toSortedMap().forEach { (k, v) ->
|
obj.hashMap.toSortedMap().forEach { (k, v) ->
|
||||||
json.writeValue(k, v)
|
json.writeValue(k,
|
||||||
|
if (v is Int) v as Int
|
||||||
|
else if (v is Double) v as Double
|
||||||
|
else if (v is IntArray) v as IntArray
|
||||||
|
else if (v is DoubleArray) v as DoubleArray
|
||||||
|
else if (v is Boolean) v as Boolean
|
||||||
|
else v.toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
json.writeObjectEnd()
|
json.writeObjectEnd()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.terrarum.ui
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
|
import net.torvald.terrarum.sqr
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-03-22.
|
* Created by minjaesong on 2016-03-22.
|
||||||
@@ -26,5 +27,19 @@ object Movement{
|
|||||||
if (scale < 0f) start
|
if (scale < 0f) start
|
||||||
else if (scale > 1f) end
|
else if (scale > 1f) end
|
||||||
else (start - end) * FastMath.cos2(0.5f * FastMath.PI * scale) + 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,12 +24,13 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
|||||||
* Created by minjaesong on 2015-12-31.
|
* Created by minjaesong on 2015-12-31.
|
||||||
*/
|
*/
|
||||||
class UIHandler(//var UI: UICanvas,
|
class UIHandler(//var UI: UICanvas,
|
||||||
var toggleKeyLiteral: Int? = null,
|
var toggleKeyLiteral: Int? = null,
|
||||||
var toggleButtonLiteral: Int? = null,
|
var toggleButtonLiteral: Int? = null,
|
||||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||||
var customPositioning: Boolean = false, // mainly used by vital meter
|
var customPositioning: Boolean = false, // mainly used by vital meter
|
||||||
var doNotWarnConstant: Boolean = false,
|
var doNotWarnConstant: Boolean = false,
|
||||||
internal var allowESCtoClose: Boolean = false
|
internal var allowESCtoClose: Boolean = false,
|
||||||
|
var uiTogglerFunctionDefault: ((UIHandler) -> Unit)? = null
|
||||||
): Disposable {
|
): Disposable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -128,6 +129,21 @@ void main() {
|
|||||||
private val toggleButton: Int?; get() = toggleButtonLiteral // to support in-screen keybind changing
|
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 subUIs = ArrayList<UICanvas>()
|
||||||
|
|
||||||
val mouseUp: Boolean
|
val mouseUp: Boolean
|
||||||
@@ -165,15 +181,30 @@ void main() {
|
|||||||
// some UIs will pause the game, and they still need to be closed
|
// 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 (!uiToggleLocked && (Terrarum.ingame?.consoleOpened == false && (Terrarum.ingame?.paused == false || isOpened))) {
|
||||||
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!)) {
|
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!)) {
|
||||||
if (isClosed)
|
if (uiTogglerFunctionDefault == null) {
|
||||||
setAsOpen()
|
if (isClosed)
|
||||||
else if (isOpened)
|
setAsOpen()
|
||||||
setAsClose()
|
else if (isOpened)
|
||||||
|
setAsClose()
|
||||||
|
}
|
||||||
|
else uiTogglerFunctionDefault!!.invoke(this)
|
||||||
|
|
||||||
// for the case of intermediate states, do nothing.
|
// 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
|
// ESC is a master key for closing
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class UIItemList<Item: UIItem>(
|
|||||||
highlighterMoveTimer += delta
|
highlighterMoveTimer += delta
|
||||||
|
|
||||||
if (selectedIndex != null) {
|
if (selectedIndex != null) {
|
||||||
highlightY = UIUtils.moveQuick(
|
highlightY = Movement.moveQuick(
|
||||||
highlighterYStart!!,
|
highlighterYStart!!,
|
||||||
highlighterYEnd!!,
|
highlighterYEnd!!,
|
||||||
highlighterMoveTimer,
|
highlighterMoveTimer,
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class UIItemTextButtonList(
|
|||||||
highlighterMoveTimer += delta
|
highlighterMoveTimer += delta
|
||||||
|
|
||||||
if (selectedIndex != null) {
|
if (selectedIndex != null) {
|
||||||
highlightY = UIUtils.moveQuick(
|
highlightY = Movement.moveQuick(
|
||||||
highlighterYStart!!,
|
highlighterYStart!!,
|
||||||
highlighterYEnd!!,
|
highlighterYEnd!!,
|
||||||
highlighterMoveTimer.toFloat(),
|
highlighterMoveTimer.toFloat(),
|
||||||
|
|||||||
@@ -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) {
|
override fun update(delta: Float) {
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.update(delta) }
|
uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.update(delta) }
|
||||||
@@ -56,7 +64,7 @@ open class UIItemTransitionContainer(
|
|||||||
if (transitionOngoing) {
|
if (transitionOngoing) {
|
||||||
transitionTimer += Gdx.graphics.deltaTime
|
transitionTimer += Gdx.graphics.deltaTime
|
||||||
|
|
||||||
currentPosition = UIUtils.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
|
currentPosition = Movement.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
|
||||||
|
|
||||||
if (transitionTimer > transitionLength) {
|
if (transitionTimer > transitionLength) {
|
||||||
transitionOngoing = false
|
transitionOngoing = false
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user