Skip to content

Commit

Permalink
Improve auto hire crew count validation
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed May 19, 2024
1 parent f8a1087 commit ecee343
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Source/RP0/UI/KCT/GUI_Personnel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,33 +405,33 @@ private static void RenderHireNButton(bool isResearch)
{
LaunchComplex currentLC = isResearch ? null : ksc.LaunchComplexes[_LCIndex];
int curCount = isResearch ? SpaceCenterManagement.Instance.Researchers : currentLC.Engineers;
string sNumCrew = curCount.ToString("N0");
string sNumStaff = curCount.ToString("N0");
string sReserveFunds = Funding.Instance.Funds.ToString("N0");
PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new MultiOptionDialog(dialogName, "", dialogTitle, HighLogic.UISkin,
isResearch ? new DialogGUISpace(0f) : new DialogGUILabel($"LC: {currentLC.Name}"),
new DialogGUILabel($"Final count {(isResearch ? "" : $"(max: {currentLC.MaxEngineers:N0})")}"),
new DialogGUITextInput(sNumCrew, false, 7, (string n) =>
new DialogGUITextInput(sNumStaff, false, 7, (string n) =>
{
sNumCrew = n;
return sNumCrew;
sNumStaff = n;
return sNumStaff;
}, 24f),
new DialogGUILabel("Reserve funds"),
new DialogGUITextInput(sReserveFunds, false, 12, (string n) =>
{
sReserveFunds = n;
return sReserveFunds;
}, 24f),
new DialogGUIButton("Add", () => { TryAddAutoHire(sNumCrew, sReserveFunds, currentLC); }),
new DialogGUIButton("Add", () => { TryAddAutoHire(sNumStaff, sReserveFunds, currentLC); }),
new DialogGUIButton("Cancel", () => { })
), false, HighLogic.UISkin).HideGUIsWhilePopup();
}
}
}

private static void TryAddAutoHire(string sNumCrew, string sReserveFunds, LaunchComplex lc)
private static void TryAddAutoHire(string sNumStaff, string sReserveFunds, LaunchComplex lc)
{
bool b1 = int.TryParse(sNumCrew, out int numCrew);
bool b1 = int.TryParse(sNumStaff, out int numCrew);
bool b2 = double.TryParse(sReserveFunds, out double reserveFunds);
if (!b1 || !b2)
{
Expand All @@ -449,14 +449,16 @@ private static void TryAddAutoHire(string sNumCrew, string sReserveFunds, Launch
if (lc == null)
{
startCount = SpaceCenterManagement.Instance.Researchers;
endCount = numCrew;
endCount = Math.Max(numCrew, startCount);
}
else
{
startCount = Math.Min(lc.Engineers, lc.MaxEngineers);
startCount = lc.Engineers;
endCount = Math.Min(numCrew, lc.MaxEngineers);
endCount = Math.Max(endCount, startCount);
}

var target = new HireStaffProject(startCount, numCrew, reserveFunds, lc);
var target = new HireStaffProject(startCount, endCount, reserveFunds, lc);
SpaceCenterManagement.Instance.staffTarget = target;
}
}
Expand Down

0 comments on commit ecee343

Please sign in to comment.