forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTSpaceCentre.cs
More file actions
122 lines (103 loc) · 3.95 KB
/
Copy pathRTSpaceCentre.cs
File metadata and controls
122 lines (103 loc) · 3.95 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
using RemoteTech.UI;
using System;
using System.Linq;
using UnityEngine;
using KSP.UI.Screens;
namespace RemoteTech
{
[KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
public class RTSpaceCentre : MonoBehaviour
{
/// <summary>Button for KSP Stock Tool bar</summary>
public static ApplicationLauncherButton LauncherButton = null;
/// <summary>OptionWindow</summary>
private OptionWindow _optionWindow;
/// <summary>Texture for the KSP Stock Tool-bar Button</summary>
private Texture2D _rtOptionBtn;
/// <summary>
/// Start method for RTSpaceCentre
/// </summary>
public void Start()
{
// create the option window
_optionWindow = new OptionWindow();
GameEvents.onLevelWasLoaded.Add(onLevelWasLoaded);
GameEvents.OnUpgradeableObjLevelChange.Add(OnUpgradeableObjLevelChange);
RTSettings.OnSettingsChanged.Add(OnRtSettingsChanged);
_rtOptionBtn = RTUtil.LoadImage("gitpagessat");
LauncherButton = ApplicationLauncher.Instance.AddModApplication(
_optionWindow.toggleWindow, null, null, null, null, null,
ApplicationLauncher.AppScenes.SPACECENTER,
_rtOptionBtn);
}
/// <summary>
/// Callback-Event when a Upgradeable object (TrackingStation) has changed
/// </summary>
private void OnUpgradeableObjLevelChange(Upgradeables.UpgradeableObject obj, int lvl)
{
if (!obj.name.Equals("TrackingStation"))
return;
RTLog.Verbose("OnUpgradeableObjLevelChange {0} - Level: {1}", RTLogLevel.LVL4, obj.name, lvl);
ReloadUpgradableAntennas(lvl+1);
}
/// <summary>
/// Callback-Event when the RTSettings are changed
/// </summary>
private void OnRtSettingsChanged()
{
ReloadUpgradableAntennas();
}
// Note: KSP's GameEvents.onLevelWasLoaded has the lower-case 'on' instead of usual 'On'
private void onLevelWasLoaded(GameScenes scene)
{
if (scene != GameScenes.SPACECENTER)
return;
if (!RTSettings.Instance.FirstStart)
return;
// open here the option dialog for the first start
RTLog.Notify("First start of RemoteTech!");
_optionWindow.Show();
RTSettings.Instance.FirstStart = false;
}
/// <summary>
/// Apply antenna upgrades to all ground stations.
/// </summary>
/// <param name="techlvl">The level applied to the antennas range.</param>
private void ReloadUpgradableAntennas(int techlvl = 0)
{
foreach ( var satellite in RTSettings.Instance.GroundStations)
{
satellite.reloadUpgradeableAntennas(techlvl);
}
}
/// <summary>
/// Unity onGUI Method to draw the OptionWindow
/// </summary>
public void OnGUI()
{
Action windows = delegate { };
var windowCount = AbstractWindow.Windows.Values.Count;
for (var i = 0; i < windowCount; i++)
{
var window = AbstractWindow.Windows.Values.ElementAt(i);
windows += window.Draw;
}
windows.Invoke();
}
/// <summary>
/// Unity OnDestroy Method to clean up
/// </summary>
public void OnDestroy()
{
RTSettings.OnSettingsChanged.Remove(OnRtSettingsChanged);
GameEvents.onLevelWasLoaded.Remove(onLevelWasLoaded);
GameEvents.OnUpgradeableObjLevelChange.Remove(OnUpgradeableObjLevelChange);
_optionWindow.Hide();
_optionWindow = null;
if (LauncherButton != null)
{
ApplicationLauncher.Instance.RemoveModApplication(LauncherButton);
}
}
}
}