Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
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
5
class
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
;
9
protected
static
ref
SCR_InventoryStorageQuickSlotsUI
s_QuickSlotStorage
;
10
protected
static
SCR_WeaponSwitchingBaseUI
s_WeaponSwitchingUI
;
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
{
21
if
(!
s_QuickSlotStorage
)
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
39
if
(
s_QuickSlotStorage
)
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
53
if
(
s_QuickSlotStorage
)
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
{
63
if
(
s_WeaponSwitchingUI
)
64
{
65
Print
(
"More than one SCR_WeaponSwitchingBaseUI used in "
+ __FILE__ +
" L"
+ __LINE__,
LogLevel
.WARNING);
66
return
;
67
}
68
69
s_WeaponSwitchingUI
=
this
;
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
{
81
Resource
rsc =
Resource
.Load(
s_sItemPreviewManagerPrefab
);
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
//------------------------------------------------------------------------------------------------
117
void
OpenQuickSlots
()
118
{
119
if
(
s_bOpened
)
120
return
;
121
122
ChimeraCharacter
character =
ChimeraCharacter
.Cast(
SCR_PlayerController
.
GetLocalControlledEntity
());
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
138
if
(
s_wQuickSlotStorage
)
139
{
140
s_wQuickSlotStorage
.RemoveHandler(
s_wQuickSlotStorage
.FindHandler(
SCR_InventoryStorageQuickSlotsUI
));
141
s_wQuickSlotStorage
.RemoveFromHierarchy();
142
}
143
Widget
parent =
m_wRoot
.FindAnyWidget(
"QuickSlots"
);
144
s_wQuickSlotStorage
=
GetGame
().GetWorkspace().CreateWidgets(
m_sQuickSlotGridLayout
, parent);
145
if
(!
s_wQuickSlotStorage
)
146
return
;
147
148
s_QuickSlotStorage
=
new
SCR_InventoryStorageQuickSlotsUI
(null, null, null);
149
s_wQuickSlotStorage
.AddHandler(
s_QuickSlotStorage
);
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
//------------------------------------------------------------------------------------------------
174
void
CloseQuickSlots
()
175
{
176
if
(
s_QuickSlotStorage
)
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;
245
CloseQuickSlots
();
246
OpenQuickSlots
();
247
}
248
}
249
250
//------------------------------------------------------------------------------------------------
251
protected
void
Action_QuickSlotsBar
(
float
value = 0.0,
EActionTrigger
reason
= 0)
252
{
253
if
(
reason
==
EActionTrigger
.DOWN)
254
OpenQuickSlots
();
255
else
256
CloseQuickSlots
();
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
)
290
CloseQuickSlots
();
291
292
s_bRadial
=
false
;
293
OpenQuickSlots
();
294
295
SelectQuickSlot
(targetSlot);
296
}
297
298
//------------------------------------------------------------------------------------------------
299
protected
void
Action_ScrollSlot
(
float
value = 0.0,
EActionTrigger
reason
= 0)
300
{
301
if
(!
s_bOpened
|| !
s_QuickSlotStorage
)
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);
336
RemoveActionListeners
();
337
s_QuickSlotStorage
= null;
338
}
339
340
//------------------------------------------------------------------------------------------------
341
static
SCR_WeaponSwitchingBaseUI
GetWeaponSwitchingBaseUI
()
342
{
343
return
s_WeaponSwitchingUI
;
344
}
345
}
346
347
class
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 ----
Init
override void Init()
Definition
CharacterCameraHandlerComponent.c:40
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
EntityEditorProps
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Definition
SCR_CompassComponent.c:10
m_wRoot
Widget m_wRoot
Definition
SCR_GameModeCleanSweep.c:25
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
reason
string reason
Definition
ServerBrowserMenuCallbacks.c:41
BlurWidget
Definition
BlurWidget.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
ChimeraWorld
Definition
ChimeraWorld.c:13
IEntity
Definition
IEntity.c:13
IEntity::GetWorld
proto external BaseWorld GetWorld()
InputManager
Input management system for user interactions.
Definition
InputManager.c:20
Resource
Object holding reference to resource. In destructor release the resource.
Definition
Resource.c:25
ResourceName
Definition
ResourceName.c:13
SCR_CharacterInventoryStorageComponent
Definition
SCR_CharacterInventoryStorageComponent.c:90
SCR_CharacterInventoryStorageComponent::GetContainerFromQuickslot
SCR_QuickslotBaseContainer GetContainerFromQuickslot(int index)
Definition
SCR_CharacterInventoryStorageComponent.c:525
SCR_InventoryStorageQuickSlotsUI
Definition
SCR_InventoryStorageQuickSlotsUI.c:7
SCR_PlayerController
Definition
SCR_PlayerController.c:31
SCR_PlayerController::GetLocalControlledEntity
static IEntity GetLocalControlledEntity()
Definition
SCR_PlayerController.c:495
SCR_QuickslotCommandContainer
Definition
SCR_QuickslotBaseContainer.c:78
SCR_QuickslotCommandContainer::GetCommandName
string GetCommandName()
Definition
SCR_QuickslotBaseContainer.c:90
SCR_SoundEvent
Definition
SCR_SoundEvent.c:2
SCR_UISoundEntity
Definition
SCR_UISoundEntity.c:8
SCR_WeaponSwitchingBaseUI
Definition
SCR_WeaponSwitchingBaseUI.c:6
SCR_WeaponSwitchingBaseUI::RemoveActionListeners
void RemoveActionListeners()
Definition
SCR_WeaponSwitchingBaseUI.c:101
SCR_WeaponSwitchingBaseUI::OnStartDraw
override event void OnStartDraw(IEntity owner)
Definition
SCR_WeaponSwitchingBaseUI.c:325
SCR_WeaponSwitchingBaseUI::HighlightQuickSlot
static void HighlightQuickSlot(int id, bool highlight=true)
Definition
SCR_WeaponSwitchingBaseUI.c:47
SCR_WeaponSwitchingBaseUI::Init
void Init(IEntity owner)
Definition
SCR_WeaponSwitchingBaseUI.c:61
SCR_WeaponSwitchingBaseUI::s_bOpened
static bool s_bOpened
Definition
SCR_WeaponSwitchingBaseUI.c:12
SCR_WeaponSwitchingBaseUI::CloseQuickSlots
void CloseQuickSlots()
Definition
SCR_WeaponSwitchingBaseUI.c:174
SCR_WeaponSwitchingBaseUI::SelectQuickSlot
static void SelectQuickSlot(int id)
Definition
SCR_WeaponSwitchingBaseUI.c:33
SCR_WeaponSwitchingBaseUI::s_QuickSlotStorage
static ref SCR_InventoryStorageQuickSlotsUI s_QuickSlotStorage
Definition
SCR_WeaponSwitchingBaseUI.c:9
SCR_WeaponSwitchingBaseUI::RefreshQuickSlots
static void RefreshQuickSlots(int id=-1)
Definition
SCR_WeaponSwitchingBaseUI.c:19
SCR_WeaponSwitchingBaseUI::ShowQuickSlots
void ShowQuickSlots(bool show, float speed=UIConstants.FADE_RATE_DEFAULT)
Definition
SCR_WeaponSwitchingBaseUI.c:319
SCR_WeaponSwitchingBaseUI::UpdateValues
override void UpdateValues(IEntity owner, float timeSlice)
Definition
SCR_WeaponSwitchingBaseUI.c:311
SCR_WeaponSwitchingBaseUI::OpenQuickSlots
void OpenQuickSlots()
Definition
SCR_WeaponSwitchingBaseUI.c:117
SCR_WeaponSwitchingBaseUI::s_WeaponSwitchingUI
static SCR_WeaponSwitchingBaseUI s_WeaponSwitchingUI
Definition
SCR_WeaponSwitchingBaseUI.c:10
SCR_WeaponSwitchingBaseUI::Action_SwitchSlot
void Action_SwitchSlot(float value=0.0, EActionTrigger reason=0)
Definition
SCR_WeaponSwitchingBaseUI.c:260
SCR_WeaponSwitchingBaseUI::Action_QuickSlotsBar
void Action_QuickSlotsBar(float value=0.0, EActionTrigger reason=0)
Definition
SCR_WeaponSwitchingBaseUI.c:251
SCR_WeaponSwitchingBaseUI::OnStopDraw
override event void OnStopDraw(IEntity owner)
Definition
SCR_WeaponSwitchingBaseUI.c:333
SCR_WeaponSwitchingBaseUI::ShowCommand
void ShowCommand(notnull SCR_InventoryStorageManagerComponent inventory)
Definition
SCR_WeaponSwitchingBaseUI.c:212
SCR_WeaponSwitchingBaseUI::Action_ScrollSlot
void Action_ScrollSlot(float value=0.0, EActionTrigger reason=0)
Definition
SCR_WeaponSwitchingBaseUI.c:299
SCR_WeaponSwitchingBaseUI::s_bRadial
static bool s_bRadial
Definition
SCR_WeaponSwitchingBaseUI.c:13
SCR_WeaponSwitchingBaseUI::s_sItemPreviewManagerPrefab
static ResourceName s_sItemPreviewManagerPrefab
Definition
SCR_WeaponSwitchingBaseUI.c:7
SCR_WeaponSwitchingBaseUI::s_wQuickSlotStorage
static Widget s_wQuickSlotStorage
Definition
SCR_WeaponSwitchingBaseUI.c:8
SCR_WeaponSwitchingBaseUI::Action_QuickSlotsRadial
void Action_QuickSlotsRadial(float value=0.0, EActionTrigger reason=0)
Definition
SCR_WeaponSwitchingBaseUI.c:230
SCR_WeaponSwitchingBaseUI::m_sQuickSlotGridLayout
string m_sQuickSlotGridLayout
Definition
SCR_WeaponSwitchingBaseUI.c:16
SCR_WeaponSwitchingBaseUI::GetWeaponSwitchingBaseUI
static SCR_WeaponSwitchingBaseUI GetWeaponSwitchingBaseUI()
Definition
SCR_WeaponSwitchingBaseUI.c:341
ScriptedInventoryOperationCallback
Definition
ScriptedInventoryOperationCallback.c:13
ScriptedInventoryOperationCallback::OnComplete
void OnComplete()
UIConstants
Definition
Constants.c:151
Widget
Definition
Widget.c:13
Show
override void Show()
Definition
gameLib.c:262
ECharacterLifeState
ECharacterLifeState
Definition
ECharacterLifeState.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
EActionTrigger
EActionTrigger
Definition
EActionTrigger.c:13
scripts
Game
UI
HUD
WeaponSwitching
SCR_WeaponSwitchingBaseUI.c
Generated by
1.17.0