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