mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
UIs wont FOR SURE update (more like, process events) anymore when they are not visible
This commit is contained in:
@@ -72,15 +72,17 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
|
|
||||||
|
|
||||||
open fun update(delta: Float) {
|
open fun update(delta: Float) {
|
||||||
if (updateListener != null) {
|
if (parentUI.isVisible) {
|
||||||
updateListener!!.invoke(delta)
|
if (updateListener != null) {
|
||||||
|
updateListener!!.invoke(delta)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
abstract fun render(batch: SpriteBatch)
|
abstract fun render(batch: SpriteBatch)
|
||||||
|
|
||||||
// keyboard controlled
|
// keyboard controlled
|
||||||
open fun keyDown(keycode: Int): Boolean {
|
open fun keyDown(keycode: Int): Boolean {
|
||||||
if (keyDownListener != null) {
|
if (parentUI.isVisible && keyDownListener != null) {
|
||||||
keyDownListener!!.invoke(keycode)
|
keyDownListener!!.invoke(keycode)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -88,7 +90,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
open fun keyUp(keycode: Int): Boolean {
|
open fun keyUp(keycode: Int): Boolean {
|
||||||
if (keyUpListener != null) {
|
if (parentUI.isVisible && keyUpListener != null) {
|
||||||
keyUpListener!!.invoke(keycode)
|
keyUpListener!!.invoke(keycode)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -98,7 +100,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
|
|
||||||
// mouse controlled
|
// mouse controlled
|
||||||
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
|
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
|
||||||
if (mouseMovedListener != null) {
|
if (parentUI.isVisible && mouseMovedListener != null) {
|
||||||
mouseMovedListener!!.invoke(relativeMouseX, relativeMouseY)
|
mouseMovedListener!!.invoke(relativeMouseX, relativeMouseY)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -106,7 +108,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||||
if (touchDraggedListener != null) {
|
if (parentUI.isVisible && touchDraggedListener != null) {
|
||||||
touchDraggedListener!!.invoke(relativeMouseX, relativeMouseY, pointer)
|
touchDraggedListener!!.invoke(relativeMouseX, relativeMouseY, pointer)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -116,14 +118,16 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
var actionDone = false
|
var actionDone = false
|
||||||
|
|
||||||
if (touchDownListener != null) {
|
if (parentUI.isVisible) {
|
||||||
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
if (touchDownListener != null) {
|
||||||
actionDone = true
|
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||||
}
|
actionDone = true
|
||||||
|
}
|
||||||
|
|
||||||
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp) {
|
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp) {
|
||||||
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
|
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
|
||||||
actionDone = true
|
actionDone = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionDone
|
return actionDone
|
||||||
@@ -131,7 +135,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
clickOnceListenerFired = false
|
clickOnceListenerFired = false
|
||||||
|
|
||||||
if (touchUpListener != null) {
|
if (parentUI.isVisible && touchUpListener != null) {
|
||||||
touchUpListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
touchUpListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -139,7 +143,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
open fun scrolled(amount: Int): Boolean {
|
open fun scrolled(amount: Int): Boolean {
|
||||||
if (scrolledListener != null) {
|
if (parentUI.isVisible && scrolledListener != null) {
|
||||||
scrolledListener!!.invoke(amount)
|
scrolledListener!!.invoke(amount)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
|
|||||||
highlightBackCol = Color(0),
|
highlightBackCol = Color(0),
|
||||||
backgroundCol = Color(0),
|
backgroundCol = Color(0),
|
||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = 0
|
defaultSelection = null
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -39,9 +39,8 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
|
|||||||
|
|
||||||
// attach listeners
|
// attach listeners
|
||||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
|
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
|
||||||
println("UITitleRemoConCredits srtaenirstneiotrsaeinoarst")
|
|
||||||
superMenu.setAsOpen()
|
|
||||||
this.setAsClose()
|
this.setAsClose()
|
||||||
|
superMenu.setAsOpen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
67
src/net/torvald/terrarum/ui/UITitleRemoConLanguage.kt
Normal file
67
src/net/torvald/terrarum/ui/UITitleRemoConLanguage.kt
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Camera
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import net.torvald.terrarum.gameactors.Second
|
||||||
|
|
||||||
|
class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
|
||||||
|
|
||||||
|
val menuLabels = arrayOf(
|
||||||
|
"MENU_LABEL_RETURN"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
override var width: Int = UITitleRemoConRoot.remoConWidth
|
||||||
|
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
|
||||||
|
override var openCloseTime: Second = 0f
|
||||||
|
|
||||||
|
|
||||||
|
private val menubar = UIItemTextButtonList(
|
||||||
|
this,
|
||||||
|
menuLabels,
|
||||||
|
this.width, this.height,
|
||||||
|
textAreaWidth = this.width,
|
||||||
|
readFromLang = true,
|
||||||
|
activeBackCol = Color(0),
|
||||||
|
highlightBackCol = Color(0),
|
||||||
|
backgroundCol = Color(0),
|
||||||
|
inactiveCol = Color.WHITE,
|
||||||
|
defaultSelection = null
|
||||||
|
)
|
||||||
|
|
||||||
|
init {
|
||||||
|
uiItems.add(menubar)
|
||||||
|
|
||||||
|
|
||||||
|
// attach listeners
|
||||||
|
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
|
||||||
|
this.setAsClose()
|
||||||
|
superMenu.setAsOpen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateUI(delta: Float) {
|
||||||
|
menubar.update(delta)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
|
menubar.render(batch)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doOpening(delta: Float) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doClosing(delta: Float) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun endOpening(delta: Float) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun endClosing(delta: Float) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -47,12 +47,16 @@ class UITitleRemoConRoot : UICanvas() {
|
|||||||
//private val paneCredits = UIHandler()
|
//private val paneCredits = UIHandler()
|
||||||
private val remoConCredits = UITitleRemoConCredits(this)
|
private val remoConCredits = UITitleRemoConCredits(this)
|
||||||
|
|
||||||
|
private val remoConLanguage = UITitleRemoConLanguage(this)
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
remoConLanguage.setPosition(0, menubarOffY)
|
||||||
remoConCredits.setPosition(0, menubarOffY)
|
remoConCredits.setPosition(0, menubarOffY)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
addSubUI(remoConLanguage)
|
||||||
addSubUI(remoConCredits)
|
addSubUI(remoConCredits)
|
||||||
|
|
||||||
|
|
||||||
@@ -63,9 +67,13 @@ class UITitleRemoConRoot : UICanvas() {
|
|||||||
|
|
||||||
|
|
||||||
// attach listeners
|
// attach listeners
|
||||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_CREDITS")].clickOnceListener = { _, _, _ ->
|
menubar.buttons[menuLabels.indexOf("MENU_LABEL_LANGUAGE")].clickOnceListener = { _, _, _ ->
|
||||||
remoConCredits.setAsOpen()
|
|
||||||
this.setAsClose()
|
this.setAsClose()
|
||||||
|
remoConLanguage.setAsOpen()
|
||||||
|
}
|
||||||
|
menubar.buttons[menuLabels.indexOf("MENU_LABEL_CREDITS")].clickOnceListener = { _, _, _ ->
|
||||||
|
this.setAsClose()
|
||||||
|
remoConCredits.setAsOpen()
|
||||||
}
|
}
|
||||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> System.exit(0) }
|
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> System.exit(0) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user