-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SidebarPages.cs
203 lines (170 loc) 路 5.99 KB
/
SidebarPages.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
锘縰sing System.Collections;
using System.Collections.Generic;
using System.IO;
using AdrianMiasik.Components.Base;
using AdrianMiasik.Components.Core.Items.Pages;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
namespace AdrianMiasik.Components.Core.Containers
{
/// <summary>
/// A <see cref="ItemSelector{T}"/> that hold's references to all our application <see cref="Page"/>'s.
/// Intended to control which page is currently selected/opened/seen.
/// </summary>
public class SidebarPages : ItemSelector<Page>
{
[SerializeField] private TimerPage m_timerPage;
[SerializeField] private SettingsPage m_settingsPage;
[SerializeField] private AboutPage m_aboutPage;
private readonly UnityEvent onTimerPageShow = new();
public override void Initialize(PomodoroTimer pomodoroTimer, bool updateColors = true)
{
base.Initialize(pomodoroTimer, updateColors);
m_timerPage.Initialize(pomodoroTimer);
m_settingsPage.Initialize(pomodoroTimer);
m_aboutPage.Initialize(pomodoroTimer);
List<Page> pages = new List<Page>
{
m_timerPage,
m_settingsPage,
m_aboutPage
};
Initialize(pages);
onSelectionChange += OnSelectionChange;
}
private new void OnSelectionChange(Page previousPage, Page newPage)
{
previousPage.Hide(() =>
{
newPage.Show(() =>
{
Timer.ColorUpdateEndTimestampGhost();
});
if (newPage == m_timerPage)
{
onTimerPageShow?.Invoke();
onTimerPageShow.RemoveAllListeners();
}
});
}
public void SwitchToTimerPage(UnityAction onShow = null)
{
if (onShow != null)
{
onTimerPageShow.AddListener(onShow);
}
Select(m_timerPage);
}
public IEnumerator AddCustomSoundFiles(List<string> customAudioFiles)
{
foreach (string audioFile in customAudioFiles)
{
yield return StartCoroutine(AddCustomAudioFile(audioFile));
}
}
IEnumerator AddCustomAudioFile(string audioFile)
{
// Fetch audio file type based on audio file extension
string audioFileExtension = Path.GetExtension(audioFile);
AudioType type;
switch (audioFileExtension)
{
case ".wav":
type = AudioType.WAV;
break;
case ".mp3":
type = AudioType.MPEG;
break;
default:
Debug.LogWarning("Unsupported audio file extension.");
type = AudioType.UNKNOWN;
break;
}
// Define request
using UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://" + audioFile, type);
// Submit and await request
yield return www.SendWebRequest();
// On request return...
// If the request failed...
if (www.result != UnityWebRequest.Result.Success)
{
// Log the error in question
Debug.Log(www.error);
}
// Otherwise...
else
{
// Create and load AudioClip
AudioClip audioClip = DownloadHandlerAudioClip.GetContent(www);
audioClip.name = Path.GetFileName(audioFile);
// Cache custom alarm to sound bank + add dropdown option
m_settingsPage.AddCustomDropdownSoundOption(audioClip, Path.GetFileName(audioClip.name));
}
}
public void RemoveCustomAudioFile(string audioFile)
{
m_settingsPage.RemoveCustomDropdownSoundOption(audioFile);
}
public void ValidateCustomSoundChoice()
{
m_settingsPage.ValidateCustomSoundChoice();
}
public void SwitchToSettingsPage()
{
Select(m_settingsPage);
}
public void SwitchToAboutPage()
{
Select(m_aboutPage);
}
public void RefreshTimerPage()
{
m_timerPage.Refresh();
}
public void RefreshSettingsPage()
{
m_settingsPage.Refresh();
}
public bool IsAboutPageOpen()
{
return m_aboutPage.IsPageOpen();
}
public bool IsTimerPageOpen()
{
return m_timerPage.gameObject.activeSelf;
}
public bool IsSettingsPageOpen()
{
return m_settingsPage.IsPageOpen();
}
public void UpdateSettingsDigitFormatDropdown()
{
m_settingsPage.UpdateDigitFormatDropdown();
}
public void SetSettingDigitFormatDropdown(int digitFormatIndex)
{
m_settingsPage.SetDigitFormatDropdown(digitFormatIndex);
}
public void MCSwitchToMainPageInstant()
{
m_aboutPage.gameObject.SetActive(false);
m_settingsPage.gameObject.SetActive(false);
m_timerPage.gameObject.SetActive(true);
}
public void MCSwitchToAboutPageInstant()
{
m_timerPage.gameObject.SetActive(false);
m_settingsPage.gameObject.SetActive(false);
m_aboutPage.gameObject.SetActive(true);
m_aboutPage.ColorUpdate(Timer.GetTheme());
}
public void MCSwitchToSettingsPageInstant()
{
m_timerPage.gameObject.SetActive(false);
m_aboutPage.gameObject.SetActive(false);
m_settingsPage.gameObject.SetActive(true);
m_settingsPage.ColorUpdate(Timer.GetTheme());
}
}
}