Skip to content

Commit

Permalink
Merge 2.7.4.0 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
TriggerAu committed Jan 3, 2016
2 parents effef1a + ec34623 commit 505b3b7
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 74 deletions.
139 changes: 81 additions & 58 deletions AlternateResourcePanel/ARP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private KSPAlternateResourcePanel()

public Dictionary<Int32, ARPResourceList> lstResourcesVesselPerStage;

private const double baseRange = 2000;

/// <summary>
/// ResourceIDs of ones to show in window
Expand Down Expand Up @@ -503,8 +504,16 @@ internal override void RepeatingWorker()
)
SetAppButtonToTrue();

Vessel active = FlightGlobals.ActiveVessel;
LastStage = GetLastStage(active.parts);
List<Vessel> vessels;
if (settings.ShowBase)
{
var currentPosition = FlightGlobals.ActiveVessel.GetWorldPos3D();
vessels = FlightGlobals.Vessels.Where(v => v.mainBody == FlightGlobals.ActiveVessel.mainBody && Vector3d.Distance(currentPosition, v.GetWorldPos3D()) < baseRange).ToList();
}
else
{
vessels = new List<Vessel> { FlightGlobals.ActiveVessel };
}

Double RatePeriod = RepeatingWorkerUTPeriod;
if (!settings.RatesUseUT) RatePeriod = RepeatingWorkerUTPeriod / TimeWarp.CurrentRate;
Expand Down Expand Up @@ -532,80 +541,94 @@ internal override void RepeatingWorker()
//set the controllable flag
blnVesselIsControllable = false;

//Now loop through and update em
foreach (Part p in active.parts)
//Now loop through the vessels
foreach (Vessel active in vessels)
{
//Check each part for a control module to see if its status is Good
foreach (ModuleCommand mc in p.Modules.OfType<ModuleCommand>())
{
if (mc.State == ModuleCommand.ControlSourceState.Good)
blnVesselIsControllable = true;
}
LastStage = GetLastStage(active.parts);

//is the part decoupled in the last stage
Boolean DecoupledInLastStage = (p.DecoupledAt()==LastStage);

foreach (PartResource pr in p.Resources)
//Now loop through and update em
foreach (Part p in active.parts)
{
//store a list of all resources in vessel so we can nuke resources from the other lists later
if (!lstVesselResourceIDs.Contains(pr.info.id)) lstVesselResourceIDs.Add(pr.info.id);
//Check each part for a control module to see if its status is Good
foreach (ModuleCommand mc in p.Modules.OfType<ModuleCommand>())
{
if (mc.State == ModuleCommand.ControlSourceState.Good && active == FlightGlobals.ActiveVessel)
blnVesselIsControllable = true;
}

//Is this resource set to split on disabled parts instead of staging
if ((PartResourceLibrary.Instance.resourceDefinitions[pr.info.id].resourceFlowMode == ResourceFlowMode.ALL_VESSEL ||
PartResourceLibrary.Instance.resourceDefinitions[pr.info.id].resourceFlowMode == ResourceFlowMode.STAGE_PRIORITY_FLOW) &&
settings.Resources[pr.info.id].ShowReserveLevels)
//is the part decoupled in the last stage
Boolean DecoupledInLastStage = (p.DecoupledAt() == LastStage);

foreach (PartResource pr in p.Resources)
{
if (pr.flowState) {
//store a list of all resources in vessel so we can nuke resources from the other lists later
if (!lstVesselResourceIDs.Contains(pr.info.id)) lstVesselResourceIDs.Add(pr.info.id);

//Is this resource set to split on disabled parts instead of staging
if ((PartResourceLibrary.Instance.resourceDefinitions[pr.info.id].resourceFlowMode == ResourceFlowMode.ALL_VESSEL ||
PartResourceLibrary.Instance.resourceDefinitions[pr.info.id].resourceFlowMode == ResourceFlowMode.STAGE_PRIORITY_FLOW) &&
settings.Resources[pr.info.id].ShowReserveLevels)
{
if (pr.flowState)
{
//update the resource in the vessel list
lstResourcesVessel.UpdateResource(pr);//,InitialSettings:settings.Resources[pr.info.id]);

//if it dont exist in the last stage list - add a 0 value
if (!settings.ShowBase && !lstResourcesLastStage.ContainsKey(pr.info.id))
{
LogFormatted_DebugOnly("Adding 0 value into last stage");
PartResource prTemp = new PartResource() { info = pr.info, amount = 0, maxAmount = 0 };
lstResourcesLastStage.UpdateResource(prTemp);
}
}
else
{
if (!settings.ShowBase)
{
//and if it needs to go in the last stage list
lstResourcesLastStage.UpdateResource(pr);
}
}
}
else
{
//update the resource in the vessel list
lstResourcesVessel.UpdateResource(pr);//,InitialSettings:settings.Resources[pr.info.id]);
//if it dont exist in the last stage list - add a 0 value
if (!lstResourcesLastStage.ContainsKey(pr.info.id))

//and if it needs to go in the last stage list
if (DecoupledInLastStage && !settings.ShowBase)
{
LogFormatted_DebugOnly("Adding 0 value into last stage");
PartResource prTemp = new PartResource() { info = pr.info, amount = 0, maxAmount = 0 };
lstResourcesLastStage.UpdateResource(prTemp);
lstResourcesLastStage.UpdateResource(pr);
}
} else {
//and if it needs to go in the last stage list
lstResourcesLastStage.UpdateResource(pr);
}
}
else {
//update the resource in the vessel list
lstResourcesVessel.UpdateResource(pr);//,InitialSettings:settings.Resources[pr.info.id]);

//and if it needs to go in the last stage list
if (DecoupledInLastStage)
//Update the whole vessel list
lstResourcesVesselPerStage[p.DecoupledAt().Clamp(1, Staging.StageCount)].UpdateResource(pr);

//is the resource in the selected list
if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].AllVisible && !settings.Resources[pr.info.id].ShowReserveLevels)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].LastStageVisible && DecoupledInLastStage && !settings.Resources[pr.info.id].ShowReserveLevels)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].AllVisible && settings.Resources[pr.info.id].ShowReserveLevels && pr.flowState)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].LastStageVisible && settings.Resources[pr.info.id].ShowReserveLevels && !pr.flowState)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (lstPartWindows.ContainsKey(p.GetInstanceID()))
{
lstResourcesLastStage.UpdateResource(pr);
//or not,but the window is in the list
if (lstPartWindows[p.GetInstanceID()].ResourceList.ContainsKey(pr.info.id))
lstPartWindows[p.GetInstanceID()].ResourceList.Remove(pr.info.id);
}
}

