Skip to content

Commit

Permalink
Remove constructor from RPM menu
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jun 24, 2024
1 parent 724ae7b commit e09fa18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 5 additions & 0 deletions GameData/Astrogator/Astrogator-Changelog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ KERBALCHANGELOG
change = Better fixes for FlightGlobals NREs
type = Fix
}
CHANGE
{
change = Initialize RPM menu on demand instead of in constructor
type = Change
}
}

VERSION
Expand Down
28 changes: 12 additions & 16 deletions Source/AstrogatorMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ namespace Astrogator {
/// </summary>
public class AstrogatorMenu : InternalModule {

AstrogatorMenu()
: base()
{
model = new AstrogationModel(GetBestOrigin());
loader = new AstrogationLoadBehaviorette(model, null);
timeToWait = new List<DateTimeParts>();
cursorTransfer = 0;

loader.TryStartLoad(model.origin, null, null, null);
}

/// <summary>
/// Key code for the upward pointing wedge button, overridable by RPM configuration.
/// We use it to move the selection up by one row.
Expand Down Expand Up @@ -78,9 +67,9 @@ public class AstrogatorMenu : InternalModule {

private AstrogationModel model { get; set; }
private AstrogationLoadBehaviorette loader { get; set; }
private List<DateTimeParts> timeToWait { get; set; }
private List<DateTimeParts> timeToWait { get; set; } = new List<DateTimeParts>();
private double lastUniversalTime { get; set; }
private int cursorTransfer { get; set; }
private int cursorTransfer { get; set; } = 0;
private bool cursorMoved { get; set; }
private string menu { get; set; }
private int? activeButton { get; set; }
Expand Down Expand Up @@ -282,6 +271,13 @@ private void addRow(StringBuilder sb, TransferModel m, DateTimeParts dt, bool se
/// </returns>
public string ShowMenu(int columns, int rows)
{
if (model == null) {
model = new AstrogationModel(GetBestOrigin());
loader = new AstrogationLoadBehaviorette(model, null);
loader.OnDisplayOpened();
loader.TryStartLoad(model.origin, null, null, null);
}

if ((RefreshTransfers() || cursorMoved)) {
StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -334,10 +330,10 @@ private bool ErrorCondition {
public void PageActive(bool pageActive, int pageNumber)
{
if (pageActive) {
loader.OnDisplayOpened();
loader.TryStartLoad(model.origin, null, null, null);
loader?.OnDisplayOpened();
loader?.TryStartLoad(model.origin, null, null, null);
} else {
loader.OnDisplayClosed();
loader?.OnDisplayClosed();
}
}

Expand Down

0 comments on commit e09fa18

Please sign in to comment.