forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugWindow.cs
More file actions
506 lines (466 loc) · 22.6 KB
/
Copy pathDebugWindow.cs
File metadata and controls
506 lines (466 loc) · 22.6 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
using System;
using System.Collections.Generic;
using UnityEngine;
namespace RemoteTech.UI
{
class DebugWindow : AbstractWindow
{
#region AbstractWindow-Definitions
public DebugWindow()
: base(new Guid("B17930C0-EDE6-4299-BE78-D975EAD1986B"), "RemoteTech DebugWindow",
new Rect(Screen.width / 2 - 250, Screen.height / 2 - 225, 500, 450), WindowAlign.Floating)
{
this.mSavePosition = true;
this.initializeDebugMenue();
}
public override void Hide()
{
InputLockManager.RemoveControlLock("RTLockDebug");
base.Hide();
}
#endregion
#region Member
/// <summary>Scroll position of the debug log textarea</summary>
private Vector2 debugLogScrollPosition;
/// <summary>Scroll position of the content area</summary>
private Vector2 contentScrollPosition;
/// <summary>Current selected log level</summary>
private RTLogLevel currentLogLevel = RTLogLevel.LVL1;
/// <summary>Current selected menue item</summary>
private int currentDebugMenue = 0;
/// <summary>List of all menue items</summary>
private List<string> debugMenueItems = new List<string>();
private int deactivatedMissionControls = 0;
/// API Input fields
private string HasFlightComputerGuidInput = "";
private string HasAnyConnectionGuidInput = "";
private string HasConnectionToKSCGuidInput = "";
private string GetShortestSignalDelayGuidInput = "";
private string GetSignalDelayToKSCGuidInput = "";
private string GetSignalDelayToSatelliteGuidAInput = "";
private string GetSignalDelayToSatelliteGuidBInput = "";
private string ReceivDataVesselGuidInput = "";
private string HasLocalControlGuidInput = "";
#endregion
#region Base-drawing
/// <summary>
/// Draws the content of the window
/// </summary>
public override void Window(int uid)
{
// push the current GUI.skin
var pushSkin = GUI.skin;
GUI.skin = HighLogic.Skin;
GUILayout.BeginVertical(GUILayout.Width(500), GUILayout.Height(350));
{
#region Draw debug menue
// Draw the debug menue
GUILayout.BeginHorizontal();
{
// push the font size of buttons
var pushFontsize = GUI.skin.button.fontSize;
GUI.skin.button.fontSize = 11;
int menueItemCounter = 0;
foreach (string menueItem in this.debugMenueItems)
{
RTUtil.FakeStateButton(new GUIContent(menueItem), () => { this.currentDebugMenue = menueItemCounter; }, currentDebugMenue, menueItemCounter, GUILayout.Height(16));
menueItemCounter++;
}
// pop the saved button size back
GUI.skin.button.fontSize = pushFontsize;
}
GUILayout.EndHorizontal();
#endregion
#region Draw content
contentScrollPosition = GUILayout.BeginScrollView(contentScrollPosition);
{
switch (this.currentDebugMenue)
{
case 0: { this.drawRTSettingsTab(); break; }
case 1: { this.drawAPITester(); break; }
case 2: { this.drawGuidReader(); break; }
default: { GUILayout.Label("Item " + this.currentDebugMenue.ToString() + " not yet implemented"); break; }
}
GUILayout.FlexibleSpace();
}
GUILayout.EndScrollView();
#endregion
#region Draw debug log
// Draw a 100 height debug-console at the bottom of the debug-window
GUILayout.BeginVertical(GUILayout.Height(150));
this.drawRTDebugLogEntrys();
GUILayout.EndVertical();
// Draw the clear log button
// Clear Logs Button
GUILayout.BeginHorizontal();
{
var pushFontsize = GUI.skin.button.fontSize;
GUI.skin.button.fontSize = 12;
RTUtil.Button(new GUIContent("Clear Logs in " + this.currentLogLevel.ToString(), "tbd."), () => RTLog.RTLogList[this.currentLogLevel].Clear());
GUI.skin.button.fontSize = pushFontsize;
}
GUILayout.EndHorizontal();
#endregion
}
GUILayout.EndVertical();
// Set a control lock that we can scroll through textareas
InputLockManager.RemoveControlLock("RTLockDebug");
if (this.backupPosition.ContainsMouse())
{
InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS, "RTLockDebug");
}
base.Window(uid);
// pop back the saved skin
GUI.skin = pushSkin;
}
#endregion
private void initializeDebugMenue()
{
this.debugMenueItems.Add("RemoteTech Settings");
this.debugMenueItems.Add("API-Tester");
this.debugMenueItems.Add("GUID-Reader");
}
/// <summary>
/// Draws all debug logs
/// </summary>
private void drawRTDebugLogEntrys()
{
GUIStyle lablestyle = new GUIStyle(GUI.skin.label);
lablestyle.wordWrap = false;
lablestyle.fontSize = 11;
lablestyle.normal.textColor = Color.white;
// draw the vertical buttons for each debug lvl
GUILayout.BeginHorizontal();
{
var pushFontsize = GUI.skin.button.fontSize;
GUI.skin.button.fontSize = 11;
foreach (RTLogLevel lvl in Enum.GetValues(typeof(RTLogLevel)))
{
RTUtil.FakeStateButton(new GUIContent(lvl.ToString()), () => { this.currentLogLevel = lvl; }, (int)currentLogLevel, (int)lvl, GUILayout.Height(16));
}
GUI.skin.button.fontSize = pushFontsize;
}
GUILayout.EndHorizontal();
// draw the input of the selected debug list
debugLogScrollPosition = GUILayout.BeginScrollView(debugLogScrollPosition);
{
foreach (var logEntry in RTLog.RTLogList[this.currentLogLevel])
{
GUILayout.Label(logEntry, lablestyle, GUILayout.Height(13));
}
}
GUILayout.EndScrollView();
// If the mouse is not over the debug window we will flip the scrollposition.y to maximum
if (!this.backupPosition.ContainsMouse())
{
debugLogScrollPosition.y = Mathf.Infinity;
}
}
/// <summary>
/// Draws the RTSettings section
/// </summary>
private void drawRTSettingsTab()
{
var settings = RTSettings.Instance;
int firstColWidth = 250;
var pushLabelSize = GUI.skin.label.fontSize;
var pushButtonSize = GUI.skin.button.fontSize;
GUI.skin.label.fontSize = 12;
GUI.skin.button.fontSize = 12;
// Deaktivate Mission Control
GUILayout.BeginHorizontal();
{
GUILayout.Label("Deactivate KSC: ", GUILayout.Width(firstColWidth));
RTUtil.FakeStateButton(new GUIContent("On"), () => { foreach (MissionControlSatellite mcs in settings.GroundStations) { mcs.togglePower(false); }; deactivatedMissionControls = 1; }, deactivatedMissionControls, 1);
RTUtil.FakeStateButton(new GUIContent("Off"), () => { foreach (MissionControlSatellite mcs in settings.GroundStations) { mcs.togglePower(true); }; deactivatedMissionControls = 0; }, deactivatedMissionControls, 0);
}
GUILayout.EndHorizontal();
GUILayout.Space(10);
GUILayout.Label("Cheat options");
GUILayout.BeginHorizontal();
{
GUILayout.Label("Signal through bodys: ", GUILayout.Width(firstColWidth));
int cheatEVAFuel = (CheatOptions.InfinitePropellant) ? 1 : 0;
RTUtil.FakeStateButton(new GUIContent("On"), () => { CheatOptions.InfinitePropellant = true; }, cheatEVAFuel, 1);
RTUtil.FakeStateButton(new GUIContent("Off"), () => { CheatOptions.InfinitePropellant = false; }, cheatEVAFuel, 0);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
GUILayout.Label("Infinite Fuel: ", GUILayout.Width(firstColWidth));
int cheatinfiniteFuel = (CheatOptions.InfinitePropellant) ? 1 : 0;
RTUtil.FakeStateButton(new GUIContent("On"), () => { CheatOptions.InfinitePropellant = true; }, cheatinfiniteFuel, 1);
RTUtil.FakeStateButton(new GUIContent("Off"), () => { CheatOptions.InfinitePropellant = false; }, cheatinfiniteFuel, 0);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
GUILayout.Label("Infinite RCS Fuel: ", GUILayout.Width(firstColWidth));
int cheatinfiniteRCSFuel = (CheatOptions.InfinitePropellant) ? 1 : 0;
RTUtil.FakeStateButton(new GUIContent("On"), () => { CheatOptions.InfinitePropellant = true; }, cheatinfiniteRCSFuel, 1);
RTUtil.FakeStateButton(new GUIContent("Off"), () => { CheatOptions.InfinitePropellant = false; }, cheatinfiniteRCSFuel, 0);
}
GUILayout.EndHorizontal();
GUI.skin.label.fontSize = pushLabelSize;
GUI.skin.button.fontSize = pushButtonSize;
}
/// <summary>
/// Draws the API Tester section
/// </summary>
private void drawAPITester()
{
// switch to the API Debug log
this.currentLogLevel = RTLogLevel.API;
#region API.HasFlightComputer
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.HasFlightComputer; Guid: ", GUILayout.ExpandWidth(true));
this.HasFlightComputerGuidInput = GUILayout.TextField(this.HasFlightComputerGuidInput, GUILayout.Width(160));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
var result = RemoteTech.API.API.HasFlightComputer(new Guid(this.HasFlightComputerGuidInput));
RTLog.Verbose("API.HasFlightComputer({0}) = {1}", this.currentLogLevel, this.HasFlightComputerGuidInput, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
#region API.HasAnyConnection
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.HasAnyConnection; Guid: ", GUILayout.ExpandWidth(true));
this.HasAnyConnectionGuidInput = GUILayout.TextField(this.HasAnyConnectionGuidInput, GUILayout.Width(160));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
var result = RemoteTech.API.API.HasAnyConnection(new Guid(this.HasAnyConnectionGuidInput));
RTLog.Verbose("API.HasAnyConnection({0}) = {1}", this.currentLogLevel, this.HasAnyConnectionGuidInput, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
#region API.HasConnectionToKSC
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.HasConnectionToKSC; Guid: ", GUILayout.ExpandWidth(true));
this.HasConnectionToKSCGuidInput = GUILayout.TextField(this.HasConnectionToKSCGuidInput, GUILayout.Width(160));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
var result = RemoteTech.API.API.HasConnectionToKSC(new Guid(this.HasConnectionToKSCGuidInput));
RTLog.Verbose("API.HasConnectionToKSC({0}) = {1}", this.currentLogLevel, this.HasConnectionToKSCGuidInput, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
#region APi.GetShortestSignalDelay
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.GetShortestSignalDelay; Guid: ", GUILayout.ExpandWidth(true));
this.GetShortestSignalDelayGuidInput = GUILayout.TextField(this.GetShortestSignalDelayGuidInput, GUILayout.Width(160));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
var result = RemoteTech.API.API.GetShortestSignalDelay(new Guid(this.GetShortestSignalDelayGuidInput));
RTLog.Verbose("API.GetShortestSignalDelayGuidInput({0}) = {1}", this.currentLogLevel, this.GetShortestSignalDelayGuidInput, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
#region API.GetSignalDelayToKSC
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.GetSignalDelayToKSC; Guid: ", GUILayout.ExpandWidth(true));
this.GetSignalDelayToKSCGuidInput = GUILayout.TextField(this.GetSignalDelayToKSCGuidInput, GUILayout.Width(160));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
var result = RemoteTech.API.API.GetSignalDelayToKSC(new Guid(this.GetSignalDelayToKSCGuidInput));
RTLog.Verbose("API.GetSignalDelayToKSC({0}) = {1}", this.currentLogLevel, this.GetSignalDelayToKSCGuidInput, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
#region API.GetSignalDelayToSatellite
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.GetSignalDelayToSatellite; Guid: ", GUILayout.ExpandWidth(true));
this.GetSignalDelayToSatelliteGuidAInput = GUILayout.TextField(this.GetSignalDelayToSatelliteGuidAInput, GUILayout.Width(70));
GUILayout.Label("to: ", GUILayout.ExpandWidth(true));
this.GetSignalDelayToSatelliteGuidBInput = GUILayout.TextField(this.GetSignalDelayToSatelliteGuidBInput, GUILayout.Width(70));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
var result = RemoteTech.API.API.GetSignalDelayToSatellite(new Guid(this.GetSignalDelayToSatelliteGuidAInput), new Guid(this.GetSignalDelayToSatelliteGuidBInput));
RTLog.Verbose("API.GetSignalDelayToSatellite({0},{1}) = {2}", this.currentLogLevel, this.GetSignalDelayToSatelliteGuidAInput, this.GetSignalDelayToSatelliteGuidBInput, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
#region API.QueueCommandToFlightComputer
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.QueueCommandToFlightComputer; Guid: ", GUILayout.ExpandWidth(true));
this.ReceivDataVesselGuidInput = GUILayout.TextField(this.ReceivDataVesselGuidInput, GUILayout.Width(160));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
ConfigNode dataNode = new ConfigNode();
dataNode.AddValue("Executor", "RemoteTech");
dataNode.AddValue("QueueLabel", "Receive Data");
dataNode.AddValue("ActiveLabel", "Receiveing Data ...");
dataNode.AddValue("ShortLabel", "Receive Data");
dataNode.AddValue("ReflectionType", "RemoteTech.UI.DebugWindow");
dataNode.AddValue("ReflectionPopMethod", "ReceiveDataPop");
dataNode.AddValue("ReflectionExecuteMethod", "ReceiveDataExec");
dataNode.AddValue("ReflectionAbortMethod", "ReceiveDataAbort");
dataNode.AddValue("GUIDString", this.ReceivDataVesselGuidInput);
dataNode.AddValue("YourData1", "RemoteTech");
dataNode.AddValue("YourDataN", "TechRemote");
var result = RemoteTech.API.API.QueueCommandToFlightComputer(dataNode);
RTLog.Verbose("API.QueueCommandToFlightComputer(ConfigNode) = {0}", this.currentLogLevel, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
#region API.HasLocalControl
GUILayout.BeginHorizontal();
{
GUILayout.Label("API.HasLocalControl; Guid: ", GUILayout.ExpandWidth(true));
this.HasLocalControlGuidInput = GUILayout.TextField(this.HasLocalControlGuidInput, GUILayout.Width(160));
if (GUILayout.Button("Run", GUILayout.Width(50)))
{
try
{
var result = RemoteTech.API.API.HasLocalControl(new Guid(this.HasLocalControlGuidInput));
RTLog.Verbose("API.HasLocalControl({0}) = {1}", this.currentLogLevel, this.HasLocalControlGuidInput, result);
}
catch (Exception ex)
{
RTLog.Verbose("Exception {0}", this.currentLogLevel, ex);
}
// go to the end of the log
this.debugLogScrollPosition.y = Mathf.Infinity;
}
}
GUILayout.EndHorizontal();
#endregion
}
/// <summary>
/// Draws a list with all ship guids and command stations to copy these values for the api tester
/// </summary>
private void drawGuidReader()
{
// draw the vessel list
#region Vessel list
foreach (var vessel in FlightGlobals.Vessels)
{
// skip different types
if (vessel.vesselType == VesselType.SpaceObject || vessel.vesselType == VesselType.Unknown) continue;
GUILayout.BeginHorizontal();
{
var pushFontStyle = GUI.skin.label.fontStyle;
// active vessel, make bold
if (FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.id == vessel.id)
{
GUI.skin.label.fontStyle = FontStyle.Bold;
}
GUILayout.Label(vessel.vesselName, GUILayout.ExpandWidth(true));
GUILayout.TextField(vessel.id.ToString(), GUILayout.Width(270));
GUI.skin.label.fontStyle = pushFontStyle;
}
GUILayout.EndHorizontal();
}
#endregion
// draw the Ground stations
#region Ground stations
foreach (var stations in RTCore.Instance.Network.GroundStations)
{
GUILayout.BeginHorizontal();
{
GUILayout.Label(stations.Value.Name, GUILayout.ExpandWidth(true));
GUILayout.TextField(stations.Key.ToString(), GUILayout.Width(270));
}
GUILayout.EndHorizontal();
}
#endregion
}
/// <summary>
/// This method is needed as a callback function for the API.QueueCommandToFlightComputer
/// </summary>
/// <param name="data">data passed from the flightcomputer</param>
public static bool ReceiveDataPop(ConfigNode data)
{
RTLog.Verbose("Received Data via Api.ReceiveData", RTLogLevel.API);
RTLog.Notify("Data: {0}",data);
return true;
}
public static bool ReceiveDataExec(ConfigNode data)
{
RTLog.Verbose("Received Data via Api.ReceiveDataExec", RTLogLevel.API);
RTLog.Notify("Data: {0}", data);
return bool.Parse(data.GetValue("AbortCommand"));
}
public static void ReceiveDataAbort(ConfigNode data)
{
RTLog.Verbose("Aborting via Api.ReceiveDataAbort", RTLogLevel.API);
RTLog.Notify("Data: {0}", data);
}
}
}