Skip to content

Commit

Permalink
Stuff Strikes Back. Christmas Remaster.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Hoksbergen committed Dec 26, 2013
1 parent a6fcaaf commit 731df1d
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/RemoteTech2/FlightComputer/Commands/AbstractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class AbstractCommand : ICommand
// true: delete afterwards.
public virtual bool Execute(FlightComputer f, FlightCtrlState fcs) { return true; }

public virtual void Abort() { }

public int CompareTo(ICommand dc)
{
return TimeStamp.CompareTo(dc.TimeStamp);
Expand Down
12 changes: 11 additions & 1 deletion src/RemoteTech2/FlightComputer/Commands/AttitudeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AttitudeCommand : AbstractCommand
{
public static readonly Dictionary<FlightMode, String> FormatMode = new Dictionary<FlightMode, String>()
{
{ FlightMode.Off, "Mode: Off," },
{ FlightMode.Off, "Mode: Off" },
{ FlightMode.KillRot, "Mode: Kill rotation" },
{ FlightMode.AttitudeHold, "Mode: Hold {0} {1}" },
{ FlightMode.AltitudeHold, "Mode: Hold {0}" },
Expand Down Expand Up @@ -101,6 +101,8 @@ public override string Description
}
}

private bool mAbort;

public override bool Pop(FlightComputer f)
{
if (Mode == FlightMode.KillRot)
Expand All @@ -112,6 +114,12 @@ public override bool Pop(FlightComputer f)

public override bool Execute(FlightComputer f, FlightCtrlState fcs)
{
if (mAbort)
{
Mode = FlightMode.Off;
mAbort = false;
}

switch (Mode)
{
case FlightMode.Off:
Expand All @@ -129,6 +137,8 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
return false;
}

public override void Abort() { mAbort = true; }

public static AttitudeCommand Off()
{
return new AttitudeCommand()
Expand Down
10 changes: 10 additions & 0 deletions src/RemoteTech2/FlightComputer/Commands/BurnCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ public override String Description
}
}

private bool mAbort;

public override bool Pop(FlightComputer f)
{
return true;
}

public override bool Execute(FlightComputer f, FlightCtrlState fcs)
{
if (mAbort)
{
fcs.mainThrottle = 0.0f;
return true;
}

if (Duration > 0)
{
fcs.mainThrottle = Throttle;
Expand All @@ -45,6 +53,8 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
return false;
}

public override void Abort() { mAbort = true; }

public static BurnCommand Off()
{
return new BurnCommand()
Expand Down
18 changes: 17 additions & 1 deletion src/RemoteTech2/FlightComputer/Commands/CancelCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ public class CancelCommand : AbstractCommand

public override bool Pop(FlightComputer f)
{
f.Remove(Command);
if (Command == null)
{
f.Reset();
}
else
{
f.Remove(Command);
}
return false;
}

Expand All @@ -26,5 +33,14 @@ public static CancelCommand WithCommand(ICommand cmd)
TimeStamp = RTUtil.GameTime,
};
}

public static CancelCommand ResetActive()
{
return new CancelCommand()
{
Command = null,
TimeStamp = RTUtil.GameTime,
};
}
}
}
1 change: 1 addition & 0 deletions src/RemoteTech2/FlightComputer/Commands/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public interface ICommand : IComparable<ICommand>

bool Pop(FlightComputer f);
bool Execute(FlightComputer f, FlightCtrlState fcs);
void Abort();
}
}
9 changes: 9 additions & 0 deletions src/RemoteTech2/FlightComputer/FlightComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public FlightComputer(ISignalProcessor s)
SignalProcessor = s;
Vessel = s.Vessel;
SanctionedPilots = new List<Action<FlightCtrlState>>();

var target = TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget);
mActiveCommands[target.Priority] = target;
var attitude = AttitudeCommand.Off();
Expand All @@ -99,6 +100,14 @@ public void Dispose()
}
}

public void Reset()
{
foreach (var cmd in mActiveCommands.Values)
{
cmd.Abort();
}
}

