[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / ui / windows / GameWindowsManager.kt
1 package ru.deadsoftware.cavedroid.game.ui.windows
3 import ru.deadsoftware.cavedroid.game.GameItemsHolder
4 import ru.deadsoftware.cavedroid.game.GameScope
5 import ru.deadsoftware.cavedroid.game.GameUiWindow
6 import ru.deadsoftware.cavedroid.game.mobs.MobsController
7 import ru.deadsoftware.cavedroid.game.objects.container.Chest
8 import ru.deadsoftware.cavedroid.game.objects.drop.DropController
9 import ru.deadsoftware.cavedroid.game.objects.container.Furnace
10 import ru.deadsoftware.cavedroid.game.ui.TooltipManager
11 import ru.deadsoftware.cavedroid.game.ui.windows.inventory.*
12 import javax.inject.Inject
14 @GameScope
15 class GameWindowsManager @Inject constructor(
16 private val tooltipManager: TooltipManager,
17 private val mobsController: MobsController,
18 private val dropController: DropController,
19 private val gameItemsHolder: GameItemsHolder,
20 ) {
22 var creativeScrollAmount = 0
23 var isDragging = false
25 var currentWindow: AbstractInventoryWindow? = null
27 @JvmName("getCurrentWindowType")
28 fun getCurrentWindow(): GameUiWindow {
29 return currentWindow?.type ?: GameUiWindow.NONE
30 }
32 fun openInventory() {
33 if (mobsController.player.gameMode == 1) {
34 currentWindow = CreativeInventoryWindow()
35 } else {
36 currentWindow = SurvivalInventoryWindow(gameItemsHolder)
37 }
38 }
40 fun openFurnace(furnace: Furnace) {
41 currentWindow = FurnaceInventoryWindow(furnace)
42 }
44 fun openChest(chest: Chest) {
45 currentWindow = ChestInventoryWindow(chest)
46 }
48 fun openCrafting() {
49 currentWindow = CraftingInventoryWindow(gameItemsHolder)
50 }
52 fun closeWindow() {
53 (currentWindow as? AbstractInventoryWindowWithCraftGrid)?.let { window ->
54 window.craftingItems.forEach { item ->
55 dropController.addDrop(mobsController.player.x, mobsController.player.y, item)
56 }
57 }
59 currentWindow = null
60 tooltipManager.showMouseTooltip("")
61 }
63 }