mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
no more context fuckups on apploader
This commit is contained in:
@@ -10,14 +10,14 @@ import net.torvald.terrarum.controller.TerrarumController
|
||||
import net.torvald.terrarum.floorInt
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
|
||||
|
||||
val hasGamepad: Boolean
|
||||
@@ -29,10 +29,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
|
||||
/** 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() = WorldCamera.x + Gdx.input.x / (ingame.screenZoom)
|
||||
get() = WorldCamera.x + Gdx.input.x / (terrarumIngame.screenZoom)
|
||||
/** 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() = WorldCamera.y + Gdx.input.y / (ingame.screenZoom)
|
||||
get() = WorldCamera.y + Gdx.input.y / (terrarumIngame.screenZoom)
|
||||
/** currently pointing tile coordinate */
|
||||
val mouseTileX: Int
|
||||
get() = (mouseX / CreateTileAtlas.TILE_SIZE).floorInt()
|
||||
@@ -54,14 +54,14 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
|
||||
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
|
||||
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
|
||||
if (ingame.canPlayerControl) {
|
||||
if (terrarumIngame.canPlayerControl) {
|
||||
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
||||
if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
|
||||
if (
|
||||
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) ||
|
||||
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
|
||||
ingame.worldPrimaryClickStart(AppLoader.UPDATE_RATE.toFloat())
|
||||
terrarumIngame.worldPrimaryClickStart(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
/*if Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldSecondaryClickStart(AppLoader.UPDATE_RATE.toFloat())
|
||||
@@ -79,35 +79,35 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
|
||||
if (ingame.canPlayerControl) {
|
||||
ingame.actorNowPlaying?.keyDown(keycode)
|
||||
if (terrarumIngame.canPlayerControl) {
|
||||
terrarumIngame.actorNowPlaying?.keyDown(keycode)
|
||||
|
||||
// quickslot by number keys
|
||||
val quickslotKeys = AppLoader.getConfigIntArray("keyquickslots")
|
||||
if (keycode in quickslotKeys) {
|
||||
ingame.actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, quickslotKeys.indexOf(keycode))
|
||||
terrarumIngame.actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, quickslotKeys.indexOf(keycode))
|
||||
}
|
||||
|
||||
// pie menu
|
||||
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|
||||
|| keycode == AppLoader.getConfigInt("keyquicksel")) {
|
||||
ingame.uiPieMenu.setAsOpen()
|
||||
ingame.uiQuickBar.setAsClose()
|
||||
terrarumIngame.uiPieMenu.setAsOpen()
|
||||
terrarumIngame.uiQuickBar.setAsClose()
|
||||
}
|
||||
}
|
||||
|
||||
ingame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases
|
||||
terrarumIngame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases
|
||||
|
||||
// Debug UIs
|
||||
if (keycode == Input.Keys.GRAVE) {
|
||||
ingame.consoleHandler.toggleOpening()
|
||||
terrarumIngame.consoleHandler.toggleOpening()
|
||||
}
|
||||
|
||||
|
||||
// screenshot key
|
||||
if (keycode == Input.Keys.F12 && !f12Down) {
|
||||
AppLoader.requestScreenshot()
|
||||
ingame.sendNotification("Screenshot taken")
|
||||
terrarumIngame.sendNotification("Screenshot taken")
|
||||
f12Down = true
|
||||
println("Screenshot taken.")
|
||||
}
|
||||
@@ -118,11 +118,11 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
override fun keyUp(keycode: Int): Boolean {
|
||||
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|
||||
|| keycode == AppLoader.getConfigInt("keyquicksel")) {
|
||||
ingame.uiPieMenu.setAsClose()
|
||||
ingame.uiQuickBar.setAsOpen()
|
||||
terrarumIngame.uiPieMenu.setAsClose()
|
||||
terrarumIngame.uiQuickBar.setAsOpen()
|
||||
}
|
||||
|
||||
ingame.uiContainer.forEach { it.keyUp(keycode) } // for KeyboardControlled UIcanvases
|
||||
terrarumIngame.uiContainer.forEach { it.keyUp(keycode) } // for KeyboardControlled UIcanvases
|
||||
|
||||
|
||||
// screenshot key
|
||||
@@ -133,25 +133,25 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
}
|
||||
|
||||
override fun keyTyped(character: Char): Boolean {
|
||||
ingame.uiContainer.forEach { if (it.isVisible) it.keyTyped(character) }
|
||||
terrarumIngame.uiContainer.forEach { if (it.isVisible) it.keyTyped(character) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
|
||||
ingame.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
|
||||
terrarumIngame.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
|
||||
if (ingame.canPlayerControl) {
|
||||
if (terrarumIngame.canPlayerControl) {
|
||||
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
||||
if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
|
||||
if (
|
||||
button == AppLoader.getConfigInt("mouseprimary") ||
|
||||
button == AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldPrimaryClickEnd(AppLoader.UPDATE_RATE.toFloat())
|
||||
terrarumIngame.worldPrimaryClickEnd(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
/*if (button == AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldSecondaryClickEnd(AppLoader.UPDATE_RATE.toFloat())
|
||||
@@ -160,33 +160,33 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
}
|
||||
|
||||
|
||||
ingame.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
|
||||
terrarumIngame.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun scrolled(amount: Int): Boolean {
|
||||
if (ingame.canPlayerControl) {
|
||||
if (terrarumIngame.canPlayerControl) {
|
||||
// quickslot by wheel
|
||||
if (ingame.actorNowPlaying != null) {
|
||||
ingame.actorNowPlaying!!.actorValue.set(
|
||||
if (terrarumIngame.actorNowPlaying != null) {
|
||||
terrarumIngame.actorNowPlaying!!.actorValue.set(
|
||||
AVKey.__PLAYER_QUICKSLOTSEL,
|
||||
(ingame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amount) fmod ingame.actorNowPlaying!!.inventory.quickSlot.size
|
||||
(terrarumIngame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amount) fmod terrarumIngame.actorNowPlaying!!.inventory.quickSlot.size
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ingame.uiContainer.forEach { it.scrolled(amount) }
|
||||
terrarumIngame.uiContainer.forEach { it.scrolled(amount) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
ingame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
|
||||
terrarumIngame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
ingame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
|
||||
terrarumIngame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user