Skip to content

Commit

Permalink
Handle existing saves and extra UI stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
severedsolo committed Jan 26, 2020
1 parent 5068908 commit 5671277
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 71 deletions.
132 changes: 74 additions & 58 deletions .idea/.idea.Bureaucracy/.idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Bureaucracy/Budget/BudgetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class BudgetManager : Manager

public BudgetManager()
{
Name = "Budget Manager";
Name = "Budget";
Instance = this;
FundingAllocation = 40;
FundingAllocation = 0.4f;
Debug.Log("[Bureaucracy]: Budget Manager is ready");
}

Expand Down
7 changes: 4 additions & 3 deletions Bureaucracy/Facilities/FacilityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public FacilityManager()
SpaceCenterFacility spf = spaceCentreFacilities.ElementAt(i);
Facilities.Add(new BureaucracyFacility(spf));
}

Name = "Construction";
ThisMonthsBudget = HighLogic.CurrentGame.Parameters.Career.StartingFunds * FundingAllocation;
Instance = this;
Debug.Log("[Bureaucracy]: Facility Manager Ready");
}
Expand Down Expand Up @@ -80,8 +80,9 @@ public void OnLoad(ConfigNode cn)
Debug.Log("[Bureaucracy]: FacilityManager OnLoad");
ConfigNode managerNode = cn.GetNode("FACILITY_MANAGER");
if (managerNode == null) return;
int.TryParse(managerNode.GetValue("FundingAllocation"), out int funding);
double.TryParse(managerNode.GetValue("thisMonth"), out ThisMonthsBudget);
float.TryParse(managerNode.GetValue("FundingAllocation"), out float funding);
if(double.TryParse(managerNode.GetValue("thisMonth"), out double d)) ThisMonthsBudget = d;
else ThisMonthsBudget = Utilities.Instance.GetNetBudget(Name);
FundingAllocation = funding;
float.TryParse(managerNode.GetValue("CostMultiplier"), out CostMultiplier);
float.TryParse(managerNode.GetValue("FireChance"), out FireChance);
Expand Down
2 changes: 1 addition & 1 deletion Bureaucracy/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Manager
//obviously you change these in the constructor.
public string Name = "Blank Manager";
public float FundingAllocation = 0.3f;
public double ThisMonthsBudget = 0;
public double ThisMonthsBudget;

protected double ProgressTime()
{
Expand Down
6 changes: 4 additions & 2 deletions Bureaucracy/Science/ResearchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public ResearchManager()
{
Name = "Research";
Instance = this;
ThisMonthsBudget = HighLogic.CurrentGame.Parameters.Career.StartingFunds * FundingAllocation;
Debug.Log("[Bureaucracy]: Research Manager Ready");
}

Expand Down Expand Up @@ -69,8 +70,9 @@ public void OnLoad(ConfigNode node)
ConfigNode researchNode = node.GetNode("RESEARCH");
if (researchNode == null) return;
float.TryParse(researchNode.GetValue("ScienceMultiplier"), out ScienceMultiplier);
int.TryParse(researchNode.GetValue("FundingAllocation"), out int funding);
double.TryParse(researchNode.GetValue("thisMonth"), out ThisMonthsBudget);
float.TryParse(researchNode.GetValue("FundingAllocation"), out float funding);
if(double.TryParse(researchNode.GetValue("thisMonth"), out double d)) ThisMonthsBudget = d;
else ThisMonthsBudget = Utilities.Instance.GetNetBudget(Name);
FundingAllocation = funding;
ConfigNode[] scienceNodes = researchNode.GetNodes("SCIENCE_DATA");
if (scienceNodes.Length == 0) return;
Expand Down
27 changes: 22 additions & 5 deletions Bureaucracy/UI/UIController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
using KSP.UI.Screens;
Expand All @@ -26,7 +27,7 @@ public class UiController : MonoBehaviour
private void Awake()
{
Instance = this;
SetAllocation("Budget Manager", "40");
SetAllocation("Budget", "40");
SetAllocation("Research", "30");
SetAllocation("Construction", "30");
}
Expand Down Expand Up @@ -67,7 +68,7 @@ private PopupDialog DrawBudgetAllocationUi()
horizontalArray[0] = new DialogGUISpace(10);
horizontalArray[1] = new DialogGUILabel("Budget", MessageStyle(true));
horizontalArray[2] = new DialogGUISpace(70);
horizontalArray[3] = new DialogGUITextInput(fundingAllocation.ToString(), false, 3, s => SetAllocation("Budget Manager", s), 40.0f, 30.0f);
horizontalArray[3] = new DialogGUITextInput(fundingAllocation.ToString(), false, 3, s => SetAllocation("Budget", s), 40.0f, 30.0f);
innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
horizontalArray = new DialogGUIBase[4];
horizontalArray[0] = new DialogGUISpace(10);
Expand All @@ -81,6 +82,16 @@ private PopupDialog DrawBudgetAllocationUi()
horizontalArray[2] = new DialogGUISpace(45);
horizontalArray[3] = new DialogGUITextInput(researchAllocation.ToString(), false, 3, s => SetAllocation("Research", s), 40.0f, 30.0f);
innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
for (int i = 0; i < Bureaucracy.Instance.registeredManagers.Count; i++)
{
Manager m = Bureaucracy.Instance.registeredManagers.ElementAt(i);
if (Utilities.Instance.GetNetBudget(m.Name) == -1.0f) continue;
horizontalArray = new DialogGUIBase[3];
horizontalArray[0] = new DialogGUISpace(10);
horizontalArray[1] = new DialogGUILabel(m.Name+": ");
horizontalArray[2] = new DialogGUILabel(() => ShowFunding(m));
innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
}
horizontalArray = new DialogGUIBase[2];
horizontalArray[0] = new DialogGUISpace(10);
horizontalArray[1] = new DialogGUIButton("Load Settings", () => SettingsClass.Instance.InGameLoad(), false);
Expand All @@ -93,6 +104,11 @@ private PopupDialog DrawBudgetAllocationUi()
GetRect(dialogElements), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
}

