6 private BaseWeaponManagerComponent m_WeaponManager;
7 private SCR_InventoryStorageManagerComponent m_inventory20ManagerComp
9 private BaseControllerComponent m_Controller;
11 private BaseInteractionHandlerComponent m_InteractionMenu;
12 private Widget m_wVerticalLayout;
13 private Widget m_wHighlightedWeapon;
15 private float m_fLastInteractionTime = 0;
16 private float m_fLastSelectionTime = 0;
18 private ref array<WeaponSlotComponent> m_aWeaponSlotsUnsorted =
new array<WeaponSlotComponent>;
19 private ref array<WeaponSlotComponent> m_aWeaponSlotsSorted =
new array<WeaponSlotComponent>;
20 private ref array<IEntity> m_aWeaponEntities =
new array<IEntity>;
21 private ref array<Widget> m_aWeaponWidgets =
new array<Widget>;
25 [
Attribute(
"{80102F7397A6DFDC}UI/layouts/HUD/WeaponSelection/WeaponSelectionCategoryNumber.layout",
UIWidgets.ResourceNamePicker,
"Layout of category number widget",
"layout")]
28 [
Attribute(
"{F6725A5E6A624F5F}UI/layouts/HUD/WeaponSelection/WeaponSlot.layout",
UIWidgets.ResourceNamePicker,
"Scoreboard layout",
"layout")]
31 [
Attribute(
"100",
UIWidgets.EditBox,
"Speed of scrolling between weapons (delay in ms)")]
32 private float m_fSelectionTimeout;
35 private float m_fInteractionTimeout;
55 [
Attribute(
"{0054C496786770A6}UI/Textures/Icons/icons_keyboard_32.imageset",
UIWidgets.ResourceNamePicker,
"")]
70 PlayerController pc =
game.GetPlayerController();
73 m_InteractionMenu = BaseInteractionHandlerComponent.Cast(pc.FindComponent(BaseInteractionHandlerComponent));
76 HUDManagerComponent hudManager =
game.GetHUDManager();
79 array<SCR_InfoDisplay> displays = hudManager.GetHUDElements();
80 foreach (SCR_InfoDisplay display : displays)
83 if (weaponSwitching && weaponSwitching !=
this)
85 weaponSwitching.Show(
false,
UIConstants.FADE_RATE_DEFAULT);
92 m_InputManager =
GetGame().GetInputManager();
96 BaseVehicleNodeComponent nodeComponent = BaseVehicleNodeComponent.Cast(m_Owner.FindComponent(BaseVehicleNodeComponent));
99 m_Controller = BaseControllerComponent.Cast(nodeComponent.FindComponent(BaseControllerComponent));
100 m_WeaponManager = BaseWeaponManagerComponent.Cast(nodeComponent.FindComponent(BaseWeaponManagerComponent));
105 m_Controller = BaseControllerComponent.Cast(m_Owner.FindComponent(BaseControllerComponent));
106 m_WeaponManager = BaseWeaponManagerComponent.Cast(m_Owner.FindComponent(BaseWeaponManagerComponent));
109 if (!m_WeaponManager)
112 array<WeaponSlotComponent> weapons =
new array<WeaponSlotComponent>;
113 m_WeaponManager.GetWeaponsSlots(weapons);
115 m_aWeaponSlotsUnsorted.Clear();
118 m_aWeaponSlotsUnsorted.Insert(slot);
136 m_wVerticalLayout =
m_wRoot.FindAnyWidget(
"WeaponMenu");
146 newChild = child.GetSibling();
159 if (!m_inventory20ManagerComp)
160 m_inventory20ManagerComp = SCR_InventoryStorageManagerComponent.Cast(m_Owner.FindComponent(SCR_InventoryStorageManagerComponent));
161 if (!m_inventory20ManagerComp)
164 CharacterControllerComponent controller = CharacterControllerComponent.Cast(m_Owner.FindComponent(CharacterControllerComponent));
168 auto bandage = m_inventory20ManagerComp.GetBandageItem();
170 controller.TakeGadgetInLeftHand(bandage, 1);
176 m_aWeaponEntities.Clear();
179 IEntity entity = weapon.GetWeaponEntity();
180 m_aWeaponEntities.Insert(entity);
187 if (m_aWeaponSlotsUnsorted.Count() != m_aWeaponEntities.Count())
192 if (slot && slot.GetWeaponEntity() != m_aWeaponEntities.Get(i))
205 int i = m_aWeaponWidgets.Find(m_wHighlightedWeapon);
206 if (i < 0 && i < m_aWeaponSlotsSorted.Count())
213 if (slot != m_WeaponManager.GetCurrent())
215 OnSelectWeapon(slot);
224 if (!m_wVerticalLayout)
228 Widget child = m_wVerticalLayout.GetChildren();
231 Widget nextChild = child.GetSibling();
232 child.RemoveFromHierarchy();
236 m_aWeaponWidgets.Clear();
240 if (!slot || !slot.GetWeaponEntity())
242 m_aWeaponWidgets.Insert(null);
247 Widget category =
GetGame().GetWorkspace().CreateWidgets(
"{93F4C116E103AFD4}UI/layouts/HUD/WeaponSelection/WeaponCategory.layout",m_wVerticalLayout);
254 int categoryNumber = slot.GetWeaponSlotIndex() + 1;
257 m_aWeaponWidgets.Insert(w);
272 array<WeaponSlotComponent> sortedWeapons =
new array<WeaponSlotComponent>;
273 array<int> slotIndexes =
new array<int>;
279 int i = slot.GetWeaponSlotIndex() + 1;
282 slotIndexes.Insert(i);
286 slotIndexes.Insert(100);
290 int count = weapons.Count();
291 for (
int i = 0; i < count; i++)
293 int lowestScore = 1000;
296 for (
int j = 0; j < count; j++)
298 if (slotIndexes.Get(j) <= lowestScore)
301 lowestScore = slotIndexes.Get(j);
308 sortedWeapons.Insert(slot);
309 slotIndexes.Set(slotIndex,1000);
313 return sortedWeapons;
329 UIInfo uiInfo = weapon.GetUIInfo();
337 string text = uiInfo.GetName();
344 string path = uiInfo.GetIconPath();
345 if (
path !=
string.Empty)
347 icon.LoadImageTexture(0,
path);
349 icon.GetImageSize(0,x,y);
350 icon.SetSize((
float)x, (
float)y);
365 int count = m_aWeaponWidgets.Count();
366 if (i > -1 && i < count)
368 Widget w = m_aWeaponWidgets.Get(i);
369 if (w && m_wHighlightedWeapon != w)
374 m_wHighlightedWeapon = w;
384 int count = m_aWeaponWidgets.Count();
386 for (i; i < count; i++)
388 if (m_aWeaponWidgets.Get(i))
405 if (m_aWeaponWidgets.Get(i))
425 if (!m_wHighlightedWeapon)
427 if (!m_WeaponManager)
434 i = m_aWeaponSlotsSorted.Find(currentSlot);
438 i = m_aWeaponWidgets.Find(m_wHighlightedWeapon);
449 if (m_InputManager.GetActionTriggered(
"SwitchWeaponCategory1"))
451 else if (m_InputManager.GetActionTriggered(
"SwitchWeaponCategory2"))
453 else if (m_InputManager.GetActionTriggered(
"SwitchWeaponCategory3"))
455 else if (m_InputManager.GetActionTriggered(
"SwitchWeaponCategory4"))
457 else if (m_InputManager.GetActionTriggered(
"SwitchWeaponCategory5"))
459 else if (m_InputManager.GetActionTriggered(
"SwitchWeaponCategory6"))
462 if (targetSlot < 0 || !m_aWeaponSlotsSorted)
470 if (targetSlot == slot.GetWeaponSlotIndex())
472 if (!m_Controller || !m_WeaponManager)
475 IEntity weaponEntity = slot.GetWeaponEntity();
479 if (weaponEntity && currentlySelectedSlot != slot)
481 OnSelectWeapon(slot);
482 if (
IsShown() && i < m_aWeaponWidgets.Count())
484 Widget w = m_aWeaponWidgets.Get(i);
486 GetGame().GetWorkspace().SetFocusedWidget(w);
513 Widget background = w.FindAnyWidget(
"Background");
526 background.SetColor(backgroundColor);
527 w.SetColor(colorChild);
532 private void RegisterListeners()
548 super.Show(show, speed);
559 private void OnSelectWeapon(WeaponSlotComponent slot)
567 CharacterControllerComponent characterController = CharacterControllerComponent.Cast(m_Controller);
568 if (characterController)
570 characterController.SelectWeapon(slot);
574 TurretControllerComponent turretController = TurretControllerComponent.Cast(m_Controller);
575 if (turretController)
577 IEntity player = SCR_PlayerController.GetLocalControlledEntity();
578 turretController.SelectWeapon(player, slot);
589 #define DISABLE_WEAPON_SWITCHING
590 #ifndef DISABLE_WEAPON_SWITCHING
603 float cancel =
m_InputManager.GetActionTriggered(
"CharacterCancelWeaponSwitch");
604 float switching =
m_InputManager.GetActionValue(
"CharacterSwitchWeapon");
605 float radialSwitch =
m_InputManager.GetActionValue(
"CharacterSwitchWeaponRadial");
611 if (m_InteractionMenu && m_InteractionMenu.IsInteractionAvailable())
622 m_fLastSelectionTime = owner.
GetWorld().GetWorldTime();
637 float time = owner.
GetWorld().GetWorldTime();
638 if (switching == 0 && time > m_fLastInteractionTime + m_fInteractionTimeout)
648 float time = owner.
GetWorld().GetWorldTime();
649 float remainingTime = time - m_fLastSelectionTime + m_fSelectionTimeout;
651 m_fLastInteractionTime = time;
656 m_fLastSelectionTime = time;
658 else if (time > m_fLastSelectionTime + m_fSelectionTimeout)
660 m_fLastSelectionTime = time;
672 m_aWeaponSlotsUnsorted.Clear();
673 m_aWeaponSlotsSorted.Clear();
675 HUDManagerComponent hudManager =
GetGame().GetHUDManager();
678 array<SCR_InfoDisplay> displays = hudManager.GetHUDElements();
679 foreach (SCR_InfoDisplay display : displays)
681 SCR_WeaponSelectionMenu weaponSwitching = SCR_WeaponSelectionMenu.Cast(display);
682 if (weaponSwitching && weaponSwitching !=
this)
684 weaponSwitching.Show(
true, UIConstants.FADE_RATE_DEFAULT);
690 super.OnStopDraw(owner);
696 super.OnStartDraw(owner);
703 void ~SCR_WeaponSelectionMenu()