Skip to content

Commit

Permalink
Add "just tool it all fer crissakes" button (#915)
Browse files Browse the repository at this point in the history
Name sort of suggested by schnobs on #RO.

General layout was copied from some other dialog, but I don't remember
from which one, unfortunately
pap1723 authored Dec 1, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 723f5cb commit 06d9550
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Source/Tooling/ToolingGUI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Smooth.Slinq;

namespace RP0
{
@@ -110,6 +111,50 @@ public tabs toolingTab()
} finally {
GUILayout.EndScrollView();
}
GUILayout.BeginHorizontal();
try {
GUILayout.Label("Total vessel cost if all parts are tooled: " + (EditorLogic.fetch.ship.GetShipCosts(out _, out _) - EditorLogic.fetch.ship.parts.Slinq().SelectMany(p => p.FindModulesImplementing<ModuleTooling>().Slinq()).Where(mt => !mt.IsUnlocked()).Select(mt => mt.GetModuleCost(mt.part.partInfo.cost, ModifierStagingSituation.CURRENT)).Sum()));
} finally {
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal();
try {
if (GUILayout.Button("just tool it all, fer crissakes"))
{
var totalToolingCost = untooledParts.Slinq().Select(up => up.toolingCost).Sum();
bool canAfford = Funding.Instance.Funds >= totalToolingCost;
PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new MultiOptionDialog(
"ConfirmAllToolingsPurchase",
"Tooling for all untooled parts will cost " + totalToolingCost.ToString("N0") + " funds.",
"Tooling Purchase",
HighLogic.UISkin,
new Rect(0.5f, 0.5f, 150f, 60f),
new DialogGUIFlexibleSpace(),
new DialogGUIVerticalLayout(
new DialogGUIFlexibleSpace(),
new DialogGUIButton(canAfford ? "Purchase All Toolings" : "Can't Afford",
() =>
{
if (canAfford)
{
Funding.Instance.AddFunds(-totalToolingCost, TransactionReasons.RnDPartPurchase);
EditorLogic.fetch.ship.Parts.Slinq().SelectMany(p => p.FindModulesImplementing<ModuleTooling>().Slinq()).Where(mt => !mt.IsUnlocked()).ForEach(mt => {
mt.PurchaseTooling();
mt.Events["ToolingEvent"].guiActiveEditor = false;
});
GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
}
}, 140.0f, 30.0f, true),
new DialogGUIButton("Close", () => { }, 140.0f, 30.0f, true)
)),
false,
HighLogic.UISkin);
}
} finally {
GUILayout.EndHorizontal();
}
}
return currentToolingType == null ? tabs.Tooling : tabs.ToolingType;
}

0 comments on commit 06d9550

Please sign in to comment.