From 3d972278cf3a54b6a7b574690ca4b41577464dce Mon Sep 17 00:00:00 2001 From: fredboy Date: Sat, 11 May 2024 00:03:51 +0700 Subject: [PATCH] Refactor window controls --- .../cavedroid/game/GamePhysics.java | 2 +- ...AbstractInventoryItemsMouseInputHandler.kt | 104 +++++++++++++++++ ...lectChestInventoryItemMouseInputHandler.kt | 77 ++----------- ...tCraftingInventoryItemMouseInputHandler.kt | 101 ++++------------- ...ctFurnaceInventoryItemMouseInputHandler.kt | 105 +++--------------- ...tSurvivalInventoryItemMouseInputHandler.kt | 99 +++-------------- .../cavedroid/game/mobs/player/Inventory.kt | 12 +- .../game/model/item/InventoryItem.kt | 9 +- .../game/ui/windows/GameWindowsManager.kt | 20 +--- .../inventory/AbstractInventoryWindow.kt | 34 ++++-- .../AbstractInventoryWindowWithCraftGrid.kt | 24 ++++ .../inventory/CraftingInventoryWindow.kt | 9 +- .../inventory/SurvivalInventoryWindow.kt | 9 +- 13 files changed, 245 insertions(+), 360 deletions(-) create mode 100644 core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt create mode 100644 core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindowWithCraftGrid.kt diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java index aebf8eb..d9bf21f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java @@ -118,7 +118,7 @@ public class GamePhysics { private Rectangle getShiftedMagnetingPlayerRect(Drop drop) { final Player player = mMobsController.getPlayer(); - if (!player.inventory.canPickItem(drop.getItem())) { + if (!player.inventory.canPickItem(drop)) { return null; } 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 new file mode 100644 index 0000000..4aaff27 --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt @@ -0,0 +1,104 @@ +package ru.deadsoftware.cavedroid.game.input.handler.mouse + +import com.badlogic.gdx.graphics.g2d.TextureRegion +import ru.deadsoftware.cavedroid.game.GameItemsHolder +import ru.deadsoftware.cavedroid.game.GameUiWindow +import ru.deadsoftware.cavedroid.game.input.IGameInputHandler +import ru.deadsoftware.cavedroid.game.input.action.MouseInputAction +import ru.deadsoftware.cavedroid.game.input.action.keys.MouseInputActionKey +import ru.deadsoftware.cavedroid.game.input.isInsideWindow +import ru.deadsoftware.cavedroid.game.model.item.InventoryItem +import ru.deadsoftware.cavedroid.game.model.item.InventoryItem.Companion.isNoneOrNull +import ru.deadsoftware.cavedroid.game.objects.container.Furnace +import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager +import ru.deadsoftware.cavedroid.game.ui.windows.inventory.AbstractInventoryWindow +import ru.deadsoftware.cavedroid.game.ui.windows.inventory.AbstractInventoryWindowWithCraftGrid + +abstract class AbstractInventoryItemsMouseInputHandler( + private val gameItemsHolder: GameItemsHolder, + private val gameWindowsManager: GameWindowsManager, + private val windowType: GameUiWindow, +) : IGameInputHandler { + + protected abstract val windowTexture: TextureRegion + + override fun checkConditions(action: MouseInputAction): Boolean { + return gameWindowsManager.getCurrentWindow() == windowType && + isInsideWindow(action, windowTexture) && + (action.actionKey is MouseInputActionKey.Left || + action.actionKey is MouseInputActionKey.Right || + action.actionKey is MouseInputActionKey.Screen) + && (action.actionKey.touchUp || action.actionKey is MouseInputActionKey.Screen) + } + + protected fun updateCraftResult(window: AbstractInventoryWindowWithCraftGrid) { + window.craftResult = gameItemsHolder.craftItem(window.craftingItems.map(InventoryItem::item)) + ?: gameItemsHolder.fallbackItem.toInventoryItem() + } + + private fun reduceCraftItems(window: AbstractInventoryWindowWithCraftGrid) { + for (i in window.craftingItems.indices) { + if (window.craftingItems[i].amount > 1) { + window.craftingItems[i].amount-- + } else { + window.craftingItems[i] = gameItemsHolder.fallbackItem.toInventoryItem() + } + } + } + + protected fun handleInsidePlaceableCell( + action: MouseInputAction, + items: MutableList, + window: AbstractInventoryWindow, + index: Int + ) { + if (action.actionKey is MouseInputActionKey.Screen) { + if (!action.actionKey.touchUp) { + window.onLeftCLick(items, gameItemsHolder, index, action.actionKey.pointer) + } else { + if (action.actionKey.pointer == window.selectItemPointer) { + window.onLeftCLick(items, gameItemsHolder, index, action.actionKey.pointer) + } else { + window.onRightClick(items, index) + } + } + } else if (action.actionKey is MouseInputActionKey.Left) { + window.onLeftCLick(items, gameItemsHolder, index) + } else { + window.onRightClick(items, index) + } + } + + protected fun handleInsideCraftResultCell( + action: MouseInputAction, + items: MutableList, + window: AbstractInventoryWindow, + index: Int + ) { + val selectedItem = window.selectedItem + + if (!selectedItem.isNoneOrNull() && (selectedItem.item != items[index].item || + !selectedItem.canBeAdded(items[index].amount))) { + return + } + + if (!selectedItem.isNoneOrNull()) { + selectedItem.amount += items[index].amount + items[index] = gameItemsHolder.fallbackItem.toInventoryItem() + } else { + if (action.actionKey is MouseInputActionKey.Screen) { + if (!action.actionKey.touchUp) { + window.onLeftCLick(items, gameItemsHolder, Furnace.RESULT_INDEX, action.actionKey.pointer) + } + } else if (action.actionKey is MouseInputActionKey.Left) { + window.onLeftCLick(items, gameItemsHolder, index) + } + } + + if (window is AbstractInventoryWindowWithCraftGrid) { + reduceCraftItems(window) + } + + } + +} \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectChestInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectChestInventoryItemMouseInputHandler.kt index 3d1bfae..d47202e 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectChestInventoryItemMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectChestInventoryItemMouseInputHandler.kt @@ -1,20 +1,13 @@ package ru.deadsoftware.cavedroid.game.input.handler.mouse -import com.badlogic.gdx.Gdx import ru.deadsoftware.cavedroid.game.GameItemsHolder 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.MouseInputAction -import ru.deadsoftware.cavedroid.game.input.action.keys.MouseInputActionKey -import ru.deadsoftware.cavedroid.game.input.isInsideWindow import ru.deadsoftware.cavedroid.game.mobs.MobsController -import ru.deadsoftware.cavedroid.game.model.item.InventoryItem -import ru.deadsoftware.cavedroid.game.objects.drop.DropController import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsConfigs import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager import ru.deadsoftware.cavedroid.game.ui.windows.inventory.ChestInventoryWindow -import ru.deadsoftware.cavedroid.game.ui.windows.inventory.SurvivalInventoryWindow import ru.deadsoftware.cavedroid.misc.Assets import javax.inject.Inject @@ -23,82 +16,35 @@ class SelectChestInventoryItemMouseInputHandler @Inject constructor( private val gameWindowsManager: GameWindowsManager, private val mobsController: MobsController, private val gameItemsHolder: GameItemsHolder, - private val dropController: DropController, -) : IGameInputHandler { +) : AbstractInventoryItemsMouseInputHandler(gameItemsHolder, gameWindowsManager, GameUiWindow.CHEST) { - private val chestWindowTexture get() = requireNotNull(Assets.textureRegions["chest"]) - - override fun checkConditions(action: MouseInputAction): Boolean { - return gameWindowsManager.getCurrentWindow() == GameUiWindow.CHEST && - isInsideWindow(action, chestWindowTexture) && - (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Right || action.actionKey is MouseInputActionKey.Screen) - && (action.actionKey.touchUp || action.actionKey is MouseInputActionKey.Screen) - } + override val windowTexture get() = requireNotNull(Assets.textureRegions["chest"]) private fun handleInsideContentGrid(action: MouseInputAction, xOnGrid: Int, yOnGrid: Int) { val window = gameWindowsManager.currentWindow as ChestInventoryWindow + val itemIndex = xOnGrid + yOnGrid * GameWindowsConfigs.Chest.contentsInRow - val itemIndex = ((xOnGrid.toInt() + yOnGrid.toInt() * GameWindowsConfigs.Chest.contentsInRow)) - - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(window.chest.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(window.chest.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - window.onRightClick(window.chest.items as MutableList, itemIndex) - } - } - } else if (action.actionKey is MouseInputActionKey.Left) { - window.onLeftCLick(window.chest.items as MutableList, gameItemsHolder, itemIndex) - } else { - window.onRightClick(window.chest.items as MutableList, itemIndex) - } - - Gdx.app.debug( - TAG, - "selected item: ${window.selectedItem?.item?.params?.key ?: "null"}; index $itemIndex, grid ($xOnGrid;$yOnGrid)" - ) + handleInsidePlaceableCell(action, window.chest.items, window, itemIndex) } private fun handleInsideInventoryGrid(action: MouseInputAction, xOnGrid: Int, yOnGrid: Int) { val window = gameWindowsManager.currentWindow as ChestInventoryWindow - var itemIndex = ((xOnGrid.toInt() + yOnGrid.toInt() * GameWindowsConfigs.Chest.itemsInRow)) + var itemIndex = xOnGrid + yOnGrid * GameWindowsConfigs.Chest.itemsInRow itemIndex += GameWindowsConfigs.Chest.hotbarCells if (itemIndex >= mobsController.player.inventory.size) { itemIndex -= mobsController.player.inventory.size } - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - } - } else if (action.actionKey is MouseInputActionKey.Left) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - - Gdx.app.debug( - TAG, - "selected item: ${window.selectedItem?.item?.params?.key ?: "null"}; index $itemIndex, grid ($xOnGrid;$yOnGrid)" - ) + handleInsidePlaceableCell(action, mobsController.player.inventory.items, window, itemIndex) } override fun handle(action: MouseInputAction) { - val chestTexture = chestWindowTexture + val texture = windowTexture - val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - chestTexture.regionWidth / 2) - val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - chestTexture.regionHeight / 2) + val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - texture.regionWidth / 2) + val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - texture.regionHeight / 2) val xOnGrid = (xOnWindow - GameWindowsConfigs.Chest.itemsGridMarginLeft) / GameWindowsConfigs.Chest.itemsGridColWidth @@ -123,9 +69,4 @@ class SelectChestInventoryItemMouseInputHandler @Inject constructor( handleInsideContentGrid(action, xOnContent.toInt(), yOnContent.toInt()) } } - - companion object { - private const val TAG = "SelectChestInventoryItemMouseInputHandler" - - } } \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCraftingInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCraftingInventoryItemMouseInputHandler.kt index 32c7a43..88e3620 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCraftingInventoryItemMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCraftingInventoryItemMouseInputHandler.kt @@ -1,16 +1,10 @@ package ru.deadsoftware.cavedroid.game.input.handler.mouse -import com.badlogic.gdx.Gdx import ru.deadsoftware.cavedroid.game.GameItemsHolder 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.MouseInputAction -import ru.deadsoftware.cavedroid.game.input.action.keys.MouseInputActionKey -import ru.deadsoftware.cavedroid.game.input.isInsideWindow import ru.deadsoftware.cavedroid.game.mobs.MobsController -import ru.deadsoftware.cavedroid.game.model.item.InventoryItem -import ru.deadsoftware.cavedroid.game.objects.drop.DropController import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsConfigs import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager import ru.deadsoftware.cavedroid.game.ui.windows.inventory.CraftingInventoryWindow @@ -22,80 +16,45 @@ class SelectCraftingInventoryItemMouseInputHandler @Inject constructor( private val gameWindowsManager: GameWindowsManager, private val mobsController: MobsController, private val gameItemsHolder: GameItemsHolder, - private val dropController: DropController, -) : IGameInputHandler { +) : AbstractInventoryItemsMouseInputHandler(gameItemsHolder, gameWindowsManager, GameUiWindow.CRAFTING_TABLE) { - private val survivalWindowTexture get() = requireNotNull(Assets.textureRegions["survival"]) - - override fun checkConditions(action: MouseInputAction): Boolean { - return gameWindowsManager.getCurrentWindow() == GameUiWindow.CRAFTING_TABLE && - isInsideWindow(action, survivalWindowTexture) && - (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Right || action.actionKey is MouseInputActionKey.Screen) - && (action.actionKey.touchUp || action.actionKey is MouseInputActionKey.Screen) - } + override val windowTexture get() = requireNotNull(Assets.textureRegions["crafting_table"]) private fun handleInsideInventoryGrid(action: MouseInputAction, xOnGrid: Int, yOnGrid: Int) { val window = gameWindowsManager.currentWindow as CraftingInventoryWindow - var itemIndex = ((xOnGrid.toInt() + yOnGrid.toInt() * GameWindowsConfigs.Crafting.itemsInRow)) + var itemIndex = xOnGrid + yOnGrid * GameWindowsConfigs.Crafting.itemsInRow itemIndex += GameWindowsConfigs.Crafting.hotbarCells if (itemIndex >= mobsController.player.inventory.size) { itemIndex -= mobsController.player.inventory.size } - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - } - } else if (action.actionKey is MouseInputActionKey.Left) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - - Gdx.app.debug( - TAG, - "selected item: ${window.selectedItem?.item?.params?.key ?: "null"}; index $itemIndex, grid ($xOnGrid;$yOnGrid)" - ) + handleInsidePlaceableCell(action, mobsController.player.inventory.items, window, itemIndex) } private fun handleInsideCraft(action: MouseInputAction, xOnCraft: Int, yOnCraft: Int) { val window = gameWindowsManager.currentWindow as CraftingInventoryWindow val index = xOnCraft + yOnCraft * GameWindowsConfigs.Crafting.craftGridSize - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(window.craftingItems, gameItemsHolder, index, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(window.craftingItems, gameItemsHolder, index, action.actionKey.pointer) - } else { - window.onRightClick(window.craftingItems, index) - } - } - } else if (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) { - window.onLeftCLick(window.craftingItems, gameItemsHolder, index) - } else { - window.onRightClick(window.craftingItems, index) - } + handleInsidePlaceableCell(action, window.craftingItems, window, index) - window.craftResult = - gameItemsHolder.craftItem(window.craftingItems.map { it?.item ?: gameItemsHolder.fallbackItem }) + updateCraftResult(window) } - override fun handle(action: MouseInputAction) { - val survivalTexture = survivalWindowTexture + private fun handleInsideCraftResult(action: MouseInputAction) { val window = gameWindowsManager.currentWindow as CraftingInventoryWindow - val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - survivalTexture.regionWidth / 2) - val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - survivalTexture.regionHeight / 2) + handleInsideCraftResultCell(action, window.craftResultList, window, 0) + + updateCraftResult(window) + } + + override fun handle(action: MouseInputAction) { + val texture = windowTexture + + val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - texture.regionWidth / 2) + val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - texture.regionHeight / 2) val xOnGrid = (xOnWindow - GameWindowsConfigs.Crafting.itemsGridMarginLeft) / GameWindowsConfigs.Crafting.itemsGridColWidth @@ -122,31 +81,9 @@ class SelectCraftingInventoryItemMouseInputHandler @Inject constructor( handleInsideInventoryGrid(action, xOnGrid.toInt(), yOnGrid.toInt()) } else if (isInsideCraftGrid) { handleInsideCraft(action, xOnCraft.toInt(), yOnCraft.toInt()) - } else if (isInsideCraftResult && action.actionKey.touchUp) { - val selectedItem = window.selectedItem - if (selectedItem == null || selectedItem.item.isNone() || - (selectedItem.item == window.craftResult?.item && selectedItem.amount + (window.craftResult?.amount ?: 0) <= selectedItem.item.params.maxStack)) { - for (i in window.craftingItems.indices) { - if ((window.craftingItems[i]?.amount ?: 0) > 1) { - window.craftingItems[i]?.amount = window.craftingItems[i]?.amount!! - 1 - } else { - window.craftingItems[i] = null - } - } - if (selectedItem != null && !selectedItem.item.isNone()) { - selectedItem.amount += (window.craftResult?.amount ?: 0) - } else { - window.selectedItem = window.craftResult - } - window.craftResult = gameItemsHolder.craftItem(window.craftingItems - .map { it?.item ?: gameItemsHolder.fallbackItem }) - } + } else if (isInsideCraftResult) { + handleInsideCraftResult(action) } } - - companion object { - private const val TAG = "SelectCraftingInventoryItemMouseInputHandler" - - } } \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectFurnaceInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectFurnaceInventoryItemMouseInputHandler.kt index e11c433..f4a00eb 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectFurnaceInventoryItemMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectFurnaceInventoryItemMouseInputHandler.kt @@ -1,17 +1,11 @@ package ru.deadsoftware.cavedroid.game.input.handler.mouse -import com.badlogic.gdx.Gdx import ru.deadsoftware.cavedroid.game.GameItemsHolder 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.MouseInputAction -import ru.deadsoftware.cavedroid.game.input.action.keys.MouseInputActionKey -import ru.deadsoftware.cavedroid.game.input.isInsideWindow import ru.deadsoftware.cavedroid.game.mobs.MobsController -import ru.deadsoftware.cavedroid.game.model.item.InventoryItem import ru.deadsoftware.cavedroid.game.model.item.InventoryItem.Companion.isNoneOrNull -import ru.deadsoftware.cavedroid.game.objects.drop.DropController import ru.deadsoftware.cavedroid.game.objects.container.Furnace import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsConfigs import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager @@ -24,48 +18,21 @@ class SelectFurnaceInventoryItemMouseInputHandler @Inject constructor( private val gameWindowsManager: GameWindowsManager, private val mobsController: MobsController, private val gameItemsHolder: GameItemsHolder, - private val dropController: DropController, -) : IGameInputHandler { +) : AbstractInventoryItemsMouseInputHandler(gameItemsHolder, gameWindowsManager, GameUiWindow.FURNACE) { - private val survivalWindowTexture get() = requireNotNull(Assets.textureRegions["survival"]) - - override fun checkConditions(action: MouseInputAction): Boolean { - return gameWindowsManager.getCurrentWindow() == GameUiWindow.FURNACE && - isInsideWindow(action, survivalWindowTexture) && - (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Right || action.actionKey is MouseInputActionKey.Screen) - && (action.actionKey.touchUp || action.actionKey is MouseInputActionKey.Screen) - } + override val windowTexture get() = requireNotNull(Assets.textureRegions["furnace"]) private fun handleInsideInventoryGrid(action: MouseInputAction, xOnGrid: Int, yOnGrid: Int) { val window = gameWindowsManager.currentWindow as FurnaceInventoryWindow - var itemIndex = ((xOnGrid.toInt() + yOnGrid.toInt() * GameWindowsConfigs.Furnace.itemsInRow)) + var itemIndex = xOnGrid + yOnGrid * GameWindowsConfigs.Furnace.itemsInRow itemIndex += GameWindowsConfigs.Furnace.hotbarCells if (itemIndex >= mobsController.player.inventory.size) { itemIndex -= mobsController.player.inventory.size } - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - } - } else if (action.actionKey is MouseInputActionKey.Left) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - - Gdx.app.debug( - TAG, - "selected item: ${window.selectedItem?.item?.params?.key ?: "null"}; index $itemIndex, grid ($xOnGrid;$yOnGrid)" - ) + handleInsidePlaceableCell(action, mobsController.player.inventory.items, window, itemIndex) } private fun handleInsideFuel(action: MouseInputAction) { @@ -75,49 +42,26 @@ class SelectFurnaceInventoryItemMouseInputHandler @Inject constructor( return } - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(window.furnace.items as MutableList, gameItemsHolder, Furnace.FUEL_INDEX, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(window.furnace.items as MutableList, gameItemsHolder, Furnace.FUEL_INDEX, action.actionKey.pointer) - } else { - window.onRightClick(window.furnace.items as MutableList, Furnace.FUEL_INDEX) - } - } - } else if (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) { - window.onLeftCLick(window.furnace.items as MutableList, gameItemsHolder, Furnace.FUEL_INDEX) - } else { - window.onRightClick(window.furnace.items as MutableList, Furnace.FUEL_INDEX) - } + handleInsidePlaceableCell(action, window.furnace.items, window, Furnace.FUEL_INDEX) } private fun handleInsideInput(action: MouseInputAction) { val window = gameWindowsManager.currentWindow as FurnaceInventoryWindow - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(window.furnace.items as MutableList, gameItemsHolder, Furnace.INPUT_INDEX, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(window.furnace.items as MutableList, gameItemsHolder, Furnace.INPUT_INDEX, action.actionKey.pointer) - } else { - window.onRightClick(window.furnace.items as MutableList, Furnace.INPUT_INDEX) - } - } - } else if (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) { - window.onLeftCLick(window.furnace.items as MutableList, gameItemsHolder, Furnace.INPUT_INDEX) - } else { - window.onRightClick(window.furnace.items as MutableList, Furnace.INPUT_INDEX) - } + handleInsidePlaceableCell(action, window.furnace.items, window, Furnace.INPUT_INDEX) } - override fun handle(action: MouseInputAction) { - val survivalTexture = survivalWindowTexture + private fun handleInsideResult(action: MouseInputAction) { val window = gameWindowsManager.currentWindow as FurnaceInventoryWindow - val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - survivalTexture.regionWidth / 2) - val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - survivalTexture.regionHeight / 2) + handleInsideCraftResultCell(action, window.furnace.items, window, Furnace.RESULT_INDEX) + } + + override fun handle(action: MouseInputAction) { + val texture = windowTexture + + val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - texture.regionWidth / 2) + val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - texture.regionHeight / 2) val xOnGrid = (xOnWindow - GameWindowsConfigs.Furnace.itemsGridMarginLeft) / GameWindowsConfigs.Furnace.itemsGridColWidth @@ -148,24 +92,9 @@ class SelectFurnaceInventoryItemMouseInputHandler @Inject constructor( handleInsideFuel(action) } else if (isInsideInput) { handleInsideInput(action) - } else if (isInsideResult && action.actionKey.touchUp) { - val selectedItem = window.selectedItem - if (selectedItem == null || selectedItem.item.isNone() || - (selectedItem.item == window.furnace.result?.item && selectedItem.amount + (window.furnace.result?.amount ?: 0) <= selectedItem.item.params.maxStack)) { - - if (selectedItem != null && !selectedItem.item.isNone()) { - selectedItem.amount += (window.furnace.result?.amount ?: 0) - } else { - window.selectedItem = window.furnace.result - } - window.furnace.items[Furnace.RESULT_INDEX] = gameItemsHolder.fallbackItem.toInventoryItem() - } + } else if (isInsideResult) { + handleInsideResult(action) } } - - companion object { - private const val TAG = "SelectFurnaceInventoryItemMouseInputHandler" - - } } \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt index 263d59e..0a455ab 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt @@ -1,16 +1,10 @@ package ru.deadsoftware.cavedroid.game.input.handler.mouse -import com.badlogic.gdx.Gdx import ru.deadsoftware.cavedroid.game.GameItemsHolder 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.MouseInputAction -import ru.deadsoftware.cavedroid.game.input.action.keys.MouseInputActionKey -import ru.deadsoftware.cavedroid.game.input.isInsideWindow import ru.deadsoftware.cavedroid.game.mobs.MobsController -import ru.deadsoftware.cavedroid.game.model.item.InventoryItem -import ru.deadsoftware.cavedroid.game.objects.drop.DropController import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsConfigs import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager import ru.deadsoftware.cavedroid.game.ui.windows.inventory.SurvivalInventoryWindow @@ -22,80 +16,43 @@ class SelectSurvivalInventoryItemMouseInputHandler @Inject constructor( private val gameWindowsManager: GameWindowsManager, private val mobsController: MobsController, private val gameItemsHolder: GameItemsHolder, - private val dropController: DropController, -) : IGameInputHandler { +) : AbstractInventoryItemsMouseInputHandler(gameItemsHolder, gameWindowsManager, GameUiWindow.SURVIVAL_INVENTORY) { - private val survivalWindowTexture get() = requireNotNull(Assets.textureRegions["survival"]) - - override fun checkConditions(action: MouseInputAction): Boolean { - return gameWindowsManager.getCurrentWindow() == GameUiWindow.SURVIVAL_INVENTORY && - isInsideWindow(action, survivalWindowTexture) && - (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Right || action.actionKey is MouseInputActionKey.Screen) - && (action.actionKey.touchUp || action.actionKey is MouseInputActionKey.Screen) - } + override val windowTexture get() = requireNotNull(Assets.textureRegions["survival"]) private fun handleInsideInventoryGrid(action: MouseInputAction, xOnGrid: Int, yOnGrid: Int) { val window = gameWindowsManager.currentWindow as SurvivalInventoryWindow - var itemIndex = ((xOnGrid.toInt() + yOnGrid.toInt() * GameWindowsConfigs.Survival.itemsInRow)) + var itemIndex = xOnGrid + yOnGrid * GameWindowsConfigs.Survival.itemsInRow itemIndex += GameWindowsConfigs.Survival.hotbarCells if (itemIndex >= mobsController.player.inventory.size) { itemIndex -= mobsController.player.inventory.size } - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex, action.actionKey.pointer) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - } - } else if (action.actionKey is MouseInputActionKey.Left) { - window.onLeftCLick(mobsController.player.inventory.items as MutableList, gameItemsHolder, itemIndex) - } else { - window.onRightClick(mobsController.player.inventory.items as MutableList, itemIndex) - } - - Gdx.app.debug( - TAG, - "selected item: ${window.selectedItem?.item?.params?.key ?: "null"}; index $itemIndex, grid ($xOnGrid;$yOnGrid)" - ) + handleInsidePlaceableCell(action, mobsController.player.inventory.items, window, itemIndex) } private fun handleInsideCraft(action: MouseInputAction, xOnCraft: Int, yOnCraft: Int) { val window = gameWindowsManager.currentWindow as SurvivalInventoryWindow val index = xOnCraft + yOnCraft * GameWindowsConfigs.Crafting.craftGridSize // this is crafting on purpose!! - if (action.actionKey is MouseInputActionKey.Screen) { - if (!action.actionKey.touchUp) { - window.onLeftCLick(window.craftingItems, gameItemsHolder, index, action.actionKey.pointer) - } else { - if (action.actionKey.pointer == window.selectItemPointer) { - window.onLeftCLick(window.craftingItems, gameItemsHolder, index, action.actionKey.pointer) - } else { - window.onRightClick(window.craftingItems, index) - } - } - } else if (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) { - window.onLeftCLick(window.craftingItems, gameItemsHolder, index) - } else { - window.onRightClick(window.craftingItems, index) - } + handleInsidePlaceableCell(action, window.craftingItems, window, index) - window.craftResult = - gameItemsHolder.craftItem(window.craftingItems.map { it?.item ?: gameItemsHolder.fallbackItem }) + updateCraftResult(window) } - override fun handle(action: MouseInputAction) { - val survivalTexture = survivalWindowTexture + private fun handleInsideCraftResult(action: MouseInputAction) { val window = gameWindowsManager.currentWindow as SurvivalInventoryWindow - val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - survivalTexture.regionWidth / 2) - val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - survivalTexture.regionHeight / 2) + handleInsideCraftResultCell(action, window.craftResultList, window, 0) + + updateCraftResult(window) + } + + override fun handle(action: MouseInputAction) { + val xOnWindow = action.screenX - (action.cameraViewport.width / 2 - windowTexture.regionWidth / 2) + val yOnWindow = action.screenY - (action.cameraViewport.height / 2 - windowTexture.regionHeight / 2) val xOnGrid = (xOnWindow - GameWindowsConfigs.Survival.itemsGridMarginLeft) / GameWindowsConfigs.Survival.itemsGridColWidth @@ -122,31 +79,9 @@ class SelectSurvivalInventoryItemMouseInputHandler @Inject constructor( handleInsideInventoryGrid(action, xOnGrid.toInt(), yOnGrid.toInt()) } else if (isInsideCraftGrid) { handleInsideCraft(action, xOnCraft.toInt(), yOnCraft.toInt()) - } else if (isInsideCraftResult && action.actionKey.touchUp) { - val selectedItem = window.selectedItem - if (selectedItem == null || selectedItem.item.isNone() || - (selectedItem.item == window.craftResult?.item && selectedItem.amount + (window.craftResult?.amount ?: 0) <= selectedItem.item.params.maxStack)) { - for (i in window.craftingItems.indices) { - if ((window.craftingItems[i]?.amount ?: 0) > 1) { - window.craftingItems[i]?.amount = window.craftingItems[i]?.amount!! - 1 - } else { - window.craftingItems[i] = null - } - } - if (selectedItem != null && !selectedItem.item.isNone()) { - selectedItem.amount += (window.craftResult?.amount ?: 0) - } else { - window.selectedItem = window.craftResult - } - window.craftResult = gameItemsHolder.craftItem(window.craftingItems - .map { it?.item ?: gameItemsHolder.fallbackItem }) - } + } else if (isInsideCraftResult) { + handleInsideCraftResult(action) } } - - companion object { - private const val TAG = "SelectSurvivalInventoryItemMouseInputHandler" - - } } \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt index c5e10d0..c6dea8b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt @@ -59,11 +59,13 @@ class Inventory( } } - private fun getItemPickSlot(item: Item): Int { + private fun getItemPickSlot(drop: Drop): Int { + val item = drop.item + for (i in _items.indices) { val inventoryItem = _items[i] - if (item == inventoryItem.item && inventoryItem.canBeAdded()) { + if (item == inventoryItem.item && inventoryItem.canBeAdded(drop.amount)) { return i } } @@ -79,12 +81,12 @@ class Inventory( return -1 } - fun canPickItem(item: Item): Boolean { - return getItemPickSlot(item) >= 0 + fun canPickItem(drop: Drop): Boolean { + return getItemPickSlot(drop) >= 0 } fun pickDrop(drop: Drop) { - val slot = getItemPickSlot(drop.item).takeIf { it >= 0 } ?: return + val slot = getItemPickSlot(drop).takeIf { it >= 0 } ?: return val inventoryItem = _items[slot] if (inventoryItem.item == drop.item) { 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 44d3179..f847f7d 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt @@ -10,6 +10,8 @@ import ru.deadsoftware.cavedroid.misc.utils.drawSprite import ru.deadsoftware.cavedroid.misc.utils.drawString import ru.deadsoftware.cavedroid.misc.utils.px import java.io.Serializable +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract class InventoryItem @JvmOverloads constructor( val itemKey: String, @@ -123,6 +125,11 @@ class InventoryItem @JvmOverloads constructor( } companion object { - fun InventoryItem?.isNoneOrNull() = this?.item == null || this.item.isNone() + + @OptIn(ExperimentalContracts::class) + fun InventoryItem?.isNoneOrNull(): Boolean { + contract { returns(false) implies(this@isNoneOrNull != null) } + return this?.item == null || this.item.isNone() + } } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/GameWindowsManager.kt b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/GameWindowsManager.kt index 32494ed..8d32f94 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/GameWindowsManager.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/GameWindowsManager.kt @@ -1,5 +1,6 @@ package ru.deadsoftware.cavedroid.game.ui.windows +import ru.deadsoftware.cavedroid.game.GameItemsHolder import ru.deadsoftware.cavedroid.game.GameScope import ru.deadsoftware.cavedroid.game.GameUiWindow import ru.deadsoftware.cavedroid.game.mobs.MobsController @@ -15,6 +16,7 @@ class GameWindowsManager @Inject constructor( private val tooltipManager: TooltipManager, private val mobsController: MobsController, private val dropController: DropController, + private val gameItemsHolder: GameItemsHolder, ) { var creativeScrollAmount = 0 @@ -31,7 +33,7 @@ class GameWindowsManager @Inject constructor( if (mobsController.player.gameMode == 1) { currentWindow = CreativeInventoryWindow() } else { - currentWindow = SurvivalInventoryWindow() + currentWindow = SurvivalInventoryWindow(gameItemsHolder) } } @@ -44,23 +46,13 @@ class GameWindowsManager @Inject constructor( } fun openCrafting() { - currentWindow = CraftingInventoryWindow() + currentWindow = CraftingInventoryWindow(gameItemsHolder) } fun closeWindow() { - (currentWindow as? SurvivalInventoryWindow)?.let { window -> + (currentWindow as? AbstractInventoryWindowWithCraftGrid)?.let { window -> window.craftingItems.forEach { item -> - item?.item?.let { - dropController.addDrop(mobsController.player.x, mobsController.player.y, it, item.amount) - } - } - } - - (currentWindow as? CraftingInventoryWindow)?.let { window -> - window.craftingItems.forEach { item -> - item?.item?.let { - dropController.addDrop(mobsController.player.x, mobsController.player.y, it, item.amount) - } + dropController.addDrop(mobsController.player.x, mobsController.player.y, item) } } 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 f49ba49..c26bda9 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 @@ -3,6 +3,7 @@ package ru.deadsoftware.cavedroid.game.ui.windows.inventory import ru.deadsoftware.cavedroid.game.GameItemsHolder import ru.deadsoftware.cavedroid.game.GameUiWindow import ru.deadsoftware.cavedroid.game.model.item.InventoryItem +import ru.deadsoftware.cavedroid.game.model.item.InventoryItem.Companion.isNoneOrNull abstract class AbstractInventoryWindow { @@ -12,17 +13,27 @@ abstract class AbstractInventoryWindow { var selectItemPointer: Int = -1 - fun onLeftCLick(items: MutableList, gameItemsHolder: GameItemsHolder, index: Int, pointer: Int = -1) { - if (selectedItem != null && selectedItem?.item?.isNone() != true && pointer >= 0 && selectItemPointer >= 0 && pointer != selectItemPointer) { + fun onLeftCLick( + items: MutableList, + gameItemsHolder: GameItemsHolder, + index: Int, + pointer: Int = -1 + ) { + if (selectedItem != null && + selectedItem?.item?.isNone() != true && + pointer >= 0 && selectItemPointer >= 0 && + pointer != selectItemPointer + ) { return } val clickedItem = items[index] selectedItem?.let { selectedItem -> - if (clickedItem != null && items[index]!!.item == selectedItem.item && - items[index]!!.amount + selectedItem.amount <= selectedItem.item.params.maxStack) { - items[index]!!.amount += selectedItem.amount + if (!clickedItem.isNoneOrNull() && items[index].item == selectedItem.item && + items[index].amount + selectedItem.amount <= selectedItem.item.params.maxStack + ) { + items[index].amount += selectedItem.amount this@AbstractInventoryWindow.selectedItem = null selectItemPointer = -1 return @@ -35,15 +46,20 @@ abstract class AbstractInventoryWindow { selectItemPointer = pointer } - fun onRightClick(items: MutableList, index: Int) { + fun onRightClick(items: MutableList, index: Int) { val clickedItem = items[index] val selectedItem = selectedItem - ?.takeIf { clickedItem == null || clickedItem.item.isNone() || it.item == items[index]!!.item && items[index]!!.amount + 1 < it.item.params.maxStack } + ?.takeIf { + !clickedItem.isNoneOrNull() || clickedItem.item.isNone() || + it.item == items[index].item && items[index].amount + 1 < it.item.params.maxStack + } ?: return - val newItem = selectedItem.item.toInventoryItem((clickedItem?.takeIf { !it.item.isNone() }?.amount ?: 0) + 1) + val newItem = selectedItem.item.toInventoryItem( + (clickedItem.takeIf { !it.item.isNone() }?.amount ?: 0) + 1 + ) items[index] = newItem - selectedItem.amount -- + selectedItem.amount-- if (selectedItem.amount <= 0) { this@AbstractInventoryWindow.selectedItem = null diff --git a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindowWithCraftGrid.kt b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindowWithCraftGrid.kt new file mode 100644 index 0000000..066ca37 --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindowWithCraftGrid.kt @@ -0,0 +1,24 @@ +package ru.deadsoftware.cavedroid.game.ui.windows.inventory + +import ru.deadsoftware.cavedroid.game.GameItemsHolder +import ru.deadsoftware.cavedroid.game.model.item.InventoryItem + +abstract class AbstractInventoryWindowWithCraftGrid( + gameItemsHolder: GameItemsHolder, +) : AbstractInventoryWindow() { + + private val _items = Array(10) { gameItemsHolder.fallbackItem.toInventoryItem() } + + val items get() = _items.asList() + + val craftingItems get() = items.subList(0, 9) as MutableList + + val craftResultList get() = items.subList(9, 10) as MutableList + + var craftResult: InventoryItem + get() = craftResultList[0] + set(value) { + craftResultList[0] = value + } + +} \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/CraftingInventoryWindow.kt b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/CraftingInventoryWindow.kt index d83f1d5..cd7c0ff 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/CraftingInventoryWindow.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/CraftingInventoryWindow.kt @@ -1,15 +1,14 @@ package ru.deadsoftware.cavedroid.game.ui.windows.inventory +import ru.deadsoftware.cavedroid.game.GameItemsHolder import ru.deadsoftware.cavedroid.game.GameUiWindow import ru.deadsoftware.cavedroid.game.model.item.InventoryItem -class CraftingInventoryWindow : AbstractInventoryWindow() { +class CraftingInventoryWindow( + gameItemsHolder: GameItemsHolder +) : AbstractInventoryWindowWithCraftGrid(gameItemsHolder) { override val type = GameUiWindow.CRAFTING_TABLE override var selectedItem: InventoryItem? = null - - val craftingItems = MutableList(9) { null } - - var craftResult: InventoryItem? = null } \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/SurvivalInventoryWindow.kt b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/SurvivalInventoryWindow.kt index 12026d8..ce250fc 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/SurvivalInventoryWindow.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/SurvivalInventoryWindow.kt @@ -1,15 +1,14 @@ package ru.deadsoftware.cavedroid.game.ui.windows.inventory +import ru.deadsoftware.cavedroid.game.GameItemsHolder import ru.deadsoftware.cavedroid.game.GameUiWindow import ru.deadsoftware.cavedroid.game.model.item.InventoryItem -class SurvivalInventoryWindow() : AbstractInventoryWindow() { +class SurvivalInventoryWindow( + gameItemsHolder: GameItemsHolder +) : AbstractInventoryWindowWithCraftGrid(gameItemsHolder) { override val type = GameUiWindow.SURVIVAL_INVENTORY override var selectedItem: InventoryItem? = null - - val craftingItems = MutableList(9) { null } - - var craftResult: InventoryItem? = null } \ No newline at end of file -- 2.29.2