public void Enqueue(ICommand cmd, bool ignore_control = false, bool ignore_delay = false, bool ignore_extra = false)
{
if (!InputAllowed && !ignore_control) return;
Expand Down
6 changes: 4 additions & 2 deletions src/RemoteTech2/NetworkRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private void UpdateNetworkCones()
for (int i = newLength; i < oldLength; i++)
{
GameObject.Destroy(mCones[i]);
mCones[i] = null;
}
mCones.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0));
mCones.AddRange(Enumerable.Repeat((NetworkCone) null, Math.Max(newLength - oldLength, 0)));
Expand All @@ -121,6 +122,7 @@ private void UpdateNetworkEdges()
for (int i = newLength; i < oldLength; i++)
{
GameObject.Destroy(mLines[i]);
mLines[i] = null;
}
mLines.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0));
mLines.AddRange(Enumerable.Repeat<NetworkLine>(null, Math.Max(newLength - oldLength, 0)));
Expand Down Expand Up @@ -195,12 +197,12 @@ public void Detach()
{
for (int i = 0; i < mLines.Count; i++)
{
GameObject.Destroy(mLines[i]);
GameObject.DestroyImmediate(mLines[i]);
}
mLines.Clear();
for (int i = 0; i < mCones.Count; i++)
{
GameObject.Destroy(mCones[i]);
GameObject.DestroyImmediate(mCones[i]);
}
mCones.Clear();
DestroyImmediate(this);
Expand Down
17 changes: 13 additions & 4 deletions src/RemoteTech2/RTUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ public static float Format180To360(float degrees)

public static String FormatDuration(double duration)
{
TimeSpan time = TimeSpan.FromSeconds(duration);
StringBuilder s = new StringBuilder();
if (time.TotalDays > DaysInAYear)
var time = TimeSpan.FromSeconds(duration);
var s = new StringBuilder();
if (time.TotalDays / DaysInAYear >= 1)
{
s.Append(Math.Floor(time.TotalDays / DaysInAYear));
s.Append("y");
}
if (time.TotalDays > 0)
if (time.TotalDays % DaysInAYear >= 1)
{
s.Append(Math.Floor(time.TotalDays % DaysInAYear));
s.Append("d");
Expand Down Expand Up @@ -263,6 +263,15 @@ public static void GroupButton(int wide, String[] text, ref int group, Action<in
}
}

public static void StateButton(GUIContent text, int state, int value, Action<int> onStateChange, params GUILayoutOption[] options)
{
bool result;
if ((result = GUILayout.Toggle(Object.Equals(state, value), text, GUI.skin.button, options)) != Object.Equals(state, value))
{
onStateChange.Invoke(result ? value : ~value);
}
}

public static void StateButton<T>(GUIContent text, T state, T value, Action<int> onStateChange, params GUILayoutOption[] options)
{
bool result;
Expand Down
10 changes: 8 additions & 2 deletions src/RemoteTech2/UI/FocusFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Draw()
mSelection = (s > 0) ? sat : null;
if (mSelection != null)
{
var newTarget = PlanetariumCamera.fetch.targets.FirstOrDefault(t => t.gameObject.name == sat.Name);
var newTarget = PlanetariumCamera.fetch.targets.FirstOrDefault(t => t != null && t.gameObject.name == sat.Name);
if (newTarget == null)
{
var vessel = sat.SignalProcessor.Vessel;
Expand All @@ -37,8 +37,14 @@ public void Draw()
scaledMovement.vessel = vessel;
scaledMovement.type = MapObject.MapObjectType.VESSEL;
newTarget = scaledMovement;
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
PlanetariumCamera.fetch.targets.Remove(newTarget);
}
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
else
{
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
}
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/RemoteTech2/UI/FocusOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ private Rect PositionButton
{
if (!KnowledgeBase.Instance) return new Rect(0, 0, 0, 0);
var position = KnowledgeBase.Instance.KnowledgeContainer.transform.position;
return new Rect(Screen.width - Texture.Satellite.width + (position.x - 613.5f),
var position2 = UIManager.instance.rayCamera.WorldToScreenPoint(position);
var rect = new Rect(position2.x + 154,
250 + 2 * 31,
Texture.Satellite.width,
Texture.Satellite.height);
return rect;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/RemoteTech2/UI/NetworkCone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private void SetupMesh()
mMeshFilter.mesh.vertices = new Vector3[8];
mMeshFilter.mesh.uv = new Vector2[8] { new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 0), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 0) };
mMeshFilter.mesh.SetIndices(new int[] { 0, 2, 1, 2, 3, 1, 4, 6, 5, 6, 7, 5}, MeshTopology.Triangles, 0);
mMeshFilter.mesh.MarkDynamic();
Active = false;
}

Expand Down
14 changes: 11 additions & 3 deletions src/RemoteTech2/UI/QueueFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,26 @@ public void Draw()
mScrollPosition = GUILayout.BeginScrollView(mScrollPosition, GUILayout.Width(250));
{
{
GUILayout.BeginVertical(GUI.skin.box);
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.EndVertical();
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));
RTUtil.Button("x", () => RTCore.Instance.StartCoroutine(OnClickCancel(c)), GUILayout.Width(21), GUILayout.Height(21));
}
GUILayout.EndHorizontal();
}
Expand All @@ -125,5 +127,11 @@ public IEnumerator OnClickCancel(ICommand c)
yield return null;
mFlightComputer.Enqueue(CancelCommand.WithCommand(c));
}

public IEnumerator OnClickReset()
{
yield return null;
mFlightComputer.Enqueue(CancelCommand.ResetActive());
}
}
}

0 comments on commit 731df1d

Please sign in to comment.