From f0a4354558e24dc39913eca1d33cf87f60f3347f Mon Sep 17 00:00:00 2001 From: Pavel Kurkutov Date: Sun, 14 Feb 2021 20:18:42 +0700 Subject: [PATCH] Refactor --- .../Models/Modals/QuitModalBehaviour.cs | 10 +++ .../Scripts/Models/Modals/QuitModalBody.cs | 90 +++++++++++-------- 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBehaviour.cs b/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBehaviour.cs index 0d2fdae94..08dbf593e 100644 --- a/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBehaviour.cs +++ b/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBehaviour.cs @@ -1,8 +1,18 @@ namespace Assets.Zilon.Scripts.Models.Modals { + /// + /// Behaviour of modal. Specify command and vizualization of modal. + /// public enum QuitModalBehaviour { + /// + /// Ends game session. Go to title menu. + /// QuitToTitleMenu = 1, + + /// + /// Closes game. + /// QuitGame = 2 } } diff --git a/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBody.cs b/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBody.cs index c12fe97c0..f99cec8d4 100644 --- a/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBody.cs +++ b/Zilon.Client/Assets/Zilon/Scripts/Models/Modals/QuitModalBody.cs @@ -18,12 +18,24 @@ public class QuitModalBody : MonoBehaviour, IModalWindowHandler private QuitModalBehaviour _quitModalBehaviour; + /// + /// Text object to display random quit phrase. + /// public Text QuitPhraseText; + /// + /// Caption to Close game. + /// public LocalizedString QuitGameCaption; + /// + /// Caption to end game session. + /// public LocalizedString QuitToTitleMenuCaption; + /// + /// Multiline string with quit phrases. + /// public LocalizedString QuitPhrasesString; [Inject(Id = "quit-command")] @@ -47,6 +59,41 @@ public async void Start() await SetQuitPhrase(); } + public void Init(QuitModalBehaviour quitModalBehaviour) + { + _quitModalBehaviour = quitModalBehaviour; + + switch (quitModalBehaviour) + { + case QuitModalBehaviour.QuitGame: + _targetCommand = _quitCommand; + break; + + case QuitModalBehaviour.QuitToTitleMenu: + _targetCommand = _quitTitleCommand; + break; + + default: + if (Debug.isDebugBuild || Application.isEditor) + { + throw new InvalidOperationException($"Invalid behaviour for quit modal: {quitModalBehaviour}."); + } + break; + } + } + + public void ApplyChanges() + { + _clientCommandExecutor.Push(_targetCommand); + } + + public void CancelChanges() + { + // ничего не делаем + // просто закрываем окно + Closed?.Invoke(this, new EventArgs()); + } + private async Task SetQuitCaption() { var captionLocalizedString = GetCaptionLocalizedStringByBehaviour(_quitModalBehaviour); @@ -86,47 +133,12 @@ private async Task SetQuitPhrase() private static async Task ReadStringFromLocalized(LocalizedString localizedString) { - var _textsAsyncHandler = localizedString.GetLocalizedString(); - if (_textsAsyncHandler.IsDone) + var _textsAsyncHandle = localizedString.GetLocalizedString(); + if (_textsAsyncHandle.IsDone) { - return _textsAsyncHandler.Result; + return _textsAsyncHandle.Result; } - return await _textsAsyncHandler.Task; - } - - public void Init(QuitModalBehaviour quitModalBehaviour) - { - _quitModalBehaviour = quitModalBehaviour; - - switch (quitModalBehaviour) - { - case QuitModalBehaviour.QuitGame: - _targetCommand = _quitCommand; - break; - - case QuitModalBehaviour.QuitToTitleMenu: - _targetCommand = _quitTitleCommand; - break; - - default: - if (Debug.isDebugBuild || Application.isEditor) - { - throw new InvalidOperationException($"Invalid behaviour for quit modal: {quitModalBehaviour}."); - } - break; - } - } - - public void ApplyChanges() - { - _clientCommandExecutor.Push(_targetCommand); - } - - public void CancelChanges() - { - // ничего не делаем - // просто закрываем окно - Closed?.Invoke(this, new EventArgs()); + return await _textsAsyncHandle.Task; } }