simplified a structure of UIs a bit

This commit is contained in:
minjaesong
2017-07-16 23:15:32 +09:00
parent 942971f456
commit 485cbe1206
29 changed files with 321 additions and 371 deletions

View File

@@ -28,19 +28,99 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
open val mousePushed: Boolean
get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")!!)
abstract fun update(delta: Float)
// kind of listener implementation
var updateAction: ((Float) -> Unit)? = null
var keyDownAction: ((Int) -> Unit)? = null
var keyUpAction: ((Int) -> Unit)? = null
var mouseMovedAction: ((Int, Int) -> Unit)? = null
var touchDraggedAction: ((Int, Int, Int) -> Unit)? = null
var touchDownAction: ((Int, Int, Int, Int) -> Unit)? = null
var touchUpAction: ((Int, Int, Int, Int) -> Unit)? = null
var scrolledAction: ((Int) -> Unit)? = null
var clickOnceAction: ((Int, Int, Int) -> Unit)? = null
var clickOnceActionEngaged = false
open fun update(delta: Float) {
if (updateAction != null) {
updateAction!!.invoke(delta)
}
}
abstract fun render(batch: SpriteBatch)
// keyboard controlled
abstract fun keyDown(keycode: Int): Boolean
abstract fun keyUp(keycode: Int): Boolean
open fun keyDown(keycode: Int): Boolean {
if (keyDownAction != null) {
keyDownAction!!.invoke(keycode)
return true
}
return false
}
open fun keyUp(keycode: Int): Boolean {
if (keyUpAction != null) {
keyUpAction!!.invoke(keycode)
return true
}
return false
}
// mouse controlled
abstract fun mouseMoved(screenX: Int, screenY: Int): Boolean
abstract fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean
abstract fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean
abstract fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean
abstract fun scrolled(amount: Int): Boolean
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
if (mouseMovedAction != null) {
mouseMovedAction!!.invoke(relativeMouseX, relativeMouseY)
return true
}
return false
}
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (touchDraggedAction != null) {
touchDraggedAction!!.invoke(relativeMouseX, relativeMouseY, pointer)
return true
}
return false
}
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
var actionDone = false
if (touchDownAction != null) {
touchDownAction!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
actionDone = true
}
if (!clickOnceActionEngaged && mouseUp) {
clickOnceAction!!.invoke(relativeMouseX, relativeMouseY, button)
actionDone = true
}
return actionDone
}
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
clickOnceActionEngaged = false
if (touchUpAction != null) {
touchUpAction!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
return true
}
return false
}
open fun scrolled(amount: Int): Boolean {
if (scrolledAction != null) {
scrolledAction!!.invoke(amount)
return true
}
return false
}
abstract fun dispose()
}