Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ListMenuEntryComponent.c
Go to the documentation of this file.
1 /*
2 Base class for Scenario and Server list menu entries
3 */
6 typedef ScriptInvokerBase<ScriptInvokerListMenuEntryMethod> ScriptInvokerListMenuEntry;
7 
8 //------------------------------------------------------------------------------------------------
10 {
11  protected ref SCR_ModularButtonComponent m_FavComponent;
12 
13  protected bool m_bIsInErrorState; //Entry is enabled, but some of it's buttons are unavailable. Useful for disabling multiple mouse buttons based on one condition. TODO: make it a state of modular buttons
14 
15  // Text scrolling anims
16  protected ref array<ref SCR_HorizontalScrollAnimationComponent> m_aScrollAnimations = {};
17 
18  // Mouse buttons
19  // These arrays need to be filled by child classes with the specific buttons
20  protected bool m_bInnerButtonInteraction;
21  protected ref array<SCR_ModularButtonComponent> m_aMouseButtons = {};
22  protected ref array<SCR_ModularButtonComponent> m_aMouseButtonsError = {};
23 
24  // Main
25  protected SCR_ModularButtonComponent m_MainModularButton;
26  protected bool m_bFavorite;
27  protected bool m_bDisabled; //Entry is unavailable but the widget still needs to be interactable. TODO: clean up confusing naming
28  protected bool m_bFocused;
29  protected bool m_bMouseButtonsEnabled = true;
30 
31  // Tooltip
32  protected SCR_ScriptedWidgetTooltip m_CurrentTooltip;
33 
34  // Invokers
35  // Called when a mouse interaction button is pressed
36  protected ref ScriptInvokerString m_OnMouseInteractionButtonClicked;
37 
38  protected ref ScriptInvokerScriptedWidgetComponent m_OnFocus;
39  protected ref ScriptInvokerScriptedWidgetComponent m_OnFocusLost;
40  protected ref ScriptInvokerListMenuEntry m_OnFavorite;
41 
42  // ---- OVERRIDES ----
43  //------------------------------------------------------------------------------------------------
44  override void HandlerAttached(Widget w)
45  {
46  // Setup scroll animations
47  EnableTextAnimations(false);
48 
49  // Mouse Buttons
50  SCR_ButtonEffectColor colorEffect;
51  foreach (SCR_ModularButtonComponent button : m_aMouseButtons)
52  {
53  button.m_OnMouseEnter.Insert(OnInnerButtonHover);
54  button.m_OnMouseLeave.Insert(OnInnerButtonLeave);
55  }
56 
57  // Favorite button
58  if (m_FavComponent)
59  m_FavComponent.m_OnClicked.Insert(OnFavoriteClicked);
60 
61  super.HandlerAttached(w);
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  override void HandlerDeattached(Widget w)
66  {
67  if (m_OnFocus)
68  m_OnFocus.Clear();
69 
70  if (m_OnFocusLost)
71  m_OnFocusLost.Clear();
72 
73  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnTooltipShow);
74 
75  super.HandlerDeattached(w);
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  override bool OnClick(Widget w, int x, int y, int button)
80  {
81  // LMB check
82  if (button != 0 || m_bInnerButtonInteraction)
83  return false;
84 
85  return super.OnClick(w, x, y, button);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override bool OnDoubleClick(Widget w, int x, int y, int button)
90  {
91  // LMB check
92  if (button != 0 || m_bInnerButtonInteraction)
93  return false;
94 
95  return super.OnDoubleClick(w, x, y, button);
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  override bool OnFocus(Widget w, int x, int y)
100  {
101  if (m_OnFocus)
102  m_OnFocus.Invoke(this);
103 
104  m_bFocused = true;
105  UpdateModularButtons();
106 
107  if (!m_aScrollAnimations.IsEmpty())
108  EnableTextAnimations(true);
109 
110  // Tooltips
111  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Insert(OnTooltipShow);
112 
113  return super.OnFocus(w, x, y);
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  override bool OnFocusLost(Widget w, int x, int y)
118  {
119  if (m_OnFocusLost)
120  m_OnFocusLost.Invoke(this);
121 
122  m_bFocused = false;
123  UpdateModularButtons();
124 
125  // Stop anim
126  EnableTextAnimations(false);
127 
128  // Tooltips
129  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnTooltipShow);
130 
131  return super.OnFocusLost(w, x, y);
132  }
133 
134  // ---- PROTECTED ----
135  //------------------------------------------------------------------------------------------------
136  protected void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
137  {
138  m_CurrentTooltip = tooltipClass;
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  protected void OnInnerButtonHover()
143  {
144  m_bInnerButtonInteraction = true;
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  protected void OnInnerButtonLeave()
149  {
150  m_bInnerButtonInteraction = false
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  protected void OnFavoriteClicked(SCR_ModularButtonComponent comp)
155  {
156  SetFavorite(!m_bFavorite);
157  }
158 
159  // ----
160  //------------------------------------------------------------------------------------------------
162  protected void EnableTextAnimations(bool enable)
163  {
164  foreach (SCR_HorizontalScrollAnimationComponent anim : m_aScrollAnimations)
165  {
166  HandleTextAnimation(anim, enable);
167  }
168  }
169 
170  //------------------------------------------------------------------------------------------------
173  protected void HandleTextAnimation(SCR_HorizontalScrollAnimationComponent anim, bool enable)
174  {
175  if (!anim)
176  return;
177 
178  if (enable)
179  {
180  if (!anim.GetContentFit())
181  {
182  anim.AnimationStart();
183  }
184  else
185  {
186  anim.AnimationStop();
187  anim.ResetPosition();
188  }
189 
190  return;
191  }
192 
193  // Disabled
194  anim.AnimationStop();
195  anim.ResetPosition();
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  protected void UpdateModularButtons()
200  {
201  SCR_ListEntryHelper.UpdateMouseButtons(m_aMouseButtons, m_aMouseButtonsError, m_bIsInErrorState, m_bFocused);
202 
203  // --- Main elements color ---
204  // Toggling the line's main modular button component is used as a quck way to change the line's elements while mantaining it active (they inherit color)
205  if (!m_MainModularButton)
206  m_MainModularButton = SCR_ModularButtonComponent.FindComponent(m_wRoot);
207  if (!m_MainModularButton)
208  return;
209 
210  m_MainModularButton.SetToggled(m_bDisabled, false);
211 
212  // Name
213  Color color = Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt());
214  if (m_bDisabled)
215  color = Color.FromInt(UIColors.IDLE_DISABLED.PackToInt());
216 
217  SCR_ButtonEffectColor nameEffect = SCR_ButtonEffectColor.Cast(m_MainModularButton.FindEffect(SCR_ListEntryHelper.EFFECT_NAME_COLOR));
218  if (nameEffect)
219  nameEffect.m_cFocusLost = color;
220 
221  // Elements
222  if (!m_bDisabled)
223  color = Color.FromInt(UIColors.NEUTRAL_ACTIVE_STANDBY.PackToInt());
224 
225  array<SCR_ButtonEffectBase> effects = m_MainModularButton.FindAllEffects(SCR_ListEntryHelper.EFFECT_WRAPPER_COLOR);
226  if (effects.IsEmpty())
227  return;
228 
229  foreach (SCR_ButtonEffectBase effect : effects)
230  {
231  SCR_ButtonEffectColor colorEffect = SCR_ButtonEffectColor.Cast(effect);
232  if (colorEffect)
233  colorEffect.m_cFocusLost = color;
234  }
235 
236  m_MainModularButton.InvokeAllEnabledEffects(false);
237  }
238 
239  //------------------------------------------------------------------------------------------------
240  protected void OpacityAnimation(int time, float opacityEnd)
241  {
242  AnimateWidget.Opacity(GetRootWidget(), opacityEnd, time);
243  }
244 
245  // ---- PUBLIC ----
246  //------------------------------------------------------------------------------------------------
248  void AnimateOpacity(int delay, float animationTime, float opacityEnd, float opacityStart = -1)
249  {
250  if (opacityStart != -1)
251  GetRootWidget().SetOpacity(opacityStart);
252 
253  GetGame().GetCallqueue().Remove(OpacityAnimation);
254 
255  // Start animating with a delay to prevent flickering
256  GetGame().GetCallqueue().CallLater(OpacityAnimation, delay, false, animationTime, opacityEnd);
257  }
258 
259  //------------------------------------------------------------------------------------------------
260  void ShowMouseInteractionButtons(bool show)
261  {
262  m_bMouseButtonsEnabled = show;
263  UpdateModularButtons();
264  }
265 
266  //------------------------------------------------------------------------------------------------
267  bool SetFavorite(bool favorite)
268  {
269  if (m_FavComponent)
270  m_FavComponent.SetToggled(favorite);
271 
272  if (m_bFavorite == favorite)
273  return false;
274 
275  m_bFavorite = favorite;
276 
277  if (m_OnFavorite)
278  m_OnFavorite.Invoke(this, favorite);
279 
280  return true;
281  }
282 
283  //------------------------------------------------------------------------------------------------
284  bool IsInnerButtonInteraction()
285  {
286  return m_bInnerButtonInteraction;
287  }
288 
289  //------------------------------------------------------------------------------------------------
290  bool IsFavorite()
291  {
292  return m_bFavorite;
293  }
294 
295  //------------------------------------------------------------------------------------------------
296  bool IsInErrorState()
297  {
298  return m_bIsInErrorState;
299  }
300 
301  //------------------------------------------------------------------------------------------------
302  ScriptInvokerString GetOnMouseInteractionButtonClicked()
303  {
304  if (!m_OnMouseInteractionButtonClicked)
305  m_OnMouseInteractionButtonClicked = new ScriptInvokerString();
306 
307  return m_OnMouseInteractionButtonClicked;
308  }
309 
310  //------------------------------------------------------------------------------------------------
312  {
313  if (!m_OnFocus)
315 
316  return m_OnFocus;
317  }
318 
319  //------------------------------------------------------------------------------------------------
320  ScriptInvokerScriptedWidgetComponent GetOnFocusLost()
321  {
322  if (!m_OnFocusLost)
324 
325  return m_OnFocusLost;
326  }
327 
328  //------------------------------------------------------------------------------------------------
329  ScriptInvokerListMenuEntry GetOnFavorite()
330  {
331  if (!m_OnFavorite)
333 
334  return m_OnFavorite;
335  }
336 }
ScriptInvokerListMenuEntry
ScriptInvokerBase< ScriptInvokerListMenuEntryMethod > ScriptInvokerListMenuEntry
Definition: SCR_ListMenuEntryComponent.c:6
SCR_HorizontalScrollAnimationComponent
Definition: SCR_HorizontalScrollAnimationComponent.c:14
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ListEntryHelper
Definition: SCR_ScenarioEntryHelper.c:1
func
func
Definition: SCR_AIThreatSystem.c:5
m_OnFocusLost
ref ScriptInvoker m_OnFocusLost
Definition: SCR_ModularButtonComponent.c:64
SCR_ButtonEffectColor
Effect which colorizes a widget with given name.
Definition: SCR_ButtonEffectColor.c:3
m_OnFavorite
protected ref ScriptInvokerMissionWorkshopItem m_OnFavorite
Definition: SCR_ScenarioDialogs.c:44
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
UIColors
Definition: Constants.c:16
ScriptInvokerString
ScriptInvokerBase< ScriptInvokerStringMethod > ScriptInvokerString
Definition: SCR_ScriptInvokerHelper.c:75
ScriptInvokerListMenuEntryMethod
func ScriptInvokerListMenuEntryMethod
Definition: SCR_ListMenuEntryComponent.c:5
SCR_ListMenuEntryComponent
Definition: SCR_ListMenuEntryComponent.c:9
m_OnFocus
ref ScriptInvoker m_OnFocus
Definition: SCR_ModularButtonComponent.c:63
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
ScriptInvokerScriptedWidgetComponent
ScriptInvokerBase< ScriptInvokerScriptedWidgetComponentMethod > ScriptInvokerScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:4