mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
confirmation added for exit game and return to main menu
This commit is contained in:
@@ -19,7 +19,14 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
|||||||
override var height: Int = App.scr.height
|
override var height: Int = App.scr.height
|
||||||
override var openCloseTime = 0.0f
|
override var openCloseTime = 0.0f
|
||||||
|
|
||||||
private val gameMenu = arrayOf("MENU_LABEL_MAINMENU", "MENU_LABEL_DESKTOP", "MENU_OPTIONS_CONTROLS", "MENU_OPTIONS_SOUND", "MENU_LABEL_GRAPHICS")
|
private val gameMenu = arrayOf(
|
||||||
|
"MENU_IO_SAVE_GAME",
|
||||||
|
"MENU_LABEL_GRAPHICS",
|
||||||
|
"MENU_OPTIONS_CONTROLS",
|
||||||
|
"MENU_OPTIONS_SOUND",
|
||||||
|
"MENU_LABEL_RETURN_MAIN",
|
||||||
|
"MENU_LABEL_DESKTOP",
|
||||||
|
)
|
||||||
private val gameMenuListHeight = DEFAULT_LINE_HEIGHT * gameMenu.size
|
private val gameMenuListHeight = DEFAULT_LINE_HEIGHT * gameMenu.size
|
||||||
private val gameMenuListWidth = 400
|
private val gameMenuListWidth = 400
|
||||||
private val gameMenuButtons = UIItemTextButtonList(
|
private val gameMenuButtons = UIItemTextButtonList(
|
||||||
@@ -35,42 +42,114 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
|||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = null
|
defaultSelection = null
|
||||||
)
|
)
|
||||||
|
private val areYouSureMainMenuButtons = UIItemTextButtonList(
|
||||||
|
this, DEFAULT_LINE_HEIGHT, arrayOf("MENU_LABEL_RETURN_MAIN_QUESTION", "MENU_LABEL_RETURN_MAIN", "MENU_LABEL_CANCEL"),
|
||||||
|
(App.scr.width - gameMenuListWidth) / 2,
|
||||||
|
INVENTORY_CELLS_OFFSET_Y + (INVENTORY_CELLS_UI_HEIGHT - (DEFAULT_LINE_HEIGHT * 3)) / 2,
|
||||||
|
gameMenuListWidth, DEFAULT_LINE_HEIGHT * 3,
|
||||||
|
readFromLang = true,
|
||||||
|
textAreaWidth = gameMenuListWidth,
|
||||||
|
activeBackCol = Color(0),
|
||||||
|
highlightBackCol = Color(0),
|
||||||
|
backgroundCol = Color(0),
|
||||||
|
inactiveCol = Color.WHITE,
|
||||||
|
defaultSelection = null
|
||||||
|
)
|
||||||
|
private val areYouSureQuitButtons = UIItemTextButtonList(
|
||||||
|
this, DEFAULT_LINE_HEIGHT, arrayOf("MENU_LABEL_DESKTOP_QUESTION", "MENU_LABEL_DESKTOP", "MENU_LABEL_CANCEL"),
|
||||||
|
(App.scr.width - gameMenuListWidth) / 2,
|
||||||
|
INVENTORY_CELLS_OFFSET_Y + (INVENTORY_CELLS_UI_HEIGHT - (DEFAULT_LINE_HEIGHT * 3)) / 2,
|
||||||
|
gameMenuListWidth, DEFAULT_LINE_HEIGHT * 3,
|
||||||
|
readFromLang = true,
|
||||||
|
textAreaWidth = gameMenuListWidth,
|
||||||
|
activeBackCol = Color(0),
|
||||||
|
highlightBackCol = Color(0),
|
||||||
|
backgroundCol = Color(0),
|
||||||
|
inactiveCol = Color.WHITE,
|
||||||
|
defaultSelection = null
|
||||||
|
)
|
||||||
|
|
||||||
|
private var screen = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
uiItems.add(gameMenuButtons)
|
uiItems.add(gameMenuButtons)
|
||||||
|
|
||||||
gameMenuButtons.selectionChangeListener = { _, new ->
|
gameMenuButtons.selectionChangeListener = { _, new ->
|
||||||
when (new) {
|
when (new) {
|
||||||
0 -> App.setScreen(TitleScreen(App.batch))
|
4 -> screen = 2
|
||||||
|
5 -> screen = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
areYouSureMainMenuButtons.selectionChangeListener = { _, new ->
|
||||||
|
when (new) {
|
||||||
|
1 -> App.setScreen(TitleScreen(App.batch))
|
||||||
|
2 -> screen = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
areYouSureQuitButtons.selectionChangeListener = { _, new ->
|
||||||
|
when (new) {
|
||||||
1 -> Gdx.app.exit()
|
1 -> Gdx.app.exit()
|
||||||
|
2 -> screen = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val screenUpdates = arrayOf(
|
||||||
|
{ delta: Float ->
|
||||||
|
gameMenuButtons.update(delta)
|
||||||
|
},
|
||||||
|
{ delta: Float ->
|
||||||
|
areYouSureQuitButtons.update(delta)
|
||||||
|
},
|
||||||
|
{ delta: Float ->
|
||||||
|
areYouSureMainMenuButtons.update(delta)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
private val screenRenders = arrayOf(
|
||||||
|
{ batch: SpriteBatch, camera: Camera ->
|
||||||
|
// control hints
|
||||||
|
App.fontGame.draw(batch, full.gameMenuControlHelp, full.offsetX, full.yEnd - 20)
|
||||||
|
|
||||||
|
// text buttons
|
||||||
|
gameMenuButtons.render(batch, camera)
|
||||||
|
},
|
||||||
|
{ batch: SpriteBatch, camera: Camera ->
|
||||||
|
// control hints
|
||||||
|
App.fontGame.draw(batch, full.gameMenuControlHelp, full.offsetX, full.yEnd - 20)
|
||||||
|
|
||||||
|
areYouSureQuitButtons.render(batch, camera)
|
||||||
|
},
|
||||||
|
{ batch: SpriteBatch, camera: Camera ->
|
||||||
|
// control hints
|
||||||
|
App.fontGame.draw(batch, full.gameMenuControlHelp, full.offsetX, full.yEnd - 20)
|
||||||
|
|
||||||
|
areYouSureMainMenuButtons.render(batch, camera)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
override fun updateUI(delta: Float) {
|
override fun updateUI(delta: Float) {
|
||||||
gameMenuButtons.update(delta)
|
screenUpdates[screen](delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
// control hints
|
|
||||||
blendNormal(batch)
|
blendNormal(batch)
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
App.fontGame.draw(batch, full.gameMenuControlHelp, full.offsetX, full.yEnd - 20)
|
screenRenders[screen](batch, camera)
|
||||||
|
|
||||||
// text buttons
|
|
||||||
gameMenuButtons.render(batch, camera)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doClosing(delta: Float) {
|
override fun doClosing(delta: Float) {
|
||||||
|
screen = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endOpening(delta: Float) {
|
override fun endOpening(delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endClosing(delta: Float) {
|
override fun endClosing(delta: Float) {
|
||||||
|
screen = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
abstract val width: Int
|
abstract val width: Int
|
||||||
abstract val height: Int
|
abstract val height: Int
|
||||||
|
|
||||||
|
private val mouseButton = App.getConfigInt("config_mouseprimary")
|
||||||
|
|
||||||
/** This variable is NOT updated on its own.
|
/** This variable is NOT updated on its own.
|
||||||
* ```
|
* ```
|
||||||
* val posXDelta = posX - oldPosX
|
* val posXDelta = posX - oldPosX
|
||||||
@@ -88,9 +90,20 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||||
/** If mouse is hovering over it and mouse is down */
|
/** If mouse is hovering over it and mouse is down */
|
||||||
open val mousePushed: Boolean
|
open val mousePushed: Boolean
|
||||||
get() = mouseUp && Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))
|
get() = mouseUp && Gdx.input.isButtonPressed(mouseButton)
|
||||||
|
/** If mouse is just pushed */
|
||||||
|
open val mouseJustPushed: Boolean
|
||||||
|
get() {
|
||||||
|
if (mouseUp && !mouseLatched && Gdx.input.isButtonJustPressed(mouseButton)) {
|
||||||
|
mouseLatched = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private var mouseLatched = false
|
||||||
|
|
||||||
/** UI to call (show up) while mouse is up */
|
/** UI to call (show up) while mouse is up */
|
||||||
open val mouseOverCall: UICanvas? = null
|
open val mouseOverCall: UICanvas? = null
|
||||||
|
|
||||||
@@ -139,6 +152,8 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
if (mouseOverCall?.isVisible ?: false) {
|
if (mouseOverCall?.isVisible ?: false) {
|
||||||
mouseOverCall?.setAsClose()
|
mouseOverCall?.setAsClose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mouseLatched = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package net.torvald.terrarum.ui
|
|||||||
import com.badlogic.gdx.graphics.Camera
|
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 net.torvald.terrarum.*
|
import net.torvald.terrarum.BlendMode
|
||||||
|
import net.torvald.terrarum.Second
|
||||||
|
import net.torvald.terrarum.fillRect
|
||||||
|
import net.torvald.terrarum.toInt
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-03-13.
|
* Created by minjaesong on 2017-03-13.
|
||||||
@@ -186,7 +188,7 @@ class UIItemTextButtonList(
|
|||||||
btn.update(delta)
|
btn.update(delta)
|
||||||
|
|
||||||
|
|
||||||
if (btn.mousePushed && index != selectedIndex) {
|
if (btn.mouseJustPushed && index != selectedIndex) {
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
if (kinematic) {
|
if (kinematic) {
|
||||||
|
|||||||
Reference in New Issue
Block a user