Skip to content

Commit 731df1d

Browse files
author
Sander Hoksbergen
committed
Stuff Strikes Back. Christmas Remaster.
1 parent a6fcaaf commit 731df1d

File tree

12 files changed

+90
-14
lines changed

12 files changed

+90
-14
lines changed

src/RemoteTech2/FlightComputer/Commands/AbstractCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public virtual String Description {
3030
// true: delete afterwards.
3131
public virtual bool Execute(FlightComputer f, FlightCtrlState fcs) { return true; }
3232

33+
public virtual void Abort() { }
34+
3335
public int CompareTo(ICommand dc)
3436
{
3537
return TimeStamp.CompareTo(dc.TimeStamp);

src/RemoteTech2/FlightComputer/Commands/AttitudeCommand.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class AttitudeCommand : AbstractCommand
4141
{
4242
public static readonly Dictionary<FlightMode, String> FormatMode = new Dictionary<FlightMode, String>()
4343
{
44-
{ FlightMode.Off, "Mode: Off," },
44+
{ FlightMode.Off, "Mode: Off" },
4545
{ FlightMode.KillRot, "Mode: Kill rotation" },
4646
{ FlightMode.AttitudeHold, "Mode: Hold {0} {1}" },
4747
{ FlightMode.AltitudeHold, "Mode: Hold {0}" },
@@ -101,6 +101,8 @@ public override string Description
101101
}
102102
}
103103

104+
private bool mAbort;
105+
104106
public override bool Pop(FlightComputer f)
105107
{
106108
if (Mode == FlightMode.KillRot)
@@ -112,6 +114,12 @@ public override bool Pop(FlightComputer f)
112114

113115
public override bool Execute(FlightComputer f, FlightCtrlState fcs)
114116
{
117+
if (mAbort)
118+
{
119+
Mode = FlightMode.Off;
120+
mAbort = false;
121+
}
122+
115123
switch (Mode)
116124
{
117125
case FlightMode.Off:
@@ -129,6 +137,8 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
129137
return false;
130138
}
131139

140+
public override void Abort() { mAbort = true; }
141+
132142
public static AttitudeCommand Off()
133143
{
134144
return new AttitudeCommand()

src/RemoteTech2/FlightComputer/Commands/BurnCommand.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ public override String Description
2020
}
2121
}
2222

23+
private bool mAbort;
24+
2325
public override bool Pop(FlightComputer f)
2426
{
2527
return true;
2628
}
2729

2830
public override bool Execute(FlightComputer f, FlightCtrlState fcs)
2931
{
32+
if (mAbort)
33+
{
34+
fcs.mainThrottle = 0.0f;
35+
return true;
36+
}
37+
3038
if (Duration > 0)
3139
{
3240
fcs.mainThrottle = Throttle;
@@ -45,6 +53,8 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
4553
return false;
4654
}
4755

56+
public override void Abort() { mAbort = true; }
57+
4858
public static BurnCommand Off()
4959
{
5060
return new BurnCommand()

src/RemoteTech2/FlightComputer/Commands/CancelCommand.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ public class CancelCommand : AbstractCommand
1414

1515
public override bool Pop(FlightComputer f)
1616
{
17-
f.Remove(Command);
17+
if (Command == null)
18+
{
19+
f.Reset();
20+
}
21+
else
22+
{
23+
f.Remove(Command);
24+
}
1825
return false;
1926
}
2027

@@ -26,5 +33,14 @@ public static CancelCommand WithCommand(ICommand cmd)
2633
TimeStamp = RTUtil.GameTime,
2734
};
2835
}
36+
37+
public static CancelCommand ResetActive()
38+
{
39+
return new CancelCommand()
40+
{
41+
Command = null,
42+
TimeStamp = RTUtil.GameTime,
43+
};
44+
}
2945
}
3046
}

src/RemoteTech2/FlightComputer/Commands/ICommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public interface ICommand : IComparable<ICommand>
1414

1515
bool Pop(FlightComputer f);
1616
bool Execute(FlightComputer f, FlightCtrlState fcs);
17+
void Abort();
1718
}
1819
}

src/RemoteTech2/FlightComputer/FlightComputer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public FlightComputer(ISignalProcessor s)
7979
SignalProcessor = s;
8080
Vessel = s.Vessel;
8181
SanctionedPilots = new List<Action<FlightCtrlState>>();
82+
8283
var target = TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget);
8384
mActiveCommands[target.Priority] = target;
8485
var attitude = AttitudeCommand.Off();
@@ -99,6 +100,14 @@ public void Dispose()
99100
}
100101
}
101102

