Skip to content

Commit

Permalink
Beta 2
Browse files Browse the repository at this point in the history
Autobalance costs option
Upgrades can be cancelled
Improvements to upgrade pipeline
Maximum science output is now shown on UI
Fix Allocation Error UI being way too big
  • Loading branch information
severedsolo committed Jan 15, 2020
1 parent cbfe04f commit c43b9a5
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 19 deletions.
23 changes: 13 additions & 10 deletions .idea/.idea.Bureaucracy/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Bureaucracy/ContractInterceptor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Contracts;
using System.Linq;
using KSPAchievements;
using UnityEngine;

namespace Bureaucracy
Expand Down
9 changes: 9 additions & 0 deletions Bureaucracy/Facilities/BureaucracyFacility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,14 @@ public bool IsDestroyed()

return false;
}

public void CancelUpgrade()
{
Upgrade = null;
Upgrading = false;
IsPriority = false;
Debug.Log("[Bureaucracy]: Upgrade of "+Name+" cancelled");
ScreenMessages.PostScreenMessage("[Bureaucracy]: " + Name + " - Upgrade cancelled");
}
}
}
27 changes: 23 additions & 4 deletions Bureaucracy/Facilities/FacilityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class FacilityManager : Manager
{
public readonly List<BureaucracyFacility> Facilities = new List<BureaucracyFacility>();
public static FacilityManager Instance;
private PopupDialog warningDialog;

public FacilityManager()
{
Expand Down Expand Up @@ -121,15 +122,33 @@ public void StartUpgrade(UpgradeableFacility facility)

if (facilityToUpgrade.Upgrading)
{
Debug.Log("[Bureaucracy]: " + facility.id + " is already being upgraded. Prioritising");
SetPriority(facilityToUpgrade, true);
ScreenMessages.PostScreenMessage("Upgrade of "+facilityToUpgrade.Name + " prioritised");
return;
if (facilityToUpgrade.IsPriority)
{
warningDialog = DrawWarningDialog(facilityToUpgrade);
}
else
{
Debug.Log("[Bureaucracy]: " + facility.id + " is already being upgraded. Prioritising");
SetPriority(facilityToUpgrade, true);
ScreenMessages.PostScreenMessage("Upgrade of " + facilityToUpgrade.Name + " prioritised");
return;
}
}

facilityToUpgrade.StartUpgrade(facility);
}

private PopupDialog DrawWarningDialog(BureaucracyFacility facility)
{
List<DialogGUIBase> dialogElements = new List<DialogGUIBase>();
dialogElements.Add(new DialogGUILabel("Upgrade of "+facility.Name+" will be cancelled. "+(facility.Upgrade.RemainingInvestment-facility.Upgrade.OriginalCost+" will be lost. Are you sure?")));
dialogElements.Add(new DialogGUIButton("Yes", facility.CancelUpgrade, true));
dialogElements.Add(new DialogGUIButton("No", () => { }, true));
return PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("CancelUpgradeDialog", "", "Bureaucracy: Cancel Upgrade", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 210, 100), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
}



private BureaucracyFacility UpgradeableToActualFacility(UpgradeableFacility facility)
{
for (int i = 0; i < Facilities.Count; i++)
Expand Down
35 changes: 32 additions & 3 deletions Bureaucracy/SettingsClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class SettingsClass
{
public static SettingsClass Instance;
public bool ContractInterceptor = true;
public bool AutoBalanceSettings = true;
public bool KctError = true;
public bool HandleKscUpgrades = true;
public bool StopTimeWarp = true;
Expand Down Expand Up @@ -39,8 +40,8 @@ public class SettingsClass
public int StrikeMemory = 6;
public int DeadKerbalPenalty = 25;
private string defaultPath;
private string settingsVersion = "1.0";
private string previousVersion = "0.0";
private string settingsVersion = "0.2";
private string previousVersion = "1.0";
private string savePath;

public SettingsClass()
Expand Down Expand Up @@ -82,7 +83,7 @@ public void OnLoad(string path)
Debug.Log("[Bureaucracy]: Settings are not compatible with this version of Bureaucracy. Aborting Load");
return;
}

if(saveVersion == "0.2") bool.TryParse(cn.GetValue("AutoBalanceSettings"), out AutoBalanceSettings);
bool.TryParse(cn.GetValue("ShowKCTWarning"), out KctError);
bool.TryParse(cn.GetValue("ContractInterceptorEnabled"), out ContractInterceptor);
bool.TryParse(cn.GetValue("HandleKSCUpgrades"), out HandleKscUpgrades);
Expand Down Expand Up @@ -119,9 +120,36 @@ public void OnLoad(string path)
BudgetManager.Instance.NextBudget = null;
BudgetManager.Instance.NextBudget = new BudgetEvent(Planetarium.GetUniversalTime()+TimeBetweenBudgets*FlightGlobals.GetHomeBody().solarDayLength, BudgetManager.Instance, true);
}

if (AutoBalanceSettings) BalanceSettings();
if(saveVersion != "0.2") OnSave(defaultPath);
Debug.Log("[Bureaucracy]: Settings Loaded");
}

