-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDefaultLightArrayManager.cs
More file actions
154 lines (123 loc) · 4.11 KB
/
DefaultLightArrayManager.cs
File metadata and controls
154 lines (123 loc) · 4.11 KB
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
#region Usings
using System;
using System.Diagnostics;
using System.Linq;
using PAPIPlugin.Interfaces;
using PAPIPlugin.Internal;
using PAPIPlugin.UI;
using Tac;
using UnityEngine;
#endregion
namespace PAPIPlugin.Impl
{
public class DefaultLightArrayManager : ILightArrayManager
{
private ApplicationLauncherButton _appButtonStock;
private GroupWindow<ILightArrayConfig> _groupWindow;
private ILightArrayConfig _lightConfig;
public DefaultLightArrayManager()
{
GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
}
#region ILightArrayManager Members
public event EventHandler ParsingFinished;
public ILightArrayConfig LightConfig
{
get { return _lightConfig; }
set
{
if (Equals(_lightConfig, value))
{
return;
}
_lightConfig = value;
InitializeConfig(_lightConfig);
}
}
public ILightArrayConfig LoadConfig()
{
Util.LogInfo("Starting to parse light definitions...");
var stopwatch = Stopwatch.StartNew();
var defaultConfig = new DefaultLightArrayConfig();
defaultConfig.LoadConfig();
LightConfig = defaultConfig;
Util.LogInfo(string.Format("Finished parsing definitions. Found {0} light groups with a total of {1} light arrays in a time of {2}.",
LightConfig.LightArrayGroups.Count(), LightConfig.LightArrayGroups.Sum(group => group.LightArrays.Count()), stopwatch.Elapsed));
OnParsingFinished();
return LightConfig;
}
public void Update()
{
foreach (var lightGroup in LightConfig.LightArrayGroups)
{
lightGroup.Update();
}
}
public void Dispose()
{
Dispose(true);
}
#endregion
private void OnGUIAppLauncherReady()
{
if (ApplicationLauncher.Ready)
{
_appButtonStock = ApplicationLauncher.Instance.AddModApplication(
OnIconClickHandler,
OnIconClickHandler,
DummyVoid,
DummyVoid,
DummyVoid,
DummyVoid,
ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.SPACECENTER,
(Texture)GameDatabase.Instance.GetTexture("PAPIPlugin/icon_button", false)
);
}
}
private void DummyVoid() { }
private void OnIconClickHandler()
{
if (_groupWindow == null)
{
_groupWindow = new GroupWindow<ILightArrayConfig>(LightConfig);
_groupWindow.SetVisible(true);
}
else
{
_groupWindow.ToggleVisible();
}
// Don't lock highlight on the button since it's just a toggle
_appButtonStock.SetFalse(false);
}
private void InitializeConfig(ILightArrayConfig lightConfig)
{
foreach (var lightArray in lightConfig.LightArrayGroups.SelectMany(group => group.LightArrays))
{
lightArray.InitializeDisplay(this);
}
}
protected virtual void OnParsingFinished()
{
var handler = ParsingFinished;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
~DefaultLightArrayManager()
{
Dispose(false);
}
protected virtual void Dispose(bool disposing)
{
LightConfig.Destroy();
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
if (_appButtonStock != null)
ApplicationLauncher.Instance.RemoveModApplication(_appButtonStock);
if (_groupWindow != null)
{
_groupWindow.SetVisible(false);
}
}
}
}