Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WLibComponentBase.c
Go to the documentation of this file.
1//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
2// Many interactable elements do not use this as their base! It is not generic enough: sounds, opacity and animation settings would ideally be handled in a more centralized way (stylesheets?) together with other data like color, because having them on each component makes mantaining a project wide consistent look impossible. In the end, most layouts using children of this ended up with a SCR_ModularButtonComponent on them anyways. It is missing key features like caching of interaction states and events, and handling of enabled state is very limited (it should keep track of multiple stacking state change requests)
3
5
6
7//------------------------------------------------------------------------------------------------
9{
10 [Attribute(SCR_SoundEvent.SOUND_FE_BUTTON_HOVER, UIWidgets.EditBox, "")]
11 protected string m_sSoundHovered;
12
13 [Attribute(SCR_SoundEvent.CLICK, UIWidgets.EditBox, "")]
14 protected string m_sSoundClicked;
15
16 [Attribute(SCR_SoundEvent.SOUND_INV_CLOSE,"Sound used for closing container")]
17 protected string m_sSoundContainerClosed;
18
19 [Attribute(defvalue: "0.2", UIWidgets.EditBox, "How fast each animation proceeds")]
20 protected float m_fAnimationTime;
21
22 [Attribute()]
23 protected bool m_bMouseOverToFocus;
24
25 [Attribute("0.3")]
26 protected float m_fDisabledOpacity;
27
28 protected float m_fAnimationRate;
29
30 protected ref Managed m_UserData; // User data - can be accessed with SetData, GetData
31
32 static const float START_ANIMATION_RATE = 10001; // Custom rate that creates instant animations and supress sounds playing at start
33 static const float START_ANIMATION_PERIOD = 250; // Time since start in ms without sounds and animations
34
35 //------------------------------------------------------------------------------------------------
36 override void HandlerAttached(Widget w)
37 {
38 super.HandlerAttached(w);
39
41 // Set correct animation rate after the first frame, so animations are not played at the start of the visualization
42 GetGame().GetCallqueue().CallLater(SetAnimationRate, START_ANIMATION_PERIOD);
43
44 if (!w.IsEnabled())
45 SetEnabled(false, false);
46 }
47
48 //------------------------------------------------------------------------------------------------
49 override bool OnClick(Widget w, int x, int y, int button)
50 {
51 // Accept only LMB as valid click
52 if (button != 0)
53 return false;
54
56 return false;
57 }
58
59 //------------------------------------------------------------------------------------------------
60 override bool OnMouseEnter(Widget w, int x, int y)
61 {
62 // Do not remove the 'w.IsFocusable()' part of condition, it ensures that refocusing is happening only in case mouse enters focusable widget
63 if (m_bMouseOverToFocus && w.IsFocusable() && GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
64 {
65 GetGame().GetWorkspace().SetFocusedWidget(null);
66 GetGame().GetWorkspace().SetFocusedWidget(w);
67 }
68 else
70
71 return false;
72 }
73
74 //------------------------------------------------------------------------------------------------
75 override bool OnFocus(Widget w, int x, int y)
76 {
78 return false;
79 }
80
81 //------------------------------------------------------------------------------------------------
82 protected void OnEnabled(bool animate)
83 {
84 if (animate && m_fAnimationRate != START_ANIMATION_RATE)
86 else
87 m_wRoot.SetOpacity(1);
88 }
89
90 //------------------------------------------------------------------------------------------------
91 protected void OnDisabled(bool animate)
92 {
93 if (animate && m_fAnimationRate != START_ANIMATION_RATE)
95 else
96 m_wRoot.SetOpacity(m_fDisabledOpacity);
97 }
98
99 //------------------------------------------------------------------------------------------------
100 protected bool IsChildWidget(Widget parent, Widget child)
101 {
102 if (parent == null || child == null)
103 return false;
104
105 child = child.GetParent();
106 while (child)
107 {
108 if (child == parent)
109 return true;
110
111 child = child.GetParent();
112 }
113 return false;
114 }
115
116 //------------------------------------------------------------------------------------------------
117 protected void SetAnimationRate()
118 {
120 }
121
122 //------------------------------------------------------------------------------------------------
123 protected void PlaySound(string sound)
124 {
125 if (m_fAnimationRate != START_ANIMATION_RATE && sound != string.Empty)
126 SCR_UISoundEntity.SoundEvent(sound);
127 }
128
129 //------------------------------------------------------------------------------------------------
130 static bool SetTexture(ImageWidget widget, ResourceName texture, string image = "")
131 {
132 if (!widget || texture == ResourceName.Empty)
133 return false;
134
135 bool success;
136
137 if (texture.EndsWith(".edds"))
138 success = widget.LoadImageTexture(0, texture);
139 else
140 success = widget.LoadImageFromSet(0, texture, image);
141
142 if (success)
143 {
144 int x, y;
145 widget.GetImageSize(0, x, y);
146 widget.SetSize(x, y);
147 }
148
149 return success;
150 }
151
152 //------------------------------------------------------------------------------------------------
153 void SetHoverSound(string soundHover)
154 {
155 m_sSoundHovered = soundHover;
156 }
157
158 //------------------------------------------------------------------------------------------------
159 void SetClickedSound(string soundClicked)
160 {
161 m_sSoundClicked = soundClicked;
162 }
163
164 //------------------------------------------------------------------------------------------------
166 {
167 return m_sSoundHovered;
168 }
169
170 //------------------------------------------------------------------------------------------------
172 {
173 return m_sSoundClicked;
174
175 }
176
177 //------------------------------------------------------------------------------------------------
178 void SetEnabled(bool enabled, bool animate = true)
179 {
180 if (!m_wRoot || m_wRoot.IsEnabled() == enabled)
181 return;
182
183 m_wRoot.SetEnabled(enabled);
184 if (enabled)
185 OnEnabled(animate);
186 else
187 OnDisabled(animate);
188 }
189
190 //------------------------------------------------------------------------------------------------
191 void SetVisible(bool visible, bool animate = true)
192 {
193 if (!m_wRoot)
194 return;
195
196 if (animate)
198 else
199 m_wRoot.SetVisible(visible);
200 }
201
202 //------------------------------------------------------------------------------------------------
204 {
205 if (!m_wRoot)
206 return false;
207
208 return m_wRoot.IsEnabled();
209 }
210
211 //------------------------------------------------------------------------------------------------
212 void SetMouseOverToFocus(bool mouseOverToFocus)
213 {
214 m_bMouseOverToFocus = mouseOverToFocus;
215 }
216
217 //------------------------------------------------------------------------------------------------
218 void SetDisabledOpacity(float newDisabledOpacity)
219 {
220 m_fDisabledOpacity = newDisabledOpacity;
221 }
222
223 //------------------------------------------------------------------------------------------------
226 void SetData(Managed data)
227 {
229 }
230
231 //------------------------------------------------------------------------------------------------
234 Managed GetData()
235 {
236 return m_UserData;
237 }
238};
239
240
241//---- REFACTOR NOTE END ----
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
Get all prefabs that have the spawner data
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
Base class for all final Reforger interactive elements.
override bool OnMouseEnter(Widget w, int x, int y)
void SetClickedSound(string soundClicked)
void SetMouseOverToFocus(bool mouseOverToFocus)
override bool OnFocus(Widget w, int x, int y)
override void HandlerAttached(Widget w)
void SetEnabled(bool enabled, bool animate=true)
bool IsChildWidget(Widget parent, Widget child)
void SetHoverSound(string soundHover)
override bool OnClick(Widget w, int x, int y, int button)
static bool SetTexture(ImageWidget widget, ResourceName texture, string image="")
void OnDisabled(bool animate)
static const float START_ANIMATION_PERIOD
void SetVisible(bool visible, bool animate=true)
static const float START_ANIMATION_RATE
void SetDisabledOpacity(float newDisabledOpacity)
void OnEnabled(bool animate)
SCR_FieldOfViewSettings Attribute