forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueFragment.cs
More file actions
137 lines (127 loc) · 5.06 KB
/
Copy pathQueueFragment.cs
File metadata and controls
137 lines (127 loc) · 5.06 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
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RemoteTech
{
public class QueueFragment : IFragment
{
private readonly FlightComputer mFlightComputer;
private Vector2 mScrollPosition;
private String mExtraDelay;
private double Delay
{
get
{
TimeSpan delay;
if (!RTUtil.TryParseDuration(mExtraDelay, out delay))
{
delay = new TimeSpan();
}
return Math.Max(delay.TotalSeconds, 0);
}
set { mExtraDelay = value.ToString(); }
}
private GUIContent Status
{
get
{
var tooltip = new List<String>();
var status = new List<String>();
if ((mFlightComputer.Status & FlightComputer.State.NoConnection) == FlightComputer.State.NoConnection)
{
status.Add("Connection Error");
tooltip.Add("Cannot queue commands");
}
if ((mFlightComputer.Status & FlightComputer.State.OutOfPower) == FlightComputer.State.OutOfPower)
{
status.Add("Out of Power");
tooltip.Add("Commands can be missed");
tooltip.Add("Timers halt");
}
if ((mFlightComputer.Status & FlightComputer.State.NotMaster) == FlightComputer.State.NotMaster)
{
status.Add("Slave");
tooltip.Add("Has no control");
}
if ((mFlightComputer.Status & FlightComputer.State.Packed) == FlightComputer.State.Packed)
{
status.Add("Packed");
tooltip.Add("Frozen");
}
if (mFlightComputer.Status == FlightComputer.State.Normal)
{
status.Add("All systems nominal");
tooltip.Add("None");
}
return new GUIContent("Status: " + String.Join(", ", status.ToArray()) + ".",
"Effects: " + String.Join("; ", tooltip.ToArray()) + ".");
}
}
public QueueFragment(FlightComputer fc)
{
mFlightComputer = fc;
Delay = 0;
}
public void Draw()
{
if (Event.current.Equals(Event.KeyboardEvent("return")) && GUI.GetNameOfFocusedControl() == "xd")
{
mFlightComputer.TotalDelay = Delay;
}
GUILayout.BeginVertical();
{
mScrollPosition = GUILayout.BeginScrollView(mScrollPosition, GUILayout.Width(250));
{
{
GUILayout.BeginHorizontal(GUI.skin.box);
{
var s = new StringBuilder();
foreach (var c in mFlightComputer.ActiveCommands)
{
s.Append(c.Description);
}
GUILayout.Label(s.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
GUILayout.FlexibleSpace();
RTUtil.Button("x", () => RTCore.Instance.StartCoroutine(OnClickReset()), GUILayout.Width(21), GUILayout.Height(21));
}
GUILayout.EndHorizontal();
foreach (var c in mFlightComputer.QueuedCommands)
{
GUILayout.BeginHorizontal(GUI.skin.box);
{
GUILayout.Label(c.Description);
GUILayout.FlexibleSpace();
RTUtil.Button("x", () => RTCore.Instance.StartCoroutine(OnClickCancel(c)), GUILayout.Width(21), GUILayout.Height(21));
}
GUILayout.EndHorizontal();
}
}
}
GUILayout.EndScrollView();
GUILayout.Label(Status);
GUILayout.BeginHorizontal();
{
GUILayout.Label(new GUIContent("Delay (+ signal): " + RTUtil.FormatDuration(mFlightComputer.TotalDelay), "Total delay including signal delay."));
GUILayout.FlexibleSpace();
GUI.SetNextControlName("xd");
RTUtil.TextField(ref mExtraDelay, GUILayout.Width(50));
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
public IEnumerator OnClickCancel(ICommand c)
{
yield return null;
mFlightComputer.Enqueue(CancelCommand.WithCommand(c));
}
public IEnumerator OnClickReset()
{
yield return null;
mFlightComputer.Enqueue(CancelCommand.ResetActive());
}
}
}