-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCAN_UI_Loader.cs
845 lines (713 loc) · 23.6 KB
/
SCAN_UI_Loader.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCAN_UI_Loader - Script for loading in all UI objects
*
* 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;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using SCANsat.Unity;
using SCANsat.Unity.Unity;
using KSP.UI;
using KSP.UI.Screens;
using TMPro;
using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette;
namespace SCANsat.SCAN_Unity
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class SCAN_UI_Loader : MonoBehaviour
{
private const string prefabAssetName = "scansat_prefabs";
private const string imageAssetName = "scan_images";
private static bool loaded;
private static bool skinLoaded;
private static bool spritesLoaded;
private static bool tmpProcessed;
private static bool tooltipsProcessed;
private static bool prefabsProcessed;
private static bool clearLoaded;
private static bool toggleLoaded;
private static bool appLoaded;
private static UISkinDef _unitySkinDef;
private static Sprite _podIcon;
private static Sprite _planeIcon;
private static Sprite _probeIcon;
private static Sprite _debrisIcon;
private static Sprite _baseIcon;
private static Sprite _stationIcon;
private static Sprite _landerIcon;
private static Sprite _roverIcon;
private static Sprite _relayIcon;
private static Sprite _asteroidIcon;
private static Sprite _evaIcon;
private static Sprite _planetIcon;
private static Sprite _mysteryIcon;
private static Sprite _flagIcon;
private static Sprite _apMarker;
private static Sprite _peMarker;
private static Sprite _maneuverMarker;
private static Sprite _encounterMarker;
private static Sprite _exitMarker;
private static Sprite _anomalyIcon;
private static Sprite _waypointIcon;
private static Sprite _clearSprite;
private static Sprite _toggleNormal;
private static Sprite _toggleHover;
private static Sprite _toggleActive;
private static Sprite _toggleOn;
private static Sprite _toggleOnHover;
private static Sprite _toggleOnActive;
private static Sprite _unityToggleOnHover;
private static Sprite _appButtonNormal;
private static Sprite _appButtonHover;
private static Sprite _appButtonActive;
private static Sprite _appButtonDisabled;
private static Sprite _appBackground;
private static Sprite _kspTooltipBackground;
private static Sprite _unityTooltipBackground;
private static GameObject[] loadedPrefabs;
private static GameObject _mainMapPrefab;
private static GameObject _bigMapPrefab;
private static GameObject _zoomMapPrefab;
private static GameObject _instrumentsPrefab;
private static GameObject _overlayPrefab;
private static GameObject _settingsPrefab;
private static GameObject _toolbarPrefab;
private static GameObject _tooltipPrefab;
public static GameObject MainMapPrefab
{
get { return _mainMapPrefab; }
}
public static GameObject BigMapPrefab
{
get { return _bigMapPrefab; }
}
public static GameObject ZoomMapPrefab
{
get { return _zoomMapPrefab; }
}
public static GameObject InstrumentsPrefab
{
get { return _instrumentsPrefab; }
}
public static GameObject OverlayPrefab
{
get { return _overlayPrefab; }
}
public static GameObject SettingsPrefab
{
get { return _settingsPrefab; }
}
public static GameObject ToolbarPrefab
{
get { return _toolbarPrefab; }
}
public static UISkinDef UnitySkinDef
{
get { return _unitySkinDef; }
}
public static Sprite PodIcon
{
get { return _podIcon; }
}
public static Sprite PlaneIcon
{
get { return _planeIcon; }
}
public static Sprite ProbeIcon
{
get { return _probeIcon; }
}
public static Sprite DebrisIcon
{
get { return _debrisIcon; }
}
public static Sprite BaseIcon
{
get { return _baseIcon; }
}
public static Sprite StationIcon
{
get { return _stationIcon; }
}
public static Sprite LanderIcon
{
get { return _landerIcon; }
}
public static Sprite RoverIcon
{
get { return _roverIcon; }
}
public static Sprite RelayIcon
{
get { return _relayIcon; }
}
public static Sprite AsteroidIcon
{
get { return _asteroidIcon; }
}
public static Sprite EVAIcon
{
get { return _evaIcon; }
}
public static Sprite PlanetIcon
{
get { return _planetIcon; }
}
public static Sprite MysteryIcon
{
get { return _mysteryIcon; }
}
public static Sprite FlagIcon
{
get { return _flagIcon; }
}
public static Sprite APMarker
{
get { return _apMarker; }
}
public static Sprite PEMarker
{
get { return _peMarker; }
}
public static Sprite ManeuverMarker
{
get { return _maneuverMarker; }
}
public static Sprite EncounterMarker
{
get { return _encounterMarker; }
}
public static Sprite ExitMarker
{
get { return _exitMarker; }
}
public static Sprite AnomalyIcon
{
get { return _anomalyIcon; }
}
public static Sprite WaypointIcon
{
get { return _waypointIcon; }
}
public static Sprite VesselIcon(VesselType type)
{
switch(type)
{
case VesselType.Base:
return _baseIcon;
case VesselType.Debris:
return _debrisIcon;
case VesselType.EVA:
return _evaIcon;
case VesselType.Flag:
return _flagIcon;
case VesselType.Lander:
return _landerIcon;
case VesselType.Plane:
return _planeIcon;
case VesselType.Probe:
return _probeIcon;
case VesselType.Relay:
return _relayIcon;
case VesselType.Rover:
return _roverIcon;
case VesselType.Ship:
return _podIcon;
case VesselType.SpaceObject:
return _asteroidIcon;
case VesselType.Station:
return _stationIcon;
case VesselType.Unknown:
return _mysteryIcon;
default:
return _mysteryIcon;
}
}
public static void ResetUIStyle()
{
if (loadedPrefabs != null)
processUIPrefabs();
}
private static string path;
private void Awake()
{
if (loaded)
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
path = KSPUtil.ApplicationRootPath + "GameData/SCANsat/Resources/";
StartCoroutine(loadResources());
}
private IEnumerator loadResources()
{
while (ApplicationLauncher.Instance == null)
yield return null;
while (SCANconfigLoader.languagePack == null)
yield return null;
while (SCAN_Settings_Config.Instance == null)
yield return null;
if (!spritesLoaded)
loadTextures();
if (!skinLoaded)
loadUnitySkin();
loadPrefabBundle();
loaded = true;
}
private static void loadTextures()
{
if (!clearLoaded)
{
Texture2D clear = new Texture2D(1, 1);
clear.SetPixel(1, 1, palette.clear);
clear.Apply();
_clearSprite = Sprite.Create(clear, new Rect(0, 0, 1, 1), new Vector2(0.5f, 0.5f));
clearLoaded = true;
}
if (!toggleLoaded)
{
GUISkin skin = HighLogic.Skin;
if (skin == null)
return;
_toggleNormal = Sprite.Create(skin.toggle.normal.background, new Rect(16, 16, skin.toggle.normal.background.width - 32, skin.toggle.normal.background.height - 32), new Vector2(0.5f, 0.5f));
_toggleHover = Sprite.Create(skin.toggle.hover.background, new Rect(16, 16, skin.toggle.hover.background.width - 32, skin.toggle.hover.background.height - 32), new Vector2(0.5f, 0.5f));
_toggleActive = Sprite.Create(skin.toggle.active.background, new Rect(16, 16, skin.toggle.active.background.width - 32, skin.toggle.active.background.height - 32), new Vector2(0.5f, 0.5f));
_toggleOn = Sprite.Create(skin.toggle.onNormal.background, new Rect(16, 16, skin.toggle.onNormal.background.width - 32, skin.toggle.onNormal.background.height - 32), new Vector2(0.5f, 0.5f));
_toggleOnHover = Sprite.Create(skin.toggle.onHover.background, new Rect(16, 16, skin.toggle.onHover.background.width - 32, skin.toggle.onHover.background.height - 32), new Vector2(0.5f, 0.5f));
_toggleOnActive = Sprite.Create(skin.toggle.onActive.background, new Rect(16, 16, skin.toggle.onActive.background.width - 32, skin.toggle.onActive.background.height - 32), new Vector2(0.5f, 0.5f));
toggleLoaded = true;
}
if (!appLoaded)
{
if (ApplicationLauncher.Instance != null)
{
UIRadioButton button = ApplicationLauncher.Instance.listItemPrefab.toggleButton;
_appButtonNormal = button.stateFalse.normal;
_appButtonHover = button.stateTrue.highlight;
_appButtonActive = button.stateTrue.pressed;
_appButtonDisabled = button.stateTrue.disabled;
Image background = ApplicationLauncher.Instance.listItemPrefab.GetComponent<Image>();
if (background != null)
_appBackground = background.sprite;
appLoaded = true;
}
}
if (clearLoaded && toggleLoaded && appLoaded)
spritesLoaded = true;
}
private static void loadPrefabBundle()
{
if (loadedPrefabs == null)
{
AssetBundle prefabs = AssetBundle.LoadFromFile(path + prefabAssetName);
if (prefabs != null)
loadedPrefabs = prefabs.LoadAllAssets<GameObject>();
}
if (loadedPrefabs != null)
{
if (!tmpProcessed)
processTMPPrefabs();
if (!tooltipsProcessed && _tooltipPrefab != null)
processTooltips();
if (!prefabsProcessed)
processUIPrefabs();
}
}
private static void loadUnitySkin()
{
_unitySkinDef = new UISkinDef();
SkinInit(_unitySkinDef);
AssetBundle images = AssetBundle.LoadFromFile(path + imageAssetName);
if (images == null)
return;
Sprite[] loadedImages = images.LoadAllAssets<Sprite>();
if (loadedImages == null)
return;
for (int i = loadedImages.Length - 1; i >= 0; i--)
{
Sprite s = loadedImages[i];
if (s.name == "window")
_unitySkinDef.window.normal.background = s;
else if (s.name == "box")
_unitySkinDef.box.normal.background = s;
else if (s.name == "button")
_unitySkinDef.button.normal.background = s;
else if (s.name == "button hover")
_unitySkinDef.button.highlight.background = s;
else if (s.name == "button on")
_unitySkinDef.button.active.background = s;
else if (s.name == "toggle_border")
_unitySkinDef.toggle.normal.background = s;
else if (s.name == "SCAN_Toggle_Hover_Border")
_unitySkinDef.toggle.highlight.background = s;
else if (s.name == "toggle active_border")
_unitySkinDef.toggle.active.background = s;
else if (s.name == "SCAN_Toggle_Border")
_unitySkinDef.toggle.disabled.background = s;
else if (s.name == "SCAN_Toggle_On_Hover_Border")
_unityToggleOnHover = s;
else if (s.name == "textfield")
_unitySkinDef.textField.normal.background = s;
else if (s.name == "textfield hover")
_unitySkinDef.textField.highlight.background = s;
else if (s.name == "textfield on")
_unitySkinDef.textField.active.background = s;
else if (s.name == "horizontal scrollbar")
_unitySkinDef.horizontalScrollbar.normal.background = s;
else if (s.name == "horizontal scrollbar thumb")
_unitySkinDef.horizontalScrollbarThumb.normal.background = s;
else if (s.name == "vertical scrollbar")
_unitySkinDef.verticalScrollbar.normal.background = s;
else if (s.name == "vertical scrollbar thumb")
_unitySkinDef.verticalScrollbarThumb.normal.background = s;
else if (s.name == "horizontalslider")
_unitySkinDef.horizontalSlider.normal.background = s;
else if (s.name == "slider thumb")
_unitySkinDef.horizontalSliderThumb.normal.background = s;
else if (s.name == "slider thumb hover")
_unitySkinDef.horizontalSliderThumb.highlight.background = s;
else if (s.name == "slider thumb active")
_unitySkinDef.horizontalSliderThumb.active.background = s;
else if (s.name == "verticalslider")
_unitySkinDef.verticalSlider.normal.background = s;
else if (s.name == "slider thumb")
_unitySkinDef.verticalSliderThumb.normal.background = s;
else if (s.name == "slider thumb hover")
_unitySkinDef.verticalSliderThumb.highlight.background = s;
else if (s.name == "slider thumb active")
_unitySkinDef.verticalSliderThumb.active.background = s;
else if (s.name == "PodIcon")
_podIcon = s;
else if (s.name == "PlaneIcon")
_planeIcon = s;
else if (s.name == "ProbeIcon")
_probeIcon = s;
else if (s.name == "DebrisIcon")
_debrisIcon = s;
else if (s.name == "StationIcon")
_stationIcon = s;
else if (s.name == "LanderIcon")
_landerIcon = s;
else if (s.name == "RoverIcon")
_roverIcon = s;
else if (s.name == "RelayIcon")
_relayIcon = s;
else if (s.name == "AsteroidIcon")
_asteroidIcon = s;
else if (s.name == "EVAIcon")
_evaIcon = s;
else if (s.name == "BaseIcon")
_baseIcon = s;
else if (s.name == "PlanetIcon")
_planetIcon = s;
else if (s.name == "MysteryIcon")
_mysteryIcon = s;
else if (s.name == "FlagIcon")
_flagIcon = s;
else if (s.name == "APMarker")
_apMarker = s;
else if (s.name == "PEMarker")
_peMarker = s;
else if (s.name == "ManeuverMarker")
_maneuverMarker = s;
else if (s.name == "EncounterMarker")
_encounterMarker = s;
else if (s.name == "ExitMarker")
_exitMarker = s;
else if (s.name == "AnomalyIconOutline")
_anomalyIcon = s;
else if (s.name == "SCAN_WayPointIcon_Outline")
_waypointIcon = s;
else if (s.name == "KSP_Tooltip")
_kspTooltipBackground = s;
else if (s.name == "DropDownTex")
_unityTooltipBackground = s;
}
skinLoaded = true;
}
private static void SkinInit (UISkinDef skin)
{
skin.window = new UIStyle();
skin.box = new UIStyle();
skin.button = new UIStyle();
skin.toggle = new UIStyle();
skin.textField = new UIStyle();
skin.horizontalScrollbar = new UIStyle();
skin.horizontalScrollbarThumb = new UIStyle();
skin.verticalScrollbar = new UIStyle();
skin.verticalScrollbarThumb = new UIStyle();
skin.horizontalSlider = new UIStyle();
skin.horizontalSliderThumb = new UIStyle();
skin.verticalSlider = new UIStyle();
skin.verticalSliderThumb = new UIStyle();
skin.window.normal = new UIStyleState();
skin.box.normal = new UIStyleState();
skin.button.normal = new UIStyleState();
skin.button.highlight = new UIStyleState();
skin.button.active = new UIStyleState();
skin.toggle.normal = new UIStyleState();
skin.toggle.highlight = new UIStyleState();
skin.toggle.active = new UIStyleState();
skin.toggle.disabled = new UIStyleState();
skin.textField.normal = new UIStyleState();
skin.textField.highlight = new UIStyleState();
skin.textField.active = new UIStyleState();
skin.horizontalScrollbar.normal = new UIStyleState();
skin.horizontalScrollbarThumb.normal = new UIStyleState();
skin.verticalScrollbar.normal = new UIStyleState();
skin.verticalScrollbarThumb.normal = new UIStyleState();
skin.horizontalSlider.normal = new UIStyleState();
skin.horizontalSliderThumb.normal = new UIStyleState();
skin.horizontalSliderThumb.highlight = new UIStyleState();
skin.horizontalSliderThumb.active = new UIStyleState();
skin.verticalSlider.normal = new UIStyleState();
skin.verticalSliderThumb.normal = new UIStyleState();
skin.verticalSliderThumb.highlight = new UIStyleState();
skin.verticalSliderThumb.active = new UIStyleState();
}
private static void processTMPPrefabs()
{
for (int i = loadedPrefabs.Length - 1; i >= 0; i--)
{
GameObject o = loadedPrefabs[i];
if (o.name == "SCAN_MainMap")
_mainMapPrefab = o;
else if (o.name == "SCAN_BigMap")
_bigMapPrefab = o;
else if (o.name == "SCAN_ZoomMap")
_zoomMapPrefab = o;
else if (o.name == "SCAN_Instruments")
_instrumentsPrefab = o;
else if (o.name == "SCAN_Overlay")
_overlayPrefab = o;
else if (o.name == "SCAN_Settings")
_settingsPrefab = o;
else if (o.name == "SCAN_Toolbar")
_toolbarPrefab = o;
else if (o.name == "SCAN_Tooltip")
_tooltipPrefab = o;
if (o != null)
processTMP(o);
}
tmpProcessed = true;
}
private static void processTMP(GameObject obj)
{
TextHandler[] handlers = obj.GetComponentsInChildren<TextHandler>(true);
if (handlers == null)
return;
for (int i = 0; i < handlers.Length; i++)
TMProFromText(handlers[i]);
}
private static void TMProFromText(TextHandler handler)
{
if (handler == null)
return;
Text text = handler.GetComponent<Text>();
if (text == null)
return;
string t = text.text;
Color c = text.color;
int i = text.fontSize;
bool r = text.raycastTarget;
FontStyles sty = getStyle(text.fontStyle);
TextAlignmentOptions align = getAnchor(text.alignment);
float spacing = text.lineSpacing;
GameObject obj = text.gameObject;
MonoBehaviour.DestroyImmediate(text);
SCAN_TextMeshPro tmp = obj.AddComponent<SCAN_TextMeshPro>();
tmp.text = t;
tmp.color = c;
tmp.fontSize = i;
tmp.raycastTarget = r;
tmp.alignment = align;
tmp.fontStyle = sty;
tmp.lineSpacing = spacing;
tmp.font = Resources.Load("Fonts/Calibri SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
if (handler.Outline)
{
tmp.fontSharedMaterial = Resources.Load("Fonts/Materials/Calibri Dropshadow Outline", typeof(Material)) as Material; //smt.text.fontSharedMaterial;
if (tmp.fontMaterial) { }
tmp.outlineColor = palette.black;
tmp.outlineWidth = handler.OutlineWidth;
}
else
tmp.fontSharedMaterial = Resources.Load("Fonts/Materials/Calibri Dropshadow", typeof(Material)) as Material;
tmp.enableWordWrapping = true;
tmp.isOverlay = false;
tmp.richText = true;
}
private static void processTooltips()
{
for (int i = loadedPrefabs.Length - 1; i >= 0; i--)
{
GameObject o = loadedPrefabs[i];
TooltipHandler[] handlers = o.GetComponentsInChildren<TooltipHandler>(true);
if (handlers == null)
return;
for (int j = 0; j < handlers.Length; j++)
processTooltip(handlers[j]);
}
tooltipsProcessed = true;
}
private static void processTooltip(TooltipHandler handler)
{
if (handler == null)
return;
handler.Prefab = _tooltipPrefab;
handler.TooltipText = SCANconfigLoader.languagePack.GetStringWithName(handler.TooltipName);
toggleTooltip(handler, SCAN_Settings_Config.Instance.WindowTooltips);
}
public static void ToggleTooltips(bool isOn)
{
for (int i = loadedPrefabs.Length - 1; i >= 0; i--)
{
GameObject o = loadedPrefabs[i];
TooltipHandler[] handlers = o.GetComponentsInChildren<TooltipHandler>(true);
if (handlers == null)
return;
for (int j = 0; j < handlers.Length; j++)
toggleTooltip(handlers[j], isOn);
}
}
private static void toggleTooltip(TooltipHandler handler, bool isOn)
{
if (handler == null)
return;
handler.IsActive = isOn && !handler.HelpTip;
}
private static FontStyles getStyle(FontStyle style)
{
switch (style)
{
case FontStyle.Normal:
return FontStyles.Normal;
case FontStyle.Bold:
return FontStyles.Bold;
case FontStyle.Italic:
return FontStyles.Italic;
case FontStyle.BoldAndItalic:
return FontStyles.Bold;
default:
return FontStyles.Normal;
}
}
private static TextAlignmentOptions getAnchor(TextAnchor anchor)
{
switch (anchor)
{
case TextAnchor.UpperLeft:
return TextAlignmentOptions.TopLeft;
case TextAnchor.UpperCenter:
return TextAlignmentOptions.Top;
case TextAnchor.UpperRight:
return TextAlignmentOptions.TopRight;
case TextAnchor.MiddleLeft:
return TextAlignmentOptions.MidlineLeft;
case TextAnchor.MiddleCenter:
return TextAlignmentOptions.Midline;
case TextAnchor.MiddleRight:
return TextAlignmentOptions.MidlineRight;
case TextAnchor.LowerLeft:
return TextAlignmentOptions.BottomLeft;
case TextAnchor.LowerCenter:
return TextAlignmentOptions.Bottom;
case TextAnchor.LowerRight:
return TextAlignmentOptions.BottomRight;
default:
return TextAlignmentOptions.Center;
}
}
private static void processUIPrefabs()
{
for (int i = loadedPrefabs.Length - 1; i >= 0; i--)
{
GameObject o = loadedPrefabs[i];
if (o != null)
processUIComponents(o);
}
prefabsProcessed = true;
}
private static void processUIComponents(GameObject obj)
{
SCAN_Style[] styles = obj.GetComponentsInChildren<SCAN_Style>(true);
if (styles == null)
return;
for (int i = 0; i < styles.Length; i++)
processComponents(styles[i]);
}
private static void processComponents(SCAN_Style style)
{
if (style == null)
return;
UISkinDef skin = UISkinManager.defaultSkin;
Sprite KSPWindow = skin.window.normal.background;
bool stock = SCAN_Settings_Config.Instance == null || SCAN_Settings_Config.Instance.StockUIStyle || _unitySkinDef == null;
if (!stock)
skin = _unitySkinDef;
if (skin == null)
return;
switch (style.StlyeType)
{
case SCAN_Style.StyleTypes.Window:
style.setImage(skin.window.normal.background);
break;
case SCAN_Style.StyleTypes.KSPWindow:
style.setImage(_appBackground);
break;
case SCAN_Style.StyleTypes.Box:
style.setImage(skin.box.normal.background);
break;
case SCAN_Style.StyleTypes.HiddenBox:
style.setImage(stock ? skin.box.normal.background : _clearSprite);
break;
case SCAN_Style.StyleTypes.Button:
style.setButton(skin.button.normal.background, skin.button.highlight.background, skin.button.active.background, skin.button.active.background);
break;
case SCAN_Style.StyleTypes.HiddenButton:
style.setButton(_clearSprite, skin.button.highlight.background, skin.button.active.background, skin.button.active.background);
break;
case SCAN_Style.StyleTypes.AppButton:
style.setToggleButton(_appButtonNormal, _appButtonHover, _appButtonActive, _appButtonDisabled, _appButtonHover);
break;
case SCAN_Style.StyleTypes.Toggle:
if (stock)
style.setToggle(_toggleNormal, _toggleHover, _toggleActive, _toggleActive, _toggleOn, _toggleOnHover);
else
style.setToggle(skin.toggle.normal.background, skin.toggle.highlight.background, skin.toggle.active.background, skin.toggle.active.background, skin.toggle.disabled.background, _unityToggleOnHover);
break;
case SCAN_Style.StyleTypes.ToggleButton:
style.setToggleButton(skin.button.normal.background, skin.button.highlight.background, skin.button.active.background, skin.button.active.background, skin.button.active.background);
break;
case SCAN_Style.StyleTypes.KSPToggle:
style.setToggle(_toggleNormal, _toggleHover, _toggleActive, _toggleActive, _toggleOn, _toggleOnHover);
break;
case SCAN_Style.StyleTypes.HorizontalSlider:
style.setSlider(skin.horizontalSlider.normal.background, skin.horizontalSliderThumb.normal.background, skin.horizontalSliderThumb.highlight.background, skin.horizontalSliderThumb.active.background, skin.horizontalSliderThumb.active.background);
break;
case SCAN_Style.StyleTypes.VerticalScrollbar:
style.setScrollbar(skin.verticalScrollbar.normal.background, skin.verticalScrollbarThumb.normal.background);
break;
case SCAN_Style.StyleTypes.Tooltip:
style.setImage(stock ? _kspTooltipBackground : _unityTooltipBackground);
break;
case SCAN_Style.StyleTypes.VerticalSlider:
style.setButton(skin.horizontalSliderThumb.normal.background, skin.horizontalSliderThumb.highlight.background, skin.horizontalSliderThumb.active.background, skin.horizontalSliderThumb.active.background);
break;
case SCAN_Style.StyleTypes.Popup:
style.setImage(stock ? _kspTooltipBackground : _unityTooltipBackground);
break;
default:
break;
}
}
}
}