Skip to content

Commit

Permalink
Handle PAW Field Caching
Browse files Browse the repository at this point in the history
Fixes KSP-RO#255
KSP after 1.8 is cacheing more PAW fields.  In 1.10, the created event buttons hang around and don't get cleared by PAW creation, only by refresh.  Catch the PAW show event and request a refresh if one is requested.
Refactor UpdateUsedBy a little.  Every tank PartModule iterating over every vessel PartModule to build the UsedBy mapping may need analysis
  • Loading branch information
DRVeyl committed Mar 27, 2021
1 parent 5969985 commit 4da4928
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions Source/Tanks/ModuleFuelTanks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public UnmanagedResource(string name, double amount, double maxAmount)

bool compatible = true;
bool started;
private bool windowDirty = false;

public bool fueledByLaunchClamp = false;

Expand Down Expand Up @@ -385,6 +386,7 @@ public override void OnStart(StartState state)
GameEvents.onPartRemove.Add(onPartRemove);
GameEvents.onEditorShipModified.Add(onEditorShipModified);
GameEvents.onPartActionUIDismiss.Add(OnPartActionGuiDismiss);
GameEvents.onPartActionUIShown.Add(OnPartActionUIShown);

if (part.symmetryCounterparts.Count > 0) {
UpdateTankType(false);
Expand All @@ -409,6 +411,7 @@ void OnDestroy ()
GameEvents.onPartRemove.Remove (onPartRemove);
GameEvents.onEditorShipModified.Remove (onEditorShipModified);
GameEvents.onPartActionUIDismiss.Remove (OnPartActionGuiDismiss);
GameEvents.onPartActionUIShown.Remove(OnPartActionUIShown);
TankWindow.HideGUI();
}

Expand Down Expand Up @@ -485,6 +488,16 @@ private void onPartRemove (GameEvents.HostTargetAction<Part, Part> hostTarget)
}
}

private void OnPartActionUIShown(UIPartActionWindow window, Part p)
{
if (p == part && windowDirty)
{
windowDirty = false; // Un-flag state
window.displayDirty = true; // Signal refresh
//MonoUtilities.RefreshPartContextWindow(part);
}
}

private void OnPartActionGuiDismiss(Part p)
{
if (p == part)
Expand Down Expand Up @@ -1030,16 +1043,11 @@ internal void MarkWindowDirty ()
if (!started) {
return;
}
UIPartActionWindow action_window;
if (UIPartActionController.Instance == null) {
// no controller means no window to mark dirty
return;
}
action_window = UIPartActionController.Instance.GetItem(part);
if (action_window == null) {
return;
}
action_window.displayDirty = true;
if (UIPartActionController.Instance?.GetItem(part) is UIPartActionWindow paw)
paw.displayDirty = true;
else
windowDirty = true; // The PAW isn't open, so request refresh later
//MonoUtilities.RefreshPartContextWindow(part);
}


Expand Down Expand Up @@ -1078,27 +1086,19 @@ public void UpdateUsedBy ()
parts = vessel.parts;
else parts = new List<Part>();

FuelInfo f;
string title;
PartModule m;
for(int i = 0; i < parts.Count; ++i)
foreach(Part p in parts)
{
title = parts[i].partInfo.title;
for(int j = 0; j < parts[i].Modules.Count; ++j)
string title = p.partInfo.title;
for(int j = 0; j < p.Modules.Count; ++j)
{
m = parts[i].Modules[j];
FuelInfo f = null;
PartModule m = p.Modules[j];
if (m is ModuleEngines)
{
f = new FuelInfo((m as ModuleEngines).propellants, this, title);
if(f.ratioFactor > 0d)
UpdateFuelInfo(f, title);
}
else if (m is ModuleRCS)
{
f = new FuelInfo((m as ModuleRCS).propellants, this, title);
if (f.ratioFactor > 0d)
UpdateFuelInfo(f, title);
}
if (f?.ratioFactor > 0d)
UpdateFuelInfo(f, title);
}
}

Expand Down

0 comments on commit 4da4928

Please sign in to comment.