-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecipeViewerPanel.cs
167 lines (145 loc) · 5.96 KB
/
RecipeViewerPanel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace Cocktailor
{
/// <summary>
/// manages the selection and display the cocktail recipes based on different modes.
/// </summary>
public class RecipeViewerPanel : MonoBehaviour
{
[Header("Managers and Controllers")]
[SerializeField] private RecipeListManager recipeListManager;
[SerializeField] private SfxManager sfxManager;
[SerializeField] private SettingsManager settingsPanel;
[Header("QuizCard Components")]
[SerializeField] private Dropdown rangeSelectorDropdown;
[SerializeField] private ScrollRect selectionScrollRect;
private RecipeCardController currentRecipeCard;
public bool isInQuizMode, isMenuVisible, isInHideTabMode;
private List<int> recipeSelectionList = new(40);
private int currentSelectionIndex, totalRecipeCount;
private void Start()
{
totalRecipeCount = CocktailRecipeManger.GetTotalRecipeCount();
for (var i = 0; i < totalRecipeCount; i++) recipeSelectionList.Add(i);
currentSelectionIndex = 0;
InitiateSelection();
OpenCard(currentSelectionIndex, CardAnimationType.InFromLeft);
settingsPanel.Start();
}
public void InitiateSelection()
{
var mode = (SelectionDropdownValue)rangeSelectorDropdown.value;
switch (mode)
{
case SelectionDropdownValue.NotMemorized when PlayerData.NotMemorizedRecipes.Count == 0:
PopupMessageManager.Instance.ShowMsg("[못 외운 레시피]가 없습니다!");
mode = SelectionDropdownValue.All;
break;
case SelectionDropdownValue.Memorized when PlayerData.MemorizedRecipes.Count == 0:
PopupMessageManager.Instance.ShowMsg("[다 외운 레시피]가 없습니다!");
mode = SelectionDropdownValue.All;
break;
}
switch (mode)
{
case SelectionDropdownValue.NotMemorized:
recipeSelectionList = GetRecipesSelectionFromState(MemorizedState.No);
break;
case SelectionDropdownValue.Memorized:
recipeSelectionList = GetRecipesSelectionFromState(MemorizedState.Yes);
break;
default:
recipeSelectionList = new List<int>(Enumerable.Range(0, totalRecipeCount));
break;
}
var maxIdx = recipeSelectionList.Count;
recipeListManager.SetupSelections(recipeSelectionList, OpenCardFromSelection);
selectionScrollRect.verticalNormalizedPosition = 1f - currentSelectionIndex / (float)maxIdx;
}
private List<int> GetRecipesSelectionFromState(MemorizedState state)
{
var selection = new List<int>();
for (var i = 0; i < totalRecipeCount; i++)
if (PlayerData.GetUserState(i) == state)
selection.Add(i);
return selection;
}
private void OpenCardFromSelection(int selectionIndex)
{
currentSelectionIndex = selectionIndex;
if (currentSelectionIndex <= GetStageIdxIndex(selectionIndex))
{
currentRecipeCard.panelAnimControl.PlayAnim(CardAnimationType.OutFromRight);
OpenCard(selectionIndex, CardAnimationType.InFromLeft);
}
else if (currentSelectionIndex > GetStageIdxIndex(selectionIndex))
{
currentRecipeCard.panelAnimControl.PlayAnim(CardAnimationType.OutFromLeft);
OpenCard(selectionIndex, CardAnimationType.InFromRight);
}
}
private int GetStageIdxIndex(int num)
{
for (var i = 0; i < recipeSelectionList.Count; i++)
if (num == recipeSelectionList[i])
return i;
return -1;
}
private void HandleSwipeRight()
{
if (currentSelectionIndex < recipeSelectionList.Count - 1)
currentSelectionIndex++;
else
currentSelectionIndex = 0;
OpenCard(recipeSelectionList[currentSelectionIndex], CardAnimationType.InFromLeft);
}
private void HandleSwipeLeft()
{
if (currentSelectionIndex > 0)
currentSelectionIndex--;
else
currentSelectionIndex = recipeSelectionList.Count - 1;
OpenCard(recipeSelectionList[currentSelectionIndex], CardAnimationType.InFromRight);
}
private void OpenCard(int selectionIndex, CardAnimationType anim)
{
// gameObject.GetComponent<TutorialControl>().UpdateStatus(1);
var cardInfo = new RecipeCardData(
recipeSelectionList[currentSelectionIndex],
selectionIndex,
recipeSelectionList.Count,
anim,
!isInHideTabMode,
OnCardSwipeEvent);
currentRecipeCard = RecipeCardManager.Instance.OpenCard(cardInfo);
InitiateSelection();
}
private void OnCardSwipeEvent(SwipeEventType swipeEventType)
{
switch (swipeEventType)
{
case SwipeEventType.SwipeLeft:
HandleSwipeLeft();
break;
case SwipeEventType.SwipeRight:
HandleSwipeRight();
break;
}
}
public void ToggleTabVisibility(bool show)
{
isInHideTabMode = !show;
if (currentRecipeCard != null)
currentRecipeCard.ShowAllTabs(show);
}
private enum SelectionDropdownValue
{
All = 0,
NotMemorized = 1,
Memorized = 2
}
}
}