Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LoadoutPreviewComponent.c
Go to the documentation of this file.
1 class SCR_LoadoutPreviewComponent : ScriptedWidgetComponent
2 {
3  [Attribute("{9F18C476AB860F3B}Prefabs/World/Game/ItemPreviewManager.et")]
4  protected ResourceName m_sPreviewManager;
5 
6  [Attribute("Preview")]
7  protected string m_sPreviewWidgetName;
8 
9  protected ItemPreviewManagerEntity m_PreviewManager;
10  protected ItemPreviewWidget m_wPreview;
11 
12  protected bool m_bReloadLoadout;
13 
14  //------------------------------------------------------------------------------------------------
15  override void HandlerAttached(Widget w)
16  {
17  m_wPreview = ItemPreviewWidget.Cast(w.FindAnyWidget(m_sPreviewWidgetName));
18  m_bReloadLoadout = true;
19  }
20 
21  protected void DeleteChildrens(IEntity entity, bool deleteRoot = true)
22  {
23  if (!entity || !entity.FindComponent(InventoryItemComponent))
24  return;
25 
26  IEntity child = entity.GetChildren();
27  while (child)
28  {
29  IEntity sibling = child.GetSibling();
30  DeleteChildrens(child);
31  child = sibling;
32  }
33 
34  if (!entity.IsDeleted() && deleteRoot)
35  delete entity;
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  IEntity SetPreviewedLoadout(notnull SCR_BasePlayerLoadout loadout, PreviewRenderAttributes attributes = null)
40  {
41  if (!m_bReloadLoadout)
42  return null;
43 
44  ChimeraWorld world = GetGame().GetWorld();
45  m_PreviewManager = world.GetItemPreviewManager();
46 
47  if (!m_PreviewManager)
48  {
49  Resource res = Resource.Load(m_sPreviewManager);
50  if (res.IsValid())
51  GetGame().SpawnEntityPrefabLocal(res, world);
52 
53  m_PreviewManager = world.GetItemPreviewManager();
54  if (!m_PreviewManager)
55  {
56  return null;
57  }
58  }
59 
60  ResourceName resName = loadout.GetLoadoutResource();
62  {
63  IEntity previewedEntity = m_PreviewManager.ResolvePreviewEntityForPrefab(resName);
64  if (!previewedEntity)
65  return previewedEntity;
66 
67  SCR_ArsenalManagerComponent arsenalManager;
68  if (!SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager))
69  return previewedEntity;
70 
71  SCR_PlayerLoadoutData loadoutData = arsenalManager.m_bLocalPlayerLoadoutData;
72  if (!loadoutData)
73  return previewedEntity;
74 
75  DeleteChildrens(previewedEntity, false);
76 
77  EquipedLoadoutStorageComponent loadoutStorage = EquipedLoadoutStorageComponent.Cast(previewedEntity.FindComponent(EquipedLoadoutStorageComponent));
78  if (loadoutStorage)
79  {
80  for (int i = 0; i < loadoutData.Clothings.Count(); ++i)
81  {
82  InventoryStorageSlot slot = loadoutStorage.GetSlot(loadoutData.Clothings[i].SlotIdx);
83  if (!slot)
84  continue;
85 
86  Resource resource = Resource.Load(loadoutData.Clothings[i].ClothingPrefab);
87  if (!resource)
88  continue;
89 
90  IEntity cloth = GetGame().SpawnEntityPrefabLocal(resource, previewedEntity.GetWorld());
91  if (!cloth)
92  continue;
93 
94  slot.AttachEntity(cloth);
95  }
96  }
97 
98  EquipedWeaponStorageComponent weaponStorage = EquipedWeaponStorageComponent.Cast(previewedEntity.FindComponent(EquipedWeaponStorageComponent));
99  if (weaponStorage)
100  {
101  for (int i = 0; i < loadoutData.Weapons.Count(); ++i)
102  {
103  InventoryStorageSlot slot = weaponStorage.GetSlot(loadoutData.Weapons[i].SlotIdx);
104  if (!slot)
105  continue;
106 
107  Resource resource = Resource.Load(loadoutData.Weapons[i].WeaponPrefab);
108  if (!resource)
109  continue;
110 
111  IEntity weapon = GetGame().SpawnEntityPrefabLocal(resource, previewedEntity.GetWorld());
112  if (!weapon)
113  continue;
114 
115  slot.AttachEntity(weapon);
116  }
117  }
118 
119  BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(previewedEntity.FindComponent(BaseWeaponManagerComponent));
120  if (weaponManager)
121  {
122  int weaponDefaultIndex = weaponManager.GetDefaultWeaponIndex();
123  if (weaponDefaultIndex > -1)
124  {
125  array<WeaponSlotComponent> outSlots = {};
126  weaponManager.GetWeaponsSlots(outSlots);
127  foreach (WeaponSlotComponent weaponSlot: outSlots)
128  {
129  if (weaponSlot.GetWeaponSlotIndex() == weaponDefaultIndex)
130  {
131  weaponManager.SelectWeapon(weaponSlot);
132  break;
133  }
134  }
135  }
136  }
137 
138  m_PreviewManager.SetPreviewItem(m_wPreview, previewedEntity, attributes, true);
139  return previewedEntity;
140  }
141  else
142  {
143  m_PreviewManager.SetPreviewItemFromPrefab(m_wPreview, resName, attributes);
144  return m_PreviewManager.ResolvePreviewEntityForPrefab(resName);
145  }
146  }
147 
148  //------------------------------------------------------------------------------------------------
149  ItemPreviewManagerEntity GetPreviewManagerEntity()
150  {
151  return m_PreviewManager;
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  void SetPreviewManagerEntity(ItemPreviewManagerEntity instance)
156  {
157  m_PreviewManager = instance;
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  ItemPreviewWidget GetItemPreviewWidget()
162  {
163  return m_wPreview;
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  void SetItemPreviewWidget(ItemPreviewWidget instance)
168  {
169  m_wPreview = instance;
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  void SetReloadLoadout(bool flag)
174  {
175  m_bReloadLoadout = flag;
176  }
177 };
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_PlayerLoadoutData
Definition: SCR_PlayerLoadoutData.c:13
InventoryStorageSlot
Definition: InventoryStorageSlot.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
PreviewRenderAttributes
Definition: PreviewRenderAttributes.c:12
m_PreviewManager
private SCR_PreviewEntityEditorComponent m_PreviewManager
Definition: SCR_CursorEditorUIComponent.c:22
loadout
string loadout
Definition: SCR_ArsenalManagerComponent.c:2
WeaponSlotComponent
Definition: WeaponSlotComponent.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
loadoutData
ref SCR_PlayerLoadoutData loadoutData
Definition: SCR_ArsenalManagerComponent.c:3
InventoryItemComponent
Definition: InventoryItemComponent.c:12
ItemPreviewWidget
Definition: ItemPreviewWidget.c:12
SCR_PlayerArsenalLoadout
Definition: SCR_PlayerArsenalLoadout.c:2
SCR_LoadoutPreviewComponent
Definition: SCR_LoadoutPreviewComponent.c:1
SCR_BasePlayerLoadout
Definition: SCR_BasePlayerLoadout.c:2