diff --git a/Assets/Prefabs/Cells/ButtonMine.prefab b/Assets/Prefabs/Cells/ButtonMine.prefab index 30f8400..9b8fdc6 100644 --- a/Assets/Prefabs/Cells/ButtonMine.prefab +++ b/Assets/Prefabs/Cells/ButtonMine.prefab @@ -276,6 +276,7 @@ GameObject: - component: {fileID: 7313243575525116621} - component: {fileID: 8390786300108739894} - component: {fileID: 1091584581727823407} + - component: {fileID: 6241952381746257391} m_Layer: 5 m_Name: ButtonMine m_TagString: Untagged @@ -385,3 +386,20 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &6241952381746257391 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6406400753494049822} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2904d462d22809c499afe1842f6e6239, type: 3} + m_Name: "" + m_EditorClassIdentifier: Assembly-CSharp::Minesweeper.Presentation.Views.CellView + button: {fileID: 1091584581727823407} + backgroundImage: {fileID: 8390786300108739894} + contentRoot: {fileID: 855905148978497855} + contentImage: {fileID: 2245737607582627579} + label: {fileID: 8958233407636047794} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index d52318b..a9da44f 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -636,10 +636,6 @@ MonoBehaviour: k__BackingField: {fileID: 6869455415096409219, guid: 73d5a09dc8885e64a8c20a68ea82c5dc, type: 3} contentRoot: {fileID: 1373940536} topPanelView: {fileID: 1101876296} - mainMenuView: {fileID: 5456992800552396061, guid: 66407cd7142d6a945b37ca8dc5e7c6b7, type: 3} - boardView: {fileID: -4096144217532421454, guid: 91c5885a4fbe47540abf4bfd814a32d0, type: 3} - pauseView: {fileID: 7010459690024596299, guid: ec358f6fec19e3b469f516bd1ade70cd, type: 3} - resultView: {fileID: -2277025653673582644, guid: 73d5a09dc8885e64a8c20a68ea82c5dc, type: 3} --- !u!4 &1287266282 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Commands/GameCommandHandlers.cs b/Assets/Scripts/Commands/GameCommandHandlers.cs index 86e31f4..8d0f84d 100644 --- a/Assets/Scripts/Commands/GameCommandHandlers.cs +++ b/Assets/Scripts/Commands/GameCommandHandlers.cs @@ -197,7 +197,8 @@ namespace Minesweeper.Commands public void Handle(PauseCommand command) { - if (gameStateService.Current == GameState.Playing) + var state = gameStateService.Current; + if (state == GameState.Preparing || state == GameState.Playing) { pauseService.Pause(); } diff --git a/Assets/Scripts/Infrastructure/MinesweeperLifetimeScope.cs b/Assets/Scripts/Infrastructure/MinesweeperLifetimeScope.cs index 4ebd840..7371f0e 100644 --- a/Assets/Scripts/Infrastructure/MinesweeperLifetimeScope.cs +++ b/Assets/Scripts/Infrastructure/MinesweeperLifetimeScope.cs @@ -20,10 +20,6 @@ namespace Minesweeper.Infrastructure [SerializeField] private MinesweeperScreenCatalog screenCatalog = new MinesweeperScreenCatalog(); [SerializeField] private Transform contentRoot; [SerializeField] private TopPanelView topPanelView; - [SerializeField] private MainMenuView mainMenuView; - [SerializeField] private BoardView boardView; - [SerializeField] private PauseView pauseView; - [SerializeField] private ResultView resultView; protected override void Configure(IContainerBuilder builder) { @@ -42,25 +38,6 @@ namespace Minesweeper.Infrastructure builder.Register(Lifetime.Singleton).As(); var screenRefs = SpawnScreens(); - if (screenRefs.MainMenuView != null) - { - mainMenuView = screenRefs.MainMenuView; - } - - if (screenRefs.BoardView != null) - { - boardView = screenRefs.BoardView; - } - - if (screenRefs.PauseView != null) - { - pauseView = screenRefs.PauseView; - } - - if (screenRefs.ResultView != null) - { - resultView = screenRefs.ResultView; - } if (topPanelView != null) { @@ -72,37 +49,37 @@ namespace Minesweeper.Infrastructure builder.Register(Lifetime.Singleton).As(); } - if (mainMenuView != null) + if (screenRefs.MainMenuView != null) { - builder.RegisterComponent(mainMenuView).As(); + builder.RegisterComponent(screenRefs.MainMenuView).As(); } else { builder.Register(Lifetime.Singleton).As(); } - if (boardView != null) + if (screenRefs.BoardView != null) { - boardView.BindConfig(resolvedUiConfig); - builder.RegisterComponent(boardView).As(); + screenRefs.BoardView.BindConfig(resolvedUiConfig); + builder.RegisterComponent(screenRefs.BoardView).As(); } else { builder.Register(Lifetime.Singleton).As(); } - if (pauseView != null) + if (screenRefs.PauseView != null) { - builder.RegisterComponent(pauseView).As(); + builder.RegisterComponent(screenRefs.PauseView).As(); } else { builder.Register(Lifetime.Singleton).As(); } - if (resultView != null) + if (screenRefs.ResultView != null) { - builder.RegisterComponent(resultView).As(); + builder.RegisterComponent(screenRefs.ResultView).As(); } else { diff --git a/Assets/Scripts/Presentation/Presenters/GamePresenter.cs b/Assets/Scripts/Presentation/Presenters/GamePresenter.cs index d2fa82c..eb470a1 100644 --- a/Assets/Scripts/Presentation/Presenters/GamePresenter.cs +++ b/Assets/Scripts/Presentation/Presenters/GamePresenter.cs @@ -130,7 +130,7 @@ namespace Minesweeper.Presentation.Presenters private void OnPauseChanged(bool isPaused) { - if (isPaused && gameStateService.Current == GameState.Playing) + if (isPaused && CanPause(gameStateService.Current)) { pauseView.Show(); } @@ -189,5 +189,10 @@ namespace Minesweeper.Presentation.Presenters { commandDispatcher.Dispatch(new PauseCommand()); } + + private static bool CanPause(GameState state) + { + return state == GameState.Preparing || state == GameState.Playing; + } } } diff --git a/Assets/Scripts/Presentation/Presenters/TopPanelPresenter.cs b/Assets/Scripts/Presentation/Presenters/TopPanelPresenter.cs index 00bc94b..92b3356 100644 --- a/Assets/Scripts/Presentation/Presenters/TopPanelPresenter.cs +++ b/Assets/Scripts/Presentation/Presenters/TopPanelPresenter.cs @@ -75,11 +75,11 @@ namespace Minesweeper.Presentation.Presenters { commandDispatcher.Dispatch(new StartGameCommand()); } - else if (state == GameState.Playing && !pauseService.IsPaused) + else if (CanPause(state) && !pauseService.IsPaused) { commandDispatcher.Dispatch(new PauseCommand()); } - else if (state == GameState.Playing && pauseService.IsPaused) + else if (CanPause(state) && pauseService.IsPaused) { commandDispatcher.Dispatch(new ResumeCommand()); } @@ -126,5 +126,10 @@ namespace Minesweeper.Presentation.Presenters return SmileFaceState.Smile; } + + private static bool CanPause(GameState state) + { + return state == GameState.Preparing || state == GameState.Playing; + } } }