6 private BaseWeaponManagerComponent m_WeaponManager;
7 private SCR_InventoryStorageManagerComponent m_inventory20ManagerComp
9 private BaseControllerComponent m_Controller;
10 private InputManager m_InputManager;
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>;
23 protected static ref ScriptInvoker Event_OnSelectWeapon =
new ScriptInvoker;
25 [
Attribute(
"{80102F7397A6DFDC}UI/layouts/HUD/WeaponSelection/WeaponSelectionCategoryNumber.layout", UIWidgets.ResourceNamePicker,
"Layout of category number widget",
"layout")]
26 ResourceName m_sNumberWidgetLayout;
28 [
Attribute(
"{F6725A5E6A624F5F}UI/layouts/HUD/WeaponSelection/WeaponSlot.layout", UIWidgets.ResourceNamePicker,
"Scoreboard layout",
"layout")]
29 ResourceName m_sWeaponWidgetLayout;
31 [
Attribute(
"100", UIWidgets.EditBox,
"Speed of scrolling between weapons (delay in ms)")]
32 private float m_fSelectionTimeout;
34 [
Attribute(
"5000", UIWidgets.EditBox,
"Weapon selection auto closing time (in ms)")]
35 private float m_fInteractionTimeout;
37 [
Attribute(
"1 1 1 0.10", UIWidgets.ColorPicker,
"")]
38 protected ref Color m_ColorSelected;
40 [
Attribute(
"0 0 0 1", UIWidgets.ColorPicker,
"")]
41 protected ref Color m_ColorChildSelected;
43 [
Attribute(
"0 0 0 0.1", UIWidgets.ColorPicker,
"")]
44 protected ref Color m_ColorDefault;
46 [
Attribute(
"1 1 1 1", UIWidgets.ColorPicker,
"")]
47 protected ref Color m_ColorChildDefault;
50 protected float m_fHighlightAnimationSpeed;
53 protected ResourceName m_sSoundSwitch;
55 [
Attribute(
"{0054C496786770A6}UI/Textures/Icons/icons_keyboard_32.imageset", UIWidgets.ResourceNamePicker,
"")]
56 protected ResourceName m_sWeaponNumberImageset;
59 void Init(IEntity owner)
67 ArmaReforgerScripted game =
GetGame();
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);
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));
112 array<WeaponSlotComponent> weapons =
new array<WeaponSlotComponent>;
115 m_aWeaponSlotsUnsorted.Clear();
118 m_aWeaponSlotsUnsorted.Insert(slot);
121 m_aWeaponSlotsSorted = GetSortedWeaponSlots(m_aWeaponSlotsUnsorted);
138 Widget child =
m_wRoot.GetChildren();
143 Widget newChild =
null;
146 newChild = child.GetSibling();
153 CreateWeaponWidgets();
157 void EquipHealingItem()
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);
174 void UpdateWeaponsList()
176 m_aWeaponEntities.Clear();
179 IEntity entity = weapon.GetWeaponEntity();
180 m_aWeaponEntities.Insert(entity);
185 bool DidWeaponsChange()
187 if (m_aWeaponSlotsUnsorted.Count() != m_aWeaponEntities.Count())
192 if (slot && slot.GetWeaponEntity() != m_aWeaponEntities.Get(i))
200 bool SelectHighlightedWeapon()
205 int i = m_aWeaponWidgets.Find(m_wHighlightedWeapon);
206 if (i < 0 && i < m_aWeaponSlotsSorted.Count())
215 OnSelectWeapon(slot);
222 void CreateWeaponWidgets()
231 Widget nextChild = child.GetSibling();
232 child.RemoveFromHierarchy();
236 m_aWeaponWidgets.Clear();
240 if (!slot || !slot.GetWeaponEntity())
242 m_aWeaponWidgets.Insert(
null);
251 VerticalLayoutSlot.SetPadding(
category, 0,4,0,4);
254 int categoryNumber = slot.GetWeaponSlotIndex() + 1;
256 Widget w = LoadWeaponPrefab(
category, slot, categoryNumber);
257 m_aWeaponWidgets.Insert(w);
259 Widget numberRoot =
GetGame().GetWorkspace().CreateWidgets(m_sNumberWidgetLayout,
category);
263 ImageWidget number = ImageWidget.Cast(numberRoot.FindAnyWidget(
"NumberText"));
265 number.LoadImageFromSet(0, m_sWeaponNumberImageset, categoryNumber.ToString());
270 array<WeaponSlotComponent> GetSortedWeaponSlots(array<WeaponSlotComponent> weapons)
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;
322 Widget w =
GetGame().GetWorkspace().CreateWidgets(m_sWeaponWidgetLayout, parent);
326 HorizontalLayoutSlot.SetPadding(w,0,0,2,0);
327 SetDefaultColor(w,
false);
329 UIInfo uiInfo = weapon.GetUIInfo();
332 TextWidget name = TextWidget.Cast(w.FindAnyWidget(
"Name"));
333 ImageWidget icon = ImageWidget.Cast(w.FindAnyWidget(
"Icon"));
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);
363 void HighlightWeapon(
int i)
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)
371 SetDefaultColor(m_wHighlightedWeapon);
372 SetHighlightColor(w);
374 m_wHighlightedWeapon = w;
380 void HighlightNextWeapon()
382 int i = GetHighlightedWeaponIndex();
384 int count = m_aWeaponWidgets.Count();
386 for (i; i < count; i++)
388 if (m_aWeaponWidgets.Get(i))
399 void HighlightPreviousWeapon()
401 int i = GetHighlightedWeaponIndex();
405 if (m_aWeaponWidgets.Get(i))
415 void HighlightCurrentWeapon()
417 int i = GetHighlightedWeaponIndex();
422 int GetHighlightedWeaponIndex()
425 if (!m_wHighlightedWeapon)
434 i = m_aWeaponSlotsSorted.Find(currentSlot);
438 i = m_aWeaponWidgets.Find(m_wHighlightedWeapon);
445 void HandleKeyboardWeaponSwitch()
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())
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);
496 void SetDefaultColor(Widget w,
bool animate =
true)
498 HighlightWidget(w, m_ColorDefault, m_ColorChildDefault, animate);
502 void SetHighlightColor(Widget w,
bool animate =
true)
504 HighlightWidget(w, m_ColorSelected, m_ColorChildSelected, animate);
508 void HighlightWidget(Widget w, Color backgroundColor, Color colorChild,
bool animate =
true)
513 Widget background = w.FindAnyWidget(
"Background");
521 AnimateWidget.Color(background, backgroundColor, m_fHighlightAnimationSpeed);
522 AnimateWidget.Color(w, colorChild, m_fHighlightAnimationSpeed);
526 background.SetColor(backgroundColor);
527 w.SetColor(colorChild);
532 private void RegisterListeners()
537 m_InputManager.AddActionListener(
"SwitchWeaponCategory1", EActionTrigger.DOWN, HandleKeyboardWeaponSwitch);
538 m_InputManager.AddActionListener(
"SwitchWeaponCategory2", EActionTrigger.DOWN, HandleKeyboardWeaponSwitch);
539 m_InputManager.AddActionListener(
"SwitchWeaponCategory3", EActionTrigger.DOWN, HandleKeyboardWeaponSwitch);
540 m_InputManager.AddActionListener(
"SwitchWeaponCategory4", EActionTrigger.DOWN, HandleKeyboardWeaponSwitch);
541 m_InputManager.AddActionListener(
"SwitchWeaponCategory5", EActionTrigger.DOWN, EquipHealingItem);
542 m_InputManager.AddActionListener(
"SwitchWeaponCategory6", EActionTrigger.DOWN, HandleKeyboardWeaponSwitch);
546 override void Show(
bool show,
float speed =
UIConstants.FADE_RATE_DEFAULT, EAnimationCurve curve = EAnimationCurve.LINEAR)
548 super.Show(show, speed);
554 CreateWeaponWidgets();
561 if (Event_OnSelectWeapon)
562 Event_OnSelectWeapon.Invoke();
567 CharacterControllerComponent characterController = CharacterControllerComponent.Cast(
m_Controller);
568 if (characterController)
570 characterController.SelectWeapon(slot);
575 if (turretController)
578 turretController.SelectWeapon(player, slot);
584 static ScriptInvoker GetOnSelectWeaponInvoker()
586 return Event_OnSelectWeapon;
589 #define DISABLE_WEAPON_SWITCHING
590 #ifndef DISABLE_WEAPON_SWITCHING
592 override event void UpdateValues(IEntity owner,
float timeSlice)
600 CreateWeaponWidgets();
603 float cancel =
m_InputManager.GetActionTriggered(
"CharacterCancelWeaponSwitch");
604 float switching =
m_InputManager.GetActionValue(
"CharacterSwitchWeapon");
605 float radialSwitch =
m_InputManager.GetActionValue(
"CharacterSwitchWeaponRadial");
608 if (Math.AbsFloat(
m_InputManager.GetActionValue(
"CharacterSpeedAnalog")) > 0)
611 if (m_InteractionMenu && m_InteractionMenu.IsInteractionAvailable())
622 m_fLastSelectionTime = owner.GetWorld().GetWorldTime();
623 SelectHighlightedWeapon();
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;
655 HighlightCurrentWeapon();
656 m_fLastSelectionTime = time;
658 else if (time > m_fLastSelectionTime + m_fSelectionTimeout)
660 m_fLastSelectionTime = time;
662 HighlightPreviousWeapon();
664 HighlightNextWeapon();
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)
682 if (weaponSwitching && weaponSwitching !=
this)
684 weaponSwitching.Show(
true,
UIConstants.FADE_RATE_DEFAULT);
690 super.OnStopDraw(owner);
696 super.OnStartDraw(owner);