mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 21:31:51 +09:00
reset button for control setup
This commit is contained in:
@@ -10,6 +10,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTOR
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_UI_HEIGHT
|
||||
import net.torvald.terrarum.serialise.WriteSavegame
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT
|
||||
import java.io.File
|
||||
@@ -24,9 +25,8 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
"MENU_IO_SAVE_GAME",
|
||||
"MENU_LABEL_GRAPHICS",
|
||||
"MENU_OPTIONS_CONTROLS",
|
||||
"MENU_OPTIONS_SOUND",
|
||||
"MENU_LABEL_RETURN_MAIN",
|
||||
"MENU_LABEL_DESKTOP",
|
||||
"MENU_LABEL_MAINMENU",
|
||||
"MENU_LABEL_QUIT",
|
||||
)
|
||||
private val gameMenuListHeight = DEFAULT_LINE_HEIGHT * gameMenu.size
|
||||
private val gameMenuListWidth = 400
|
||||
@@ -71,6 +71,8 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
)
|
||||
private val savingUI = UIItemSaving(this, (width - UIItemSaving.WIDTH) / 2, (height - UIItemSaving.HEIGHT) / 2)
|
||||
|
||||
private val keyConfigUI = UIKeyboardControlPanel()
|
||||
|
||||
private var oldScreen = 0
|
||||
private var screen = 0
|
||||
|
||||
@@ -92,10 +94,13 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
full.unlockTransition()
|
||||
}
|
||||
}
|
||||
4 -> {
|
||||
2 -> {
|
||||
screen = 4; gameMenuButtons.deselect()
|
||||
}
|
||||
3 -> {
|
||||
screen = 2; gameMenuButtons.deselect()
|
||||
}
|
||||
5 -> {
|
||||
4 -> {
|
||||
screen = 1; gameMenuButtons.deselect()
|
||||
}
|
||||
}
|
||||
@@ -122,7 +127,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
}
|
||||
|
||||
private val screens = arrayOf(
|
||||
gameMenuButtons, areYouSureQuitButtons, areYouSureMainMenuButtons, savingUI
|
||||
gameMenuButtons, areYouSureQuitButtons, areYouSureMainMenuButtons, savingUI, keyConfigUI
|
||||
)
|
||||
|
||||
|
||||
@@ -148,16 +153,26 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
},
|
||||
{ batch: SpriteBatch, camera: Camera ->
|
||||
savingUI.render(batch, camera)
|
||||
}
|
||||
},
|
||||
{ batch: SpriteBatch, camera: Camera ->
|
||||
keyConfigUI.render(batch, camera)
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
val yeet = screens[screen]
|
||||
if (oldScreen != screen) {
|
||||
screens[screen].show()
|
||||
if (yeet is UIItem)
|
||||
yeet.show()
|
||||
else if (yeet is UICanvas)
|
||||
yeet.show()
|
||||
oldScreen = screen
|
||||
}
|
||||
screens[screen].update(delta)
|
||||
if (yeet is UIItem)
|
||||
yeet.update(delta)
|
||||
else if (yeet is UICanvas)
|
||||
yeet.update(delta)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
@@ -115,6 +115,8 @@ class UIKeyboardControlPanel : UICanvas() {
|
||||
|
||||
) // end of keycaps
|
||||
|
||||
private val buttonReset = UIItemTextButton(this, "MENU_LABEL_RESET", kbx + 1, kby + 165, 180, true, alignment = UIItemTextButton.Companion.Alignment.LEFT)
|
||||
|
||||
private val symbolLeft = labels.get(0,2)
|
||||
private val symbolUp = labels.get(1,2)
|
||||
private val symbolRight = labels.get(2,2)
|
||||
@@ -125,11 +127,29 @@ class UIKeyboardControlPanel : UICanvas() {
|
||||
private val symbolGrapplingHook = labels.get(5,1)
|
||||
private val symbolGamemenu = labels.get(6,2)
|
||||
|
||||
private val controlPalette = UIItemControlPaletteBaloon(this, (App.scr.width - 480) / 2, kby + 199)
|
||||
private val controlPalette = UIItemControlPaletteBaloon(this, (App.scr.width - 480) / 2, kby + 219)
|
||||
|
||||
init {
|
||||
keycaps.values.forEach { addUIitem(it) }
|
||||
updateKeycaps()
|
||||
|
||||
buttonReset.clickOnceListener = { x, y, button ->
|
||||
println("reset keys!")
|
||||
resetKeyConfig()
|
||||
updateKeycaps()
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetKeyConfig() {
|
||||
App.setConfig("control_key_up", Input.Keys.E)
|
||||
App.setConfig("control_key_left", Input.Keys.S)
|
||||
App.setConfig("control_key_down", Input.Keys.D)
|
||||
App.setConfig("control_key_right", Input.Keys.F)
|
||||
App.setConfig("control_key_jump", Input.Keys.SPACE)
|
||||
App.setConfig("control_key_zoom", Input.Keys.Z)
|
||||
App.setConfig("control_key_inventory", Input.Keys.Q)
|
||||
App.setConfig("control_key_movementaux", Input.Keys.A)
|
||||
App.setConfig("control_key_gamemenu", Input.Keys.TAB)
|
||||
}
|
||||
|
||||
private fun updateKeycaps() {
|
||||
@@ -165,6 +185,8 @@ class UIKeyboardControlPanel : UICanvas() {
|
||||
}
|
||||
}
|
||||
|
||||
buttonReset.update(delta)
|
||||
|
||||
if (keycapClicked >= 0 && controlSelected < 0) {
|
||||
controlPalette.update(delta)
|
||||
}
|
||||
@@ -176,6 +198,7 @@ class UIKeyboardControlPanel : UICanvas() {
|
||||
// batch.color = fillCol
|
||||
// Toolkit.fillArea(batch, drawX, drawY, width, height)
|
||||
uiItems.forEach { it.render(batch, camera) }
|
||||
buttonReset.render(batch, camera)
|
||||
|
||||
batch.color = Color.WHITE
|
||||
|
||||
@@ -196,6 +219,16 @@ class UIKeyboardControlPanel : UICanvas() {
|
||||
updateKeycaps()
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
buttonReset.touchDown(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
buttonReset.touchUp(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
@@ -210,6 +243,8 @@ class UIKeyboardControlPanel : UICanvas() {
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +333,7 @@ class UIItemKeycap(
|
||||
|
||||
class UIItemControlPaletteBaloon(val parent: UIKeyboardControlPanel, initialX: Int, initialY: Int) : UIItem(parent, initialX, initialY) {
|
||||
override val width = 480
|
||||
override val height = 260
|
||||
override val height = 230
|
||||
override fun dispose() {}
|
||||
|
||||
private val icons = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
||||
|
||||
Reference in New Issue
Block a user