Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WeaponSwitchingBaseUI.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/UI/HUD/WeaponSwitchingBar", description: "Concept of quick selection bar")]
2
3//---- REFACTOR NOTE START: This script is not made the best way and relies on delayed calls a bit too much. ----
4
5class SCR_WeaponSwitchingBaseUI : SCR_InfoDisplay
6{
7 protected static ResourceName s_sItemPreviewManagerPrefab = "{9F18C476AB860F3B}Prefabs/World/Game/ItemPreviewManager.et"; // This could be attribute
8 protected static Widget s_wQuickSlotStorage;
11
12 static bool s_bOpened;
13 static bool s_bRadial;
14
15 [Attribute("{A1E61EF091EAC47D}UI/layouts/Menus/Inventory/InventoryQuickSlotsGrid.layout")]
16 protected string m_sQuickSlotGridLayout;
17
18 //------------------------------------------------------------------------------------------------
19 static void RefreshQuickSlots(int id = -1)
20 {
22 return;
23
24 if (id < 0)
25 s_QuickSlotStorage.RefreshQuickSlots();
26 else
27 s_QuickSlotStorage.RefreshSlot(id);
28
29 s_QuickSlotStorage.HighlightLastSelectedSlot();
30 }
31
32 //------------------------------------------------------------------------------------------------
33 static void SelectQuickSlot(int id)
34 {
35 bool wasOpen = s_bOpened;
36 if (!wasOpen && s_WeaponSwitchingUI)
37 s_WeaponSwitchingUI.OpenQuickSlots();
38
40 s_QuickSlotStorage.SelectSlot(id);
41
42 if (!wasOpen && s_WeaponSwitchingUI)
43 s_WeaponSwitchingUI.CloseQuickSlots();
44 }
45
46 //------------------------------------------------------------------------------------------------
47 static void HighlightQuickSlot(int id, bool highlight = true)
48 {
49 bool wasOpen = s_bOpened;
50 if (!wasOpen && s_WeaponSwitchingUI)
51 s_WeaponSwitchingUI.OpenQuickSlots();
52
54 s_QuickSlotStorage.HighlightSlot(id, highlight);
55
56 if (!wasOpen && s_WeaponSwitchingUI)
57 s_WeaponSwitchingUI.CloseQuickSlots();
58 }
59
60 //------------------------------------------------------------------------------------------------
61 protected void Init(IEntity owner)
62 {
64 {
65 Print("More than one SCR_WeaponSwitchingBaseUI used in " + __FILE__ + " L" + __LINE__, LogLevel.WARNING);
66 return;
67 }
68
70 s_bOpened = false;
71
72 if (!owner || !m_wRoot)
73 return;
74
75 ChimeraWorld world = ChimeraWorld.CastFrom(owner.GetWorld());
76 if (world)
77 {
78 //instantiate the preview manager
79 if (!world.GetItemPreviewManager())
80 {
82 if (rsc.IsValid())
83 GetGame().SpawnEntityPrefabLocal(rsc, world);
84 }
85 }
86
87 InputManager inputManager = GetGame().GetInputManager();
88 inputManager.AddActionListener("Inventory_WeaponSwitching", EActionTrigger.DOWN, Action_QuickSlotsBar);
89 inputManager.AddActionListener("Inventory_WeaponSwitching", EActionTrigger.UP, Action_QuickSlotsBar);
90 inputManager.AddActionListener("Inventory_WeaponSwitchingRadial", EActionTrigger.DOWN, Action_QuickSlotsRadial);
91 inputManager.AddActionListener("Inventory_WeaponSwitchingRadial", EActionTrigger.UP, Action_QuickSlotsRadial);
92
93 for (int i; i < 10; ++i)
94 {
95 inputManager.AddActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.DOWN, Action_SwitchSlot);
96 inputManager.AddActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.UP, Action_QuickSlotsBar);
97 }
98 }
99
100 //------------------------------------------------------------------------------------------------
101 protected void RemoveActionListeners()
102 {
103 InputManager inputManager = GetGame().GetInputManager();
104 inputManager.RemoveActionListener("Inventory_WeaponSwitching", EActionTrigger.DOWN, Action_QuickSlotsBar);
105 inputManager.RemoveActionListener("Inventory_WeaponSwitching", EActionTrigger.UP, Action_QuickSlotsBar);
106 inputManager.RemoveActionListener("Inventory_WeaponSwitchingRadial", EActionTrigger.DOWN, Action_QuickSlotsRadial);
107 inputManager.RemoveActionListener("Inventory_WeaponSwitchingRadial", EActionTrigger.UP, Action_QuickSlotsRadial);
108
109 for (int i; i < 10; ++i)
110 {
111 inputManager.RemoveActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.DOWN, Action_SwitchSlot);
112 inputManager.RemoveActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.UP, Action_QuickSlotsBar);
113 }
114 }
115
116 //------------------------------------------------------------------------------------------------
118 {
119 if (s_bOpened)
120 return;
121
123 CharacterControllerComponent controller;
124
125 if (character)
126 controller = character.GetCharacterController();
127
128 if (controller && controller.GetLifeState() != ECharacterLifeState.ALIVE)
129 return;
130
131 GetGame().GetInputManager().AddActionListener("CharacterSwitchWeapon", EActionTrigger.VALUE, Action_ScrollSlot);
132 s_bOpened = true;
133 GetGame().GetCallqueue().Remove(ShowQuickSlots); // if there's a delayed Show method from the previous quick bar usage, purge it
134
135 if (!m_wRoot)
136 return;
137
139 {
141 s_wQuickSlotStorage.RemoveFromHierarchy();
142 }
143 Widget parent = m_wRoot.FindAnyWidget("QuickSlots");
144 s_wQuickSlotStorage = GetGame().GetWorkspace().CreateWidgets(m_sQuickSlotGridLayout, parent);
146 return;
147
150 s_QuickSlotStorage.SetInitialQuickSlot();
151 s_QuickSlotStorage.HighlightLastSelectedSlot();
152
153 Show(true, UIConstants.FADE_RATE_DEFAULT);
154 BlurWidget wBlur = BlurWidget.Cast(m_wRoot.FindAnyWidget("wBlur"));
155
156 if (wBlur)
157 wBlur.SetVisible(true);
158
159 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_OPEN);
160
161 if (!controller)
162 return;
163
164 SCR_InventoryStorageManagerComponent inventory = SCR_InventoryStorageManagerComponent.Cast(controller.GetInventoryStorageManager());
165 if (inventory)
166 {
167 inventory.m_OnQuickBarOpenInvoker.Invoke(true);
168 // Delay by 1 frame so the selected slot gets updated first
169 GetGame().GetCallqueue().Call(ShowCommand, inventory);
170 }
171 }
172
173 //------------------------------------------------------------------------------------------------
175 {
177 s_QuickSlotStorage.SetQuickBarClosed();
178
179 GetGame().GetInputManager().RemoveActionListener("CharacterSwitchWeapon", EActionTrigger.VALUE, Action_ScrollSlot);
180 s_bOpened = false;
181
182 if (!m_wRoot)
183 return;
184
185 BlurWidget wBlur = BlurWidget.Cast(m_wRoot.FindAnyWidget("wBlur"));
186 if (wBlur)
187 wBlur.SetVisible(false);
188
189 if (s_QuickSlotStorage && s_QuickSlotStorage.UseItemInSlot(true))
190 GetGame().GetCallqueue().CallLater(ShowQuickSlots, 2000, false, false, UIConstants.FADE_RATE_DEFAULT, true);
191 else
192 Show(false, UIConstants.FADE_RATE_DEFAULT);
193
194 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
195 if (!character)
196 return;
197
198 CharacterControllerComponent controller = character.GetCharacterController();
199 if (!controller)
200 return;
201
202 SCR_InventoryStorageManagerComponent inventory = SCR_InventoryStorageManagerComponent.Cast(controller.GetInventoryStorageManager());
203 if (inventory)
204 inventory.m_OnQuickBarOpenInvoker.Invoke(false);
205
206 SCR_PlayerControllerCommandingComponent commandComp = SCR_PlayerControllerCommandingComponent.GetLocalPlayerControllerCommandingComponent();
207 if (commandComp)
208 commandComp.HideCommandPreview();
209 }
210
211 //------------------------------------------------------------------------------------------------
212 protected void ShowCommand(notnull SCR_InventoryStorageManagerComponent inventory)
213 {
214 SCR_CharacterInventoryStorageComponent characterStorage = inventory.GetCharacterStorage();
215 if (!characterStorage)
216 return;
217
218 SCR_QuickslotCommandContainer commandQuickSlotContainer = SCR_QuickslotCommandContainer.Cast(characterStorage.GetContainerFromQuickslot(s_QuickSlotStorage.GetLastSelectedSlotIndex()));
219 if (!commandQuickSlotContainer)
220 return;
221
222 SCR_PlayerControllerCommandingComponent commandComp = SCR_PlayerControllerCommandingComponent.GetLocalPlayerControllerCommandingComponent();
223 if (!commandComp)
224 return;
225
226 commandComp.ShowCommandPreview(commandQuickSlotContainer.GetCommandName());
227 }
228
229 //------------------------------------------------------------------------------------------------
230 protected void Action_QuickSlotsRadial(float value = 0.0, EActionTrigger reason = 0)
231 {
232 bool radial = reason == EActionTrigger.DOWN;
233
234 if (!s_bOpened)
235 {
236 s_bRadial = radial;
237 return;
238 }
239
240
241 // Restart the quick slots bar
242 if (radial != s_bRadial)
243 {
244 s_bRadial = radial;
247 }
248 }
249
250 //------------------------------------------------------------------------------------------------
251 protected void Action_QuickSlotsBar(float value = 0.0, EActionTrigger reason = 0)
252 {
253 if (reason == EActionTrigger.DOWN)
255 else
257 }
258
259 //------------------------------------------------------------------------------------------------
260 protected void Action_SwitchSlot(float value = 0.0, EActionTrigger reason = 0)
261 {
262 int targetSlot = -1;
263
264 InputManager inputManager = GetGame().GetInputManager();
265 if (inputManager.GetActionTriggered("SwitchWeaponCategory1"))
266 targetSlot = 0;
267 else if (inputManager.GetActionTriggered("SwitchWeaponCategory2"))
268 targetSlot = 1;
269 else if (inputManager.GetActionTriggered("SwitchWeaponCategory3"))
270 targetSlot = 2;
271 else if (inputManager.GetActionTriggered("SwitchWeaponCategory4"))
272 targetSlot = 3;
273 else if (inputManager.GetActionTriggered("SwitchWeaponCategory5"))
274 targetSlot = 4;
275 else if (inputManager.GetActionTriggered("SwitchWeaponCategory6"))
276 targetSlot = 5;
277 else if (inputManager.GetActionTriggered("SwitchWeaponCategory7"))
278 targetSlot = 6;
279 else if (inputManager.GetActionTriggered("SwitchWeaponCategory8"))
280 targetSlot = 7;
281 else if (inputManager.GetActionTriggered("SwitchWeaponCategory9"))
282 targetSlot = 8;
283 else if (inputManager.GetActionTriggered("SwitchWeaponCategory0"))
284 targetSlot = 9;
285
286 if (targetSlot < 0)
287 return;
288
289 if (s_bOpened && s_bRadial)
291
292 s_bRadial = false;
294
295 SelectQuickSlot(targetSlot);
296 }
297
298 //------------------------------------------------------------------------------------------------
299 protected void Action_ScrollSlot(float value = 0.0, EActionTrigger reason = 0)
300 {
302 return;
303
304 if (float.AlmostEqual(value, 0))
305 return;
306
307 s_QuickSlotStorage.SelectSlot(value);
308 }
309
310 //------------------------------------------------------------------------------------------------
311 override void UpdateValues(IEntity owner, float timeSlice)
312 {
313 if (!s_bOpened)
314 return;
315
316 GetGame().GetInputManager().ActivateContext("WeaponSelectionContext");
317 }
318
319 protected void ShowQuickSlots(bool show, float speed = UIConstants.FADE_RATE_DEFAULT)
320 {
321 Show(show, speed);
322 }
323
324 //------------------------------------------------------------------------------------------------
325 override event void OnStartDraw(IEntity owner)
326 {
327 super.OnStartDraw(owner);
328 Init(owner);
329 Show(false, 0);
330 }
331
332 //------------------------------------------------------------------------------------------------
333 override event void OnStopDraw(IEntity owner)
334 {
335 super.OnStopDraw(owner);
337 s_QuickSlotStorage = null;
338 }
339
340 //------------------------------------------------------------------------------------------------
345}
346
347class SCR_QuickSlotRefreshCB : ScriptedInventoryOperationCallback
348{
349 override void OnComplete()
350 {
351 SCR_WeaponSwitchingBaseUI.RefreshQuickSlots();
352 }
353}
354
355//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
override void Init()
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Widget m_wRoot
proto external BaseWorld GetWorld()
Input management system for user interactions.
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
SCR_QuickslotBaseContainer GetContainerFromQuickslot(int index)
static IEntity GetLocalControlledEntity()
override event void OnStartDraw(IEntity owner)
static void HighlightQuickSlot(int id, bool highlight=true)
static ref SCR_InventoryStorageQuickSlotsUI s_QuickSlotStorage
static void RefreshQuickSlots(int id=-1)
void ShowQuickSlots(bool show, float speed=UIConstants.FADE_RATE_DEFAULT)
override void UpdateValues(IEntity owner, float timeSlice)
static SCR_WeaponSwitchingBaseUI s_WeaponSwitchingUI
void Action_SwitchSlot(float value=0.0, EActionTrigger reason=0)
void Action_QuickSlotsBar(float value=0.0, EActionTrigger reason=0)
override event void OnStopDraw(IEntity owner)
void ShowCommand(notnull SCR_InventoryStorageManagerComponent inventory)
void Action_ScrollSlot(float value=0.0, EActionTrigger reason=0)
static ResourceName s_sItemPreviewManagerPrefab
void Action_QuickSlotsRadial(float value=0.0, EActionTrigger reason=0)
static SCR_WeaponSwitchingBaseUI GetWeaponSwitchingBaseUI()
override void Show()
Definition gameLib.c:262
ECharacterLifeState
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
SCR_FieldOfViewSettings Attribute
EActionTrigger