-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cs
112 lines (91 loc) · 1.82 KB
/
Window.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
using UnityEngine;
namespace SciencePlus
{
[KSPAddon(KSPAddon.Startup.Flight, false)]
public class WindowFlight : Window
{
}
[KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
public class WindowSpaceCenter : Window
{
}
public class Window : MonoBehaviour
{
static Rect windowpos;
private static bool gui_enabled;
private static bool hide_ui;
static Window instance;
public static void ToggleGUI()
{
gui_enabled = !gui_enabled;
if (instance != null)
{
instance.UpdateGUIState();
}
}
public static void HideGUI()
{
gui_enabled = false;
if (instance != null)
{
instance.UpdateGUIState();
}
}
public static void ShowGUI()
{
gui_enabled = true;
if (instance != null)
{
instance.UpdateGUIState();
}
}
void UpdateGUIState()
{
enabled = !hide_ui && gui_enabled;
}
void onHideUI()
{
hide_ui = true;
UpdateGUIState();
}
void onShowUI()
{
hide_ui = false;
UpdateGUIState();
}
public void Awake()
{
instance = this;
GameEvents.onHideUI.Add(onHideUI);
GameEvents.onShowUI.Add(onShowUI);
}
void OnDestroy()
{
instance = null;
GameEvents.onHideUI.Remove(onHideUI);
GameEvents.onShowUI.Remove(onShowUI);
}
void Start()
{
UpdateGUIState();
}
void WindowGUI(int windowID)
{
GUILayout.BeginVertical();
foreach (ScienceCounter.ScienceType scienceType in ScienceCounter.instance.allScienceTypes)
{
GUILayout.Label(scienceType.scienceName + ": " + (scienceType.scienceBank + scienceType.scienceCache));
}
GUILayout.EndVertical();
GUI.DragWindow(new Rect(0, 0, 1000, 200));
}
void OnGUI()
{
if (gui_enabled)
{
GUI.skin = HighLogic.Skin;
windowpos = GUILayout.Window(GetInstanceID(), windowpos, WindowGUI, "Science+", GUILayout.Width(200));
}
}
}
}