Skip to content

Commit

Permalink
Fix allocation rates not persisting
Browse files Browse the repository at this point in the history
  • Loading branch information
severedsolo committed Mar 27, 2023
1 parent a4e0556 commit 9ff82e5
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 51 deletions.
66 changes: 59 additions & 7 deletions .idea/.idea.Bureaucracy/.idea/workspace.xml

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

3 changes: 1 addition & 2 deletions Bureaucracy/Budget/BudgetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public void OnLoad(ConfigNode cn)
double nextBudgetTime = GetNextBudgetTime();
if (managerNode != null)
{
int.TryParse(managerNode.GetValue("FundingAllocation"), out int i);
FundingAllocation = i;
float.TryParse(managerNode.GetValue("FundingAllocation"), out FundingAllocation);
double.TryParse(managerNode.GetValue("nextBudget"), out nextBudgetTime);
CreateNewBudget(nextBudgetTime);
}
Expand Down
2 changes: 0 additions & 2 deletions Bureaucracy/Bureaucracy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public void OnLoad(ConfigNode node)
ResearchManager.Instance.OnLoad(node);
CrewManager.Instance.OnLoad(node);
RandomEventLoader.Instance.OnLoad(node);
UiController.Instance.OnLoad(node);
node.TryGetValue("existingSave", ref existingSave);
node.TryGetValue("lastProgressUpdate", ref lastProgressUpdate);
if(progressEvent == null) progressEvent = new ManagerProgressEvent();
Expand All @@ -150,7 +149,6 @@ public void OnSave(ConfigNode node)
ResearchManager.Instance.OnSave(node);
CrewManager.Instance.OnSave(node);
RandomEventLoader.Instance.OnSave(node);
UiController.Instance.OnSave(node);
node.SetValue("existingSave", existingSave, true);
node.SetValue("lastProgressUpdate", lastProgressUpdate, true);
Debug.Log("[Bureaucracy]: OnSave Complete");
Expand Down
58 changes: 19 additions & 39 deletions Bureaucracy/UI/UIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class UiController : MonoBehaviour
private PopupDialog researchWindow;
public PopupDialog allocationWindow;
public PopupDialog crewWindow;
private int fundingAllocation;
private int constructionAllocation;
private int researchAllocation;
[UsedImplicitly] public PopupDialog errorWindow;
private int padding;
private const int PadFactor = 10;
Expand All @@ -49,13 +46,15 @@ private void Awake()

private void Start()
{
SetAllocation("Budget", "40");
SetAllocation("Research", "30");
SetAllocation("Construction", "30");
GameEvents.onGUIApplicationLauncherReady.Add(SetupToolbarButton);
GameEvents.onGUIApplicationLauncherUnreadifying.Add(RemoveToolbarButton);
}

private int GetAllocation(Manager manager)
{
return (int)Math.Round((manager.FundingAllocation*100), 0);
}


