diff --git a/roguelike/src/main/scala/roguelike/model/Model.scala b/roguelike/src/main/scala/roguelike/model/Model.scala index d5eab98..2aed116 100644 --- a/roguelike/src/main/scala/roguelike/model/Model.scala +++ b/roguelike/src/main/scala/roguelike/model/Model.scala @@ -17,6 +17,7 @@ import roguelike.model.gamedata.Ranged import roguelike.windows.ActiveWindow import roguelike.windows.WindowManagerCommand import roguelike.windows.WindowStateManager +import roguelikestarterkit.WindowId import scala.scalajs.js @@ -34,11 +35,15 @@ final case class Model( autoMovePath: Batch[Point], activeWindow: ActiveWindow, collectables: Batch[Collectable], - hostiles: HostilesPool + hostiles: HostilesPool, + mouseOverWindows: Batch[WindowId] ): val gameWindowContext: GameWindowContext = GameWindowContext(currentFloor, player, messageLog) + lazy val gameClickAllowed: Boolean = + mouseOverWindows.isEmpty + def entitiesList: js.Array[Entity] = (collectables.toJSArray ++ hostiles.toJSArray.sortBy(_.isAlive)) @@ -499,7 +504,8 @@ object Model: Batch.empty, WindowStateManager.initialModel, Batch.empty, - HostilesPool(Batch.empty) + HostilesPool(Batch.empty), + Batch.empty ) def fromSaveData(model: Model, saveData: ModelSaveData): Model = @@ -555,7 +561,8 @@ object Model: Batch.empty, WindowStateManager.initialModel, Batch.fromList(dungeon.collectables), - HostilesPool(Batch.fromList(dungeon.hostiles)) + HostilesPool(Batch.fromList(dungeon.hostiles)), + Batch.empty ) } } diff --git a/roguelike/src/main/scala/roguelike/scenes/GameSceneUpdate.scala b/roguelike/src/main/scala/roguelike/scenes/GameSceneUpdate.scala index 76eba01..dfeb37f 100644 --- a/roguelike/src/main/scala/roguelike/scenes/GameSceneUpdate.scala +++ b/roguelike/src/main/scala/roguelike/scenes/GameSceneUpdate.scala @@ -33,6 +33,12 @@ object GameSceneUpdate: context: SceneContext[Size], model: Model ): GlobalEvent => Outcome[Model] = + case WindowEvent.MouseOver(id) => + Outcome(model.copy(mouseOverWindows = id :: model.mouseOverWindows)) + + case WindowEvent.MouseOut(id) => + Outcome(model.copy(mouseOverWindows = model.mouseOverWindows.filterNot(_ == id))) + // Window close keys case KeyboardEvent.KeyUp(KeyMapping.CloseWindow) if !model.gameState.isWaitForInput || @@ -42,10 +48,15 @@ object GameSceneUpdate: .map(_.closeAllWindows) case WindowEvent.Closed(HistoryWindow.windowId) => + val filtered = + model.copy(mouseOverWindows = model.mouseOverWindows.filterNot(_ == HistoryWindow.windowId)) WindowStateManager - .updateModel(context, model)(WindowManagerCommand.CloseAll) + .updateModel(context, filtered)(WindowManagerCommand.CloseAll) .map(_.closeAllWindows) + case WindowEvent.Closed(id) => + Outcome(model.copy(mouseOverWindows = model.mouseOverWindows.filterNot(_ == id))) + // Quit window toggle case KeyboardEvent.KeyUp(KeyMapping.Quit1) | KeyboardEvent.KeyUp(KeyMapping.Quit2) if model.gameState.isWaitForInput => diff --git a/roguelike/src/main/scala/roguelike/viewmodel/ViewModel.scala b/roguelike/src/main/scala/roguelike/viewmodel/ViewModel.scala index 9220d24..cc96a4c 100644 --- a/roguelike/src/main/scala/roguelike/viewmodel/ViewModel.scala +++ b/roguelike/src/main/scala/roguelike/viewmodel/ViewModel.scala @@ -85,13 +85,15 @@ final case class GameViewModel( case _: MouseEvent.Click if !WindowStateManager.showingWindow(model) && model.player.position == hoverSquare && - model.gameState.isWaitForInput => + model.gameState.isWaitForInput && + model.gameClickAllowed => Outcome(this) .addGlobalEvents(GameEvent.PlayerTryPickUp) case _: MouseEvent.Click if !WindowStateManager.showingWindow(model) && - model.gameState.isWaitForInput => + model.gameState.isWaitForInput && + model.gameClickAllowed => Outcome(this) .addGlobalEvents(GameEvent.PlayerMoveTowards(hoverSquare))