DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
AttachmentCategoriesContainer.c
Go to the documentation of this file.
2{
4 protected int m_SlotsCount;
6
7 void AttachmentCategoriesContainer( LayoutHolder parent, int sort = -1 )
8 {
10 }
11
12 void SetEntity( EntityAI entity )
13 {
14 m_Entity = entity;
16
17 m_MainWidget = m_RootWidget.FindAnyWidget( "body" );
18 WidgetEventHandler.GetInstance().RegisterOnChildAdd( m_MainWidget, this, "OnChildAdd" );
19 WidgetEventHandler.GetInstance().RegisterOnChildRemove( m_MainWidget, this, "OnChildRemove" );
20
22
23 ( Container.Cast( m_Parent ) ).m_Body.Insert( this );
24 m_Parent.Refresh();
26 RecomputeOpenedContainers();
27 }
28
30 {
31 m_CollapsibleHeader.SetName( m_Entity.GetDisplayName() );
32 }
33
34 override bool IsDisplayable()
35 {
36 return !IsEmpty() || CanDisplayAnyCategory();
37 }
38
39 override void UpdateInterval()
40 {
41 if( m_Entity )
42 {
43 if( m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || m_Hidden )
44 {
45 if( m_Body.Count() > 0 && !m_Hidden )
46 m_CollapsibleHeader.OnHide();
47 HideContent();
48 GetMainWidget().Show( false );
49 }
50 else
51 {
52 if( m_Body.Count() > 0 && !m_Hidden )
53 {
54 if( m_Body.Count() > 0 && !m_Hidden )
55 m_CollapsibleHeader.OnShow();
56 int i;
57 for (i = m_SlotsCount; i < m_Body.Count(); i++)
58 {
60 if (row)
61 {
62 if (m_Entity.CanDisplayAttachmentCategory( row.GetCategoryIdentifier() ))
63 {
64 if ( row.IsDisplayable() )
65 {
67 if (!row.IsVisible())
68 {
69 row.OnShow();
70 }
71 }
72 else
73 {
74 ShowInSlots( row.GetCategoryIdentifier(), false );
75 if (row.IsVisible())
76 {
77 row.OnHide();
78 }
79 }
80 }
81 else
82 {
83 ShowInSlots( row.GetCategoryIdentifier(), false );
84 if (row.IsVisible())
85 {
86 row.OnHide();
87 }
88 }
89 row.UpdateInterval();
90 }
91 else
92 {
93 ContainerWithCargo cargo = ContainerWithCargo.Cast(m_Body[i]);
94 if (cargo)
95 {
96 if (m_Entity.CanDisplayCargo())
97 {
98 m_CargoSlotsIcon.m_MainWidget.Show(true);
99 if (!cargo.IsVisible())
100 {
101 cargo.OnShow();
102 }
103 }
104 else
105 {
106 m_CargoSlotsIcon.m_MainWidget.Show(false);
107 if (cargo.IsVisible())
108 {
109 cargo.OnHide();
110 }
111 }
112 cargo.UpdateInterval();
113 }
114 RecomputeOpenedContainers();
115
116 }
117
118 }
119 for ( i = 0; i < m_SlotsCount; i++)
120 {
122 {
123 if (slots.IsDisplayable())
124 {
125 slots.OnShow();
126 }
127 else
128 {
129 slots.OnHide();
130 }
131 }
132 }
133 }
134 GetMainWidget().Show( true );
135 }
136 }
137 }
138
139 void LoadAttachmentCategoriesIcon( SlotsContainer items_cont, string icon_name, int slot_number )
140 {
141 SlotsIcon icon = items_cont.GetSlotIcon( slot_number );
142 ImageWidget image_widget = icon.GetGhostSlot();
143 image_widget.Show( true );
144 image_widget.LoadImageFile( 0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY,icon_name) ); //icon_name must be in format "set:<setname> image:<imagename>"
145 }
146
147 int GetAttachmentCategoriesCount( string config_path )
148 {
149 return GetGame().ConfigGetChildrenCount( config_path );
150 }
151
153 {
154 AttachmentCategoriesSlotsContainer items_cont = AttachmentCategoriesSlotsContainer.Cast(m_Body.Get(icons_row));
155 return items_cont.GetSlotsContainer();
156 }
157
159 {
160 return m_CargoSlotsIcon;
161 }
162
163 void ShowInSlots( string category, bool show )
164 {
165 int index = m_CategorySlotIndex.Get( category );
166 int slot_number = index % ITEMS_IN_ROW;
167
168 SlotsContainer items_cont = GetSlotsContainer( index / ITEMS_IN_ROW );
169 if( items_cont )
170 {
171 Widget icon_widget = items_cont.GetSlotIcon( slot_number ).GetMainWidget();
172 if( icon_widget )
173 icon_widget.Show( show );
174 icon_widget.GetParent().Update();
175 icon_widget.GetParent().GetParent().Update();
176 icon_widget.GetParent().GetParent().GetParent().Update();
177 }
178 }
179
180 //oof
181 override bool CanDisplayAnyCategory()
182 {
183 int count = m_Body.Count();
185 for (int i = m_SlotsCount; i < count; i++)
186 {
187 if (Class.CastTo(row,m_Body[i]) && m_Entity.CanDisplayAttachmentCategory( row.GetCategoryIdentifier() ))
188 {
189 return true;
190 }
191 }
192 return super.CanDisplayAnyCategory();
193 }
194
195 override void UpdateRadialIcon()
196 {
197 if ( m_SlotIcon )
198 {
199 if (m_Entity.CanDisplayCargo() || CanDisplayAnyCategory())
200 {
201 m_SlotIcon.GetRadialIconPanel().Show( true );
202 SetOpenForSlotIcon(!m_Hidden);
203 }
204 else
205 {
206 m_SlotIcon.GetRadialIconPanel().Show( false );
207 }
208 }
209 }
210
211 string GetAttachmentCategory( string config_path_attachment_categories, int i )
212 {
213 string attachment_category;
214 GetGame().ConfigGetChildName(config_path_attachment_categories, i, attachment_category);
215 return attachment_category;
216 }
217
218 string GetIconName( string config_path_attachment_categories, string attachment_category )
219 {
220 string icon_path = config_path_attachment_categories+ " " + attachment_category + " icon";
221 string icon_name;
222 GetGame().ConfigGetText(icon_path, icon_name);
223 return icon_name;
224 }
225
226 int GetViewIndex( string config_path_attachment_categories, string attachment_category )
227 {
228 string preview_path = config_path_attachment_categories+ " " + attachment_category + " view_index";
229 return GetGame().ConfigGetInt( preview_path );;
230 }
231
233 {
234 SlotsIcon slots_icon;
235 w.GetUserData(slots_icon);
236
237 ClosableContainer c = ClosableContainer.Cast( slots_icon.GetContainer() );
238 if( c )
239 {
240 if( c.IsOpened() )
241 {
242 c.Close();
243 }
244 else
245 {
246 c.Open();
247 }
248 }
249 }
250
252 {
253 if (m_OpenedContainers.Count() > m_ActiveIndex)
254 {
255 //c - container where selected icon is part of
256 Container c = Container.Cast(m_OpenedContainers.Get( m_ActiveIndex ));
257 //cc - container connected to selected icon (this container will be close/open)
259 //icon - selected icon
260 SlotsIcon icon = c.GetFocusedSlotsIcon();
261
262 if (icon)
263 {
264 cc = ClosableContainer.Cast(icon.GetContainer());
265 }
266
267 if (cc)
268 {
269
270 cc.Toggle();
271 RecomputeOpenedContainers();
272 }
273 }
274 }
275
277 {
278 return m_CollapsibleHeader.IsActive();
279 }
280
282 {
283 m_SlotsCount = 0;
284
285 string type = m_Entity.GetType();
286 string config_path_attachment_categories = "CfgVehicles " + type + " GUIInventoryAttachmentsProps";
287 int attachments_categories_count = GetAttachmentCategoriesCount( config_path_attachment_categories );
288 int categories_count = attachments_categories_count;
289 if (m_Entity.GetInventory().GetCargo())
290 {
291 categories_count++;
292 }
293 int row_count = categories_count / ITEMS_IN_ROW;
294 if (categories_count % ITEMS_IN_ROW != 0)
295 {
296 row_count++;
297 }
298 for ( int i = 0; i < row_count; i++ )
299 {
301 m_Body.Insert( items_cont );
302 m_OpenedContainers.Insert( items_cont );
303
304 //TODO MW find better way
305 if (i == ( row_count - 1 ) && categories_count % ITEMS_IN_ROW != 0)
306 items_cont.GetSlotsContainer().SetColumnCount( categories_count % ITEMS_IN_ROW );
307 else
308 items_cont.GetSlotsContainer().SetColumnCount( ITEMS_IN_ROW );
309 }
310 m_SlotsCount = row_count;
311 }
312
314 {
315 string type = m_Entity.GetType();
316 string config_path_attachment_categories = "CfgVehicles " + type + " GUIInventoryAttachmentsProps";
317
318 int attachments_categories_count = GetAttachmentCategoriesCount( config_path_attachment_categories );
319
320 SlotsContainer items_cont;
321 SlotsIcon icon;
322 string attachment_category;
323 string icon_name;
324
325 for (int i = 0; i < attachments_categories_count; i++)
326 {
327 items_cont = GetSlotsContainer( i / ITEMS_IN_ROW );
328 attachment_category = GetAttachmentCategory( config_path_attachment_categories, i );
329 icon_name = GetIconName( config_path_attachment_categories, attachment_category );
330
331 if ( items_cont )
332 {
333 int slot_number = i % ITEMS_IN_ROW;
334 m_CategorySlotIndex.Insert( attachment_category, i );
335 icon = items_cont.GetSlotIcon( slot_number );
336 icon.GetGhostSlot().SetFlags( WidgetFlags.IGNOREPOINTER );
337
338 LoadAttachmentCategoriesIcon( items_cont, icon_name, slot_number );
339
340 string config = config_path_attachment_categories + " " + attachment_category + " name";
341 string name;
342
343 GetGame().ConfigGetText(config,name);
345
347
348 ar = new AttachmentCategoriesRow( this, -1 );
349 ar.Init(attachments_categories_count, i, attachment_category, config_path_attachment_categories, m_Entity, m_Body.Count() );
350
351 //Insert(ar);
352 ar.SetSlotIcon(icon);
353 //icon.SetContainer(ar);
354
355 icon.GetRadialIconPanel().Show( true );
356 ar.Open();
357 icon.SetContainer(ar);
358 Insert(ar);
359 }
360 }
361
362 if ( m_Entity.GetInventory().GetCargo() )
363 {
364 items_cont = GetSlotsContainer( m_SlotsCount - 1 );
365 if ( items_cont )
366 {
367 icon = items_cont.GetSlotIcon( attachments_categories_count );
368 icon.GetGhostSlot().Show( true );
369 icon.GetGhostSlot().LoadImageFile( 0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY,m_Entity.ConfigGetString("GUIInventoryCargoIcon")) );
370 icon.SetSlotDisplayName(m_Entity.ConfigGetString("GUIInventoryCargoName"));
371 icon.GetGhostSlot().SetFlags( WidgetFlags.IGNOREPOINTER );
372
373 icon.GetRadialIconPanel().Show( true );
374 icon.GetMainWidget().Show( true );
375
376 ContainerWithCargo iwc = new ContainerWithCargo( this, -1 );
377 iwc.Get( 0 ).GetRootWidget().ClearFlags( WidgetFlags.DRAGGABLE );
378 iwc.SetEntity( m_Entity, 0, false );
379 iwc.SetSlotIcon( icon );
380 iwc.Open();
381
382 icon.SetContainer(iwc);
383 m_CargoSlotsIcon = icon;
384 }
385 }
386
387 RecomputeOpenedContainers();
388 }
389
390
391 override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
392 {
393 ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
394 if(!iw)
395 {
396 string name = w.GetName();
397 name.Replace("PanelWidget", "Render");
398 iw = ItemPreviewWidget.Cast( w.FindAnyWidget(name) );
399 }
400 if(!iw)
401 {
402 iw = ItemPreviewWidget.Cast( w );
403 }
404 if( !iw.GetItem() )
405 return;
406 if( m_Entity.GetInventory().CanAddAttachment( iw.GetItem() ) && iw.GetItem().GetInventory().CanRemoveEntity() )
407 {
408 GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment( m_Entity, iw.GetItem() );
409 }
410 else if( m_Entity.GetInventory().CanAddEntityToInventory( iw.GetItem() ) && iw.GetItem().GetInventory().CanRemoveEntity() )
411 {
412 GetGame().GetPlayer().PredictiveTakeEntityToTargetInventory( m_Entity, FindInventoryLocationType.ANY, iw.GetItem() );
413 }
414 }
415
416 override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
417 {
418 if( w == null )
419 {
420 return;
421 }
422 ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
423 if(!iw)
424 {
425 string name = w.GetName();
426 name.Replace("PanelWidget", "Render");
427 iw = ItemPreviewWidget.Cast( w.FindAnyWidget(name) );
428 }
429 if(!iw)
430 {
431 iw = ItemPreviewWidget.Cast( w );
432 }
433 if( !iw || !iw.GetItem() )
434 {
435 return;
436 }
437
440 }
441
442 /*override void CollapseButtonOnMouseButtonDown(Widget w)
443 {
444 super.CollapseButtonOnMouseButtonDown(w);
445 RecomputeOpenedContainers();
446 }*/
448 {
449 if( !m_Hidden )
450 {
451 for (int i = 1; i < m_Body.Count(); i++)
452 {
453 m_Body.Get( i ).OnHide();
454 Container c = Container.Cast(m_Body.Get(i));
455 if (c)
456 {
457 c.Close();
458 }
459 }
460
461 //m_Hidden = true;
462 OnHide();
463 }
464 else
465 {
466 //m_Hidden = false;
467 OnShow();
468 }
469 m_Closed = m_Hidden;
470
473 {
475 }
476
478 RecomputeOpenedContainers();
479 }
480
481 override void Open()
482 {
483 if( IsDisplayable() )
484 {
485 super.Open();
486 //ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), true );
487 SetOpenForSlotIcon(true);
488 OnShow();
489 //m_Parent.m_Parent.Refresh();
490 }
491 }
492
493 override void Close()
494 {
495 //ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), false );
496 super.Close();
497
498 SlotsIcon icon = null;
500 {
501 icon = m_CargoSlotsIcon;
502 }
503 else if (m_SlotIcon && m_SlotIcon.GetObject())
504 {
505 icon = m_SlotIcon;
506 }
507 /*else
508 {
509 Print("Dbg | no object in icon here!");
510 }
511 */
512
513 SetOpenForSlotIcon(false,icon);
514 OnHide();
515 }
516
517 override void OnHide()
518 {
520 {
521 bool b1 = !m_SlotIcon && !m_CargoSlotsIcon;
522 bool b2 = (!m_SlotIcon || !m_SlotIcon.IsVisible()) && m_CargoSlotsIcon && m_CargoSlotsIcon.IsVisible();
524 }
525 super.OnHide();
526 }
527
528 override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
529 {
530 if (m_OpenedContainers.Count() > m_ActiveIndex)
531 {
533 SlotsIcon icon = GetFocusedSlotsIcon();
534
535 if (icon)
536 {
537 c = ClosableContainer.Cast(icon.GetContainer());
538 }
539
540 if (c && c.IsDisplayable())
541 {
542 return true;
543 }
544 }
545
546 return false;
547 }
548
549 override bool CanSplitEx(EntityAI focusedEntity)
550 {
551 return false;
552 }
553}
const int ITEMS_IN_ROW
Definition Attachments.c:1
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
string name
class PluginItemDiagnosticEventHandler extends ScriptedWidgetEventHandler m_Entity
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
protected Widget m_Parent
Definition SizeToChild.c:92
int GetAttachmentCategoriesCount(string config_path)
void ShowInSlots(string category, bool show)
void LoadAttachmentCategoriesIcon(SlotsContainer items_cont, string icon_name, int slot_number)
string GetIconName(string config_path_attachment_categories, string attachment_category)
override bool CanSplitEx(EntityAI focusedEntity)
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
void AttachmentCategoriesContainer(LayoutHolder parent, int sort=-1)
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
protected ref map< string, int > m_CategorySlotIndex
string GetAttachmentCategory(string config_path_attachment_categories, int i)
override void CollapseButtonOnMouseButtonDown(Widget w)
int GetViewIndex(string config_path_attachment_categories, string attachment_category)
SlotsContainer GetSlotsContainer(int icons_row)
void Init(int attachments_categories_count, int i, string attachment_category, string config_path_attachment_categories, EntityAI entity, int parent_m_Body_count)
proto native int ConfigGetChildrenCount(string path)
Get count of subclasses in config class on path.
proto native DayZPlayer GetPlayer()
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native int ConfigGetInt(string path)
Get int value from config on path.
proto bool ConfigGetChildName(string path, int index, out string name)
Get name of subclass in config class on path.
Super root of all classes in Enforce script.
Definition EnScript.c:11
override bool IsOpened()
override void Close()
override void Open()
override bool IsDisplayable()
protected ref CollapsibleHeader m_CollapsibleHeader
void SetCollapsibleHeaderArrowState(bool open)
override void Insert(LayoutHolder container, int pos=-1, bool immedUpdate=true)
void SetHeaderVisible(bool show)
static ColorManager GetInstance()
static int RED_COLOR
void SetColor(Widget w, int color)
override void OnShow()
override void Close()
override bool IsEmpty()
void SetName(string name)
Definition Header.c:33
void ShowSourceDropzone(EntityAI item)
static ItemManager GetInstance()
proto native EntityAI GetItem()
SlotsIcon GetSlotIcon(int index)
void SetSlotDisplayName(string text)
Definition SlotsIcon.c:144
Widget GetRadialIconPanel()
Definition SlotsIcon.c:295
override void UpdateInterval()
Definition SlotsIcon.c:669
Container GetContainer()
Definition SlotsIcon.c:149
Object GetObject()
Definition SlotsIcon.c:348
ImageWidget GetGhostSlot()
Definition SlotsIcon.c:235
void SetContainer(Container container)
Definition SlotsIcon.c:139
override bool IsVisible()
Definition SlotsIcon.c:129
static const int IMAGESETGROUP_INVENTORY
static string VerifyIconImageString(int imageset_group=IMAGESETGROUP_INVENTORY, string icon_name="")
Checks for improperly formated, legacy image names and corrects them to default format.
static WidgetEventHandler GetInstance()
void RegisterOnChildRemove(Widget w, Managed eventHandler, string functionName)
void RegisterOnChildAdd(Widget w, Managed eventHandler, string functionName)
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto int Replace(string sample, string replace)
Replace all occurrances of 'sample' in 'str' by 'replace'.
WidgetFlags
Definition EnWidgets.c:57