Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WLibComponentBase.c
Go to the documentation of this file.
1 
3 //------------------------------------------------------------------------------------------------
5 {
6  [Attribute(SCR_SoundEvent.SOUND_FE_BUTTON_HOVER, UIWidgets.EditBox, "")]
7  protected string m_sSoundHovered;
8 
9  [Attribute(SCR_SoundEvent.CLICK, UIWidgets.EditBox, "")]
10  protected string m_sSoundClicked;
11 
12  [Attribute(defvalue: "0.2", UIWidgets.EditBox, "How fast each animation proceeds")]
13  protected float m_fAnimationTime;
14 
15  [Attribute()]
16  protected bool m_bMouseOverToFocus;
17 
18  [Attribute("0.3")]
19  protected float m_fDisabledOpacity;
20 
21  protected float m_fAnimationRate;
22 
23  static const float START_ANIMATION_RATE = 10001; // Custom rate that creates instant animations and supress sounds playing at start
24  static const float START_ANIMATION_PERIOD = 250; // Time since start in ms without sounds and animations
25 
26  //------------------------------------------------------------------------------------------------
27  override void HandlerAttached(Widget w)
28  {
29  super.HandlerAttached(w);
30 
31  m_fAnimationRate = START_ANIMATION_RATE;
32  // Set correct animation rate after the first frame, so animations are not played at the start of the visualization
33  GetGame().GetCallqueue().CallLater(SetAnimationRate, START_ANIMATION_PERIOD);
34 
35  if (!w.IsEnabled())
36  SetEnabled(false, false);
37  }
38 
39  //------------------------------------------------------------------------------------------------
40  override bool OnClick(Widget w, int x, int y, int button)
41  {
42  // Accept only LMB as valid click
43  if (button != 0)
44  return false;
45 
46  PlaySound(m_sSoundClicked);
47  return false;
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  override bool OnMouseEnter(Widget w, int x, int y)
52  {
53  // Do not remove the 'w.IsFocusable()' part of condition, it ensures that refocusing is happening only in case mouse enters focusable widget
54  if (m_bMouseOverToFocus && w.IsFocusable() && GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
55  {
56  GetGame().GetWorkspace().SetFocusedWidget(null);
57  GetGame().GetWorkspace().SetFocusedWidget(w);
58  }
59  else
60  PlaySound(m_sSoundHovered);
61 
62  return false;
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  override bool OnFocus(Widget w, int x, int y)
67  {
68  PlaySound(m_sSoundHovered);
69  return false;
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  protected void OnEnabled(bool animate)
74  {
75  if (animate && m_fAnimationRate != START_ANIMATION_RATE)
76  AnimateWidget.Opacity(m_wRoot, 1, m_fAnimationRate);
77  else
78  m_wRoot.SetOpacity(1);
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  protected void OnDisabled(bool animate)
83  {
84  if (animate && m_fAnimationRate != START_ANIMATION_RATE)
85  AnimateWidget.Opacity(m_wRoot, m_fDisabledOpacity, m_fAnimationRate);
86  else
87  m_wRoot.SetOpacity(m_fDisabledOpacity);
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  protected bool IsChildWidget(Widget parent, Widget child)
92  {
93  if (parent == null || child == null)
94  return false;
95 
96  child = child.GetParent();
97  while (child)
98  {
99  if (child == parent)
100  return true;
101 
102  child = child.GetParent();
103  }
104  return false;
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  protected void SetAnimationRate()
109  {
110  m_fAnimationRate = 1 / m_fAnimationTime;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  protected void PlaySound(string sound)
115  {
116  if (m_fAnimationRate != START_ANIMATION_RATE && sound != string.Empty)
117  SCR_UISoundEntity.SoundEvent(sound);
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  static bool SetTexture(ImageWidget widget, ResourceName texture, string image = "")
122  {
123  if (!widget || texture == ResourceName.Empty)
124  return false;
125 
126  bool success;
127 
128  if (texture.EndsWith(".edds"))
129  success = widget.LoadImageTexture(0, texture);
130  else
131  success = widget.LoadImageFromSet(0, texture, image);
132 
133  if (success)
134  {
135  int x, y;
136  widget.GetImageSize(0, x, y);
137  widget.SetSize(x, y);
138  }
139 
140  return success;
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  void SetHoverSound(string soundHover)
145  {
146  m_sSoundHovered = soundHover;
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  void SetClickedSound(string soundClicked)
151  {
152  m_sSoundClicked = soundClicked;
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  string GetHoverSound()
157  {
158  return m_sSoundHovered;
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  string GetClickedSound()
163  {
164  return m_sSoundClicked;
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  void SetEnabled(bool enabled, bool animate = true)
169  {
170  if (!m_wRoot || m_wRoot.IsEnabled() == enabled)
171  return;
172 
173  m_wRoot.SetEnabled(enabled);
174  if (enabled)
175  OnEnabled(animate);
176  else
177  OnDisabled(animate);
178  }
179 
180  //------------------------------------------------------------------------------------------------
181  void SetVisible(bool visible, bool animate = true)
182  {
183  if (!m_wRoot)
184  return;
185 
186  if (animate)
187  AnimateWidget.Opacity(m_wRoot, visible, m_fAnimationRate, true);
188  else
189  m_wRoot.SetVisible(visible);
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  bool IsEnabled()
194  {
195  if (!m_wRoot)
196  return false;
197 
198  return m_wRoot.IsEnabled();
199  }
200 
201  //------------------------------------------------------------------------------------------------
202  void SetMouseOverToFocus(bool mouseOverToFocus)
203  {
204  m_bMouseOverToFocus = mouseOverToFocus;
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  void SetDisabledOpacity(float newDisabledOpacity)
209  {
210  m_fDisabledOpacity = newDisabledOpacity;
211  }
212 };
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
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7