//Update the whole vessel list
lstResourcesVesselPerStage[p.DecoupledAt().Clamp(1,Staging.StageCount)].UpdateResource(pr);

//is the resource in the selected list
if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].AllVisible && !settings.Resources[pr.info.id].ShowReserveLevels)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].LastStageVisible && DecoupledInLastStage && !settings.Resources[pr.info.id].ShowReserveLevels)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].AllVisible && settings.Resources[pr.info.id].ShowReserveLevels && pr.flowState)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].LastStageVisible && settings.Resources[pr.info.id].ShowReserveLevels && !pr.flowState)
lstPartWindows.AddPartWindow(p, pr, this, RatePeriod);
else if (lstPartWindows.ContainsKey(p.GetInstanceID()))
if (!settings.ShowBase && DecoupledInLastStage && (p.Modules.OfType<ModuleEngines>().Any() || p.Modules.OfType<ModuleEnginesFX>().Any()))
{
//or not,but the window is in the list
if (lstPartWindows[p.GetInstanceID()].ResourceList.ContainsKey(pr.info.id))
lstPartWindows[p.GetInstanceID()].ResourceList.Remove(pr.info.id);
//Add the part to the engines list for the active stage
lstPartsLastStageEngines.Add(p);
}
}

if(DecoupledInLastStage && (p.Modules.OfType<ModuleEngines>().Any() || p.Modules.OfType<ModuleEnginesFX>().Any()))
{
//Add the part to the engines list for the active stage
lstPartsLastStageEngines.Add(p);
}

}
Expand Down
46 changes: 34 additions & 12 deletions AlternateResourcePanel/ARPWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ internal override void DrawWindow(Int32 id)
Boolean Highlight = SelectedResources.ContainsKey(ResourceID) && SelectedResources[ResourceID].AllVisible;

//For resources with no stage specifics - or the Resources is set to split display and values are different for all vessel and flow enabled ones
if (!settings.SplitLastStage || !lstResources[ResourceID].ResourceConfig.SplitLastStage ||
if (!settings.SplitLastStage || !lstResources[ResourceID].ResourceConfig.SplitLastStage || settings.ShowBase ||
(lstResources[ResourceID].ResourceDef.resourceFlowMode == ResourceFlowMode.ALL_VESSEL ||
lstResources[ResourceID].ResourceDef.resourceFlowMode == ResourceFlowMode.STAGE_PRIORITY_FLOW) &&
(( !settings.Resources[ResourceID].ShowReserveLevels )
Expand Down Expand Up @@ -207,11 +207,13 @@ internal override void DrawWindow(Int32 id)
if (mbARP.blnVesselIsControllable) {
if (GUILayout.Button("Activate Stage", "ButtonGeneral", GUILayout.Width(100)))
Staging.ActivateNextStage();
GUILayout.Space(51 + IconAlarmOffset);
GUILayout.Space(21 + IconAlarmOffset);
//GUILayout.Space(51 + IconAlarmOffset);
}
else {
GUILayout.Label("No Vessel Control", GUILayout.Width(120));
GUILayout.Space(31 + IconAlarmOffset);
GUILayout.Space(1 + IconAlarmOffset);
//GUILayout.Space(31 + IconAlarmOffset);
}
}
//GUILayout.Space(48 + IconAlarmOffset);
Expand Down Expand Up @@ -246,28 +248,48 @@ internal override void DrawWindow(Int32 id)
GUIStyle StatusStyle = new GUIStyle(SkinsLibrary.CurrentSkin.label) ;
StatusStyle.normal.textColor = mbARP.AutoStagingStatusColor;
//GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(147 + IconAlarmOffset));
//GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(120 + IconAlarmOffset));
GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(150 + IconAlarmOffset));
GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(120 + IconAlarmOffset));
//GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(150 + IconAlarmOffset));
}
}
else
{
//GUILayout.Space(234 + IconAlarmOffset);
//GUILayout.Space(207 + IconAlarmOffset);
GUILayout.Space(237 + IconAlarmOffset);
GUILayout.Space(207 + IconAlarmOffset);
//GUILayout.Space(237 + IconAlarmOffset);
}

