17 enum EModularButtonEventHandler
29 class SCR_ModularButtonComponent : ScriptedWidgetComponent
36 protected ref array<ref SCR_ButtonEffectBase>
m_aEffects;
40 [
Attribute(
"false", UIWidgets.CheckBox,
"Can the button be only clicked, or also toggled?")]
43 [
Attribute(
"false", UIWidgets.CheckBox,
"If the button can be toggled, toggle it automatically on click or only through external API?")]
49 [
Attribute(
"2147483647", UIWidgets.Flags,
"Value which will be returned from event handlers. Useful in button-over-button cases: tiles with buttons inside or similar.",
"", ParamEnumArray.FromEnum(EModularButtonEventHandler))]
52 [
Attribute(
"false", UIWidgets.CheckBox,
"The button will be focused on mouse enter events")]
55 [
Attribute(
"false", UIWidgets.CheckBox,
"Mouse over, focus, clicks, etc, will be completely ignored. Useful to create a button driven by SlaveButton effect.")]
88 static SCR_ModularButtonComponent FindComponent(Widget w)
90 return SCR_ModularButtonComponent.Cast(w.FindHandler(SCR_ModularButtonComponent));
97 #ifdef DEBUG_MODULAR_BUTTON
98 _print(
string.Format(
"SetEnabled: %1", enabled));
117 #ifdef DEBUG_MODULAR_BUTTON
118 _print(
string.Format(
"SetToggled: %1", toggled));
204 if (e.m_aTags.Contains(tag))
216 array<SCR_ButtonEffectBase> effects = {};
219 if (e.m_aTags.Contains(tag))
230 array<SCR_ButtonEffectBase> effects = {};
245 #ifdef DEBUG_MODULAR_BUTTON
246 _print(
string.Format(
"SetEffectsEnabled: %1, %2", tag, enable));
251 if (e.m_aTags.Contains(tag))
252 e.SetEnabled(enable);
264 foreach (
string tag : tags)
266 if (e.m_aTags.Contains(tag))
282 #ifdef DEBUG_MODULAR_BUTTON
283 _print(
string.Format(
"SetAllEffectsEnabled: %1", enable));
288 e.SetEnabled(enable);
324 #ifdef DEBUG_MODULAR_BUTTON
328 if (newState != oldState)
390 EInputDeviceType deviceType =
GetGame().GetInputManager().GetLastUsedInputDevice();
392 #ifdef DEBUG_MODULAR_BUTTON
393 _print(
string.Format(
"InvokeEffectsEvent: %1, %2",
typename.EnumToString(
EModularButtonEventFlag, eventFlag),
typename.EnumToString(EInputDeviceType, deviceType)));
396 foreach (SCR_ButtonEffectBase effect :
m_aEffects)
398 if (effect.GetEnabled())
399 effect.Internal_OnEvent(eventFlag, deviceType, instant);
419 if (newToggled != oldToggled)
429 if (invokeOnToggled && newToggled != oldToggled)
439 EInputDeviceType deviceType =
GetGame().GetInputManager().GetLastUsedInputDevice();
440 effect.Internal_OnEvent(state, deviceType,
true);
464 foreach (SCR_ButtonEffectBase effect :
m_aEffects)
467 effect.OnHandlerAttached(w);
476 array<ref Tuple3<Widget, typename, int>> widgetEffectEventMasks = {};
477 foreach (SCR_ButtonEffectBase effect :
m_aEffects)
479 SCR_ButtonEffectWidgetBase widgetEffect = SCR_ButtonEffectWidgetBase.Cast(effect);
480 if (effect.GetEnabled() && widgetEffect)
483 bool disabled =
false;
484 foreach (Tuple3<Widget, typename, int> i : widgetEffectEventMasks)
486 if (i.param1 == widgetEffect.GetTargetWidget() &&
487 i.param2 == widgetEffect.Type() &&
488 (i.param3 & widgetEffect.m_eEvents))
491 widgetEffect.SetEnabled(
false);
500 Tuple3<Widget, typename, int> entry;
501 foreach (Tuple3<Widget, typename, int> i : widgetEffectEventMasks)
503 if (i.param1 == widgetEffect.GetTargetWidget() &&
504 i.param2 == widgetEffect.Type())
513 entry =
new Tuple3<Widget, typename, int>(widgetEffect.GetTargetWidget(), widgetEffect.Type(), 0);
514 widgetEffectEventMasks.Insert(entry);
517 entry.param3 = entry.param3 | widgetEffect.m_eEvents;
527 override bool OnClick(Widget w,
int x,
int y,
int button)
529 #ifdef DEBUG_MODULAR_BUTTON
536 WorkspaceWidget workspace =
GetGame().GetWorkspace();
537 Widget currentFocus = workspace.GetFocusedWidget();
539 workspace.SetFocusedWidget(
m_wRoot);
545 return eventReturnValue;
557 return eventReturnValue;
573 #ifdef DEBUG_MODULAR_BUTTON
584 EInputDeviceType lastInput =
GetGame().GetInputManager().GetLastUsedInputDevice();
585 bool mouseInput = lastInput == EInputDeviceType.MOUSE;
603 #ifdef DEBUG_MODULAR_BUTTON
614 EInputDeviceType lastInput =
GetGame().GetInputManager().GetLastUsedInputDevice();
615 bool mouseInput = lastInput == EInputDeviceType.MOUSE;
627 #ifdef DEBUG_MODULAR_BUTTON
646 #ifdef DEBUG_MODULAR_BUTTON
667 Print(
string.Format(
"[SCR_ModularButtonComponent] %1: %2",
GetRootWidget().
GetName(), s), LogLevel.NORMAL);