Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 12497fed1ff3
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6b44f7fa5d55
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 4, 2020

  1. collapsible manœuvres

    eggrobin committed Aug 4, 2020
    Copy the full SHA
    4a5413a View commit details

Commits on Aug 5, 2020

  1. After pleroy’s review

    eggrobin committed Aug 5, 2020
    Copy the full SHA
    5238065 View commit details
  2. Merge pull request #2664 from eggrobin/minimize

    Collapsible manœuvres
    eggrobin authored Aug 5, 2020
    Copy the full SHA
    6b44f7f View commit details
Showing with 101 additions and 71 deletions.
  1. +32 −14 ksp_plugin_adapter/burn_editor.cs
  2. +69 −57 ksp_plugin_adapter/flight_planner.cs
46 changes: 32 additions & 14 deletions ksp_plugin_adapter/burn_editor.cs
Original file line number Diff line number Diff line change
@@ -56,29 +56,45 @@ public BurnEditor(PrincipiaPluginAdapter adapter,
ComputeEngineCharacteristics();
}

public enum Event {
None,
Changed,
Deleted,
Minimized,
Maximized,
}

// Renders the |BurnEditor|. Returns true if and only if the settings were
// changed.
public bool Render(string header,
bool anomalous,
double burn_final_time,
Action delete) {
public Event Render(string header,
bool anomalous,
double burn_final_time) {
bool changed = false;
previous_coast_duration_.max_value = burn_final_time - time_base;
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label(header);
string frame_info = "";
if (!reference_frame_selector_.FrameParameters().Equals(
if (UnityEngine.GUILayout.Button(
minimized ? "+" : "-", GUILayoutWidth(1))) {
minimized = !minimized;
return minimized ? Event.Minimized : Event.Maximized;
}
UnityEngine.GUILayout.Label(minimized ? $"{header} ({Δv():0.000} m/s)"
: header);
string info = "";
if (!minimized &&
!reference_frame_selector_.FrameParameters().Equals(
adapter_.plotting_frame_selector_.FrameParameters())) {
frame_info = "Manœuvre frame differs from plotting frame";
info = "Manœuvre frame differs from plotting frame";
}
UnityEngine.GUILayout.Label(
frame_info,
Style.RightAligned(Style.Info(UnityEngine.GUI.skin.label)));
info,
Style.Info(UnityEngine.GUI.skin.label));
if (UnityEngine.GUILayout.Button("Delete", GUILayoutWidth(2))) {
delete();
changed = true;
return Event.Deleted;
}
}
if (minimized) {
return Event.None;
}
using (new UnityEngine.GUILayout.VerticalScope()) {
// When we are first rendered, the |initial_mass_in_tonnes_| will just have
// been set. If we have fallen back to instant impulse, we should use this
@@ -152,7 +168,7 @@ public bool Render(string header,
Style.Warning(UnityEngine.GUI.skin.label));
changed_reference_frame_ = false;
}
return changed;
return changed ? Event.Changed : Event.None;
}

public double Δv() {
@@ -297,10 +313,12 @@ internal bool TryParsePreviousCoastDuration(string text, out double value) {
plugin.FlightPlanGetInitialTime(
vessel_.id.ToString());

private double final_time => initial_time_ + duration_;
public double initial_time => initial_time_;
public double final_time => initial_time_ + duration_;

private IntPtr plugin => adapter_.Plugin();
public int index { private get; set; }
public bool minimized { private get; set; } = true;
private BurnEditor previous_burn => get_burn_at_index_(index - 1);

private bool is_inertially_fixed_;
126 changes: 69 additions & 57 deletions ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -259,38 +259,44 @@ private void RenderFlightPlan(string vessel_guid) {

for (int i = 0; i < burn_editors_.Count; ++i) {
Style.HorizontalLine();
// In the future, coast information, e.g., orbit analysis will be
// shown between these lines. For now, we only have a button to
// insert a burn.
if (RenderAddManœuvreButton(i)) {
if (RenderCoast(i)) {
return;
}
Style.HorizontalLine();
BurnEditor burn = burn_editors_[i];
bool delete = false;
if (burn.Render(header : "Manœuvre #" + (i + 1),
anomalous :
i >= (burn_editors_.Count -
number_of_anomalous_manœuvres_),
burn_final_time : final_times[i],
delete : () => {delete = true;})) {
if (delete) {
switch (burn.Render(header : "Manœuvre #" + (i + 1),
anomalous :
i >= (burn_editors_.Count -
number_of_anomalous_manœuvres_),
burn_final_time : final_times[i])) {
case BurnEditor.Event.Deleted: {
var status = plugin.FlightPlanRemove(vessel_guid, i);
UpdateStatus(status, null);
burn_editors_[i].Close();
burn_editors_.RemoveAt(i);
UpdateBurnEditorIndices();
Shrink();
return;
} else {
}
case BurnEditor.Event.Minimized:
case BurnEditor.Event.Maximized: {
Shrink();
return;
}
case BurnEditor.Event.Changed: {
var status =
plugin.FlightPlanReplace(vessel_guid, burn.Burn(), i);
UpdateStatus(status, i);
burn.Reset(plugin.FlightPlanGetManoeuvre(vessel_guid, i));
break;
}
case BurnEditor.Event.None: {
break;
}
}
}
if (RenderAddManœuvreButton(burn_editors_.Count)) {
Style.HorizontalLine();
if (RenderCoast(burn_editors_.Count)) {
return;
}
}
@@ -347,47 +353,58 @@ private void RenderUpcomingEvents() {
}
}

private bool RenderAddManœuvreButton(int index) {
private bool RenderCoast(int index) {
string vessel_guid = predicted_vessel.id.ToString();
if (UnityEngine.GUILayout.Button(
"Add manœuvre",
UnityEngine.GUILayout.ExpandWidth(true))) {
double initial_time;
if (index == 0) {
initial_time = plugin.CurrentTime() + 60;
} else {
initial_time = plugin.FlightPlanGetManoeuvre(
vessel_guid,
index - 1).final_time + 60;
}
var editor =
new BurnEditor(adapter_,
predicted_vessel,
initial_time,
index,
get_burn_at_index : burn_editors_.ElementAtOrDefault);
Burn candidate_burn = editor.Burn();
var status = plugin.FlightPlanInsert(
vessel_guid, candidate_burn, index);

// The previous call did not necessarily create a manœuvre. Check if
// we need to add an editor.
int number_of_manœuvres =
plugin.FlightPlanNumberOfManoeuvres(vessel_guid);
if (number_of_manœuvres > burn_editors_.Count) {
editor.Reset(plugin.FlightPlanGetManoeuvre(
vessel_guid, index));
burn_editors_.Insert(index, editor);
UpdateBurnEditorIndices();
using (new UnityEngine.GUILayout.HorizontalScope()) {
double start_of_coast = index == 0
? plugin.FlightPlanGetInitialTime(vessel_guid)
: burn_editors_[index - 1].final_time;
string coast_description = index == burn_editors_.Count
? "Final trajectory"
: $@"Coast for {
(burn_editors_[index].initial_time -
start_of_coast).FormatDuration(show_seconds : false)}";
UnityEngine.GUILayout.Label(coast_description);
if (UnityEngine.GUILayout.Button("Add manœuvre", GUILayoutWidth(4))) {
double initial_time;
if (index == 0) {
initial_time = plugin.CurrentTime() + 60;
} else {
initial_time =
plugin.FlightPlanGetManoeuvre(vessel_guid,
index - 1).final_time + 60;
}
var editor = new BurnEditor(
adapter_,
predicted_vessel,
initial_time,
index,
get_burn_at_index : burn_editors_.ElementAtOrDefault);
editor.minimized = false;
Burn candidate_burn = editor.Burn();
var status = plugin.FlightPlanInsert(
vessel_guid, candidate_burn, index);

// The previous call did not necessarily create a manœuvre. Check if
// we need to add an editor.
int number_of_manœuvres =
plugin.FlightPlanNumberOfManoeuvres(vessel_guid);
if (number_of_manœuvres > burn_editors_.Count) {
editor.Reset(plugin.FlightPlanGetManoeuvre(
vessel_guid, index));
burn_editors_.Insert(index, editor);
UpdateBurnEditorIndices();
UpdateStatus(status, index);
Shrink();
return true;
}
// TODO(phl): The error messaging here will be either confusing or
// wrong. The messages should mention the new manœuvre without
// numbering it, since the numbering has not changed (“the new manœuvre
// would overlap with manœuvre #1 or manœuvre #2” or something along
// these lines).
UpdateStatus(status, index);
Shrink();
return true;
}
// TODO(phl): The error messaging here will be either confusing or wrong.
// The messages should mention the new manœuvre without numbering it,
// since the numbering has not changed (“the new manœuvre would overlap
// with manœuvre #1 or manœuvre #2” or something along these lines).
UpdateStatus(status, index);
}
return false;
}
@@ -522,11 +539,6 @@ private string GetStatusMessage() {
return message;
}

private BurnEditor GetPreviousBurnEditor(BurnEditor editor) {
int i = burn_editors_.IndexOf(editor);
return i == 0 ? null : burn_editors_[i - 1];
}

private void UpdateBurnEditorIndices() {
for (int j = 0; j < burn_editors_.Count; ++j) {
burn_editors_[j].index = j;