From bebe00556d22861e6bde36762346e55800f0f4ed Mon Sep 17 00:00:00 2001 From: David Finol Date: Fri, 13 Jul 2018 11:31:13 -0500 Subject: [PATCH 01/17] Improve error handling --- Assets/Scripts/CGS/CardInfoViewerSelectable.cs | 2 +- Assets/Scripts/UnityExtensionMethods.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/CGS/CardInfoViewerSelectable.cs b/Assets/Scripts/CGS/CardInfoViewerSelectable.cs index 9d6d49bc7..f28a61a2d 100644 --- a/Assets/Scripts/CGS/CardInfoViewerSelectable.cs +++ b/Assets/Scripts/CGS/CardInfoViewerSelectable.cs @@ -18,7 +18,7 @@ public void OnSelect(BaseEventData eventData) public void OnDeselect(BaseEventData eventData) { - if (ignoreDeselect) + if (ignoreDeselect || CardInfoViewer.Instance == null) return; if (!CardInfoViewer.Instance.zoomPanel.gameObject.activeSelf) diff --git a/Assets/Scripts/UnityExtensionMethods.cs b/Assets/Scripts/UnityExtensionMethods.cs index a96dd5b88..5b20ab4f9 100644 --- a/Assets/Scripts/UnityExtensionMethods.cs +++ b/Assets/Scripts/UnityExtensionMethods.cs @@ -175,7 +175,7 @@ public static IEnumerator SaveUrlToFile(string url, string filePath, string post { if (string.IsNullOrEmpty(url) || !Uri.IsWellFormedUriString(url, UriKind.Absolute)) { - Debug.LogWarning("SaveUrlToFile::UrlInvalid:" + url); + Debug.LogWarning("SaveUrlToFile::UrlInvalid:" + url + "," + filePath); yield break; } @@ -183,7 +183,7 @@ public static IEnumerator SaveUrlToFile(string url, string filePath, string post string fileName = Path.GetFileName(filePath); if (string.IsNullOrEmpty(directory) || string.IsNullOrEmpty(fileName)) { - Debug.LogWarning("SaveUrlToFile::FilepathInvalid:" + filePath); + Debug.LogWarning("SaveUrlToFile::FilepathInvalid:" + url + "," + filePath); yield break; } From fdeeaff2403fac4ee366ddbc0aa3162edcea8340 Mon Sep 17 00:00:00 2001 From: David Finol Date: Fri, 13 Jul 2018 15:46:02 -0500 Subject: [PATCH 02/17] Improve ui/ux --- Assets/Scripts/CGS/CardGameManager.cs | 19 ++++++----- Assets/Scripts/CGS/CardInfoViewer.cs | 3 ++ Assets/Scripts/CGS/Menus/DeckLoadMenu.cs | 6 ++-- Assets/Scripts/CGS/Menus/GameSelectionMenu.cs | 9 ++---- Assets/Scripts/CGS/Menus/LobbyMenu.cs | 6 ++-- .../Scripts/CGS/ScrollRects/SelectionPanel.cs | 32 ++++++++++++------- Assets/Scripts/UnityExtensionMethods.cs | 2 +- .../LiberationSans SDF.asset | 28 +++++++++------- ProjectSettings/InputManager.asset | 14 ++++---- docs/pages/keyboard.md | 10 +++--- 10 files changed, 70 insertions(+), 59 deletions(-) diff --git a/Assets/Scripts/CGS/CardGameManager.cs b/Assets/Scripts/CGS/CardGameManager.cs index 0483eaf78..d03249a5a 100644 --- a/Assets/Scripts/CGS/CardGameManager.cs +++ b/Assets/Scripts/CGS/CardGameManager.cs @@ -51,13 +51,13 @@ void Awake() _instance = this; DontDestroyOnLoad(gameObject); - FindCardGames(); - if (AllCardGames.Count < 1) + if (!Directory.Exists(GamesFilePathBase)) CreateDefaultCardGames(); + LookupCardGames(); CardGame currentGame; Current = AllCardGames.TryGetValue(PlayerPrefs.GetString(PlayerPrefGameName, FirstGameName), out currentGame) - ? currentGame : new CardGame(); + ? currentGame : AllCardGames.First().Value; if (Debug.isDebugBuild) Application.logMessageReceived += ShowLogToUser; @@ -67,18 +67,17 @@ void Awake() private void CreateDefaultCardGames() { -#if !UNITY_ANDROID || UNITY_EDITOR - UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, GamesFilePathBase); -#else +#if UNITY_ANDROID && !UNITY_EDITOR UnityExtensionMethods.ExtractAndroidStreamingAssets(GamesFilePathBase); +#else + UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, GamesFilePathBase); #endif - FindCardGames(); } - private void FindCardGames() + private void LookupCardGames() { - if (!Directory.Exists(GamesFilePathBase)) - return; + if (!Directory.Exists(GamesFilePathBase) || Directory.GetDirectories(GamesFilePathBase).Length < 1) + CreateDefaultCardGames(); foreach (string gameDirectory in Directory.GetDirectories(GamesFilePathBase)) { diff --git a/Assets/Scripts/CGS/CardInfoViewer.cs b/Assets/Scripts/CGS/CardInfoViewer.cs index 65eb47c1c..25bf4e188 100644 --- a/Assets/Scripts/CGS/CardInfoViewer.cs +++ b/Assets/Scripts/CGS/CardInfoViewer.cs @@ -39,6 +39,9 @@ void Start() void Update() { + if (IsVisible && EventSystem.current.currentSelectedGameObject == null && !EventSystem.current.alreadySelecting) + EventSystem.current.SetSelectedGameObject(gameObject); + infoPanel.anchorMin = IsVisible ? new Vector2(infoPanel.anchorMin.x, Mathf.Lerp(infoPanel.anchorMin.y, VisibleYMin, AnimationSpeed * Time.deltaTime)) : new Vector2(infoPanel.anchorMin.x, Mathf.Lerp(infoPanel.anchorMin.y, HiddenYmin, AnimationSpeed * Time.deltaTime)); diff --git a/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs b/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs index 43c2de2a5..da66294d4 100644 --- a/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs +++ b/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs @@ -122,7 +122,7 @@ public void BuildDeckFileSelectionOptions() loadFromFileButton.interactable = !string.IsNullOrEmpty(SelectedFileName); } - public void SelectFile(bool isOn, string deckFileName) + public void SelectFile(Toggle toggle, string deckFileName) { if (string.IsNullOrEmpty(deckFileName)) { @@ -133,14 +133,14 @@ public void SelectFile(bool isOn, string deckFileName) return; } - if (isOn) + if (toggle.isOn) { SelectedFileName = deckFileName; shareFileButton.interactable = true; deleteFileButton.interactable = true; loadFromFileButton.interactable = true; } - else if (SelectedFileName.Equals(deckFileName)) + else if (!toggle.group.AnyTogglesOn() && SelectedFileName.Equals(deckFileName)) LoadFromFileAndHide(); } diff --git a/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs b/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs index 574cda591..1f8c9935e 100644 --- a/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs +++ b/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs @@ -73,14 +73,11 @@ public void Show() Rebuild(CardGameManager.Instance.AllCardGames.Keys.ToList(), SelectGame, CardGameManager.Current.Name); } - public void SelectGame(bool isOn, string gameName) + public void SelectGame(Toggle toggle, string gameName) { - if (isOn) - { - gameObject.SetActive(true); + if (toggle.isOn) CardGameManager.Instance.SelectCardGame(gameName); - } - else + else if (!toggle.group.AnyTogglesOn()) Hide(); } diff --git a/Assets/Scripts/CGS/Menus/LobbyMenu.cs b/Assets/Scripts/CGS/Menus/LobbyMenu.cs index 769632c1d..69694cf28 100644 --- a/Assets/Scripts/CGS/Menus/LobbyMenu.cs +++ b/Assets/Scripts/CGS/Menus/LobbyMenu.cs @@ -76,17 +76,17 @@ public IEnumerator WaitToShowDeckLoader() CGSNetManager.Instance.playController.ShowDeckMenu(); } - public void SelectHost(bool isOn, string hostName) + public void SelectHost(Toggle toggle, string hostName) { if (string.IsNullOrEmpty(hostName)) return; - if (isOn) + if (toggle.isOn) { SelectedHost = hostName; joinButton.interactable = true; } - else if (SelectedHost.Equals(hostName)) + else if (!toggle.group.AnyTogglesOn() && SelectedHost.Equals(hostName)) Join(); } diff --git a/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs b/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs index 40a2d7cf6..31eaa723a 100644 --- a/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs +++ b/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs @@ -4,7 +4,7 @@ using UnityEngine.EventSystems; using UnityEngine.UI; -public delegate void OnSelectDelegate (bool isOn, string selection); +public delegate void OnSelectDelegate(Toggle toggle, string selection); public class SelectionPanel : MonoBehaviour { @@ -14,12 +14,12 @@ public class SelectionPanel : MonoBehaviour protected List Toggles { get; } = new List(); - public void Rebuild(List options, OnSelectDelegate valueChange, string currentValue = "") + public void Rebuild(List options, OnSelectDelegate changeValue, string currentValue = "") { if (options == null) options = new List(); - if (valueChange == null) - valueChange = delegate {}; + if (changeValue == null) + changeValue = delegate { }; if (currentValue == null) currentValue = string.Empty; @@ -27,14 +27,15 @@ public void Rebuild(List options, OnSelectDelegate valueChange, string c selectionContent.DestroyAllChildren(); selectionContent.sizeDelta = new Vector2(selectionContent.sizeDelta.x, selectionTemplate.rect.height * options.Count); - foreach (string option in options) { + foreach (string option in options) + { Toggle toggle = Instantiate(selectionTemplate.gameObject, selectionContent).GetOrAddComponent(); toggle.gameObject.SetActive(true); toggle.transform.localScale = Vector3.one; toggle.GetComponentInChildren().text = option; toggle.interactable = true; toggle.isOn = option.Equals(currentValue); - toggle.onValueChanged.AddListener(isOn => valueChange(isOn, option)); + toggle.onValueChanged.AddListener(isOn => changeValue(toggle, option)); Toggles.Add(toggle.gameObject); } @@ -48,7 +49,7 @@ public void Rebuild(List options, OnSelectDelegate valueChange, string c public void ScrollPage(bool scrollUp) { - scrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollRect.verticalNormalizedPosition + scrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollRect.verticalNormalizedPosition + (scrollUp ? 0.1f : -0.1f)); } @@ -57,14 +58,17 @@ public void ScrollToggles(bool scrollUp) if (EventSystem.current.alreadySelecting || Toggles.Count < 1) return; - if (!Toggles.Contains(EventSystem.current.currentSelectedGameObject)) { + if (!Toggles.Contains(EventSystem.current.currentSelectedGameObject)) + { EventSystem.current.SetSelectedGameObject(Toggles[0]); scrollRect.verticalNormalizedPosition = 1f; return; } - if (scrollUp) { - for (int i = Toggles.Count -1; i >= 0; i--) { + if (scrollUp) + { + for (int i = Toggles.Count - 1; i >= 0; i--) + { if (!EventSystem.current.currentSelectedGameObject.Equals(Toggles[i])) continue; i--; @@ -75,8 +79,11 @@ public void ScrollToggles(bool scrollUp) return; } - } else { - for (int i = 0; i < Toggles.Count; i++) { + } + else + { + for (int i = 0; i < Toggles.Count; i++) + { if (!EventSystem.current.currentSelectedGameObject.Equals(Toggles[i])) continue; i++; @@ -88,4 +95,5 @@ public void ScrollToggles(bool scrollUp) } } } + } diff --git a/Assets/Scripts/UnityExtensionMethods.cs b/Assets/Scripts/UnityExtensionMethods.cs index 5b20ab4f9..df8e19b6b 100644 --- a/Assets/Scripts/UnityExtensionMethods.cs +++ b/Assets/Scripts/UnityExtensionMethods.cs @@ -198,7 +198,7 @@ public static IEnumerator SaveUrlToFile(string url, string filePath, string post yield return loader; if (!string.IsNullOrEmpty(loader.error)) { - Debug.LogError(loader.error); + Debug.LogError(url + ":" + loader.error); yield break; } diff --git a/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset b/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset index 64c025fb1..d26c955f7 100644 --- a/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset +++ b/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset @@ -3840,19 +3840,23 @@ MonoBehaviour: yAdvance: 0 xOffset: 0 fallbackFontAssets: [] - fontCreationSettings: - fontSourcePath: - fontSizingMode: 0 - fontSize: 0 - fontPadding: 0 - fontPackingMode: 0 - fontAtlasWidth: 0 - fontAtlasHeight: 0 - fontCharacterSet: 0 + m_CreationSettings: + sourceFontFileName: + sourceFontFileGUID: + pointSizeSamplingMode: 0 + pointSize: 0 + padding: 0 + packingMode: 0 + atlasWidth: 0 + atlasHeight: 0 + characterSetSelectionMode: 0 + characterSequence: + referencedFontAssetGUID: + referencedTextAssetGUID: fontStyle: 0 - fontStlyeModifier: 0 - fontRenderMode: 0 - fontKerning: 0 + fontStyleModifier: 0 + renderMode: 0 + includeFontFeatures: 0 fontWeights: - regularTypeface: {fileID: 0} italicTypeface: {fileID: 0} diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index ed8b44c81..9aa385828 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -140,7 +140,7 @@ InputManager: negativeButton: positiveButton: '`' altNegativeButton: - altPositiveButton: + altPositiveButton: '[' gravity: 1000 dead: 0.001 sensitivity: 1000 @@ -156,7 +156,7 @@ InputManager: negativeButton: positiveButton: tab altNegativeButton: - altPositiveButton: + altPositiveButton: ']' gravity: 1000 dead: 0.001 sensitivity: 1000 @@ -172,7 +172,7 @@ InputManager: negativeButton: positiveButton: f altNegativeButton: - altPositiveButton: + altPositiveButton: \ gravity: 1000 dead: 0.001 sensitivity: 1000 @@ -188,7 +188,7 @@ InputManager: negativeButton: positiveButton: q altNegativeButton: - altPositiveButton: + altPositiveButton: j gravity: 1000 dead: 0.001 sensitivity: 1000 @@ -204,7 +204,7 @@ InputManager: negativeButton: positiveButton: e altNegativeButton: - altPositiveButton: + altPositiveButton: k gravity: 1000 dead: 0.001 sensitivity: 1000 @@ -220,7 +220,7 @@ InputManager: negativeButton: positiveButton: r altNegativeButton: - altPositiveButton: + altPositiveButton: l gravity: 1000 dead: 0.001 sensitivity: 1000 @@ -236,7 +236,7 @@ InputManager: negativeButton: positiveButton: t altNegativeButton: - altPositiveButton: + altPositiveButton: ; gravity: 1000 dead: 0.001 sensitivity: 1000 diff --git a/docs/pages/keyboard.md b/docs/pages/keyboard.md index 3f88ce59e..70f2313db 100644 --- a/docs/pages/keyboard.md +++ b/docs/pages/keyboard.md @@ -9,10 +9,10 @@ If [your CGS device](index.html#play-anywhere) has a keyboard, you can use these - **Cancel**: *Esc* - Exit CGS. - **Horizontal**: *left*, *right* - Select previous/next card game. - **Vertical**: *down*, *up* - Scroll through Main Menu buttons. -- **Sort**: *q* - Brings up the Game Selection Menu. -- **New**: *e* - Start Game. -- **Load**: *r* - Join Game. -- **Save**: *t* - Edit Deck. +- **Sort**: *q* or *j* - Brings up the Game Selection Menu. +- **New**: *e* or *k* - Start Game. +- **Load**: *r* or *l* - Join Game. +- **Save**: *t* or *;* - Edit Deck. - **Filter**: *f* - Brings up the Options Menu. - **Submit**: *Enter* - Click on selected button. @@ -52,7 +52,7 @@ If [your CGS device](index.html#play-anywhere) has a keyboard, you can use these ## Popup - **Cancel**: *Esc* - Cancel/Close. -- **No**: *n* - No. +- **Delete**: *Delete* - No. - **Submit**: *Enter* - Yes/Close. ## Game Selection Menu From 2bc6b4c864d41295c5bb6d7f66be54aa6f86eb55 Mon Sep 17 00:00:00 2001 From: David Finol Date: Fri, 13 Jul 2018 16:10:41 -0500 Subject: [PATCH 03/17] Update selection color --- Assets/Prefabs/Card Model.prefab | 2 +- Assets/Prefabs/Menus/Card Search Menu.prefab | 2 +- Assets/Prefabs/Menus/Components/SFButton.preset | 4 ++-- Assets/Prefabs/Menus/Components/SFToggle.preset | 4 ++-- Assets/Prefabs/Menus/Deck Load Menu.prefab | 2 +- Assets/Prefabs/Menus/Lobby Menu.prefab | 2 +- Assets/Resources/Game Selection Menu.prefab | 2 +- Assets/Scenes/MainMenu.unity | 10 +++++----- Assets/Scripts/CGS/CardModel.cs | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Assets/Prefabs/Card Model.prefab b/Assets/Prefabs/Card Model.prefab index 3b9e2fa81..e0ac6d9e6 100644 --- a/Assets/Prefabs/Card Model.prefab +++ b/Assets/Prefabs/Card Model.prefab @@ -196,7 +196,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7da0cfd7bd166ba43bf3e99b8d74f2e7, type: 3} m_Name: m_EditorClassIdentifier: - localPosition: {x: 0, y: 0} + position: {x: 0, y: 0} rotation: {x: 0, y: 0, z: 0, w: 0} --- !u!114 &114876689799331718 MonoBehaviour: diff --git a/Assets/Prefabs/Menus/Card Search Menu.prefab b/Assets/Prefabs/Menus/Card Search Menu.prefab index a7654df89..bfd4464f8 100644 --- a/Assets/Prefabs/Menus/Card Search Menu.prefab +++ b/Assets/Prefabs/Menus/Card Search Menu.prefab @@ -1380,7 +1380,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 diff --git a/Assets/Prefabs/Menus/Components/SFButton.preset b/Assets/Prefabs/Menus/Components/SFButton.preset index bb7c232a6..2ae0dda67 100644 --- a/Assets/Prefabs/Menus/Components/SFButton.preset +++ b/Assets/Prefabs/Menus/Components/SFButton.preset @@ -70,11 +70,11 @@ Preset: objectReference: {fileID: 0} - target: {fileID: 0} propertyPath: m_Colors.m_HighlightedColor.r - value: 0.88235295 + value: 1 objectReference: {fileID: 0} - target: {fileID: 0} propertyPath: m_Colors.m_HighlightedColor.g - value: 0.42745098 + value: 0.4509804 objectReference: {fileID: 0} - target: {fileID: 0} propertyPath: m_Colors.m_HighlightedColor.b diff --git a/Assets/Prefabs/Menus/Components/SFToggle.preset b/Assets/Prefabs/Menus/Components/SFToggle.preset index e3bff9f7d..8a795ea63 100644 --- a/Assets/Prefabs/Menus/Components/SFToggle.preset +++ b/Assets/Prefabs/Menus/Components/SFToggle.preset @@ -70,11 +70,11 @@ Preset: objectReference: {fileID: 0} - target: {fileID: 0} propertyPath: m_Colors.m_HighlightedColor.r - value: 0.88235295 + value: 1 objectReference: {fileID: 0} - target: {fileID: 0} propertyPath: m_Colors.m_HighlightedColor.g - value: 0.42745098 + value: 0.4509804 objectReference: {fileID: 0} - target: {fileID: 0} propertyPath: m_Colors.m_HighlightedColor.b diff --git a/Assets/Prefabs/Menus/Deck Load Menu.prefab b/Assets/Prefabs/Menus/Deck Load Menu.prefab index 3f028af13..6e46da294 100644 --- a/Assets/Prefabs/Menus/Deck Load Menu.prefab +++ b/Assets/Prefabs/Menus/Deck Load Menu.prefab @@ -3027,7 +3027,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 diff --git a/Assets/Prefabs/Menus/Lobby Menu.prefab b/Assets/Prefabs/Menus/Lobby Menu.prefab index 277dc8f65..e574e267c 100644 --- a/Assets/Prefabs/Menus/Lobby Menu.prefab +++ b/Assets/Prefabs/Menus/Lobby Menu.prefab @@ -512,7 +512,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 diff --git a/Assets/Resources/Game Selection Menu.prefab b/Assets/Resources/Game Selection Menu.prefab index 6e13ed50e..f7fbf41cb 100644 --- a/Assets/Resources/Game Selection Menu.prefab +++ b/Assets/Resources/Game Selection Menu.prefab @@ -2322,7 +2322,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 diff --git a/Assets/Scenes/MainMenu.unity b/Assets/Scenes/MainMenu.unity index a6332363c..7e81cf54c 100644 --- a/Assets/Scenes/MainMenu.unity +++ b/Assets/Scenes/MainMenu.unity @@ -236,7 +236,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 0} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 @@ -876,7 +876,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 0, g: 0.54901963, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 @@ -1233,7 +1233,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 0, g: 0.54901963, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 @@ -1359,7 +1359,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 0, g: 0.54901963, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 @@ -1562,7 +1562,7 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 0, g: 0.54901963, b: 1, a: 1} - m_HighlightedColor: {r: 0.88235295, g: 0.42745098, b: 0, a: 1} + m_HighlightedColor: {r: 1, g: 0.4509804, b: 0, a: 1} m_PressedColor: {r: 0.38875425, g: 0.28925174, b: 0.78676474, a: 1} m_DisabledColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 1} m_ColorMultiplier: 1 diff --git a/Assets/Scripts/CGS/CardModel.cs b/Assets/Scripts/CGS/CardModel.cs index fca17fb47..77ae0337d 100644 --- a/Assets/Scripts/CGS/CardModel.cs +++ b/Assets/Scripts/CGS/CardModel.cs @@ -21,7 +21,7 @@ public enum DragPhase public class CardModel : NetworkBehaviour, IPointerDownHandler, IPointerUpHandler, ISelectHandler, IDeselectHandler, IBeginDragHandler, IDragHandler, IEndDragHandler { public const float MovementSpeed = 600f; - public static readonly Color SelectedHighlightColor = new Color(0.39f, 0.29f, 0.79f); + public static readonly Color SelectedHighlightColor = new Color(1f, 0.45f, 0f); public static readonly Vector2 OutlineHighlightDistance = new Vector2(10, 10); public bool IsOnline => CGSNetManager.Instance != null && CGSNetManager.Instance.isNetworkActive From b50e7e455f391dff343668542e49ccbfeb9de7ca Mon Sep 17 00:00:00 2001 From: David Finol Date: Fri, 13 Jul 2018 16:49:04 -0500 Subject: [PATCH 04/17] Improve error handling --- Assets/Scripts/CardGameDef/CardGame.cs | 3 ++- docs/pages/roadmap.md | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/CardGameDef/CardGame.cs b/Assets/Scripts/CardGameDef/CardGame.cs index 2cc9acff0..ddfe2bbc9 100644 --- a/Assets/Scripts/CardGameDef/CardGame.cs +++ b/Assets/Scripts/CardGameDef/CardGame.cs @@ -257,7 +257,8 @@ public IEnumerator Download() } string setsFilePath = SetsFilePath + (AllSetsUrlZipped ? UnityExtensionMethods.ZipExtension : string.Empty); - yield return UnityExtensionMethods.SaveUrlToFile(AllSetsUrl, setsFilePath); + if (!string.IsNullOrEmpty(AllSetsUrl)) + yield return UnityExtensionMethods.SaveUrlToFile(AllSetsUrl, setsFilePath); yield return UnityExtensionMethods.SaveUrlToFile(BackgroundImageUrl, BackgroundImageFilePath); yield return UnityExtensionMethods.SaveUrlToFile(CardBackImageUrl, CardBackImageFilePath); diff --git a/docs/pages/roadmap.md b/docs/pages/roadmap.md index 8e4e27cde..5f983b72a 100644 --- a/docs/pages/roadmap.md +++ b/docs/pages/roadmap.md @@ -11,6 +11,7 @@ permalink: roadmap.html - Increase maximum zoom out ## Current Sprint +- Add link to json schema validator - In Deck Editor, make search button clear filters and only do search by name in name input field - Show name filter in filters bar (in quotes) - Show condensed value of enum filters in filters bar From 5529659f0b16440a4863987efa7f48965c3d8530 Mon Sep 17 00:00:00 2001 From: David Finol Date: Mon, 16 Jul 2018 04:19:10 -0500 Subject: [PATCH 05/17] Reorganize files --- Assets/{Scripts => }/Editor/BuildCGS.cs | 0 Assets/{Scripts => }/Editor/BuildCGS.cs.meta | 0 Assets/Prefabs/Menus/Card Search Menu.prefab | 6 +- Assets/Scripts/CGS/DeckEditor/DeckEditor.cs | 2 +- .../Scripts/CGS/DeckEditor/SearchResults.cs | 2 +- Assets/Scripts/CGS/Menus/CardSearchMenu.cs | 139 +++++------------- Assets/Scripts/CardGameDef/CardGame.cs | 35 ++--- .../Scripts/CardGameDef/CardSearchFilters.cs | 65 ++++++++ .../CardGameDef/CardSearchFilters.cs.meta | 11 ++ Assets/Scripts/CardGameDef/Deck.cs | 4 +- .../{Editor.meta => CardGameView.meta} | 2 +- .../{CGS => CardGameView}/CardInfoViewer.cs | 0 .../CardInfoViewer.cs.meta | 0 .../CardInfoViewerSelectable.cs | 0 .../CardInfoViewerSelectable.cs.meta | 0 .../{CGS => CardGameView}/CardModel.cs | 0 .../{CGS => CardGameView}/CardModel.cs.meta | 0 .../{CGS => CardGameView}/CardStack.cs | 0 .../{CGS => CardGameView}/CardStack.cs.meta | 0 docs/pages/custom.md | 2 +- docs/pages/roadmap.md | 1 - 21 files changed, 138 insertions(+), 131 deletions(-) rename Assets/{Scripts => }/Editor/BuildCGS.cs (100%) rename Assets/{Scripts => }/Editor/BuildCGS.cs.meta (100%) create mode 100644 Assets/Scripts/CardGameDef/CardSearchFilters.cs create mode 100644 Assets/Scripts/CardGameDef/CardSearchFilters.cs.meta rename Assets/Scripts/{Editor.meta => CardGameView.meta} (77%) rename Assets/Scripts/{CGS => CardGameView}/CardInfoViewer.cs (100%) rename Assets/Scripts/{CGS => CardGameView}/CardInfoViewer.cs.meta (100%) rename Assets/Scripts/{CGS => CardGameView}/CardInfoViewerSelectable.cs (100%) rename Assets/Scripts/{CGS => CardGameView}/CardInfoViewerSelectable.cs.meta (100%) rename Assets/Scripts/{CGS => CardGameView}/CardModel.cs (100%) rename Assets/Scripts/{CGS => CardGameView}/CardModel.cs.meta (100%) rename Assets/Scripts/{CGS => CardGameView}/CardStack.cs (100%) rename Assets/Scripts/{CGS => CardGameView}/CardStack.cs.meta (100%) diff --git a/Assets/Scripts/Editor/BuildCGS.cs b/Assets/Editor/BuildCGS.cs similarity index 100% rename from Assets/Scripts/Editor/BuildCGS.cs rename to Assets/Editor/BuildCGS.cs diff --git a/Assets/Scripts/Editor/BuildCGS.cs.meta b/Assets/Editor/BuildCGS.cs.meta similarity index 100% rename from Assets/Scripts/Editor/BuildCGS.cs.meta rename to Assets/Editor/BuildCGS.cs.meta diff --git a/Assets/Prefabs/Menus/Card Search Menu.prefab b/Assets/Prefabs/Menus/Card Search Menu.prefab index bfd4464f8..1d7a76d32 100644 --- a/Assets/Prefabs/Menus/Card Search Menu.prefab +++ b/Assets/Prefabs/Menus/Card Search Menu.prefab @@ -1804,7 +1804,7 @@ MonoBehaviour: m_PersistentCalls: m_Calls: - m_Target: {fileID: 114126704938545522} - m_MethodName: set_NameFilter + m_MethodName: SetNameFilter m_Mode: 0 m_Arguments: m_ObjectArgument: {fileID: 0} @@ -2022,7 +2022,7 @@ MonoBehaviour: m_PersistentCalls: m_Calls: - m_Target: {fileID: 114126704938545522} - m_MethodName: set_SetCodeFilter + m_MethodName: SetCodeFilter m_Mode: 0 m_Arguments: m_ObjectArgument: {fileID: 0} @@ -2344,7 +2344,7 @@ MonoBehaviour: m_PersistentCalls: m_Calls: - m_Target: {fileID: 114126704938545522} - m_MethodName: set_IdFilter + m_MethodName: SetIdFilter m_Mode: 0 m_Arguments: m_ObjectArgument: {fileID: 0} diff --git a/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs b/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs index 685b5395b..ffc3456b4 100644 --- a/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs +++ b/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs @@ -97,7 +97,7 @@ void Update() if (!CardGameManager.Current.CardNameIsAtTop) LabelCardsInStacks(); - if (CardInfoViewer.Instance.IsVisible || !Input.anyKeyDown || CardGameManager.TopMenuCanvas != null || searchResults.nameInputField.isFocused) + if (CardInfoViewer.Instance.IsVisible || CardGameManager.TopMenuCanvas != null || searchResults.nameInputField.isFocused) return; if (Input.GetButtonDown(Inputs.Sort)) diff --git a/Assets/Scripts/CGS/DeckEditor/SearchResults.cs b/Assets/Scripts/CGS/DeckEditor/SearchResults.cs index d398539fa..104f3dd22 100644 --- a/Assets/Scripts/CGS/DeckEditor/SearchResults.cs +++ b/Assets/Scripts/CGS/DeckEditor/SearchResults.cs @@ -39,7 +39,7 @@ public string SetNameInputField(string nameFilter) public void SetNameFilter(string nameFilter) { - CardSearcher.NameFilter = nameFilter; + CardSearcher.Filters.Name = nameFilter; } public void Search() diff --git a/Assets/Scripts/CGS/Menus/CardSearchMenu.cs b/Assets/Scripts/CGS/Menus/CardSearchMenu.cs index 5fb70f115..fe28863ac 100644 --- a/Assets/Scripts/CGS/Menus/CardSearchMenu.cs +++ b/Assets/Scripts/CGS/Menus/CardSearchMenu.cs @@ -28,16 +28,9 @@ public class CardSearchMenu : MonoBehaviour public List InputFields { get; } = new List(); public List Toggles { get; } = new List(); - public Dictionary StringPropertyFilters { get; } = new Dictionary(); - public Dictionary IntMinPropertyFilters { get; } = new Dictionary(); - public Dictionary IntMaxPropertyFilters { get; } = new Dictionary(); - public Dictionary EnumPropertyFilters { get; } = new Dictionary(); + public CardSearchFilters Filters { get; } = new CardSearchFilters(); public List Results { get; } = new List(); - private string _nameFilter; - private string _idFilter; - private string _setCodeFilter; - void LateUpdate() { if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) @@ -240,7 +233,7 @@ public GameObject CreateStringPropertyFilterPanel(string propertyName, string di SearchPropertyPanel config = newPanel.GetComponent(); config.nameLabelText.text = !string.IsNullOrEmpty(displayName) ? displayName : propertyName; string storedFilter; - if (StringPropertyFilters.TryGetValue(propertyName, out storedFilter)) + if (Filters.StringProperties.TryGetValue(propertyName, out storedFilter)) config.stringInputField.text = storedFilter; config.stringPlaceHolderText.text = "Enter " + propertyName + "..."; config.stringInputField.onValueChanged.AddListener(text => SetStringPropertyFilter(propertyName, text)); @@ -257,11 +250,11 @@ public GameObject CreateIntegerPropertyFilterPanel(string propertyName, string d config.nameLabelText.text = !string.IsNullOrEmpty(displayName) ? displayName : propertyName; int storedFilter; - if (IntMinPropertyFilters.TryGetValue(propertyName, out storedFilter)) + if (Filters.IntMinProperties.TryGetValue(propertyName, out storedFilter)) config.integerMinInputField.text = storedFilter.ToString(); config.integerMinInputField.onValueChanged.AddListener(text => SetIntMinPropertyFilter(propertyName, text)); - if (IntMaxPropertyFilters.TryGetValue(propertyName, out storedFilter)) + if (Filters.IntMaxProperties.TryGetValue(propertyName, out storedFilter)) config.integerMaxInputField.text = storedFilter.ToString(); config.integerMaxInputField.onValueChanged.AddListener(text => SetIntMaxPropertyFilter(propertyName, text)); @@ -276,7 +269,7 @@ public GameObject CreateEnumPropertyFilterPanel(PropertyDef property) SearchPropertyPanel config = newPanel.GetComponent(); config.nameLabelText.text = !string.IsNullOrEmpty(property.Display) ? property.Display : property.Name; int storedFilter; - EnumPropertyFilters.TryGetValue(property.Name, out storedFilter); + Filters.EnumProperties.TryGetValue(property.Name, out storedFilter); EnumDef enumDef = CardGameManager.Current.Enums.First(def => def.Property.Equals(property.Name)); Vector3 localPosition = config.enumToggle.transform.localPosition; @@ -320,16 +313,31 @@ public GameObject CreateEnumPropertyFilterPanel(PropertyDef property) return newPanel; } + public void SetNameFilter(string name) + { + Filters.Name = name; + } + + public void SetIdFilter(string id) + { + Filters.Id = id; + } + + public void SetCodeFilter(string code) + { + Filters.SetCode = code; + } + public void SetStringPropertyFilter(string propertyName, string filterValue) { if (string.IsNullOrEmpty(filterValue)) { - if (StringPropertyFilters.ContainsKey(propertyName)) - StringPropertyFilters.Remove(propertyName); + if (Filters.StringProperties.ContainsKey(propertyName)) + Filters.StringProperties.Remove(propertyName); return; } - StringPropertyFilters[propertyName] = filterValue; + Filters.StringProperties[propertyName] = filterValue; } public void SetIntMinPropertyFilter(string propertyName, string filterValue) @@ -337,12 +345,12 @@ public void SetIntMinPropertyFilter(string propertyName, string filterValue) int intValue; if (!int.TryParse(filterValue, out intValue)) { - if (IntMinPropertyFilters.ContainsKey(propertyName)) - IntMinPropertyFilters.Remove(propertyName); + if (Filters.IntMinProperties.ContainsKey(propertyName)) + Filters.IntMinProperties.Remove(propertyName); return; } - IntMinPropertyFilters[propertyName] = intValue; + Filters.IntMinProperties[propertyName] = intValue; } public void SetIntMaxPropertyFilter(string propertyName, string filterValue) @@ -350,12 +358,12 @@ public void SetIntMaxPropertyFilter(string propertyName, string filterValue) int intValue; if (!int.TryParse(filterValue, out intValue)) { - if (IntMaxPropertyFilters.ContainsKey(propertyName)) - IntMaxPropertyFilters.Remove(propertyName); + if (Filters.IntMaxProperties.ContainsKey(propertyName)) + Filters.IntMaxProperties.Remove(propertyName); return; } - IntMaxPropertyFilters[propertyName] = intValue; + Filters.IntMaxProperties[propertyName] = intValue; } public void SetEnumPropertyFilter(string propertyName, int filterValue, bool isOn) @@ -363,19 +371,19 @@ public void SetEnumPropertyFilter(string propertyName, int filterValue, bool isO if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) return; - bool isStored = EnumPropertyFilters.ContainsKey(propertyName); + bool isStored = Filters.EnumProperties.ContainsKey(propertyName); int storedFilter = 0; if (isStored) - storedFilter = EnumPropertyFilters[propertyName]; + storedFilter = Filters.EnumProperties[propertyName]; int newFilter = isOn ? storedFilter | filterValue : storedFilter & ~filterValue; if (newFilter == 0) { if (isStored) - EnumPropertyFilters.Remove(propertyName); + Filters.EnumProperties.Remove(propertyName); } else - EnumPropertyFilters[propertyName] = newFilter; + Filters.EnumProperties[propertyName] = newFilter; } public void ClearFilters() @@ -385,10 +393,10 @@ public void ClearFilters() foreach (Toggle toggle in GetComponentsInChildren()) toggle.isOn = false; - StringPropertyFilters.Clear(); - IntMinPropertyFilters.Clear(); - IntMaxPropertyFilters.Clear(); - EnumPropertyFilters.Clear(); + Filters.StringProperties.Clear(); + Filters.IntMinProperties.Clear(); + Filters.IntMaxProperties.Clear(); + Filters.EnumProperties.Clear(); } public void ClearSearch() @@ -400,10 +408,10 @@ public void ClearSearch() public void Search() { Results.Clear(); - IEnumerable cardSearcher = CardGameManager.Current.FilterCards(IdFilter, NameFilter, SetCodeFilter, StringPropertyFilters, IntMinPropertyFilters, IntMaxPropertyFilters, EnumPropertyFilters); + IEnumerable cardSearcher = CardGameManager.Current.FilterCards(Filters); foreach (Card card in cardSearcher) Results.Add(card); - SearchCallback?.Invoke(Filters, Results); + SearchCallback?.Invoke(Filters.ToString(), Results); } public void Hide() @@ -411,75 +419,6 @@ public void Hide() gameObject.SetActive(false); } - public string Filters - { - get - { - string filters = string.Empty; - if (!string.IsNullOrEmpty(IdFilter)) - filters += "id:" + IdFilter + "; "; - if (!string.IsNullOrEmpty(SetCodeFilter)) - filters += "set:" + SetCodeFilter + "; "; - foreach (PropertyDef property in CardGameManager.Current.CardProperties) - { - switch (property.Type) - { - case PropertyType.ObjectEnum: - case PropertyType.ObjectEnumList: - case PropertyType.StringEnum: - case PropertyType.StringEnumList: - if (!EnumPropertyFilters.ContainsKey(property.Name)) - break; - EnumDef enumDef = CardGameManager.Current.Enums.FirstOrDefault(def => def.Property.Equals(property.Name)); - if (enumDef != null) - filters += property.Name + ":=" + EnumPropertyFilters[property.Name] + "; "; - break; - case PropertyType.Integer: - if (IntMinPropertyFilters.ContainsKey(property.Name)) - filters += property.Name + ">=" + IntMinPropertyFilters[property.Name] + "; "; - if (IntMaxPropertyFilters.ContainsKey(property.Name)) - filters += property.Name + "<=" + IntMaxPropertyFilters[property.Name] + "; "; - break; - case PropertyType.Object: - case PropertyType.ObjectList: - case PropertyType.Number: - case PropertyType.Boolean: - case PropertyType.StringList: - case PropertyType.EscapedString: - case PropertyType.String: - default: - if (StringPropertyFilters.ContainsKey(property.Name)) - filters += property.Name + ":" + StringPropertyFilters[property.Name] + "; "; - break; - } - } - return filters; - } - } - - public string NameFilter - { - get { return _nameFilter ?? (_nameFilter = string.Empty); } - set - { - _nameFilter = value; - NameChangeCallback?.Invoke(_nameFilter); - if (nameInputField != null) - nameInputField.text = _nameFilter; - } - } - - public string IdFilter - { - get { return _idFilter ?? (_idFilter = string.Empty); } - set { _idFilter = value; } - } - - public string SetCodeFilter - { - get { return _setCodeFilter ?? (_setCodeFilter = string.Empty); } - set { _setCodeFilter = value; } - } public InputField ActiveInputField { get diff --git a/Assets/Scripts/CardGameDef/CardGame.cs b/Assets/Scripts/CardGameDef/CardGame.cs index ddfe2bbc9..ca104cd70 100644 --- a/Assets/Scripts/CardGameDef/CardGame.cs +++ b/Assets/Scripts/CardGameDef/CardGame.cs @@ -500,40 +500,33 @@ public void LoadSetFromJToken(JToken setJToken, string defaultSetCode) LoadCardFromJToken(jToken, setCode); } - public IEnumerable FilterCards(string id, string name, string setCode, Dictionary stringProperties, Dictionary intMinProperties, Dictionary intMaxProperties, Dictionary enumProperties) + public IEnumerable FilterCards(CardSearchFilters filters) { - if (id == null) - id = string.Empty; - if (name == null) - name = string.Empty; - if (setCode == null) - setCode = string.Empty; - if (stringProperties == null) - stringProperties = new Dictionary(); - if (intMinProperties == null) - intMinProperties = new Dictionary(); - if (intMaxProperties == null) - intMaxProperties = new Dictionary(); - if (enumProperties == null) - enumProperties = new Dictionary(); + if (filters == null) + { + UnityEngine.Debug.LogWarning("FilterCards::NullFilters"); + yield break; + } foreach (Card card in Cards.Values) { - if (!name.ToLower().Split(' ').All(card.Name.ToLower().Contains)) + if (!string.IsNullOrEmpty(filters.Name) && !filters.Name.ToLower().Split(' ').All(card.Name.ToLower().Contains)) + continue; + if (!string.IsNullOrEmpty(filters.Id) && !card.Id.ToLower().Contains(filters.Id.ToLower())) continue; - if (!card.Id.ToLower().Contains(id.ToLower()) || !card.SetCode.ToLower().Contains(setCode.ToLower())) + if (!string.IsNullOrEmpty(filters.SetCode) && !card.SetCode.ToLower().Contains(filters.SetCode.ToLower())) continue; bool propsMatch = true; - foreach (KeyValuePair entry in stringProperties) + foreach (KeyValuePair entry in filters.StringProperties) if (!card.GetPropertyValueString(entry.Key).ToLower().Contains(entry.Value.ToLower())) propsMatch = false; - foreach (KeyValuePair entry in intMinProperties) + foreach (KeyValuePair entry in filters.IntMinProperties) if (card.GetPropertyValueInt(entry.Key) < entry.Value) propsMatch = false; - foreach (KeyValuePair entry in intMaxProperties) + foreach (KeyValuePair entry in filters.IntMaxProperties) if (card.GetPropertyValueInt(entry.Key) > entry.Value) propsMatch = false; - foreach (KeyValuePair entry in enumProperties) + foreach (KeyValuePair entry in filters.EnumProperties) { EnumDef enumDef = CardGameManager.Current.Enums.FirstOrDefault(def => def.Property.Equals(entry.Key)); if (enumDef == null) diff --git a/Assets/Scripts/CardGameDef/CardSearchFilters.cs b/Assets/Scripts/CardGameDef/CardSearchFilters.cs new file mode 100644 index 000000000..c16f2b8e7 --- /dev/null +++ b/Assets/Scripts/CardGameDef/CardSearchFilters.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using System.Linq; + +namespace CardGameDef +{ + public class CardSearchFilters + { + public string Id { get; set; } = ""; + + public string Name { get; set; } = ""; + + public string SetCode { get; set; } = ""; + + public Dictionary StringProperties { get; } = new Dictionary(); + + public Dictionary IntMinProperties { get; } = new Dictionary(); + + public Dictionary IntMaxProperties { get; } = new Dictionary(); + + public Dictionary EnumProperties { get; } = new Dictionary(); + + public override string ToString() + { + string filters = string.Empty; + if (!string.IsNullOrEmpty(Id)) + filters += "id:" + Id + "; "; + if (!string.IsNullOrEmpty(SetCode)) + filters += "set:" + SetCode + "; "; + foreach (PropertyDef property in CardGameManager.Current.CardProperties) + { + switch (property.Type) + { + case PropertyType.ObjectEnum: + case PropertyType.ObjectEnumList: + case PropertyType.StringEnum: + case PropertyType.StringEnumList: + if (!EnumProperties.ContainsKey(property.Name)) + break; + EnumDef enumDef = CardGameManager.Current.Enums.FirstOrDefault(def => def.Property.Equals(property.Name)); + if (enumDef != null) + filters += property.Name + ":=" + EnumProperties[property.Name] + "; "; + break; + case PropertyType.Integer: + if (IntMinProperties.ContainsKey(property.Name)) + filters += property.Name + ">=" + IntMinProperties[property.Name] + "; "; + if (IntMaxProperties.ContainsKey(property.Name)) + filters += property.Name + "<=" + IntMaxProperties[property.Name] + "; "; + break; + case PropertyType.Object: + case PropertyType.ObjectList: + case PropertyType.Number: + case PropertyType.Boolean: + case PropertyType.StringList: + case PropertyType.EscapedString: + case PropertyType.String: + default: + if (StringProperties.ContainsKey(property.Name)) + filters += property.Name + ":" + StringProperties[property.Name] + "; "; + break; + } + } + return filters; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/CardGameDef/CardSearchFilters.cs.meta b/Assets/Scripts/CardGameDef/CardSearchFilters.cs.meta new file mode 100644 index 000000000..287ce45e5 --- /dev/null +++ b/Assets/Scripts/CardGameDef/CardSearchFilters.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b1b19c596704eb47a2a20c282df3607 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CardGameDef/Deck.cs b/Assets/Scripts/CardGameDef/Deck.cs index 0e8b3588c..4980e8f33 100644 --- a/Assets/Scripts/CardGameDef/Deck.cs +++ b/Assets/Scripts/CardGameDef/Deck.cs @@ -91,7 +91,7 @@ public void LoadDec(string line) if (tokens.Count > 0 && int.TryParse(tokens[0], out cardCount)) tokens.RemoveAt(0); string cardName = tokens.Count > 0 ? string.Join(" ", tokens.ToArray()) : string.Empty; - IEnumerable cards = CardGameManager.Current.FilterCards(null, cardName, null, null, null, null, null); + IEnumerable cards = CardGameManager.Current.FilterCards(new CardSearchFilters() { Name = cardName }); foreach (Card card in cards) { if (!string.Equals(card.Name, cardName, StringComparison.OrdinalIgnoreCase)) @@ -190,7 +190,7 @@ public void LoadTxt(string line) cardName = tokens.Count > 0 ? string.Join(" ", tokens.ToArray()) : string.Empty; } - IEnumerable cards = CardGameManager.Current.FilterCards(cardId, cardName, cardSet, null, null, null, null); + IEnumerable cards = CardGameManager.Current.FilterCards(new CardSearchFilters() { Id = cardId, Name = cardName, SetCode = cardSet }); foreach (Card card in cards) { if (!card.Id.Equals(cardId) && (!string.Equals(card.Name, cardName, StringComparison.OrdinalIgnoreCase) || diff --git a/Assets/Scripts/Editor.meta b/Assets/Scripts/CardGameView.meta similarity index 77% rename from Assets/Scripts/Editor.meta rename to Assets/Scripts/CardGameView.meta index 67cd2962d..f4d29c571 100644 --- a/Assets/Scripts/Editor.meta +++ b/Assets/Scripts/CardGameView.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a2cdecd882851f84293862b97cdd553c +guid: 05b1c8d1ff09cd74daf7cdd34591aa1f folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/CGS/CardInfoViewer.cs b/Assets/Scripts/CardGameView/CardInfoViewer.cs similarity index 100% rename from Assets/Scripts/CGS/CardInfoViewer.cs rename to Assets/Scripts/CardGameView/CardInfoViewer.cs diff --git a/Assets/Scripts/CGS/CardInfoViewer.cs.meta b/Assets/Scripts/CardGameView/CardInfoViewer.cs.meta similarity index 100% rename from Assets/Scripts/CGS/CardInfoViewer.cs.meta rename to Assets/Scripts/CardGameView/CardInfoViewer.cs.meta diff --git a/Assets/Scripts/CGS/CardInfoViewerSelectable.cs b/Assets/Scripts/CardGameView/CardInfoViewerSelectable.cs similarity index 100% rename from Assets/Scripts/CGS/CardInfoViewerSelectable.cs rename to Assets/Scripts/CardGameView/CardInfoViewerSelectable.cs diff --git a/Assets/Scripts/CGS/CardInfoViewerSelectable.cs.meta b/Assets/Scripts/CardGameView/CardInfoViewerSelectable.cs.meta similarity index 100% rename from Assets/Scripts/CGS/CardInfoViewerSelectable.cs.meta rename to Assets/Scripts/CardGameView/CardInfoViewerSelectable.cs.meta diff --git a/Assets/Scripts/CGS/CardModel.cs b/Assets/Scripts/CardGameView/CardModel.cs similarity index 100% rename from Assets/Scripts/CGS/CardModel.cs rename to Assets/Scripts/CardGameView/CardModel.cs diff --git a/Assets/Scripts/CGS/CardModel.cs.meta b/Assets/Scripts/CardGameView/CardModel.cs.meta similarity index 100% rename from Assets/Scripts/CGS/CardModel.cs.meta rename to Assets/Scripts/CardGameView/CardModel.cs.meta diff --git a/Assets/Scripts/CGS/CardStack.cs b/Assets/Scripts/CardGameView/CardStack.cs similarity index 100% rename from Assets/Scripts/CGS/CardStack.cs rename to Assets/Scripts/CardGameView/CardStack.cs diff --git a/Assets/Scripts/CGS/CardStack.cs.meta b/Assets/Scripts/CardGameView/CardStack.cs.meta similarity index 100% rename from Assets/Scripts/CGS/CardStack.cs.meta rename to Assets/Scripts/CardGameView/CardStack.cs.meta diff --git a/docs/pages/custom.md b/docs/pages/custom.md index 533a2428e..ced0fe6e7 100644 --- a/docs/pages/custom.md +++ b/docs/pages/custom.md @@ -34,7 +34,7 @@ The structure of this custom game folder is: ## JSON File Structure When downloading a custom game from a url, the data that is being downloaded is the contents of the \.json file. CGS generates the rest of the folder structure based off the information in that file. -You can create your own json and validate against these schema: +You can create your own json and [validate](https://jsonschemalint.com/#/version/draft-06/markup/json) against these schema: - [CardGameDef](schema/CardGameDef.json) - [AllCards](schema/AllCards.json) - [AllSets](schema/AllSets.json) diff --git a/docs/pages/roadmap.md b/docs/pages/roadmap.md index 5f983b72a..8e4e27cde 100644 --- a/docs/pages/roadmap.md +++ b/docs/pages/roadmap.md @@ -11,7 +11,6 @@ permalink: roadmap.html - Increase maximum zoom out ## Current Sprint -- Add link to json schema validator - In Deck Editor, make search button clear filters and only do search by name in name input field - Show name filter in filters bar (in quotes) - Show condensed value of enum filters in filters bar From 6753e37404704d0b6a4271c4471c89fca5374e7b Mon Sep 17 00:00:00 2001 From: David Finol Date: Wed, 18 Jul 2018 01:46:11 -0500 Subject: [PATCH 06/17] Reorganize --- Assets/Prefabs/Menus/Deck Load Menu.prefab | 7 +- Assets/Scenes/DeckEditor.unity | 14 +- Assets/Scripts/CGS/CardGameManager.cs | 170 ++++++++------- Assets/Scripts/CGS/DeckEditor/DeckEditor.cs | 2 +- .../Scripts/CGS/DeckEditor/SearchResults.cs | 7 +- Assets/Scripts/CGS/Menus/CardSearchMenu.cs | 76 ++++--- Assets/Scripts/CGS/Menus/DeckLoadMenu.cs | 7 + Assets/Scripts/CGS/Menus/DeckSaveMenu.cs | 4 +- Assets/Scripts/CGS/Menus/DiceMenu.cs | 43 ++-- Assets/Scripts/CGS/Menus/GameSelectionMenu.cs | 1 - Assets/Scripts/CGS/Menus/LobbyMenu.cs | 15 +- Assets/Scripts/CGS/PlayMode/PlayMode.cs | 8 +- .../Scripts/CGS/ScrollRects/SelectionPanel.cs | 1 + Assets/Scripts/CGS/Tags.cs | 8 + Assets/Scripts/CGS/Tags.cs.meta | 11 + Assets/Scripts/CardGameDef/Card.cs | 2 +- Assets/Scripts/CardGameDef/CardGame.cs | 26 +-- .../Scripts/CardGameDef/CardSearchFilters.cs | 11 +- Assets/Scripts/CardGameView/CardInfoViewer.cs | 195 +++++++++--------- docs/pages/roadmap.md | 8 +- 20 files changed, 328 insertions(+), 288 deletions(-) create mode 100644 Assets/Scripts/CGS/Tags.cs create mode 100644 Assets/Scripts/CGS/Tags.cs.meta diff --git a/Assets/Prefabs/Menus/Deck Load Menu.prefab b/Assets/Prefabs/Menus/Deck Load Menu.prefab index 6e46da294..38e272f6e 100644 --- a/Assets/Prefabs/Menus/Deck Load Menu.prefab +++ b/Assets/Prefabs/Menus/Deck Load Menu.prefab @@ -983,6 +983,7 @@ MonoBehaviour: selectionContent: {fileID: 224937724690924458} selectionTemplate: {fileID: 224513094372486550} scrollRect: {fileID: 114606226609976292} + cancelButton: {fileID: 114440245882454988} shareFileButton: {fileID: 114207059650301704} deleteFileButton: {fileID: 114582670716232018} loadFromFileButton: {fileID: 114827358892291670} @@ -2253,7 +2254,7 @@ MonoBehaviour: m_HandleRect: {fileID: 224000485604831812} m_Direction: 2 m_Value: 0 - m_Size: 0.99999446 + m_Size: 0.99998367 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -3324,7 +3325,7 @@ RectTransform: m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 0.99999446} + m_AnchorMax: {x: 1, y: 0.99998367} m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 20, y: 20} m_Pivot: {x: 0.5, y: 0.5} @@ -4087,7 +4088,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -0.000012579555} + m_AnchoredPosition: {x: 0, y: 0.00006396077} m_SizeDelta: {x: 0, y: 150} m_Pivot: {x: 0.5, y: 1} --- !u!224 &224977536836211226 diff --git a/Assets/Scenes/DeckEditor.unity b/Assets/Scenes/DeckEditor.unity index 63f3ad74d..b491cabd6 100644 --- a/Assets/Scenes/DeckEditor.unity +++ b/Assets/Scenes/DeckEditor.unity @@ -629,7 +629,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0.000034322762, y: 0} + m_AnchoredPosition: {x: -0.000022224247, y: 0} m_SizeDelta: {x: 0, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &179835150 @@ -722,7 +722,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -0.000045761146, y: 0} + m_AnchoredPosition: {x: 0.000002341923, y: 0} m_SizeDelta: {x: 0, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &196520020 @@ -2234,7 +2234,7 @@ MonoBehaviour: m_PersistentCalls: m_Calls: - m_Target: {fileID: 62766703} - m_MethodName: Search + m_MethodName: ClearSearchName m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} @@ -2473,7 +2473,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -0.000038166, y: 0} + m_AnchoredPosition: {x: -0.00010915344, y: 0} m_SizeDelta: {x: 0, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &796070842 @@ -2598,7 +2598,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0.00003052519, y: 0} + m_AnchoredPosition: {x: -0.000022888184, y: 0} m_SizeDelta: {x: 0, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &836546758 @@ -2952,7 +2952,7 @@ MonoBehaviour: m_HandleRect: {fileID: 335690429} m_Direction: 0 m_Value: 0 - m_Size: 0.98539513 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -4623,7 +4623,7 @@ MonoBehaviour: m_PersistentCalls: m_Calls: - m_Target: {fileID: 62766703} - m_MethodName: Search + m_MethodName: ClearSearchName m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} diff --git a/Assets/Scripts/CGS/CardGameManager.cs b/Assets/Scripts/CGS/CardGameManager.cs index d03249a5a..0724c9e35 100644 --- a/Assets/Scripts/CGS/CardGameManager.cs +++ b/Assets/Scripts/CGS/CardGameManager.cs @@ -12,20 +12,32 @@ public class CardGameManager : MonoBehaviour { - public const string CardGameManagerTag = "CardGameManager"; - public const string BackgroundImageTag = "Background"; - public const string CardCanvasTag = "CardCanvas"; - public const string MenuCanvasTag = "MenuCanvas"; - public const string SelectorPrefabName = "Game Selection Menu"; public const string PlayerPrefGameName = "DefaultGame"; - public const string FirstGameName = "Standard Playing Cards"; + public const string SelectorPrefabName = "Game Selection Menu"; public const string MessengerPrefabName = "Popup"; public const string InvalidGameSelectionMessage = "Could not select the card game because the name is not recognized in the list of card games! Try selecting a different card game."; public const string GameLoadErrorMessage = "Error loading game!: "; public const string GameDeleteErrorMessage = "Error deleting game!: "; public const int PixelsPerInch = 100; - public static string GamesFilePathBase => Application.persistentDataPath + "/games"; + public static CardGameManager Instance + { + get + { + if (IsQuitting) return null; + if (_instance != null) return _instance; + GameObject cardGameManager = GameObject.FindGameObjectWithTag(Tags.CardGameManager); + if (cardGameManager == null) + { + cardGameManager = new GameObject(Tags.CardGameManager) { tag = Tags.CardGameManager }; + cardGameManager.transform.position = Vector3.zero; + } + _instance = cardGameManager.GetOrAddComponent(); + return _instance; + } + } + private static CardGameManager _instance; + public static CardGame Current { get; private set; } = new CardGame(); public static bool IsQuitting { get; private set; } @@ -36,11 +48,65 @@ public class CardGameManager : MonoBehaviour public LobbyDiscovery Discovery => _discovery ?? (_discovery = gameObject.GetOrAddComponent()); - private static CardGameManager _instance; private GameSelectionMenu _selector; + public GameSelectionMenu Selector + { + get + { + if (_selector != null) return _selector; + _selector = Instantiate(Resources.Load(SelectorPrefabName)).GetOrAddComponent(); + _selector.transform.SetParent(null); + return _selector; + } + } + private Popup _messenger; + public Popup Messenger + { + get + { + if (_messenger != null) return _messenger; + _messenger = Instantiate(Resources.Load(MessengerPrefabName)).GetOrAddComponent(); + _messenger.transform.SetParent(transform); + return _messenger; + } + } private Image _backgroundImage; + public Image BackgroundImage + { + get + { + if (_backgroundImage == null && GameObject.FindGameObjectWithTag(Tags.BackgroundImage) != null) + _backgroundImage = GameObject.FindGameObjectWithTag(Tags.BackgroundImage).GetOrAddComponent(); + return _backgroundImage; + } + } + + public static Canvas TopCardCanvas + { + get + { + Canvas topCanvas = null; + foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(Tags.CardCanvas)) + if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) + topCanvas = canvas.GetComponent(); + return topCanvas; + } + } + + public static Canvas TopMenuCanvas + { + get + { + Canvas topCanvas = null; + foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(Tags.MenuCanvas)) + if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) + topCanvas = canvas.GetComponent(); + return topCanvas; + } + } + void Awake() { if (_instance != null && _instance != this) @@ -51,12 +117,12 @@ void Awake() _instance = this; DontDestroyOnLoad(gameObject); - if (!Directory.Exists(GamesFilePathBase)) + if (!Directory.Exists(CardGame.GamesDirectoryPath)) CreateDefaultCardGames(); LookupCardGames(); CardGame currentGame; - Current = AllCardGames.TryGetValue(PlayerPrefs.GetString(PlayerPrefGameName, FirstGameName), out currentGame) + Current = AllCardGames.TryGetValue(PlayerPrefs.GetString(PlayerPrefGameName), out currentGame) ? currentGame : AllCardGames.First().Value; if (Debug.isDebugBuild) @@ -68,20 +134,20 @@ void Awake() private void CreateDefaultCardGames() { #if UNITY_ANDROID && !UNITY_EDITOR - UnityExtensionMethods.ExtractAndroidStreamingAssets(GamesFilePathBase); + UnityExtensionMethods.ExtractAndroidStreamingAssets(CardGame.GamesDirectoryPath); #else - UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, GamesFilePathBase); + UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, CardGame.GamesDirectoryPath); #endif } private void LookupCardGames() { - if (!Directory.Exists(GamesFilePathBase) || Directory.GetDirectories(GamesFilePathBase).Length < 1) + if (!Directory.Exists(CardGame.GamesDirectoryPath) || Directory.GetDirectories(CardGame.GamesDirectoryPath).Length < 1) CreateDefaultCardGames(); - foreach (string gameDirectory in Directory.GetDirectories(GamesFilePathBase)) + foreach (string gameDirectory in Directory.GetDirectories(CardGame.GamesDirectoryPath)) { - string gameName = gameDirectory.Substring(GamesFilePathBase.Length + 1); + string gameName = gameDirectory.Substring(CardGame.GamesDirectoryPath.Length + 1); AllCardGames[gameName] = new CardGame(gameName, string.Empty); } } @@ -204,7 +270,7 @@ public void DeleteGame() { try { - Directory.Delete(Current.FilePathBase, true); + Directory.Delete(Current.GameFolderPath, true); AllCardGames.Remove(Current.Name); SelectCardGame(AllCardGames.Keys.First()); Selector.Show(); @@ -224,76 +290,4 @@ void OnApplicationQuit() { IsQuitting = true; } - - public static CardGameManager Instance - { - get - { - if (IsQuitting) return null; - if (_instance != null) return _instance; - GameObject cardGameManager = GameObject.FindGameObjectWithTag(CardGameManagerTag); - if (cardGameManager == null) - { - cardGameManager = new GameObject(CardGameManagerTag) { tag = CardGameManagerTag }; - cardGameManager.transform.position = Vector3.zero; - } - _instance = cardGameManager.GetOrAddComponent(); - return _instance; - } - } - - public GameSelectionMenu Selector - { - get - { - if (_selector != null) return _selector; - _selector = Instantiate(Resources.Load(SelectorPrefabName)).GetOrAddComponent(); - _selector.transform.SetParent(null); - return _selector; - } - } - - public Popup Messenger - { - get - { - if (_messenger != null) return _messenger; - _messenger = Instantiate(Resources.Load(MessengerPrefabName)).GetOrAddComponent(); - _messenger.transform.SetParent(transform); - return _messenger; - } - } - public Image BackgroundImage - { - get - { - if (_backgroundImage == null && GameObject.FindGameObjectWithTag(BackgroundImageTag) != null) - _backgroundImage = GameObject.FindGameObjectWithTag(BackgroundImageTag).GetOrAddComponent(); - return _backgroundImage; - } - } - - public static Canvas TopCardCanvas - { - get - { - Canvas topCanvas = null; - foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(CardCanvasTag)) - if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) - topCanvas = canvas.GetComponent(); - return topCanvas; - } - } - - public static Canvas TopMenuCanvas - { - get - { - Canvas topCanvas = null; - foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(MenuCanvasTag)) - if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) - topCanvas = canvas.GetComponent(); - return topCanvas; - } - } } diff --git a/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs b/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs index ffc3456b4..6d26c3a0f 100644 --- a/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs +++ b/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs @@ -5,7 +5,7 @@ using UnityEngine.SceneManagement; using CardGameDef; -public delegate string OnDeckNameChangeDelegate(string newName); +public delegate string OnNameChangeDelegate(string newName); public class DeckEditor : MonoBehaviour, ICardDropHandler { diff --git a/Assets/Scripts/CGS/DeckEditor/SearchResults.cs b/Assets/Scripts/CGS/DeckEditor/SearchResults.cs index 104f3dd22..f5e04be1d 100644 --- a/Assets/Scripts/CGS/DeckEditor/SearchResults.cs +++ b/Assets/Scripts/CGS/DeckEditor/SearchResults.cs @@ -39,7 +39,12 @@ public string SetNameInputField(string nameFilter) public void SetNameFilter(string nameFilter) { - CardSearcher.Filters.Name = nameFilter; + CardSearcher.SetNameFilter(nameFilter); + } + + public void ClearSearchName() + { + CardSearcher.ClearSearchName(); } public void Search() diff --git a/Assets/Scripts/CGS/Menus/CardSearchMenu.cs b/Assets/Scripts/CGS/Menus/CardSearchMenu.cs index fe28863ac..bdbe64aa0 100644 --- a/Assets/Scripts/CGS/Menus/CardSearchMenu.cs +++ b/Assets/Scripts/CGS/Menus/CardSearchMenu.cs @@ -21,7 +21,7 @@ public class CardSearchMenu : MonoBehaviour public SearchPropertyPanel integerPropertyPanel; public SearchPropertyPanel enumPropertyPanel; - public OnDeckNameChangeDelegate NameChangeCallback { get; set; } + public OnNameChangeDelegate NameChangeCallback { get; set; } public OnSearchDelegate SearchCallback { get; set; } public List FilterPanels { get; } = new List(); @@ -31,6 +31,34 @@ public class CardSearchMenu : MonoBehaviour public CardSearchFilters Filters { get; } = new CardSearchFilters(); public List Results { get; } = new List(); + public InputField ActiveInputField + { + get + { + return EventSystem.current.currentSelectedGameObject != null + ? EventSystem.current.currentSelectedGameObject?.GetComponent() : null; + } + set + { + if (!EventSystem.current.alreadySelecting) + EventSystem.current.SetSelectedGameObject(value.gameObject); + } + } + + public Toggle ActiveToggle + { + get + { + return EventSystem.current.currentSelectedGameObject != null + ? EventSystem.current.currentSelectedGameObject.GetComponent() : null; + } + set + { + if (!EventSystem.current.alreadySelecting) + EventSystem.current.SetSelectedGameObject(value.gameObject); + } + } + void LateUpdate() { if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) @@ -179,7 +207,7 @@ public void ToggleEnum() ActiveToggle.isOn = !ActiveToggle.isOn; } - public void Show(OnDeckNameChangeDelegate nameChangeCallback, OnSearchDelegate searchCallback) + public void Show(OnNameChangeDelegate nameChangeCallback, OnSearchDelegate searchCallback) { gameObject.SetActive(true); transform.SetAsLastSibling(); @@ -315,7 +343,10 @@ public GameObject CreateEnumPropertyFilterPanel(PropertyDef property) public void SetNameFilter(string name) { - Filters.Name = name; + Filters.Name = NameChangeCallback != null ? NameChangeCallback(name) : name; + + if (!nameInputField.text.Equals(Filters.Name)) + nameInputField.text = Filters.Name; } public void SetIdFilter(string id) @@ -393,6 +424,9 @@ public void ClearFilters() foreach (Toggle toggle in GetComponentsInChildren()) toggle.isOn = false; + Filters.Name = string.Empty; + Filters.Id = string.Empty; + Filters.SetCode = string.Empty; Filters.StringProperties.Clear(); Filters.IntMinProperties.Clear(); Filters.IntMaxProperties.Clear(); @@ -405,6 +439,14 @@ public void ClearSearch() Search(); } + public void ClearSearchName() + { + string name = Filters.Name; + ClearFilters(); + SetNameFilter(name); + Search(); + } + public void Search() { Results.Clear(); @@ -418,32 +460,4 @@ public void Hide() { gameObject.SetActive(false); } - - public InputField ActiveInputField - { - get - { - return EventSystem.current.currentSelectedGameObject != null - ? EventSystem.current.currentSelectedGameObject?.GetComponent() : null; - } - set - { - if (!EventSystem.current.alreadySelecting) - EventSystem.current.SetSelectedGameObject(value.gameObject); - } - } - - public Toggle ActiveToggle - { - get - { - return EventSystem.current.currentSelectedGameObject != null - ? EventSystem.current.currentSelectedGameObject.GetComponent() : null; - } - set - { - if (!EventSystem.current.alreadySelecting) - EventSystem.current.SetSelectedGameObject(value.gameObject); - } - } } diff --git a/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs b/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs index da66294d4..9059e9cca 100644 --- a/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs +++ b/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs @@ -202,6 +202,7 @@ public void LoadFromFileAndHide() Deck newDeck = Deck.Parse(SelectedFileName, CardGameManager.Current.DeckFileType, deckText); LoadCallback?.Invoke(newDeck); + ResetCancelButton(); Hide(); } @@ -262,6 +263,12 @@ public void HideNewDeckPanel() newDeckPanel.gameObject.SetActive(false); } + public void ResetCancelButton() + { + cancelButton.onClick.RemoveAllListeners(); + cancelButton.onClick.AddListener(Hide); + } + public void Hide() { gameObject.SetActive(false); diff --git a/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs b/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs index e01977d1a..87486c3b0 100644 --- a/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs +++ b/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs @@ -17,7 +17,7 @@ public class DeckSaveMenu : MonoBehaviour public TMPro.TMP_Text textOutputArea; public Deck CurrentDeck { get; private set; } - public OnDeckNameChangeDelegate NameChangeCallback { get; private set; } + public OnNameChangeDelegate NameChangeCallback { get; private set; } public OnDeckSavedDelegate DeckSaveCallback { get; private set; } public bool DoesAutoOverwrite { get; private set; } @@ -36,7 +36,7 @@ void LateUpdate() Hide(); } - public void Show(Deck deckToShow, OnDeckNameChangeDelegate nameChangeCallback = null, OnDeckSavedDelegate deckSaveCallback = null, bool overwrite = false) + public void Show(Deck deckToShow, OnNameChangeDelegate nameChangeCallback = null, OnDeckSavedDelegate deckSaveCallback = null, bool overwrite = false) { gameObject.SetActive(true); transform.SetAsLastSibling(); diff --git a/Assets/Scripts/CGS/Menus/DiceMenu.cs b/Assets/Scripts/CGS/Menus/DiceMenu.cs index a14f13d9e..4c0ceae35 100644 --- a/Assets/Scripts/CGS/Menus/DiceMenu.cs +++ b/Assets/Scripts/CGS/Menus/DiceMenu.cs @@ -10,11 +10,30 @@ public class DiceMenu : MonoBehaviour public Text minText; public Text maxText; - protected RectTransform Target { get; set; } - + public int Min + { + get { return _min; } + set + { + _min = value; + minText.text = _min.ToString(); + } + } private int _min; + + public int Max + { + get { return _max; } + set + { + _max = value; + maxText.text = _max.ToString(); + } + } private int _max; + protected RectTransform Target { get; set; } + void Start() { Min = DefaultMin; @@ -72,24 +91,4 @@ public void Hide() { gameObject.SetActive(false); } - - public int Min - { - get { return _min; } - set - { - _min = value; - minText.text = _min.ToString(); - } - } - - public int Max - { - get { return _max; } - set - { - _max = value; - maxText.text = _max.ToString(); - } - } } diff --git a/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs b/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs index 1f8c9935e..bef85beb1 100644 --- a/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs +++ b/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs @@ -16,7 +16,6 @@ public class GameSelectionMenu : SelectionPanel public RectTransform downloadPanel; public InputField urlInput; - public Button cancelButton; public Button downloadButton; void Update() diff --git a/Assets/Scripts/CGS/Menus/LobbyMenu.cs b/Assets/Scripts/CGS/Menus/LobbyMenu.cs index 69694cf28..5893d0b69 100644 --- a/Assets/Scripts/CGS/Menus/LobbyMenu.cs +++ b/Assets/Scripts/CGS/Menus/LobbyMenu.cs @@ -2,13 +2,13 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; +using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.Networking; using UnityEngine.UI; public class LobbyMenu : SelectionPanel { - public Button cancelButton; public Button joinButton; public List HostNames { get; private set; } = new List(); @@ -33,11 +33,14 @@ void Update() Hide(); } - public void Show() + public void Show(UnityAction cancelAction) { gameObject.SetActive(true); transform.SetAsLastSibling(); + cancelButton.onClick.RemoveAllListeners(); + cancelButton.onClick.AddListener(cancelAction); + HostNames.Clear(); SelectedHost = string.Empty; Rebuild(HostNames, SelectHost, SelectedHost); @@ -63,17 +66,19 @@ public void DisplayHosts(List hostNames) Rebuild(HostNames, SelectHost, SelectedHost); } - public void Host() + public void Host(UnityAction cancelAction = null) { NetworkManager.singleton.StartHost(); - NetworkManager.singleton.StartCoroutine(WaitToShowDeckLoader()); + NetworkManager.singleton.StartCoroutine(WaitToShowDeckLoader(cancelAction)); Hide(); } - public IEnumerator WaitToShowDeckLoader() + public IEnumerator WaitToShowDeckLoader(UnityAction cancelAction) { yield return null; CGSNetManager.Instance.playController.ShowDeckMenu(); + CGSNetManager.Instance.playController.DeckLoader.cancelButton.onClick.RemoveAllListeners(); + CGSNetManager.Instance.playController.DeckLoader.cancelButton.onClick.AddListener(cancelAction); } public void SelectHost(Toggle toggle, string hostName) diff --git a/Assets/Scripts/CGS/PlayMode/PlayMode.cs b/Assets/Scripts/CGS/PlayMode/PlayMode.cs index eb6e6e868..0875fb476 100644 --- a/Assets/Scripts/CGS/PlayMode/PlayMode.cs +++ b/Assets/Scripts/CGS/PlayMode/PlayMode.cs @@ -42,13 +42,9 @@ void Start() playAreaContent.gameObject.GetOrAddComponent().OnAddCardActions.Add(AddCardToPlay); if (CardGameManager.Instance.Discovery.HasReceivedBroadcast) - { - Lobby.cancelButton.onClick.RemoveAllListeners(); - Lobby.cancelButton.onClick.AddListener(BackToMainMenu); - Lobby.Show(); - } + Lobby.Show(BackToMainMenu); else - Lobby.Host(); + Lobby.Host(BackToMainMenu); } void Update() diff --git a/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs b/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs index 31eaa723a..de751ebe8 100644 --- a/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs +++ b/Assets/Scripts/CGS/ScrollRects/SelectionPanel.cs @@ -11,6 +11,7 @@ public class SelectionPanel : MonoBehaviour public RectTransform selectionContent; public RectTransform selectionTemplate; public ScrollRect scrollRect; + public Button cancelButton; protected List Toggles { get; } = new List(); diff --git a/Assets/Scripts/CGS/Tags.cs b/Assets/Scripts/CGS/Tags.cs new file mode 100644 index 000000000..19507a551 --- /dev/null +++ b/Assets/Scripts/CGS/Tags.cs @@ -0,0 +1,8 @@ +public static class Tags +{ + public const string CardGameManager = "CardGameManager"; + public const string BackgroundImage = "Background"; + public const string CardInfoViewer = "CardInfoViewer"; + public const string CardCanvas = "CardCanvas"; + public const string MenuCanvas = "MenuCanvas"; +} diff --git a/Assets/Scripts/CGS/Tags.cs.meta b/Assets/Scripts/CGS/Tags.cs.meta new file mode 100644 index 000000000..f6594537f --- /dev/null +++ b/Assets/Scripts/CGS/Tags.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 976440f7cafe97442b106f5495bf8f0a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CardGameDef/Card.cs b/Assets/Scripts/CardGameDef/Card.cs index b0b5f9e44..a2fda0378 100644 --- a/Assets/Scripts/CardGameDef/Card.cs +++ b/Assets/Scripts/CardGameDef/Card.cs @@ -20,7 +20,7 @@ public class Card : IComparable, IEquatable public bool IsLoadingImage { get; set; } public string ImageFileName => UnityExtensionMethods.GetSafeFileName(Id + "." + CardGameManager.Current.CardImageFileType); - public string ImageFilePath => UnityExtensionMethods.GetSafeFilePath(CardGameManager.Current.FilePathBase + "/sets/" + SetCode + "/") + ImageFileName; + public string ImageFilePath => UnityExtensionMethods.GetSafeFilePath(CardGameManager.Current.GameFolderPath + "/sets/" + SetCode + "/") + ImageFileName; public string ImageWebUrl { get diff --git a/Assets/Scripts/CardGameDef/CardGame.cs b/Assets/Scripts/CardGameDef/CardGame.cs index ca104cd70..37dbe5db9 100644 --- a/Assets/Scripts/CardGameDef/CardGame.cs +++ b/Assets/Scripts/CardGameDef/CardGame.cs @@ -17,14 +17,16 @@ public class CardGame public const string BackgroundImageFileName = "Background"; public const string CardBackImageFileName = "CardBack"; - public string FilePathBase => CardGameManager.GamesFilePathBase + "/" + Name; - public string ConfigFilePath => FilePathBase + "/" + Name + ".json"; - public string CardsFilePath => FilePathBase + "/AllCards.json"; - public string SetsFilePath => FilePathBase + "/AllSets.json"; - public string BackgroundImageFilePath => FilePathBase + "/" + BackgroundImageFileName + "." + BackgroundImageFileType; - public string CardBackImageFilePath => FilePathBase + "/" + CardBackImageFileName + "." + CardBackImageFileType; - public string DecksFilePath => FilePathBase + "/decks"; - public string GameBoardsFilePath => FilePathBase + "/boards"; + public static string GamesDirectoryPath => UnityEngine.Application.persistentDataPath + "/games"; + + public string GameFolderPath => GamesDirectoryPath + "/" + Name; + public string ConfigFilePath => GameFolderPath + "/" + Name + ".json"; + public string CardsFilePath => GameFolderPath + "/AllCards.json"; + public string SetsFilePath => GameFolderPath + "/AllSets.json"; + public string BackgroundImageFilePath => GameFolderPath + "/" + BackgroundImageFileName + "." + BackgroundImageFileType; + public string CardBackImageFilePath => GameFolderPath + "/" + CardBackImageFileName + "." + CardBackImageFileType; + public string DecksFilePath => GameFolderPath + "/decks"; + public string GameBoardsFilePath => GameFolderPath + "/boards"; public float CardAspectRatio => CardSize.y > 0 ? UnityEngine.Mathf.Abs(CardSize.x / CardSize.y) : 0.715f; public IReadOnlyDictionary Cards => LoadedCards; @@ -214,7 +216,7 @@ public IEnumerator Download() yield break; IsDownloading = true; - string initialDirectory = FilePathBase; + string initialDirectory = GameFolderPath; yield return UnityExtensionMethods.SaveUrlToFile(AutoUpdateUrl, ConfigFilePath); try { @@ -227,7 +229,7 @@ public IEnumerator Download() IsDownloading = false; yield break; } - if (!initialDirectory.Equals(FilePathBase)) + if (!initialDirectory.Equals(GameFolderPath)) { CardGameManager.Instance.StartCoroutine(UnityExtensionMethods.SaveUrlToFile(AutoUpdateUrl, ConfigFilePath)); Directory.Delete(initialDirectory, true); @@ -325,7 +327,7 @@ private void LoadCards(int page) try { if (AllCardsUrlZipped) - UnityExtensionMethods.ExtractZip(cardsFilePath + UnityExtensionMethods.ZipExtension, FilePathBase); + UnityExtensionMethods.ExtractZip(cardsFilePath + UnityExtensionMethods.ZipExtension, GameFolderPath); if (AllCardsUrlWrapped) UnityExtensionMethods.UnwrapFile(cardsFilePath); LoadJsonFromFile(cardsFilePath, LoadCardFromJToken, CardDataIdentifier); @@ -339,7 +341,7 @@ private void LoadCards(int page) private void LoadSets() { if (AllSetsUrlZipped) - UnityExtensionMethods.ExtractZip(SetsFilePath + UnityExtensionMethods.ZipExtension, FilePathBase); + UnityExtensionMethods.ExtractZip(SetsFilePath + UnityExtensionMethods.ZipExtension, GameFolderPath); if (AllSetsUrlWrapped) UnityExtensionMethods.UnwrapFile(SetsFilePath); LoadJsonFromFile(SetsFilePath, LoadSetFromJToken, SetDataIdentifier); diff --git a/Assets/Scripts/CardGameDef/CardSearchFilters.cs b/Assets/Scripts/CardGameDef/CardSearchFilters.cs index c16f2b8e7..8b3320c5a 100644 --- a/Assets/Scripts/CardGameDef/CardSearchFilters.cs +++ b/Assets/Scripts/CardGameDef/CardSearchFilters.cs @@ -22,6 +22,8 @@ public class CardSearchFilters public override string ToString() { string filters = string.Empty; + if (!string.IsNullOrEmpty(Name)) + filters += "name:\"" + Name + "\"; "; if (!string.IsNullOrEmpty(Id)) filters += "id:" + Id + "; "; if (!string.IsNullOrEmpty(SetCode)) @@ -38,7 +40,12 @@ public override string ToString() break; EnumDef enumDef = CardGameManager.Current.Enums.FirstOrDefault(def => def.Property.Equals(property.Name)); if (enumDef != null) - filters += property.Name + ":=" + EnumProperties[property.Name] + "; "; + { + string filterValue = enumDef.GetStringFromLookupFlags(EnumProperties[property.Name]); + if (filterValue.Contains(' ')) + filterValue = "\'" + filterValue + "\'"; + filters += property.Name + ":" + filterValue + "; "; + } break; case PropertyType.Integer: if (IntMinProperties.ContainsKey(property.Name)) @@ -55,7 +62,7 @@ public override string ToString() case PropertyType.String: default: if (StringProperties.ContainsKey(property.Name)) - filters += property.Name + ":" + StringProperties[property.Name] + "; "; + filters += property.Name + ":\"" + StringProperties[property.Name] + "\"; "; break; } } diff --git a/Assets/Scripts/CardGameView/CardInfoViewer.cs b/Assets/Scripts/CardGameView/CardInfoViewer.cs index 25bf4e188..1d3a1fa6a 100644 --- a/Assets/Scripts/CardGameView/CardInfoViewer.cs +++ b/Assets/Scripts/CardGameView/CardInfoViewer.cs @@ -6,7 +6,6 @@ public class CardInfoViewer : MonoBehaviour, IPointerDownHandler, ISelectHandler, IDeselectHandler { - public const string CardInfoViewerTag = "CardInfoViewer"; public const string SetLabel = "Set"; public const float VisibleYMin = 0.625f; public const float VisibleYMax = 1; @@ -14,6 +13,20 @@ public class CardInfoViewer : MonoBehaviour, IPointerDownHandler, ISelectHandler public const float HiddenYMax = 1.4f; public const float AnimationSpeed = 5.0f; + public static CardInfoViewer Instance + { + get + { + if (_instance != null) + return _instance; + + GameObject cardInfoViewer = GameObject.FindWithTag(Tags.CardInfoViewer); + _instance = cardInfoViewer?.GetOrAddComponent(); + return _instance; + } + } + private static CardInfoViewer _instance; + public RectTransform infoPanel; public RectTransform zoomPanel; public Image cardImage; @@ -27,10 +40,90 @@ public class CardInfoViewer : MonoBehaviour, IPointerDownHandler, ISelectHandler public List PropertyOptions { get; } = new List(); public Dictionary DisplayNameLookup { get; } = new Dictionary(); - private static CardInfoViewer _instance; - private CardModel _selectedCardModel; + + public string SelectedPropertyName + { + get + { + string selectedName = SetLabel; + if (SelectedPropertyIndex >= 1 && SelectedPropertyIndex < PropertyOptions.Count) + DisplayNameLookup.TryGetValue(SelectedPropertyDisplay, out selectedName); + return selectedName; + } + } + public string SelectedPropertyDisplay + { + get + { + string selectedDisplay = SetLabel; + if (SelectedPropertyIndex >= 1 && SelectedPropertyIndex < PropertyOptions.Count) + selectedDisplay = PropertyOptions[SelectedPropertyIndex].text; + return selectedDisplay; + } + } + public int SelectedPropertyIndex + { + get { return _selectedPropertyIndex; } + set + { + _selectedPropertyIndex = value; + if (_selectedPropertyIndex < 0) + _selectedPropertyIndex = PropertyOptions.Count - 1; + if (_selectedPropertyIndex >= PropertyOptions.Count) + _selectedPropertyIndex = 0; + propertySelection.value = _selectedPropertyIndex; + labelText.text = SelectedPropertyDisplay; + SetContentText(); + } + } private int _selectedPropertyIndex; + + public CardModel SelectedCardModel + { + get { return _selectedCardModel; } + set + { + if (_selectedCardModel != null) + _selectedCardModel.HideHighlight(); + + _selectedCardModel = value; + + if (_selectedCardModel == null) + { + IsVisible = false; + return; + } + cardImage.sprite = _selectedCardModel.GetComponent().sprite; + zoomImage.sprite = cardImage.sprite; + nameText.text = _selectedCardModel.Value.Name; + idText.text = _selectedCardModel.Value.Id; + SetContentText(); + + IsVisible = true; + } + } + private CardModel _selectedCardModel; + + public bool IsVisible + { + get { return _isVisible; } + set + { + _isVisible = value; + if (!_isVisible && zoomPanel != null) + zoomPanel.gameObject.SetActive(false); + + if (SelectedCardModel == null) + return; + + if (_isVisible) + SelectedCardModel.ShowHighlight(); + else + SelectedCardModel.HideHighlight(); + } + } private bool _isVisible; + public bool WasVisible => infoPanel.anchorMax.y < (HiddenYMax + VisibleYMax) / 2.0f; void Start() { @@ -145,100 +238,4 @@ public void HideCardZoomed() return; zoomPanel.gameObject.SetActive(false); } - - public static CardInfoViewer Instance - { - get - { - if (_instance != null) - return _instance; - - GameObject cardInfoViewer = GameObject.FindWithTag(CardInfoViewerTag); - _instance = cardInfoViewer?.GetOrAddComponent(); - return _instance; - } - } - - public string SelectedPropertyName - { - get - { - string selectedName = SetLabel; - if (SelectedPropertyIndex >= 1 && SelectedPropertyIndex < PropertyOptions.Count) - DisplayNameLookup.TryGetValue(SelectedPropertyDisplay, out selectedName); - return selectedName; - } - } - - public string SelectedPropertyDisplay - { - get - { - string selectedDisplay = SetLabel; - if (SelectedPropertyIndex >= 1 && SelectedPropertyIndex < PropertyOptions.Count) - selectedDisplay = PropertyOptions[SelectedPropertyIndex].text; - return selectedDisplay; - } - } - - public int SelectedPropertyIndex - { - get { return _selectedPropertyIndex; } - set - { - _selectedPropertyIndex = value; - if (_selectedPropertyIndex < 0) - _selectedPropertyIndex = PropertyOptions.Count - 1; - if (_selectedPropertyIndex >= PropertyOptions.Count) - _selectedPropertyIndex = 0; - propertySelection.value = _selectedPropertyIndex; - labelText.text = SelectedPropertyDisplay; - SetContentText(); - } - } - - public CardModel SelectedCardModel - { - get { return _selectedCardModel; } - set - { - if (_selectedCardModel != null) - _selectedCardModel.HideHighlight(); - - _selectedCardModel = value; - - if (_selectedCardModel == null) - { - IsVisible = false; - return; - } - cardImage.sprite = _selectedCardModel.GetComponent().sprite; - zoomImage.sprite = cardImage.sprite; - nameText.text = _selectedCardModel.Value.Name; - idText.text = _selectedCardModel.Value.Id; - SetContentText(); - - IsVisible = true; - } - } - - public bool IsVisible - { - get { return _isVisible; } - set - { - _isVisible = value; - if (!_isVisible && zoomPanel != null) - zoomPanel.gameObject.SetActive(false); - - if (SelectedCardModel == null) - return; - - if (_isVisible) - SelectedCardModel.ShowHighlight(); - else - SelectedCardModel.HideHighlight(); - } - } - public bool WasVisible => infoPanel.anchorMax.y < (HiddenYMax + VisibleYMax) / 2.0f; } diff --git a/docs/pages/roadmap.md b/docs/pages/roadmap.md index 8e4e27cde..13a5ccc47 100644 --- a/docs/pages/roadmap.md +++ b/docs/pages/roadmap.md @@ -5,15 +5,9 @@ permalink: roadmap.html # Roadmap ## What's New -- Improve deck loading process -- Double-click on selection to load it -- Highlight selected buttons in orange and pressed in purple -- Increase maximum zoom out +- Stream-lined menu navigation ## Current Sprint -- In Deck Editor, make search button clear filters and only do search by name in name input field - - Show name filter in filters bar (in quotes) - - Show condensed value of enum filters in filters bar - Group cards in the deck editor with a number instead of stacking them - Support deep links for games and decks through https://docs.branch.io/ - Facebook link and homepage banner image link should use this From 2cbf051f91392a6f63bcf7d9f640c0ad3fddadf1 Mon Sep 17 00:00:00 2001 From: David Finol Date: Wed, 18 Jul 2018 01:50:44 -0500 Subject: [PATCH 07/17] Accommodate platform-specific line-endings --- .editorconfig | 1 - ProjectSettings/EditorSettings.asset | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index e65297d59..cae76123c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,6 +4,5 @@ root = true [*.cs] indent_style = space indent_size = 4 -end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true diff --git a/ProjectSettings/EditorSettings.asset b/ProjectSettings/EditorSettings.asset index c0c814fdf..fe01c1840 100644 --- a/ProjectSettings/EditorSettings.asset +++ b/ProjectSettings/EditorSettings.asset @@ -3,12 +3,17 @@ --- !u!159 &1 EditorSettings: m_ObjectHideFlags: 0 - serializedVersion: 4 + serializedVersion: 7 m_ExternalVersionControlSupport: Visible Meta Files m_SerializationMode: 2 + m_LineEndingsForNewScripts: 0 m_DefaultBehaviorMode: 1 m_SpritePackerMode: 4 m_SpritePackerPaddingPower: 1 + m_EtcTextureCompressorBehavior: 0 + m_EtcTextureFastCompressor: 2 + m_EtcTextureNormalCompressor: 2 + m_EtcTextureBestCompressor: 5 m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd m_ProjectGenerationRootNamespace: m_UserGeneratedProjectSuffix: From b830f0985a27df1290f9135615dc466f0cd8a8f9 Mon Sep 17 00:00:00 2001 From: David Finol Date: Wed, 18 Jul 2018 02:14:22 -0500 Subject: [PATCH 08/17] Update roadmap --- docs/pages/roadmap.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/roadmap.md b/docs/pages/roadmap.md index 13a5ccc47..7ae027e4c 100644 --- a/docs/pages/roadmap.md +++ b/docs/pages/roadmap.md @@ -17,6 +17,7 @@ permalink: roadmap.html - Tech: Finalize namespaces - Tech: Add unit tests - Tech: Review with Resharper +- Tech: Update TMP default text settings - Fix: UWP join and host - Fix: NetworkDiscovery error on iOS sleep - Fix: Card dissapears when being sent to host but the connnection is dropped and the card is never received by the host to be replicated From be2b4a96ca8eea19eb2a6bc88c3ec9faf9d27e06 Mon Sep 17 00:00:00 2001 From: David Finol Date: Fri, 3 Aug 2018 19:31:26 -0500 Subject: [PATCH 09/17] Finalize namespaces --- Assets/Scripts/CGS/CardGameManager.cs | 450 ++++---- Assets/Scripts/CGS/DeckEditor/CardSelector.cs | 269 ----- Assets/Scripts/CGS/DeckEditor/DeckEditor.cs | 312 ------ .../CGS/DeckEditor/DeckEditorLayout.cs | Bin 5672 -> 0 bytes .../Scripts/CGS/DeckEditor/SearchResults.cs | 121 --- .../CGS/{DeckEditor.meta => EditDeck.meta} | 0 Assets/Scripts/CGS/EditDeck/CardSelector.cs | 273 +++++ .../CardSelector.cs.meta | 0 Assets/Scripts/CGS/EditDeck/DeckEditor.cs | 304 ++++++ .../DeckEditor.cs.meta | 0 .../Scripts/CGS/EditDeck/DeckEditorLayout.cs | Bin 0 -> 6078 bytes .../DeckEditorLayout.cs.meta | 0 Assets/Scripts/CGS/EditDeck/SearchResults.cs | 127 +++ .../SearchResults.cs.meta | 0 Assets/Scripts/CGS/Inputs.cs | 45 +- Assets/Scripts/CGS/Menus/CardSearchMenu.cs | 731 ++++++------- Assets/Scripts/CGS/Menus/DeckLoadMenu.cs | 451 ++++---- Assets/Scripts/CGS/Menus/DeckSaveMenu.cs | 169 +-- Assets/Scripts/CGS/Menus/DiceMenu.cs | 146 +-- Assets/Scripts/CGS/Menus/GameSelectionMenu.cs | 265 ++--- Assets/Scripts/CGS/Menus/LobbyMenu.cs | 166 +-- Assets/Scripts/CGS/Menus/MainMenu.cs | 177 ++-- Assets/Scripts/CGS/Menus/OptionsMenu.cs | 113 +- Assets/Scripts/CGS/Menus/Popup.cs | 162 +-- .../Scripts/CGS/Menus/SearchPropertyPanel.cs | 19 +- Assets/Scripts/CGS/Menus/TitleScreen.cs | 23 +- .../Scripts/CGS/{PlayMode.meta => Play.meta} | 0 Assets/Scripts/CGS/Play/Die.cs | 123 +++ .../CGS/{PlayMode => Play}/Die.cs.meta | 0 Assets/Scripts/CGS/Play/DieSelectable.cs | 15 + .../{PlayMode => Play}/DieSelectable.cs.meta | 0 .../CGS/{PlayMode => Play}/Multiplayer.meta | 0 .../CGS/Play/Multiplayer/CGSNetData.cs | 112 ++ .../Multiplayer/CGSNetData.cs.meta | 0 .../CGS/Play/Multiplayer/CGSNetManager.cs | 102 ++ .../Multiplayer/CGSNetManager.cs.meta | 0 .../CGS/Play/Multiplayer/CGSNetPlayer.cs | 177 ++++ .../Multiplayer/CGSNetPlayer.cs.meta | 0 .../CGS/Play/Multiplayer/LobbyDiscovery.cs | 78 ++ .../Multiplayer/LobbyDiscovery.cs.meta | 0 Assets/Scripts/CGS/Play/PlayMode.cs | 264 +++++ .../CGS/{PlayMode => Play}/PlayMode.cs.meta | 0 Assets/Scripts/CGS/Play/PointsCounter.cs | 32 + .../{PlayMode => Play}/PointsCounter.cs.meta | 0 .../Scripts/CGS/{PlayMode => Play}/Zones.meta | 0 Assets/Scripts/CGS/Play/Zones/CardDropZone.cs | 38 + .../Zones/CardDropZone.cs.meta | 0 .../CGS/Play/Zones/ExtensibleCardZone.cs | 140 +++ .../Zones/ExtensibleCardZone.cs.meta | 0 Assets/Scripts/CGS/Play/Zones/StackedZone.cs | 132 +++ .../Zones/StackedZone.cs.meta | 0 Assets/Scripts/CGS/Play/Zones/ZonesViewer.cs | 180 ++++ .../Zones/ZonesViewer.cs.meta | 0 Assets/Scripts/CGS/PlayMode/Die.cs | 116 -- Assets/Scripts/CGS/PlayMode/DieSelectable.cs | 12 - .../CGS/PlayMode/Multiplayer/CGSNetData.cs | 101 -- .../CGS/PlayMode/Multiplayer/CGSNetManager.cs | 97 -- .../CGS/PlayMode/Multiplayer/CGSNetPlayer.cs | 173 --- .../PlayMode/Multiplayer/LobbyDiscovery.cs | 72 -- Assets/Scripts/CGS/PlayMode/PlayMode.cs | 257 ----- Assets/Scripts/CGS/PlayMode/PointsCounter.cs | 27 - .../CGS/PlayMode/Zones/CardDropZone.cs | 34 - .../CGS/PlayMode/Zones/ExtensibleCardZone.cs | 138 --- .../Scripts/CGS/PlayMode/Zones/StackedZone.cs | 128 --- .../Scripts/CGS/PlayMode/Zones/ZonesViewer.cs | 174 --- Assets/Scripts/CGS/ScreenRotationManager.cs | 44 +- Assets/Scripts/CGS/SwipeManager.cs | 343 +++--- Assets/Scripts/CGS/Tags.cs | 15 +- Assets/Scripts/CardGameDef/Card.cs | 104 +- Assets/Scripts/CardGameDef/CardGame.cs | 134 +-- .../Scripts/CardGameDef/CardSearchFilters.cs | 29 +- Assets/Scripts/CardGameDef/Deck.cs | 74 +- Assets/Scripts/CardGameDef/EnumDef.cs | 5 - Assets/Scripts/CardGameDef/GameBoard.cs | 2 +- Assets/Scripts/CardGameDef/GameBoardCard.cs | 2 +- Assets/Scripts/CardGameDef/ICardDisplay.cs | 7 + .../Scripts/CardGameDef/ICardDisplay.cs.meta | 11 + Assets/Scripts/CardGameView/CardInfoViewer.cs | 395 +++---- .../CardGameView/CardInfoViewerSelectable.cs | 37 +- Assets/Scripts/CardGameView/CardModel.cs | 987 +++++++++--------- Assets/Scripts/CardGameView/CardStack.cs | 168 +-- Assets/Scripts/{CGS => }/ScrollRects.meta | 0 .../{CGS => }/ScrollRects/CardScrollArea.cs | 1 + .../ScrollRects/CardScrollArea.cs.meta | 0 .../Scripts/{CGS => }/ScrollRects/Editor.meta | 0 .../Editor/PassThroughScrollRectEditor.cs | 0 .../PassThroughScrollRectEditor.cs.meta | 0 .../ScrollRects/PassThroughScrollRect.cs | 0 .../ScrollRects/PassThroughScrollRect.cs.meta | 0 .../ScrollRects/PinchableScrollRect.cs | 1 + .../ScrollRects/PinchableScrollRect.cs.meta | 0 .../ScrollRects/ScrollRectAutoScroll.cs | 0 .../ScrollRects/ScrollRectAutoScroll.cs.meta | 0 .../ScrollRects/SecondaryScrollView.cs | 0 .../ScrollRects/SecondaryScrollView.cs.meta | 0 .../{CGS => }/ScrollRects/SelectionPanel.cs | 0 .../ScrollRects/SelectionPanel.cs.meta | 0 docs/pages/roadmap.md | 1 - 98 files changed, 4783 insertions(+), 4622 deletions(-) delete mode 100644 Assets/Scripts/CGS/DeckEditor/CardSelector.cs delete mode 100644 Assets/Scripts/CGS/DeckEditor/DeckEditor.cs delete mode 100644 Assets/Scripts/CGS/DeckEditor/DeckEditorLayout.cs delete mode 100644 Assets/Scripts/CGS/DeckEditor/SearchResults.cs rename Assets/Scripts/CGS/{DeckEditor.meta => EditDeck.meta} (100%) create mode 100644 Assets/Scripts/CGS/EditDeck/CardSelector.cs rename Assets/Scripts/CGS/{DeckEditor => EditDeck}/CardSelector.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/EditDeck/DeckEditor.cs rename Assets/Scripts/CGS/{DeckEditor => EditDeck}/DeckEditor.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/EditDeck/DeckEditorLayout.cs rename Assets/Scripts/CGS/{DeckEditor => EditDeck}/DeckEditorLayout.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/EditDeck/SearchResults.cs rename Assets/Scripts/CGS/{DeckEditor => EditDeck}/SearchResults.cs.meta (100%) rename Assets/Scripts/CGS/{PlayMode.meta => Play.meta} (100%) create mode 100644 Assets/Scripts/CGS/Play/Die.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Die.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/DieSelectable.cs rename Assets/Scripts/CGS/{PlayMode => Play}/DieSelectable.cs.meta (100%) rename Assets/Scripts/CGS/{PlayMode => Play}/Multiplayer.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Multiplayer/CGSNetData.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Multiplayer/CGSNetData.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Multiplayer/CGSNetManager.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Multiplayer/CGSNetManager.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Multiplayer/CGSNetPlayer.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Multiplayer/CGSNetPlayer.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Multiplayer/LobbyDiscovery.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Multiplayer/LobbyDiscovery.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/PlayMode.cs rename Assets/Scripts/CGS/{PlayMode => Play}/PlayMode.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/PointsCounter.cs rename Assets/Scripts/CGS/{PlayMode => Play}/PointsCounter.cs.meta (100%) rename Assets/Scripts/CGS/{PlayMode => Play}/Zones.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Zones/CardDropZone.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Zones/CardDropZone.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Zones/ExtensibleCardZone.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Zones/ExtensibleCardZone.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Zones/StackedZone.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Zones/StackedZone.cs.meta (100%) create mode 100644 Assets/Scripts/CGS/Play/Zones/ZonesViewer.cs rename Assets/Scripts/CGS/{PlayMode => Play}/Zones/ZonesViewer.cs.meta (100%) delete mode 100644 Assets/Scripts/CGS/PlayMode/Die.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/DieSelectable.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Multiplayer/CGSNetData.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Multiplayer/CGSNetManager.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Multiplayer/CGSNetPlayer.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Multiplayer/LobbyDiscovery.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/PlayMode.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/PointsCounter.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Zones/CardDropZone.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Zones/ExtensibleCardZone.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Zones/StackedZone.cs delete mode 100644 Assets/Scripts/CGS/PlayMode/Zones/ZonesViewer.cs create mode 100644 Assets/Scripts/CardGameDef/ICardDisplay.cs create mode 100644 Assets/Scripts/CardGameDef/ICardDisplay.cs.meta rename Assets/Scripts/{CGS => }/ScrollRects.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/CardScrollArea.cs (99%) rename Assets/Scripts/{CGS => }/ScrollRects/CardScrollArea.cs.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/Editor.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/Editor/PassThroughScrollRectEditor.cs (100%) rename Assets/Scripts/{CGS => }/ScrollRects/Editor/PassThroughScrollRectEditor.cs.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/PassThroughScrollRect.cs (100%) rename Assets/Scripts/{CGS => }/ScrollRects/PassThroughScrollRect.cs.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/PinchableScrollRect.cs (99%) rename Assets/Scripts/{CGS => }/ScrollRects/PinchableScrollRect.cs.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/ScrollRectAutoScroll.cs (100%) rename Assets/Scripts/{CGS => }/ScrollRects/ScrollRectAutoScroll.cs.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/SecondaryScrollView.cs (100%) rename Assets/Scripts/{CGS => }/ScrollRects/SecondaryScrollView.cs.meta (100%) rename Assets/Scripts/{CGS => }/ScrollRects/SelectionPanel.cs (100%) rename Assets/Scripts/{CGS => }/ScrollRects/SelectionPanel.cs.meta (100%) diff --git a/Assets/Scripts/CGS/CardGameManager.cs b/Assets/Scripts/CGS/CardGameManager.cs index 0724c9e35..93a617fdb 100644 --- a/Assets/Scripts/CGS/CardGameManager.cs +++ b/Assets/Scripts/CGS/CardGameManager.cs @@ -3,291 +3,295 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using CardGameDef; +using CardGameView; +using CGS.Menus; +using CGS.Play; +using CGS.Play.Multiplayer; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; -using CardGameDef; +using UnityEngine.Events; -public delegate void GameSceneDelegate(); - -public class CardGameManager : MonoBehaviour +namespace CGS { - public const string PlayerPrefGameName = "DefaultGame"; - public const string SelectorPrefabName = "Game Selection Menu"; - public const string MessengerPrefabName = "Popup"; - public const string InvalidGameSelectionMessage = "Could not select the card game because the name is not recognized in the list of card games! Try selecting a different card game."; - public const string GameLoadErrorMessage = "Error loading game!: "; - public const string GameDeleteErrorMessage = "Error deleting game!: "; - public const int PixelsPerInch = 100; - - public static CardGameManager Instance + public class CardGameManager : MonoBehaviour { - get + public const string PlayerPrefGameName = "DefaultGame"; + public const string SelectorPrefabName = "Game Selection Menu"; + public const string MessengerPrefabName = "Popup"; + public const string InvalidGameSelectionMessage = "Could not select the card game because the name is not recognized in the list of card games! Try selecting a different card game."; + public const string GameLoadErrorMessage = "Error loading game!: "; + public const string GameDeleteErrorMessage = "Error deleting game!: "; + public const int PixelsPerInch = 100; + + public static CardGameManager Instance { - if (IsQuitting) return null; - if (_instance != null) return _instance; - GameObject cardGameManager = GameObject.FindGameObjectWithTag(Tags.CardGameManager); - if (cardGameManager == null) + get { - cardGameManager = new GameObject(Tags.CardGameManager) { tag = Tags.CardGameManager }; - cardGameManager.transform.position = Vector3.zero; + if (IsQuitting) return null; + if (_instance != null) return _instance; + GameObject cardGameManager = GameObject.FindGameObjectWithTag(Tags.CardGameManager); + if (cardGameManager == null) + { + cardGameManager = new GameObject(Tags.CardGameManager) { tag = Tags.CardGameManager }; + cardGameManager.transform.position = Vector3.zero; + } + _instance = cardGameManager.GetOrAddComponent(); + return _instance; } - _instance = cardGameManager.GetOrAddComponent(); - return _instance; } - } - private static CardGameManager _instance; + private static CardGameManager _instance; - public static CardGame Current { get; private set; } = new CardGame(); - public static bool IsQuitting { get; private set; } + public static CardGame Current { get; private set; } = CardGame.Invalid; + public static bool IsQuitting { get; private set; } = false; - public SortedDictionary AllCardGames { get; } = new SortedDictionary(); - public List OnSceneActions { get; } = new List(); + public SortedDictionary AllCardGames { get; } = new SortedDictionary(); + public List OnSceneActions { get; } = new List(); - private LobbyDiscovery _discovery; - public LobbyDiscovery Discovery => _discovery ?? - (_discovery = gameObject.GetOrAddComponent()); + public LobbyDiscovery Discovery => _discovery ?? (_discovery = gameObject.GetOrAddComponent()); + private LobbyDiscovery _discovery; - private GameSelectionMenu _selector; - public GameSelectionMenu Selector - { - get + public GameSelectionMenu Selector { - if (_selector != null) return _selector; - _selector = Instantiate(Resources.Load(SelectorPrefabName)).GetOrAddComponent(); - _selector.transform.SetParent(null); - return _selector; + get + { + if (_selector != null) return _selector; + _selector = Instantiate(Resources.Load(SelectorPrefabName)).GetOrAddComponent(); + _selector.transform.SetParent(null); + return _selector; + } } - } + private GameSelectionMenu _selector; - private Popup _messenger; - public Popup Messenger - { - get + public Popup Messenger { - if (_messenger != null) return _messenger; - _messenger = Instantiate(Resources.Load(MessengerPrefabName)).GetOrAddComponent(); - _messenger.transform.SetParent(transform); - return _messenger; + get + { + if (_messenger != null) return _messenger; + _messenger = Instantiate(Resources.Load(MessengerPrefabName)).GetOrAddComponent(); + _messenger.transform.SetParent(transform); + return _messenger; + } } - } - private Image _backgroundImage; + private Popup _messenger; - public Image BackgroundImage - { - get + public Image BackgroundImage { - if (_backgroundImage == null && GameObject.FindGameObjectWithTag(Tags.BackgroundImage) != null) - _backgroundImage = GameObject.FindGameObjectWithTag(Tags.BackgroundImage).GetOrAddComponent(); - return _backgroundImage; + get + { + if (_backgroundImage == null && GameObject.FindGameObjectWithTag(Tags.BackgroundImage) != null) + _backgroundImage = GameObject.FindGameObjectWithTag(Tags.BackgroundImage).GetOrAddComponent(); + return _backgroundImage; + } } - } + private Image _backgroundImage; - public static Canvas TopCardCanvas - { - get + public static Canvas TopCardCanvas { - Canvas topCanvas = null; - foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(Tags.CardCanvas)) - if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) - topCanvas = canvas.GetComponent(); - return topCanvas; + get + { + Canvas topCanvas = null; + foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(Tags.CardCanvas)) + if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) + topCanvas = canvas.GetComponent(); + return topCanvas; + } } - } - public static Canvas TopMenuCanvas - { - get + public static Canvas TopMenuCanvas { - Canvas topCanvas = null; - foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(Tags.MenuCanvas)) - if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) - topCanvas = canvas.GetComponent(); - return topCanvas; + get + { + Canvas topCanvas = null; + foreach (GameObject canvas in GameObject.FindGameObjectsWithTag(Tags.MenuCanvas)) + if (canvas.activeSelf && (topCanvas == null || canvas.GetComponent().sortingOrder > topCanvas.sortingOrder)) + topCanvas = canvas.GetComponent(); + return topCanvas; + } } - } - void Awake() - { - if (_instance != null && _instance != this) + void Awake() { - Destroy(gameObject); - return; + if (_instance != null && _instance != this) + { + Destroy(gameObject); + return; + } + _instance = this; + CardGame.Invalid.CoroutineRunner = this; + DontDestroyOnLoad(gameObject); + + if (!Directory.Exists(CardGame.GamesDirectoryPath)) + CreateDefaultCardGames(); + LookupCardGames(); + + CardGame currentGame; + Current = AllCardGames.TryGetValue(PlayerPrefs.GetString(PlayerPrefGameName), out currentGame) + ? currentGame : AllCardGames.First().Value; + + if (Debug.isDebugBuild) + Application.logMessageReceived += ShowLogToUser; + SceneManager.sceneLoaded += OnSceneLoaded; + SceneManager.sceneUnloaded += OnSceneUnloaded; } - _instance = this; - DontDestroyOnLoad(gameObject); - - if (!Directory.Exists(CardGame.GamesDirectoryPath)) - CreateDefaultCardGames(); - LookupCardGames(); - - CardGame currentGame; - Current = AllCardGames.TryGetValue(PlayerPrefs.GetString(PlayerPrefGameName), out currentGame) - ? currentGame : AllCardGames.First().Value; - - if (Debug.isDebugBuild) - Application.logMessageReceived += ShowLogToUser; - SceneManager.sceneLoaded += OnSceneLoaded; - SceneManager.sceneUnloaded += OnSceneUnloaded; - } - private void CreateDefaultCardGames() - { + private void CreateDefaultCardGames() + { #if UNITY_ANDROID && !UNITY_EDITOR - UnityExtensionMethods.ExtractAndroidStreamingAssets(CardGame.GamesDirectoryPath); + UnityExtensionMethods.ExtractAndroidStreamingAssets(CardGame.GamesDirectoryPath); #else - UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, CardGame.GamesDirectoryPath); + UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, CardGame.GamesDirectoryPath); #endif - } - - private void LookupCardGames() - { - if (!Directory.Exists(CardGame.GamesDirectoryPath) || Directory.GetDirectories(CardGame.GamesDirectoryPath).Length < 1) - CreateDefaultCardGames(); + } - foreach (string gameDirectory in Directory.GetDirectories(CardGame.GamesDirectoryPath)) + private void LookupCardGames() { - string gameName = gameDirectory.Substring(CardGame.GamesDirectoryPath.Length + 1); - AllCardGames[gameName] = new CardGame(gameName, string.Empty); - } - } + if (!Directory.Exists(CardGame.GamesDirectoryPath) || Directory.GetDirectories(CardGame.GamesDirectoryPath).Length < 1) + CreateDefaultCardGames(); - void ShowLogToUser(string logString, string stackTrace, LogType type) - { - Messenger.Show(logString); - } + foreach (string gameDirectory in Directory.GetDirectories(CardGame.GamesDirectoryPath)) + { + string gameName = gameDirectory.Substring(CardGame.GamesDirectoryPath.Length + 1); + AllCardGames[gameName] = new CardGame(this, gameName, string.Empty); + } + } - void OnSceneLoaded(Scene scene, LoadSceneMode mode) - { - DoGameSceneActions(); - } + void ShowLogToUser(string logString, string stackTrace, LogType type) + { + Messenger.Show(logString); + } - void OnSceneUnloaded(Scene scene) - { - OnSceneActions.Clear(); - } + void OnSceneLoaded(Scene scene, LoadSceneMode mode) + { + DoGameSceneActions(); + } - public IEnumerator DownloadCardGame(string gameUrl) - { - //Messenger.Show("Game download has started"); - CardGame newGame = new CardGame(Set.DefaultCode, gameUrl) { AutoUpdate = true }; - Current = newGame; - yield return newGame.Download(); - if (string.IsNullOrEmpty(newGame.Error)) - AllCardGames[newGame.Name] = newGame; - else - Debug.LogError(GameLoadErrorMessage + newGame.Error); - SelectCardGame(newGame.Name); - //Messenger.Show("Game download has finished"); - } + void OnSceneUnloaded(Scene scene) + { + OnSceneActions.Clear(); + } - public void SelectLeft() - { - string prevGameName = AllCardGames.Keys.Last(); - SortedDictionary.Enumerator allCardGamesEnum = AllCardGames.GetEnumerator(); - bool found = false; - while (!found && allCardGamesEnum.MoveNext()) + public IEnumerator DownloadCardGame(string gameUrl) { - if (!allCardGamesEnum.Current.Key.Equals(Current.Name)) - prevGameName = allCardGamesEnum.Current.Key; + //Messenger.Show("Game download has started"); + CardGame newGame = new CardGame(this, Set.DefaultCode, gameUrl) { AutoUpdate = true }; + Current = newGame; + yield return newGame.Download(); + if (string.IsNullOrEmpty(newGame.Error)) + AllCardGames[newGame.Name] = newGame; else - found = true; + Debug.LogError(GameLoadErrorMessage + newGame.Error); + SelectCardGame(newGame.Name); + //Messenger.Show("Game download has finished"); } - SelectCardGame(prevGameName); - } - public void SelectRight() - { - string nextGameName = Current.Name; - SortedDictionary.Enumerator allCardGamesEnum = AllCardGames.GetEnumerator(); - bool found = false; - while (!found && allCardGamesEnum.MoveNext()) - if (allCardGamesEnum.Current.Key.Equals(Current.Name)) - found = true; - if (allCardGamesEnum.MoveNext()) - nextGameName = allCardGamesEnum.Current.Key; - else if (found) - nextGameName = AllCardGames.Keys.First(); - SelectCardGame(nextGameName); - } + public void SelectLeft() + { + string prevGameName = AllCardGames.Keys.Last(); + SortedDictionary.Enumerator allCardGamesEnum = AllCardGames.GetEnumerator(); + bool found = false; + while (!found && allCardGamesEnum.MoveNext()) + { + if (!allCardGamesEnum.Current.Key.Equals(Current.Name)) + prevGameName = allCardGamesEnum.Current.Key; + else + found = true; + } + SelectCardGame(prevGameName); + } - public void SelectCardGame(string gameName, string gameUrl) - { - if (string.IsNullOrEmpty(gameName) || !AllCardGames.ContainsKey(gameName)) + public void SelectRight() { - StartCoroutine(DownloadCardGame(gameUrl)); - return; + string nextGameName = Current.Name; + SortedDictionary.Enumerator allCardGamesEnum = AllCardGames.GetEnumerator(); + bool found = false; + while (!found && allCardGamesEnum.MoveNext()) + if (allCardGamesEnum.Current.Key.Equals(Current.Name)) + found = true; + if (allCardGamesEnum.MoveNext()) + nextGameName = allCardGamesEnum.Current.Key; + else if (found) + nextGameName = AllCardGames.Keys.First(); + SelectCardGame(nextGameName); } - SelectCardGame(gameName); - } - public void SelectCardGame(string gameName) - { - if (string.IsNullOrEmpty(gameName) || !AllCardGames.ContainsKey(gameName)) + public void SelectCardGame(string gameName, string gameUrl) { - Debug.LogError(InvalidGameSelectionMessage); - Selector.Show(); - return; + if (string.IsNullOrEmpty(gameName) || !AllCardGames.ContainsKey(gameName)) + { + StartCoroutine(DownloadCardGame(gameUrl)); + return; + } + SelectCardGame(gameName); } - CardGame currentGame; - Current = AllCardGames.TryGetValue(gameName, out currentGame) ? currentGame : new CardGame(); + public void SelectCardGame(string gameName) + { + if (string.IsNullOrEmpty(gameName) || !AllCardGames.ContainsKey(gameName)) + { + Debug.LogError(InvalidGameSelectionMessage); + Selector.Show(); + return; + } - DoGameSceneActions(); - } + Current = AllCardGames[gameName]; + DoGameSceneActions(); + } - public IEnumerator LoadCards() - { - //Messenger.Show("Cards are loading in the background. Performance may be affected in the meantime."); - yield return Current.LoadAllCards(); - if (!string.IsNullOrEmpty(Current.Error)) - Debug.LogError(GameLoadErrorMessage + Current.Error); - //Messenger.Show("All cards have finished loading."); - } + public void DoGameSceneActions() + { + if (!Current.IsLoaded) + Current.Load(); - public void DoGameSceneActions() - { - if (!Current.IsLoaded) - Current.Load(); - - if (!string.IsNullOrEmpty(Current.Error)) - Debug.LogError(GameLoadErrorMessage + Current.Error); - else - PlayerPrefs.SetString(PlayerPrefGameName, Current.Name); - - if (BackgroundImage != null) - BackgroundImage.sprite = Current.BackgroundImageSprite; - CardInfoViewer.Instance?.ResetInfo(); - - for (int i = OnSceneActions.Count - 1; i >= 0; i--) - if (OnSceneActions[i] == null) - OnSceneActions.RemoveAt(i); - foreach (GameSceneDelegate action in OnSceneActions) - action(); - } + if (!string.IsNullOrEmpty(Current.Error)) + Debug.LogError(GameLoadErrorMessage + Current.Error); + else + PlayerPrefs.SetString(PlayerPrefGameName, Current.Name); - public void DeleteGame() - { - try + if (BackgroundImage != null) + BackgroundImage.sprite = Current.BackgroundImageSprite; + CardInfoViewer.Instance?.ResetInfo(); + + for (int i = OnSceneActions.Count - 1; i >= 0; i--) + if (OnSceneActions[i] == null) + OnSceneActions.RemoveAt(i); + foreach (UnityAction action in OnSceneActions) + action(); + } + + public IEnumerator LoadCards() { - Directory.Delete(Current.GameFolderPath, true); - AllCardGames.Remove(Current.Name); - SelectCardGame(AllCardGames.Keys.First()); - Selector.Show(); + //Messenger.Show("Cards are loading in the background. Performance may be affected in the meantime."); + yield return Current.LoadAllCards(); + if (!string.IsNullOrEmpty(Current.Error)) + Debug.LogError(GameLoadErrorMessage + Current.Error); + //Messenger.Show("All cards have finished loading."); } - catch (Exception ex) + + public void DeleteGame() { - Debug.LogError(GameDeleteErrorMessage + ex.Message); + try + { + Directory.Delete(Current.GameFolderPath, true); + AllCardGames.Remove(Current.Name); + SelectCardGame(AllCardGames.Keys.First()); + Selector.Show(); + } + catch (Exception ex) + { + Debug.LogError(GameDeleteErrorMessage + ex.Message); + } } - } - void OnDisable() - { - SceneManager.sceneLoaded -= OnSceneLoaded; - } + void OnDisable() + { + SceneManager.sceneLoaded -= OnSceneLoaded; + } - void OnApplicationQuit() - { - IsQuitting = true; + void OnApplicationQuit() + { + IsQuitting = true; + } } } diff --git a/Assets/Scripts/CGS/DeckEditor/CardSelector.cs b/Assets/Scripts/CGS/DeckEditor/CardSelector.cs deleted file mode 100644 index 394657986..000000000 --- a/Assets/Scripts/CGS/DeckEditor/CardSelector.cs +++ /dev/null @@ -1,269 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.EventSystems; - -public class CardSelector : MonoBehaviour -{ - public DeckEditor editor; - public SearchResults results; - - void Update() - { - if (CardGameManager.TopMenuCanvas != null || editor.searchResults.nameInputField.isFocused) - return; - - if (CardInfoViewer.Instance.zoomPanel.gameObject.activeSelf && SwipeManager.DetectSwipe()) - { - if (SwipeManager.IsSwipingDown()) - SelectUp(); - else if (SwipeManager.IsSwipingUp()) - SelectDown(); - else if (SwipeManager.IsSwipingRight()) - SelectLeft(); - else if (SwipeManager.IsSwipingLeft()) - SelectRight(); - } - - if (Input.anyKeyDown) - { - if (Input.GetButtonDown(Inputs.Vertical)) - { - if (Input.GetAxis(Inputs.Vertical) > 0) - SelectUp(); - else - SelectDown(); - } - else if (Input.GetButtonDown(Inputs.Horizontal)) - { - if (Input.GetAxis(Inputs.Horizontal) > 0) - SelectRight(); - else - SelectLeft(); - } - else if (Input.GetButtonDown(Inputs.Column)) - { - if (Input.GetAxis(Inputs.Column) > 0) - ShiftRight(); - else - ShiftLeft(); - } - else if (Input.GetButtonDown(Inputs.Page) && !CardInfoViewer.Instance.IsVisible) - { - if (Input.GetAxis(Inputs.Page) > 0) - PageRight(); - else - PageLeft(); - } - } - } - - public void SelectDown() - { - if (EventSystem.current.alreadySelecting) - return; - - List editorCards = editor.CardModels; - if (editorCards.Count < 1) - { - EventSystem.current.SetSelectedGameObject(null); - return; - } - - for (int i = 0; i < editorCards.Count; i++) - { - if (editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) - continue; - i++; - if (i == editorCards.Count) - i = 0; - EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); - return; - } - EventSystem.current.SetSelectedGameObject(editorCards[0].gameObject); - } - - public void SelectUp() - { - if (EventSystem.current.alreadySelecting) - return; - - List editorCards = editor.CardModels; - if (editorCards.Count < 1) - { - EventSystem.current.SetSelectedGameObject(null); - return; - } - - for (int i = editorCards.Count - 1; i >= 0; i--) - { - if (editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) - continue; - i--; - if (i < 0) - i = editorCards.Count - 1; - EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); - return; - } - EventSystem.current.SetSelectedGameObject(editorCards[editorCards.Count - 1].gameObject); - } - - public void SelectLeft() - { - if (EventSystem.current.alreadySelecting) - return; - - if (results.layoutArea.childCount < 1) - { - EventSystem.current.SetSelectedGameObject(null); - return; - } - - for (int i = results.layoutArea.childCount - 1; i >= 0; i--) - { - if (results.layoutArea.GetChild(i).GetComponent() != CardInfoViewer.Instance.SelectedCardModel) - continue; - i--; - if (i < 0) - { - results.PageLeft(); - i = results.layoutArea.childCount - 1; - } - EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(i).gameObject); - return; - } - EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(0).gameObject); - } - - public void SelectRight() - { - if (EventSystem.current.alreadySelecting) - return; - - if (results.layoutArea.childCount < 1) - { - EventSystem.current.SetSelectedGameObject(null); - return; - } - - for (int i = 0; i < results.layoutArea.childCount; i++) - { - if (results.layoutArea.GetChild(i).GetComponent() != CardInfoViewer.Instance.SelectedCardModel) - continue; - i++; - if (i == results.layoutArea.childCount) - { - results.PageRight(); - i = 0; - } - EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(i).gameObject); - return; - } - EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(0).gameObject); - } - - public void ShiftLeft() - { - if (EventSystem.current.alreadySelecting) - return; - - List editorCards = editor.CardModels; - if (editorCards.Count < 1) - { - EventSystem.current.SetSelectedGameObject(null); - return; - } - - Transform startParent = null; - for (int i = editorCards.Count - 1; i >= 0; i--) - { - if (startParent == null && editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) - continue; - if (editorCards[i] == CardInfoViewer.Instance.SelectedCardModel) - startParent = editorCards[i].transform.parent; - if (startParent != editorCards[i].transform.parent) - { - editor.scrollRect.horizontalNormalizedPosition = editorCards[i].transform.parent.GetSiblingIndex() / (editorCards[i].transform.parent.parent.childCount - 1f); - EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); - return; - } - } - editor.scrollRect.horizontalNormalizedPosition = 1; - EventSystem.current.SetSelectedGameObject(editorCards[editorCards.Count - 1].gameObject); - } - - public void ShiftRight() - { - if (EventSystem.current.alreadySelecting) - return; - - List editorCards = editor.CardModels; - if (editorCards.Count < 1) - { - EventSystem.current.SetSelectedGameObject(null); - return; - } - - Transform startParent = null; - for (int i = 0; i < editorCards.Count; i++) - { - if (startParent == null && editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) - continue; - if (editorCards[i] == CardInfoViewer.Instance.SelectedCardModel) - startParent = editorCards[i].transform.parent; - if (startParent != editorCards[i].transform.parent) - { - editor.scrollRect.horizontalNormalizedPosition = editorCards[i].transform.parent.GetSiblingIndex() / (editorCards[i].transform.parent.parent.childCount - 1f); - EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); - return; - } - } - editor.scrollRect.horizontalNormalizedPosition = 0; - EventSystem.current.SetSelectedGameObject(editorCards[0].gameObject); - } - - public void PageLeft() - { - results.PageLeft(); - } - - public void PageRight() - { - results.PageRight(); - } - - public void GoLeft() - { - RectTransform rt = GetComponent(); - if (rt.rect.width > rt.rect.height) - ShiftLeft(); - else - PageLeft(); - } - - public void GoRight() - { - RectTransform rt = GetComponent(); - if (rt.rect.width > rt.rect.height) - ShiftRight(); - else - PageRight(); - } - - public void MoveLeft() - { - RectTransform rt = GetComponent(); - if (rt.rect.width > rt.rect.height) - PageLeft(); - else - SelectLeft(); - } - - public void MoveRight() - { - RectTransform rt = GetComponent(); - if (rt.rect.width > rt.rect.height) - PageRight(); - else - SelectRight(); - } -} diff --git a/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs b/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs deleted file mode 100644 index 6d26c3a0f..000000000 --- a/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs +++ /dev/null @@ -1,312 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.EventSystems; -using UnityEngine.SceneManagement; -using CardGameDef; - -public delegate string OnNameChangeDelegate(string newName); - -public class DeckEditor : MonoBehaviour, ICardDropHandler -{ - public const string NewDeckPrompt = "Clear the editor and start a new Untitled deck?"; - public const string SaveChangesPrompt = "You have unsaved changes. Would you like to save?"; - public const string ChangeIndicator = "*"; - - public float PreHeight => cardModelPrefab.GetComponent().rect.height; - public int CardsPerStack => Mathf.FloorToInt(8 * (CardGameManager.PixelsPerInch * CardGameManager.Current.CardSize.y / PreHeight)); - public int CardStackCount => Mathf.CeilToInt((float)CardGameManager.Current.DeckMaxCount / CardsPerStack); - public List CardStacks => _cardStacks ?? (_cardStacks = new List()); - public int CurrentCardStackIndex - { - get - { - if (_currentCardStackIndex < 0 || _currentCardStackIndex >= CardStacks.Count) - _currentCardStackIndex = 0; - return _currentCardStackIndex; - } - set { _currentCardStackIndex = value; } - } - public DeckLoadMenu DeckLoader => _deckLoader ?? (_deckLoader = Instantiate(deckLoadMenuPrefab).GetOrAddComponent()); - public DeckSaveMenu DeckSaver => _deckSaver ?? (_deckSaver = Instantiate(deckSaveMenuPrefab).GetOrAddComponent()); - - public List CardModels - { - get - { - List cardModels = new List(); - foreach (CardStack stack in CardStacks) - foreach (CardModel cardModel in stack.GetComponentsInChildren()) - cardModels.Add(cardModel); - return cardModels; - } - } - public Deck CurrentDeck - { - get - { - Deck deck = new Deck(SavedDeck != null ? SavedDeck.Name : Deck.DefaultName, CardGameManager.Current.DeckFileType); - foreach (CardStack stack in CardStacks) - foreach (CardModel card in stack.GetComponentsInChildren()) - deck.Cards.Add(card.Value); - return deck; - } - } - public Deck SavedDeck { get; private set; } - public bool HasChanged - { - get - { - Deck currentDeck = CurrentDeck; - if (currentDeck.Cards.Count < 1) - return false; - return !currentDeck.Equals(SavedDeck); - } - } - - public GameObject cardViewerPrefab; - public GameObject cardModelPrefab; - public GameObject cardStackPrefab; - public GameObject deckLoadMenuPrefab; - public GameObject deckSaveMenuPrefab; - public RectTransform layoutContent; - public CardDropZone dropZone; - public ScrollRect scrollRect; - public Text nameText; - public Text countText; - public SearchResults searchResults; - - private List _cardStacks; - private int _currentCardStackIndex; - private DeckLoadMenu _deckLoader; - private DeckSaveMenu _deckSaver; - - void OnEnable() - { - Instantiate(cardViewerPrefab); - CardGameManager.Instance.OnSceneActions.Add(ResetCardStacks); - } - - void Start() - { - dropZone.dropHandler = this; - } - - void Update() - { - if (!CardGameManager.Current.CardNameIsAtTop) - LabelCardsInStacks(); - - if (CardInfoViewer.Instance.IsVisible || CardGameManager.TopMenuCanvas != null || searchResults.nameInputField.isFocused) - return; - - if (Input.GetButtonDown(Inputs.Sort)) - Sort(); - else if (Input.GetButtonDown(Inputs.New)) - PromptForClear(); - else if (Input.GetButtonDown(Inputs.Load)) - ShowDeckLoadMenu(); - else if (Input.GetButtonDown(Inputs.Save)) - ShowDeckSaveMenu(); - else if (Input.GetButtonDown(Inputs.FocusName)) - searchResults.nameInputField.ActivateInputField(); - else if (Input.GetButtonDown(Inputs.Filter)) - searchResults.ShowSearchMenu(); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - CheckBackToMainMenu(); - } - - public void LabelCardsInStacks() - { - foreach (CardStack cardStack in CardStacks) - foreach (CardModel cardModel in cardStack.GetComponentsInChildren()) - cardModel.ShowNameLabel(); - } - - public void ResetCardStacks() - { - Clear(); - layoutContent.DestroyAllChildren(); - CardStacks.Clear(); - for (int i = 0; i < CardStackCount; i++) - { - CardStack newCardStack = Instantiate(cardStackPrefab, layoutContent).GetOrAddComponent(); - newCardStack.type = CardStackType.Vertical; - newCardStack.scrollRectContainer = scrollRect; - newCardStack.DoesImmediatelyRelease = true; - newCardStack.OnAddCardActions.Add(OnAddCardModel); - newCardStack.OnRemoveCardActions.Add(OnRemoveCardModel); - CardStacks.Add(newCardStack); - newCardStack.GetComponent().spacing = cardStackPrefab.GetComponent().spacing - * (CardGameManager.PixelsPerInch * CardGameManager.Current.CardSize.y / PreHeight); - } - layoutContent.sizeDelta = new Vector2(cardStackPrefab.GetComponent().rect.width * CardStacks.Count, - layoutContent.sizeDelta.y); - } - - public void OnDrop(CardModel cardModel) - { - AddCardModel(cardModel); - } - - public void AddCardModel(CardModel cardModel) - { - if (cardModel == null || CardStacks.Count < 1) - return; - - EventSystem.current.SetSelectedGameObject(null, cardModel.CurrentPointerEventData); - - AddCard(cardModel.Value); - } - - public void AddCard(Card card) - { - if (card == null || CardStacks.Count < 1) - return; - - int maxCopiesInStack = CardsPerStack; - CardModel newCardModel = null; - while (newCardModel == null) - { - if (CardStacks[CurrentCardStackIndex].transform.childCount < maxCopiesInStack) - { - newCardModel = Instantiate(cardModelPrefab, CardStacks[CurrentCardStackIndex].transform).GetOrAddComponent(); - newCardModel.Value = card; - } - else - { - CurrentCardStackIndex++; - if (CurrentCardStackIndex == 0) - maxCopiesInStack++; - } - } - scrollRect.horizontalNormalizedPosition = CardStacks.Count > 1 ? - CurrentCardStackIndex / (CardStacks.Count - 1f) : 0f; - - OnAddCardModel(CardStacks[CurrentCardStackIndex], newCardModel); - } - - public void OnAddCardModel(CardStack cardStack, CardModel cardModel) - { - if (cardStack == null || cardModel == null) - return; - - CurrentCardStackIndex = CardStacks.IndexOf(cardStack); - cardModel.SecondaryDragAction = cardModel.UpdateParentCardStackScrollRect; - cardModel.DoubleClickAction = DestroyCardModel; - - UpdateDeckStats(); - } - - public void OnRemoveCardModel(CardStack cardStack, CardModel cardModel) - { - if (cardModel.HasImage) - cardModel.HideNameLabel(); - UpdateDeckStats(); - } - - public void DestroyCardModel(CardModel cardModel) - { - if (cardModel == null) - return; - - cardModel.transform.SetParent(null); - Destroy(cardModel.gameObject); - CardInfoViewer.Instance.IsVisible = false; - - UpdateDeckStats(); - } - - public void Sort() - { - Deck sortedDeck = CurrentDeck; - sortedDeck.Sort(); - foreach (CardStack stack in CardStacks) - stack.transform.DestroyAllChildren(); - CurrentCardStackIndex = 0; - foreach (Card card in sortedDeck.Cards) - AddCard(card); - } - - public void PromptForClear() - { - CardGameManager.Instance.Messenger.Prompt(NewDeckPrompt, Clear); - } - - public void Clear() - { - foreach (CardStack stack in CardStacks) - stack.transform.DestroyAllChildren(); - CurrentCardStackIndex = 0; - scrollRect.horizontalNormalizedPosition = 0; - - CardInfoViewer.Instance.IsVisible = false; - SavedDeck = null; - UpdateDeckStats(); - } - - public string UpdateDeckName(string newName) - { - if (newName == null) - newName = string.Empty; - newName = UnityExtensionMethods.GetSafeFileName(newName); - nameText.text = newName + (HasChanged ? ChangeIndicator : string.Empty); - return newName; - } - - public void UpdateDeckStats() - { - string deckName = Deck.DefaultName; - if (SavedDeck != null) - deckName = SavedDeck.Name; - nameText.text = deckName + (HasChanged ? ChangeIndicator : string.Empty); - countText.text = CurrentDeck.Cards.Count.ToString(); - } - - public void ShowDeckLoadMenu() - { - Deck currentDeck = CurrentDeck; - DeckLoader.Show(LoadDeck, currentDeck.Name, currentDeck.Cards.Count > 0 ? currentDeck.ToString() : null); - } - - public void LoadDeck(Deck newDeck) - { - if (newDeck == null) - return; - - Clear(); - foreach (Card card in newDeck.Cards) - AddCard(card); - SavedDeck = newDeck; - UpdateDeckStats(); - } - - public void ShowDeckSaveMenu() - { - Deck deckToSave = CurrentDeck; - bool overwrite = SavedDeck != null && deckToSave.Name.Equals(SavedDeck.Name); - DeckSaver.Show(deckToSave, UpdateDeckName, OnSaveDeck, overwrite); - } - - public void OnSaveDeck(Deck savedDeck) - { - SavedDeck = savedDeck; - UpdateDeckStats(); - } - - public void CheckBackToMainMenu() - { - if (HasChanged) - { - CardGameManager.Instance.Messenger.Ask(SaveChangesPrompt, BackToMainMenu, ShowDeckSaveMenu); - return; - } - - BackToMainMenu(); - } - - public void BackToMainMenu() - { - SceneManager.LoadScene(MainMenu.MainMenuSceneIndex); - } -} diff --git a/Assets/Scripts/CGS/DeckEditor/DeckEditorLayout.cs b/Assets/Scripts/CGS/DeckEditor/DeckEditorLayout.cs deleted file mode 100644 index 700c0e1e95a715c3ec5ed7b417661c6205b80f8c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5672 zcmd5=Yje^-6uqDQ73nt|ZEUNxKH56kI^vAlPOJDCX(%WSOp=0F{p;#EyIGUK=0Tt% zlL-mg-TOLw@1EU1zpo{fzW8z}j(oziFOf{;wfe&Eo;;U3xJGgH1tE3*MRc45VRv}{TP))q&}g(d6}iK{&71Cbv7IdTv86WPOe z%Dan;h}ivNq!=NM5+$~wncfV5$E=NZzloiXQ6a2p19#8rd6D0Vwe)^VS*>T0-Rf-Q zw3R{ZMH`l?-o#DJo5ct7N3Xm_}|Q292=AEtHoq>cqDUgwV7h~ zds!?t6&A+(ax@mtZ&rW+ncR~Pc)N+I&d|bj;iE!~t6^7JbA{EXfz=?r za!gS9^}5Ja#{ueG;fn0Gk7jMW4SdVvxGdU4cvsc->S*Uj*g>=z!7MY#Uw?}vjSH)K zJ(-48WUFyKSt0D3trhhomCriL&EqgdF*N?>am{>t&r{w}LkOlf0Ip=PY0tB5Sv$v= z3(PM^PLP}Vb{?Y_D=l-CESFF6RPw4zd}r1s-ruC&4L|B5#~t+BK!07ePr$yvVytF} zZT0MfMSJoVQk&32&S3DHW;7V7<{6-Gq`0>~!;(#peBT_E4Vr7$uUToFjLtN_=iY+M zlir@eE6usJR%WBUYB}-%QJZb&{=l$lo8IEQbaN2ke2U~{3Wo;lv|GIotG03f#O37n zI*j)(hUeRCEzhj~Yi}~E4XU>K=^_R`BB#CakWse1l_T}%SKj;}686303$)bR1#)+5 z8(F@R*$^(9jq4e?7P5hP$9-oVZp0WC%cvJkvtDG^$90{5_B}@VIRv9;A6qSIwyd4! z0_z&J^vYg+kE648-pgtcGu6#JtJLN7%-m+_4x!roE0T%g$V|DxM&c&v37F zirPbdMMlKT|Bk%inc!CD#LQrp&-z@PgpMGAyu(9nPi9G0KlSnSZ=e{Rt(qGicZ8k+ zB+@eO-dc*UO)xe9m*H2vv*)Vl!Qu^Nx34(rppeTgCYicIrJc-_=eg9z7 Mathf.FloorToInt(layoutArea.rect.width / (CardGameManager.PixelsPerInch * CardGameManager.Current.CardSize.x + layoutArea.gameObject.GetOrAddComponent().spacing)); - public int TotalPageCount => CardsPerPage == 0 ? 0 : (AllResults.Count / CardsPerPage) + ((AllResults.Count % CardsPerPage) == 0 ? -1 : 0); - - public CardSearchMenu CardSearcher => _cardSearcher ?? - (_cardSearcher = Instantiate(cardSearchMenuPrefab).GetOrAddComponent()); - - public int CurrentPageIndex { get; set; } - - private CardSearchMenu _cardSearcher; - private List _allResults; - - void OnEnable() - { - CardSearcher.SearchCallback = ShowResults; - CardGameManager.Instance.OnSceneActions.Add(CardSearcher.ClearSearch); - } - - public string SetNameInputField(string nameFilter) - { - nameInputField.text = nameFilter; - return nameInputField.text; - } - - public void SetNameFilter(string nameFilter) - { - CardSearcher.SetNameFilter(nameFilter); - } - - public void ClearSearchName() - { - CardSearcher.ClearSearchName(); - } - - public void Search() - { - CardSearcher.Search(); - } - - public void PageLeft() - { - if (!CardInfoViewer.Instance.zoomPanel.gameObject.activeSelf) - CardInfoViewer.Instance.SelectedCardModel = null; - CurrentPageIndex--; - if (CurrentPageIndex < 0) - CurrentPageIndex = TotalPageCount; - UpdateSearchResultsPanel(); - } - - public void PageRight() - { - if (!CardInfoViewer.Instance.zoomPanel.gameObject.activeSelf) - CardInfoViewer.Instance.SelectedCardModel = null; - CurrentPageIndex++; - if (CurrentPageIndex > TotalPageCount) - CurrentPageIndex = 0; - UpdateSearchResultsPanel(); - } - - public void UpdateSearchResultsPanel() - { - layoutArea.DestroyAllChildren(); - - for (int i = 0; i < CardsPerPage && CurrentPageIndex >= 0 && CurrentPageIndex * CardsPerPage + i < AllResults.Count; i++) - { - string cardId = AllResults[CurrentPageIndex * CardsPerPage + i].Id; - if (!CardGameManager.Current.Cards.ContainsKey(cardId)) - continue; - Card cardToShow = CardGameManager.Current.Cards[cardId]; - CardModel cardModelToShow = Instantiate(deckEditor.cardModelPrefab, layoutArea).GetOrAddComponent(); - cardModelToShow.Value = cardToShow; - cardModelToShow.DoesCloneOnDrag = true; - if (((RectTransform)deckEditor.transform).rect.width > ((RectTransform)deckEditor.transform).rect.height) - cardModelToShow.DoubleClickAction = deckEditor.AddCardModel; - else - cardModelToShow.DoubleClickAction = CardInfoViewer.Instance.ShowCardZoomed; - } - - countText.text = (CurrentPageIndex + 1) + "/" + (TotalPageCount + 1); - } - - public void ShowSearchMenu() - { - CardSearcher.Show(SetNameInputField, ShowResults); - } - - public void ShowResults(string filters, List results) - { - if (string.IsNullOrEmpty(filters)) - filters = EmptyFilterText; - filtersText.text = filters; - - AllResults = results; - } - - public List AllResults - { - get { return _allResults ?? (_allResults = new List()); } - set - { - _allResults = value; - CurrentPageIndex = 0; - UpdateSearchResultsPanel(); - } - } -} diff --git a/Assets/Scripts/CGS/DeckEditor.meta b/Assets/Scripts/CGS/EditDeck.meta similarity index 100% rename from Assets/Scripts/CGS/DeckEditor.meta rename to Assets/Scripts/CGS/EditDeck.meta diff --git a/Assets/Scripts/CGS/EditDeck/CardSelector.cs b/Assets/Scripts/CGS/EditDeck/CardSelector.cs new file mode 100644 index 000000000..d93c57524 --- /dev/null +++ b/Assets/Scripts/CGS/EditDeck/CardSelector.cs @@ -0,0 +1,273 @@ +using System.Collections.Generic; +using CardGameView; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace CGS.EditDeck +{ + public class CardSelector : MonoBehaviour + { + public DeckEditor editor; + public SearchResults results; + + void Update() + { + if (CardGameManager.TopMenuCanvas != null || editor.searchResults.nameInputField.isFocused) + return; + + if (CardInfoViewer.Instance.zoomPanel.gameObject.activeSelf && SwipeManager.DetectSwipe()) + { + if (SwipeManager.IsSwipingDown()) + SelectUp(); + else if (SwipeManager.IsSwipingUp()) + SelectDown(); + else if (SwipeManager.IsSwipingRight()) + SelectLeft(); + else if (SwipeManager.IsSwipingLeft()) + SelectRight(); + } + + if (Input.anyKeyDown) + { + if (Input.GetButtonDown(Inputs.Vertical)) + { + if (Input.GetAxis(Inputs.Vertical) > 0) + SelectUp(); + else + SelectDown(); + } + else if (Input.GetButtonDown(Inputs.Horizontal)) + { + if (Input.GetAxis(Inputs.Horizontal) > 0) + SelectRight(); + else + SelectLeft(); + } + else if (Input.GetButtonDown(Inputs.Column)) + { + if (Input.GetAxis(Inputs.Column) > 0) + ShiftRight(); + else + ShiftLeft(); + } + else if (Input.GetButtonDown(Inputs.Page) && !CardInfoViewer.Instance.IsVisible) + { + if (Input.GetAxis(Inputs.Page) > 0) + PageRight(); + else + PageLeft(); + } + } + } + + public void SelectDown() + { + if (EventSystem.current.alreadySelecting) + return; + + List editorCards = editor.CardModels; + if (editorCards.Count < 1) + { + EventSystem.current.SetSelectedGameObject(null); + return; + } + + for (int i = 0; i < editorCards.Count; i++) + { + if (editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) + continue; + i++; + if (i == editorCards.Count) + i = 0; + EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); + return; + } + EventSystem.current.SetSelectedGameObject(editorCards[0].gameObject); + } + + public void SelectUp() + { + if (EventSystem.current.alreadySelecting) + return; + + List editorCards = editor.CardModels; + if (editorCards.Count < 1) + { + EventSystem.current.SetSelectedGameObject(null); + return; + } + + for (int i = editorCards.Count - 1; i >= 0; i--) + { + if (editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) + continue; + i--; + if (i < 0) + i = editorCards.Count - 1; + EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); + return; + } + EventSystem.current.SetSelectedGameObject(editorCards[editorCards.Count - 1].gameObject); + } + + public void SelectLeft() + { + if (EventSystem.current.alreadySelecting) + return; + + if (results.layoutArea.childCount < 1) + { + EventSystem.current.SetSelectedGameObject(null); + return; + } + + for (int i = results.layoutArea.childCount - 1; i >= 0; i--) + { + if (results.layoutArea.GetChild(i).GetComponent() != CardInfoViewer.Instance.SelectedCardModel) + continue; + i--; + if (i < 0) + { + results.PageLeft(); + i = results.layoutArea.childCount - 1; + } + EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(i).gameObject); + return; + } + EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(0).gameObject); + } + + public void SelectRight() + { + if (EventSystem.current.alreadySelecting) + return; + + if (results.layoutArea.childCount < 1) + { + EventSystem.current.SetSelectedGameObject(null); + return; + } + + for (int i = 0; i < results.layoutArea.childCount; i++) + { + if (results.layoutArea.GetChild(i).GetComponent() != CardInfoViewer.Instance.SelectedCardModel) + continue; + i++; + if (i == results.layoutArea.childCount) + { + results.PageRight(); + i = 0; + } + EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(i).gameObject); + return; + } + EventSystem.current.SetSelectedGameObject(results.layoutArea.GetChild(0).gameObject); + } + + public void ShiftLeft() + { + if (EventSystem.current.alreadySelecting) + return; + + List editorCards = editor.CardModels; + if (editorCards.Count < 1) + { + EventSystem.current.SetSelectedGameObject(null); + return; + } + + Transform startParent = null; + for (int i = editorCards.Count - 1; i >= 0; i--) + { + if (startParent == null && editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) + continue; + if (editorCards[i] == CardInfoViewer.Instance.SelectedCardModel) + startParent = editorCards[i].transform.parent; + if (startParent != editorCards[i].transform.parent) + { + editor.scrollRect.horizontalNormalizedPosition = editorCards[i].transform.parent.GetSiblingIndex() / (editorCards[i].transform.parent.parent.childCount - 1f); + EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); + return; + } + } + editor.scrollRect.horizontalNormalizedPosition = 1; + EventSystem.current.SetSelectedGameObject(editorCards[editorCards.Count - 1].gameObject); + } + + public void ShiftRight() + { + if (EventSystem.current.alreadySelecting) + return; + + List editorCards = editor.CardModels; + if (editorCards.Count < 1) + { + EventSystem.current.SetSelectedGameObject(null); + return; + } + + Transform startParent = null; + for (int i = 0; i < editorCards.Count; i++) + { + if (startParent == null && editorCards[i] != CardInfoViewer.Instance.SelectedCardModel) + continue; + if (editorCards[i] == CardInfoViewer.Instance.SelectedCardModel) + startParent = editorCards[i].transform.parent; + if (startParent != editorCards[i].transform.parent) + { + editor.scrollRect.horizontalNormalizedPosition = editorCards[i].transform.parent.GetSiblingIndex() / (editorCards[i].transform.parent.parent.childCount - 1f); + EventSystem.current.SetSelectedGameObject(editorCards[i].gameObject); + return; + } + } + editor.scrollRect.horizontalNormalizedPosition = 0; + EventSystem.current.SetSelectedGameObject(editorCards[0].gameObject); + } + + public void PageLeft() + { + results.PageLeft(); + } + + public void PageRight() + { + results.PageRight(); + } + + public void GoLeft() + { + RectTransform rt = GetComponent(); + if (rt.rect.width > rt.rect.height) + ShiftLeft(); + else + PageLeft(); + } + + public void GoRight() + { + RectTransform rt = GetComponent(); + if (rt.rect.width > rt.rect.height) + ShiftRight(); + else + PageRight(); + } + + public void MoveLeft() + { + RectTransform rt = GetComponent(); + if (rt.rect.width > rt.rect.height) + PageLeft(); + else + SelectLeft(); + } + + public void MoveRight() + { + RectTransform rt = GetComponent(); + if (rt.rect.width > rt.rect.height) + PageRight(); + else + SelectRight(); + } + } +} diff --git a/Assets/Scripts/CGS/DeckEditor/CardSelector.cs.meta b/Assets/Scripts/CGS/EditDeck/CardSelector.cs.meta similarity index 100% rename from Assets/Scripts/CGS/DeckEditor/CardSelector.cs.meta rename to Assets/Scripts/CGS/EditDeck/CardSelector.cs.meta diff --git a/Assets/Scripts/CGS/EditDeck/DeckEditor.cs b/Assets/Scripts/CGS/EditDeck/DeckEditor.cs new file mode 100644 index 000000000..c0b0ab55c --- /dev/null +++ b/Assets/Scripts/CGS/EditDeck/DeckEditor.cs @@ -0,0 +1,304 @@ +using System.Collections.Generic; +using CardGameDef; +using CardGameView; +using CGS.Menus; +using CGS.Play.Zones; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using UnityEngine.SceneManagement; + +namespace CGS.EditDeck +{ + public class DeckEditor : MonoBehaviour, ICardDropHandler + { + public const string NewDeckPrompt = "Clear the editor and start a new Untitled deck?"; + public const string SaveChangesPrompt = "You have unsaved changes. Would you like to save?"; + public const string ChangeIndicator = "*"; + + public float PreHeight => cardModelPrefab.GetComponent().rect.height; + public int CardsPerStack => Mathf.FloorToInt(8 * (CardGameManager.PixelsPerInch * CardGameManager.Current.CardSize.y / PreHeight)); + public int CardStackCount => Mathf.CeilToInt((float)CardGameManager.Current.DeckMaxCount / CardsPerStack); + public List CardStacks => _cardStacks ?? (_cardStacks = new List()); + public int CurrentCardStackIndex + { + get + { + if (_currentCardStackIndex < 0 || _currentCardStackIndex >= CardStacks.Count) + _currentCardStackIndex = 0; + return _currentCardStackIndex; + } + set { _currentCardStackIndex = value; } + } + public DeckLoadMenu DeckLoader => _deckLoader ?? (_deckLoader = Instantiate(deckLoadMenuPrefab).GetOrAddComponent()); + public DeckSaveMenu DeckSaver => _deckSaver ?? (_deckSaver = Instantiate(deckSaveMenuPrefab).GetOrAddComponent()); + + public List CardModels + { + get + { + List cardModels = new List(); + foreach (CardStack stack in CardStacks) + foreach (CardModel cardModel in stack.GetComponentsInChildren()) + cardModels.Add(cardModel); + return cardModels; + } + } + public Deck CurrentDeck + { + get + { + Deck deck = new Deck(CardGameManager.Current, SavedDeck?.Name ?? Deck.DefaultName, CardGameManager.Current.DeckFileType); + foreach (CardStack stack in CardStacks) + foreach (CardModel card in stack.GetComponentsInChildren()) + deck.Cards.Add(card.Value); + return deck; + } + } + public Deck SavedDeck { get; private set; } + public bool HasChanged + { + get + { + Deck currentDeck = CurrentDeck; + if (currentDeck.Cards.Count < 1) + return false; + return !currentDeck.Equals(SavedDeck); + } + } + + public GameObject cardViewerPrefab; + public GameObject cardModelPrefab; + public GameObject cardStackPrefab; + public GameObject deckLoadMenuPrefab; + public GameObject deckSaveMenuPrefab; + public RectTransform layoutContent; + public CardDropZone dropZone; + public ScrollRect scrollRect; + public Text nameText; + public Text countText; + public SearchResults searchResults; + + private List _cardStacks; + private int _currentCardStackIndex; + private DeckLoadMenu _deckLoader; + private DeckSaveMenu _deckSaver; + + void OnEnable() + { + Instantiate(cardViewerPrefab); + CardGameManager.Instance.OnSceneActions.Add(ResetCardStacks); + } + + void Start() + { + dropZone.dropHandler = this; + } + + void Update() + { + if (CardInfoViewer.Instance.IsVisible || CardGameManager.TopMenuCanvas != null || searchResults.nameInputField.isFocused) + return; + + if (Input.GetButtonDown(Inputs.Sort)) + Sort(); + else if (Input.GetButtonDown(Inputs.New)) + PromptForClear(); + else if (Input.GetButtonDown(Inputs.Load)) + ShowDeckLoadMenu(); + else if (Input.GetButtonDown(Inputs.Save)) + ShowDeckSaveMenu(); + else if (Input.GetButtonDown(Inputs.FocusName)) + searchResults.nameInputField.ActivateInputField(); + else if (Input.GetButtonDown(Inputs.Filter)) + searchResults.ShowSearchMenu(); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + CheckBackToMainMenu(); + } + + public void ResetCardStacks() + { + Clear(); + layoutContent.DestroyAllChildren(); + CardStacks.Clear(); + for (int i = 0; i < CardStackCount; i++) + { + CardStack newCardStack = Instantiate(cardStackPrefab, layoutContent).GetOrAddComponent(); + newCardStack.type = CardStackType.Vertical; + newCardStack.scrollRectContainer = scrollRect; + newCardStack.DoesImmediatelyRelease = true; + newCardStack.OnAddCardActions.Add(OnAddCardModel); + newCardStack.OnRemoveCardActions.Add(OnRemoveCardModel); + CardStacks.Add(newCardStack); + newCardStack.GetComponent().spacing = cardStackPrefab.GetComponent().spacing + * (CardGameManager.PixelsPerInch * CardGameManager.Current.CardSize.y / PreHeight); + } + layoutContent.sizeDelta = new Vector2(cardStackPrefab.GetComponent().rect.width * CardStacks.Count, + layoutContent.sizeDelta.y); + } + + public void OnDrop(CardModel cardModel) + { + AddCardModel(cardModel); + } + + public void AddCardModel(CardModel cardModel) + { + if (cardModel == null || CardStacks.Count < 1) + return; + + EventSystem.current.SetSelectedGameObject(null, cardModel.CurrentPointerEventData); + + AddCard(cardModel.Value); + } + + public void AddCard(Card card) + { + if (card == null || CardStacks.Count < 1) + return; + + int maxCopiesInStack = CardsPerStack; + CardModel newCardModel = null; + while (newCardModel == null) + { + if (CardStacks[CurrentCardStackIndex].transform.childCount < maxCopiesInStack) + { + newCardModel = Instantiate(cardModelPrefab, CardStacks[CurrentCardStackIndex].transform).GetOrAddComponent(); + newCardModel.Value = card; + } + else + { + CurrentCardStackIndex++; + if (CurrentCardStackIndex == 0) + maxCopiesInStack++; + } + } + scrollRect.horizontalNormalizedPosition = CardStacks.Count > 1 ? + CurrentCardStackIndex / (CardStacks.Count - 1f) : 0f; + + OnAddCardModel(CardStacks[CurrentCardStackIndex], newCardModel); + } + + public void OnAddCardModel(CardStack cardStack, CardModel cardModel) + { + if (cardStack == null || cardModel == null) + return; + + CurrentCardStackIndex = CardStacks.IndexOf(cardStack); + cardModel.SecondaryDragAction = cardModel.UpdateParentCardStackScrollRect; + cardModel.DoubleClickAction = DestroyCardModel; + + UpdateDeckStats(); + } + + public void OnRemoveCardModel(CardStack cardStack, CardModel cardModel) + { + UpdateDeckStats(); + } + + public void DestroyCardModel(CardModel cardModel) + { + if (cardModel == null) + return; + + cardModel.transform.SetParent(null); + Destroy(cardModel.gameObject); + CardInfoViewer.Instance.IsVisible = false; + + UpdateDeckStats(); + } + + public void Sort() + { + Deck sortedDeck = CurrentDeck; + sortedDeck.Sort(); + foreach (CardStack stack in CardStacks) + stack.transform.DestroyAllChildren(); + CurrentCardStackIndex = 0; + foreach (Card card in sortedDeck.Cards) + AddCard(card); + } + + public void PromptForClear() + { + CardGameManager.Instance.Messenger.Prompt(NewDeckPrompt, Clear); + } + + public void Clear() + { + foreach (CardStack stack in CardStacks) + stack.transform.DestroyAllChildren(); + CurrentCardStackIndex = 0; + scrollRect.horizontalNormalizedPosition = 0; + + CardInfoViewer.Instance.IsVisible = false; + SavedDeck = null; + UpdateDeckStats(); + } + + public string UpdateDeckName(string newName) + { + if (newName == null) + newName = string.Empty; + newName = UnityExtensionMethods.GetSafeFileName(newName); + nameText.text = newName + (HasChanged ? ChangeIndicator : string.Empty); + return newName; + } + + public void UpdateDeckStats() + { + string deckName = Deck.DefaultName; + if (SavedDeck != null) + deckName = SavedDeck.Name; + nameText.text = deckName + (HasChanged ? ChangeIndicator : string.Empty); + countText.text = CurrentDeck.Cards.Count.ToString(); + } + + public void ShowDeckLoadMenu() + { + Deck currentDeck = CurrentDeck; + DeckLoader.Show(LoadDeck, currentDeck.Name, currentDeck.Cards.Count > 0 ? currentDeck.ToString() : null); + } + + public void LoadDeck(Deck newDeck) + { + if (newDeck == null) + return; + + Clear(); + foreach (Card card in newDeck.Cards) + AddCard(card); + SavedDeck = newDeck; + UpdateDeckStats(); + } + + public void ShowDeckSaveMenu() + { + Deck deckToSave = CurrentDeck; + bool overwrite = SavedDeck != null && deckToSave.Name.Equals(SavedDeck.Name); + DeckSaver.Show(deckToSave, UpdateDeckName, OnSaveDeck, overwrite); + } + + public void OnSaveDeck(Deck savedDeck) + { + SavedDeck = savedDeck; + UpdateDeckStats(); + } + + public void CheckBackToMainMenu() + { + if (HasChanged) + { + CardGameManager.Instance.Messenger.Ask(SaveChangesPrompt, BackToMainMenu, ShowDeckSaveMenu); + return; + } + + BackToMainMenu(); + } + + public void BackToMainMenu() + { + SceneManager.LoadScene(MainMenu.MainMenuSceneIndex); + } + } +} diff --git a/Assets/Scripts/CGS/DeckEditor/DeckEditor.cs.meta b/Assets/Scripts/CGS/EditDeck/DeckEditor.cs.meta similarity index 100% rename from Assets/Scripts/CGS/DeckEditor/DeckEditor.cs.meta rename to Assets/Scripts/CGS/EditDeck/DeckEditor.cs.meta diff --git a/Assets/Scripts/CGS/EditDeck/DeckEditorLayout.cs b/Assets/Scripts/CGS/EditDeck/DeckEditorLayout.cs new file mode 100644 index 0000000000000000000000000000000000000000..8193994457e8e56cfb0c99923c1864ab81612b02 GIT binary patch literal 6078 zcmd5=ZBx@g5Z=%Hitw$D5&=bg0UQ;kIHSUV;OE*FS}iG)L=e%xu0GFQ)+X)cg{B=l zne?u?yS?3KZ{P0E?{5-GUjjK7Pu@sNLg`2o?S*vZ6eC@^mKU-l>3JuZ-4p*2I|c9PfMl3-G=M^&UpAK#AjFYLE1OdHa$|WT>8jhao6&hfko^L9YjC zdI|rYY-3~%&oew{2?9!2+pJutW^D|*p{!%|vFXL&nv(E)Acx7f5PK76{->5=BT;}= z+p>dSqJE7wOS1ufHo(mTjI2llTwApB(DT6wXT;DDCF|oX^zhG<`*@$qCccy2Jv=-K zDwnod`G_15vsxtO7C4|(1L$jLq5YquJ?abSCFxNpAV; z>So30Mp3A)oxA%1dWsMh-;)pMG5%EXgGF9Iz2M`-&gSF4Ci$+5`N)6MGDiM)8V|N_ zVo6_q7#~dEJZmr3gr;Id#UXTdX?E$td&jaRM;KvT`3Swzqet*{jC&V|UJXQ(bmX~4 z#IW&|QOm6c|4MHnj%dD&Yz|Hmn*xl@EpbAWTe%sP!ocFfK970wXt z)RP0)b3Wg@m_-jxn`aizmU%P1z&XCt`X^Djb$rt-vk%|lVcjy;+vsqBYT*lL+02!- z2D46{$+y^LAARO5s_z@;j!IqI5Nl#nGXy!=yw1#*-7{8ZYlG>1qf4*4ce*ZNjl>L@ z(jP%uTO-)rY3*(=>B&Q&IX<4w{)_f6wtGKELp+DEyh`b*0e;=wZ-Kityg%`HxwCeX z`b+DRBA&}F_5bocX$`7vm*4h*NdP3RR9#r4t48!tch5RDQ#0;b_$5ZBt7cifyH=J* z(jtwQozlfb@Dv)$ue8cDVq#fLqaLankFs%jQO~2hCaQ*_du=uJimZ7u2U%3~(wRf` zn#@}Bq?FZ=Q?EDPR`K79Y0>+ol}xqsSWc%J!qv`ZHXHPjz40cM`4MZoL&P8Eam=*n z5x&Fg@Gf-Kc|)kW%+EG`IYAcF0o54P(&sMA2lwTz=fGr;Mc!ZYMZMD|r>s8pPMcoV zH~ib13Pw}jRWBPk0+S;TD&>rK+ktyVh6`rKyzl0&#O@5T4KQYJ(iJmpf2DF`_WAw= D+-dN+ literal 0 HcmV?d00001 diff --git a/Assets/Scripts/CGS/DeckEditor/DeckEditorLayout.cs.meta b/Assets/Scripts/CGS/EditDeck/DeckEditorLayout.cs.meta similarity index 100% rename from Assets/Scripts/CGS/DeckEditor/DeckEditorLayout.cs.meta rename to Assets/Scripts/CGS/EditDeck/DeckEditorLayout.cs.meta diff --git a/Assets/Scripts/CGS/EditDeck/SearchResults.cs b/Assets/Scripts/CGS/EditDeck/SearchResults.cs new file mode 100644 index 000000000..6c4c05076 --- /dev/null +++ b/Assets/Scripts/CGS/EditDeck/SearchResults.cs @@ -0,0 +1,127 @@ +using System.Collections.Generic; +using CardGameDef; +using CardGameView; +using CGS.Menus; +using UnityEngine; +using UnityEngine.UI; + +namespace CGS.EditDeck +{ + public class SearchResults : MonoBehaviour + { + public const string EmptyFilterText = "*"; + + public GameObject cardSearchMenuPrefab; + public DeckEditor deckEditor; + public RectTransform layoutArea; + public InputField nameInputField; + public Text filtersText; + public Text countText; + + public int CardsPerPage => Mathf.FloorToInt(layoutArea.rect.width / + (CardGameManager.PixelsPerInch * CardGameManager.Current.CardSize.x + layoutArea.gameObject.GetOrAddComponent().spacing)); + public int TotalPageCount => CardsPerPage == 0 ? 0 : (AllResults.Count / CardsPerPage) + ((AllResults.Count % CardsPerPage) == 0 ? -1 : 0); + + public CardSearchMenu CardSearcher => _cardSearcher ?? + (_cardSearcher = Instantiate(cardSearchMenuPrefab).GetOrAddComponent()); + + public int CurrentPageIndex { get; set; } + + private CardSearchMenu _cardSearcher; + private List _allResults; + + void OnEnable() + { + CardSearcher.SearchCallback = ShowResults; + CardGameManager.Instance.OnSceneActions.Add(CardSearcher.ClearSearch); + } + + public string SetNameInputField(string nameFilter) + { + nameInputField.text = nameFilter; + return nameInputField.text; + } + + public void SetNameFilter(string nameFilter) + { + CardSearcher.SetNameFilter(nameFilter); + } + + public void ClearSearchName() + { + CardSearcher.ClearSearchName(); + } + + public void Search() + { + CardSearcher.Search(); + } + + public void PageLeft() + { + if (!CardInfoViewer.Instance.zoomPanel.gameObject.activeSelf) + CardInfoViewer.Instance.SelectedCardModel = null; + CurrentPageIndex--; + if (CurrentPageIndex < 0) + CurrentPageIndex = TotalPageCount; + UpdateSearchResultsPanel(); + } + + public void PageRight() + { + if (!CardInfoViewer.Instance.zoomPanel.gameObject.activeSelf) + CardInfoViewer.Instance.SelectedCardModel = null; + CurrentPageIndex++; + if (CurrentPageIndex > TotalPageCount) + CurrentPageIndex = 0; + UpdateSearchResultsPanel(); + } + + public void UpdateSearchResultsPanel() + { + layoutArea.DestroyAllChildren(); + + for (int i = 0; i < CardsPerPage && CurrentPageIndex >= 0 && CurrentPageIndex * CardsPerPage + i < AllResults.Count; i++) + { + string cardId = AllResults[CurrentPageIndex * CardsPerPage + i].Id; + if (!CardGameManager.Current.Cards.ContainsKey(cardId)) + continue; + Card cardToShow = CardGameManager.Current.Cards[cardId]; + CardModel cardModelToShow = Instantiate(deckEditor.cardModelPrefab, layoutArea).GetOrAddComponent(); + cardModelToShow.Value = cardToShow; + cardModelToShow.DoesCloneOnDrag = true; + if (((RectTransform)deckEditor.transform).rect.width > ((RectTransform)deckEditor.transform).rect.height) + cardModelToShow.DoubleClickAction = deckEditor.AddCardModel; + else + cardModelToShow.DoubleClickAction = CardInfoViewer.Instance.ShowCardZoomed; + } + + countText.text = (CurrentPageIndex + 1) + "/" + (TotalPageCount + 1); + } + + public void ShowSearchMenu() + { + CardSearcher.Show(SetNameInputField, ShowResults); + } + + public void ShowResults(string filters, List results) + { + if (string.IsNullOrEmpty(filters)) + filters = EmptyFilterText; + filtersText.text = filters; + + AllResults = results; + } + + public List AllResults + { + get { return _allResults ?? (_allResults = new List()); } + set + { + _allResults = value; + CurrentPageIndex = 0; + UpdateSearchResultsPanel(); + } + } + } +} diff --git a/Assets/Scripts/CGS/DeckEditor/SearchResults.cs.meta b/Assets/Scripts/CGS/EditDeck/SearchResults.cs.meta similarity index 100% rename from Assets/Scripts/CGS/DeckEditor/SearchResults.cs.meta rename to Assets/Scripts/CGS/EditDeck/SearchResults.cs.meta diff --git a/Assets/Scripts/CGS/Inputs.cs b/Assets/Scripts/CGS/Inputs.cs index fb1f9c588..13b370fdf 100644 --- a/Assets/Scripts/CGS/Inputs.cs +++ b/Assets/Scripts/CGS/Inputs.cs @@ -1,27 +1,30 @@ using UnityEngine; -public static class Inputs +namespace CGS { - public const KeyCode BluetoothReturn = (KeyCode)10; - public const string Cancel = "Cancel"; - public const string Column = "Column"; - public const string Delete = "Delete"; - public const string Filter = "Filter"; - public const string FocusName = "FocusName"; - public const string FocusText = "FocusText"; - public const string Horizontal = "Horizontal"; - public const string Load = "Load"; - public const string New = "New"; - public const string Page = "Page"; - public const string Save = "Save"; - public const string Sort = "Sort"; - public const string Submit = "Submit"; - public const string Vertical = "Vertical"; - - public static char FilterFocusNameInput(char charToValidate) + public static class Inputs { - if (charToValidate == '`') - charToValidate = '\0'; - return charToValidate; + public const KeyCode BluetoothReturn = (KeyCode)10; + public const string Cancel = "Cancel"; + public const string Column = "Column"; + public const string Delete = "Delete"; + public const string Filter = "Filter"; + public const string FocusName = "FocusName"; + public const string FocusText = "FocusText"; + public const string Horizontal = "Horizontal"; + public const string Load = "Load"; + public const string New = "New"; + public const string Page = "Page"; + public const string Save = "Save"; + public const string Sort = "Sort"; + public const string Submit = "Submit"; + public const string Vertical = "Vertical"; + + public static char FilterFocusNameInput(char charToValidate) + { + if (charToValidate == '`') + charToValidate = '\0'; + return charToValidate; + } } } diff --git a/Assets/Scripts/CGS/Menus/CardSearchMenu.cs b/Assets/Scripts/CGS/Menus/CardSearchMenu.cs index bdbe64aa0..8d3df2d4a 100644 --- a/Assets/Scripts/CGS/Menus/CardSearchMenu.cs +++ b/Assets/Scripts/CGS/Menus/CardSearchMenu.cs @@ -5,459 +5,462 @@ using UnityEngine.EventSystems; using UnityEngine.UI; -public delegate void OnSearchDelegate(string filters, List searchResults); - -public class CardSearchMenu : MonoBehaviour +namespace CGS.Menus { - public const string ClearFiltersPrompt = "Clear Filters?"; - public float PropertyPanelHeight => ((RectTransform)stringPropertyPanel.transform).rect.height; + public delegate void OnSearchDelegate(string filters, List searchResults); - public Scrollbar scrollbar; - public InputField nameInputField; - public InputField idInputField; - public InputField setCodeInputField; - public RectTransform propertyFiltersContent; - public SearchPropertyPanel stringPropertyPanel; - public SearchPropertyPanel integerPropertyPanel; - public SearchPropertyPanel enumPropertyPanel; + public class CardSearchMenu : MonoBehaviour + { + public const string ClearFiltersPrompt = "Clear Filters?"; + public float PropertyPanelHeight => ((RectTransform)stringPropertyPanel.transform).rect.height; - public OnNameChangeDelegate NameChangeCallback { get; set; } - public OnSearchDelegate SearchCallback { get; set; } + public Scrollbar scrollbar; + public InputField nameInputField; + public InputField idInputField; + public InputField setCodeInputField; + public RectTransform propertyFiltersContent; + public SearchPropertyPanel stringPropertyPanel; + public SearchPropertyPanel integerPropertyPanel; + public SearchPropertyPanel enumPropertyPanel; - public List FilterPanels { get; } = new List(); - public List InputFields { get; } = new List(); - public List Toggles { get; } = new List(); + public OnNameChangeDelegate NameChangeCallback { get; set; } + public OnSearchDelegate SearchCallback { get; set; } - public CardSearchFilters Filters { get; } = new CardSearchFilters(); - public List Results { get; } = new List(); + public List FilterPanels { get; } = new List(); + public List InputFields { get; } = new List(); + public List Toggles { get; } = new List(); - public InputField ActiveInputField - { - get - { - return EventSystem.current.currentSelectedGameObject != null - ? EventSystem.current.currentSelectedGameObject?.GetComponent() : null; - } - set - { - if (!EventSystem.current.alreadySelecting) - EventSystem.current.SetSelectedGameObject(value.gameObject); - } - } + public CardSearchFilters Filters { get; } = new CardSearchFilters(); + public List Results { get; } = new List(); - public Toggle ActiveToggle - { - get + public InputField ActiveInputField { - return EventSystem.current.currentSelectedGameObject != null - ? EventSystem.current.currentSelectedGameObject.GetComponent() : null; - } - set - { - if (!EventSystem.current.alreadySelecting) - EventSystem.current.SetSelectedGameObject(value.gameObject); - } - } - - void LateUpdate() - { - if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) - return; - - if (Input.GetButtonDown(Inputs.FocusName) || Input.GetButtonDown(Inputs.FocusText)) - { - FocusInputField(); - return; + get + { + return EventSystem.current.currentSelectedGameObject != null + ? EventSystem.current.currentSelectedGameObject?.GetComponent() : null; + } + set + { + if (!EventSystem.current.alreadySelecting) + EventSystem.current.SetSelectedGameObject(value.gameObject); + } } - if (ActiveInputField != null && ActiveInputField.isFocused) - return; - - if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) + public Toggle ActiveToggle { - Search(); - Hide(); + get + { + return EventSystem.current.currentSelectedGameObject != null + ? EventSystem.current.currentSelectedGameObject.GetComponent() : null; + } + set + { + if (!EventSystem.current.alreadySelecting) + EventSystem.current.SetSelectedGameObject(value.gameObject); + } } - else if (Input.GetButtonDown(Inputs.Page)) - scrollbar.value = Mathf.Clamp01(scrollbar.value + (Input.GetAxis(Inputs.Page) < 0 ? 0.1f : -0.1f)); - else if (Input.GetButtonDown(Inputs.Vertical) || Input.GetButtonDown(Inputs.Horizontal)) - FocusToggle(); - else if (Input.GetButtonDown(Inputs.New) && ActiveToggle != null) - ToggleEnum(); - else if (Input.GetButtonDown(Inputs.Delete) && ActiveInputField == null) - ClearFilters(); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - Hide(); - } - public void FocusInputField() - { - if (ActiveInputField == null || InputFields.Count < 1) + void LateUpdate() { - InputFields.FirstOrDefault()?.ActivateInputField(); - ActiveInputField = InputFields.FirstOrDefault(); - return; - } + if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) + return; - if (Input.GetButtonDown(Inputs.FocusName)) - { // up - InputField previous = InputFields.Last(); - for (int i = 0; i < InputFields.Count; i++) + if (Input.GetButtonDown(Inputs.FocusName) || Input.GetButtonDown(Inputs.FocusText)) { - if (ActiveInputField == InputFields[i]) - { - previous.ActivateInputField(); - ActiveInputField = previous; - break; - } - previous = InputFields[i]; + FocusInputField(); + return; } - } - else - { // down - InputField next = InputFields.First(); - for (int i = InputFields.Count - 1; i >= 0; i--) + + if (ActiveInputField != null && ActiveInputField.isFocused) + return; + + if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) { - if (ActiveInputField == InputFields[i]) - { - next.ActivateInputField(); - ActiveInputField = next; - break; - } - next = InputFields[i]; + Search(); + Hide(); } + else if (Input.GetButtonDown(Inputs.Page)) + scrollbar.value = Mathf.Clamp01(scrollbar.value + (Input.GetAxis(Inputs.Page) < 0 ? 0.1f : -0.1f)); + else if (Input.GetButtonDown(Inputs.Vertical) || Input.GetButtonDown(Inputs.Horizontal)) + FocusToggle(); + else if (Input.GetButtonDown(Inputs.New) && ActiveToggle != null) + ToggleEnum(); + else if (Input.GetButtonDown(Inputs.Delete) && ActiveInputField == null) + ClearFilters(); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + Hide(); } - } - public void FocusToggle() - { - if (ActiveToggle == null || Toggles.Count < 1) + public void FocusInputField() { - ActiveToggle = Toggles.FirstOrDefault(); - return; - } + if (ActiveInputField == null || InputFields.Count < 1) + { + InputFields.FirstOrDefault()?.ActivateInputField(); + ActiveInputField = InputFields.FirstOrDefault(); + return; + } - if (Input.GetButtonDown(Inputs.Vertical)) - { - Transform currentPanel = ActiveToggle.transform.parent; - if (Input.GetAxis(Inputs.Vertical) > 0) + if (Input.GetButtonDown(Inputs.FocusName)) { // up - Toggle previous = Toggles.Last(); - for (int i = 0; i < Toggles.Count; i++) + InputField previous = InputFields.Last(); + for (int i = 0; i < InputFields.Count; i++) { - if (ActiveToggle == Toggles[i]) + if (ActiveInputField == InputFields[i]) { - ActiveToggle = previous; + previous.ActivateInputField(); + ActiveInputField = previous; break; } - if (Toggles[i].transform.parent != ActiveToggle.transform.parent) - previous = Toggles[i]; + previous = InputFields[i]; } } else { // down - Toggle next = Toggles.First(); - for (int i = Toggles.Count - 1; i >= 0; i--) + InputField next = InputFields.First(); + for (int i = InputFields.Count - 1; i >= 0; i--) { - if (ActiveToggle == Toggles[i]) + if (ActiveInputField == InputFields[i]) { - ActiveToggle = next; + next.ActivateInputField(); + ActiveInputField = next; break; } - if (Toggles[i].transform.parent != ActiveToggle.transform.parent) - next = Toggles[i]; + next = InputFields[i]; } } } - else if (Input.GetButton(Inputs.Horizontal)) + + public void FocusToggle() { - if (Input.GetAxis(Inputs.Horizontal) > 0) - { // right - Toggle next = Toggles.First(); - for (int i = Toggles.Count - 1; i >= 0; i--) - { - if (ActiveToggle == Toggles[i]) + if (ActiveToggle == null || Toggles.Count < 1) + { + ActiveToggle = Toggles.FirstOrDefault(); + return; + } + + if (Input.GetButtonDown(Inputs.Vertical)) + { + Transform currentPanel = ActiveToggle.transform.parent; + if (Input.GetAxis(Inputs.Vertical) > 0) + { // up + Toggle previous = Toggles.Last(); + for (int i = 0; i < Toggles.Count; i++) { - ActiveToggle = next; - break; + if (ActiveToggle == Toggles[i]) + { + ActiveToggle = previous; + break; + } + if (Toggles[i].transform.parent != ActiveToggle.transform.parent) + previous = Toggles[i]; + } + } + else + { // down + Toggle next = Toggles.First(); + for (int i = Toggles.Count - 1; i >= 0; i--) + { + if (ActiveToggle == Toggles[i]) + { + ActiveToggle = next; + break; + } + if (Toggles[i].transform.parent != ActiveToggle.transform.parent) + next = Toggles[i]; } - next = Toggles[i]; } } - else - { // left - Toggle previous = Toggles.Last(); - for (int i = 0; i < Toggles.Count; i++) - { - if (ActiveToggle == Toggles[i]) + else if (Input.GetButton(Inputs.Horizontal)) + { + if (Input.GetAxis(Inputs.Horizontal) > 0) + { // right + Toggle next = Toggles.First(); + for (int i = Toggles.Count - 1; i >= 0; i--) { - ActiveToggle = previous; - break; + if (ActiveToggle == Toggles[i]) + { + ActiveToggle = next; + break; + } + next = Toggles[i]; + } + } + else + { // left + Toggle previous = Toggles.Last(); + for (int i = 0; i < Toggles.Count; i++) + { + if (ActiveToggle == Toggles[i]) + { + ActiveToggle = previous; + break; + } + previous = Toggles[i]; } - previous = Toggles[i]; } } } - } - public void ToggleEnum() - { - if (ActiveToggle == null) - return; - ActiveToggle.isOn = !ActiveToggle.isOn; - } - - public void Show(OnNameChangeDelegate nameChangeCallback, OnSearchDelegate searchCallback) - { - gameObject.SetActive(true); - transform.SetAsLastSibling(); - NameChangeCallback = nameChangeCallback; - SearchCallback = searchCallback; - - stringPropertyPanel.gameObject.SetActive(false); - integerPropertyPanel.gameObject.SetActive(false); - enumPropertyPanel.gameObject.SetActive(false); - for (int i = FilterPanels.Count - 1; i >= 0; i--) + public void ToggleEnum() { - Destroy(FilterPanels[i].gameObject); - FilterPanels.RemoveAt(i); + if (ActiveToggle == null) + return; + ActiveToggle.isOn = !ActiveToggle.isOn; } - InputFields.Clear(); - Toggles.Clear(); - - nameInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; - InputFields.Add(nameInputField); - idInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; - InputFields.Add(idInputField); - setCodeInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; - InputFields.Add(setCodeInputField); - - propertyFiltersContent.sizeDelta = new Vector2(propertyFiltersContent.sizeDelta.x, PropertyPanelHeight * CardGameManager.Current.CardProperties.Count + (PropertyPanelHeight * 3)); - foreach (PropertyDef property in CardGameManager.Current.CardProperties) + + public void Show(OnNameChangeDelegate nameChangeCallback, OnSearchDelegate searchCallback) { - GameObject newPanel; - if (EnumDef.IsEnumProperty(property.Name)) - newPanel = CreateEnumPropertyFilterPanel(property); - else if (property.Type == PropertyType.Integer) - newPanel = CreateIntegerPropertyFilterPanel(property.Name, property.Display); - else //if (property.Type == PropertyType.String) - newPanel = CreateStringPropertyFilterPanel(property.Name, property.Display); - FilterPanels.Add(newPanel); - foreach (InputField inputField in newPanel.GetComponentsInChildren()) + gameObject.SetActive(true); + transform.SetAsLastSibling(); + NameChangeCallback = nameChangeCallback; + SearchCallback = searchCallback; + + stringPropertyPanel.gameObject.SetActive(false); + integerPropertyPanel.gameObject.SetActive(false); + enumPropertyPanel.gameObject.SetActive(false); + for (int i = FilterPanels.Count - 1; i >= 0; i--) { - inputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; - InputFields.Add(inputField); + Destroy(FilterPanels[i].gameObject); + FilterPanels.RemoveAt(i); + } + InputFields.Clear(); + Toggles.Clear(); + + nameInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; + InputFields.Add(nameInputField); + idInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; + InputFields.Add(idInputField); + setCodeInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; + InputFields.Add(setCodeInputField); + + propertyFiltersContent.sizeDelta = new Vector2(propertyFiltersContent.sizeDelta.x, PropertyPanelHeight * CardGameManager.Current.CardProperties.Count + (PropertyPanelHeight * 3)); + foreach (PropertyDef property in CardGameManager.Current.CardProperties) + { + GameObject newPanel; + if (CardGameManager.Current.IsEnumProperty(property.Name)) + newPanel = CreateEnumPropertyFilterPanel(property); + else if (property.Type == PropertyType.Integer) + newPanel = CreateIntegerPropertyFilterPanel(property.Name, property.Display); + else //if (property.Type == PropertyType.String) + newPanel = CreateStringPropertyFilterPanel(property.Name, property.Display); + FilterPanels.Add(newPanel); + foreach (InputField inputField in newPanel.GetComponentsInChildren()) + { + inputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return Inputs.FilterFocusNameInput(addedChar); }; + InputFields.Add(inputField); + } + foreach (Toggle toggle in newPanel.GetComponentsInChildren()) + Toggles.Add(toggle); } - foreach (Toggle toggle in newPanel.GetComponentsInChildren()) - Toggles.Add(toggle); } - } - public GameObject CreateStringPropertyFilterPanel(string propertyName, string displayName) - { - GameObject newPanel = Instantiate(stringPropertyPanel.gameObject, propertyFiltersContent); - newPanel.gameObject.SetActive(true); - - SearchPropertyPanel config = newPanel.GetComponent(); - config.nameLabelText.text = !string.IsNullOrEmpty(displayName) ? displayName : propertyName; - string storedFilter; - if (Filters.StringProperties.TryGetValue(propertyName, out storedFilter)) - config.stringInputField.text = storedFilter; - config.stringPlaceHolderText.text = "Enter " + propertyName + "..."; - config.stringInputField.onValueChanged.AddListener(text => SetStringPropertyFilter(propertyName, text)); - - return newPanel; - } - - public GameObject CreateIntegerPropertyFilterPanel(string propertyName, string displayName) - { - GameObject newPanel = Instantiate(integerPropertyPanel.gameObject, propertyFiltersContent); - newPanel.gameObject.SetActive(true); + public GameObject CreateStringPropertyFilterPanel(string propertyName, string displayName) + { + GameObject newPanel = Instantiate(stringPropertyPanel.gameObject, propertyFiltersContent); + newPanel.gameObject.SetActive(true); + + SearchPropertyPanel config = newPanel.GetComponent(); + config.nameLabelText.text = !string.IsNullOrEmpty(displayName) ? displayName : propertyName; + string storedFilter; + if (Filters.StringProperties.TryGetValue(propertyName, out storedFilter)) + config.stringInputField.text = storedFilter; + config.stringPlaceHolderText.text = "Enter " + propertyName + "..."; + config.stringInputField.onValueChanged.AddListener(text => SetStringPropertyFilter(propertyName, text)); + + return newPanel; + } - SearchPropertyPanel config = newPanel.GetComponent(); - config.nameLabelText.text = !string.IsNullOrEmpty(displayName) ? displayName : propertyName; - int storedFilter; + public GameObject CreateIntegerPropertyFilterPanel(string propertyName, string displayName) + { + GameObject newPanel = Instantiate(integerPropertyPanel.gameObject, propertyFiltersContent); + newPanel.gameObject.SetActive(true); - if (Filters.IntMinProperties.TryGetValue(propertyName, out storedFilter)) - config.integerMinInputField.text = storedFilter.ToString(); - config.integerMinInputField.onValueChanged.AddListener(text => SetIntMinPropertyFilter(propertyName, text)); + SearchPropertyPanel config = newPanel.GetComponent(); + config.nameLabelText.text = !string.IsNullOrEmpty(displayName) ? displayName : propertyName; + int storedFilter; - if (Filters.IntMaxProperties.TryGetValue(propertyName, out storedFilter)) - config.integerMaxInputField.text = storedFilter.ToString(); - config.integerMaxInputField.onValueChanged.AddListener(text => SetIntMaxPropertyFilter(propertyName, text)); + if (Filters.IntMinProperties.TryGetValue(propertyName, out storedFilter)) + config.integerMinInputField.text = storedFilter.ToString(); + config.integerMinInputField.onValueChanged.AddListener(text => SetIntMinPropertyFilter(propertyName, text)); - return newPanel; - } + if (Filters.IntMaxProperties.TryGetValue(propertyName, out storedFilter)) + config.integerMaxInputField.text = storedFilter.ToString(); + config.integerMaxInputField.onValueChanged.AddListener(text => SetIntMaxPropertyFilter(propertyName, text)); - public GameObject CreateEnumPropertyFilterPanel(PropertyDef property) - { - GameObject newPanel = Instantiate(enumPropertyPanel.gameObject, propertyFiltersContent); - newPanel.gameObject.SetActive(true); - - SearchPropertyPanel config = newPanel.GetComponent(); - config.nameLabelText.text = !string.IsNullOrEmpty(property.Display) ? property.Display : property.Name; - int storedFilter; - Filters.EnumProperties.TryGetValue(property.Name, out storedFilter); - - EnumDef enumDef = CardGameManager.Current.Enums.First(def => def.Property.Equals(property.Name)); - Vector3 localPosition = config.enumToggle.transform.localPosition; - float panelWidth = 0; - foreach (KeyValuePair enumValue in enumDef.Values) - { - int lookupKey; - if (!enumDef.Lookup.TryGetValue(enumValue.Key, out lookupKey)) - lookupKey = enumDef.CreateLookup(enumValue.Key); - Toggle newToggle = Instantiate(config.enumToggle.gameObject, config.enumContent).GetOrAddComponent(); - newToggle.isOn = (storedFilter & lookupKey) != 0; - newToggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(property.Name, lookupKey, isOn)); - newToggle.GetComponentInChildren().text = enumValue.Value; - newToggle.transform.localPosition = localPosition; - float width = newToggle.GetComponentInChildren().preferredWidth + 25; - RectTransform imageTransform = (RectTransform)newToggle.GetComponentInChildren().transform; - imageTransform.sizeDelta = new Vector2(width, imageTransform.sizeDelta.y); - localPosition.x += width; - panelWidth += width; + return newPanel; } - if (!string.IsNullOrEmpty(property.Empty)) + public GameObject CreateEnumPropertyFilterPanel(PropertyDef property) { - int lookupKey; - if (!enumDef.Lookup.TryGetValue(property.Empty, out lookupKey)) - lookupKey = enumDef.CreateLookup(property.Empty); - Toggle newToggle = Instantiate(config.enumToggle.gameObject, config.enumContent).GetOrAddComponent(); - newToggle.isOn = (storedFilter & lookupKey) != 0; - newToggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(property.Name, lookupKey, isOn)); - newToggle.GetComponentInChildren().text = property.Empty; - newToggle.transform.localPosition = localPosition; - float width = newToggle.GetComponentInChildren().preferredWidth + 25; - RectTransform imageTransform = (RectTransform)newToggle.GetComponentInChildren().transform; - imageTransform.sizeDelta = new Vector2(width, imageTransform.sizeDelta.y); - localPosition.x += width; - panelWidth += width; - } - config.enumToggle.gameObject.SetActive(false); - config.enumContent.sizeDelta = new Vector2(panelWidth, config.enumContent.sizeDelta.y); - - return newPanel; - } + GameObject newPanel = Instantiate(enumPropertyPanel.gameObject, propertyFiltersContent); + newPanel.gameObject.SetActive(true); + + SearchPropertyPanel config = newPanel.GetComponent(); + config.nameLabelText.text = !string.IsNullOrEmpty(property.Display) ? property.Display : property.Name; + int storedFilter; + Filters.EnumProperties.TryGetValue(property.Name, out storedFilter); + + EnumDef enumDef = CardGameManager.Current.Enums.First(def => def.Property.Equals(property.Name)); + Vector3 localPosition = config.enumToggle.transform.localPosition; + float panelWidth = 0; + foreach (KeyValuePair enumValue in enumDef.Values) + { + int lookupKey; + if (!enumDef.Lookup.TryGetValue(enumValue.Key, out lookupKey)) + lookupKey = enumDef.CreateLookup(enumValue.Key); + Toggle newToggle = Instantiate(config.enumToggle.gameObject, config.enumContent).GetOrAddComponent(); + newToggle.isOn = (storedFilter & lookupKey) != 0; + newToggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(property.Name, lookupKey, isOn)); + newToggle.GetComponentInChildren().text = enumValue.Value; + newToggle.transform.localPosition = localPosition; + float width = newToggle.GetComponentInChildren().preferredWidth + 25; + RectTransform imageTransform = (RectTransform)newToggle.GetComponentInChildren().transform; + imageTransform.sizeDelta = new Vector2(width, imageTransform.sizeDelta.y); + localPosition.x += width; + panelWidth += width; + } - public void SetNameFilter(string name) - { - Filters.Name = NameChangeCallback != null ? NameChangeCallback(name) : name; + if (!string.IsNullOrEmpty(property.Empty)) + { + int lookupKey; + if (!enumDef.Lookup.TryGetValue(property.Empty, out lookupKey)) + lookupKey = enumDef.CreateLookup(property.Empty); + Toggle newToggle = Instantiate(config.enumToggle.gameObject, config.enumContent).GetOrAddComponent(); + newToggle.isOn = (storedFilter & lookupKey) != 0; + newToggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(property.Name, lookupKey, isOn)); + newToggle.GetComponentInChildren().text = property.Empty; + newToggle.transform.localPosition = localPosition; + float width = newToggle.GetComponentInChildren().preferredWidth + 25; + RectTransform imageTransform = (RectTransform)newToggle.GetComponentInChildren().transform; + imageTransform.sizeDelta = new Vector2(width, imageTransform.sizeDelta.y); + localPosition.x += width; + panelWidth += width; + } + config.enumToggle.gameObject.SetActive(false); + config.enumContent.sizeDelta = new Vector2(panelWidth, config.enumContent.sizeDelta.y); - if (!nameInputField.text.Equals(Filters.Name)) - nameInputField.text = Filters.Name; - } + return newPanel; + } - public void SetIdFilter(string id) - { - Filters.Id = id; - } + public void SetNameFilter(string name) + { + Filters.Name = NameChangeCallback != null ? NameChangeCallback(name) : name; - public void SetCodeFilter(string code) - { - Filters.SetCode = code; - } + if (!nameInputField.text.Equals(Filters.Name)) + nameInputField.text = Filters.Name; + } - public void SetStringPropertyFilter(string propertyName, string filterValue) - { - if (string.IsNullOrEmpty(filterValue)) + public void SetIdFilter(string id) { - if (Filters.StringProperties.ContainsKey(propertyName)) - Filters.StringProperties.Remove(propertyName); - return; + Filters.Id = id; } - Filters.StringProperties[propertyName] = filterValue; - } - - public void SetIntMinPropertyFilter(string propertyName, string filterValue) - { - int intValue; - if (!int.TryParse(filterValue, out intValue)) + public void SetCodeFilter(string code) { - if (Filters.IntMinProperties.ContainsKey(propertyName)) - Filters.IntMinProperties.Remove(propertyName); - return; + Filters.SetCode = code; } - Filters.IntMinProperties[propertyName] = intValue; - } - - public void SetIntMaxPropertyFilter(string propertyName, string filterValue) - { - int intValue; - if (!int.TryParse(filterValue, out intValue)) + public void SetStringPropertyFilter(string propertyName, string filterValue) { - if (Filters.IntMaxProperties.ContainsKey(propertyName)) - Filters.IntMaxProperties.Remove(propertyName); - return; + if (string.IsNullOrEmpty(filterValue)) + { + if (Filters.StringProperties.ContainsKey(propertyName)) + Filters.StringProperties.Remove(propertyName); + return; + } + + Filters.StringProperties[propertyName] = filterValue; } - Filters.IntMaxProperties[propertyName] = intValue; - } + public void SetIntMinPropertyFilter(string propertyName, string filterValue) + { + int intValue; + if (!int.TryParse(filterValue, out intValue)) + { + if (Filters.IntMinProperties.ContainsKey(propertyName)) + Filters.IntMinProperties.Remove(propertyName); + return; + } - public void SetEnumPropertyFilter(string propertyName, int filterValue, bool isOn) - { - if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) - return; + Filters.IntMinProperties[propertyName] = intValue; + } + + public void SetIntMaxPropertyFilter(string propertyName, string filterValue) + { + int intValue; + if (!int.TryParse(filterValue, out intValue)) + { + if (Filters.IntMaxProperties.ContainsKey(propertyName)) + Filters.IntMaxProperties.Remove(propertyName); + return; + } - bool isStored = Filters.EnumProperties.ContainsKey(propertyName); - int storedFilter = 0; - if (isStored) - storedFilter = Filters.EnumProperties[propertyName]; + Filters.IntMaxProperties[propertyName] = intValue; + } - int newFilter = isOn ? storedFilter | filterValue : storedFilter & ~filterValue; - if (newFilter == 0) + public void SetEnumPropertyFilter(string propertyName, int filterValue, bool isOn) { + if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) + return; + + bool isStored = Filters.EnumProperties.ContainsKey(propertyName); + int storedFilter = 0; if (isStored) - Filters.EnumProperties.Remove(propertyName); + storedFilter = Filters.EnumProperties[propertyName]; + + int newFilter = isOn ? storedFilter | filterValue : storedFilter & ~filterValue; + if (newFilter == 0) + { + if (isStored) + Filters.EnumProperties.Remove(propertyName); + } + else + Filters.EnumProperties[propertyName] = newFilter; } - else - Filters.EnumProperties[propertyName] = newFilter; - } - public void ClearFilters() - { - foreach (InputField input in GetComponentsInChildren()) - input.text = string.Empty; - foreach (Toggle toggle in GetComponentsInChildren()) - toggle.isOn = false; - - Filters.Name = string.Empty; - Filters.Id = string.Empty; - Filters.SetCode = string.Empty; - Filters.StringProperties.Clear(); - Filters.IntMinProperties.Clear(); - Filters.IntMaxProperties.Clear(); - Filters.EnumProperties.Clear(); - } + public void ClearFilters() + { + foreach (InputField input in GetComponentsInChildren()) + input.text = string.Empty; + foreach (Toggle toggle in GetComponentsInChildren()) + toggle.isOn = false; + + Filters.Name = string.Empty; + Filters.Id = string.Empty; + Filters.SetCode = string.Empty; + Filters.StringProperties.Clear(); + Filters.IntMinProperties.Clear(); + Filters.IntMaxProperties.Clear(); + Filters.EnumProperties.Clear(); + } - public void ClearSearch() - { - ClearFilters(); - Search(); - } + public void ClearSearch() + { + ClearFilters(); + Search(); + } - public void ClearSearchName() - { - string name = Filters.Name; - ClearFilters(); - SetNameFilter(name); - Search(); - } + public void ClearSearchName() + { + string name = Filters.Name; + ClearFilters(); + SetNameFilter(name); + Search(); + } - public void Search() - { - Results.Clear(); - IEnumerable cardSearcher = CardGameManager.Current.FilterCards(Filters); - foreach (Card card in cardSearcher) - Results.Add(card); - SearchCallback?.Invoke(Filters.ToString(), Results); - } + public void Search() + { + Results.Clear(); + IEnumerable cardSearcher = CardGameManager.Current.FilterCards(Filters); + foreach (Card card in cardSearcher) + Results.Add(card); + SearchCallback?.Invoke(Filters.ToString(CardGameManager.Current), Results); + } - public void Hide() - { - gameObject.SetActive(false); + public void Hide() + { + gameObject.SetActive(false); + } } } diff --git a/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs b/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs index 9059e9cca..1c3b1027c 100644 --- a/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs +++ b/Assets/Scripts/CGS/Menus/DeckLoadMenu.cs @@ -8,269 +8,272 @@ using UnityEngine.EventSystems; using UnityEngine.UI; -public delegate void OnDeckLoadedDelegate(Deck loadedDeck); - -public class DeckLoadMenu : SelectionPanel +namespace CGS.Menus { - public const string DecInstructions = "//On each line, enter:\n// \n//For example:\n4 Super Awesome Card\n3 Less Awesome Card I Still Like\n1 Card That Is Situational"; - public const string HsdInstructions = "#Paste the deck string/code here"; - public const string TxtInstructions = "### Instructions\n#On each line, enter:\n# \n#For example:\n4 Super Awesome Card\n3 Less Awesome Card I Still Like\n1 Card That Is Situational"; - public const string YdkInstructions = "#On each line, enter \n#Copy/Paste recommended"; - - public const string DeletePrompt = "Are you sure you would like to delete this deck?"; - public const string DeckDeleteErrorMessage = "There was an error while attempting to delete the deck: "; - public const string DeckLoadErrorMessage = "There was an error while loading the deck: "; - public const string DeckSaveErrorMessage = "There was an error saving the deck to file: "; - - public Button shareFileButton; - public Button deleteFileButton; - public Button loadFromFileButton; - - public RectTransform newDeckPanel; - public InputField nameInputField; - public TMPro.TextMeshProUGUI instructionsText; - public TMPro.TMP_InputField textInputField; - - public OnDeckLoadedDelegate LoadCallback { get; private set; } - public string SelectedFileName { get; private set; } - public SortedDictionary DeckFiles { get; } = new SortedDictionary(); - - void LateUpdate() - { - if (nameInputField.isFocused || !Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) - return; + public delegate void OnDeckLoadedDelegate(Deck loadedDeck); - if (newDeckPanel.gameObject.activeSelf) - { - if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && EventSystem.current.currentSelectedGameObject == null) - DoSaveDontOverwrite(); - else if (Input.GetButtonDown(Inputs.New) && EventSystem.current.currentSelectedGameObject == null) - textInputField.text = string.Empty; - else if (Input.GetButtonDown(Inputs.FocusName) && EventSystem.current.currentSelectedGameObject == null) - nameInputField.ActivateInputField(); - else if (Input.GetButtonDown(Inputs.FocusText) && EventSystem.current.currentSelectedGameObject == null) - textInputField.ActivateInputField(); - else if (Input.GetButtonDown(Inputs.Save) && EventSystem.current.currentSelectedGameObject == null) - PasteClipboardIntoText(); - else if (Input.GetButtonDown(Inputs.Delete) && EventSystem.current.currentSelectedGameObject == null) - textInputField.text = string.Empty; - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - HideNewDeckPanel(); - } - else + public class DeckLoadMenu : SelectionPanel + { + public const string DecInstructions = "//On each line, enter:\n// \n//For example:\n4 Super Awesome Card\n3 Less Awesome Card I Still Like\n1 Card That Is Situational"; + public const string HsdInstructions = "#Paste the deck string/code here"; + public const string TxtInstructions = "### Instructions\n#On each line, enter:\n# \n#For example:\n4 Super Awesome Card\n3 Less Awesome Card I Still Like\n1 Card That Is Situational"; + public const string YdkInstructions = "#On each line, enter \n#Copy/Paste recommended"; + + public const string DeletePrompt = "Are you sure you would like to delete this deck?"; + public const string DeckDeleteErrorMessage = "There was an error while attempting to delete the deck: "; + public const string DeckLoadErrorMessage = "There was an error while loading the deck: "; + public const string DeckSaveErrorMessage = "There was an error saving the deck to file: "; + + public Button shareFileButton; + public Button deleteFileButton; + public Button loadFromFileButton; + + public RectTransform newDeckPanel; + public InputField nameInputField; + public TMPro.TextMeshProUGUI instructionsText; + public TMPro.TMP_InputField textInputField; + + public OnDeckLoadedDelegate LoadCallback { get; private set; } + public string SelectedFileName { get; private set; } + public SortedDictionary DeckFiles { get; } = new SortedDictionary(); + + void LateUpdate() { - if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && loadFromFileButton.interactable) - LoadFromFileAndHide(); - else if (Input.GetKeyDown(Inputs.BluetoothReturn) && Toggles.Contains(EventSystem.current.currentSelectedGameObject)) - EventSystem.current.currentSelectedGameObject.GetComponent().isOn = true; - else if (Input.GetButtonDown(Inputs.Sort) && shareFileButton.interactable) - Share(); - else if (Input.GetButtonDown(Inputs.New)) - ShowNewDeckPanel(); - else if (Input.GetButtonDown(Inputs.Delete) && deleteFileButton.interactable) - PromptForDeleteFile(); - else if (Input.GetButtonDown(Inputs.Vertical)) - ScrollToggles(Input.GetAxis(Inputs.Vertical) > 0); - else if (Input.GetButtonDown(Inputs.Page)) - ScrollPage(Input.GetAxis(Inputs.Page) < 0); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - Hide(); + if (nameInputField.isFocused || !Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) + return; + + if (newDeckPanel.gameObject.activeSelf) + { + if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && EventSystem.current.currentSelectedGameObject == null) + DoSaveDontOverwrite(); + else if (Input.GetButtonDown(Inputs.New) && EventSystem.current.currentSelectedGameObject == null) + textInputField.text = string.Empty; + else if (Input.GetButtonDown(Inputs.FocusName) && EventSystem.current.currentSelectedGameObject == null) + nameInputField.ActivateInputField(); + else if (Input.GetButtonDown(Inputs.FocusText) && EventSystem.current.currentSelectedGameObject == null) + textInputField.ActivateInputField(); + else if (Input.GetButtonDown(Inputs.Save) && EventSystem.current.currentSelectedGameObject == null) + PasteClipboardIntoText(); + else if (Input.GetButtonDown(Inputs.Delete) && EventSystem.current.currentSelectedGameObject == null) + textInputField.text = string.Empty; + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + HideNewDeckPanel(); + } + else + { + if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && loadFromFileButton.interactable) + LoadFromFileAndHide(); + else if (Input.GetKeyDown(Inputs.BluetoothReturn) && Toggles.Contains(EventSystem.current.currentSelectedGameObject)) + EventSystem.current.currentSelectedGameObject.GetComponent().isOn = true; + else if (Input.GetButtonDown(Inputs.Sort) && shareFileButton.interactable) + Share(); + else if (Input.GetButtonDown(Inputs.New)) + ShowNewDeckPanel(); + else if (Input.GetButtonDown(Inputs.Delete) && deleteFileButton.interactable) + PromptForDeleteFile(); + else if (Input.GetButtonDown(Inputs.Vertical)) + ScrollToggles(Input.GetAxis(Inputs.Vertical) > 0); + else if (Input.GetButtonDown(Inputs.Page)) + ScrollPage(Input.GetAxis(Inputs.Page) < 0); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + Hide(); + } } - } - - public void Show(OnDeckLoadedDelegate loadCallback = null, string originalName = null, string originalText = null) - { - gameObject.SetActive(true); - transform.SetAsLastSibling(); - LoadCallback = loadCallback; - SelectedFileName = string.Empty; - - BuildDeckFileSelectionOptions(); - nameInputField.text = originalName ?? Deck.DefaultName; - textInputField.text = originalText ?? string.Empty; - switch (CardGameManager.Current.DeckFileType) + public void Show(OnDeckLoadedDelegate loadCallback = null, string originalName = null, string originalText = null) { - case DeckFileType.Dec: - instructionsText.text = DecInstructions; - break; - case DeckFileType.Hsd: - instructionsText.text = HsdInstructions; - break; - case DeckFileType.Ydk: - instructionsText.text = YdkInstructions; - break; - case DeckFileType.Txt: - default: - instructionsText.text = TxtInstructions; - break; + gameObject.SetActive(true); + transform.SetAsLastSibling(); + LoadCallback = loadCallback; + SelectedFileName = string.Empty; + + BuildDeckFileSelectionOptions(); + + nameInputField.text = originalName ?? Deck.DefaultName; + textInputField.text = originalText ?? string.Empty; + switch (CardGameManager.Current.DeckFileType) + { + case DeckFileType.Dec: + instructionsText.text = DecInstructions; + break; + case DeckFileType.Hsd: + instructionsText.text = HsdInstructions; + break; + case DeckFileType.Ydk: + instructionsText.text = YdkInstructions; + break; + case DeckFileType.Txt: + default: + instructionsText.text = TxtInstructions; + break; + } } - } - public void BuildDeckFileSelectionOptions() - { - DeckFiles.Clear(); - string[] files = Directory.Exists(CardGameManager.Current.DecksFilePath) ? Directory.GetFiles(CardGameManager.Current.DecksFilePath) : new string[0]; - foreach (string file in files) - if (GetFileTypeFromPath(file) == CardGameManager.Current.DeckFileType) - DeckFiles[GetNameFromPath((file))] = file; + public void BuildDeckFileSelectionOptions() + { + DeckFiles.Clear(); + string[] files = Directory.Exists(CardGameManager.Current.DecksFilePath) ? Directory.GetFiles(CardGameManager.Current.DecksFilePath) : new string[0]; + foreach (string file in files) + if (GetFileTypeFromPath(file) == CardGameManager.Current.DeckFileType) + DeckFiles[GetNameFromPath((file))] = file; - Rebuild(DeckFiles.Keys.ToList(), SelectFile, SelectedFileName); + Rebuild(DeckFiles.Keys.ToList(), SelectFile, SelectedFileName); - shareFileButton.interactable = !string.IsNullOrEmpty(SelectedFileName); - deleteFileButton.interactable = !string.IsNullOrEmpty(SelectedFileName); - loadFromFileButton.interactable = !string.IsNullOrEmpty(SelectedFileName); - } + shareFileButton.interactable = !string.IsNullOrEmpty(SelectedFileName); + deleteFileButton.interactable = !string.IsNullOrEmpty(SelectedFileName); + loadFromFileButton.interactable = !string.IsNullOrEmpty(SelectedFileName); + } - public void SelectFile(Toggle toggle, string deckFileName) - { - if (string.IsNullOrEmpty(deckFileName)) + public void SelectFile(Toggle toggle, string deckFileName) { - SelectedFileName = string.Empty; - shareFileButton.interactable = false; - deleteFileButton.interactable = false; - loadFromFileButton.interactable = false; - return; + if (string.IsNullOrEmpty(deckFileName)) + { + SelectedFileName = string.Empty; + shareFileButton.interactable = false; + deleteFileButton.interactable = false; + loadFromFileButton.interactable = false; + return; + } + + if (toggle.isOn) + { + SelectedFileName = deckFileName; + shareFileButton.interactable = true; + deleteFileButton.interactable = true; + loadFromFileButton.interactable = true; + } + else if (!toggle.group.AnyTogglesOn() && SelectedFileName.Equals(deckFileName)) + LoadFromFileAndHide(); } - if (toggle.isOn) + public string GetNameFromPath(string filePath) { - SelectedFileName = deckFileName; - shareFileButton.interactable = true; - deleteFileButton.interactable = true; - loadFromFileButton.interactable = true; + int startName = filePath.LastIndexOf(Path.DirectorySeparatorChar) + 1; + int endName = filePath.LastIndexOf('.'); + return filePath.Substring(startName, endName > 0 ? endName - startName : 0); } - else if (!toggle.group.AnyTogglesOn() && SelectedFileName.Equals(deckFileName)) - LoadFromFileAndHide(); - } - - public string GetNameFromPath(string filePath) - { - int startName = filePath.LastIndexOf(Path.DirectorySeparatorChar) + 1; - int endName = filePath.LastIndexOf('.'); - return filePath.Substring(startName, endName > 0 ? endName - startName : 0); - } - - public DeckFileType GetFileTypeFromPath(string filePath) - { - DeckFileType fileType = DeckFileType.Txt; - string extension = filePath.Substring(filePath.LastIndexOf('.') + 1); - if (extension.ToLower().Equals(DeckFileType.Dec.ToString().ToLower())) - fileType = DeckFileType.Dec; - else if (extension.ToLower().Equals(DeckFileType.Hsd.ToString().ToLower())) - fileType = DeckFileType.Hsd; - else if (extension.ToLower().Equals(DeckFileType.Ydk.ToString().ToLower())) - fileType = DeckFileType.Ydk; - return fileType; - } - - public void Share() - { - CardGameManager.Instance.Messenger.Show("Share functionality is coming soon."); - } - public void PromptForDeleteFile() - { - CardGameManager.Instance.Messenger.Prompt(DeletePrompt, DeleteFile); - } - - public void DeleteFile() - { - try + public DeckFileType GetFileTypeFromPath(string filePath) { - File.Delete(DeckFiles[SelectedFileName]); + DeckFileType fileType = DeckFileType.Txt; + string extension = filePath.Substring(filePath.LastIndexOf('.') + 1); + if (extension.ToLower().Equals(DeckFileType.Dec.ToString().ToLower())) + fileType = DeckFileType.Dec; + else if (extension.ToLower().Equals(DeckFileType.Hsd.ToString().ToLower())) + fileType = DeckFileType.Hsd; + else if (extension.ToLower().Equals(DeckFileType.Ydk.ToString().ToLower())) + fileType = DeckFileType.Ydk; + return fileType; } - catch (Exception e) + + public void Share() { - Debug.LogError(DeckDeleteErrorMessage + e.Message); + CardGameManager.Instance.Messenger.Show("Share functionality is coming soon."); } - SelectedFileName = string.Empty; - BuildDeckFileSelectionOptions(); - } - public void LoadFromFileAndHide() - { - string deckText = string.Empty; - try + public void PromptForDeleteFile() { - deckText = File.ReadAllText(DeckFiles[SelectedFileName]); + CardGameManager.Instance.Messenger.Prompt(DeletePrompt, DeleteFile); } - catch (Exception e) + + public void DeleteFile() { - Debug.LogError(DeckLoadErrorMessage + e.Message); + try + { + File.Delete(DeckFiles[SelectedFileName]); + } + catch (Exception e) + { + Debug.LogError(DeckDeleteErrorMessage + e.Message); + } + SelectedFileName = string.Empty; + BuildDeckFileSelectionOptions(); } - Deck newDeck = Deck.Parse(SelectedFileName, CardGameManager.Current.DeckFileType, deckText); - LoadCallback?.Invoke(newDeck); - ResetCancelButton(); - Hide(); - } - - public void ShowNewDeckPanel() - { - newDeckPanel.gameObject.SetActive(true); - } + public void LoadFromFileAndHide() + { + string deckText = string.Empty; + try + { + deckText = File.ReadAllText(DeckFiles[SelectedFileName]); + } + catch (Exception e) + { + Debug.LogError(DeckLoadErrorMessage + e.Message); + } + + Deck newDeck = Deck.Parse(CardGameManager.Current, SelectedFileName, CardGameManager.Current.DeckFileType, deckText); + LoadCallback?.Invoke(newDeck); + ResetCancelButton(); + Hide(); + } - public void ValidateDeckName(string deckName) - { - nameInputField.text = UnityExtensionMethods.GetSafeFileName(deckName); - } + public void ShowNewDeckPanel() + { + newDeckPanel.gameObject.SetActive(true); + } - public void Clear() - { - textInputField.text = string.Empty; - } + public void ValidateDeckName(string deckName) + { + nameInputField.text = UnityExtensionMethods.GetSafeFileName(deckName); + } - public void PasteClipboardIntoText() - { - textInputField.text = UniClipboard.GetText(); - } + public void Clear() + { + textInputField.text = string.Empty; + } - public void DoSaveDontOverwrite() - { - Deck filePathFinder = new Deck(nameInputField.text, CardGameManager.Current.DeckFileType); - if (File.Exists(filePathFinder.FilePath)) - CardGameManager.Instance.StartCoroutine(WaitToPromptOverwrite()); - else - DoSave(); - } + public void PasteClipboardIntoText() + { + textInputField.text = UniClipboard.GetText(); + } - public IEnumerator WaitToPromptOverwrite() - { - yield return null; - CardGameManager.Instance.Messenger.Ask(DeckSaveMenu.OverWriteDeckPrompt, null, DoSave); - } + public void DoSaveDontOverwrite() + { + Deck filePathFinder = new Deck(CardGameManager.Current, nameInputField.text, CardGameManager.Current.DeckFileType); + if (File.Exists(filePathFinder.FilePath)) + CardGameManager.Instance.StartCoroutine(WaitToPromptOverwrite()); + else + DoSave(); + } - public void DoSave() - { - Deck filePathFinder = new Deck(nameInputField.text, CardGameManager.Current.DeckFileType); - try + public IEnumerator WaitToPromptOverwrite() { - if (!Directory.Exists(CardGameManager.Current.DecksFilePath)) - Directory.CreateDirectory(CardGameManager.Current.DecksFilePath); - File.WriteAllText(filePathFinder.FilePath, textInputField.text); + yield return null; + CardGameManager.Instance.Messenger.Ask(DeckSaveMenu.OverWriteDeckPrompt, null, DoSave); } - catch (Exception e) + + public void DoSave() { - Debug.LogError(DeckSaveErrorMessage + e.Message); + Deck filePathFinder = new Deck(CardGameManager.Current, nameInputField.text, CardGameManager.Current.DeckFileType); + try + { + if (!Directory.Exists(CardGameManager.Current.DecksFilePath)) + Directory.CreateDirectory(CardGameManager.Current.DecksFilePath); + File.WriteAllText(filePathFinder.FilePath, textInputField.text); + } + catch (Exception e) + { + Debug.LogError(DeckSaveErrorMessage + e.Message); + } + BuildDeckFileSelectionOptions(); + HideNewDeckPanel(); } - BuildDeckFileSelectionOptions(); - HideNewDeckPanel(); - } - public void HideNewDeckPanel() - { - newDeckPanel.gameObject.SetActive(false); - } + public void HideNewDeckPanel() + { + newDeckPanel.gameObject.SetActive(false); + } - public void ResetCancelButton() - { - cancelButton.onClick.RemoveAllListeners(); - cancelButton.onClick.AddListener(Hide); - } + public void ResetCancelButton() + { + cancelButton.onClick.RemoveAllListeners(); + cancelButton.onClick.AddListener(Hide); + } - public void Hide() - { - gameObject.SetActive(false); + public void Hide() + { + gameObject.SetActive(false); + } } } diff --git a/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs b/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs index 87486c3b0..b33e09eba 100644 --- a/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs +++ b/Assets/Scripts/CGS/Menus/DeckSaveMenu.cs @@ -5,106 +5,109 @@ using UnityEngine.EventSystems; using UnityEngine.UI; -public delegate void OnDeckSavedDelegate(Deck savedDeck); - -public class DeckSaveMenu : MonoBehaviour +namespace CGS.Menus { - public const string DeckCopiedMessage = "The text for this deck has been copied to the clipboard."; - public const string OverWriteDeckPrompt = "A deck with that name already exists. Overwrite?"; - public const string DeckSaveErrorMessage = "There was an error saving the deck to file: "; + public delegate void OnDeckSavedDelegate(Deck savedDeck); - public InputField nameInputField; - public TMPro.TMP_Text textOutputArea; + public class DeckSaveMenu : MonoBehaviour + { + public const string DeckCopiedMessage = "The text for this deck has been copied to the clipboard."; + public const string OverWriteDeckPrompt = "A deck with that name already exists. Overwrite?"; + public const string DeckSaveErrorMessage = "There was an error saving the deck to file: "; - public Deck CurrentDeck { get; private set; } - public OnNameChangeDelegate NameChangeCallback { get; private set; } - public OnDeckSavedDelegate DeckSaveCallback { get; private set; } - public bool DoesAutoOverwrite { get; private set; } + public InputField nameInputField; + public TMPro.TMP_Text textOutputArea; - void LateUpdate() - { - if (nameInputField.isFocused || !Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) - return; + public Deck CurrentDeck { get; private set; } + public OnNameChangeDelegate NameChangeCallback { get; private set; } + public OnDeckSavedDelegate DeckSaveCallback { get; private set; } + public bool DoesAutoOverwrite { get; private set; } - if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && EventSystem.current.currentSelectedGameObject == null) - AttemptSaveAndHide(); - else if (Input.GetButtonDown(Inputs.FocusName)) - nameInputField.ActivateInputField(); - else if (Input.GetButtonDown(Inputs.Load) && EventSystem.current.currentSelectedGameObject == null) - CopyTextToClipboard(); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - Hide(); - } + void LateUpdate() + { + if (nameInputField.isFocused || !Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) + return; - public void Show(Deck deckToShow, OnNameChangeDelegate nameChangeCallback = null, OnDeckSavedDelegate deckSaveCallback = null, bool overwrite = false) - { - gameObject.SetActive(true); - transform.SetAsLastSibling(); - CurrentDeck = deckToShow ?? new Deck(); - NameChangeCallback = nameChangeCallback; - DeckSaveCallback = deckSaveCallback; - DoesAutoOverwrite = overwrite; - nameInputField.text = CurrentDeck.Name; - textOutputArea.text = CurrentDeck.ToString(); - } + if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && EventSystem.current.currentSelectedGameObject == null) + AttemptSaveAndHide(); + else if (Input.GetButtonDown(Inputs.FocusName)) + nameInputField.ActivateInputField(); + else if (Input.GetButtonDown(Inputs.Load) && EventSystem.current.currentSelectedGameObject == null) + CopyTextToClipboard(); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + Hide(); + } - public void ChangeName(string newName) - { - if (NameChangeCallback != null) - newName = NameChangeCallback(newName); - if (!string.IsNullOrEmpty(newName)) - nameInputField.text = newName; - Deck newDeck = new Deck(newName, CardGameManager.Current.DeckFileType); - newDeck.Cards.AddRange(CurrentDeck.Cards); - textOutputArea.text = newDeck.ToString(); - } + public void Show(Deck deckToShow, OnNameChangeDelegate nameChangeCallback = null, OnDeckSavedDelegate deckSaveCallback = null, bool overwrite = false) + { + gameObject.SetActive(true); + transform.SetAsLastSibling(); + CurrentDeck = deckToShow ?? new Deck(CardGameManager.Current); + NameChangeCallback = nameChangeCallback; + DeckSaveCallback = deckSaveCallback; + DoesAutoOverwrite = overwrite; + nameInputField.text = CurrentDeck.Name; + textOutputArea.text = CurrentDeck.ToString(); + } - public void CopyTextToClipboard() - { - UniClipboard.SetText(textOutputArea.text); - CardGameManager.Instance.Messenger.Show(DeckCopiedMessage); - } + public void ChangeName(string newName) + { + if (NameChangeCallback != null) + newName = NameChangeCallback(newName); + if (!string.IsNullOrEmpty(newName)) + nameInputField.text = newName; + Deck newDeck = new Deck(CardGameManager.Current, newName, CardGameManager.Current.DeckFileType); + newDeck.Cards.AddRange(CurrentDeck.Cards); + textOutputArea.text = newDeck.ToString(); + } - public void AttemptSaveAndHide() - { - Deck filePathFinder = new Deck(nameInputField.text, CardGameManager.Current.DeckFileType); - if (!DoesAutoOverwrite && File.Exists(filePathFinder.FilePath)) - CardGameManager.Instance.Messenger.Prompt(OverWriteDeckPrompt, SaveToFile); - else - SaveToFile(); + public void CopyTextToClipboard() + { + UniClipboard.SetText(textOutputArea.text); + CardGameManager.Instance.Messenger.Show(DeckCopiedMessage); + } - Hide(); - } + public void AttemptSaveAndHide() + { + Deck filePathFinder = new Deck(CardGameManager.Current, nameInputField.text, CardGameManager.Current.DeckFileType); + if (!DoesAutoOverwrite && File.Exists(filePathFinder.FilePath)) + CardGameManager.Instance.Messenger.Prompt(OverWriteDeckPrompt, SaveToFile); + else + SaveToFile(); - public void SaveToFile() - { - CurrentDeck.Name = nameInputField.text; - SaveToFile(CurrentDeck, DeckSaveCallback); - } + Hide(); + } - public static void SaveToFile(Deck deck, OnDeckSavedDelegate deckSaveCallback = null) - { - try + public void SaveToFile() { - if (!Directory.Exists(CardGameManager.Current.DecksFilePath)) - Directory.CreateDirectory(CardGameManager.Current.DecksFilePath); - File.WriteAllText(deck.FilePath, deck.ToString()); + CurrentDeck.Name = nameInputField.text; + SaveToFile(CurrentDeck, DeckSaveCallback); } - catch (Exception e) + + public static void SaveToFile(Deck deck, OnDeckSavedDelegate deckSaveCallback = null) { - Debug.LogError(DeckSaveErrorMessage + e.Message); + try + { + if (!Directory.Exists(CardGameManager.Current.DecksFilePath)) + Directory.CreateDirectory(CardGameManager.Current.DecksFilePath); + File.WriteAllText(deck.FilePath, deck.ToString()); + } + catch (Exception e) + { + Debug.LogError(DeckSaveErrorMessage + e.Message); + } + deckSaveCallback?.Invoke(deck); } - deckSaveCallback?.Invoke(deck); - } - public void CancelAndHide() - { - NameChangeCallback?.Invoke(CurrentDeck.Name); - Hide(); - } + public void CancelAndHide() + { + NameChangeCallback?.Invoke(CurrentDeck.Name); + Hide(); + } - public void Hide() - { - gameObject.SetActive(false); + public void Hide() + { + gameObject.SetActive(false); + } } } diff --git a/Assets/Scripts/CGS/Menus/DiceMenu.cs b/Assets/Scripts/CGS/Menus/DiceMenu.cs index 4c0ceae35..9d90f8e44 100644 --- a/Assets/Scripts/CGS/Menus/DiceMenu.cs +++ b/Assets/Scripts/CGS/Menus/DiceMenu.cs @@ -1,94 +1,98 @@ -using UnityEngine; +using CGS.Play; +using UnityEngine; using UnityEngine.UI; -public class DiceMenu : MonoBehaviour +namespace CGS.Menus { - public const int DefaultMin = 1; - public const int DefaultMax = 6; + public class DiceMenu : MonoBehaviour + { + public const int DefaultMin = 1; + public const int DefaultMax = 6; - public GameObject diePrefab; - public Text minText; - public Text maxText; + public GameObject diePrefab; + public Text minText; + public Text maxText; - public int Min - { - get { return _min; } - set + public int Min { - _min = value; - minText.text = _min.ToString(); + get { return _min; } + set + { + _min = value; + minText.text = _min.ToString(); + } } - } - private int _min; + private int _min; - public int Max - { - get { return _max; } - set + public int Max { - _max = value; - maxText.text = _max.ToString(); + get { return _max; } + set + { + _max = value; + maxText.text = _max.ToString(); + } } - } - private int _max; + private int _max; - protected RectTransform Target { get; set; } + protected RectTransform Target { get; set; } - void Start() - { - Min = DefaultMin; - Max = DefaultMax; - } + void Start() + { + Min = DefaultMin; + Max = DefaultMax; + } - void LateUpdate() - { - if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) - return; + void LateUpdate() + { + if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) + return; - if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) - CreateAndHide(); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - Hide(); - } + if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) + CreateAndHide(); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + Hide(); + } - public void Show(RectTransform playArea) - { - gameObject.SetActive(true); - transform.SetAsLastSibling(); - Target = playArea; - } + public void Show(RectTransform playArea) + { + gameObject.SetActive(true); + transform.SetAsLastSibling(); + Target = playArea; + } - public void DecrementMin() - { - Min--; - } + public void DecrementMin() + { + Min--; + } - public void IncrementMin() - { - Min++; - } + public void IncrementMin() + { + Min++; + } - public void DecrementMax() - { - Max--; - } + public void DecrementMax() + { + Max--; + } - public void IncrementMax() - { - Max++; - } + public void IncrementMax() + { + Max++; + } - public void CreateAndHide() - { - Die die = Instantiate(diePrefab, Target.parent).GetOrAddComponent(); - die.transform.SetParent(Target); - die.Min = Min; - die.Max = Max; - Hide(); - } + public void CreateAndHide() + { + Die die = Instantiate(diePrefab, Target.parent).GetOrAddComponent(); + die.transform.SetParent(Target); + die.Min = Min; + die.Max = Max; + Hide(); + } - public void Hide() - { - gameObject.SetActive(false); + public void Hide() + { + gameObject.SetActive(false); + } } } diff --git a/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs b/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs index bef85beb1..67837196f 100644 --- a/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs +++ b/Assets/Scripts/CGS/Menus/GameSelectionMenu.cs @@ -6,160 +6,163 @@ using UnityEngine.EventSystems; using UnityEngine.UI; -public class GameSelectionMenu : SelectionPanel +namespace CGS.Menus { - public const string DeleteMessage = "Please download additional card games before deleting."; - public const string DeletePrompt = "Deleting a card game also deletes all decks saved for that card game. Are you sure you would like to delete this card game?"; - public const string DominoesUrl = "https://cardgamesim.finoldigital.com/games/Dominoes/Dominoes.json"; - public const string StandardUrl = "https://cardgamesim.finoldigital.com/games/Standard/Standard.json"; - public const string MahjongUrl = "https://cardgamesim.finoldigital.com/games/Mahjong/Mahjong.json"; + public class GameSelectionMenu : SelectionPanel + { + public const string DeleteMessage = "Please download additional card games before deleting."; + public const string DeletePrompt = "Deleting a card game also deletes all decks saved for that card game. Are you sure you would like to delete this card game?"; + public const string DominoesUrl = "https://cardgamesim.finoldigital.com/games/Dominoes/Dominoes.json"; + public const string StandardUrl = "https://cardgamesim.finoldigital.com/games/Standard/Standard.json"; + public const string MahjongUrl = "https://cardgamesim.finoldigital.com/games/Mahjong/Mahjong.json"; - public RectTransform downloadPanel; - public InputField urlInput; - public Button downloadButton; + public RectTransform downloadPanel; + public InputField urlInput; + public Button downloadButton; - void Update() - { - if (urlInput.isFocused || !Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) - return; - - if (downloadPanel.gameObject.activeSelf) - { - if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && downloadButton.interactable) - StartDownload(); - else if ((Input.GetButtonDown(Inputs.New) || Input.GetButtonDown(Inputs.Load)) && urlInput.interactable) - Clear(); - else if (Input.GetButtonDown(Inputs.Save) && urlInput.interactable) - Paste(); - else if (Input.GetButtonDown(Inputs.FocusName) && urlInput.interactable) - urlInput.ActivateInputField(); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - HideDownloadPanel(); - } - else - { - if (Input.GetKeyDown(Inputs.BluetoothReturn) && Toggles.Contains(EventSystem.current.currentSelectedGameObject)) - EventSystem.current.currentSelectedGameObject.GetComponent().isOn = true; - else if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) - Hide(); - else if (Input.GetButtonDown(Inputs.Sort)) - Share(); - else if (Input.GetButtonDown(Inputs.New) || Input.GetButtonDown(Inputs.Load)) - ShowDownloadPanel(); - else if (Input.GetButtonDown(Inputs.Delete)) - Delete(); - else if (Input.GetButtonDown(Inputs.Horizontal)) + void Update() + { + if (urlInput.isFocused || !Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) + return; + + if (downloadPanel.gameObject.activeSelf) { - if (Input.GetAxis(Inputs.Horizontal) < 0) - CardGameManager.Instance.SelectLeft(); - else - CardGameManager.Instance.SelectRight(); - Rebuild(CardGameManager.Instance.AllCardGames.Keys.ToList(), SelectGame, CardGameManager.Current.Name); + if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && downloadButton.interactable) + StartDownload(); + else if ((Input.GetButtonDown(Inputs.New) || Input.GetButtonDown(Inputs.Load)) && urlInput.interactable) + Clear(); + else if (Input.GetButtonDown(Inputs.Save) && urlInput.interactable) + Paste(); + else if (Input.GetButtonDown(Inputs.FocusName) && urlInput.interactable) + urlInput.ActivateInputField(); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + HideDownloadPanel(); + } + else + { + if (Input.GetKeyDown(Inputs.BluetoothReturn) && Toggles.Contains(EventSystem.current.currentSelectedGameObject)) + EventSystem.current.currentSelectedGameObject.GetComponent().isOn = true; + else if (Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) + Hide(); + else if (Input.GetButtonDown(Inputs.Sort)) + Share(); + else if (Input.GetButtonDown(Inputs.New) || Input.GetButtonDown(Inputs.Load)) + ShowDownloadPanel(); + else if (Input.GetButtonDown(Inputs.Delete)) + Delete(); + else if (Input.GetButtonDown(Inputs.Horizontal)) + { + if (Input.GetAxis(Inputs.Horizontal) < 0) + CardGameManager.Instance.SelectLeft(); + else + CardGameManager.Instance.SelectRight(); + Rebuild(CardGameManager.Instance.AllCardGames.Keys.ToList(), SelectGame, CardGameManager.Current.Name); + } + else if (Input.GetButtonDown(Inputs.Vertical)) + ScrollToggles(Input.GetAxis(Inputs.Vertical) > 0); + else if (Input.GetButtonDown(Inputs.Page)) + ScrollPage(Input.GetAxis(Inputs.Page) < 0); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + Hide(); } - else if (Input.GetButtonDown(Inputs.Vertical)) - ScrollToggles(Input.GetAxis(Inputs.Vertical) > 0); - else if (Input.GetButtonDown(Inputs.Page)) - ScrollPage(Input.GetAxis(Inputs.Page) < 0); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - Hide(); } - } - public void Show() - { - gameObject.SetActive(true); - transform.SetAsLastSibling(); - Rebuild(CardGameManager.Instance.AllCardGames.Keys.ToList(), SelectGame, CardGameManager.Current.Name); - } + public void Show() + { + gameObject.SetActive(true); + transform.SetAsLastSibling(); + Rebuild(CardGameManager.Instance.AllCardGames.Keys.ToList(), SelectGame, CardGameManager.Current.Name); + } - public void SelectGame(Toggle toggle, string gameName) - { - if (toggle.isOn) - CardGameManager.Instance.SelectCardGame(gameName); - else if (!toggle.group.AnyTogglesOn()) - Hide(); - } + public void SelectGame(Toggle toggle, string gameName) + { + if (toggle.isOn) + CardGameManager.Instance.SelectCardGame(gameName); + else if (!toggle.group.AnyTogglesOn()) + Hide(); + } - public void Share() - { - CardGameManager.Instance.Messenger.Show("Share functionality is coming soon."); - } + public void Share() + { + CardGameManager.Instance.Messenger.Show("Share functionality is coming soon."); + } - public void Delete() - { - if (CardGameManager.Instance.AllCardGames.Count > 1) - CardGameManager.Instance.Messenger.Prompt(DeletePrompt, CardGameManager.Instance.DeleteGame); - else - CardGameManager.Instance.Messenger.Show(DeleteMessage); - } + public void Delete() + { + if (CardGameManager.Instance.AllCardGames.Count > 1) + CardGameManager.Instance.Messenger.Prompt(DeletePrompt, CardGameManager.Instance.DeleteGame); + else + CardGameManager.Instance.Messenger.Show(DeleteMessage); + } - public void ShowDownloadPanel() - { - downloadPanel.gameObject.SetActive(true); - } + public void ShowDownloadPanel() + { + downloadPanel.gameObject.SetActive(true); + } - public void ApplyDominoes() - { - if (urlInput.interactable) - urlInput.text = DominoesUrl; - } + public void ApplyDominoes() + { + if (urlInput.interactable) + urlInput.text = DominoesUrl; + } - public void ApplyStandard() - { - if (urlInput.interactable) - urlInput.text = StandardUrl; - } + public void ApplyStandard() + { + if (urlInput.interactable) + urlInput.text = StandardUrl; + } - public void ApplyMahjong() - { - if (urlInput.interactable) - urlInput.text = MahjongUrl; - } + public void ApplyMahjong() + { + if (urlInput.interactable) + urlInput.text = MahjongUrl; + } - public void Paste() - { - if (urlInput.interactable) - urlInput.text = UniClipboard.GetText(); - } + public void Paste() + { + if (urlInput.interactable) + urlInput.text = UniClipboard.GetText(); + } - public void Clear() - { - urlInput.text = string.Empty; - } + public void Clear() + { + urlInput.text = string.Empty; + } - public void CheckDownloadUrl(string url) - { - downloadButton.interactable = System.Uri.IsWellFormedUriString(url.Trim(), System.UriKind.Absolute); - } + public void CheckDownloadUrl(string url) + { + downloadButton.interactable = System.Uri.IsWellFormedUriString(url.Trim(), System.UriKind.Absolute); + } - public void StartDownload() - { - CardGameManager.Instance.StartCoroutine(DownloadGame()); - } + public void StartDownload() + { + CardGameManager.Instance.StartCoroutine(DownloadGame()); + } - public IEnumerator DownloadGame() - { - string gameUrl = urlInput.text.Trim(); + public IEnumerator DownloadGame() + { + string gameUrl = urlInput.text.Trim(); - urlInput.text = string.Empty; - urlInput.interactable = false; - cancelButton.interactable = false; + urlInput.text = string.Empty; + urlInput.interactable = false; + cancelButton.interactable = false; - yield return CardGameManager.Instance.DownloadCardGame(gameUrl); + yield return CardGameManager.Instance.DownloadCardGame(gameUrl); - cancelButton.interactable = true; - urlInput.interactable = true; - HideDownloadPanel(); - } + cancelButton.interactable = true; + urlInput.interactable = true; + HideDownloadPanel(); + } - public void HideDownloadPanel() - { - Show(); - downloadPanel.gameObject.SetActive(false); - } + public void HideDownloadPanel() + { + Show(); + downloadPanel.gameObject.SetActive(false); + } - public void Hide() - { - gameObject.SetActive(false); + public void Hide() + { + gameObject.SetActive(false); + } } } diff --git a/Assets/Scripts/CGS/Menus/LobbyMenu.cs b/Assets/Scripts/CGS/Menus/LobbyMenu.cs index 5893d0b69..90566131a 100644 --- a/Assets/Scripts/CGS/Menus/LobbyMenu.cs +++ b/Assets/Scripts/CGS/Menus/LobbyMenu.cs @@ -1,109 +1,113 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using CGS.Play.Multiplayer; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.Networking; using UnityEngine.UI; -public class LobbyMenu : SelectionPanel +namespace CGS.Menus { - public Button joinButton; - - public List HostNames { get; private set; } = new List(); - public string SelectedHost { get; private set; } = ""; - - void Update() + public class LobbyMenu : SelectionPanel { - if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) - return; - - if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && joinButton.interactable) - Join(); - else if (Input.GetKeyDown(Inputs.BluetoothReturn) && Toggles.Contains(EventSystem.current.currentSelectedGameObject)) - EventSystem.current.currentSelectedGameObject.GetComponent().isOn = true; - else if (Input.GetButtonDown(Inputs.New)) - Host(); - else if (Input.GetButtonDown(Inputs.Vertical)) - ScrollToggles(Input.GetAxis(Inputs.Vertical) > 0); - else if (Input.GetButtonDown(Inputs.Page)) - ScrollPage(Input.GetAxis(Inputs.Page) < 0); - else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) - Hide(); - } + public Button joinButton; - public void Show(UnityAction cancelAction) - { - gameObject.SetActive(true); - transform.SetAsLastSibling(); + public List HostNames { get; private set; } = new List(); + public string SelectedHost { get; private set; } = ""; - cancelButton.onClick.RemoveAllListeners(); - cancelButton.onClick.AddListener(cancelAction); - - HostNames.Clear(); - SelectedHost = string.Empty; - Rebuild(HostNames, SelectHost, SelectedHost); + void Update() + { + if (!Input.anyKeyDown || gameObject != CardGameManager.TopMenuCanvas?.gameObject) + return; + + if ((Input.GetKeyDown(Inputs.BluetoothReturn) || Input.GetButtonDown(Inputs.Submit)) && joinButton.interactable) + Join(); + else if (Input.GetKeyDown(Inputs.BluetoothReturn) && Toggles.Contains(EventSystem.current.currentSelectedGameObject)) + EventSystem.current.currentSelectedGameObject.GetComponent().isOn = true; + else if (Input.GetButtonDown(Inputs.New)) + Host(); + else if (Input.GetButtonDown(Inputs.Vertical)) + ScrollToggles(Input.GetAxis(Inputs.Vertical) > 0); + else if (Input.GetButtonDown(Inputs.Page)) + ScrollPage(Input.GetAxis(Inputs.Page) < 0); + else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(Inputs.Cancel)) + Hide(); + } - CardGameManager.Instance.Discovery.lobby = this; - CardGameManager.Instance.Discovery.SearchForHost(); - } + public void Show(UnityAction cancelAction) + { + gameObject.SetActive(true); + transform.SetAsLastSibling(); - public void DisplayHosts(List hostNames) - { - if (hostNames == null || hostNames.Equals(HostNames)) - return; + cancelButton.onClick.RemoveAllListeners(); + cancelButton.onClick.AddListener(cancelAction); - HostNames.Clear(); - foreach (string hostname in hostNames) - HostNames.Add(hostname.Split(':').Last()); - if (!HostNames.Contains(SelectedHost)) - { + HostNames.Clear(); SelectedHost = string.Empty; - joinButton.interactable = false; - } + Rebuild(HostNames, SelectHost, SelectedHost); - Rebuild(HostNames, SelectHost, SelectedHost); - } + CardGameManager.Instance.Discovery.lobby = this; + CardGameManager.Instance.Discovery.SearchForHost(); + } - public void Host(UnityAction cancelAction = null) - { - NetworkManager.singleton.StartHost(); - NetworkManager.singleton.StartCoroutine(WaitToShowDeckLoader(cancelAction)); - Hide(); - } + public void DisplayHosts(List hostNames) + { + if (hostNames == null || hostNames.Equals(HostNames)) + return; + + HostNames.Clear(); + foreach (string hostname in hostNames) + HostNames.Add(hostname.Split(':').Last()); + if (!HostNames.Contains(SelectedHost)) + { + SelectedHost = string.Empty; + joinButton.interactable = false; + } + + Rebuild(HostNames, SelectHost, SelectedHost); + } - public IEnumerator WaitToShowDeckLoader(UnityAction cancelAction) - { - yield return null; - CGSNetManager.Instance.playController.ShowDeckMenu(); - CGSNetManager.Instance.playController.DeckLoader.cancelButton.onClick.RemoveAllListeners(); - CGSNetManager.Instance.playController.DeckLoader.cancelButton.onClick.AddListener(cancelAction); - } + public void Host(UnityAction cancelAction = null) + { + NetworkManager.singleton.StartHost(); + NetworkManager.singleton.StartCoroutine(WaitToShowDeckLoader(cancelAction)); + Hide(); + } - public void SelectHost(Toggle toggle, string hostName) - { - if (string.IsNullOrEmpty(hostName)) - return; + public IEnumerator WaitToShowDeckLoader(UnityAction cancelAction) + { + yield return null; + CGSNetManager.Instance.playController.ShowDeckMenu(); + CGSNetManager.Instance.playController.DeckLoader.cancelButton.onClick.RemoveAllListeners(); + CGSNetManager.Instance.playController.DeckLoader.cancelButton.onClick.AddListener(cancelAction); + } - if (toggle.isOn) + public void SelectHost(Toggle toggle, string hostName) { - SelectedHost = hostName; - joinButton.interactable = true; + if (string.IsNullOrEmpty(hostName)) + return; + + if (toggle.isOn) + { + SelectedHost = hostName; + joinButton.interactable = true; + } + else if (!toggle.group.AnyTogglesOn() && SelectedHost.Equals(hostName)) + Join(); } - else if (!toggle.group.AnyTogglesOn() && SelectedHost.Equals(hostName)) - Join(); - } - public void Join() - { - NetworkManager.singleton.networkAddress = SelectedHost; - NetworkManager.singleton.StartClient(); - Hide(); - } + public void Join() + { + NetworkManager.singleton.networkAddress = SelectedHost; + NetworkManager.singleton.StartClient(); + Hide(); + } - public void Hide() - { - gameObject.SetActive(false); + public void Hide() + { + gameObject.SetActive(false); + } } } diff --git a/Assets/Scripts/CGS/Menus/MainMenu.cs b/Assets/Scripts/CGS/Menus/MainMenu.cs index c3db2dc15..ca9e6498b 100644 --- a/Assets/Scripts/CGS/Menus/MainMenu.cs +++ b/Assets/Scripts/CGS/Menus/MainMenu.cs @@ -6,115 +6,118 @@ using UnityEngine.SceneManagement; using UnityEngine.UI; -public class MainMenu : MonoBehaviour +namespace CGS.Menus { - public const int MainMenuSceneIndex = 1; - public const int PlayModeSceneIndex = 2; - public const int DeckEditorSceneIndex = 3; - public const int OptionsMenuSceneIndex = 4; - public const string VersionMessage = "Ver. "; + public class MainMenu : MonoBehaviour + { + public const int MainMenuSceneIndex = 1; + public const int PlayModeSceneIndex = 2; + public const int DeckEditorSceneIndex = 3; + public const int OptionsMenuSceneIndex = 4; + public const string VersionMessage = "Ver. "; - public List buttons; - public GameObject quitButton; - public Text versionText; + public List buttons; + public GameObject quitButton; + public Text versionText; - void Start() - { + void Start() + { #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR quitButton.SetActive(false); #endif - versionText.text = VersionMessage + Application.version; - - if (CardGameManager.Instance.Discovery.running) - CardGameManager.Instance.Discovery.StopBroadcast(); - CardGameManager.Instance.Discovery.HasReceivedBroadcast = false; - CardGameManager.Instance.Discovery.SearchForHost(); - } + versionText.text = VersionMessage + Application.version; - void Update() - { - if (!Input.anyKeyDown || CardGameManager.TopMenuCanvas != null) - return; + if (CardGameManager.Instance.Discovery.running) + CardGameManager.Instance.Discovery.StopBroadcast(); + CardGameManager.Instance.Discovery.HasReceivedBroadcast = false; + CardGameManager.Instance.Discovery.SearchForHost(); + } - if (Input.GetKeyDown(Inputs.BluetoothReturn)) - EventSystem.current.currentSelectedGameObject?.GetComponent