Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseEditorAttributeUIComponent.c
Go to the documentation of this file.
1
4{
5 [Attribute()]
6 protected string m_sUiComponentName;
7
8 [Attribute("TickboxHolder")]
9 protected string m_sTickBoxAttributeName;
10
11 [Attribute("AttributeHolder")]
12 protected string m_sAttributeHolder;
13
14 [Attribute("GamePadLockedSelector")]
16
17 [Attribute("SubAttributeIndicator", desc: "Shown when attribute is a subattribute")]
19
20 [Attribute("0.25", desc: "Subattribute indicator disabled alpha")]
22
25
27 private SCR_BaseEditorAttribute m_Attribute;
28 protected float m_fBottomPadding = 1;
29 protected bool m_bIsSubAttribute;
32 protected SCR_AttributesManagerEditorComponent m_AttributeManager;
36
37 protected bool m_bEnabledByAttribute;
38 protected bool m_bEnabledByTickbox;
39 protected bool m_bIsFocused;
40
41 //Attribute desciption
44 protected string m_sButtonDescription;
46
52
53
54 //============================ Getters ============================\\
55
60 {
61 return m_Attribute;
62 }
63
64 //============================ Set from var ============================\\
65 protected void SetFromVarExternal(SCR_BaseEditorAttributeVar var, bool isReset)
66 {
67 //If Reset
68 if (isReset)
69 {
71 if (GetAttribute().GetHasConflictingValues())
72 {
74
77 }
78 }
79
80 SetFromVar(var);
81 }
82
91
92 protected void SetFromVarOrDefault()
93 {
94 array<SCR_BaseAttributeDynamicDescription> dynamicDescriptionArray = {};
95 m_Attribute.GetDynamicDescriptionArray(dynamicDescriptionArray);
96
97 //~ Init dynamic descriptions
99 {
100 discription.InitDynamicDescription(m_Attribute, this);
101 }
102
103 //~ Update discription if showing
105 ShowAttributeDescription();
106 }
107
108 //============================ Init ============================\\
109
116 {
117 m_Attribute = attribute;
118 m_AttributeManager = SCR_AttributesManagerEditorComponent.Cast(SCR_AttributesManagerEditorComponent.GetInstance(SCR_AttributesManagerEditorComponent));
119
120 if (m_Attribute.GetOnExternalnChange())
121 m_Attribute.GetOnExternalnChange().Insert(SetFromVarExternal);
122 m_Attribute.GetOnVarChanged().Insert(SetFromVar);
123 m_Attribute.GetOnToggleEnable().Insert(ToggleEnableAttribute);
124 m_Attribute.GetOnToggleButtonSelected().Insert(ToggleButtonSelected);
125 m_Attribute.GetOnSetAsSubAttribute().Insert(SetAsSubAttribute);
126
128
129 m_InputManager = GetGame().GetInputManager();
130
131 Widget tickbox = w.FindAnyWidget(m_sTickBoxAttributeName);
132 if (!tickbox)
133 {
134 Print(string.Format("SCR_BaseEditorAttributeUIComponent could not find tickbox: %1!", m_sTickBoxAttributeName), LogLevel.ERROR);
135 return;
136 }
137
139
141
143 {
145
146 if (focusComponent)
148 }
149
151 m_TickBoxAttribute.GetOnToggleChanged().Insert(OnTickboxToggleChanged);
152
153 //m_AttributeSizeLayout = SizeLayoutWidget.Cast(w.FindAnyWidget(m_sAttributeSizeLayoutName));
154
155 Widget uiComponentWidget = w.FindAnyWidget(m_sUiComponentName);
156 if (uiComponentWidget)
157 {
158 m_UIComponent = SCR_ChangeableComponentBase.Cast(uiComponentWidget.FindHandler(SCR_ChangeableComponentBase));
159
160 if (m_UIComponent)
161 attribute.GetUIInfo().SetNameTo(m_UIComponent.GetLabel());
162 }
163
164 //Check if is disabled by means of overriding varriables
165 m_bEnabledByTickbox = (!attribute.GetIsMultiSelect()) || (attribute.GetIsMultiSelect() && !attribute.GetHasConflictingValues() || (attribute.GetHasConflictingValues() && attribute.GetIsOverridingValues()));
166
167 //If not multi select it can be disabled and enabled
168 ToggleEnableAttribute(attribute.IsEnabled());
169
170 if (attribute.GetIsSubAttribute())
172
173 //Padding
174 LayoutSlot.SetPadding(w,0,0,0,m_fBottomPadding);
175
176 //Override attributes link
177 typename linkedOverrideAttributeType = typename.Empty;
178
179 if (attribute.GetHasConflictingValues() && !GetAttribute().GetInitCalled())
180 {
181 GetGame().OnInputDeviceIsGamepadInvoker().Insert(SetGamepadLockSelectorActive);
182 }
183
184 //Multiselect
185 if (attribute.GetIsMultiSelect())
186 {
187 //If attribute init or reset was called make sure that attribute settings are reset and default values are set
188 if (attribute.GetHasConflictingValues() && (!GetAttribute().GetInitCalled() || GetAttribute().GetConflictingAttributeWasReset()))
189 {
190 if (!attribute.GetInitCalled())
191 attribute.SetInitCalled(true);
192 else if (attribute.GetConflictingAttributeWasReset())
193 attribute.SetConflictingAttributeWasReset(false);
194
195 attribute.ResetAttribute();
196 SetVariableToDefaultValue(m_Attribute.GetVariableOrCopy());
197 }
198 }
199 //Override
200 else
201 {
202 array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
203 attribute.GetEntries(entries);
204
205 foreach (SCR_BaseEditorAttributeEntry entry: entries)
206 {
208
209 if (overrideEntry)
210 {
211 //attribute.SetHasConflictingValues(true);
212 bool isOverride;
213 overrideEntry.GetToggleStateAndTypename(isOverride, linkedOverrideAttributeType);
214 attribute.SetIsOverridingValues(isOverride);
215
216 break;
217 }
218 }
219 }
220
221 if (attribute.GetIsMultiSelect())
222 {
223 if (attribute.GetHasConflictingValues())
224 m_TickBoxAttribute.InitTickbox(attribute.GetIsOverridingValues(), this);
225 else
226 m_TickBoxAttribute.InitDisabled();
227 }
228 //If values are overriden by another attribute
229 else if (attribute.GetHasConflictingValues())
230 {
231 m_TickBoxAttribute.InitTickbox(attribute.GetIsOverridingValues(), this, linkedOverrideAttributeType);
232 }
233
234 // Setup attribut holder
235 m_wAttributeHolder = w.FindAnyWidget(m_sAttributeHolder);
237 {
238 Widget child = m_wAttributeHolder.GetChildren();
239 if (child)
240 {
241 // Setup event handler and callbacks
243 eventHandler.GetOnFocus().Insert(OnFocusAttributeWidget);
244 child.AddHandler(eventHandler);
245
246 }
247 }
248 }
249
250 //============================ Set button states ============================\\
251 //Button boxs only, toggle the slection state of buttons
252 protected void ToggleButtonSelected(bool selected, int index, bool animated = true)
253 {
254 }
255
256 //============================ UI Logics ============================\\
257 //Sets an indent on the label if it is a child of another attribute
258 protected void SetAsSubAttribute()
259 {
260 m_bIsSubAttribute = true;
261 m_Attribute.GetOnSetAsSubAttribute().Remove(SetAsSubAttribute);
262
264 {
265 Print("SCR_BaseEditorAttributeUIComponent is lacking subattribute indicator and can never be shown as a subattribute", LogLevel.WARNING);
266 return;
267 }
268
269 m_SubAttributeIndicator.SetVisible(true);
270
271 if (GetAttribute().GetHasConflictingValues())
272 m_TickBoxAttribute.ToggleEnableByAttribute(false);
273 }
274
275 //============================ Varriable changed ============================\\
276 override bool OnChange(Widget w, bool finished)
277 {
278 return OnChangeInternal(w, 0, 0, finished);
279
280 }
281
282 bool OnChangeInternal(Widget w, int x, int y, bool finished)
283 {
285 return false;
286 }
287
288 //On attribute value changed
289 protected void AttributeValueChanged()
290 {
291 m_Attribute.UpdateInterlinkedVariables(m_Attribute.GetVariable(), m_AttributeManager);
292 m_Attribute.PreviewVariable(true, m_AttributeManager);
293
294 //~ Update discription
295 ShowAttributeDescription();
297 }
298
299 //============================ Set tooltip ============================\\
300 protected void ShowAttributeDescription()
301 {
303 return;
304
306
307 //~ Always show tickbox description first
308 if (!m_TickBoxAttribute.GetToggled() && m_TickBoxAttribute.IsVisibleAndEnabled())
309 {
310 m_AttributeManager.SetAttributeDescription(m_AttributeManager.GetConflictingAttributeUIInfo(), m_AttributeManager.GetConflictingAttributeUIInfo().GetDescription());
311 return;
312 }
313
314 array<SCR_BaseAttributeDynamicDescription> dynamicDescriptionArray = {};
315 m_Attribute.GetDynamicDescriptionArray(dynamicDescriptionArray);
316
317 //~ Get first valid description
320 {
321 if (discription.IsValid(m_Attribute, this))
322 {
323 dynamicDescription = discription;
324 break;
325 }
326 }
327
328 //~ Get button dynamic
334
335 //~ Button description
337 {
338 m_AttributeManager.SetAttributeDescription(m_ButtonDescriptionUIInfo, string.Empty, m_sButtonDescriptionParam1);
339 return;
340 }
341
342 //~ Dynamic description
344 {
346 string param1, param2, param3;
347
348 dynamicDescription.GetDescriptionData(m_Attribute, this, uiInfo, param1, param2, param3);
349
350 if (!uiInfo)
351 {
352 Print("SCR_BaseEditorAttributeUIComponent 'dynamicDescription' is missing UIInfo this means a dynamic description was added but the UIInfo was not set!", LogLevel.WARNING);
353 m_AttributeManager.SetAttributeDescription(GetAttribute().GetUIInfo());
354 return;
355 }
356
357 string descr = uiInfo.GetDescription();
358
360 {
361 Print("'SCR_BaseEditorAttributeUIComponent' dynamicDescription does not have a description assigned! This means the description is not set!", LogLevel.WARNING);
362 m_AttributeManager.SetAttributeDescription(GetAttribute().GetUIInfo());
363 return;
364 }
365
366 m_AttributeManager.SetAttributeDescription(uiInfo, descr, param1, param2, param3);
367 return;
368 }
369
370 //~ Default attribute description
371 m_AttributeManager.SetAttributeDescription(GetAttribute().GetUIInfo());
372 }
373
375 {
377 return;
378
380 m_AttributeManager.SetAttributeDescription(null);
381 }
382
383 void ShowButtonDescription(SCR_AttributeButtonUIComponent button, bool showButtonDescription, string buttonDescription = string.Empty)
384 {
385 //~ If trying to hide description but that description is not active ignore it
386 if (showButtonDescription)
388 else if (m_ActiveButtonDescription != button && button != null)
389 return;
390
391 if (buttonDescription.IsEmpty())
393 else
394 m_bShowButtonDescription = showButtonDescription;
395
396 m_sButtonDescriptionParam1 = buttonDescription;
397
398 //~ Override description to that of the button
399 ShowAttributeDescription();
400 }
401
402 //============================ Script Invokers ============================\\
403
411
420
429
438
439 //============================ Enabling and Disabling UI and Tickbox ============================\\
440 //Sets a default state for the UI and var value if conflicting attribute
445
446 protected void ToggleEnableAttribute(bool enabled)
447 {
448 m_bEnabledByAttribute = enabled;
451
452 if (GetAttribute().GetHasConflictingValues())
453 m_TickBoxAttribute.ToggleEnableByAttribute(enabled);
454 }
455
456
461 protected void ToggleEnable(bool enabled)
462 {
464 {
465 Color color = Color.FromInt(m_SubAttributeIndicator.GetColor().PackToInt());
466 if (!enabled)
468 else
469 color.SetA(1);
470
471 m_SubAttributeIndicator.SetColor(color);
472 }
473
474 //If Multiselect
475 if (GetAttribute().GetHasConflictingValues())
476 {
477 //~ Create var from copy var if enabled
478 if (enabled)
479 {
480 //~ Only do this if copy existis
481 if (m_Attribute.GetCopyVariable())
482 {
483 GetAttribute().SetVariable(m_Attribute.GetCopyVariable());
485 }
486 }
487 //~ Create copy var and Delete var if disabled
488 else
489 {
490 //~ Only do this if var existis
491 if (GetAttribute().GetVariable(false))
492 {
495 }
496 }
497 }
498
500 m_UIComponent.SetEnabled(true);
501 else
502 m_UIComponent.SetEnabled(false);
503
504 }
505
511 {
512 return m_TickBoxAttribute && m_TickBoxAttribute.GetEnabled();
513 }
514
519 {
520 if (GetAttribute().GetHasConflictingValues())
521 m_TickBoxAttribute.ToggleTickbox(!GetAttribute().GetIsOverridingValues());
522
523 if (GetAttribute().GetIsOverridingValues())
524 GetGame().GetWorkspace().SetFocusedWidget(m_UIComponent.GetRootWidget());
525 else
526 GetGame().GetWorkspace().SetFocusedWidget(m_GamePadLockedSelector);
527 }
528
529 //Listens to tickbox if the state changed
530 protected void OnTickboxToggleChanged(bool toggle)
531 {
532 if (GetAttribute().GetHasConflictingValues())
533 {
535 }
536
537 m_bEnabledByTickbox = toggle;
538 ToggleEnable(toggle);
539
540 SetGamepadLockSelectorActive(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
541
542 if (toggle)
544
546 ShowAttributeDescription();
547 }
548
549 //If Disabled attribute is focused or not with gamepad
550 protected void GamePadLockedSelectorFocusChanged(bool newFocus)
551 {
552 if (!GetAttribute().GetHasConflictingValues())
553 return;
554
555 if (newFocus)
556 {
557 ShowAttributeDescription();
559 }
560
561 else
562 {
565 }
566 }
567
573 {
574 return m_bIsFocused;
575 }
576
577 //------------------------------------------------------------------------------------------------
580 {
581 OnFocus(w, 0, 0);
582 }
583
584 //------------------------------------------------------------------------------------------------
585 //If enabled UI is focused
586 override bool OnFocus(Widget w, int x, int y)
587 {
588 m_bIsFocused = true;
589
590 if (!m_InputManager.IsUsingMouseAndKeyboard())
591 ShowButtonDescription(null, false);
592
593 if (GetAttribute().GetHasConflictingValues())
595
596 ShowAttributeDescription();
597
598 return true;
599 }
600
601 //------------------------------------------------------------------------------------------------
602 //If enabled UI is lost focus
603 override bool OnFocusLost(Widget w, int x, int y)
604 {
605 m_bIsFocused = false;
606
607 if (GetAttribute().GetHasConflictingValues())
609
610 return false;
611 }
612
613 override bool OnMouseEnter(Widget w, int x, int y)
614 {
615 return OnFocus(w, x, y);
616 }
617
618 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
619 {
620 Event_OnMouseLeave.Invoke();
621 return false;
622 }
623
624 //For tickbox
625 protected void SetGamepadLockSelectorActive(bool isGamepad)
626 {
627 m_GamePadLockedSelector.SetVisible(isGamepad && !m_TickBoxAttribute.GetToggled());
628 }
629
630 //============================ On Destroy ============================\\
631 override void HandlerDeattached(Widget w)
632 {
633 if (m_Attribute)
634 {
635 if (m_Attribute.GetOnExternalnChange())
636 m_Attribute.GetOnExternalnChange().Remove(SetFromVarExternal);
637
638 m_Attribute.GetOnVarChanged().Remove(SetFromVar);
639 m_Attribute.GetOnToggleEnable().Remove(ToggleEnableAttribute);
641
643 m_Attribute.GetOnSetAsSubAttribute().Remove(SetAsSubAttribute);
644
645 if (m_Attribute.GetHasConflictingValues())
646 GetGame().OnInputDeviceIsGamepadInvoker().Remove(SetGamepadLockSelectorActive);
647 }
648
650 m_TickBoxAttribute.GetOnToggleChanged().Remove(OnTickboxToggleChanged);
651
652
654 {
656
657 if (focusComponent)
659 }
660 }
661};
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
Input management system for user interactions.
Using a controller will show/hide the Select button hint if the attribute with this script is focused...
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
void SetInitCalled(bool initCalled)
sealed bool SetVariable(SCR_BaseEditorAttributeVar var)
sealed ScriptInvoker GetOnVarChanged()
sealed ScriptInvoker GetOnToggleEnable()
sealed SCR_BaseEditorAttributeVar GetVariableOrCopy()
sealed void ClearCopyVar()
Set copy var null.
sealed ScriptInvoker GetOnExternalnChange()
sealed void ClearVar()
Set var null.
sealed void SetConflictingAttributeWasReset(bool wasReset)
sealed ScriptInvoker GetOnToggleButtonSelected()
int GetEntries(notnull array< ref SCR_BaseEditorAttributeEntry > outEntries)
void SetIsOverridingValues(bool isOverridingValues)
SCR_EditorAttributeUIInfo GetUIInfo()
sealed ScriptInvoker GetOnSetAsSubAttribute()
Get attribute this component represents return Editor attribute *SCR_BaseEditorAttribute GetAttribute()
array< SCR_BaseAttributeDynamicDescription > dynamicDescriptionArray
SCR_AttributeButtonUIComponent m_ActiveButtonDescription
Called on attribute changed via UI return Event_OnAttributeChanged ScriptInvoker *ScriptInvoker GetOnAttributeChanged()
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void ShowButtonDescription(SCR_AttributeButtonUIComponent button, bool showButtonDescription, string buttonDescription=string.Empty)
void OnFocusAttributeWidget(Widget w)
Callback for focus of widget used.
void ToggleButtonSelected(bool selected, int index, bool animated=true)
override bool OnFocusLost(Widget w, int x, int y)
SCR_AttributesManagerEditorComponent m_AttributeManager
void SetVariableToDefaultValue(SCR_BaseEditorAttributeVar var)
override bool OnMouseEnter(Widget w, int x, int y)
void SetFromVar(SCR_BaseEditorAttributeVar var)
bool OnChangeInternal(Widget w, int x, int y, bool finished)
Initialize GUI from attribute To be overridden by inherited classes param w Widget this component is attached to param attribute Editor attribute this component represents *void Init(Widget w, SCR_BaseEditorAttribute attribute)
override bool OnFocus(Widget w, int x, int y)
SCR_BaseButtonAttributeDynamicDescription buttonDynamicDescription
SCR_BaseAttributeDynamicDescription dynamicDescription
Base class for all widgets that can change their internal state as editbox or spinbox.
void GetToggleStateAndTypename(out bool overrideToggleState, out typename linkedOverrideAttributeType)
UIInfo used by editor attribute system.
static bool IsEmptyOrWhiteSpace(string input)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
T3 param3
Definition tuple.c:93
T2 param2
Definition tuple.c:92
Tuple param1
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134