Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Mar 7, 2017
2 parents eb7c61b + 9746937 commit dd1f9c3
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Astrogator.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"VERSION": {
"MAJOR": 0,
"MINOR": 6,
"PATCH": 1,
"PATCH": 2,
"BUILD": 0
},
"KSP_VERSION_MIN": {
Expand Down
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Please follow these guidelines for submitting ideas for features.
- A mock-up screenshot is extremely helpful, both in making your suggestion clear, and in selling it as a good idea
- If you know of a mod that does something similar, provide a link; a reference implementation can be very helpful if your feature ends up getting worked on

Even if your suggestion is valid, specific, and clear, I may still decide at my sole discretion that it's not the direction I want to take this mod and close it anyway. Please understand that this likely has more to do with my vision for Astrogator than with your idea. However, if you feel motivated enough, the license (GPLv3) permits you to create and distribute your own forked version with whatever changes you like. If you decide to do this, please contact me to work out ways reduce confusion among users.
Even if your suggestion is valid, specific, and clear, I may still decide at my sole discretion that it's not the direction I want to take this mod and close it anyway. Please understand that this likely has more to do with my vision for Astrogator than with your idea. However, if you feel motivated enough, the license (GPLv3) permits you to create and distribute your own forked version with whatever changes you like. If you decide to do this, please read the section on [forking](#Forks).

## [Pull requests](https://github.com/HebaruSan/Astrogator/pulls)

Expand All @@ -44,3 +44,21 @@ Any proposed code changes are welcome, but will have to meet my personal coding
- Whenever possible, break complex physics calculations down to clear steps that a non-physics major can understand
- If a value is the same every time, it should be `const` or `static`, especially if it has to be loaded from a file
- No classes just for the sake of classes; if you're not storing instance-level data, don't make me create an object (we have several static classes in the `*Tools.cs` files that should be able to accommodate new code)

## Forks

Astrogator's license (GLPv3) permits modification of source code and redistribution. The following requests are for the sake of courtesy and not legally mandated.

My wishes vary depending on whether I'm still actively working on Astrogator. To determine whether I'm still active, I request a grace period of at least two calendar months from the time of last activity. When in doubt, ask on the forum thread (but please read at least a few of the previous pages of posts to see if there has already been such a discussion).

### If I'm still active

If I have posted on the KSP forums recently, released a new version of Astrogator recently, or otherwise made my presence known, my preferences are to keep any derivative works easily distinguishable from my version. This is especially the case if you wish to take it in a different direction than I do; your new concept should be free to grow into its own unique mod.

Please contact me to work out ways reduce confusion among users. I'll probably request that you release under a different but similar name, a favorite being "Cosmogator" due to the fun Cold War connotations.

### If I am no longer active

If I have vanished or stopped developing or supporting Astrogator, my preferences are to avoid "X Continued" naming schemes and to have the option to pick up where you left off if I do come back, especially if your changes are only for the sake of compatibility with new versions of KSP. This implies continuity in naming.

Please do **not** change the name. Cooperate with any others who are interested in updating to avoid redundant efforts, then continue releasing new versions of Astrogator from your fork according to [Semantic Versioning](http://semver.org).
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If it's already within 5 minutes, you'll be auto-warped to the exact time of the

## Settings

Click the wrench to open and close the settings panel:
Click the wrench to open the settings panel and the back button to close it:

![Settings panel](screenshots/settingsPanel.png)

Expand All @@ -54,13 +54,13 @@ Click the wrench to open and close the settings panel:
| Generate plane change burns | If you turn this off, then only (prograde) ejection maneuvers will be calculated. This may be needed if the plane change calculations become disruptive. |
| Add plane change burns to Δv column | If you enable this, then the delta V shown in the table will be the ejection node plus the plane change node. Otherwise only the ejection delta V is shown, to make ejection burns less confusing when flying without maneuver nodes. |
| Auto-delete user-created maneuver nodes | Our method for calculating plane changes doesn't work if other unrelated maneuvers are active. By default, we simply don't calculate them if that happens. Enabling this setting tells Astrogator to go ahead and delete your nodes if it needs to. **Use with caution!** |
| Calculate transfers to tracked asteroids | When this is enabled, tracked astroids will be included in the list of transfers as if they were celestial bodies. |
| Automatically target destination | When this is enabled, clicking the maneuver node icon will set the destination as the active vessel's target. This can be helpful because it enables the close approach markers. |
| Automatically focus destination | When this is enabled, clicking the maneuver icon will change the map view focus. If the default maneuvers create an encounter with the desired body, then that body will be focused so you can fine tune your arrival; otherwise the destination's parent body will be focused so you can establish the encounter. |
| Automatically edit ejection node | When this is enabled, clicking the maneuver icon will leave the first node open for editing. |
| Automatically edit plane change node | If you enable this, then the second node will be opened for editing instead of the first. |
| Automatically set SAS to maneuver mode | When this is enabled, clicking a maneuver creation button will activate SAS and put it into maneuver mode, which will cause your craft to orient toward the maneuver. |
| Adjust nodes with translation controls when RCS is off | When this is enabled and RCS is turned off, maneuver nodes generated by Astrogator can be adjusted using the HNIJKL translation keys and the joystick translation axes. |
| Calculate transfers to tracked asteroids | When this is enabled, tracked astroids will be included in the list of transfers as if they were celestial bodies. |
| Units: Metric | Shows delta V in m/s (meters per second) |
| Units: United States Customary | Shows delta V in mph (miles per hour) |

Expand Down Expand Up @@ -114,6 +114,7 @@ See [INSTALL.md](INSTALL.md).
- [TCShipInfo](http://forum.kerbalspaceprogram.com/index.php?/topic/59724-112-v04-resource-details-in-tracking-center/) for figuring out the tracking station API
- Main app icon modified from http://fontawesome.io/icon/map/
- Close X icon under Apache 2 license from https://material.io/icons/#ic_close and modified
- Back icon under Apache 2 license from https://material.io/icons/#ic_chevron_left
- ProjectGuid generated by https://www.guidgenerator.com/online-guid-generator.aspx
- Kepler, Hohmann, Tsiolkovsky, and Oberth for giving us the math
- In admiration of [Sailing Master Kevin Renner](https://en.wikipedia.org/wiki/The_Mote_in_God's_Eye)
7 changes: 2 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- At the "leaf nodes", choose the center of a range as the burn time
- Pick the soonest range when showing times or making maneuvers
- Only rule out a range once the entire thing is overdue
- [ ] Merge the correction burn into the ejection burn
- [ ] Re-do launch approximation to increase accuracy
- [ ] i18n / l10n (once SQUAD releases their version of it)

## Fixes
Expand Down Expand Up @@ -36,8 +38,3 @@
## Deferred pending stock changes

- [ ] Rendezvous with asteroids near Pe of their future encounter/escape trajectories

## Documentation

- [ ] New main screenshot
- [ ] New settings screenshot
Binary file added assets/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/backHover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/settingsHover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/mainScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/settingsPanel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 51 additions & 12 deletions src/AstrogationLoadBehaviorette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Astrogator {
///
/// Burns can expire if their burn time elapses into the past, so we need to check them once per second.
/// </summary>
public class AstrogationLoadBehaviorette {
public class AstrogationLoadBehaviorette : IDisposable {

/// <summary>
/// Construct a loader object for the given model
Expand All @@ -41,38 +41,54 @@ public AstrogationLoadBehaviorette(AstrogationModel m, LoadDoneCallback unReqNot
{
model = m;
unrequestedLoadNotification = unReqNotif;

// Watch for expiring burns
StartBurnTimePolling();
}

/// <summary>
/// Destructor; destroy the timer
/// Shut down and clean up any stuff that might cause problems if it runs
/// while the rest of the game is shutting down.
/// </summary>
~AstrogationLoadBehaviorette()
public void Dispose()
{
// Release reference to UI update callback in case it keeps the plugin active
unrequestedLoadNotification = null;

// Destroy the timer
StopBurnTimePolling();

// Make sure our calculation thread exits before the main thread cleans up
StopCalculatorThread();
}

private const double minSecondsBetweenLoads = 5;
private AstrogationModel model { get; set; }
private LoadDoneCallback unrequestedLoadNotification { get; set; }
private int numOpenDisplays { get; set; } = 0;
private bool loading { get; set; }
private double lastUpdateTime { get; set; }
private readonly object bgLoadMutex = new object();
private bool loading { get; set; }
private double lastUpdateTime { get; set; }
private Thread calculator { get; set; }
private readonly object bgLoadMutex = new object();

/// <summary>
/// Tell the loader that we are currently displaying the data.
/// If it thinks we aren't, it won't calculate anything.
/// </summary>
public void OnDisplayOpened() { ++numOpenDisplays; }
public void OnDisplayOpened()
{
if (++numOpenDisplays == 1) {
StartBurnTimePolling();
}
}

/// <summary>
/// Tell the loader that we're closing a display.
/// If it thinks they're all gone, it won't calculate anything.
/// </summary>
public void OnDisplayClosed() { --numOpenDisplays; }
public void OnDisplayClosed()
{
if (--numOpenDisplays == 0) {
StopBurnTimePolling();
}
}

private bool AllowStart(ITargetable newOrigin) {
return model != null
Expand All @@ -86,6 +102,17 @@ private bool AllowStart(ITargetable newOrigin) {
);
}

private void StopCalculatorThread()
{
if (calculator != null && calculator.IsAlive) {
DbgFmt("Waiting for calculator thread");
calculator.Join();
calculator = null;
} else {
DbgFmt("Calculator thread not running");
}
}

/// <summary>
/// Callback type for notifications of load completion or failure.
/// </summary>
Expand Down Expand Up @@ -116,9 +143,19 @@ public bool TryStartLoad(ITargetable newOrigin, LoadDoneCallback partialLoaded,
aborted();
}
return false;
} else if (calculator != null && calculator.IsAlive) {
if (aborted != null) {
aborted();
}
return false;
} else {
// 2. Start background job
new Thread(() => ThreadStart(newOrigin, partialLoaded, fullyLoaded, aborted)).Start();
calculator = new Thread(
() => ThreadStart(newOrigin, partialLoaded, fullyLoaded, aborted)
) {
Name = "Astrogator transfer calculator"
};
calculator.Start();
return true;
}
} else {
Expand Down Expand Up @@ -203,6 +240,8 @@ private void StopBurnTimePolling()
timer.Stop();
timer.Dispose();
timer = null;
} else {
DbgFmt("Timer not running");
}
}

Expand Down
40 changes: 29 additions & 11 deletions src/AstrogationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ public AstrogationView(AstrogationModel m, ResetCallback reset, UnityAction clos
resetCallback = reset;
closeCallback = close;

if (!ErrorCondition) {
createHeaders();
createRows();
}
AddChild(new DialogGUIHorizontalLayout(
RowWidth, 10,
0, wrenchPadding,
TextAnchor.UpperRight,
new DialogGUILabel(getMessage, notificationStyle, true, true),
iconButton(settingsIcon, settingsStyle, "Settings", toggleSettingsVisible)
));
if (Settings.Instance.ShowSettings) {
AddChild(new SettingsView(resetCallback));
} else if (!ErrorCondition) {
createHeaders();
createRows();
AddChild(new DialogGUIHorizontalLayout(
RowWidth, 10,
0, wrenchPadding,
TextAnchor.UpperRight,
new DialogGUILabel(getMessage, notificationStyle, true, true)
));
}
}

Expand Down Expand Up @@ -260,6 +258,16 @@ private UISkinDef skinToUse {
}
}

private UIStyle settingsToggleStyle {
get {
if (Settings.Instance.ShowSettings) {
return backStyle;
} else {
return settingsStyle;
}
}
}

/// <summary>
/// Launch a PopupDialog containing the view.
/// Use Dismiss() to get rid of it.
Expand Down Expand Up @@ -289,6 +297,16 @@ public PopupDialog Show()
closeStyle,
closeCallback
);

// Add the settings button next to the close button.
// If the settings are visible it's a back '<' icon, otherwise a wrench+screwdriver.
AddFloatingButton(
dialog.transform,
-mainWindowPadding.right - 3 * mainWindowSpacing - buttonIconWidth,
-mainWindowPadding.top,
settingsToggleStyle,
toggleSettingsVisible
);
}
return dialog;
}
Expand Down
15 changes: 14 additions & 1 deletion src/Astrogator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Astrogator : MonoBehavior {
public Astrogator()
: base()
{
model = new AstrogationModel();
model = new AstrogationModel();
loader = new AstrogationLoadBehaviorette(model, ResetViewBackground);
}

Expand Down Expand Up @@ -86,6 +86,15 @@ public void OnDisable()
// Save the persistent attributes to our settings file
Settings.Instance.Save();

if (loader != null) {
// Tell the loader we don't need data anymore;
// prevents new threads from starting
loader.OnDisplayClosed();

// Clean up the timer and thread
loader.Dispose();
}

// The "dead" copy of our object will re-add itself if we don't unsubscribe to this!
GameEvents.onGUIApplicationLauncherReady.Remove(AddLauncher);

Expand Down Expand Up @@ -242,6 +251,10 @@ private void HideMainWindow(bool userInitiated)
if (userInitiated) {
// If we close the window because we're exiting, don't set the setting.
Settings.Instance.MainWindowVisible = false;

// Now that the transfers and the settings are separate,
// it doesn't make sense to still show the settings if they click the X.
Settings.Instance.ShowSettings = false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.6.1.0")]
[assembly: AssemblyFileVersion("0.6.1.0")]
[assembly: AssemblyVersion("0.6.2.0")]
[assembly: AssemblyFileVersion("0.6.2.0")]
2 changes: 1 addition & 1 deletion src/SettingsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SettingsView : DialogGUIVerticalLayout {
public SettingsView(AstrogationView.ResetCallback reset)
: base(
mainWindowMinWidth, 10,
mainWindowSpacing, settingsPadding,
settingsSpacing, settingsPadding,
TextAnchor.UpperLeft
)
{
Expand Down
42 changes: 42 additions & 0 deletions src/ViewTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,43 @@ public static Sprite SolidColorSprite(Color c)
alignment = TextAnchor.UpperRight,
};

/// <summary>
/// Icon for the normal state of the back button.
/// </summary>
public static Sprite backIcon = GetSprite(FilePath("back"));

/// <summary>
/// Icon for the normal state of the back button.
/// </summary>
public static UIStyleState backStyleState = new UIStyleState() {
background = backIcon,
textColor = Color.black
};

/// <summary>
/// Icon for the hovered state of the back button.
/// </summary>
public static Sprite backHoverIcon = GetSprite(FilePath("backHover"));

/// <summary>
/// Icon for the hovered state of the back button.
/// </summary>
public static UIStyleState backHoverStyleState = new UIStyleState() {
background = backHoverIcon,
textColor = Color.black
};

/// <value>
/// Normal/highlight icons for the back button.
/// </value>
public static UIStyle backStyle = new UIStyle() {
normal = backStyleState,
highlight = backHoverStyleState,
active = backHoverStyleState,
disabled = backStyleState,
alignment = TextAnchor.UpperRight,
};

/// <value>
/// Icon for normal state of maneuver node creation button.
/// </value>
Expand Down Expand Up @@ -795,6 +832,11 @@ public class ColumnDefinition {
/// </summary>
public static RectOffset settingsPadding = new RectOffset(0, 0, 0, 0);

/// <summary>
/// Pixels between elements of the settings
/// </summary>
public const int settingsSpacing = 2;

/// <summary>
/// Window-relative coordinate of the spot that stays fixed in place when the size changes.
/// This choice is equivalent to UpperCenter anchoring.
Expand Down

0 comments on commit dd1f9c3

Please sign in to comment.