From: fredboy Date: Fri, 10 May 2024 20:53:10 +0000 (+0700) Subject: Bug fixes X-Git-Tag: alpha0.9.1~1 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=10751913ec4e5613dd5934711e2332bbc93b81e0;p=cavedroid.git Bug fixes --- diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt index 8f0f494..b39ee74 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt @@ -3,12 +3,14 @@ package ru.deadsoftware.cavedroid.game.input.handler.keyboard import ru.deadsoftware.cavedroid.MainConfig import ru.deadsoftware.cavedroid.game.GameSaver import ru.deadsoftware.cavedroid.game.GameScope +import ru.deadsoftware.cavedroid.game.GameUiWindow import ru.deadsoftware.cavedroid.game.input.IGameInputHandler import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey import ru.deadsoftware.cavedroid.game.mobs.MobsController import ru.deadsoftware.cavedroid.game.objects.drop.DropController import ru.deadsoftware.cavedroid.game.objects.container.ContainerController +import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager import ru.deadsoftware.cavedroid.game.world.GameWorld import javax.inject.Inject @@ -19,6 +21,7 @@ class PauseGameKeyboardInputHandler @Inject constructor( private val mobsController: MobsController, private val gameWorld: GameWorld, private val containerController: ContainerController, + private val gameWindowsManager: GameWindowsManager, ) : IGameInputHandler { override fun checkConditions(action: KeyboardInputAction): Boolean { @@ -26,6 +29,11 @@ class PauseGameKeyboardInputHandler @Inject constructor( } override fun handle(action: KeyboardInputAction) { + if (gameWindowsManager.getCurrentWindow() != GameUiWindow.NONE) { + gameWindowsManager.closeWindow() + return + } + GameSaver.save(mainConfig, dropController, mobsController, containerController, gameWorld) mainConfig.caveGame.quitGame() } diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt index 4aaff27..f7fa6a5 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt @@ -59,13 +59,13 @@ abstract class AbstractInventoryItemsMouseInputHandler( if (action.actionKey.pointer == window.selectItemPointer) { window.onLeftCLick(items, gameItemsHolder, index, action.actionKey.pointer) } else { - window.onRightClick(items, index) + window.onRightClick(items, gameItemsHolder, index) } } } else if (action.actionKey is MouseInputActionKey.Left) { window.onLeftCLick(items, gameItemsHolder, index) } else { - window.onRightClick(items, index) + window.onRightClick(items, gameItemsHolder, index) } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CursorMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CursorMouseInputHandler.kt index 9093680..585a5ab 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CursorMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CursorMouseInputHandler.kt @@ -56,6 +56,7 @@ class CursorMouseInputHandler @Inject constructor( private fun handleWalkTouch() { player.cursorX = player.mapX + player.direction.basis player.cursorY = player.upperMapY + player.headRotation = 0f for (i in 1..2) { if (gameWorld.isCurrentBlockAutoselectable()) { diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt index f847f7d..3cd406b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt @@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.ShapeRenderer import ru.deadsoftware.cavedroid.game.GameItemsHolder -import ru.deadsoftware.cavedroid.game.mobs.player.Inventory import ru.deadsoftware.cavedroid.misc.Assets import ru.deadsoftware.cavedroid.misc.utils.drawSprite import ru.deadsoftware.cavedroid.misc.utils.drawString @@ -28,19 +27,27 @@ class InventoryItem @JvmOverloads constructor( } @Transient - lateinit var item: Item - private set + private var _item: Item? = null + + var item: Item + get() { + requireNotNull(_item) { "_item is null" } + return _item.takeIf { amount > 0 } ?: throw IllegalArgumentException("Accessing item with zero amount") + } + private set (value) { + _item = value + } @JvmOverloads - constructor(_item: Item, amount: Int = 1) : this(_item.params.key, amount) { - item = _item + constructor(item: Item, amount: Int = 1) : this(item.params.key, amount) { + _item = item } fun init(gameItemsHolder: GameItemsHolder) { - if (this::item.isInitialized) { + if (_item != null) { return } - item = gameItemsHolder.getItem(itemKey) + _item = gameItemsHolder.getItem(itemKey) } @JvmOverloads diff --git a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindow.kt b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindow.kt index c26bda9..ed15bac 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindow.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindow.kt @@ -1,5 +1,6 @@ package ru.deadsoftware.cavedroid.game.ui.windows.inventory +import com.badlogic.gdx.math.MathUtils import ru.deadsoftware.cavedroid.game.GameItemsHolder import ru.deadsoftware.cavedroid.game.GameUiWindow import ru.deadsoftware.cavedroid.game.model.item.InventoryItem @@ -46,14 +47,25 @@ abstract class AbstractInventoryWindow { selectItemPointer = pointer } - fun onRightClick(items: MutableList, index: Int) { + fun onRightClick(items: MutableList, gameItemsHolder: GameItemsHolder, index: Int) { val clickedItem = items[index] val selectedItem = selectedItem - ?.takeIf { - !clickedItem.isNoneOrNull() || clickedItem.item.isNone() || - it.item == items[index].item && items[index].amount + 1 < it.item.params.maxStack + + if (selectedItem.isNoneOrNull() && !clickedItem.isNoneOrNull()) { + val half = InventoryItem(clickedItem.item, MathUtils.ceil(clickedItem.amount.toFloat() / 2f)) + this.selectedItem = half + clickedItem.subtract(half.amount) + if (clickedItem.amount == 0) { + items[index] = gameItemsHolder.fallbackItem.toInventoryItem() } - ?: return + return + } + + if (selectedItem == null || + (!clickedItem.isNoneOrNull() && selectedItem.item != clickedItem.item) || + !clickedItem.canBeAdded()) { + return + } val newItem = selectedItem.item.toInventoryItem( (clickedItem.takeIf { !it.item.isNone() }?.amount ?: 0) + 1