Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AddonLinePresetComponent.c
Go to the documentation of this file.
2{
3 [Attribute(UIColors.GetColorAttribute(UIColors.CONTRAST_COLOR))]
4 protected ref Color m_cSelectedColor;
5
6 [Attribute(UIColors.GetColorAttribute(UIColors.NEUTRAL_INFORMATION))]
7 protected ref Color m_cDefaultColor;
8
9 protected const string STR_DEFAULT_NAME = "Preset ";
10
12 protected SCR_WorkshopAddonPreset m_Preset;
13
14//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
15// Old untyped invokers. Lots of duplicate code that should be in a common parent class of UI components, both the events and the common interaction states caching
16
17 protected bool m_bSelected;
18 protected bool m_bIsEdit;
19 protected bool m_bIsFocused;
20
21 // Buttons
22 protected SCR_ModularButtonComponent m_ButtonComponent;
23
24 // Current input device
25 protected EInputDeviceType m_eInputDeviceType;
26
27 //------------------------------------------------------------------------------------------------
28 // Invokers
29 //------------------------------------------------------------------------------------------------
30
40
41//---- REFACTOR NOTE END ----
42
43 //------------------------------------------------------------------------------------------------
44 protected void InvokeEventOnButtonClick()
45 {
47 Event_OnButtonClick.Invoke(this);
48 }
49
50 //------------------------------------------------------------------------------------------------
58
59 //------------------------------------------------------------------------------------------------
60 protected void InvokeEventOnNameChanged(string arg0)
61 {
63 Event_OnNameChanged.Invoke(this, arg0);
64 }
65
66 //------------------------------------------------------------------------------------------------
74
75 //------------------------------------------------------------------------------------------------
77 {
79 Event_OnNameEditStart.Invoke(this);
80
82 }
83
84 //------------------------------------------------------------------------------------------------
92
93 //------------------------------------------------------------------------------------------------
95 {
97 Event_OnNameEditLeave.Invoke(this);
98 }
99
100 //------------------------------------------------------------------------------------------------
108
109 //------------------------------------------------------------------------------------------------
110 protected void InvokeEventOnFocus()
111 {
112 if (Event_OnFocus)
113 Event_OnFocus.Invoke(this);
114 }
115
116 //------------------------------------------------------------------------------------------------
118 {
119 if (!Event_OnFocus)
121
122 return Event_OnFocus;
123 }
124
125 //------------------------------------------------------------------------------------------------
126 protected void InvokeEventOnFocusLost()
127 {
129 Event_OnFocusLost.Invoke(this);
130 }
131
132 //------------------------------------------------------------------------------------------------
140
141 //------------------------------------------------------------------------------------------------
142 protected void InvokeEventOnLoad()
143 {
144 if (Event_OnLoad)
145 Event_OnLoad.Invoke(this);
146
148 }
149
150 //------------------------------------------------------------------------------------------------
152 {
153 if (!Event_OnLoad)
155
156 return Event_OnLoad;
157 }
158
159 //------------------------------------------------------------------------------------------------
160 protected void InvokeEventOnOverride()
161 {
163 Event_OnOverride.Invoke(this);
164
166 }
167
168 //------------------------------------------------------------------------------------------------
176
177 //------------------------------------------------------------------------------------------------
178 protected void InvokeEventOnDelete()
179 {
180 if (Event_OnDelete)
181 Event_OnDelete.Invoke(this);
182
184 }
185
186 //------------------------------------------------------------------------------------------------
188 {
189 if (!Event_OnDelete)
191
192 return Event_OnDelete;
193 }
194
195 //------------------------------------------------------------------------------------------------
196 // Override widget functions
197 //------------------------------------------------------------------------------------------------
198
199 //------------------------------------------------------------------------------------------------
200 override void HandlerAttached(Widget w)
201 {
202 super.HandlerAttached(w);
203 m_Widgets.Init(w);
204
205 m_Widgets.m_EditNameButtonComponent.m_OnClicked.Insert(StartEditName);
206 m_Widgets.m_LoadButtonComponent.m_OnClicked.Insert(InvokeEventOnLoad);
207 m_Widgets.m_OverrideButtonComponent.m_OnClicked.Insert(InvokeEventOnOverride);
208 m_Widgets.m_DeleteButtonComponent.m_OnClicked.Insert(InvokeEventOnDelete);
209 m_Widgets.m_SelectedHighlightButtonComponent.m_OnClicked.Insert(ToggleSelected);
210
211
212 m_ButtonComponent = SCR_ModularButtonComponent.FindComponent(w);
213
214 ShowEditWidget(false);
215 ShowButtons(false);
216
217 //--- This will trigger everytime the input device change, so it controls the visibility of the navigation buttons, and on start
218 OnInputDeviceChange(-1, GetGame().GetInputManager().GetLastUsedInputDevice());
219 GetGame().OnInputDeviceUserChangedInvoker().Insert(OnInputDeviceChange);
220 }
221
222 //------------------------------------------------------------------------------------------------
223 override void HandlerDeattached(Widget w)
224 {
225 super.HandlerDeattached(w);
226 }
227
228 //------------------------------------------------------------------------------------------------
229 override bool OnDoubleClick(Widget w, int x, int y, int button)
230 {
231 super.OnDoubleClick(w, x, y, button);
232
233 if (button == UIConstants.MOUSE_LEFT_CLICK)
235
236 return true;
237 }
238
239 //------------------------------------------------------------------------------------------------
240 override bool OnFocus(Widget w, int x, int y)
241 {
242 m_bIsFocused = true;
243 super.OnFocus(w, x, y);
245 ShowButtons(m_eInputDeviceType == EInputDeviceType.MOUSE);
246 return true;
247 }
248
249 //------------------------------------------------------------------------------------------------
250 override bool OnFocusLost(Widget w, int x, int y)
251 {
252 m_bIsFocused = false;
253 super.OnFocusLost(w, x, y);
256 return true;
257 }
258
259 //------------------------------------------------------------------------------------------------
260 // Functions
261 //------------------------------------------------------------------------------------------------
262
263
264 //------------------------------------------------------------------------------------------------
266 protected void ToggleSelected()
267 {
269 }
270
271 //------------------------------------------------------------------------------------------------
274 {
275 m_bIsEdit = true;
276 if (!m_Widgets.m_EditName)
277 {
278 #ifdef DEBUG_WORKSHOP
279 Print("Missing m_NameEdit!");
280 #endif
281 return;
282 }
283
284 // This will prevent the edit box from immediately closing due to the button refocusing
286 m_ButtonComponent.SetIsFocusOnMouseEnter(false);
287
288 //--- Handle visibilities and focus state
289 ShowEditWidget(true);
290 ShowButtons(false);
291 GetGame().GetWorkspace().SetFocusedWidget(m_Widgets.m_EditNameComponent.GetEditBoxWidget());
292 m_Widgets.m_EditNameComponent.SetValue(m_Widgets.m_NameText.GetText());
293 m_Widgets.m_EditNameComponent.ActivateWriteMode();
294
295 //--- Handle event listeners
296 m_Widgets.m_EditNameComponent.m_OnConfirm.Insert(OnEditNameConfirm); //TODO: this does not get called on gamepad
297 m_Widgets.m_EditNameComponent.m_OnFocusChangedEditBox.Insert(OnEditNameCancel);
298 m_Widgets.m_EditNameComponent.m_OnCancel.Insert(OnEditNameCancel);
299
301 }
302
303 //------------------------------------------------------------------------------------------------
304 protected void ShowEditWidget(bool edit)
305 {
306 if (m_Widgets.m_NameText)
307 m_Widgets.m_NameText.SetVisible(!edit);
308
309 if (m_Widgets.m_EditName)
310 m_Widgets.m_EditName.SetVisible(edit);
311 }
312
313 //------------------------------------------------------------------------------------------------
314 protected void RemoveEditActions()
315 {
316 m_Widgets.m_EditNameComponent.m_OnConfirm.Remove(OnEditNameConfirm);
317 m_Widgets.m_EditNameComponent.m_OnFocusChangedEditBox.Remove(OnEditNameCancel);
318 m_Widgets.m_EditNameComponent.ClearInteractionState();
319 }
320
321 //------------------------------------------------------------------------------------------------
322 protected void OnEditNameConfirm()
323 {
324 // Reactivate focus on mouse enter
326 m_ButtonComponent.SetIsFocusOnMouseEnter(true);
327
328 InvokeEventOnNameChanged(m_Widgets.m_EditNameComponent.GetValue());
330
331 if (m_bSelected)
333 }
334
335 //------------------------------------------------------------------------------------------------
336 protected void OnEditNameCancel()
337 {
338 m_bIsEdit = false;
339
340 // If the focus change was a result of clicking the same line we're editing, then consider it a confirmation
341 // This is also necessary to register confirmation with gamepad
342 if (GetGame().GetWorkspace().GetFocusedWidget() == GetRootWidget())
343 {
345 return;
346 }
347
348 // Reactivate focus on mouse enter
350 m_ButtonComponent.SetIsFocusOnMouseEnter(true);
351
352 ShowEditWidget(false);
353 //ShowButtons(true);
355
357 }
358
359 //------------------------------------------------------------------------------------------------
360 protected void ShowButtons(bool show)
361 {
362 if (m_Widgets.m_OverrideButton)
363 m_Widgets.m_OverrideButton.SetVisible(show && !m_bIsEdit);
364
365 if (m_Widgets.m_EditNameButton)
366 m_Widgets.m_EditNameButton.SetVisible(show && !m_bIsEdit);
367
368 if (m_Widgets.m_DeleteButton)
369 m_Widgets.m_DeleteButton.SetVisible(show && !m_bIsEdit);
370 }
371
372 //------------------------------------------------------------------------------------------------
374 protected string DefaultName()
375 {
377 string name = STR_DEFAULT_NAME + count;
378
379 // Is name unique
380 int fallback = 100;
381
382 while (name || fallback > 0)
383 {
385 {
386 return name;
387 }
388 else
389 {
390 count++;
391 name = STR_DEFAULT_NAME + count;
392
393 fallback++;
394 }
395 }
396
397 return "";
398 }
399
400 //------------------------------------------------------------------------------------------------
401 // Api
402 //------------------------------------------------------------------------------------------------
403
404 //------------------------------------------------------------------------------------------------
405 SCR_WorkshopAddonPreset GetPreset()
406 {
407 return m_Preset;
408 }
409
410 //------------------------------------------------------------------------------------------------
411 void SetPreset(SCR_WorkshopAddonPreset preset)
412 {
413 m_Preset = preset;
414 }
415
416 //------------------------------------------------------------------------------------------------
418 {
419 ShowModCount(m_Preset.GetAddonCount());
420 }
421
422 //------------------------------------------------------------------------------------------------
423 void ShowWarning(bool show)
424 {
425 m_Widgets.m_SizeWarning.SetVisible(show);
426 }
427
428 //------------------------------------------------------------------------------------------------
429 void ShowModCount(int count)
430 {
431 m_Widgets.m_TxtAddonsCount.SetText(count.ToString());
432 }
433
434 //------------------------------------------------------------------------------------------------
436 {
437 m_Widgets.m_NameText.SetText(DefaultName());
438 }
439
440 //------------------------------------------------------------------------------------------------
441 string GetName()
442 {
443 return m_Widgets.m_NameText.GetText();
444 }
445
446 //------------------------------------------------------------------------------------------------
447 void SetSelected(bool selected)
448 {
449 if (m_bSelected == selected)
450 return;
451
453 m_ButtonComponent.SetToggled(selected);
454
455 if (m_Widgets.m_SelectedHighlightButtonComponent)
456 m_Widgets.m_SelectedHighlightButtonComponent.SetToggled(selected);
457
458
459
460 Color color = m_cDefaultColor;
461 if (selected)
462 color = m_cSelectedColor;
463
464 m_Widgets.m_NameText.SetColor(color);
465 m_Widgets.m_wImgAddons.SetColor(color);
466 m_Widgets.m_TxtAddonsCount.SetColor(color);
467 m_bSelected = selected;
468 }
469
470 //------------------------------------------------------------------------------------------------
472 {
473 return m_bSelected;
474 }
475 //------------------------------------------------------------------------------------------------
476 // Sets the used input device type and toggles the buttons accordingly
477 protected void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
478 {
479 ShowButtons(newDevice == EInputDeviceType.MOUSE && m_bIsFocused);
480 m_eInputDeviceType = newDevice;
481 }
482}
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
Definition Color.c:13
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnLoad
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnFocus
void SetPreset(SCR_WorkshopAddonPreset preset)
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnNameEditLeave
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnButtonClick
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnFocusLost
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnDelete
ref ScriptInvoker< SCR_AddonLinePresetComponent, string > Event_OnNameChanged
override bool OnFocusLost(Widget w, int x, int y)
void ToggleSelected()
Toggles the current selection.
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnOverride
string DefaultName()
Type default prefab name based on count of current addons.
SCR_ModularButtonComponent m_ButtonComponent
override bool OnFocus(Widget w, int x, int y)
void StartEditName()
Show editbox instead of name to edit name string.
ref SCR_AddonLinePresetWidgets m_Widgets
ref ScriptInvoker< SCR_AddonLinePresetComponent > Event_OnNameEditStart
override bool OnDoubleClick(Widget w, int x, int y, int button)
void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
SCR_WorkshopAddonManagerPresetStorage GetPresetStorage()
static SCR_AddonManager GetInstance()
Base class for all final Reforger interactive elements.
array< ref SCR_WorkshopAddonPreset > GetPresets()
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134