diff --git a/.idea/.idea.Bureaucracy/.idea/workspace.xml b/.idea/.idea.Bureaucracy/.idea/workspace.xml index ebbc18e..bb6efb9 100644 --- a/.idea/.idea.Bureaucracy/.idea/workspace.xml +++ b/.idea/.idea.Bureaucracy/.idea/workspace.xml @@ -2,27 +2,12 @@ - - - - - - + - - - - - - - - - - @@ -312,86 +299,86 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + @@ -508,13 +495,13 @@ file://$PROJECT_DIR$/Bureaucracy/Facilities/FacilityManager.cs - 120 + 121 - - + + file://$PROJECT_DIR$/Bureaucracy/Science/ResearchManager.cs + 68 + + + + + + + + + file://$PROJECT_DIR$/Bureaucracy/Facilities/FacilityManager.cs + 79 + + + + + + + @@ -1681,6 +1694,9 @@ + + + diff --git a/Bureaucracy/Budget/BudgetManager.cs b/Bureaucracy/Budget/BudgetManager.cs index 3bac7cc..a7d8808 100644 --- a/Bureaucracy/Budget/BudgetManager.cs +++ b/Bureaucracy/Budget/BudgetManager.cs @@ -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"); } diff --git a/Bureaucracy/Facilities/FacilityManager.cs b/Bureaucracy/Facilities/FacilityManager.cs index 0758696..544a919 100644 --- a/Bureaucracy/Facilities/FacilityManager.cs +++ b/Bureaucracy/Facilities/FacilityManager.cs @@ -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"); } @@ -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); diff --git a/Bureaucracy/Manager.cs b/Bureaucracy/Manager.cs index 5d70da2..bc69ed5 100644 --- a/Bureaucracy/Manager.cs +++ b/Bureaucracy/Manager.cs @@ -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() { diff --git a/Bureaucracy/Science/ResearchManager.cs b/Bureaucracy/Science/ResearchManager.cs index 26fbf5e..90d4f98 100644 --- a/Bureaucracy/Science/ResearchManager.cs +++ b/Bureaucracy/Science/ResearchManager.cs @@ -16,6 +16,7 @@ public ResearchManager() { Name = "Research"; Instance = this; + ThisMonthsBudget = HighLogic.CurrentGame.Parameters.Career.StartingFunds * FundingAllocation; Debug.Log("[Bureaucracy]: Research Manager Ready"); } @@ -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; diff --git a/Bureaucracy/UI/UIController.cs b/Bureaucracy/UI/UIController.cs index 36ee23e..d567af6 100644 --- a/Bureaucracy/UI/UIController.cs +++ b/Bureaucracy/UI/UIController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using JetBrains.Annotations; using KSP.UI.Screens; @@ -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"); } @@ -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); @@ -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); @@ -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); @@ -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": @@ -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); @@ -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")); @@ -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);