Skip to content

Commit eb1c7bc

Browse files
committed
Games Management
1 parent 8b40158 commit eb1c7bc

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

Assets/Prefabs/Menus/Games Management Menu.prefab

Lines changed: 43 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Cgs/Menu/GamesManagementMenu.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class GamesManagementMenu : SelectionPanel
3333
public Button newButton;
3434
public Button syncButton;
3535

36+
protected override bool AllowSwitchOff => false;
37+
3638
private Modal Menu => _menu ??= gameObject.GetOrAddComponent<Modal>();
3739

3840
private Modal _menu;
@@ -155,6 +157,7 @@ private static void ShowFileLoader()
155157
[UsedImplicitly]
156158
public void Sync()
157159
{
160+
BuildGameSelectionOptions();
158161
CardGameManager.Instance.StartCoroutine(CardGameManager.Instance.UpdateCardGame(CardGameManager.Current));
159162
}
160163

Assets/Scripts/Cgs/UI/SelectionPanel.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ namespace Cgs.UI
1414

1515
public class SelectionPanel : MonoBehaviour
1616
{
17+
public ToggleGroup toggleGroup;
1718
public RectTransform selectionContent;
1819
public RectTransform selectionTemplate;
1920
public Text emptyText;
2021
public ScrollRect scrollRect;
2122

23+
protected virtual bool AllowSwitchOff => true;
24+
2225
protected List<Toggle> Toggles { get; } = new();
2326

2427
protected void Rebuild<TKey, TValue>(IDictionary<TKey, TValue> options, OnSelectDelegate<TKey> select,
2528
TKey current)
2629
{
30+
if (toggleGroup != null)
31+
toggleGroup.allowSwitchOff = true;
32+
2733
Toggles.Clear();
2834
selectionContent.DestroyAllChildren();
2935
selectionContent.sizeDelta =
@@ -41,11 +47,17 @@ protected void Rebuild<TKey, TValue>(IDictionary<TKey, TValue> options, OnSelect
4147
toggle.isOn = option.Key.Equals(current);
4248
toggle.onValueChanged.AddListener(_ => select(toggle, option.Key));
4349
Toggles.Add(toggle);
44-
if (toggle.isOn)
50+
if (option.Key.Equals(current))
4551
currentSelectionIndex = i;
4652
i++;
4753
}
4854

55+
if (toggleGroup != null)
56+
toggleGroup.allowSwitchOff = AllowSwitchOff;
57+
58+
if (!AllowSwitchOff)
59+
Toggles[currentSelectionIndex].isOn = true;
60+
4961
if (emptyText == null)
5062
{
5163
selectionTemplate.gameObject.SetActive(options.Count < 1);

0 commit comments

Comments
 (0)