Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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 
4 class SCR_WeaponSwitchingBaseUI: SCR_InfoDisplay
5 {
6  protected static ResourceName m_ItemPreviewManagerPrefab = "{9F18C476AB860F3B}Prefabs/World/Game/ItemPreviewManager.et"; // This could be attribute
7  protected static Widget s_wQuickSlotStorage;
8  protected static ref SCR_InventoryStorageQuickSlotsUI s_pQuickSlotStorage;
9 
10  static bool s_bOpened;
11 
12  [Attribute( "{A1E61EF091EAC47C}UI/layouts/Menus/Inventory/InventoryQuickSlotsGrid.layout" )]
13  protected string m_sQuickSlotGridLayout;
14 
15  //------------------------------------------------------------------------ USER METHODS ----------------------------------------------------------------------
16 
17 
18  //------------------------------------------------------------------------------------------------
19  static void RefreshQuickSlots(int id = -1)
20  {
21  if (s_pQuickSlotStorage)
22  {
23  if (id < 0)
24  s_pQuickSlotStorage.RefreshQuickSlots();
25  else
26  s_pQuickSlotStorage.RefreshSlot(id);
27  s_pQuickSlotStorage.HighlightLastSelectedSlot();
28  }
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  protected void Init( IEntity owner )
33  {
34  s_bOpened = false;
35 
36  if (!owner || !m_wRoot)
37  return;
38 
39  ChimeraWorld world = ChimeraWorld.CastFrom(owner.GetWorld());
40  if (world)
41  {
42  //instantiate the preview manager
43  if (!world.GetItemPreviewManager())
44  {
45  Resource rsc = Resource.Load(m_ItemPreviewManagerPrefab);
46  if (rsc.IsValid())
47  GetGame().SpawnEntityPrefabLocal(rsc, world);
48  }
49  }
50 
51  InputManager inputManager = GetGame().GetInputManager();;
52  inputManager.AddActionListener("Inventory_WeaponSwitching", EActionTrigger.UP, QuickBarClosedOnly );
53  inputManager.AddActionListener("Inventory_WeaponSwitching", EActionTrigger.DOWN, Action_OpenQuickSelectionBar );
54  inputManager.AddActionListener("Inventory_WeaponSwitching", EActionTrigger.UP, Action_CloseQuickSelectionBar );
55 
56  for (int i = 0; i < 10; ++i)
57  {
58  inputManager.AddActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.DOWN, Action_OpenQuickSelectionBar);
59  inputManager.AddActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.UP, Action_CloseQuickSelectionBar);
60  }
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  protected void RemoveActionListeners()
65  {
66  InputManager inputManager = GetGame().GetInputManager();
67  inputManager.RemoveActionListener("Inventory_WeaponSwitching", EActionTrigger.UP, QuickBarClosedOnly );
68  inputManager.RemoveActionListener("Inventory_WeaponSwitching", EActionTrigger.DOWN, Action_OpenQuickSelectionBar );
69  inputManager.RemoveActionListener("Inventory_WeaponSwitching", EActionTrigger.UP, Action_CloseQuickSelectionBar );
70 
71  for (int i = 0; i < 10; ++i)
72  {
73  inputManager.RemoveActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.DOWN, Action_OpenQuickSelectionBar);
74  inputManager.RemoveActionListener("SwitchWeaponCategory" + i.ToString(), EActionTrigger.UP, Action_CloseQuickSelectionBar);
75  }
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  void Action_OpenQuickSelectionBar()
80  {
81  if (s_bOpened)
82  return;
83 
84  ChimeraCharacter character = ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
85  CharacterControllerComponent controller;
86 
87  if (character)
88  controller = character.GetCharacterController();
89 
90  if (controller && controller.IsUnconscious())
91  return;
92 
93  GetGame().GetInputManager().AddActionListener("CharacterSwitchWeapon", EActionTrigger.VALUE, Action_SelectSlot );
94  s_bOpened = true;
95  GetGame().GetCallqueue().Remove( ShowQuickSlots ); // if there's a delayed Show method from the previous quick bar usage, purge it
96  if ( !m_wRoot )
97  return;
98  if( s_wQuickSlotStorage )
99  {
100  s_wQuickSlotStorage.RemoveHandler( s_wQuickSlotStorage.FindHandler( SCR_InventoryStorageQuickSlotsUI ) );
101  s_wQuickSlotStorage.RemoveFromHierarchy();
102  }
103  Widget parent = m_wRoot.FindAnyWidget( "QuickSlots" );
104  s_wQuickSlotStorage = GetGame().GetWorkspace().CreateWidgets( m_sQuickSlotGridLayout, parent );
105  if( !s_wQuickSlotStorage )
106  return;
107  s_pQuickSlotStorage = new SCR_InventoryStorageQuickSlotsUI( null, null, null );
108  s_wQuickSlotStorage.AddHandler( s_pQuickSlotStorage );
109  s_pQuickSlotStorage.SetInitialQuickSlot();
110  s_pQuickSlotStorage.HighlightLastSelectedSlot();
111 
112  Show( true, UIConstants.FADE_RATE_DEFAULT );
113  BlurWidget wBlur = BlurWidget.Cast( m_wRoot.FindAnyWidget( "wBlur" ) );
114  if ( wBlur )
115  wBlur.SetVisible( true );
116 
117  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_OPEN);
118 
119  if (!controller)
120  return;
121 
122  SCR_InventoryStorageManagerComponent inventory = SCR_InventoryStorageManagerComponent.Cast(controller.GetInventoryStorageManager());
123  if (inventory)
124  inventory.m_OnQuickBarOpenInvoker.Invoke(true);
125  }
126 
127  //------------------------------------------------------------------------------------------------
128  void Action_CloseQuickSelectionBar()
129  {
130  GetGame().GetInputManager().RemoveActionListener("CharacterSwitchWeapon", EActionTrigger.VALUE, Action_SelectSlot );
131  s_bOpened = false;
132  if ( !m_wRoot )
133  return;
134  BlurWidget wBlur = BlurWidget.Cast( m_wRoot.FindAnyWidget( "wBlur" ) );
135  if ( wBlur )
136  wBlur.SetVisible( false );
137 
138  if ( s_pQuickSlotStorage && s_pQuickSlotStorage.UseItemInSlot() )
139  GetGame().GetCallqueue().CallLater( ShowQuickSlots, 2000, false, false, UIConstants.FADE_RATE_DEFAULT, true );
140  else
141  Show( false, UIConstants.FADE_RATE_DEFAULT );
142 
143  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
144  if (!character)
145  return;
146 
147  CharacterControllerComponent controller = character.GetCharacterController();
148  if (!controller)
149  return;
150 
151  SCR_InventoryStorageManagerComponent inventory = SCR_InventoryStorageManagerComponent.Cast(controller.GetInventoryStorageManager());
152  if (inventory)
153  inventory.m_OnQuickBarOpenInvoker.Invoke(false);
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  // called when the quickbar is closed by letting go the tab key
158  protected void QuickBarClosedOnly()
159  {
160  if (s_pQuickSlotStorage)
161  s_pQuickSlotStorage.SetQuickBarClosed();
162  }
163 
164  //------------------------------------------------------------------------------------------------
165  void Action_SelectSlot()
166  {
167  if (!s_bOpened || !s_pQuickSlotStorage)
168  return;
169 
170  int targetSlot = -1;
171 
172  InputManager inputManager = GetGame().GetInputManager();
173  if (inputManager.GetActionTriggered("SwitchWeaponCategory1"))
174  targetSlot = 0;
175  else if (inputManager.GetActionTriggered("SwitchWeaponCategory2"))
176  targetSlot = 1;
177  else if (inputManager.GetActionTriggered("SwitchWeaponCategory3"))
178  targetSlot = 2;
179  else if (inputManager.GetActionTriggered("SwitchWeaponCategory4"))
180  targetSlot = 3;
181  else if (inputManager.GetActionTriggered("SwitchWeaponCategory5"))
182  targetSlot = 4;
183  else if (inputManager.GetActionTriggered("SwitchWeaponCategory6"))
184  targetSlot = 5;
185  else if (inputManager.GetActionTriggered("SwitchWeaponCategory7"))
186  targetSlot = 6;
187  else if (inputManager.GetActionTriggered("SwitchWeaponCategory8"))
188  targetSlot = 7;
189  else if (inputManager.GetActionTriggered("SwitchWeaponCategory9"))
190  targetSlot = 8;
191  else if (inputManager.GetActionTriggered("SwitchWeaponCategory0"))
192  targetSlot = 9;
193 
194  if ( targetSlot == - 1 )
195  s_pQuickSlotStorage.SelectSlot( inputManager.GetActionValue("CharacterSwitchWeapon") );
196  else
197  s_pQuickSlotStorage.SelectSlot( targetSlot );
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  override void UpdateValues(IEntity owner, float timeSlice)
202  {
203  if (!s_bOpened)
204  return;
205 
206  GetGame().GetInputManager().ActivateContext("WeaponSelectionContext");
207  }
208 
209  protected void ShowQuickSlots(bool show, float speed = UIConstants.FADE_RATE_DEFAULT)
210  {
211  Show(show, speed);
212  }
213 
214  //------------------------------------------------------------------------------------------------
215  override event void OnStartDraw(IEntity owner)
216  {
217  super.OnStartDraw(owner);
218  Init(owner);
219  Show(false, 0);
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  override event void OnStopDraw(IEntity owner)
224  {
225  super.OnStopDraw(owner);
226  RemoveActionListeners();
227  s_pQuickSlotStorage = null;
228  }
229 };
230 
232 {
233  override void OnComplete()
234  {
235  SCR_WeaponSwitchingBaseUI.RefreshQuickSlots();
236  }
237 }
SCR_WeaponSwitchingBaseUI
Definition: SCR_WeaponSwitchingBaseUI.c:4
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_PlayerController
Definition: SCR_PlayerController.c:31
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
ScriptedInventoryOperationCallback
Definition: ScriptedInventoryOperationCallback.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_InventoryStorageQuickSlotsUI
Definition: SCR_InventoryStorageQuickSlotsUI.c:6
SCR_QuickSlotRefreshCB
Definition: SCR_WeaponSwitchingBaseUI.c:231
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180