// ShowAll Button
if (GUILayout.Button(new GUIContent(Resources.btnViewTimes, "Toggle Time Remaining"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
// ShowBase Button
Boolean blnShowBase = settings.ShowBase;
if (DrawToggle(ref blnShowBase, new GUIContent(Resources.btnViewBaseActive, blnShowBase ? "Back to Vessel Display" : "Show Base Display\r\nAll resource within 2km of active vessel"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
{
settings.ShowTimeRem = !settings.ShowTimeRem;
settings.ShowBase = blnShowBase;
}
//if (GUILayout.Button(new GUIContent(settings.ShowBase ? Resources.btnViewBaseActive : Resources.btnViewBase, "Toggle Vessel/Base Display"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
//{
// settings.ShowBase = !settings.ShowBase;
//}

// ShowTime Button
Boolean blnShowTimeRem = settings.ShowTimeRem;
if (DrawToggle(ref blnShowTimeRem, new GUIContent(Resources.btnViewTimes, blnShowTimeRem ? "Hide time Remianing": "Show Time Remaining"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin,"ButtonToggle").PaddingChange(1), GUILayout.Width(23))) {
settings.ShowTimeRem = blnShowTimeRem;
}
//if (GUILayout.Button(new GUIContent(Resources.btnViewTimes, "Toggle Time Remaining"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
//{
// settings.ShowTimeRem = !settings.ShowTimeRem;
//}

// ShowAll Button
if (GUILayout.Button(new GUIContent(Resources.btnViewAll, "Toggle Hidden Resources"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
Boolean blnToggleHidden = KSPAlternateResourcePanel.ShowAll;
if (DrawToggle(ref blnToggleHidden, new GUIContent(Resources.btnViewAll, "Toggle Hidden Resources"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
{
KSPAlternateResourcePanel.ShowAll = !KSPAlternateResourcePanel.ShowAll;
KSPAlternateResourcePanel.ShowAll = blnToggleHidden;
}
//if (GUILayout.Button(new GUIContent(Resources.btnViewAll, "Toggle Hidden Resources"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
//{
// KSPAlternateResourcePanel.ShowAll = !KSPAlternateResourcePanel.ShowAll;
//}

//Settings Toggle button
GUIContent btnMinMax = new GUIContent(Resources.btnChevronDown, "Show Settings...");
Expand Down
4 changes: 2 additions & 2 deletions AlternateResourcePanel/KSPAlternateResourcePanel.version
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"VERSION": {
"MAJOR": 2,
"MINOR": 7,
"PATCH": 3,
"PATCH": 4,
"BUILD": 0
},
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 0,
"PATCH": 4
"PATCH": 5
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
4 changes: 2 additions & 2 deletions AlternateResourcePanel/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.7.3.0")]
[assembly: AssemblyFileVersion("2.7.3.0")]
[assembly: AssemblyVersion("2.7.4.0")]
[assembly: AssemblyFileVersion("2.7.4.0")]
4 changes: 4 additions & 0 deletions AlternateResourcePanel/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal class Resources

internal static Texture2D btnViewAll = new Texture2D(16, 16, TextureFormat.ARGB32, false);
internal static Texture2D btnViewTimes = new Texture2D(16, 16, TextureFormat.ARGB32, false);
//internal static Texture2D btnViewBase = new Texture2D(16, 16, TextureFormat.ARGB32, false);
internal static Texture2D btnViewBaseActive = new Texture2D(16, 16, TextureFormat.ARGB32, false);

internal static Texture2D btnSettingsAttention = new Texture2D(17, 16, TextureFormat.ARGB32, false);

Expand Down Expand Up @@ -156,6 +158,8 @@ internal static void LoadTextures()

LoadImageFromFile(ref btnViewAll, "img_buttonEye.png");
LoadImageFromFile(ref btnViewTimes, "img_buttonClock.png");
//LoadImageFromFile(ref btnViewBase, "img_buttonBase.png");
LoadImageFromFile(ref btnViewBaseActive, "img_buttonBaseActive.png");

LoadImageFromFile(ref btnSettingsAttention, "img_buttonSettingsAttention.png");

Expand Down
1 change: 1 addition & 0 deletions AlternateResourcePanel/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal Settings(String FilePath) : base(FilePath) {

//[Persistent]
internal Boolean ShowTimeRem = false;
internal Boolean ShowBase = false;

[Persistent] internal Boolean SplitLastStage = true;
[Persistent] internal Boolean StageBarOnRight = true;
Expand Down
Loading

0 comments on commit 505b3b7

Please sign in to comment.