From bee939877b05c1ad9fc69e3dabbe597c3ba7e506 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 26 Sep 2023 13:15:48 +0900 Subject: [PATCH] fix: barehand action is not draggable --- .../gamecontroller/IngameController.kt | 18 +++++++++++------- .../terrarum/modulebasegame/TerrarumIngame.kt | 7 +------ .../torvald/terrarum/weather/WeatherMixer.kt | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index 6806b06b1..5eee7a261 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -117,7 +117,8 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() { GameItem.Category.TOOL, GameItem.Category.WALL, GameItem.Category.WIRE, - GameItem.Category.BLOCK + GameItem.Category.BLOCK, + null // empty hands won't prevent dragging for barehand action ) fun update() { @@ -129,25 +130,28 @@ class IngameController(val terrarumIngame: TerrarumIngame) : 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 (!terrarumIngame.paused) { + val actor = terrarumIngame.actorNowPlaying + val itemOnGrip = terrarumIngame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP) // fire world click events; the event is defined as Ingame's (or any others') WorldClick event // DON'T DO UI-FILTERING HERE; they're already done on ingame.worldPrimaryClickStart // also, some UIs should NOT affect item usage (e.g. quickslot) and ingame's uiOpened property is doing // the very job. - if (terrarumIngame.actorNowPlaying != null && Terrarum.mouseDown && !worldPrimaryClickLatched) { - terrarumIngame.worldPrimaryClickStart(terrarumIngame.actorNowPlaying!!, App.UPDATE_RATE) + if (actor != null && Terrarum.mouseDown && !worldPrimaryClickLatched) { + terrarumIngame.worldPrimaryClickStart(actor, App.UPDATE_RATE) worldPrimaryClickLatched = true } - if (Gdx.input.isButtonPressed(App.getConfigInt("config_mousesecondary"))) { - terrarumIngame.worldSecondaryClickStart(terrarumIngame.actorNowPlaying!!, App.UPDATE_RATE) + if (actor != null && Gdx.input.isButtonPressed(App.getConfigInt("config_mousesecondary"))) { + terrarumIngame.worldSecondaryClickStart(actor, App.UPDATE_RATE) } // unlatch when: // - not clicking anymore // - using any item that is not fixture (blocks, picks) - if (!Terrarum.mouseDown || - inventoryCategoryAllowClickAndDrag.contains(ItemCodex[terrarumIngame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)]?.inventoryCategory)) { + // DON'T unlatch when: + // - performing barehand action + if (!Terrarum.mouseDown || inventoryCategoryAllowClickAndDrag.contains(ItemCodex[itemOnGrip]?.inventoryCategory)) { worldPrimaryClickLatched = false } diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 63443bd59..3a68e7907 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -632,12 +632,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { val itemOnGrip = ItemCodex[(actor as Pocketed).inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)] // bring up the UIs of the fixtures (e.g. crafting menu from a crafting table) - // TODO actorsUnderMouse: support ROUNDWORLD - val actorsUnderMouse: List = getActorsAt(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance() - if (actorsUnderMouse.size > 1) { - App.printdbgerr(this, "Multiple fixtures at world coord ${Terrarum.mouseX}, ${Terrarum.mouseY}") - } - //////////////////////////////// // #1. If ~~there is no UI under and~~ I'm holding an item, use it @@ -659,6 +653,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { override fun worldPrimaryClickEnd(actor: ActorWithBody, delta: Float) { val canPerformBarehandAction = actor.scale * actor.baseHitboxH >= (actor.actorValue.getAsDouble(AVKey.BAREHAND_MINHEIGHT) ?: 4294967296.0) + val itemOnGrip = (actor as Pocketed).inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP) ItemCodex[itemOnGrip]?.endPrimaryUse(actor, delta) diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index 313f7b328..c0135b1f9 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -562,7 +562,7 @@ internal object WeatherMixer : RNGConsumer { batch.color = Color.WHITE } - private val RECIPROCAL_OF_APPARENT_SOLAR_Y_AT_90DEG = 0.0000085 + private val RECIPROCAL_OF_APPARENT_SOLAR_Y_AT_90DEG = 0.0000077 /** * Mathematical model: https://www.desmos.com/calculator/8dsgigfoys