4 protected float m_fDisabledOpacity;
6 const string WIDGET_BUDGET_TEXT =
"PercentageText";
7 const string WIDGET_BUDGET_ICON =
"Icon";
8 const string WIDGET_BUDGET_PROGRESSBAR =
"RadialProgressBar";
9 const string WIDGET_BUDGETPREVIEW_TEXT =
"Preview";
10 const string WIDGET_ICON_AREA =
"IconArea";
11 const string WIDGET_LOCK_VISUALS =
"LockVisuals";
14 protected ResourceName m_BudgetEntryPrefab;
16 protected Widget m_Layout;
18 protected ref map<EEditableEntityBudget, Widget> m_BudgetWidgets =
new map<EEditableEntityBudget, Widget>();
21 protected void OnBudgetMaxUpdate(
EEditableEntityBudget budgetType,
int currentBudgetValue,
int maxBudgetValue)
23 TextWidget budgetWidget;
24 if (m_BudgetWidgets.Find(budgetType, budgetWidget))
26 SetBudgetData(budgetWidget, currentBudgetValue, maxBudgetValue);
27 SetBudgetPreviewData(budgetWidget, 0, 0);
32 protected void OnBudgetUpdate(
EEditableEntityBudget budgetType,
int originalBudgetValue,
int updatedBudgetValue,
int maxBudgetValue)
34 TextWidget budgetWidget;
35 if (m_BudgetWidgets.Find(budgetType, budgetWidget))
37 SetBudgetData(budgetWidget, updatedBudgetValue, maxBudgetValue);
38 SetBudgetPreviewData(budgetWidget, 0, 0);
45 WorkspaceWidget workspace =
GetGame().GetWorkspace();
46 if (!workspace || !
m_Layout || m_BudgetEntryPrefab.IsEmpty())
50 if (m_BudgetWidgets.Contains(budgetType))
53 Widget budgetWidget = workspace.CreateWidgets(m_BudgetEntryPrefab,
m_Layout);
54 SetBudgetData(budgetWidget, budget.GetCurrentBudget(), maxBudget, budget.GetInfo());
56 m_BudgetWidgets.Insert(budgetType, budgetWidget);
60 protected void OnBudgetPreviewUpdate(
EEditableEntityBudget budgetType,
float previewBudgetValue,
float budgetChange)
63 if (m_BudgetWidgets.Find(budgetType, budgetWidget))
64 SetBudgetPreviewData(budgetWidget, previewBudgetValue, budgetChange);
68 protected void InitializeBudgets()
70 array<ref SCR_EditableEntityCoreBudgetSetting> budgets = {};
71 m_BudgetManager.GetBudgets(budgets);
76 m_BudgetManager.GetMaxBudgetValue(budget.GetBudgetType(), maxBudget);
78 OnBudgetAdd(budget, maxBudget);
83 protected void SetBudgetData(Widget budgetWidget,
int budgetValue,
int maxBudgetValue,
SCR_UIInfo info =
null)
86 if (maxBudgetValue > 0)
87 budgetProgress = budgetValue / (float) maxBudgetValue;
91 TextWidget budgetValueText = TextWidget.Cast(budgetWidget.FindAnyWidget(WIDGET_BUDGET_TEXT));
93 budgetValueText.SetTextFormat(
"#AR-ValueUnit_Percentage", (budgetProgress * 100).ToString(-1, 0));
95 bool isBudgetEnabled = maxBudgetValue > 0;
99 budgetValueText.SetVisible(isBudgetEnabled);
101 Widget lockVisuals = budgetWidget.FindAnyWidget(WIDGET_LOCK_VISUALS);
103 lockVisuals.SetVisible(!isBudgetEnabled);
105 Widget iconVisuals = budgetWidget.FindAnyWidget(WIDGET_ICON_AREA);
108 if (!isBudgetEnabled)
109 iconVisuals.SetOpacity(m_fDisabledOpacity);
111 iconVisuals.SetOpacity(1);
116 ImageWidget budgetIcon = ImageWidget.Cast(budgetWidget.FindAnyWidget(WIDGET_BUDGET_ICON));
117 info.SetIconTo(budgetIcon);
121 Widget progressBarWidget = budgetWidget.FindAnyWidget(WIDGET_BUDGET_PROGRESSBAR);
122 if (!progressBarWidget)
130 progressBar.SetProgress(budgetProgress);
132 progressBar.SetProgress(0);
136 protected void SetBudgetPreviewData(Widget w,
float previewBudgetValue,
float budgetChange)
138 TextWidget previewText = TextWidget.Cast(w.FindAnyWidget(WIDGET_BUDGETPREVIEW_TEXT));
140 Widget progressBarWidget = w.FindAnyWidget(WIDGET_BUDGET_PROGRESSBAR);
141 if (!progressBarWidget)
148 if (previewText && budgetChange != 0)
150 previewText.SetVisible(
true);
153 bool isLessThenOne =
false;
155 if (budgetChange > 0 && budgetChange < 1)
157 isLessThenOne =
true;
162 amount = budgetChange.ToString(-1, 0);
166 previewText.SetTextFormat(
"#AR-ValueUnit_Percentage_Add", amount);
168 previewText.SetTextFormat(
"#AR-ValueUnit_Percentage_AddLessThen", amount);
171 progressBar.SetPreviewProgress(previewBudgetValue * 0.01);
173 else if (previewText)
175 previewText.SetVisible(
false);
178 progressBar.SetPreviewProgress(0);
183 private void ResetWidgetPreviewData()
185 Widget budgetWidget =
m_Layout.GetChildren();
187 while (budgetWidget && i++ < 100)
189 SetBudgetPreviewData(budgetWidget, 0, 0);
190 budgetWidget = budgetWidget.GetSibling();
195 protected void UnregisterEvents()
197 if (!m_BudgetManager)
200 m_BudgetManager.Event_OnBudgetUpdated.Remove(OnBudgetUpdate);
201 m_BudgetManager.Event_OnBudgetMaxUpdated.Remove(OnBudgetMaxUpdate);
202 m_BudgetManager.Event_OnBudgetPreviewUpdated.Remove(OnBudgetPreviewUpdate);
203 m_BudgetManager.Event_OnBudgetPreviewReset.Remove(ResetWidgetPreviewData);
207 override void HandlerAttachedScripted(Widget w)
212 if (m_BudgetEntryPrefab.IsEmpty())
216 Widget debugBudgetWidget =
m_Layout.GetChildren();
218 while(debugBudgetWidget && i++ < 100)
220 Widget debugFilterSibling = debugBudgetWidget.GetSibling();
221 debugBudgetWidget.RemoveFromHierarchy();
222 debugBudgetWidget = debugFilterSibling;
229 m_BudgetManager.Event_OnBudgetUpdated.Insert(OnBudgetUpdate);
230 m_BudgetManager.Event_OnBudgetMaxUpdated.Insert(OnBudgetMaxUpdate);
231 m_BudgetManager.Event_OnBudgetPreviewUpdated.Insert(OnBudgetPreviewUpdate);
232 m_BudgetManager.Event_OnBudgetPreviewReset.Insert(ResetWidgetPreviewData);
236 m_BudgetManager.DemandBudgetUpdateFromServer();
240 override void HandlerDeattached(Widget w)
242 m_BudgetWidgets.Clear();