Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RadialMenuController.c
Go to the documentation of this file.
1 
6 //------------------------------------------------------------------------------------------------
7 [BaseContainerProps(configRoot: true)]
9 {
10  [Attribute("1")]
11  protected bool m_sEnableControl;
12 
13  [Attribute()]
14  protected ref SCR_SelectionMenuControllerInputs m_RMControls;
15 
16  [Attribute()]
17  protected ref SCR_SelectionMenuData m_Data;
18 
19  protected ref SCR_RadialMenu m_RadialMenuToControl; // Menu that is kept for auto retaking control, can be chenged by user
20  protected ref SCR_RadialMenu m_RadialMenu;
21  protected IEntity m_Owner;
22 
23  // Callbacks
24  //protected ref ScriptInvoker<SCR_RadialMenuController> m_OnBeforeOpen;
25  protected ref ScriptInvoker<SCR_RadialMenuController, bool> m_OnInputOpen;
26  protected ref ScriptInvoker<SCR_RadialMenuController> m_OnTakeControl;
27  protected ref ScriptInvoker<SCR_RadialMenuController, bool> m_OnControllerChanged;
28 
29  //------------------------------------------------------------------------------------------------
30  ScriptInvoker GetOnInputOpen()
31  {
32  if (!m_OnInputOpen)
33  m_OnInputOpen = new ScriptInvoker();
34 
35  return m_OnInputOpen;
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  protected void InvokeOnInputOpen(bool hasControl)
40  {
41  if (m_OnInputOpen)
42  m_OnInputOpen.Invoke(this, hasControl);
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  ScriptInvoker GetOnTakeControl()
47  {
48  if (!m_OnTakeControl)
49  m_OnTakeControl = new ScriptInvoker();
50 
51  return m_OnTakeControl;
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  protected void InvokeOnTakeControl()
56  {
57  if (m_OnTakeControl)
58  m_OnTakeControl.Invoke(this);
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  protected void InvokeOnControllerChanged(bool hasControl)
63  {
64  if (m_OnControllerChanged)
65  m_OnControllerChanged.Invoke(this, hasControl);
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  ScriptInvoker GetOnControllerChanged()
70  {
71  if (!m_OnControllerChanged)
72  m_OnControllerChanged = new ScriptInvoker();
73 
74  return m_OnControllerChanged;
75  }
76 
77  //------------------------------------------------------------------------------------------------
80  void Control(IEntity owner, SCR_RadialMenu radialMenu = null)
81  {
82  // Clear previous inputs
83  if (radialMenu)
84  radialMenu.GetOnControllerChanged().Remove(OnMenuControllerChanged);
85 
86  m_Owner = owner;
87 
88  // Setup radial menu
89  if (radialMenu == null)
90  radialMenu = SCR_RadialMenu.GlobalRadialMenu();
91 
92  m_RadialMenu = radialMenu;
93  if (!m_RadialMenu)
94  return;
95 
96  m_RadialMenu.SetController(m_Owner, m_RMControls);
97 
98  if (m_RadialMenu)
99  m_RadialMenu.GetOnControllerChanged().Insert(OnMenuControllerChanged);
100 
101  InvokeOnTakeControl();
102  }
103 
104  //------------------------------------------------------------------------------------------------
106  void StopControl(bool closeMenu = false)
107  {
108  if (m_RadialMenu)
109  {
110  m_RadialMenu.GetOnControllerChanged().Remove(OnMenuControllerChanged);
111 
112  if (closeMenu)
113  m_RadialMenu.Close();
114 
115  m_RadialMenu = null;
116  }
117  }
118 
119  //------------------------------------------------------------------------------------------------
121  void SetMenuDisplay()
122  {
123 
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  void UpdateMenuData()
128  {
129  if (m_RadialMenu)
130  m_RadialMenu.AddEntries(m_Data.GetEntries(), true);
131  }
132 
133  //------------------------------------------------------------------------------------------------
134  // Callbacks
135  //------------------------------------------------------------------------------------------------
136 
137  //------------------------------------------------------------------------------------------------
138  void OnInputOpen()
139  {
140  bool hasControl = HasControl();
141  InvokeOnInputOpen(hasControl);
142 
143  if (!m_sEnableControl)
144  return;
145 
146  if (!HasControl())
147  Control(m_Owner, m_RadialMenuToControl);
148 
149  // Check owner character concious state
150  if (!m_RMControls.m_bShowWhileUnconcious)
151  {
152  IEntity controllerEntity = SCR_PlayerController.GetLocalControlledEntity();
153  if (controllerEntity)
154  {
155  CharacterControllerComponent characterControler = CharacterControllerComponent.Cast(controllerEntity.FindComponent(CharacterControllerComponent));
156  if (characterControler && characterControler.IsUnconscious())
157  return;
158  }
159  }
160 
161  // Setup and open menu
162  if (!m_RadialMenu)
163  return;
164 
165  if (!m_RadialMenu.HasDisplay())
166  m_RadialMenu.SetMenuDisplay();
167 
168  m_RadialMenu.Open();
169  }
170 
171  //------------------------------------------------------------------------------------------------
172  protected void OnMenuControllerChanged(SCR_SelectionMenu menu, SCR_SelectionMenuControllerInputs controller)
173  {
174  // Check menu
175  if (menu != m_RadialMenu)
176  return;
177 
178  // Check control
179  if (controller != m_RMControls)
180  {
181  menu.ClearEntries();
182 
183  m_RadialMenu.Close();
184  InvokeOnControllerChanged(false);
185 
186 
187  StopControl();
188  }
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  // Get
193  //------------------------------------------------------------------------------------------------
194 
195  //------------------------------------------------------------------------------------------------
196  void SetEnableControl(bool enable)
197  {
198  m_sEnableControl = enable;
199  }
200 
201  //------------------------------------------------------------------------------------------------
202  bool GetEnableControl()
203  {
204  return m_sEnableControl;
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  void SetRadialMenuToControl(SCR_RadialMenu radialMenu)
209  {
210  m_RadialMenuToControl = radialMenu;
211  }
212 
213  //------------------------------------------------------------------------------------------------
214  SCR_RadialMenu GetRadialMenu()
215  {
216  return m_RadialMenu;
217  }
218 
219  //------------------------------------------------------------------------------------------------
221  {
222  return m_RMControls;
223  }
224 
225  //------------------------------------------------------------------------------------------------
226  SCR_SelectionMenuData GetData()
227  {
228  return m_Data;
229  }
230 
231  //------------------------------------------------------------------------------------------------
233  bool HasControl()
234  {
235  if (!m_RadialMenu)
236  {
237  Print("[SCR_RadialMenuController] - has no menu selected to control!", LogLevel.WARNING);
238  return false;
239  }
240 
241  if (!m_RadialMenu.GetControllerInputs())
242  return false;
243 
244  return m_RadialMenu.GetControllerInputs() == m_RMControls;
245  }
246 
247  //------------------------------------------------------------------------------------------------
249  {
250  if (m_RMControls && !m_RMControls.m_sOpenAction.IsEmpty())
251  GetGame().GetInputManager().AddActionListener(m_RMControls.m_sOpenAction, EActionTrigger.DOWN, OnInputOpen);
252  }
253 }
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_RadialMenuController
Definition: SCR_RadialMenuController.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SelectionMenu
Definition: SCR_SelectionMenu.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_RadialMenu
protected SCR_RadialMenu m_RadialMenu
Definition: SCR_PlayerControllerCommandingComponent.c:17
SCR_SelectionMenuControllerInputs
Definition: SCR_SelectionMenu.c:794
SCR_SelectionMenuData
Definition: SCR_SelectionMenu.c:845
m_Owner
SCR_AIGroupUtilityComponentClass m_Owner
SCR_RadialMenu
Definition: SCR_RadialMenu.c:8
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468