private string ShowFunding(Manager manager)
{
return "$"+Math.Round(Utilities.Instance.GetNetBudget(manager.Name),0).ToString(CultureInfo.CurrentCulture);
}

private string SetAllocation(string managerName, string passedString)
{
int.TryParse(passedString, out int i);
Expand All @@ -101,7 +117,7 @@ private string SetAllocation(string managerName, string passedString)
m.FundingAllocation = actualAllocation;
switch (managerName)
{
case "Budget Manager":
case "Budget":
fundingAllocation = i;
break;
case "Research":
Expand Down Expand Up @@ -218,6 +234,7 @@ private PopupDialog DrawFacilityUi()
int upgradeCount = 0;
innerElements.Add(new DialogGUISpace(10));
float investmentNeeded = 0;
innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("This Month's Budget: $"+Math.Round(FacilityManager.Instance.ThisMonthsBudget, 0), false)));;
for (int i = 0; i < FacilityManager.Instance.Facilities.Count; i++)
{
BureaucracyFacility bf = FacilityManager.Instance.Facilities.ElementAt(i);
Expand Down Expand Up @@ -260,7 +277,7 @@ private PopupDialog DrawResearchUi()
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;
double scienceOutput = ResearchManager.Instance.ThisMonthsBudget / SettingsClass.Instance.ScienceMultiplier * ResearchManager.Instance.ScienceMultiplier;
horizontal[2] = new DialogGUILabel("Research Output: "+Math.Round(scienceOutput, 1));
dialogElements.Add(new DialogGUIHorizontalLayout(horizontal));
dialogElements.Add(GetBoxes("research"));
Expand Down Expand Up @@ -351,7 +368,7 @@ public void OnLoad(ConfigNode cn)
ConfigNode uiNode = cn.GetNode("UI");
if (uiNode == null) return;
int.TryParse(uiNode.GetValue("FundingAllocation"), out fundingAllocation);
SetAllocation("Budget Manager", fundingAllocation.ToString());
SetAllocation("Budget", fundingAllocation.ToString());
int.TryParse(uiNode.GetValue("ResearchAllocation"), out researchAllocation);
SetAllocation("Research", researchAllocation.ToString());
int.TryParse(uiNode.GetValue("ConstructionAllocation"), out constructionAllocation);
Expand Down

0 comments on commit 5671277

Please sign in to comment.