mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
@@ -18,15 +18,17 @@ import org.newdawn.slick.Input
|
||||
*/
|
||||
object GameController {
|
||||
|
||||
private val ingame = Terrarum.ingame!!
|
||||
|
||||
// these four values can also be accessed with GameContainer.<varname>
|
||||
// e.g. gc.mouseTileX
|
||||
|
||||
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
|
||||
val mouseX: Float
|
||||
get() = (MapCamera.x + Terrarum.appgc.input.mouseX / (Terrarum.ingame?.screenZoom ?: 1f))
|
||||
get() = (MapCamera.x + Terrarum.appgc.input.mouseX / (ingame.screenZoom ?: 1f))
|
||||
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise)*/
|
||||
val mouseY: Float
|
||||
get() = (MapCamera.y + Terrarum.appgc.input.mouseY / (Terrarum.ingame?.screenZoom ?: 1f))
|
||||
get() = (MapCamera.y + Terrarum.appgc.input.mouseY / (ingame.screenZoom ?: 1f))
|
||||
/** currently pointing tile coordinate */
|
||||
val mouseTileX: Int
|
||||
get() = (mouseX / FeaturesDrawer.TILE_SIZE).floorInt()
|
||||
@@ -35,81 +37,97 @@ object GameController {
|
||||
get() = (mouseY / FeaturesDrawer.TILE_SIZE).floorInt()
|
||||
|
||||
fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
if (Terrarum.ingame != null) {
|
||||
val ingame = Terrarum.ingame!!
|
||||
|
||||
|
||||
// actor process input
|
||||
if (!ingame.consoleHandler.isTakingControl) {
|
||||
if (ingame.canPlayerControl) {
|
||||
ingame.actorContainer.forEach {
|
||||
if (it is Controllable) {
|
||||
// disable control of actor if the actor is riding something?
|
||||
if ((it as ActorHumanoid).vehicleRiding != null) {
|
||||
it.vehicleRiding!!.processInput(gc, delta, input)
|
||||
}
|
||||
else {
|
||||
it.processInput(gc, delta, input)
|
||||
}
|
||||
// actor process input
|
||||
if (!ingame.consoleHandler.isTakingControl) {
|
||||
if (ingame.canPlayerControl) {
|
||||
ingame.actorContainer.forEach {
|
||||
if (it is Controllable) {
|
||||
// disable control of actor if the actor is riding something?
|
||||
if ((it as ActorHumanoid).vehicleRiding != null) {
|
||||
it.vehicleRiding!!.processInput(gc, delta, input)
|
||||
}
|
||||
else {
|
||||
it.processInput(gc, delta, input)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ingame.uiContainer.forEach {
|
||||
it.processInput(gc, delta, input)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ingame.consoleHandler.processInput(gc, delta, input)
|
||||
ingame.uiContainer.forEach {
|
||||
it.processInput(gc, delta, input)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ingame.consoleHandler.processInput(gc, delta, input)
|
||||
}
|
||||
|
||||
|
||||
///////////////////
|
||||
// MOUSE CONTROL //
|
||||
///////////////////
|
||||
///////////////////
|
||||
// MOUSE CONTROL //
|
||||
///////////////////
|
||||
|
||||
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
|
||||
if (ingame.player != null && ingame.canPlayerControl) {
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP]
|
||||
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
|
||||
if (ingame.player != null && ingame.canPlayerControl) {
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP]
|
||||
|
||||
if (itemOnGrip != null) {
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
|
||||
ingame.player!!.consumePrimary(itemOnGrip)
|
||||
}
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
ingame.player!!.consumeSecondary(itemOnGrip)
|
||||
}
|
||||
if (itemOnGrip != null) {
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
|
||||
ingame.player!!.consumePrimary(itemOnGrip)
|
||||
}
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
ingame.player!!.consumeSecondary(itemOnGrip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// GAMEPAD CONTROL //
|
||||
/////////////////////
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// GAMEPAD CONTROL //
|
||||
/////////////////////
|
||||
}
|
||||
|
||||
fun keyPressed(key: Int, c: Char) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (ingame.canPlayerControl) {
|
||||
ingame.player?.keyPressed(key, c)
|
||||
}
|
||||
|
||||
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|
||||
|| key == Terrarum.getConfigInt("keyquicksel")) {
|
||||
ingame.uiPieMenu.setAsOpen()
|
||||
ingame.uiQuickBar.setAsClose()
|
||||
}
|
||||
|
||||
ingame.uiContainer.forEach { it.keyPressed(key, c) } // for KeyboardControlled UIcanvases
|
||||
}
|
||||
|
||||
fun keyReleased(key: Int, c: Char) {
|
||||
|
||||
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|
||||
|| key == Terrarum.getConfigInt("keyquicksel")) {
|
||||
ingame.uiPieMenu.setAsClose()
|
||||
ingame.uiQuickBar.setAsOpen()
|
||||
}
|
||||
|
||||
ingame.uiContainer.forEach { it.keyReleased(key, c) } // for KeyboardControlled UIcanvases
|
||||
}
|
||||
|
||||
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||
|
||||
ingame.uiContainer.forEach { it.mouseMoved(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases
|
||||
}
|
||||
|
||||
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||
|
||||
ingame.uiContainer.forEach { it.mouseDragged(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases
|
||||
}
|
||||
|
||||
fun mousePressed(button: Int, x: Int, y: Int) {
|
||||
|
||||
ingame.uiContainer.forEach { it.mousePressed(button, x, y) } // for MouseControlled UIcanvases
|
||||
}
|
||||
|
||||
fun mouseReleased(button: Int, x: Int, y: Int) {
|
||||
@@ -121,26 +139,29 @@ object GameController {
|
||||
|
||||
if (itemOnGrip != null) {
|
||||
if (button == Terrarum.getConfigInt("mousePrimary")) {
|
||||
itemOnGrip.endPrimaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||
itemOnGrip.endPrimaryUse(Terrarum.appgc, Terrarum.delta)
|
||||
}
|
||||
if (button == Terrarum.getConfigInt("mouseSecondary")) {
|
||||
itemOnGrip.endSecondaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||
itemOnGrip.endSecondaryUse(Terrarum.appgc, Terrarum.delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ingame.uiContainer.forEach { it.mouseReleased(button, x, y) } // for MouseControlled UIcanvases
|
||||
}
|
||||
}
|
||||
|
||||
fun mouseWheelMoved(change: Int) {
|
||||
|
||||
ingame.uiContainer.forEach { it.mouseWheelMoved(change) } // for MouseControlled UIcanvases
|
||||
}
|
||||
|
||||
fun controllerButtonPressed(controller: Int, button: Int) {
|
||||
|
||||
ingame.uiContainer.forEach { it.controllerButtonPressed(controller, button) } // for GamepadControlled UIcanvases
|
||||
}
|
||||
|
||||
fun controllerButtonReleased(controller: Int, button: Int) {
|
||||
|
||||
ingame.uiContainer.forEach { it.controllerButtonReleased(controller, button) } // for GamepadControlled UIcanvases
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user