Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseContextMenuEditorUIComponent.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 [Attribute("", UIWidgets.ResourceNamePicker, "Button", "layout")]
6
7 [Attribute("VLayout", UIWidgets.EditBox)]
8 protected string m_VLayoutWidgetName;
9
10 [Attribute("BottomBar")]
11 protected string m_sBottomBarName;
12
13 [Attribute("250", desc: "Screen width of the button prefab")]
14 protected int m_ButtonPrefabSizeX;
15 [Attribute("34", desc: "Screen height of the button prefab")]
16 protected int m_ButtonPrefabSizeY;
17
18 [Attribute("4")]
19 protected float m_fMenuMouseOffsetX;
20
21 [Attribute("0.025", "Fade delay in seconds. For every new button that is added the delay increases slightly")]
22 protected float m_fFadeDelayNextButton;
23
24 [Attribute("4", "How fast each button appears")]
25 protected float m_fButtonFadeSpeed;
26
29
31 protected Widget m_VLayout;
33
36
38
39 protected SCR_BaseActionsEditorComponent m_EditorActionsComponent;
43
44 protected int m_ActionFlagsOnOpen;
45
47
49 {
50 if (m_ContextMenu)
51 m_ContextMenu.SetVisible(false);
52
53 if (m_WorkSpace)
54 m_WorkSpace.SetFocusedWidget(null);
55
56 m_OnContextMenuToggle.Invoke(false);
57 }
62
63 protected void OnInputDeviceIsGamepad(bool isGamepad)
64 {
66 }
67
68 //---- REFACTOR NOTE START: UI behavior might be unifiend
69 // Using hard coded widget name
70
71 protected void PopulateContextMenu(vector cursorWorldPosition)
72 {
73 array<ref SCR_EditorActionData> actions = {};
74 m_EditorActionsComponent.GetAndEvaluateActions(cursorWorldPosition, actions, m_ActionFlagsOnOpen);
75 m_BottomBarFadeUI.GetFadeWidget().SetVisible(false);
76
77 float fadeDelay = 0;
78
79 Widget lastButtonLayout;
80
81 // Add Context Action buttons
82 for (int i = 0; i < actions.Count(); i++)
83 {
84 SCR_BaseEditorAction action = actions[i].GetAction();
85
86 // Don't show actions in context menu that can't be performed
87 bool canBePerformed = actions[i].GetCanBePerformed();
88 if (!canBePerformed)
89 continue;
90
91 SCR_UIInfo info = action.GetInfo();
92 // Create button layout
93 Widget buttonLayout = m_WorkSpace.CreateWidgets(m_ButtonPath, m_VLayout);
94 lastButtonLayout = buttonLayout;
95
97
98 ButtonActionComponent.GetOnAction(buttonLayout).Insert(OnContextMenuOptionClicked);
99
100 contextMenuButtonComponent.SetData(info, action.GetShortcut(), canBePerformed);
101
102 SCR_LinkTooltipTargetEditorUIComponent.SetInfo(buttonLayout, info, action);
103
104 m_ButtonActions.Set(buttonLayout, action);
105
106 SCR_FadeUIComponent fadeComponent = SCR_FadeUIComponent.Cast(buttonLayout.FindHandler(SCR_FadeUIComponent));
107 if (fadeComponent)
108 {
109 fadeComponent.SetFadeInSpeed(m_fButtonFadeSpeed);
110 fadeComponent.DelayedFadeIn(fadeDelay * 1000, true);
111 fadeDelay += m_fFadeDelayNextButton;
112 }
113 }
114
115 // Hide the divider for lastButtonLayout
116 if (lastButtonLayout)
117 {
118 Widget divider = lastButtonLayout.FindAnyWidget("Stripe");
119
120 if (divider)
121 divider.SetVisible(false);
122 }
123
124
126 m_BottomBarFadeUI.DelayedFadeIn(fadeDelay * 1000, true);
127 }
128
129 //---- REFACTOR NOTE END ----
130
132 {
133 return m_ContextMenu != null && m_ContextMenu.IsVisibleInHierarchy();
134 }
135
136 protected void OpenContextMenu()
137 {
138 if (!m_InputManager.IsUsingMouseAndKeyboard() || !m_EditorActionsComponent)
139 {
140 return;
141 }
142
143 // Remove existing button widgets
145
147
149
150 // Get context menu size and screen size
151 float contextMenuWidth, contextMenuHeight, screenWidth, screenHeight;
152 m_WorkSpace.GetScreenSize(screenWidth, screenHeight);
153
154 // Convert to reference resolution
155 screenWidth = m_WorkSpace.DPIUnscale(screenWidth);
156 screenHeight = m_WorkSpace.DPIUnscale(screenHeight);
157
158 contextMenuHeight = m_ButtonActions.Count() * m_ButtonPrefabSizeY;
159 contextMenuWidth = m_ButtonPrefabSizeX;
160
161
162
163 // If context menu goes offscreen, move to other side of cursor for both x and y
164 if (m_MouseDownScreenPos[0] + contextMenuWidth > screenWidth)
165 {
166 m_MouseDownScreenPos[0] = (m_MouseDownScreenPos[0]) - (contextMenuWidth + m_fMenuMouseOffsetX);
167 }
168 else
169 {
171 }
172 if (m_MouseDownScreenPos[1] + contextMenuHeight > screenHeight)
173 {
174 m_MouseDownScreenPos[1] = (m_MouseDownScreenPos[1]) - contextMenuHeight;
175 }
176
177 // Set Context menu position
179 // Show context menu
180 if (m_ButtonActions.Count() > 0)
181 {
182 m_ContextMenu.SetVisible(true);
183 m_OnContextMenuToggle.Invoke(true);
184 }
185 }
186
188 {
189 vector cursorWorldPosition;
190
192 m_CursorComponent = SCR_CursorEditorUIComponent.Cast(GetRootComponent().FindComponent(SCR_CursorEditorUIComponent));
193
194 if (m_CursorComponent && m_CursorComponent.GetCursorWorldPos(cursorWorldPosition))
195 return cursorWorldPosition;
196
197 return vector.Zero;
198 }
199
200 protected void RemoveButtonWidgets()
201 {
202 Widget childWidget = m_VLayout.GetChildren();
203
204 while (childWidget)
205 {
206 childWidget.RemoveFromHierarchy();
207 childWidget = m_VLayout.GetChildren();
208 }
209
210 m_ButtonActions.Clear();
211 }
212
213 protected void OnMouseLeftDown()
214 {
215 if (!IsContextMenuOpen()) return;
216
217 float mouseX, mouseY, layoutX1, layoutY1, layoutX2, layoutY2, layoutWidth, layoutHeight;
218 mouseX = m_InputManager.GetActionValue("MouseX");
219 mouseY = m_InputManager.GetActionValue("MouseY");
220
221 m_ContextMenu.GetScreenPos(layoutX1, layoutY1);
222 m_ContextMenu.GetScreenSize(layoutWidth, layoutHeight);
223 layoutX2 = layoutX1 + layoutWidth;
224 layoutY2 = layoutY1 + layoutHeight;
225
226 // Close context menu when clicking outside of it
227 if (mouseX < layoutX1 || mouseY < layoutY1 || mouseX > layoutX2 || mouseY > layoutY2)
228 {
230 }
231 }
232
233 protected void OnOpenActionsMenuDown()
234 {
237 if ((!m_MouseArea || m_MouseArea.IsMouseOn()) || (!hoverFilter || !hoverFilter.IsEmpty()))
239 }
240
241 protected void OnContextMenuOptionClicked(Widget widget, float value, EActionTrigger reason)
242 {
243 SCR_BaseEditorAction action = m_ButtonActions.Get(widget);
244 if (action && m_EditorActionsComponent)
245 {
247 }
249 }
250
251 protected void OnEditorModeChanged()
252 {
253 // Override to assign m_EditorActionsComponent
254 }
255
257 {
258 super.HandlerAttachedScripted(w);
259
260 ArmaReforgerScripted game = GetGame();
261 m_WorkSpace = game.GetWorkspace();
262 m_InputManager = game.GetInputManager();
263
264 if (m_InputManager)
265 {
266 m_InputManager.AddActionListener("MouseLeft", EActionTrigger.DOWN, OnMouseLeftDown);
267 m_InputManager.AddActionListener("EditorContextMenuClose", EActionTrigger.DOWN, CloseContextMenu);
268 }
269
270 if (m_ButtonPath.IsEmpty())
271 {
272 Print("Button prefab not set on (actions/waypoint) ContextMenuEditorUIComponent", LogLevel.ERROR);
273 }
274
275 game.OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
276
278
279 m_EditorManager.GetOnModeChange().Insert(OnEditorModeChanged);
280
281 m_CursorComponent = SCR_CursorEditorUIComponent.Cast(GetRootComponent().FindComponent(SCR_CursorEditorUIComponent));
282 m_MouseArea = SCR_MouseAreaEditorUIComponent.Cast(GetRootComponent().FindComponent(SCR_MouseAreaEditorUIComponent));
283
285
287 m_ContextMenu.SetVisible(false);
289
290 if (!m_VLayout)
291 {
292 Print("Vertical layout not found on (actions/waypoint) ContextMenuEditorUIComponent, see m_VLayoutWidgetName", LogLevel.ERROR);
293 }
294
295 Widget bottomBar = w.FindAnyWidget(m_sBottomBarName);
296 if (bottomBar)
297 {
298 m_BottomBarFadeUI = SCR_FadeUIComponent.Cast(bottomBar.FindHandler(SCR_FadeUIComponent));
300 {
302 bottomBar.SetVisible(false);
303 }
304 }
305 }
306
307 override void HandlerDeattached(Widget w)
308 {
309 super.HandlerDeattached(w);
310
311 if (m_InputManager)
312 {
313 m_InputManager.RemoveActionListener("MouseLeft", EActionTrigger.DOWN, OnMouseLeftDown);
314 m_InputManager.RemoveActionListener("EditorContextMenuClose", EActionTrigger.DOWN, CloseContextMenu);
315 }
316
317 if (m_EditorManager)
318 {
319 m_EditorManager.GetOnModeChange().Remove(OnEditorModeChanged);
320 }
321
323 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
324 }
325};
ref DSGameConfig game
Definition DSConfig.c:81
ArmaReforgerScripted GetGame()
Definition game.c:1398
ScriptInvoker OnInputDeviceIsGamepadInvoker()
Definition game.c:238
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Widget GetWidget()
Component to execute action when the button or its shortcut is pressed.
Input management system for user interactions.
ref map< Widget, SCR_BaseEditorAction > m_ButtonActions
void OnContextMenuOptionClicked(Widget widget, float value, EActionTrigger reason)
static SCR_BaseEditableEntityFilter GetInstance(EEditableEntityState state, bool showError=false)
void DelayedFadeIn(int delay, bool setOpacityZero=true)
void SetFadeInSpeed(float fadeInSpeed)
Definition Types.c:486
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
EEditableEntityState
SCR_FieldOfViewSettings Attribute
EActionTrigger
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134