Skip to content

Commit

Permalink
first round of code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GER-Space committed May 11, 2019
1 parent 8ad28c5 commit 559ed1d
Showing 1 changed file with 84 additions and 125 deletions.
209 changes: 84 additions & 125 deletions src/UI/BaseBossFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.IO;

namespace KerbalKonstructs.UI
{
class BaseBossFlight : KKWindow
internal class BaseBossFlight : KKWindow
{
private static BaseBossFlight _instance = null;
internal static BaseBossFlight instance
Expand All @@ -32,32 +30,29 @@ internal static BaseBossFlight instance
public Texture tIconOpen = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/siteopen", false);
public Texture tToggle = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/siteopen", false);
public Texture tToggle2 = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/siteopen", false);

Rect managerRect = new Rect(10, 25, 320, 520);
Rect facilityRect = new Rect(150, 75, 420, 640);
Rect targetSelectorRect = new Rect(450, 150, 270, 570);
Rect downlickRect = new Rect(300, 50, 160, 370);
private Rect managerRect = new Rect(10, 25, 320, 520);
private Rect facilityRect = new Rect(150, 75, 420, 640);
private Rect targetSelectorRect = new Rect(450, 150, 270, 570);
private Rect downlickRect = new Rect(300, 50, 160, 370);

public float iFundsOpen2 = 0f;

public Boolean managingFacility = false;
public Boolean foundingBase = false;
public Boolean bIsOpen = false;
public bool managingFacility = false;
public bool foundingBase = false;
public bool bIsOpen = false;

public Boolean bShowFacilities = false;
public bool bShowFacilities = false;
private static List<StaticInstance> allFacilities = new List<StaticInstance>();

public static Boolean bChangeTarget = false;
public static bool bChangeTarget = false;

public static string sTargetType = "None";

Vector2 scrollPos;

GUIStyle KKWindow;
GUIStyle DeadButton;
GUIStyle DeadButtonRed;
GUIStyle BoxNoBorder;
GUIStyle LabelInfo;
private Vector2 scrollPos;
private GUIStyle KKWindow;
private GUIStyle DeadButton;
private GUIStyle DeadButtonRed;
private GUIStyle BoxNoBorder;
private GUIStyle LabelInfo;

internal string Base;
internal string Base2;
Expand Down Expand Up @@ -99,7 +94,7 @@ public override void Close()
base.Close();
}

void drawBaseManagerWindow(int windowID)
private void drawBaseManagerWindow(int windowID)
{

if (!isInitialized)
Expand Down Expand Up @@ -140,7 +135,7 @@ void drawBaseManagerWindow(int windowID)
{
GUILayout.Space(2);
GUILayout.Label("Landing Guide ", LabelInfo);
if (GUILayout.Button(LandingGuideUI.instance.IsOpen()? tIconOpen : tIconClosed, GUILayout.Height(18), GUILayout.Width(56)))
if (GUILayout.Button(LandingGuideUI.instance.IsOpen() ? tIconOpen : tIconClosed, GUILayout.Height(18), GUILayout.Width(56)))
{
KerbalKonstructs.instance.UpdateCache();
LandingGuideUI.instance.Toggle();
Expand Down Expand Up @@ -171,50 +166,10 @@ void drawBaseManagerWindow(int windowID)
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
GUILayout.Space(2);

GUILayout.Box("Active Beacons", BoxNoBorder);

if (MiscUtils.isCareerGame())
{
GUILayout.BeginHorizontal();
{
string snearestopen = "";
LaunchSiteManager.GetNearestOpenBase(FlightGlobals.ActiveVessel.GetTransform().position, out Base, out Range, out lNearest);
if (FlightGlobals.ActiveVessel.altitude > 75000)
{
GUILayout.Label("No base's beacon in range at this altitude.", LabelInfo);
}
else
if (Base == "")
{
GUILayout.Label("No open base found.", LabelInfo);
}
else
{
if (Range < 10000)
snearestopen = Base + " at " + Range.ToString("#0.0") + " m";
else
snearestopen = Base + " at " + (Range / 1000).ToString("#0.0") + " km";

GUILayout.Space(5);
GUILayout.Label("Nearest Open: ", LabelInfo);
GUILayout.Label(snearestopen, LabelInfo, GUILayout.Width(150));
GUILayout.Box("Selected Base", BoxNoBorder);

if (NavGuidanceSystem.instance.IsOpen())
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("NGS", GUILayout.Height(21)))
{
NavGuidanceSystem.setTargetSite(lNearest);
smessage = "NGS set to " + Base;
MiscUtils.HUDMessage(smessage, 10, 2);
}
}
}
}
GUILayout.EndHorizontal();
GUILayout.Space(2);

GUILayout.Space(2);
}

GUILayout.BeginHorizontal();
{
Expand All @@ -233,9 +188,13 @@ void drawBaseManagerWindow(int windowID)
else
{
if (Range < 10000)
{
sNearestbase = Base + " at " + Range.ToString("#0.0") + " m";
}
else
{
sNearestbase = Base + " at " + (Range / 1000).ToString("#0.0") + " km";
}

GUILayout.Space(5);
GUILayout.Label("Nearest Base: ", LabelInfo);
Expand Down Expand Up @@ -263,14 +222,14 @@ void drawBaseManagerWindow(int windowID)

if (MiscUtils.isCareerGame())
{
bool bLanded = (FlightGlobals.ActiveVessel.Landed);


if (Range < 2000)
if (Range < 5000)
{
LaunchSiteManager.getSiteOpenCloseState(Base, out sClosed, out fOpenCost);
fOpenCost = fOpenCost / 2f;

if (bLanded && sClosed == "Closed")
if (FlightGlobals.ActiveVessel.Landed && sClosed == "Closed")
{
GUILayout.Space(2);
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
Expand All @@ -293,14 +252,14 @@ void drawBaseManagerWindow(int windowID)
}
}

if (bLanded && sClosed == "Open")
if (FlightGlobals.ActiveVessel.Landed && sClosed == "Open")
{
GUI.enabled = false;
GUILayout.Button("Base is Open", GUILayout.Height(23));
GUI.enabled = true;
}

if (bLanded && (sClosed == "OpenLocked" || sClosed == "ClosedLocked"))
if (FlightGlobals.ActiveVessel.Landed && (sClosed == "OpenLocked" || sClosed == "ClosedLocked"))
{
GUI.enabled = false;
GUILayout.Button("Base cannot be opened or closed", GUILayout.Height(23));
Expand All @@ -313,7 +272,7 @@ void drawBaseManagerWindow(int windowID)
}
else
{
GUILayout.Label("Bases can only be opened or closed at the base when within 2km of the base.", LabelInfo);
GUILayout.Label("Bases can only be opened or closed at the base when within 5km of the base.", LabelInfo);
}

//if (Range > 100000)
Expand Down Expand Up @@ -344,81 +303,74 @@ void drawBaseManagerWindow(int windowID)
GUILayout.Space(2);
GUILayout.Box("Operational Facilities", BoxNoBorder);

bool bAreFacilities = false;

if (FlightGlobals.ActiveVessel.Landed)
{
if (GUILayout.Button("Show/Hide", GUILayout.Height(23)))
{
if (bShowFacilities)
{
bShowFacilities = false;
}
else
{
CacheFacilities();
bShowFacilities = true;
}
}
if (bShowFacilities && allFacilities.Count == 0)
{
GUILayout.Label("No facilities within 5000m", LabelInfo);
}


if (bShowFacilities && allFacilities.Count > 0)
{
scrollPos = GUILayout.BeginScrollView(scrollPos);

for (int i = 0; i < allFacilities.Count; i++)
{
bAreFacilities = true;
GUILayout.BeginHorizontal();
for (int i = 0; i < allFacilities.Count; i++)
{
bIsOpen = allFacilities[i].myFacilities[0].isOpen;

if (!bIsOpen)
GUILayout.BeginHorizontal();
{
iFundsOpen2 = allFacilities[i].myFacilities[0].OpenCost;
if (iFundsOpen2 == 0) bIsOpen = true;
bIsOpen = allFacilities[i].myFacilities[0].isOpen;

if (!bIsOpen)
{
iFundsOpen2 = allFacilities[i].myFacilities[0].OpenCost;
if (iFundsOpen2 == 0)
{
bIsOpen = true;
}
}

if (GUILayout.Button(allFacilities[i].model.title, GUILayout.Height(23)))
{
selectedObject = allFacilities[i];
KerbalKonstructs.SelectInstance(allFacilities[i], false);
FacilityManager.selectedInstance = allFacilities[i];
FacilityManager.instance.Open();
}

if (bIsOpen)
{
GUILayout.Label(tIconOpen, GUILayout.Height(23), GUILayout.Width(23));
}

if (!bIsOpen)
{
GUILayout.Label(tIconClosed, GUILayout.Height(23), GUILayout.Width(23));
}
}
GUILayout.EndHorizontal();

if (GUILayout.Button(allFacilities[i].model.title, GUILayout.Height(23)))
{
selectedObject = allFacilities[i];
KerbalKonstructs.SelectInstance(allFacilities[i], false);
FacilityManager.selectedInstance = allFacilities[i];
FacilityManager.instance.Open();
}

if (bIsOpen)
GUILayout.Label(tIconOpen, GUILayout.Height(23), GUILayout.Width(23));

if (!bIsOpen)
GUILayout.Label(tIconClosed, GUILayout.Height(23), GUILayout.Width(23));
}
GUILayout.EndHorizontal();

}
GUILayout.EndScrollView();
}
else
{
GUILayout.Label("Click the button above to display a list of nearby operational facilities.", LabelInfo);

if (KerbalKonstructs.instance.debugMode)
{
GUILayout.Box("Debug Mode ActiveVessel Report");
GUILayout.Label("Name " + FlightGlobals.ActiveVessel.vesselName);
GUILayout.Label("Acceleration " + FlightGlobals.ActiveVessel.acceleration.ToString());
GUILayout.Label("Angular Momentum " + FlightGlobals.ActiveVessel.angularMomentum.ToString("#0.000"));
GUILayout.Label("Angular Velocity " + FlightGlobals.ActiveVessel.angularVelocity.ToString("#0.000"));
//GUILayout.Label("Centrifugal Acc " + FlightGlobals.ActiveVessel.CentrifugalAcc.ToString());
GUILayout.Label("Horiz Srf Speed " + FlightGlobals.ActiveVessel.horizontalSrfSpeed.ToString("#0.00"));
GUILayout.Label("Indicated Air Speed " + FlightGlobals.ActiveVessel.indicatedAirSpeed.ToString("#0.00"));
GUILayout.Label("Mach " + FlightGlobals.ActiveVessel.mach.ToString("#0.00"));
GUILayout.Label("Orbit Speed " + FlightGlobals.ActiveVessel.obt_speed.ToString("#0.00"));
GUILayout.Label("Orbit Velocity " + FlightGlobals.ActiveVessel.obt_velocity.ToString());
GUILayout.Label("Perturbation " + FlightGlobals.ActiveVessel.perturbation.ToString());
GUILayout.Label("rb_velocity " + FlightGlobals.ActiveVessel.rb_velocity.ToString("#0.000"));
GUILayout.Label("Specific Acc " + FlightGlobals.ActiveVessel.specificAcceleration.ToString("#0.00"));
GUILayout.Label("speed " + FlightGlobals.ActiveVessel.speed.ToString("#0.00"));
GUILayout.Label("srf_velocity " + FlightGlobals.ActiveVessel.srf_velocity.ToString());
GUILayout.Label("srfspeed " + FlightGlobals.ActiveVessel.srfSpeed.ToString("#0.00"));
}
}
}
else
Expand All @@ -427,11 +379,6 @@ void drawBaseManagerWindow(int windowID)
bShowFacilities = false;
}

if (bAreFacilities == false)
{
//GUILayout.Label("There are no nearby operational facilities.", LabelInfo);
}

GUILayout.FlexibleSpace();
GUILayout.Space(2);
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
Expand Down Expand Up @@ -510,28 +457,40 @@ private void InitializeLayout()
private void CacheFacilities()
{

StaticInstance [] allStatics = StaticDatabase.allStaticInstances;
StaticInstance[] allStatics = StaticDatabase.allStaticInstances;
allFacilities = new List<StaticInstance>();

for (int i = 0; i < allStatics.Length; i++)
{
// No facility assigned
if (!allStatics[i].hasFacilities)
{
continue;
}
//not anywhere here
if (!allStatics[i].isActive)
{
continue;
}
if (allStatics[i].myFacilities.Count == 0)
{
continue;
}
// Facility is more than 5000m away
if (Vector3.Distance(FlightGlobals.ActiveVessel.GetTransform().position, allStatics[i].position) > 5000f)
{
continue;
}
// is not a facility
if (String.Equals(allStatics[i].FacilityType, "None", StringComparison.CurrentCultureIgnoreCase))
continue;
if (allStatics[i].myFacilities.Count == 0)
if (string.Equals(allStatics[i].FacilityType, "None", StringComparison.CurrentCultureIgnoreCase))
{
continue;
}

allFacilities.Add(allStatics[i]);
}
}


}
}

0 comments on commit 559ed1d

Please sign in to comment.