Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Displayed information revison
Browse files Browse the repository at this point in the history
  • Loading branch information
jarosm committed Sep 29, 2017
1 parent fd3ff3f commit f6f3e9f
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 46 deletions.
28 changes: 20 additions & 8 deletions BonVoyage/ActiveRover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BonVoyage
{
public class ActiveRover {
public string status;
public string status2;
public double toTravel;

public Vessel vessel;
Expand Down Expand Up @@ -77,7 +78,9 @@ public ActiveRover(Vessel v, ConfigNode module) {
/// Update rover.
/// </summary>
/// <param name="currentTime">Current time.</param>
public void Update(double currentTime) {
public void Update(double currentTime)
{
status2 = "";
if (vessel.isActiveVessel)
{
status = "current";
Expand All @@ -97,13 +100,22 @@ public void Update(double currentTime) {

// Speed penalties at twighlight and at night
if (angle > 90 && isManned)
speedMultiplier = 0.25;
else if (angle > 85 && isManned)
speedMultiplier = 0.5;
else if (angle > 80 && isManned)
speedMultiplier = 0.75;
else
speedMultiplier = 1.0;
{
speedMultiplier = 0.25;
status2 = " (night)";
}
else if (angle > 85 && isManned)
{
speedMultiplier = 0.5;
status2 = " (twilight)";
}
else if (angle > 80 && isManned)
{
speedMultiplier = 0.75;
status2 = " (twilight)";
}
else
speedMultiplier = 1.0;

// No moving at night, or when there's not enougth solar light for solar powered rovers
//if (angle > 90 && solarPowered)
Expand Down
116 changes: 88 additions & 28 deletions BonVoyage/BonVoyage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ public class BonVoyage : MonoBehaviour
private bool useToolbar;
private bool guiVisible;
private bool rcVisible;
private bool globalHidden;
private bool tooltipVisible;
private bool globalHidden;
private Rect guiRect;
private int guiId;
Vector2 mainWindowScrollPosition;
private Rect rcRect;
private int rcGuiId;
private int tooltipId;
private string tooltip;
private string tooltipTitle;
private Vector2 tooltipPosition;

/// <summary>
/// Instead of constructor.
Expand All @@ -74,12 +79,17 @@ public void Awake()
toolbarButton = null;
guiVisible = false;
rcVisible = false;
globalHidden = false;
tooltipVisible = false;
tooltip = "";
tooltipTitle = "";
tooltipPosition = new Vector2(Screen.width / 2, Screen.height / 2);
globalHidden = false;
gamePaused = false;

guiId = GUIUtility.GetControlID(FocusType.Passive);
rcGuiId = GUIUtility.GetControlID (FocusType.Passive);
config = PluginConfiguration.CreateForType<BonVoyage>();
tooltipId = GUIUtility.GetControlID(FocusType.Passive);
config = PluginConfiguration.CreateForType<BonVoyage>();
config.load();
autoDewarp = config.GetValue<bool>("autoDewarp", false);

Expand All @@ -92,7 +102,7 @@ public void Awake()
sample.center = new Vector2(Screen.width / 2, Screen.height / 2);
guiRect = config.GetValue<Rect>("guiRect", new Rect(sample));
sample.width = 400;
sample.height = 500;
sample.height = 300;
sample.center = new Vector2(Screen.width / 2, Screen.height / 2);
rcRect = config.GetValue<Rect> ("rcRect", new Rect(sample));
useKSPSkin = config.GetValue<bool> ("useKSPSkin", false);
Expand Down Expand Up @@ -335,6 +345,11 @@ public void OnGUI()
DrawRcGUI,
"Bon Voyage control"
);

if (tooltipVisible)
{
Layout.Window(tooltipId, new Rect(tooltipPosition, new Vector2(400, 50)), DrawTooltip, tooltipTitle);
}
}
}

Expand All @@ -354,11 +369,21 @@ public void onToggle()
}


/// <summary>
/// Draws main UI
/// </summary>
/// <param name="guiId">GUI identifier.</param>
public void DrawGUI(int guiId)
public void DrawTooltip(int guiID)
{
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
Layout.Label(tooltip);
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}


/// <summary>
/// Draws main UI
/// </summary>
/// <param name="guiId">GUI identifier.</param>
public void DrawGUI(int guiId)
{
double currentTime = Planetarium.GetUniversalTime();
GUILayout.BeginVertical();
Expand Down Expand Up @@ -399,7 +424,7 @@ public void DrawGUI(int guiId)
}

Layout.Label (rover.vessel.mainBody.bodyDisplayName.Replace("^N", ""), GUILayout.Width(75));
Layout.Label (rover.status, GUILayout.Width (125));
Layout.Label (rover.status + (rover.status == "roving" ? rover.status2 : ""), GUILayout.Width (125));

if (rover.status == "roving" || rover.status == "awaiting sunlight") {
Layout.Label (
Expand Down Expand Up @@ -468,15 +493,16 @@ public void DrawRcGUI(int rcGuiId) {
}
double currentTime = Planetarium.GetUniversalTime();
GUILayout.BeginVertical ();
TimeSpan t = TimeSpan.FromSeconds (currentTime - currentModule.lastTime);
Layout.Label (
string.Format (
"Idle for {0:D2}h:{1:D2}m:{2:D2}s",
t.Hours,
t.Minutes,
t.Seconds
)
);

//TimeSpan t = TimeSpan.FromSeconds (currentTime - currentModule.lastTime);
//Layout.Label (
// string.Format (
// "Idle for {0:D2}h:{1:D2}m:{2:D2}s",
// t.Hours,
// t.Minutes,
// t.Seconds
// )
//);

// If required power is greater ther total power generated, then average speed can be lowered up to 50%
double speedReduction = 0;
Expand All @@ -485,15 +511,49 @@ public void DrawRcGUI(int rcGuiId) {

Layout.LabelAndText ("Target latitude", currentModule.targetLatitude.ToString());
Layout.LabelAndText ("Target longitude", currentModule.targetLongitude.ToString());
Layout.LabelAndText ("Distance to target", currentModule.distanceToTarget.ToString("N0"));
Layout.LabelAndText ("Distance travelled", currentModule.distanceTravelled.ToString("N0"));
Layout.LabelAndText ("Average speed", currentModule.averageSpeed.ToString("F"));
Layout.LabelAndText ("Solar power", currentModule.solarPower.ToString("F"));
Layout.LabelAndText ("Other power", currentModule.otherPower.ToString("F"));
Layout.LabelAndText ("Power required", currentModule.powerRequired.ToString("F")
+ (speedReduction == 0 ? "" : (((speedReduction > 0) && (speedReduction <= 50)) ? " (Not enough power, average speed was reduced by " + speedReduction.ToString("F") + "%)" : "(Not enough power!)")));
Layout.LabelAndText ("Solar powered", currentModule.solarPowered.ToString ());
Layout.LabelAndText ("Is manned", currentModule.isManned.ToString ());

Layout.LabelAndText("Distance to target", (currentModule.distanceToTarget - currentModule.distanceTravelled).ToString("N0"));
//Layout.LabelAndText ("Distance to target", currentModule.distanceToTarget.ToString("N0"));
//Layout.LabelAndText ("Distance travelled", currentModule.distanceTravelled.ToString("N0"));

if (Layout.LabelTextAndButton("Average speed", currentModule.averageSpeed.ToString("F")))
{
tooltipVisible = !tooltipVisible;
tooltipTitle = "Average speed";
if (currentModule.averageSpeed > 0)
{
tooltip = "Average speed base: " + currentModule.maxSpeedBase.ToString("F") + "\n";
tooltip += "Online wheels modifier: " + currentModule.wheelsPercentualModifier.ToString() + "%\n";
if (currentModule.isManned)
tooltip += "Pilot/Scout bonus (adds to wheels modifier): " + currentModule.crewSpeedBonus.ToString() + "%\n";
else
tooltip += "Unmanned rover penalty: 80%";
if (speedReduction > 0)
tooltip += "Unsufficient power penalty: " + (speedReduction > 50 ? "100" : speedReduction.ToString("F")) + "%\n";
tooltip += "Speed at night: " + currentModule.averageSpeedAtNight.ToString("F");
}
else
tooltip = "Wheels aren't online";
tooltipPosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y + 10);
}

if (Layout.LabelTextAndButton("Generated power", (currentModule.solarPower + currentModule.otherPower).ToString("F")))
{
tooltipVisible = !tooltipVisible;
tooltipTitle = "Generated power";
tooltip = "Solar power: " + currentModule.solarPower.ToString("F") + "\n";
tooltip += "Generators and reactors: " + currentModule.otherPower.ToString("F");
tooltipPosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y + 10);
}

//Layout.LabelAndText ("Solar power", currentModule.solarPower.ToString("F"));
//Layout.LabelAndText ("Other power", currentModule.otherPower.ToString("F"));

Layout.LabelAndText("Required power", currentModule.powerRequired.ToString("F")
+ (speedReduction == 0 ? "" : (((speedReduction > 0) && (speedReduction <= 50)) ? " (Not enough power, average speed was reduced by " + speedReduction.ToString("F") + "%)" : " (Not enough power!)")));

//Layout.LabelAndText ("Solar powered", currentModule.solarPowered.ToString ());
//Layout.LabelAndText ("Is manned", currentModule.isManned.ToString ());

if (Layout.Button ("Pick target on map", Palette.yellow)) {
currentModule.PickTarget ();
Expand Down
15 changes: 12 additions & 3 deletions BonVoyage/BonVoyageModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public WheelTestResult(double powerRequired, double maxSpeedSum, int inTheAir, i
public double otherPower;
public double powerRequired;

public WheelTestResult testResult = new WheelTestResult();
public double maxSpeedBase;
public int wheelsPercentualModifier;
public int crewSpeedBonus;

public WheelTestResult testResult = new WheelTestResult();

public void SystemCheck() {
// Test stock wheels
Expand Down Expand Up @@ -104,7 +108,7 @@ public void SystemCheck() {
this.isManned = (this.vessel.GetCrewCount() > 0);

// Pilots and Scouts (USI) increase base average speed
int crewSpeedBonus = 0;
crewSpeedBonus = 0;
if (this.isManned)
{
int maxPilotLevel = -1;
Expand Down Expand Up @@ -132,7 +136,12 @@ public void SystemCheck() {
// Average speed will vary depending on number of wheels online and crew present from 50 to 95 percent
// of average wheels' max speed
if (testResult.online != 0)
averageSpeed = testResult.maxSpeedSum / testResult.online / 100 * (Math.Min(70, (40 + 5 * testResult.online)) + crewSpeedBonus);
{
maxSpeedBase = testResult.maxSpeedSum / testResult.online;
wheelsPercentualModifier = Math.Min(70, (40 + 5 * testResult.online));
averageSpeed = maxSpeedBase / 100 * (wheelsPercentualModifier + crewSpeedBonus);
//averageSpeed = testResult.maxSpeedSum / testResult.online / 100 * (Math.Min(70, (40 + 5 * testResult.online)) + crewSpeedBonus);
}
else
averageSpeed = 0;

Expand Down
2 changes: 1 addition & 1 deletion BonVoyage/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("0.13.0.5")]
[assembly: AssemblyVersion("0.13.1.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
31 changes: 25 additions & 6 deletions BonVoyage/UIFramework/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,32 @@ public static void LabelAndText(string label, string text) {
Label (label + ": ", Palette.blue);
Label (text, Color.white);
GUILayout.EndHorizontal ();
}
}

/// <summary>
/// Margin with the specified width.
/// </summary>
/// <param name="width">Width.</param>
public static void Margin(int width) {
/// <summary>
/// Creates label with "label: text" with different colors and button in one line
/// </summary>
/// <param name="label">Label.</param>
/// <param name="text">Text.</param>
public static bool LabelTextAndButton(string label, string text)
{
GUILayout.BeginHorizontal();
Label(label + ": ", Palette.blue);
Label(text, Color.white);
Styles.button.normal.textColor = Palette.yellow;
Styles.button.alignment = TextAnchor.MiddleCenter;
Styles.button.fixedWidth = 20;
bool res = GUILayout.Button("?", Styles.button);
Styles.button.fixedWidth = 0;
GUILayout.EndHorizontal();
return res;
}

/// <summary>
/// Margin with the specified width.
/// </summary>
/// <param name="width">Width.</param>
public static void Margin(int width) {
GUILayout.Label ("", Styles.label, GUILayout.Width(width));
}

Expand Down

0 comments on commit f6f3e9f

Please sign in to comment.