Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ButtonSpecializationProgressComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  protected RichTextWidget m_wSpecializationTitle;
5  protected RichTextWidget m_wSpecializationValue;
6  protected SCR_ProgressBarWithInactiveColor m_SpecializationBar;
7 
8  protected const float m_fMinValue = 0;
9  protected const float m_fMaxValue = 100;
10 
11  protected int m_ibuttonId;
12 
13  [Attribute()]
14  protected bool m_bIsActive;
15 
16  [Attribute("1 1 1 1", UIWidgets.ColorPicker)]
17  protected ref Color m_ColorInactive;
18 
19  [Attribute("1 1 1 0.3", UIWidgets.ColorPicker)]
20  protected ref Color m_ColorInactiveHovered;
21 
22  [Attribute("0.898 0.541 0.184 1", UIWidgets.ColorPicker)]
23  protected ref Color m_ColorActive;
24 
25  // Arguments passed: m_ibuttonId
26  protected ref ScriptInvoker m_OnClicked = new ScriptInvoker();
27 
28  // Arguments passed: m_ibuttonId, bool isHovered
29  protected ref ScriptInvoker m_OnMouseEnter = new ScriptInvoker();
30  protected ref ScriptInvoker m_OnMouseLeave = new ScriptInvoker();
31 
32  //------------------------------------------------------------------------------------------------
33  protected override void HandlerAttached(Widget w)
34  {
35  super.HandlerAttached(w);
36 
37  m_wSpecializationTitle = RichTextWidget.Cast(w.FindAnyWidget("SpecializationTitle"));
38  if (!m_wSpecializationTitle)
39  return;
40 
41  m_wSpecializationValue = RichTextWidget.Cast(w.FindAnyWidget("SpecializationValue"));
42  if (!m_wSpecializationValue)
43  return;
44 
45  m_wSpecializationTitle.SetText("");
46  m_wSpecializationTitle.SetColor(m_ColorInactive);
47  m_wSpecializationValue.SetText("");
48  m_wSpecializationValue.SetColor(m_ColorInactive);
49 
50  m_SpecializationBar = SCR_ProgressBarWithInactiveColor.Cast(SCR_WLibProgressBarComponent.GetProgressBar("SpecializationProgressBar", w, true));
51  if (!m_SpecializationBar)
52  return;
53 
54  m_SpecializationBar.SetMin(m_fMinValue);
55  m_SpecializationBar.SetMax(m_fMaxValue);
56  m_SpecializationBar.SetActive(false);
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  ScriptInvoker GetOnClicked()
61  {
62  return m_OnClicked;
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  protected override bool OnClick(Widget w, int x, int y, int button)
67  {
68  super.OnClick(w, x, y, button);
69  if (button != 0)
70  return false;
71 
72  m_OnClicked.Invoke(m_ibuttonId);
73 
74  return false;
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  void Activate(bool animate = true)
79  {
80  if (m_bIsActive)
81  return;
82 
83  m_bIsActive = true;
84  PlaySound(m_sSoundClicked);
85 
86  if (animate)
87  {
88  AnimateWidget.Color(m_wSpecializationValue, m_ColorActive, m_fAnimationRate);
89  AnimateWidget.Color(m_wSpecializationTitle, m_ColorActive, m_fAnimationRate);
90  m_SpecializationBar.SetActive(true);
91  }
92  else
93  {
94  AnimateWidget.StopAnimation(m_wSpecializationValue, WidgetAnimationColor);
95  m_wSpecializationValue.SetColor(m_ColorActive);
96 
97  AnimateWidget.StopAnimation(m_wSpecializationTitle, WidgetAnimationColor);
98  m_wSpecializationTitle.SetColor(m_ColorActive);
99 
100  m_SpecializationBar.SetActive(true);
101  }
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  void Deactivate(bool animate = true)
106  {
107  if (!m_bIsActive)
108  return;
109 
110  m_bIsActive = false;
111  PlaySound(m_sSoundClicked);
112 
113  if (animate)
114  {
115  AnimateWidget.Color(m_wSpecializationValue, m_ColorInactive, m_fAnimationRate);
116  AnimateWidget.Color(m_wSpecializationTitle, m_ColorInactive, m_fAnimationRate);
117  m_SpecializationBar.SetActive(false);
118  }
119  else
120  {
121  AnimateWidget.StopAnimation(m_wSpecializationValue, WidgetAnimationColor);
122  m_wSpecializationValue.SetColor(m_ColorInactive);
123 
124  AnimateWidget.StopAnimation(m_wSpecializationTitle, WidgetAnimationColor);
125  m_wSpecializationValue.SetColor(m_ColorInactive);
126 
127  m_SpecializationBar.SetActive(false);
128  }
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  protected override bool OnMouseEnter(Widget w, int x, int y)
133  {
134  super.OnMouseEnter(w, x, y);
135  m_OnMouseEnter.Invoke(m_ibuttonId, true);
136  return false;
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  protected override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
141  {
142  super.OnMouseLeave(w, enterW, x, y);
143 
144  m_OnMouseLeave.Invoke(m_ibuttonId, false);
145  return false;
146  }
147 
148  //------------------------------------------------------------------------------------------------
149  void Hide()
150  {
151  m_wSpecializationValue.SetOpacity(0);
152  m_wSpecializationTitle.SetOpacity(0);
153  m_SpecializationBar.Hide();
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  void Unhide()
158  {
159  m_wSpecializationValue.SetOpacity(255);
160  m_wSpecializationTitle.SetOpacity(255);
161  m_SpecializationBar.Unhide();
162  }
163 
164  //------------------------------------------------------------------------------------------------
165  void SetOnHover(bool OnHover = true)
166  {
167  if(m_bIsActive)
168  return;
169 
170  if (OnHover)
171  {
172  AnimateWidget.Color(m_wSpecializationValue, m_ColorInactiveHovered, m_fAnimationRate);
173  AnimateWidget.Color(m_wSpecializationTitle, m_ColorInactiveHovered, m_fAnimationRate);
174  GetGame().GetCallqueue().CallLater(m_SpecializationBar.SetOnHover, m_fAnimationRate, false, true);
175  return;
176  }
177 
178  AnimateWidget.Color(m_wSpecializationValue, m_ColorInactive, m_fAnimationRate);
179  AnimateWidget.Color(m_wSpecializationTitle, m_ColorInactive, m_fAnimationRate);
180  GetGame().GetCallqueue().CallLater(m_SpecializationBar.SetOnHover, m_fAnimationRate, false, false);
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  ScriptInvoker GetOnMouseEnter()
185  {
186  return m_OnMouseEnter;
187  }
188 
189  //------------------------------------------------------------------------------------------------
190  ScriptInvoker GetOnMouseLeave()
191  {
192  return m_OnMouseLeave;
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  void SetTitle(string text)
197  {
198  if (!m_wSpecializationTitle)
199  return;
200 
201  m_wSpecializationTitle.SetText(text);
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  void SetValue(float num)
206  {
207  if (!m_wSpecializationValue || !m_SpecializationBar)
208  return;
209 
210  m_wSpecializationValue.SetText(""+num.ToString(-1, 2)+"%");
211 
212  m_SpecializationBar.SetValue(num);
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  void SetButtonId(int n)
217  {
218  if (n < 0 || n > SCR_PlayerDataConfigs.GetInstance().SPECIALIZATIONS_COUNT)
219  {
220  Print ("SCR_ButtonSpecializationProgress: Trying to create a Specialization Progress button for a non-valid specialization id", LogLevel.ERROR);
221  return;
222  }
223 
224  m_ibuttonId = n;
225  SetTitle(""+(n+1)+". "+"#AR-CareerProfile_Specialization"+(n+1));
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  void SetFocus()
230  {
231  WorkspaceWidget workspace = GetGame().GetWorkspace();
232  if (!workspace)
233  return;
234 
235  GetGame().GetCallqueue().CallLater(workspace.SetFocusedWidget, 1000, false, m_wRoot, true);
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  int GetButtonId()
240  {
241  return m_ibuttonId;
242  }
243 };
PlaySound
SCR_ParticleContactComponentClass ScriptComponentClass PlaySound(IEntity owner, SCR_ParticleContactComponentClass prefabData, Contact contact)
Definition: SCR_ParticleContactComponent.c:38
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnHover
protected void OnHover(EEditableEntityState state, set< SCR_EditableEntityComponent > entitiesInsert, set< SCR_EditableEntityComponent > entitiesRemove)
Definition: SCR_TooltipManagerEditorUIComponent.c:154
m_OnMouseEnter
ref ScriptInvoker m_OnMouseEnter
Definition: SCR_ModularButtonComponent.c:65
SCR_PlayerDataConfigs
Definition: SCR_PlayerDataConfigs.c:102
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ProgressBarWithInactiveColor
Definition: SCR_WLibProgressBarWithInactiveColor.c:2
SCR_WLibProgressBarComponent
Minimalist progress bar.
Definition: SCR_WLibProgressBar.c:3
m_bIsActive
SCR_HintSequenceComponentClass m_bIsActive
m_OnClicked
ref ScriptInvoker m_OnClicked
Definition: SCR_ModularButtonComponent.c:60
m_OnMouseLeave
ref ScriptInvoker m_OnMouseLeave
Definition: SCR_ModularButtonComponent.c:66
SCR_ButtonSpecializationProgressComponent
Definition: SCR_ButtonSpecializationProgressComponent.c:2