Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BudgetUIComponent.c
Go to the documentation of this file.
3 {
4  [Attribute("0", UIWidgets.ComboBox, "", enums: ParamEnumArray.FromEnum(EEditableEntityBudget))]
5  protected EEditableEntityBudget m_BudgetType;
6 
7  [Attribute("")]
8  protected string m_sBudgetProgressRoot;
9 
10  protected SCR_CampaignBuildingEditorComponent m_CampaignBuildingComponent;
11  protected SCR_BudgetEditorComponent m_BudgetManager;
12  protected SCR_BudgetProgressEditorUIComponent m_BudgetProgress;
13 
14  protected int m_iCurrentBudget;
15  protected int m_iMaxBudget;
16  protected const int INVALID_BUDGET = -1;
17 
18  //------------------------------------------------------------------------------------------------
19  // Override
20  //------------------------------------------------------------------------------------------------
21 
22  //------------------------------------------------------------------------------------------------
23  override void HandlerAttachedScripted(Widget w)
24  {
25  super.HandlerAttachedScripted(w);
26 
27  // Widget
28  Widget budgetRoot = w.FindAnyWidget(m_sBudgetProgressRoot);
29  if (!budgetRoot)
30  budgetRoot = w;
31 
32  m_CampaignBuildingComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent));
33  m_BudgetProgress = SCR_BudgetProgressEditorUIComponent.Cast(budgetRoot.FindHandler(SCR_BudgetProgressEditorUIComponent));
34 
35  // Setup budget
36  m_BudgetManager = SCR_BudgetEditorComponent.Cast(SCR_BudgetEditorComponent.GetInstance(SCR_BudgetEditorComponent, false, true));
37  if (m_BudgetManager)
38  {
39  InitializeBudgets();
40  m_BudgetManager.Event_OnBudgetUpdated.Insert(OnBudgetUpdate);
41  m_BudgetManager.Event_OnBudgetMaxUpdated.Insert(OnBudgetMaxUpdate);
42  m_BudgetManager.Event_OnBudgetPreviewUpdated.Insert(OnBudgetPreviewUpdate);
43  m_BudgetManager.Event_OnBudgetPreviewReset.Insert(ResetWidgetPreviewData);
44  }
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  override void HandlerDeattached(Widget w)
49  {
50  if (!m_BudgetManager)
51  return;
52 
53  m_BudgetManager.Event_OnBudgetUpdated.Remove(OnBudgetUpdate);
54  m_BudgetManager.Event_OnBudgetMaxUpdated.Remove(OnBudgetMaxUpdate);
55  m_BudgetManager.Event_OnBudgetPreviewUpdated.Remove(OnBudgetPreviewUpdate);
56  m_BudgetManager.Event_OnBudgetPreviewReset.Remove(ResetWidgetPreviewData);
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  override protected bool IsUnique()
61  {
62  return false;
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  // Protected
67  //------------------------------------------------------------------------------------------------
68 
69  //------------------------------------------------------------------------------------------------
70  protected void InitializeBudgets()
71  {
72  if (!m_CampaignBuildingComponent || !m_BudgetManager)
73  return;
74 
75  SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(m_CampaignBuildingComponent.GetProviderComponent());
76  if (!providerComponent)
77  return;
78 
79  EEditableEntityBudget budgetToShow = m_CampaignBuildingComponent.GetShownBudget();
80  if (budgetToShow == INVALID_BUDGET)
81  {
82  m_BudgetProgress.GetRootWidget().SetVisible(false);
83  return;
84  }
85 
86  SetBudgetType(budgetToShow);
87 
88  // Setup values
89  m_iCurrentBudget = m_BudgetManager.GetCurrentBudgetValue(m_BudgetType);
90  m_BudgetManager.GetMaxBudgetValue(m_BudgetType, m_iMaxBudget);
91 
92  if (!m_CampaignBuildingComponent)
93  return;
94 
95  m_BudgetProgress.HideBudgetChange();
96 
97  if (m_iMaxBudget != 0)
98  m_BudgetProgress.ShowBudget(m_iCurrentBudget / m_iMaxBudget);
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  // Callback
103  //------------------------------------------------------------------------------------------------
104 
105  //------------------------------------------------------------------------------------------------
106  protected void OnBudgetUpdate(EEditableEntityBudget budgetType, int originalBudgetValue, int updatedBudgetValue, int maxBudgetValue)
107  {
108  m_iCurrentBudget = m_BudgetManager.GetCurrentBudgetValue(m_BudgetType);
109  m_BudgetManager.GetMaxBudgetValue(m_BudgetType, m_iMaxBudget);
110 
111  m_BudgetProgress.HideBudgetChange();
112  m_BudgetProgress.ShowBudget(m_iCurrentBudget / m_iMaxBudget);
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  protected void OnBudgetMaxUpdate(EEditableEntityBudget budgetType, int currentBudgetValue, int maxBudgetValue)
117  {
118  m_BudgetManager.GetMaxBudgetValue(m_BudgetType, m_iMaxBudget);
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  protected void OnBudgetPreviewUpdate(EEditableEntityBudget budgetType, float previewBudgetValue, float budgetChange)
123  {
124  if (m_BudgetType != budgetType)
125  return;
126 
127  m_BudgetProgress.ShowBudgetChange(budgetChange, previewBudgetValue);
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  protected void ResetWidgetPreviewData()
132  {
133  m_BudgetProgress.HideBudgetChange();
134  }
135 
136  //------------------------------------------------------------------------------------------------
138  protected void SetBudgetUIIcon(EEditableEntityBudget budgetType)
139  {
140  if (!m_BudgetManager || !m_BudgetProgress)
141  return;
142 
143  SCR_EditableEntityCoreBudgetSetting budgetSettings = m_BudgetManager.GetBudgetSetting(budgetType);
144  if (!budgetSettings)
145  return;
146 
147  SCR_UIInfo info = budgetSettings.GetInfo();
148  if (!info)
149  return;
150 
151  info.SetIconTo(m_BudgetProgress.GetIconWidhget());
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  // Public
156  //------------------------------------------------------------------------------------------------
157 
158  //------------------------------------------------------------------------------------------------
160  void SetBudgetType(EEditableEntityBudget type)
161  {
162  m_BudgetType = type;
163  SetBudgetUIIcon(m_BudgetType);
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  EEditableEntityBudget GetBudgetType()
168  {
169  return m_BudgetType;
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  SCR_BudgetProgressEditorUIComponent GetUIComponent()
174  {
175  return m_BudgetProgress;
176  }
177 }
SCR_EditableEntityCoreBudgetSetting
Definition: SCR_EditableEntityCoreBudgetSetting.c:2
SCR_BudgetProgressEditorUIComponent
Definition: SCR_BudgetProgressEditorUIComponent.c:1
SCR_BudgetUIComponent
Component to display budget progress.
Definition: SCR_BudgetUIComponent.c:2
EEditableEntityBudget
EEditableEntityBudget
Definition: EEditableEntityBudget.c:1
SCR_BudgetEditorComponent
Definition: SCR_BudgetEditorComponent.c:18
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_CampaignBuildingComponent
protected SCR_CampaignBuildingEditorComponent m_CampaignBuildingComponent
Definition: SCR_CampaignBuildingBudgetEditorComponent.c:9
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
m_BudgetType
protected EEditableEntityBudget m_BudgetType
Definition: SCR_CampaignBuildingManagerComponent.c:20