Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ButtonEffectBase.c
Go to the documentation of this file.
1 //#define DEBUG_MODULAR_BUTTON
2 
6 {
7  // These events can coexist, unlike states in EModularButtonState
8  EVENT_CLICKED = 1 << 10,
9  EVENT_FOCUS_GAINED = 1 << 11,
10  EVENT_FOCUS_LOST = 1 << 12,
11  EVENT_TOGGLED_ON = 1 << 13,
12  EVENT_TOGGLED_OFF = 1 << 14,
13  EVENT_MOUSE_ENTER = 1 << 15,
14  EVENT_MOUSE_LEAVE = 1 << 16 // !!! This must be the last flag! Base Container formatting relies on this.
15 }
16 
18 enum EModularButtonInputDevice
19 {
20  KEYBOARD = 1 << 0,
21  MOUSE = 1 << 1,
22  GAMEPAD = 1 << 2,
23  JOYSTICK = 1 << 3
24 }
25 
29 class SCR_ButtonEffectBase
30 {
31  [Attribute("true", UIWidgets.CheckBox, "Enables this effect")]
32  protected bool m_bEnabled;
33 
34  [Attribute("", UIWidgets.EditBox, "Array of tags, can be used to find this effect or manipulate many effects at a time")]
35  ref array<string> m_aTags;
36 
37  [Attribute("0", UIWidgets.Flags, "Events this effect will listen to.", "", ParamEnumArray.FromEnum(EModularButtonEventFlag) )]
38  EModularButtonEventFlag m_eEvents;
39 
40  [Attribute("63", UIWidgets.Flags, "Input devices which can trigger this effect.", "", ParamEnumArray.FromEnum(EModularButtonInputDevice)) ]
41  EModularButtonInputDevice m_eInputDevices;
42 
43  protected SCR_ModularButtonComponent m_Button; // Parent button which owns this effect
44 
45  // Public API
46 
47  //------------------------------------------------------------------------------------------------
49  bool GetEnabled()
50  {
51  return m_bEnabled;
52  }
53 
54  //------------------------------------------------------------------------------------------------
56  void SetEnabled(bool enabled)
57  {
58  #ifdef DEBUG_MODULAR_BUTTON
59  _print(string.Format("SetEnabled: %1", enabled));
60  #endif
61 
62  bool enabledPrev = m_bEnabled;
63  m_bEnabled = enabled;
64 
65  if (enabled != enabledPrev)
66  {
67  if (enabled)
68  m_Button.Internal_OnEffectEnabled(this);
69  else
70  OnDisabled();
71  }
72  }
73 
74  //---------------------------------------------------------------------------------------------
76  void PropertiesChanged()
77  {
78  if (m_bEnabled)
79  {
80  m_Button.Internal_OnEffectEnabled(this);
81  }
82  }
83 
84  //---------------------------------------------------------------------------------------------
86  bool HasTag(string tag)
87  {
88  return m_aTags.Contains(tag);
89  }
90 
91  //---------------------------------------------------------------------------------------------
92  // Override these methods in inherited classes
93  // Instant - when true, means that the effect must be applied immediately (without animations).
94  // Typically instant = true at start of the menu.
95  protected void OnStateDefault(bool instant);
96  protected void OnStateHovered(bool instant);
97  protected void OnStateActivated(bool instant);
98  protected void OnStateActivatedHovered(bool instant);
99  protected void OnStateDisabled(bool instant);
100  protected void OnStateDisabledActivated(bool instant);
101  protected void OnClicked(bool instant);
102  protected void OnFocusGained(bool instant);
103  protected void OnFocusLost(bool instant);
104  protected void OnToggledOn(bool instant);
105  protected void OnToggledOff(bool instant);
106  protected void OnMouseEnter(bool instant);
107  protected void OnMouseLeave(bool instant);
108 
109  //------------------------------------------------------------------------------------------------
111  // Called when parent of this effect is attached to a widget
112  void OnHandlerAttached(Widget w);
113 
114  //------------------------------------------------------------------------------------------------
115  // Called when effect is disabled. Here you should stop all running effects.
116  void OnDisabled();
117 
118  // Internal methods
119 
120  //------------------------------------------------------------------------------------------------
125  bool Internal_OnEvent(EModularButtonEventFlag eventFlag, EInputDeviceType deviceType, bool instant = false)
126  {
127  #ifdef DEBUG_MODULAR_BUTTON
128  _print(string.Format("Internal_OnEvent: %1, %2, %3", typename.EnumToString(EModularButtonEventFlag, eventFlag), typename.EnumToString(EInputDeviceType, deviceType), instant));
129  #endif
130 
131  // Filter out input device
132  // But we ignore this check if instant flag is set
133  if (!instant)
134  {
135  EModularButtonInputDevice deviceFlag;
136  switch (deviceType)
137  {
138  case EInputDeviceType.KEYBOARD: deviceFlag = EModularButtonInputDevice.KEYBOARD; break;
139  case EInputDeviceType.MOUSE: deviceFlag = EModularButtonInputDevice.MOUSE; break;
140  case EInputDeviceType.GAMEPAD: deviceFlag = EModularButtonInputDevice.GAMEPAD; break;
141  case EInputDeviceType.JOYSTICK: deviceFlag = EModularButtonInputDevice.JOYSTICK; break;
142  }
143 
144  // Bail if this effect does not listen to this input type
145  if ((deviceFlag & m_eInputDevices) == 0)
146  {
147  #ifdef DEBUG_MODULAR_BUTTON
148  _print("Event ignored: device input type doesn't match.");
149  #endif
150 
151  return false;
152  }
153  }
154 
155  if (eventFlag & m_eEvents)
156  {
157  #ifdef DEBUG_MODULAR_BUTTON
158  _print("Event passed");
159  #endif
160  switch (eventFlag)
161  {
162  case EModularButtonEventFlag.STATE_DEFAULT : { OnStateDefault(instant); break; }
163  case EModularButtonEventFlag.STATE_HOVERED : { OnStateHovered(instant); break; }
164  case EModularButtonEventFlag.STATE_ACTIVATED : { OnStateActivated(instant); break; }
165  case EModularButtonEventFlag.STATE_ACTIVATED_HOVERED : { OnStateActivatedHovered(instant); break; }
166  case EModularButtonEventFlag.STATE_DISABLED : { OnStateDisabled(instant); break; }
167  case EModularButtonEventFlag.STATE_DISABLED_ACTIVATED : { OnStateDisabledActivated(instant); break; }
168  case EModularButtonEventFlag.EVENT_CLICKED : { OnClicked(instant); break; }
169  case EModularButtonEventFlag.EVENT_FOCUS_GAINED : { OnFocusGained(instant); break; }
170  case EModularButtonEventFlag.EVENT_FOCUS_LOST : { OnFocusLost(instant); break; }
171  case EModularButtonEventFlag.EVENT_TOGGLED_ON : { OnToggledOn(instant); break; }
172  case EModularButtonEventFlag.EVENT_TOGGLED_OFF : { OnToggledOff(instant); break; }
173  case EModularButtonEventFlag.EVENT_MOUSE_ENTER : { OnMouseEnter(instant); break; }
174  case EModularButtonEventFlag.EVENT_MOUSE_LEAVE : { OnMouseLeave(instant); break; }
175  }
176  return true;
177  }
178  else
179  {
180  return false;
181  }
182  }
183 
184  //------------------------------------------------------------------------------------------------
187  void Init(SCR_ModularButtonComponent parentButton)
188  {
189  m_Button = parentButton;
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  protected void _print(string s)
194  {
195  string tagsStr;
196 
197  foreach (string tag : m_aTags)
198  {
199  tagsStr = tagsStr + string.Format("'%1' ", tag);
200  }
201 
202  m_Button._print(string.Format("Effect %1 %2: %3", this, tagsStr, s));
203  }
204 }
205 
208 class SCR_ButtonEffectWidgetBase : SCR_ButtonEffectBase
209 {
210  [Attribute("", UIWidgets.Auto, "Widget name to apply the effect on")]
211  protected string m_sWidgetName;
212 
213  protected Widget m_wTarget;
214 
215  //------------------------------------------------------------------------------------------------
216  override void OnHandlerAttached(Widget w)
217  {
218  if (!m_sWidgetName.IsEmpty())
219  m_wTarget = w.FindAnyWidget(m_sWidgetName);
220  }
221 
222  //------------------------------------------------------------------------------------------------
224  Widget GetTargetWidget()
225  {
226  return m_wTarget;
227  }
228 }
229 
232 class SCR_ButtonEffectTitleAttribute : BaseContainerCustomTitle
233 {
234  protected string m_sTypeStr;
235  protected string m_sVarName;
236 
237  //------------------------------------------------------------------------------------------------
238  // constructor
241  void SCR_ButtonEffectTitleAttribute(string typeStr, string varName)
242  {
243  m_sTypeStr = typeStr;
244  m_sVarName = varName;
245  }
246 
247  //------------------------------------------------------------------------------------------------
248  override bool _WB_GetCustomTitle(BaseContainer source, out string title)
249  {
250  // Generate string according to enabled state
251  string strEnabled;
252  bool enabled;
253  source.Get("m_bEnabled", enabled);
254  if (enabled)
255  strEnabled = "[X]";
256  else
257  strEnabled = "[ ]";
258 
259  // Generate string with event flags: "(ON_SOMETHING, ON_SOMETHING_ELSE)"
260  string strFlags;
261  int events;
262  source.Get("m_eEvents", events);
263  int flag = 1;
264  int endFlag = EModularButtonEventFlag.EVENT_MOUSE_LEAVE << 1;
265  int nFlagsAdded = 0;
266  while (flag != endFlag)
267  {
268  if (events & flag)
269  {
270  if (nFlagsAdded > 0)
271  strFlags = strFlags + ", ";
272 
273  string enumStr = typename.EnumToString(EModularButtonEventFlag, flag);
274  enumStr.ToLower();
275  strFlags = strFlags + enumStr;
276  nFlagsAdded++;
277  }
278 
279  flag = flag << 1;
280  }
281 
282  // Generate string from tags
283  string strTags;
284  array<string> tags;
285  source.Get("m_aTags", tags);
286  if (tags)
287  {
288  foreach (string t : tags)
289  {
290  strTags = strTags + string.Format("'%1' ", t);
291  }
292  }
293 
294  string targetWidgetName;
295  if (!m_sVarName.IsEmpty())
296  {
297  // Variable name was provided, try to get value of a variable with name m_sVarName
298 
299  source.Get(m_sVarName, targetWidgetName);
300 
301  string strOut;
302 
303  if (!targetWidgetName.IsEmpty())
304  strOut = string.Format("%1 %2: %3 %4 (%5)", strEnabled, m_sTypeStr, strTags, targetWidgetName, strFlags);
305  else
306  strOut = string.Format("%1 (E) %2: %3 Widget name not specified!", strEnabled, m_sTypeStr, strTags);
307 
308  title = strOut;
309 
310  return true;
311  }
312  else
313  {
314  title = string.Format("%1 %2: %3 (%4)", strEnabled, m_sTypeStr, strTags, strFlags);
315  return true;
316  }
317 
318  return true;
319  }
320 }
321 
322 /*
323 Template effect:
324 
325 [BaseContainerProps()]
326 class SCR_ModularButtonEffect_Example : SCR_ModularButtonEffectBase
327 {
328  override void OnHandlerAttached(Widget w)
329  {
330  }
331 
332  // Events below are called according to the m_eEvents flags!
333  // Make sure you set them up!
334 
335  override void OnStateDefault(bool instant)
336  {
337  }
338 
339  override void OnStateHovered(bool instant)
340  {
341  }
342 
343  override void OnStateActivated(bool instant)
344  {
345  }
346 
347  override void OnStateActivatedHovered(bool instant)
348  {
349  }
350 
351  override void OnStateDisabled(bool instant)
352  {
353  }
354 
355  override void OnStateDisabledActivated(bool instant)
356  {
357  }
358 
359  override void OnClicked(bool instant)
360  {
361  }
362 
363  override void OnFocusGained(bool instant)
364  {
365  }
366 
367  override void OnFocusLost(bool instant)
368  {
369  }
370 
371  override void OnToggledOn(bool instant)
372  {
373  }
374 
375  override void OnToggledOff(bool instant)
376  {
377  }
378 
379  // Called when effect is disabled. Here you should stop all running effects.
380  override void OnDisabled()
381  {
382  }
383 }
384 */
OnDisabled
void OnDisabled()
Definition: SCR_CampaignMilitaryBaseComponent.c:557
OnStateDisabledActivated
override void OnStateDisabledActivated(bool instant)
Definition: SCR_ButtonEffectImage.c:66
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: SCR_EntitiesEditorUIComponent.c:99
OnFocusGained
override void OnFocusGained(bool instant)
Definition: SCR_ButtonEffectImage.c:72
KEYBOARD
enum EModularButtonEventFlag KEYBOARD
Flags for device input types.
SetEnabled
void SetEnabled(bool enabled)
Definition: SCR_BaseManualCameraComponent.c:91
MOUSE
enum EModularButtonEventFlag MOUSE
_print
void _print(string s)
Definition: SCR_ModularButtonComponent.c:665
_WB_GetCustomTitle
SCR_ControlPlayerCameraComponent _WB_GetCustomTitle
Definition: SCR_DestructionBaseComponent.c:697
EModularButtonEventFlag
EModularButtonEventFlag
Definition: SCR_ButtonEffectBase.c:5
EVENT_CLICKED
@ EVENT_CLICKED
Start with bit 10 to reserve some space for prev. enum.
Definition: SCR_ButtonEffectBase.c:8
GetEnabled
bool GetEnabled()
Definition: SCR_ModularButtonComponent.c:107
Init
void Init(IEntity entity=null, vector worldPos=vector.Zero, float timestamp=0.0, EAITargetInfoCategory category=0)
Definition: SCR_AITargetInfo.c:27
EVENT_TOGGLED_ON
@ EVENT_TOGGLED_ON
Definition: SCR_ButtonEffectBase.c:11
GAMEPAD
enum EModularButtonEventFlag GAMEPAD
OnStateDefault
override void OnStateDefault(bool instant)
Definition: SCR_ButtonEffectImage.c:36
OnToggledOff
override void OnToggledOff(bool instant)
Definition: SCR_ButtonEffectImage.c:90
Attribute
typedef Attribute
Post-process effect of scripted camera.
OnStateActivatedHovered
override void OnStateActivatedHovered(bool instant)
Definition: SCR_ButtonEffectImage.c:54
EModularButtonState
EModularButtonState
Definition: SCR_ModularButtonComponent.c:6
OnFocusLost
override void OnFocusLost(bool instant)
Definition: SCR_ButtonEffectImage.c:78
OnStateHovered
override void OnStateHovered(bool instant)
Definition: SCR_ButtonEffectImage.c:42
OnStateDisabled
override void OnStateDisabled(bool instant)
Definition: SCR_ButtonEffectImage.c:60
OnStateActivated
override void OnStateActivated(bool instant)
Definition: SCR_ButtonEffectImage.c:48
EVENT_FOCUS_LOST
@ EVENT_FOCUS_LOST
Definition: SCR_ButtonEffectBase.c:10
EVENT_MOUSE_ENTER
@ EVENT_MOUSE_ENTER
Definition: SCR_ButtonEffectBase.c:13
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: SCR_EntitiesEditorUIComponent.c:109
EVENT_MOUSE_LEAVE
@ EVENT_MOUSE_LEAVE
Definition: SCR_ButtonEffectBase.c:14
OnToggledOn
override void OnToggledOn(bool instant)
Definition: SCR_ButtonEffectImage.c:84
m_bEnabled
private bool m_bEnabled
Definition: SCR_BaseManualCameraComponent.c:3
EVENT_FOCUS_GAINED
@ EVENT_FOCUS_GAINED
Definition: SCR_ButtonEffectBase.c:9
EVENT_TOGGLED_OFF
@ EVENT_TOGGLED_OFF
Definition: SCR_ButtonEffectBase.c:12
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468