4 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Button",
"layout")]
5 protected ResourceName m_ButtonPath;
8 protected string m_VLayoutWidgetName;
11 protected string m_sBottomBarName;
14 protected int m_ButtonPrefabSizeX;
16 protected int m_ButtonPrefabSizeY;
19 protected float m_fMenuMouseOffsetX;
21 [
Attribute(
"0.025",
"Fade delay in seconds. For every new button that is added the delay increases slightly")]
22 protected float m_fFadeDelayNextButton;
24 [
Attribute(
"4",
"How fast each button appears")]
25 protected float m_fButtonFadeSpeed;
27 protected InputManager m_InputManager;
28 protected WorkspaceWidget m_WorkSpace;
30 protected Widget m_ContextMenu;
31 protected Widget m_VLayout;
34 protected vector m_MouseDownScreenPos;
35 protected vector m_MouseDownWorldPos;
37 protected ref map<Widget, SCR_BaseEditorAction> m_ButtonActions =
new map<Widget, SCR_BaseEditorAction>;
39 protected SCR_BaseActionsEditorComponent m_EditorActionsComponent;
44 protected int m_ActionFlagsOnOpen;
46 protected ref ScriptInvoker m_OnContextMenuToggle =
new ScriptInvoker();
48 void CloseContextMenu()
51 if (m_WorkSpace) m_WorkSpace.SetFocusedWidget(
null);
53 m_OnContextMenuToggle.Invoke(
false);
55 ScriptInvoker GetOnContextMenuToggle()
57 return m_OnContextMenuToggle;
60 protected void OnInputDeviceIsGamepad(
bool isGamepad)
65 protected void PopulateContextMenu(vector cursorWorldPosition)
67 array<ref SCR_EditorActionData> actions = {};
69 m_BottomBarFadeUI.GetFadeWidget().SetVisible(
false);
73 Widget lastButtonLayout;
76 for (
int i = 0; i < actions.Count(); i++)
81 bool canBePerformed = actions[i].GetCanBePerformed();
87 Widget buttonLayout = m_WorkSpace.CreateWidgets(m_ButtonPath, m_VLayout);
88 lastButtonLayout = buttonLayout;
94 contextMenuButtonComponent.SetData(info, action.GetShortcut(), canBePerformed);
98 m_ButtonActions.Set(buttonLayout, action);
103 fadeComponent.SetFadeInSpeed(m_fButtonFadeSpeed);
104 fadeComponent.DelayedFadeIn(fadeDelay * 1000,
true);
105 fadeDelay += m_fFadeDelayNextButton;
110 if (lastButtonLayout)
112 Widget divider = lastButtonLayout.FindAnyWidget(
"Stripe");
115 divider.SetVisible(
false);
119 if (m_BottomBarFadeUI)
120 m_BottomBarFadeUI.DelayedFadeIn(fadeDelay * 1000,
true);
123 bool IsContextMenuOpen()
128 protected void OpenContextMenu()
136 RemoveButtonWidgets();
138 m_MouseDownWorldPos = GetCursorWorldPos();
140 PopulateContextMenu(m_MouseDownWorldPos);
143 float contextMenuWidth, contextMenuHeight, screenWidth, screenHeight;
144 m_WorkSpace.GetScreenSize(screenWidth, screenHeight);
147 screenWidth = m_WorkSpace.DPIUnscale(screenWidth);
148 screenHeight = m_WorkSpace.DPIUnscale(screenHeight);
150 contextMenuHeight = m_ButtonActions.Count() * m_ButtonPrefabSizeY;
151 contextMenuWidth = m_ButtonPrefabSizeX;
156 if (m_MouseDownScreenPos[0] + contextMenuWidth > screenWidth)
158 m_MouseDownScreenPos[0] = (m_MouseDownScreenPos[0]) - (contextMenuWidth + m_fMenuMouseOffsetX);
162 m_MouseDownScreenPos[0] = m_MouseDownScreenPos[0] + m_fMenuMouseOffsetX;
164 if (m_MouseDownScreenPos[1] + contextMenuHeight > screenHeight)
166 m_MouseDownScreenPos[1] = (m_MouseDownScreenPos[1]) - contextMenuHeight;
170 FrameSlot.SetPos(
m_ContextMenu, m_MouseDownScreenPos[0], m_MouseDownScreenPos[1]);
172 if (m_ButtonActions.Count() > 0)
175 m_OnContextMenuToggle.Invoke(
true);
179 protected vector GetCursorWorldPos()
181 vector cursorWorldPosition;
187 return cursorWorldPosition;
192 protected void RemoveButtonWidgets()
194 Widget childWidget = m_VLayout.GetChildren();
198 childWidget.RemoveFromHierarchy();
199 childWidget = m_VLayout.GetChildren();
202 m_ButtonActions.Clear();
205 protected void OnMouseLeftDown()
207 if (!IsContextMenuOpen())
return;
209 float mouseX, mouseY, layoutX1, layoutY1, layoutX2, layoutY2, layoutWidth, layoutHeight;
215 layoutX2 = layoutX1 + layoutWidth;
216 layoutY2 = layoutY1 + layoutHeight;
219 if (mouseX < layoutX1 || mouseY < layoutY1 || mouseX > layoutX2 || mouseY > layoutY2)
225 protected void OnOpenActionsMenuDown()
230 m_MouseDownScreenPos = OnCancelDown();
233 protected void OnContextMenuOptionClicked(Widget widget,
float value, EActionTrigger reason)
243 protected void OnEditorModeChanged()
248 override void HandlerAttachedScripted(Widget w)
250 super.HandlerAttachedScripted(w);
252 ArmaReforgerScripted game =
GetGame();
253 m_WorkSpace = game.GetWorkspace();
258 m_InputManager.AddActionListener(
"MouseLeft", EActionTrigger.DOWN, OnMouseLeftDown);
259 m_InputManager.AddActionListener(
"EditorContextMenuClose", EActionTrigger.DOWN, CloseContextMenu);
262 if (m_ButtonPath.IsEmpty())
264 Print(
"Button prefab not set on (actions/waypoint) ContextMenuEditorUIComponent", LogLevel.ERROR);
267 game.OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
276 OnEditorModeChanged();
280 m_VLayout =
m_ContextMenu.FindAnyWidget(m_VLayoutWidgetName);
284 Print(
"Vertical layout not found on (actions/waypoint) ContextMenuEditorUIComponent, see m_VLayoutWidgetName", LogLevel.ERROR);
287 Widget bottomBar = w.FindAnyWidget(m_sBottomBarName);
291 if (m_BottomBarFadeUI)
293 m_BottomBarFadeUI.SetFadeInSpeed(m_fButtonFadeSpeed);
294 bottomBar.SetVisible(
false);
299 override void HandlerDeattached(Widget w)
301 super.HandlerDeattached(w);
305 m_InputManager.RemoveActionListener(
"MouseLeft", EActionTrigger.DOWN, OnMouseLeftDown);
306 m_InputManager.RemoveActionListener(
"EditorContextMenuClose", EActionTrigger.DOWN, CloseContextMenu);
314 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);