6 protected string m_sUiComponentName;
9 protected string m_sTickBoxAttributeName;
12 protected string m_sAttributeHolder;
15 protected string m_sGamePadLockedSelectorName;
17 [
Attribute(
"SubAttributeIndicator",
desc:
"Shown when attribute is a subattribute")]
18 protected string m_sSubAttributeIndicatorName;
20 [
Attribute(
"0.25",
desc:
"Subattribute indicator disabled alpha")]
21 protected float m_fSubAttributeDisabledAlphaColor;
28 protected float m_fBottomPadding = 1;
29 protected bool m_bIsSubAttribute;
31 protected Widget m_GamePadLockedSelector;
32 protected SCR_AttributesManagerEditorComponent m_AttributeManager;
33 protected InputManager m_InputManager;
34 protected Widget m_SubAttributeIndicator;
35 protected Widget m_wAttributeHolder;
37 protected bool m_bEnabledByAttribute;
38 protected bool m_bEnabledByTickbox;
39 protected bool m_bIsFocused;
42 protected bool m_bIsShowingDescription;
43 protected bool m_bShowButtonDescription;
44 protected string m_sButtonDescription;
45 protected string m_sButtonDescriptionParam1;
47 protected ref ScriptInvoker Event_OnAttributeChanged =
new ScriptInvoker;
48 protected ref ScriptInvoker Event_OnEnabledByAttribute =
new ScriptInvoker;
49 protected ref ScriptInvoker Event_OnAttributeUIFocusChanged =
new ScriptInvoker;
50 protected ref ScriptInvoker Event_OnInputDeviceChanged =
new ScriptInvoker;
51 protected ref ScriptInvoker Event_OnMouseLeave =
new ScriptInvoker;
70 GetAttribute().SetConflictingAttributeWasReset(
false);
71 if (GetAttribute().GetHasConflictingValues())
73 SetVariableToDefaultValue(m_Attribute.GetVariableOrCopy());
75 if (m_TickBoxAttribute.GetToggled())
76 m_TickBoxAttribute.ToggleTickbox(
false);
89 SetFromVarOrDefault();
92 protected void SetFromVarOrDefault()
94 array<SCR_BaseAttributeDynamicDescription> dynamicDescriptionArray = {};
95 m_Attribute.GetDynamicDescriptionArray(dynamicDescriptionArray);
100 discription.InitDynamicDescription(m_Attribute,
this);
104 if (m_bIsShowingDescription)
105 ShowAttributeDescription();
117 m_Attribute = attribute;
118 m_AttributeManager = SCR_AttributesManagerEditorComponent.Cast(SCR_AttributesManagerEditorComponent.GetInstance(SCR_AttributesManagerEditorComponent));
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);
127 m_SubAttributeIndicator = w.FindAnyWidget(m_sSubAttributeIndicatorName);
131 Widget tickbox = w.FindAnyWidget(m_sTickBoxAttributeName);
134 Print(
string.Format(
"SCR_BaseEditorAttributeUIComponent could not find tickbox: %1!", m_sTickBoxAttributeName), LogLevel.ERROR);
140 m_GamePadLockedSelector = w.FindAnyWidget(m_sGamePadLockedSelectorName);
142 if (m_GamePadLockedSelector)
147 focusComponent.GetOnFocusChanged().Insert(GamePadLockedSelectorFocusChanged);
150 if (m_TickBoxAttribute)
151 m_TickBoxAttribute.GetOnToggleChanged().Insert(OnTickboxToggleChanged);
155 Widget uiComponentWidget = w.FindAnyWidget(m_sUiComponentName);
156 if (uiComponentWidget)
165 m_bEnabledByTickbox = (!attribute.GetIsMultiSelect()) || (attribute.GetIsMultiSelect() && !attribute.GetHasConflictingValues() || (attribute.GetHasConflictingValues() && attribute.GetIsOverridingValues()));
168 ToggleEnableAttribute(attribute.IsEnabled());
170 if (attribute.GetIsSubAttribute())
174 LayoutSlot.SetPadding(w,0,0,0,m_fBottomPadding);
177 typename linkedOverrideAttributeType =
typename.Empty;
179 if (attribute.GetHasConflictingValues() && !GetAttribute().GetInitCalled())
181 GetGame().OnInputDeviceIsGamepadInvoker().Insert(SetGamepadLockSelectorActive);
185 if (attribute.GetIsMultiSelect())
188 if (attribute.GetHasConflictingValues() && (!GetAttribute().GetInitCalled() || GetAttribute().GetConflictingAttributeWasReset()))
190 if (!attribute.GetInitCalled())
191 attribute.SetInitCalled(
true);
192 else if (attribute.GetConflictingAttributeWasReset())
193 attribute.SetConflictingAttributeWasReset(
false);
195 attribute.ResetAttribute();
196 SetVariableToDefaultValue(m_Attribute.GetVariableOrCopy());
202 array<ref SCR_BaseEditorAttributeEntry> entries =
new array<ref SCR_BaseEditorAttributeEntry>;
203 attribute.GetEntries(entries);
205 foreach (SCR_BaseEditorAttributeEntry entry: entries)
213 overrideEntry.GetToggleStateAndTypename(isOverride, linkedOverrideAttributeType);
214 attribute.SetIsOverridingValues(isOverride);
221 if (attribute.GetIsMultiSelect())
223 if (attribute.GetHasConflictingValues())
224 m_TickBoxAttribute.InitTickbox(attribute.GetIsOverridingValues(),
this);
226 m_TickBoxAttribute.InitDisabled();
229 else if (attribute.GetHasConflictingValues())
231 m_TickBoxAttribute.InitTickbox(attribute.GetIsOverridingValues(),
this, linkedOverrideAttributeType);
235 m_wAttributeHolder = w.FindAnyWidget(m_sAttributeHolder);
236 if (m_wAttributeHolder)
238 Widget child = m_wAttributeHolder.GetChildren();
243 eventHandler.GetOnFocus().Insert(OnFocusAttributeWidget);
244 child.AddHandler(eventHandler);
252 protected void ToggleButtonSelected(
bool selected,
int index,
bool animated =
true)
258 protected void SetAsSubAttribute()
260 m_bIsSubAttribute =
true;
261 m_Attribute.GetOnSetAsSubAttribute().Remove(SetAsSubAttribute);
263 if (!m_SubAttributeIndicator)
265 Print(
"SCR_BaseEditorAttributeUIComponent is lacking subattribute indicator and can never be shown as a subattribute", LogLevel.WARNING);
269 m_SubAttributeIndicator.SetVisible(
true);
271 if (GetAttribute().GetHasConflictingValues())
272 m_TickBoxAttribute.ToggleEnableByAttribute(
false);
278 AttributeValueChanged();
283 protected void AttributeValueChanged()
285 m_Attribute.UpdateInterlinkedVariables(m_Attribute.GetVariable(), m_AttributeManager);
286 m_Attribute.PreviewVariable(
true, m_AttributeManager);
289 ShowAttributeDescription();
290 Event_OnAttributeChanged.Invoke();
296 if (!m_AttributeManager)
299 m_bIsShowingDescription =
true;
302 if (!m_TickBoxAttribute.GetToggled() && m_TickBoxAttribute.IsVisibleAndEnabled())
304 m_AttributeManager.SetAttributeDescription(m_AttributeManager.GetConflictingAttributeUIInfo(), m_AttributeManager.GetConflictingAttributeUIInfo().GetDescription());
308 array<SCR_BaseAttributeDynamicDescription> dynamicDescriptionArray = {};
309 m_Attribute.GetDynamicDescriptionArray(dynamicDescriptionArray);
315 if (discription.IsValid(m_Attribute,
this))
317 dynamicDescription = discription;
324 if (dynamicDescription)
330 if (m_bShowButtonDescription && (!buttonDynamicDescription || !buttonDynamicDescription.HasPriorityOverButton()))
332 m_AttributeManager.SetAttributeDescription(m_ButtonDescriptionUIInfo,
string.Empty, m_sButtonDescriptionParam1);
337 if (dynamicDescription)
340 string param1, param2, param3;
342 dynamicDescription.GetDescriptionData(m_Attribute,
this, uiInfo, param1, param2, param3);
346 Print(
"SCR_BaseEditorAttributeUIComponent 'dynamicDescription' is missing UIInfo this means a dynamic description was added but the UIInfo was not set!", LogLevel.WARNING);
347 m_AttributeManager.SetAttributeDescription(GetAttribute().
GetUIInfo());
351 string descr = uiInfo.GetDescription();
355 Print(
"'SCR_BaseEditorAttributeUIComponent' dynamicDescription does not have a description assigned! This means the description is not set!", LogLevel.WARNING);
356 m_AttributeManager.SetAttributeDescription(GetAttribute().
GetUIInfo());
360 m_AttributeManager.SetAttributeDescription(uiInfo, descr, param1, param2, param3);
365 m_AttributeManager.SetAttributeDescription(GetAttribute().
GetUIInfo());
368 protected void HideAttributeDescription()
370 if (!m_AttributeManager)
373 m_bIsShowingDescription =
false;
374 m_AttributeManager.SetAttributeDescription(
null);
380 if (showButtonDescription)
381 m_ActiveButtonDescription = button;
382 else if (m_ActiveButtonDescription != button && button !=
null)
385 if (buttonDescription.IsEmpty())
386 m_bShowButtonDescription =
false;
388 m_bShowButtonDescription = showButtonDescription;
390 m_sButtonDescriptionParam1 = buttonDescription;
393 ShowAttributeDescription();
401 ScriptInvoker GetOnAttributeChanged()
403 return Event_OnAttributeChanged;
410 ScriptInvoker GetOnAttributeUIFocusChanged()
412 return Event_OnAttributeUIFocusChanged;
419 ScriptInvoker GetOnEnabledByAttribute()
421 return Event_OnEnabledByAttribute;
428 ScriptInvoker GetOnMouseLeave()
430 return Event_OnMouseLeave;
437 SetFromVarOrDefault();
440 protected void ToggleEnableAttribute(
bool enabled)
442 m_bEnabledByAttribute = enabled;
443 ToggleEnable(m_bEnabledByAttribute);
444 Event_OnEnabledByAttribute.Invoke(m_bEnabledByAttribute);
446 if (GetAttribute().GetHasConflictingValues())
447 m_TickBoxAttribute.ToggleEnableByAttribute(enabled);
455 protected void ToggleEnable(
bool enabled)
457 if (m_SubAttributeIndicator)
459 Color color = Color.FromInt(m_SubAttributeIndicator.GetColor().PackToInt());
461 color.SetA(m_fSubAttributeDisabledAlphaColor);
465 m_SubAttributeIndicator.SetColor(color);
469 if (GetAttribute().GetHasConflictingValues())
475 if (m_Attribute.GetCopyVariable())
477 GetAttribute().SetVariable(m_Attribute.GetCopyVariable());
478 GetAttribute().ClearCopyVar();
485 if (GetAttribute().GetVariable(
false))
487 GetAttribute().CreateCopyVariable();
488 GetAttribute().ClearVar();
493 if (m_bEnabledByAttribute && m_bEnabledByTickbox)
504 bool GetTickboxEnabled()
506 return m_TickBoxAttribute && m_TickBoxAttribute.GetEnabled();
512 void ToggleEnableAttributeTickbox()
514 if (GetAttribute().GetHasConflictingValues())
515 m_TickBoxAttribute.ToggleTickbox(!GetAttribute().GetIsOverridingValues());
517 if (GetAttribute().GetIsOverridingValues())
520 GetGame().GetWorkspace().SetFocusedWidget(m_GamePadLockedSelector);
524 protected void OnTickboxToggleChanged(
bool toggle)
526 if (GetAttribute().GetHasConflictingValues())
528 GetAttribute().SetIsOverridingValues(toggle);
531 m_bEnabledByTickbox = toggle;
532 ToggleEnable(toggle);
537 AttributeValueChanged();
539 if (m_bIsShowingDescription)
540 ShowAttributeDescription();
544 protected void GamePadLockedSelectorFocusChanged(
bool newFocus)
546 if (!GetAttribute().GetHasConflictingValues())
551 ShowAttributeDescription();
552 Event_OnAttributeUIFocusChanged.Invoke(
this);
557 HideAttributeDescription();
558 Event_OnAttributeUIFocusChanged.Invoke(
null);
573 protected void OnFocusAttributeWidget(Widget w)
580 override bool OnFocus(Widget w,
int x,
int y)
585 ShowButtonDescription(
null,
false);
587 if (GetAttribute().GetHasConflictingValues())
588 Event_OnAttributeUIFocusChanged.Invoke(
this);
590 ShowAttributeDescription();
597 override bool OnFocusLost(Widget w,
int x,
int y)
599 m_bIsFocused =
false;
601 if (GetAttribute().GetHasConflictingValues())
602 Event_OnAttributeUIFocusChanged.Invoke(
null);
607 override bool OnMouseEnter(Widget w,
int x,
int y)
609 return OnFocus(w, x, y);
612 override bool OnMouseLeave(Widget w, Widget enterW,
int x,
int y)
614 Event_OnMouseLeave.Invoke();
619 protected void SetGamepadLockSelectorActive(
bool isGamepad)
621 m_GamePadLockedSelector.SetVisible(isGamepad && !m_TickBoxAttribute.GetToggled());
629 if (m_Attribute.GetOnExternalnChange())
630 m_Attribute.GetOnExternalnChange().Remove(SetFromVarExternal);
632 m_Attribute.GetOnVarChanged().Remove(SetFromVar);
633 m_Attribute.GetOnToggleEnable().Remove(ToggleEnableAttribute);
634 m_Attribute.GetOnToggleButtonSelected().Remove(ToggleButtonSelected);
636 if (!m_bIsSubAttribute)
637 m_Attribute.GetOnSetAsSubAttribute().Remove(SetAsSubAttribute);
639 if (m_Attribute.GetHasConflictingValues())
640 GetGame().OnInputDeviceIsGamepadInvoker().Remove(SetGamepadLockSelectorActive);
643 if (m_TickBoxAttribute)
644 m_TickBoxAttribute.GetOnToggleChanged().Remove(OnTickboxToggleChanged);
647 if (m_GamePadLockedSelector)
652 focusComponent.GetOnFocusChanged().Remove(GamePadLockedSelectorFocusChanged);