mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
UI testing env and working text buttons
Former-commit-id: b8fd27c7f71f9bc8da259ae132badcbc9ce117ac
This commit is contained in:
@@ -1,32 +1,48 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gamecontroller.mouseX
|
||||
import net.torvald.terrarum.gamecontroller.mouseY
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
interface UIItem {
|
||||
abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UIHandler!
|
||||
|
||||
// X/Y Position relative to the containing canvas
|
||||
var posX: Int
|
||||
var posY: Int
|
||||
abstract var posX: Int
|
||||
abstract var posY: Int
|
||||
abstract val width: Int
|
||||
abstract val height: Int
|
||||
|
||||
fun update(gc: GameContainer, delta: Int)
|
||||
fun render(gc: GameContainer, g: Graphics)
|
||||
protected val relativeMouseX: Int
|
||||
get() = (Terrarum.appgc.mouseX - (parentUI.handler?.posX ?: 0) - this.posX).roundInt()
|
||||
protected val relativeMouseY: Int
|
||||
get() = (Terrarum.appgc.mouseY - (parentUI.handler?.posY ?: 0) - this.posY).roundInt()
|
||||
|
||||
val mouseUp: Boolean
|
||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||
val mousePushed: Boolean
|
||||
get() = mouseUp && Terrarum.appgc.input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")!!)
|
||||
|
||||
abstract fun update(gc: GameContainer, delta: Int)
|
||||
abstract fun render(gc: GameContainer, g: Graphics)
|
||||
|
||||
// keyboard controlled
|
||||
fun keyPressed(key: Int, c: Char)
|
||||
fun keyReleased(key: Int, c: Char)
|
||||
abstract fun keyPressed(key: Int, c: Char)
|
||||
abstract fun keyReleased(key: Int, c: Char)
|
||||
|
||||
// mouse controlled
|
||||
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
fun mousePressed(button: Int, x: Int, y: Int)
|
||||
fun mouseReleased(button: Int, x: Int, y: Int)
|
||||
fun mouseWheelMoved(change: Int)
|
||||
abstract fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
abstract fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
abstract fun mousePressed(button: Int, x: Int, y: Int)
|
||||
abstract fun mouseReleased(button: Int, x: Int, y: Int)
|
||||
abstract fun mouseWheelMoved(change: Int)
|
||||
|
||||
// gamepad controlled
|
||||
fun controllerButtonPressed(controller: Int, button: Int)
|
||||
fun controllerButtonReleased(controller: Int, button: Int)
|
||||
abstract fun controllerButtonPressed(controller: Int, button: Int)
|
||||
abstract fun controllerButtonReleased(controller: Int, button: Int)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user