at least some of the new UIs are working

This commit is contained in:
minjaesong
2017-10-23 03:44:45 +09:00
parent 98a67c80c6
commit 77b563396e
26 changed files with 848 additions and 57 deletions

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
@@ -55,6 +56,9 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")!!)
/** UI to call (show up) while mouse is up */
open val mouseOverCall: UICanvas? = null
// kind of listener implementation
var updateListener: ((Float) -> Unit)? = null
@@ -76,9 +80,33 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
if (updateListener != null) {
updateListener!!.invoke(delta)
}
mouseOverCall?.update(delta)
if (mouseUp) {
if (mouseOverCall?.isVisible ?: false) {
mouseOverCall?.setAsOpen()
}
mouseOverCall?.updateUI(delta)
}
else {
if (mouseOverCall?.isVisible ?: false) {
mouseOverCall?.setAsClose()
}
}
}
}
open fun render(batch: SpriteBatch, camera: Camera) {
if (parentUI.isVisible) {
mouseOverCall?.render(batch, camera)
if (mouseUp) {
mouseOverCall?.renderUI(batch, camera)
}
}
}
abstract fun render(batch: SpriteBatch)
// keyboard controlled
open fun keyDown(keycode: Int): Boolean {