public void SetupToolbarButton()
{
Expand Down Expand Up @@ -152,19 +151,19 @@ 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", s), 40.0f, 30.0f);
horizontalArray[3] = new DialogGUITextInput(GetAllocation(BudgetManager.Instance).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);
horizontalArray[1] = new DialogGUILabel("Construction", MessageStyle(true));
horizontalArray[2] = new DialogGUISpace(10);
horizontalArray[3] = new DialogGUITextInput(constructionAllocation.ToString(), false, 3, s => SetAllocation("Construction", s), 40.0f, 30.0f);
horizontalArray[3] = new DialogGUITextInput(GetAllocation(FacilityManager.Instance).ToString(), false, 3, s => SetAllocation("Construction", s), 40.0f, 30.0f);
innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
horizontalArray = new DialogGUIBase[4];
horizontalArray[0] = new DialogGUISpace(10);
horizontalArray[1] = new DialogGUILabel("Research", MessageStyle(true));
horizontalArray[2] = new DialogGUISpace(45);
horizontalArray[3] = new DialogGUITextInput(researchAllocation.ToString(), false, 3, s => SetAllocation("Research", s), 40.0f, 30.0f);
horizontalArray[3] = new DialogGUITextInput(GetAllocation(ResearchManager.Instance).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++)
{
Expand Down Expand Up @@ -203,13 +202,12 @@ private string SetAllocation(string managerName, string passedString)
switch (managerName)
{
case "Budget":
fundingAllocation = i;
break;
return GetAllocation(BudgetManager.Instance).ToString(CultureInfo.CurrentCulture);
case "Research":
researchAllocation = i;
return GetAllocation(ResearchManager.Instance).ToString(CultureInfo.CurrentCulture);
break;
case "Construction":
constructionAllocation = i;
return GetAllocation(FacilityManager.Instance).ToString(CultureInfo.CurrentCulture);
break;
}

Expand Down Expand Up @@ -254,11 +252,11 @@ private PopupDialog DrawMainUi()
dialogElements.Add(new DialogGUIScrollList(new Vector2(300, 300), false, true, vertical));
DialogGUIBase[] horizontal = new DialogGUIBase[6];
horizontal[0] = new DialogGUILabel("Allocations: ");
horizontal[1] = new DialogGUILabel("Funds: "+fundingAllocation+"%");
horizontal[1] = new DialogGUILabel("Funds: "+GetAllocation(BudgetManager.Instance)+"%");
horizontal[2] = new DialogGUILabel("|");
horizontal[3] = new DialogGUILabel("Construction: "+constructionAllocation+"%");
horizontal[3] = new DialogGUILabel("Construction: "+GetAllocation(FacilityManager.Instance)+"%");
horizontal[4] = new DialogGUILabel("|");
horizontal[5] = new DialogGUILabel("Research: "+researchAllocation+"%");
horizontal[5] = new DialogGUILabel("Research: "+GetAllocation(ResearchManager.Instance)+"%");
dialogElements.Add(new DialogGUIHorizontalLayout(horizontal));
dialogElements.Add(GetBoxes("main"));
}
Expand Down Expand Up @@ -409,8 +407,10 @@ private DialogGUIHorizontalLayout GetBoxes(string passingUi)

public void ValidateAllocations()
{
int allocations = fundingAllocation + constructionAllocation + researchAllocation;
if (allocations != 100) errorWindow = AllocationErrorWindow();
int allocations = GetAllocation(BudgetManager.Instance);
allocations += GetAllocation(ResearchManager.Instance);
allocations+= + GetAllocation(FacilityManager.Instance);
if (allocations <99.9 || allocations >100.1) errorWindow = AllocationErrorWindow();
else DismissAllWindows();
}

Expand Down Expand Up @@ -448,27 +448,7 @@ public PopupDialog GeneralError(string error)
dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
return PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("GeneralErrorDialog", "", "Bureaucracy: Error", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 200,200), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"));
}

public void OnSave(ConfigNode cn)
{
ConfigNode uiNode = new ConfigNode("UI");
uiNode.SetValue("FundingAllocation", fundingAllocation, true);
uiNode.SetValue("ResearchAllocation", researchAllocation, true);
uiNode.SetValue("ConstructionAllocation", constructionAllocation, true);
cn.AddNode(uiNode);
}

public void OnLoad(ConfigNode cn)
{
ConfigNode uiNode = cn.GetNode("UI");
if (uiNode == null) return;
int.TryParse(uiNode.GetValue("FundingAllocation"), out fundingAllocation);
SetAllocation("Budget", fundingAllocation.ToString());
int.TryParse(uiNode.GetValue("ResearchAllocation"), out researchAllocation);
SetAllocation("Research", researchAllocation.ToString());
int.TryParse(uiNode.GetValue("ConstructionAllocation"), out constructionAllocation);
SetAllocation("Construction", constructionAllocation.ToString());
}


public PopupDialog NoLaunchesWindow()
{
Expand Down
2 changes: 1 addition & 1 deletion GameData/Bureaucracy/Bureaucracy.version
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
"MAJOR" : 1,
"MINOR" : 6,
"PATCH" : 0,
"PATCH" : 1,
"BUILD" : 0
},
"KSP_VERSION" :
Expand Down
5 changes: 5 additions & 0 deletions GameData/Bureaucracy/Changelog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ KERBALCHANGELOG
showChangelog = True
modName = Bureaucracy

VERSION
{
version = 1.6.1
change = Fixed Budget Allocations not persisting between scene changes
}
VERSION
{
version = 1.6
Expand Down

0 comments on commit 9ff82e5

Please sign in to comment.