103+
public void Reset()
104+
{
105+
foreach (var cmd in mActiveCommands.Values)
106+
{
107+
cmd.Abort();
108+
}
109+
}
110+
102111
public void Enqueue(ICommand cmd, bool ignore_control = false, bool ignore_delay = false, bool ignore_extra = false)
103112
{
104113
if (!InputAllowed && !ignore_control) return;

src/RemoteTech2/NetworkRenderer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private void UpdateNetworkCones()
9595
for (int i = newLength; i < oldLength; i++)
9696
{
9797
GameObject.Destroy(mCones[i]);
98+
mCones[i] = null;
9899
}
99100
mCones.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0));
100101
mCones.AddRange(Enumerable.Repeat((NetworkCone) null, Math.Max(newLength - oldLength, 0)));
@@ -121,6 +122,7 @@ private void UpdateNetworkEdges()
121122
for (int i = newLength; i < oldLength; i++)
122123
{
123124
GameObject.Destroy(mLines[i]);
125+
mLines[i] = null;
124126
}
125127
mLines.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0));
126128
mLines.AddRange(Enumerable.Repeat<NetworkLine>(null, Math.Max(newLength - oldLength, 0)));
@@ -195,12 +197,12 @@ public void Detach()
195197
{
196198
for (int i = 0; i < mLines.Count; i++)
197199
{
198-
GameObject.Destroy(mLines[i]);
200+
GameObject.DestroyImmediate(mLines[i]);
199201
}
200202
mLines.Clear();
201203
for (int i = 0; i < mCones.Count; i++)
202204
{
203-
GameObject.Destroy(mCones[i]);
205+
GameObject.DestroyImmediate(mCones[i]);
204206
}
205207
mCones.Clear();
206208
DestroyImmediate(this);

src/RemoteTech2/RTUtil.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ public static float Format180To360(float degrees)
122122

123123
public static String FormatDuration(double duration)
124124
{
125-
TimeSpan time = TimeSpan.FromSeconds(duration);
126-
StringBuilder s = new StringBuilder();
127-
if (time.TotalDays > DaysInAYear)
125+
var time = TimeSpan.FromSeconds(duration);
126+
var s = new StringBuilder();
127+
if (time.TotalDays / DaysInAYear >= 1)
128128
{
129129
s.Append(Math.Floor(time.TotalDays / DaysInAYear));
130130
s.Append("y");
131131
}
132-
if (time.TotalDays > 0)
132+
if (time.TotalDays % DaysInAYear >= 1)
133133
{
134134
s.Append(Math.Floor(time.TotalDays % DaysInAYear));
135135
s.Append("d");
@@ -263,6 +263,15 @@ public static void GroupButton(int wide, String[] text, ref int group, Action<in
263263
}
264264
}
265265

266+
public static void StateButton(GUIContent text, int state, int value, Action<int> onStateChange, params GUILayoutOption[] options)
267+
{
268+
bool result;
269+
if ((result = GUILayout.Toggle(Object.Equals(state, value), text, GUI.skin.button, options)) != Object.Equals(state, value))
270+
{
271+
onStateChange.Invoke(result ? value : ~value);
272+
}
273+
}
274+
266275
public static void StateButton<T>(GUIContent text, T state, T value, Action<int> onStateChange, params GUILayoutOption[] options)
267276
{
268277
bool result;

src/RemoteTech2/UI/FocusFragment.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Draw()
2626
mSelection = (s > 0) ? sat : null;
2727
if (mSelection != null)
2828
{
29-
var newTarget = PlanetariumCamera.fetch.targets.FirstOrDefault(t => t.gameObject.name == sat.Name);
29+
var newTarget = PlanetariumCamera.fetch.targets.FirstOrDefault(t => t != null && t.gameObject.name == sat.Name);
3030
if (newTarget == null)
3131
{
3232
var vessel = sat.SignalProcessor.Vessel;
@@ -37,8 +37,14 @@ public void Draw()
3737
scaledMovement.vessel = vessel;
3838
scaledMovement.type = MapObject.MapObjectType.VESSEL;
3939
newTarget = scaledMovement;
40+
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
41+
PlanetariumCamera.fetch.targets.Remove(newTarget);
4042
}
41-
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
43+
else
44+
{
45+
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
46+
}
47+
4248
}
4349
});
4450
}

src/RemoteTech2/UI/FocusOverlay.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ private Rect PositionButton
3535
{
3636
if (!KnowledgeBase.Instance) return new Rect(0, 0, 0, 0);
3737
var position = KnowledgeBase.Instance.KnowledgeContainer.transform.position;
38-
return new Rect(Screen.width - Texture.Satellite.width + (position.x - 613.5f),
38+
var position2 = UIManager.instance.rayCamera.WorldToScreenPoint(position);
39+
var rect = new Rect(position2.x + 154,
3940
250 + 2 * 31,
4041
Texture.Satellite.width,
4142
Texture.Satellite.height);
43+
return rect;
4244
}
4345
}
4446

0 commit comments

Comments
 (0)