UIs wont FOR SURE update (more like, process events) anymore when they are not visible

This commit is contained in:
minjaesong
2017-07-25 18:34:23 +09:00
parent 33657624a6
commit 9731c8384a
4 changed files with 98 additions and 20 deletions

View File

@@ -72,15 +72,17 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
open fun update(delta: Float) {
if (updateListener != null) {
updateListener!!.invoke(delta)
if (parentUI.isVisible) {
if (updateListener != null) {
updateListener!!.invoke(delta)
}
}
}
abstract fun render(batch: SpriteBatch)
// keyboard controlled
open fun keyDown(keycode: Int): Boolean {
if (keyDownListener != null) {
if (parentUI.isVisible && keyDownListener != null) {
keyDownListener!!.invoke(keycode)
return true
}
@@ -88,7 +90,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
return false
}
open fun keyUp(keycode: Int): Boolean {
if (keyUpListener != null) {
if (parentUI.isVisible && keyUpListener != null) {
keyUpListener!!.invoke(keycode)
return true
}
@@ -98,7 +100,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
// mouse controlled
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
if (mouseMovedListener != null) {
if (parentUI.isVisible && mouseMovedListener != null) {
mouseMovedListener!!.invoke(relativeMouseX, relativeMouseY)
return true
}
@@ -106,7 +108,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
return false
}
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (touchDraggedListener != null) {
if (parentUI.isVisible && touchDraggedListener != null) {
touchDraggedListener!!.invoke(relativeMouseX, relativeMouseY, pointer)
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 {
var actionDone = false
if (touchDownListener != null) {
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
actionDone = true
}
if (parentUI.isVisible) {
if (touchDownListener != null) {
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
actionDone = true
}
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp) {
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
actionDone = true
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp) {
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
actionDone = true
}
}
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 {
clickOnceListenerFired = false
if (touchUpListener != null) {
if (parentUI.isVisible && touchUpListener != null) {
touchUpListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
return true
}
@@ -139,7 +143,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
return false
}
open fun scrolled(amount: Int): Boolean {
if (scrolledListener != null) {
if (parentUI.isVisible && scrolledListener != null) {
scrolledListener!!.invoke(amount)
return true
}

View File

@@ -30,7 +30,7 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = 0
defaultSelection = null
)
init {
@@ -39,9 +39,8 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
println("UITitleRemoConCredits srtaenirstneiotrsaeinoarst")
superMenu.setAsOpen()
this.setAsClose()
superMenu.setAsOpen()
}
}

View 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() {
}
}

View File

@@ -47,12 +47,16 @@ class UITitleRemoConRoot : UICanvas() {
//private val paneCredits = UIHandler()
private val remoConCredits = UITitleRemoConCredits(this)
private val remoConLanguage = UITitleRemoConLanguage(this)
init {
remoConLanguage.setPosition(0, menubarOffY)
remoConCredits.setPosition(0, menubarOffY)
addSubUI(remoConLanguage)
addSubUI(remoConCredits)
@@ -63,9 +67,13 @@ class UITitleRemoConRoot : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_CREDITS")].clickOnceListener = { _, _, _ ->
remoConCredits.setAsOpen()
menubar.buttons[menuLabels.indexOf("MENU_LABEL_LANGUAGE")].clickOnceListener = { _, _, _ ->
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) }
}