forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlightComputerWindow.cs
More file actions
131 lines (119 loc) · 4.13 KB
/
Copy pathFlightComputerWindow.cs
File metadata and controls
131 lines (119 loc) · 4.13 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
using System;
using UnityEngine;
namespace RemoteTech.UI
{
public class FlightComputerWindow : AbstractWindow
{
private enum FragmentTab
{
Attitude = 0,
Rover = 1,
Power = 2,
}
private FragmentTab mTab = FragmentTab.Attitude;
private readonly AttitudeFragment mAttitude;
private readonly RoverFragment mRover;
private readonly QueueFragment mQueue;
private readonly PowerFragment mPower;
private bool mQueueEnabled;
private FlightComputer.FlightComputer mFlightComputer;
private readonly String tabModeDescString = "Switch to Attitude, Rover or Power mode.";
private static readonly String appTitle = "Flight Computer";
private FragmentTab Tab
{
get
{
return mTab;
}
set
{
int NumberOfTabs = 3;
if ((int)value >= NumberOfTabs) {
mTab = (FragmentTab)0;
} else if ((int)value < 0) {
mTab = (FragmentTab)(NumberOfTabs - 1);
} else {
mTab = value;
}
}
}
public FlightComputerWindow(FlightComputer.FlightComputer fc)
: base(Guid.NewGuid(), appTitle, new Rect(100, 100, 0, 0), WindowAlign.Floating)
{
mSavePosition = true;
mFlightComputer = fc;
mAttitude = new AttitudeFragment(fc, () => OnQueue());
mRover = new RoverFragment(fc, () => OnQueue());
mPower = new PowerFragment(fc, () => OnQueue());
mQueue = new QueueFragment(fc);
mQueueEnabled = false;
}
public override void Show()
{
base.Show();
mFlightComputer.OnActiveCommandAbort += mAttitude.Reset;
mFlightComputer.OnNewCommandPop += mAttitude.getActiveFlightMode;
mAttitude.getActiveFlightMode();
mPower.getActivePowerMode();
}
public override void Hide()
{
mFlightComputer.OnActiveCommandAbort -= mAttitude.Reset;
mFlightComputer.OnNewCommandPop -= mAttitude.getActiveFlightMode;
base.Hide();
}
public override void Window(int id)
{
GUI.skin = null;
GUILayout.BeginHorizontal();
{
GUILayout.BeginHorizontal();
{
switch (mTab) {
case FragmentTab.Attitude:
mAttitude.Draw();
break;
case FragmentTab.Rover:
mRover.Draw();
break;
case FragmentTab.Power:
mPower.Draw();
break;
}
}
GUILayout.EndHorizontal();
// Switch FC mode
if (GUI.Button(new Rect(2, 2, 16, 16), new GUIContent("<", tabModeDescString))) {
Tab--;
}
if (GUI.Button(new Rect(16, 2, 16, 16), new GUIContent(">", tabModeDescString))) {
Tab++;
}
if (mQueueEnabled) {
mQueue.Draw();
} else {
GUILayout.BeginVertical();
{
GUILayout.BeginScrollView(Vector2.zero, GUILayout.ExpandHeight(true));
GUILayout.EndScrollView();
}
GUILayout.EndVertical();
}
}
GUILayout.EndHorizontal();
base.Window(id);
}
private void OnQueue()
{
mQueueEnabled = !mQueueEnabled;
if(mQueueEnabled)
{
this.Title = appTitle + ": " + mFlightComputer.Vessel.vesselName.Substring(0, Math.Min(25, mFlightComputer.Vessel.vesselName.Length));
}
else
{
this.Title = appTitle;
}
}
}
}