private void BalanceSettings()
{
float balanceMultiplier = TimeBetweenBudgets / 30.0f;
AdminCost = BalanceCost(4000, balanceMultiplier);
AstronautComplexCost = BalanceCost(2000, balanceMultiplier);
MissionControlCost = BalanceCost(6000, balanceMultiplier);
SphCost = BalanceCost(8000, balanceMultiplier);
TrackingStationCost = BalanceCost(4000, balanceMultiplier);
RndCost = BalanceCost(8000, balanceMultiplier);
VabCost = BalanceCost(8000, balanceMultiplier);
OtherFacilityCost = BalanceCost(5000, balanceMultiplier);
LaunchCostSph = BalanceCost(100, balanceMultiplier);
LaunchCostVab = BalanceCost(1000, balanceMultiplier);
KerbalBaseWage = BalanceCost(1000, balanceMultiplier);
LongTermBonusYears = BalanceCost(10000, balanceMultiplier);
LongTermBonusDays = BalanceCost(30, balanceMultiplier);
}

private int BalanceCost(int initialCost, float balanceMultiplier)
{
float actualCost = initialCost * balanceMultiplier;
return (int)actualCost;
}

private bool RefreshBudget()
{
if (BudgetManager.Instance == null) return false;
Expand All @@ -135,6 +163,7 @@ public void OnSave(string path)
Debug.Log("[Bureaucracy]: Saving Settings");
ConfigNode cn = new ConfigNode("SETTINGS");
cn.SetValue("Version", settingsVersion, true);
cn.SetValue("AutoBalanceSettings", AutoBalanceSettings, true);
cn.SetValue("ShowKCTWarning", KctError, true);
cn.SetValue("ContractInterceptorEnabled", ContractInterceptor, true);
cn.SetValue("HandleKSCUpgrades", HandleKscUpgrades, true);
Expand Down
9 changes: 7 additions & 2 deletions Bureaucracy/UI/UIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ private PopupDialog DrawResearchUi()
}
DialogGUIVerticalLayout vertical = new DialogGUIVerticalLayout(innerElements.ToArray());
dialogElements.Add(new DialogGUIScrollList(-Vector2.one, false, false, vertical));
dialogElements.Add(new DialogGUILabel("Total Science to be processed: "+Math.Round(scienceCount, 1)));
DialogGUIBase[] horizontal = new DialogGUIBase[3];
horizontal[0] = new DialogGUILabel("Processing Science: " + Math.Round(scienceCount, 1));
horizontal[1] = new DialogGUILabel("|");
double scienceOutput = ResearchManager.Instance.GetAllocatedFunding() / SettingsClass.Instance.ScienceMultiplier * ResearchManager.Instance.scienceMultiplier;
horizontal[2] = new DialogGUILabel("Maximum Output: "+Math.Round(scienceOutput, 1));
dialogElements.Add(new DialogGUIHorizontalLayout(horizontal));
dialogElements.Add(GetBoxes("research"));
return PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("ResearchDialog", "", "Bureaucracy: Research", UISkinManager.GetSkin("MainMenuSkin"), GetRect(dialogElements), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
}
Expand Down Expand Up @@ -277,7 +282,7 @@ private PopupDialog AllocationErrorWindow()
List<DialogGUIBase> dialogElements = new List<DialogGUIBase>();
dialogElements.Add(new DialogGUILabel("Allocations do not add up to 100%"));
dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
return PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("AllocationError", "", "Bureaucracy: Error", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 200,200), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
return PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("AllocationError", "", "Bureaucracy: Error", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 200,90), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
}

public void RemoveToolbarButton()
Expand Down

0 comments on commit c43b9a5

Please sign in to comment.