-
Notifications
You must be signed in to change notification settings - Fork 95
/
SCAN_ColorControl.cs
266 lines (200 loc) · 6.51 KB
/
SCAN_ColorControl.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCAN_ColorControl - Script for controlling the color management settings tab
*
* Copyright (c)2014 David Grandy <david.grandy@gmail.com>;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using SCANsat.Unity.Interfaces;
namespace SCANsat.Unity.Unity
{
public class SCAN_ColorControl : SettingsPage
{
[SerializeField]
private GameObject m_MapPrefab = null;
[SerializeField]
private GameObject m_AltimetryPrefab = null;
[SerializeField]
private GameObject m_SlopePrefab = null;
[SerializeField]
private GameObject m_BiomePrefab = null;
[SerializeField]
private GameObject m_ResourcePrefab = null;
[SerializeField]
private Transform m_ContentTransform = null;
private ISCAN_Settings settingsInterface;
private ISCAN_Color colorInterface;
private SettingsPage currentPage;
public bool IsResourcePage(string body, string resource)
{
if (currentPage != null)
{
if (currentPage is SCAN_ColorResource)
{
if (colorInterface != null)
{
if (colorInterface.ResourcePlanet == body)
{
if (colorInterface.ResourceCurrent == resource)
return true;
}
}
}
}
return false;
}
public void setup(ISCAN_Settings settings, ISCAN_Color color, bool resource)
{
if (settings == null || color == null)
return;
settingsInterface = settings;
colorInterface = color;
if (resource)
ResourceSettings(true);
else
AltimetrySettings(true);
}
public override void OnPointerDown(PointerEventData eventData)
{
if (currentPage != null)
currentPage.OnPointerDown(eventData);
}
public void MapSettings(bool isOn)
{
if (!isOn)
return;
if (currentPage != null)
{
currentPage.gameObject.SetActive(false);
DestroyImmediate(currentPage.gameObject);
}
if (m_ContentTransform == null || m_MapPrefab == null || settingsInterface == null)
return;
if (settingsInterface.LockInput)
settingsInterface.LockInput = false;
currentPage = Instantiate(m_MapPrefab).GetComponent<SettingsPage>();
if (currentPage == null)
return;
currentPage.transform.SetParent(m_ContentTransform, false);
((SCAN_ColorMap)currentPage).SetMap(colorInterface, settingsInterface);
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ProcessTooltips();
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ClearWarningsAndDropDown();
}
public void AltimetrySettings(bool isOn)
{
if (!isOn)
return;
if (currentPage != null)
{
currentPage.gameObject.SetActive(false);
DestroyImmediate(currentPage.gameObject);
}
if (m_ContentTransform == null || m_AltimetryPrefab == null || settingsInterface == null)
return;
if (settingsInterface.LockInput)
settingsInterface.LockInput = false;
currentPage = Instantiate(m_AltimetryPrefab).GetComponent<SettingsPage>();
if (currentPage == null)
return;
currentPage.transform.SetParent(m_ContentTransform, false);
((SCAN_ColorAltimetry)currentPage).SetTerrain(colorInterface, settingsInterface);
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ProcessTooltips();
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ClearWarningsAndDropDown();
}
public void SlopeSettings(bool isOn)
{
if (!isOn)
return;
if (currentPage != null)
{
currentPage.gameObject.SetActive(false);
DestroyImmediate(currentPage.gameObject);
}
if (m_ContentTransform == null || m_SlopePrefab == null || settingsInterface == null)
return;
if (settingsInterface.LockInput)
settingsInterface.LockInput = false;
currentPage = Instantiate(m_SlopePrefab).GetComponent<SettingsPage>();
if (currentPage == null)
return;
currentPage.transform.SetParent(m_ContentTransform, false);
((SCAN_ColorSlope)currentPage).SetSlope(colorInterface, settingsInterface);
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ProcessTooltips();
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ClearWarningsAndDropDown();
}
public void BiomeSettings(bool isOn)
{
if (!isOn)
return;
if (currentPage != null)
{
currentPage.gameObject.SetActive(false);
DestroyImmediate(currentPage.gameObject);
}
if (m_ContentTransform == null || m_BiomePrefab == null || settingsInterface == null)
return;
if (settingsInterface.LockInput)
settingsInterface.LockInput = false;
currentPage = Instantiate(m_BiomePrefab).GetComponent<SettingsPage>();
if (currentPage == null)
return;
currentPage.transform.SetParent(m_ContentTransform, false);
((SCAN_ColorBiome)currentPage).SetBiome(colorInterface, settingsInterface);
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ProcessTooltips();
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ClearWarningsAndDropDown();
}
public void ResourceSettings(bool isOn)
{
if (!isOn)
return;
if (currentPage != null)
{
currentPage.gameObject.SetActive(false);
DestroyImmediate(currentPage.gameObject);
}
if (m_ContentTransform == null || m_ResourcePrefab == null || settingsInterface == null)
return;
if (settingsInterface.LockInput)
settingsInterface.LockInput = false;
currentPage = Instantiate(m_ResourcePrefab).GetComponent<SettingsPage>();
if (currentPage == null)
return;
currentPage.transform.SetParent(m_ContentTransform, false);
((SCAN_ColorResource)currentPage).SetResource(colorInterface, settingsInterface);
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ProcessTooltips();
if (SCAN_Settings.Instance != null)
SCAN_Settings.Instance.ClearWarningsAndDropDown();
}
public static float ParseInput(string input, float original, float min, float max, int digits)
{
float f = original;
if (!float.TryParse(input, out f))
return f;
if (f < min)
return original;
else if (f > max)
return original;
f = (float)Math.Round(f, digits);
return f;
}
}
}