Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LoadoutPreviewComponent.c
Go to the documentation of this file.
2{
3 [Attribute("{9F18C476AB860F3B}Prefabs/World/Game/ItemPreviewManager.et")]
5
6 [Attribute("Preview")]
7 protected string m_sPreviewWidgetName;
8
9 protected ItemPreviewManagerEntity m_PreviewManager;
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)
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, true);
31 child = sibling;
32 }
33
34 if (!entity.IsDeleted() && deleteRoot)
35 delete entity;
36 }
37
38 //------------------------------------------------------------------------------------------------
40 {
42 return null;
43
44 ChimeraWorld world = GetGame().GetWorld();
45 m_PreviewManager = world.GetItemPreviewManager();
46
48 {
50 if (res.IsValid())
51 GetGame().SpawnEntityPrefabLocal(res, world);
52
53 m_PreviewManager = world.GetItemPreviewManager();
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_LocalPlayerLoadoutData;
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 IEntity activeWeaponEntity;
100 if (weaponStorage)
101 {
102 for (int i = 0, weaponsCount = loadoutData.Weapons.Count(); i < weaponsCount; ++i)
103 {
104 InventoryStorageSlot slot = weaponStorage.GetSlot(loadoutData.Weapons[i].SlotIdx);
105 if (!slot)
106 continue;
107
108 Resource resource = Resource.Load(loadoutData.Weapons[i].WeaponPrefab);
109 if (!resource)
110 continue;
111
112 IEntity weapon = GetGame().SpawnEntityPrefabLocal(resource, previewedEntity.GetWorld());
113 if (!weapon)
114 continue;
115
116 slot.AttachEntity(weapon);
117
118 if (loadoutData.Weapons[i].Active)
119 activeWeaponEntity = weapon;
120
121 const int attachmentsCount = loadoutData.Weapons[i].Attachments.Count();
122 WeaponAttachmentsStorageComponent attachmentsStorage = WeaponAttachmentsStorageComponent.Cast(weapon.FindComponent(WeaponAttachmentsStorageComponent));
123 if (!attachmentsStorage || attachmentsStorage.GetSlotsCount() != attachmentsCount)
124 continue;
125
126 IEntity attachment;
127 ResourceName prefab, current;
128 for (int nAttachment = 0; nAttachment < attachmentsCount; ++nAttachment)
129 {
130 slot = attachmentsStorage.GetSlot(nAttachment);
131 attachment = slot.GetAttachedEntity();
132 current = SCR_ResourceNameUtils.GetPrefabName(attachment);
133 prefab = loadoutData.Weapons[i].Attachments[nAttachment];
134 if (current == prefab)
135 continue;
136
137 if (attachment)
138 delete attachment;
139
140 resource = Resource.Load(prefab);
141 if (!resource)
142 continue;
143
144 attachment = GetGame().SpawnEntityPrefabLocal(resource, previewedEntity.GetWorld());
145 if (!attachment)
146 continue;
147
148 slot.AttachEntity(attachment);
149 }
150 }
151 }
152
153 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(previewedEntity.FindComponent(BaseWeaponManagerComponent));
154 if (weaponManager)
155 {
156 array<WeaponSlotComponent> outSlots = {};
157 weaponManager.GetWeaponsSlots(outSlots);
158 foreach (WeaponSlotComponent weaponSlot : outSlots)
159 {
160 if (weaponSlot.GetWeaponEntity() == activeWeaponEntity)
161 {
162 weaponManager.SelectWeapon(weaponSlot);
163 break;
164 }
165 }
166 }
167
168 m_PreviewManager.SetPreviewItem(m_wPreview, previewedEntity, attributes, true);
169 return previewedEntity;
170 }
171 else
172 {
173 m_PreviewManager.SetPreviewItemFromPrefab(m_wPreview, resName, attributes);
174 return m_PreviewManager.ResolvePreviewEntityForPrefab(resName);
175 }
176 }
177
178 //------------------------------------------------------------------------------------------------
179 ItemPreviewManagerEntity GetPreviewManagerEntity()
180 {
181 return m_PreviewManager;
182 }
183
184 //------------------------------------------------------------------------------------------------
185 void SetPreviewManagerEntity(ItemPreviewManagerEntity instance)
186 {
187 m_PreviewManager = instance;
188 }
189
190 //------------------------------------------------------------------------------------------------
195
196 //------------------------------------------------------------------------------------------------
198 {
199 m_wPreview = instance;
200 }
201
202 //------------------------------------------------------------------------------------------------
203 void SetReloadLoadout(bool flag)
204 {
205 m_bReloadLoadout = flag;
206 }
207}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref SCR_PlayerLoadoutData loadoutData
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
proto external BaseWorld GetWorld()
proto external IEntity GetSibling()
proto external bool IsDeleted()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void SetPreviewManagerEntity(ItemPreviewManagerEntity instance)
ItemPreviewManagerEntity GetPreviewManagerEntity()
void DeleteChildrens(IEntity entity, bool deleteRoot)
void SetItemPreviewWidget(ItemPreviewWidget instance)
IEntity SetPreviewedLoadout(notnull SCR_BasePlayerLoadout loadout, PreviewRenderAttributes attributes=null)
ItemPreviewManagerEntity m_PreviewManager
SCR_FieldOfViewSettings Attribute