Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EquipClothAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  #ifndef DISABLE_INVENTORY
6 
7  protected bool m_bIsSwappingItems = false;
8  protected string m_sItemToSwapName = "";
9 
10  protected EquipedLoadoutStorageComponent m_LoadoutStorage;
11  protected BaseLoadoutClothComponent m_LoadoutCloth;
12  protected SCR_CharacterInventoryStorageComponent m_CharacterStorage;
13 
14 
15  [Attribute( "#AR-Inventory_Equip", desc: "What text should be displayed when the Equip action is available." )]
16  protected string m_sEquipActionString;
17  [Attribute( "#AR-Inventory_Swap", desc: "What text should be displayed when the Swap action is available." )]
18  protected string m_sSwapActionString;
19  [Attribute( "#AR-Inventory_Replaces", desc: "What text should be displayed when the Replace action is available." )]
20  protected string m_sReplaceActionString;
21 
22  //------------------------------------------------------------------------------------------------
23  override protected void PerformActionInternal(SCR_InventoryStorageManagerComponent manager, IEntity pOwnerEntity, IEntity pUserEntity)
24  {
25  manager.EquipCloth( pOwnerEntity );
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  override bool CanBePerformedScript(IEntity user)
30  {
31  if ( !super.CanBePerformedScript( user ) )
32  return false;
33 
34  if ( !m_LoadoutStorage )
35  m_LoadoutStorage = EquipedLoadoutStorageComponent.Cast( user.FindComponent( EquipedLoadoutStorageComponent ) );
36 
37  if ( !m_LoadoutCloth )
38  return false;
39 
40  LoadoutAreaType targetArea = m_LoadoutCloth.GetAreaType();
41  if (!targetArea)
42  return false;
43 
44  array<typename> blockedSlots = {};
45  m_LoadoutCloth.GetBlockedSlots(blockedSlots);
46  foreach (typename blockedArea : blockedSlots)
47  {
48  if (m_LoadoutStorage.GetClothFromArea(blockedArea))
49  {
50  m_sItemToSwapName = "";
51  m_bIsSwappingItems = false;
52  return false;
53  }
54  }
55 
56  if (!m_CharacterStorage)
57  m_CharacterStorage = SCR_CharacterInventoryStorageComponent.Cast(user.FindComponent(SCR_CharacterInventoryStorageComponent));
58 
59  if (m_CharacterStorage)
60  {
61  blockedSlots.Clear();
62  m_CharacterStorage.GetBlockedSlots(blockedSlots);
63  if (blockedSlots.Contains(targetArea.Type()))
64  {
65  m_sItemToSwapName = "";
66  m_bIsSwappingItems = false;
67  return false;
68  }
69  }
70 
71  // Checks if the desired area is occupied. If it's occupied it will save the UI info related to the replaced item is saved.
72  if ( m_LoadoutStorage)
73  {
74  IEntity itemToSwap = m_LoadoutStorage.GetClothFromArea( targetArea.Type() );
75  if (itemToSwap)
76  {
77  InventoryItemComponent itemComp = InventoryItemComponent.Cast( itemToSwap.FindComponent( InventoryItemComponent ) );
78 
79  // If the component is missing configuration we can fall back on the target area name.
80  if ( !itemComp || !itemComp.GetAttributes().GetUIInfo().GetName() )
81  {
82  m_sItemToSwapName = targetArea.ToString();
83  m_bIsSwappingItems = false;
84 
85  return true;
86  }
87 
88  m_sItemToSwapName = itemComp.GetAttributes().GetUIInfo().GetName();
89  m_bIsSwappingItems = true;
90  }
91  }
92  else
93  {
94  m_sItemToSwapName = "";
95  m_bIsSwappingItems = false;
96  }
97 
98  return true;
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  override bool GetActionNameScript(out string outName)
103  {
104  if (m_bIsSwappingItems)
105  {
106  string replaceAction = string.Format(WidgetManager.Translate(m_sReplaceActionString), WidgetManager.Translate(m_sItemToSwapName));
107  outName = string.Format( "%1 %2", m_sSwapActionString, replaceAction );
108  }
109  else
110  outName = m_sEquipActionString;
111 
112  return true;
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
117  {
118  super.Init(pOwnerEntity, pManagerComponent);
119 
120  if (!m_Item)
121  return;
122  IEntity item = m_Item.GetOwner();
123  if (!item)
124  return;
125  m_LoadoutCloth = BaseLoadoutClothComponent.Cast( item.FindComponent( BaseLoadoutClothComponent ) );
126 
127  if (!m_LoadoutCloth)
128  {
129  Print("Missing BaseLoadoutClothComponent", LogLevel.ERROR);
130  return;
131  }
132  }
133 
134  #endif
135 };
SCR_InventoryAction
modded version for to be used with the inventory 2.0
Definition: SCR_InventoryAction.c:3
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EquipClothAction
modded version for to be used with the inventory 2.0
Definition: SCR_EquipClothAction.c:3
InventoryItemComponent
Definition: InventoryItemComponent.c:12
m_LoadoutStorage
private EquipedLoadoutStorageComponent m_LoadoutStorage
Definition: CharacterCameraHandlerComponent.c:988
BaseLoadoutClothComponent
Definition: BaseLoadoutClothComponent.c:12
LoadoutAreaType
Definition: LoadoutAreaType.c:12