Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InventoryItemInfoUI.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/UI/Inventory", description: "Inventory Item Info UI class")]
2
3//------------------------------------------------------------------------------------------------
7{
16 protected bool m_bForceShow;
17
18 protected ResourceName m_sAmmoTypeConfig = "{8D3E102893955B15}Configs/Inventory/ItemHints/MagazineAmmoType.conf";
20
21 protected const string m_sHintLayout = "{9996B50BE8DFED5F}UI/layouts/Menus/Inventory/InventoryItemHintElement.layout";
22
23 protected const string m_sIdentityItemLayout = "{9168128FD3D1FBC2}UI/layouts/Menus/Inventory/InventoryIdentityItem.layout";
24 protected const string m_sIdentityWidgetHolderName = "IdentityHolder";
25
26
27 //------------------------------------------------------------------------ USER METHODS ------------------------------------------------------------------------
28 //------------------------------------------------------------------------------------------------
29 protected void ShowInfoWidget( bool bShow )
30 {
31 if (m_bForceShow)
32 {
33 m_infoWidget.SetVisible( true );
34 return;
35 }
36
38 return;
39 if ( WidgetManager.GetWidgetUnderCursor() != m_wWidgetUnderCursor )
40 return; //the cursor is on different position already
41 m_infoWidget.SetVisible( true );
42 }
43
44 //------------------------------------------------------------------------------------------------
45 void Show( float fDelay = 0.0, Widget w = null, bool forceShow = false )
46 {
47 m_bForceShow = forceShow;
49 if ( fDelay == 0 )
50 ShowInfoWidget( true );
51 else
52 {
53 GetGame().GetCallqueue().Remove( ShowInfoWidget );
54 GetGame().GetCallqueue().CallLater( ShowInfoWidget, fDelay*1000, false, true );
55 }
56 }
57
58 //------------------------------------------------------------------------------------------------
59 void SetIcon(ResourceName iconPath, Color color = null)
60 {
61 if (iconPath.IsEmpty())
62 return;
63
64 m_wItemIcon.SetVisible(m_wItemIcon.LoadImageTexture(0, iconPath));
65 if (color)
66 m_wItemIcon.SetColor(color);
67 }
68
69 //------------------------------------------------------------------------------------------------
70 void ShowIcon(bool isVisible)
71 {
72 m_wItemIcon.SetVisible(isVisible);
73 }
74
75 //------------------------------------------------------------------------------------------------
76 void Hide( float fDelay = 1.0 )
77 {
78 m_infoWidget.SetVisible( false );
79 m_infoWidget.SetEnabled( false );
80 m_wItemIcon.SetVisible(false);
81
82 Widget childWidget = m_wHintWidget.GetChildren();
83 while (childWidget)
84 {
85 Widget next = childWidget.GetSibling();
86 m_wHintWidget.RemoveChild(childWidget);
87 childWidget = next;
88 }
89
90 GetGame().GetCallqueue().Remove(ShowInfoWidget);
91 }
92
93 //------------------------------------------------------------------------------------------------
94 void Move( float x, float y )
95 {
96 if ( !m_pFrameSlotUI )
97 return;
98 m_pFrameSlotUI.SetPosX( x );
99 m_pFrameSlotUI.SetPosY( y );
100 }
101
102 //------------------------------------------------------------------------------------------------
103 void SetName( string sName )
104 {
105 m_wTextName.SetText( sName );
106 }
107
108 //------------------------------------------------------------------------------------------------
109 void SetDescription( string sDescr )
110 {
111 if( sDescr != "" )
112 {
113 m_wTextDescription.SetEnabled( true );
114 m_wTextDescription.SetVisible( true );
115 m_wTextDescription.SetText( sDescr );
116 }
117 else
118 {
119 m_wTextDescription.SetEnabled( false );
120 m_wTextDescription.SetVisible( false );
121 }
122 }
123
124 //------------------------------------------------------------------------------------------------
125 void SetItemHints(InventoryItemComponent item, array<SCR_InventoryItemHintUIInfo> itemHintArray, SCR_InventorySlotUI focusedSlot)
126 {
127 WorkspaceWidget workspace = GetGame().GetWorkspace();
128
129 //~ Clear existing hints if any
130 Widget hintChild = m_wHintWidget.GetChildren();
131 Widget deleteHint;
132 while(hintChild)
133 {
134 deleteHint = hintChild;
135 hintChild = deleteHint.GetSibling();
136
137 delete deleteHint;
138 }
139
140 foreach (SCR_InventoryItemHintUIInfo hintUIInfo : itemHintArray)
141 {
142 if (!hintUIInfo.CanBeShown(item, focusedSlot))
143 continue;
144
145 Widget createdWidget = workspace.CreateWidgets(m_sHintLayout, m_wHintWidget);
146 if (!createdWidget)
147 return;
148
149 hintUIInfo.SetItemHintNameTo(item, RichTextWidget.Cast(createdWidget.FindAnyWidget("ItemInfo_hintText")));
150 hintUIInfo.SetIconTo(ImageWidget.Cast(createdWidget.FindAnyWidget("ItemInfo_hintIcon")));
151 }
152
153 SetItemHints(item, false);
154 }
155
156 void SetItemHints(InventoryItemComponent item, bool deleteSlots = true)
157 {
158 if (!m_AmmoTypeConf)
159 {
160 Resource holder = BaseContainerTools.LoadContainer(m_sAmmoTypeConfig);
161 if (!holder || !holder.IsValid())
162 return;
163
164 BaseContainer container = holder.GetResource().ToBaseContainer();
165 if (!container)
166 return;
167
168 m_AmmoTypeConf = SCR_AmmoTypeInfoConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
169 if (!m_AmmoTypeConf)
170 return;
171 }
172
173 if (deleteSlots)
174 {
175 Widget hintChild = m_wHintWidget.GetChildren();
176 Widget deleteHint;
177 while(hintChild)
178 {
179 deleteHint = hintChild;
180 hintChild = deleteHint.GetSibling();
181
182 delete deleteHint;
183 }
184 }
185
186 if (!item || !item.GetOwner())
187 return;
188
190
192 if (mag)
193 {
194 MagazineUIInfo ammoInfo = MagazineUIInfo.Cast(mag.GetUIInfo());
195 if (!ammoInfo)
196 return;
197
198 flags = ammoInfo.GetAmmoTypeFlags();
199 }
200
201 WeaponComponent weapon = WeaponComponent.Cast(item.GetOwner().FindComponent(WeaponComponent));
202 if (weapon)
203 {
204 GrenadeUIInfo ammoInfo = GrenadeUIInfo.Cast(weapon.GetUIInfo());
205 if (!ammoInfo)
206 return;
207
208 flags = ammoInfo.GetAmmoTypeFlags();
209 }
210
211 array<EAmmoType> values = {};
212 SCR_Enum.GetEnumValues(EAmmoType, values);
213 foreach (EAmmoType flag : values)
214 {
215 if (flags & flag)
216 {
217 Widget createdWidget = GetGame().GetWorkspace().CreateWidgets(m_sHintLayout, m_wHintWidget);
218 if (!createdWidget)
219 return;
220
221 RichTextWidget text = RichTextWidget.Cast(createdWidget.FindAnyWidget("ItemInfo_hintText"));
222 ImageWidget icon = ImageWidget.Cast(createdWidget.FindAnyWidget("ItemInfo_hintIcon"));
223
224 m_AmmoTypeConf.SetIconAndDescriptionTo(flag, icon, text);
225 }
226 }
227 }
228
229 //------------------------------------------------------------------------------------------------
230 void SetWeight( string sWeight )
231 {
232 if (!sWeight.IsEmpty())
233 {
234 m_wTextWeight.SetEnabled( true );
235 m_wTextWeight.SetVisible( true );
236 m_wTextWeight.SetTextFormat("#AR-ValueUnit_Short_Kilograms", sWeight);
237 }
238 else
239 {
240 m_wTextWeight.SetEnabled( false );
241 m_wTextWeight.SetVisible( false );
242 }
243 }
244
245 //------------------------------------------------------------------------------------------------
246 void SetWeight( float fWeight )
247 {
248 if( fWeight <= 0.0 )
249 SetWeight( "" );
250 else
251 SetWeight( fWeight.ToString() );
252 }
253
254 //------------------------------------------------------------------------------------------------
257 void CreateIdentityUI(SCR_IdentityInventoryItemComponent identityItemComponent)
258 {
259 if (!m_infoWidget)
260 return;
261
262 Widget identityHolder = m_infoWidget.FindAnyWidget(m_sIdentityWidgetHolderName);
263 if (!identityHolder)
264 return;
265
266 //~ Clear existing identity if any
267 SCR_WidgetHelper.RemoveAllChildren(identityHolder);
268
269 //~ Check if can create Identity
270 if (!identityItemComponent)
271 return;
272
273 SCR_ExtendedIdentityComponent linkedIdentity = identityItemComponent.GetLinkedExtendedIdentity();
274 if (!linkedIdentity)
275 return;
276
277 SCR_IdentityBio identityBio = linkedIdentity.GetIdentityBio();
278 if (!identityBio)
279 return;
280
281 WorkspaceWidget workspace = GetGame().GetWorkspace();
282
283 //~ Create Identity
284 Widget createdWidget = workspace.CreateWidgets(m_sIdentityItemLayout, identityHolder);
285 if (!createdWidget)
286 return;
287
289 if (!identityItemWidgetComponent)
290 {
291 delete createdWidget;
292 return;
293 }
294
295 identityItemWidgetComponent.SetIdentityData(identityItemComponent, linkedIdentity, identityBio);
296 }
297
298 //------------------------------------------------------------------------------------------------
299 override void HandlerAttached( Widget w )
300 {
301 if( !w )
302 return;
303
304 m_infoWidget = w;
305 m_wHintWidget = VerticalLayoutWidget.Cast( w.FindAnyWidget( "VerticalHintParent" ) );
306 m_wTextName = TextWidget.Cast( w.FindAnyWidget( "ItemInfo_name" ) );
307 m_wTextDescription = TextWidget.Cast( w.FindAnyWidget( "ItemInfo_description" ) );
308 m_wTextWeight = TextWidget.Cast( w.FindAnyWidget( "ItemInfo_weight" ) );
309 m_wItemIcon = ImageWidget.Cast(w.FindAnyWidget("ItemInfo_icon"));
310
311 Widget wItemInfo = m_infoWidget.FindAnyWidget( "ItemInfo" );
312 if ( !wItemInfo )
313 return;
314 m_pFrameSlotUI = SCR_SlotUIComponent.Cast( wItemInfo.FindHandler( SCR_SlotUIComponent ) );
315 }
316
317 //------------------------------------------------------------------------------------------------
318 void Destroy()
319 {
320 if ( m_infoWidget )
321 {
322 GetGame().GetCallqueue().Remove( ShowInfoWidget );
323 m_infoWidget.RemoveHandler( m_pFrameSlotUI );
324 m_infoWidget.RemoveHandler( this );
325 m_infoWidget.RemoveFromHierarchy();
326 }
327 }
328
329 //------------------------------------------------------------------------------------------------
331 {
332 return m_infoWidget.FindAnyWidget("size");
333 }
334
335 //------------------------------------------------------------------------ COMMON METHODS ----------------------------------------------------------------------
336
337
338 //------------------------------------------------------------------------------------------------
340 {
341 }
342
343 //------------------------------------------------------------------------------------------------
345 {
346 }
347};
SCR_EAIThreatSectorFlags flags
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
EAmmoType
Definition Color.c:13
EAmmoType GetAmmoTypeFlags()
proto external Managed FindComponent(typename typeName)
EAmmoType GetAmmoTypeFlags()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void SetIdentityData(notnull SCR_IdentityInventoryItemComponent identityItemComponent, notnull SCR_ExtendedIdentityComponent linkedIdentity, SCR_IdentityBio identityBio)
void Show(float fDelay=0.0, Widget w=null, bool forceShow=false)
void SetItemHints(InventoryItemComponent item, bool deleteSlots=true)
void CreateIdentityUI(SCR_IdentityInventoryItemComponent identityItemComponent)
ref SCR_AmmoTypeInfoConfig m_AmmoTypeConf
void SetIcon(ResourceName iconPath, Color color=null)
SCR_SlotUIComponent m_pFrameSlotUI
void Move(float x, float y)
override void HandlerAttached(Widget w)
void Hide(float fDelay=1.0)
VerticalLayoutWidget m_wHintWidget
void SetItemHints(InventoryItemComponent item, array< SCR_InventoryItemHintUIInfo > itemHintArray, SCR_InventorySlotUI focusedSlot)