4 [
Attribute(defvalue:
"0", uiwidget: UIWidgets.ComboBox, enums: { ParamEnum(
"LMB",
"0",
""), ParamEnum(
"RMB",
"1",
""), ParamEnum(
"MMB",
"2",
""), ParamEnum(
"ALL",
"3",
"") },
desc:
"ID of mouse button which activates the action upon click.")]
5 private int m_iMouseButton;
7 [
Attribute(
desc:
"Name of input action which activates the action.")]
8 private string m_bActionName;
10 [
Attribute(defvalue:
"2", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EActionTrigger))]
11 private EActionTrigger m_ActionTrigger;
13 [
Attribute(
desc:
"Name of the widget which shows key assigned to the input action.")]
14 private string m_bWidgetHintName;
16 private Widget m_wWidget;
17 private ref ScriptInvoker m_OnAction =
new ScriptInvoker();
22 ScriptInvoker GetOnAction()
32 return m_iMouseButton;
48 static ScriptInvoker GetOnAction(Widget w,
string buttonName,
bool canCreateComponent =
false,
int mouseButton = 0)
50 Widget button = w.FindAnyWidget(buttonName);
53 Print(
string.Format(
"Widget '%1' not found in widget '%2'!", buttonName, w.GetName()), LogLevel.ERROR);
54 return new ScriptInvoker();
57 return GetOnAction(button, canCreateComponent, mouseButton);
72 static ScriptInvoker GetOnAction(Widget button,
bool canCreateComponent =
false,
int mouseButton = 0)
75 int countHandlers = button.GetNumHandlers();
76 for (
int i = 0; i < countHandlers; i++)
79 if (componentCandidate && componentCandidate.GetMouseButton() == mouseButton)
81 component = componentCandidate;
88 if (canCreateComponent)
91 component.m_iMouseButton = mouseButton;
92 button.AddHandler(component);
96 Print(
string.Format(
"Widget '%1' is missing ButtonActionComponent component!", button.GetName()), LogLevel.ERROR);
97 return new ScriptInvoker();
101 return component.GetOnAction();
105 protected void Execute(
float value, EActionTrigger reason)
107 if (!m_wWidget.IsVisible() || !m_wWidget.IsEnabledInHierarchy())
114 protected void OnAction(
float value, EActionTrigger reason)
116 Execute(value, reason);
120 override bool OnClick(Widget w,
int x,
int y,
int button)
122 if (button == m_iMouseButton || m_iMouseButton == 3)
123 Execute(1, EActionTrigger.DOWN);
129 override void HandlerAttached(Widget w)
134 RichTextWidget widgetIcon;
135 if (m_bWidgetHintName.IsEmpty())
136 widgetIcon = RichTextWidget.Cast(w);
138 widgetIcon = RichTextWidget.Cast(w.FindAnyWidget(m_bWidgetHintName));
142 if (m_bActionName !=
"")
143 widgetIcon.SetText(
string.Format(
"<action name=\"%1\"/>", m_bActionName));
145 widgetIcon.SetText(
"");
149 if (m_bWidgetHintName !=
"")
150 Print(
string.Format(
"ButtonActionComponent: RichTextWidget widget '%1' not found on widget '%2'!", m_bWidgetHintName, w.GetName()), LogLevel.ERROR);
154 if (m_bActionName ==
"")
157 ArmaReforgerScripted game =
GetGame();
161 InputManager inputManager = game.GetInputManager();
163 inputManager.AddActionListener(m_bActionName, m_ActionTrigger, OnAction);
167 override void HandlerDeattached(Widget w)
169 if (m_bActionName ==
"")
172 ArmaReforgerScripted game =
GetGame();
176 InputManager inputManager = game.GetInputManager();
178 inputManager.RemoveActionListener(m_bActionName, m_ActionTrigger, OnAction);