Skip to content

Commit

Permalink
Recalc build rates when needed (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav authored Jul 3, 2024
1 parent 9ab5955 commit 3e16156
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion Source/RP0/SpaceCenter/Projects/LCConstructionProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ private void ReassignEngineers(LaunchComplex lc)
if (engToAssign > 0)
{
KCTUtilities.ChangeEngineers(lc, engToAssign);
lc.RecalculateBuildRates();
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions Source/RP0/UI/KCT/GUI_Personnel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ private static void RenderEngineersSection(bool isCostCacheInvalid)
string assignStr = GetAssignText(true, currentLC, out int assignAmt);
string unassignStr = GetAssignText(false, currentLC, out int unassignAmt);

bool recalc = false;
ProjectType type = currentLC.LCType == LaunchComplexType.Pad ? ProjectType.VAB : ProjectType.SPH;
if (GUILayout.Button(unassignStr, GUILayout.ExpandWidth(false)) && unassignAmt > 0) { KCTUtilities.ChangeEngineers(currentLC, -unassignAmt); recalc = true; }
if (GUILayout.Button(unassignStr, GUILayout.ExpandWidth(false)) && unassignAmt > 0)
KCTUtilities.ChangeEngineers(currentLC, -unassignAmt);

if (Event.current.type == EventType.Repaint)
{
if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
Expand All @@ -136,7 +137,9 @@ private static void RenderEngineersSection(bool isCostCacheInvalid)

GUILayout.Label($" {currentLC.Engineers:N0} ", GetLabelCenterAlignStyle(), GUILayout.ExpandWidth(false));

if (GUILayout.Button(assignStr, GUILayout.ExpandWidth(false)) && assignAmt > 0) { KCTUtilities.ChangeEngineers(currentLC, assignAmt); recalc = true; }
if (GUILayout.Button(assignStr, GUILayout.ExpandWidth(false)) && assignAmt > 0)
KCTUtilities.ChangeEngineers(currentLC, assignAmt);

if (Event.current.type == EventType.Repaint)
{
if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
Expand All @@ -148,12 +151,6 @@ private static void RenderEngineersSection(bool isCostCacheInvalid)
GUILayout.Label($"Max: {currentLC.MaxEngineers:N0}", GetLabelRightAlignStyle());
GUILayout.EndHorizontal();

if (recalc)
{
currentLC.RecalculateBuildRates();
currentLC.KSC.RecalculateBuildRates(false);
}

int assignDelta = 0;
if (_currentPersonnelHover == PersonnelButtonHover.Assign)
assignDelta = assignAmt;
Expand Down
2 changes: 1 addition & 1 deletion Source/RP0/Utilities/KCTUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,6 @@ public static void HireStaff(bool isResearch, int workerAmount, LaunchComplex lc
ChangeEngineers(ksc, workerAmount);
if (lc != null)
ChangeEngineers(lc, workerAmount);
ksc.RecalculateBuildRates(false);
}
SpaceCenterManagement.Instance.Applicants = Math.Max(0, SpaceCenterManagement.Instance.Applicants - workerAmount);
if (SpaceCenterManagement.Instance.Applicants == 0)
Expand All @@ -1357,6 +1356,7 @@ public static void ChangeEngineers(LaunchComplex currentLC, int delta)
currentLC.Engineers += delta;
SCMEvents.OnPersonnelChange.Fire();
MaintenanceHandler.Instance.ScheduleMaintenanceUpdate();
currentLC.RecalculateBuildRates();
KCT_GUI.BuildRateForDisplay = null;
}

Expand Down

0 comments on commit 3e16156

Please sign in to comment.