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
145 lines (131 loc) · 4.75 KB
/
Copy pathFlightComputerWindow.cs
File metadata and controls
145 lines (131 loc) · 4.75 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
using System;
using UnityEngine;
using KSP.Localization;
namespace RemoteTech.UI
{
public class FlightComputerWindow : AbstractWindow
{
private enum FragmentTab
{
Attitude = 0,
Rover = 1,
Power = 2,
PID = 3,
}
private FragmentTab mTab = FragmentTab.Attitude;
private readonly AttitudeFragment mAttitude;
private readonly RoverFragment mRover;
private readonly QueueFragment mQueue;
private readonly PowerFragment mPower;
private readonly PIDControllerFragment mPID;
private bool mQueueEnabled;
private FlightComputer.FlightComputer mFlightComputer;
private readonly String tabModeDescString = Localizer.Format("#RT_FC_desc");//"Switch to Attitude, Rover, Power or PID mode."
private static readonly String appTitle = Localizer.Format("#RT_FC_Title");//"Flight Computer"
private FragmentTab Tab
{
get
{
return mTab;
}
set
{
int NumberOfTabs = 4;
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());
mPID = new PIDControllerFragment(fc, () => OnQueue());
mQueue = new QueueFragment(fc);
mQueueEnabled = false;
}
public override void Show()
{
Position.x= RTSettings.Instance.FCWinPosX;
Position.y = RTSettings.Instance.FCWinPosY;
base.Show();
mFlightComputer.OnActiveCommandAbort += mAttitude.Reset;
mFlightComputer.OnNewCommandPop += mAttitude.getActiveFlightMode;
mAttitude.getActiveFlightMode();
mPower.getActivePowerMode();
}
public override void Hide()
{
RTSettings.Instance.FCWinPosX = Position.x;
RTSettings.Instance.FCWinPosY = Position.y;
//RTSettings.Instance.Save(); //overkill
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;
case FragmentTab.PID:
mPID.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;
}
}
}
}