Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
attachmentcategoriescontainer.c
Go to the documentation of this file.
2 {
3  protected ref map<string, int> m_CategorySlotIndex;
4  protected int m_SlotsCount;
5  protected SlotsIcon m_CargoSlotsIcon;
6 
7  void AttachmentCategoriesContainer( LayoutHolder parent, int sort = -1 )
8  {
9  m_CategorySlotIndex = new map<string, int>;
10  }
11 
12  void SetEntity( EntityAI entity )
13  {
14  m_Entity = entity;
15  InitIconsContainers();
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 
21  InitGhostSlots();
22 
23  ( Container.Cast( m_Parent ) ).m_Body.Insert( this );
24  m_Parent.Refresh();
25  SetHeaderName();
26  RecomputeOpenedContainers();
27  }
28 
29  void SetHeaderName()
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  {
59  AttachmentCategoriesRow row = AttachmentCategoriesRow.Cast( m_Body[i] );
60  if (row)
61  {
62  if (m_Entity.CanDisplayAttachmentCategory( row.GetCategoryIdentifier() ))
63  {
64  if ( row.IsDisplayable() )
65  {
66  ShowInSlots( row.GetCategoryIdentifier(), true );
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 
152  SlotsContainer GetSlotsContainer( int icons_row )
153  {
154  AttachmentCategoriesSlotsContainer items_cont = AttachmentCategoriesSlotsContainer.Cast(m_Body.Get(icons_row));
155  return items_cont.GetSlotsContainer();
156  }
157 
158  SlotsIcon GetCargoSlotsIcon()
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 
232  void MouseClick(Widget w)
233  {
234  SlotsIcon icon;
235  w.GetUserData(icon);
236 
237  ClosableContainer c = ClosableContainer.Cast(icon.GetContainer());
238  if (c)
239  c.Toggle();
240  }
241 
242  override void ExpandCollapseContainer()
243  {
244  if (m_OpenedContainers.Count() > m_ActiveIndex)
245  {
246  //c - container where selected icon is part of
247  Container c = Container.Cast(m_OpenedContainers.Get( m_ActiveIndex ));
248  //cc - container connected to selected icon (this container will be close/open)
250  //icon - selected icon
251  SlotsIcon icon = c.GetFocusedSlotsIcon();
252 
253  if (icon)
254  {
255  cc = ClosableContainer.Cast(icon.GetContainer());
256  }
257 
258  if (cc)
259  {
260 
261  cc.Toggle();
262  RecomputeOpenedContainers();
263  }
264  }
265  }
266 
267  bool IsHeaderActive()
268  {
269  return m_CollapsibleHeader.IsActive();
270  }
271 
272  void InitIconsContainers()
273  {
274  m_SlotsCount = 0;
275 
276  string type = m_Entity.GetType();
277  string config_path_attachment_categories = "CfgVehicles " + type + " GUIInventoryAttachmentsProps";
278  int attachments_categories_count = GetAttachmentCategoriesCount( config_path_attachment_categories );
279  int categories_count = attachments_categories_count;
280  if (m_Entity.GetInventory().GetCargo())
281  {
282  categories_count++;
283  }
284  int row_count = categories_count / ITEMS_IN_ROW;
285  if (categories_count % ITEMS_IN_ROW != 0)
286  {
287  row_count++;
288  }
289  for ( int i = 0; i < row_count; i++ )
290  {
292  m_Body.Insert( items_cont );
293  m_OpenedContainers.Insert( items_cont );
294 
295  //TODO MW find better way
296  if (i == ( row_count - 1 ) && categories_count % ITEMS_IN_ROW != 0)
297  items_cont.GetSlotsContainer().SetColumnCount( categories_count % ITEMS_IN_ROW );
298  else
299  items_cont.GetSlotsContainer().SetColumnCount( ITEMS_IN_ROW );
300  }
301  m_SlotsCount = row_count;
302  }
303 
304  void InitGhostSlots()
305  {
306  string type = m_Entity.GetType();
307  string config_path_attachment_categories = "CfgVehicles " + type + " GUIInventoryAttachmentsProps";
308 
309  int attachments_categories_count = GetAttachmentCategoriesCount( config_path_attachment_categories );
310 
311  SlotsContainer items_cont;
312  SlotsIcon icon;
313  string attachment_category;
314  string icon_name;
315 
316  for (int i = 0; i < attachments_categories_count; i++)
317  {
318  items_cont = GetSlotsContainer( i / ITEMS_IN_ROW );
319  attachment_category = GetAttachmentCategory( config_path_attachment_categories, i );
320  icon_name = GetIconName( config_path_attachment_categories, attachment_category );
321 
322  if ( items_cont )
323  {
324  int slot_number = i % ITEMS_IN_ROW;
325  m_CategorySlotIndex.Insert( attachment_category, i );
326  icon = items_cont.GetSlotIcon( slot_number );
327  icon.GetGhostSlot().SetFlags( WidgetFlags.IGNOREPOINTER );
328 
329  LoadAttachmentCategoriesIcon( items_cont, icon_name, slot_number );
330 
331  string config = config_path_attachment_categories + " " + attachment_category + " name";
332  string name;
333 
334  GetGame().ConfigGetText(config,name);
335  icon.SetSlotDisplayName(name);
336 
338 
339  ar = new AttachmentCategoriesRow( this, -1 );
340  ar.Init(attachments_categories_count, i, attachment_category, config_path_attachment_categories, m_Entity, m_Body.Count() );
341 
342  //Insert(ar);
343  ar.SetSlotIcon(icon);
344  //icon.SetContainer(ar);
345 
346  icon.GetRadialIconPanel().Show( true );
347  ar.Open();
348  icon.SetContainer(ar);
349  Insert(ar);
350  }
351  }
352 
353  if ( m_Entity.GetInventory().GetCargo() )
354  {
355  items_cont = GetSlotsContainer( m_SlotsCount - 1 );
356  if ( items_cont )
357  {
358  icon = items_cont.GetSlotIcon( attachments_categories_count );
359  icon.GetGhostSlot().Show( true );
360  icon.GetGhostSlot().LoadImageFile( 0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY,m_Entity.ConfigGetString("GUIInventoryCargoIcon")) );
361  icon.SetSlotDisplayName(m_Entity.ConfigGetString("GUIInventoryCargoName"));
362  icon.GetGhostSlot().SetFlags( WidgetFlags.IGNOREPOINTER );
363 
364  icon.GetRadialIconPanel().Show( true );
365  icon.GetMainWidget().Show( true );
366 
367  ContainerWithCargo iwc = new ContainerWithCargo( this, -1 );
368  iwc.Get( 0 ).GetRootWidget().ClearFlags( WidgetFlags.DRAGGABLE );
369  iwc.SetEntity( m_Entity, 0, false );
370  iwc.SetSlotIcon( icon );
371  iwc.Open();
372 
373  icon.SetContainer(iwc);
374  m_CargoSlotsIcon = icon;
375  }
376  }
377 
378  RecomputeOpenedContainers();
379  }
380 
381 
382  override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
383  {
384  ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
385  if(!iw)
386  {
387  string name = w.GetName();
388  name.Replace("PanelWidget", "Render");
389  iw = ItemPreviewWidget.Cast( w.FindAnyWidget(name) );
390  }
391  if(!iw)
392  {
393  iw = ItemPreviewWidget.Cast( w );
394  }
395  if( !iw.GetItem() )
396  return;
397  if( m_Entity.GetInventory().CanAddAttachment( iw.GetItem() ) && iw.GetItem().GetInventory().CanRemoveEntity() )
398  {
399  GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment( m_Entity, iw.GetItem() );
400  }
401  else if( m_Entity.GetInventory().CanAddEntityToInventory( iw.GetItem() ) && iw.GetItem().GetInventory().CanRemoveEntity() )
402  {
403  GetGame().GetPlayer().PredictiveTakeEntityToTargetInventory( m_Entity, FindInventoryLocationType.ANY, iw.GetItem() );
404  }
405  }
406 
407  override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
408  {
409  if( w == null )
410  {
411  return;
412  }
413  ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
414  if(!iw)
415  {
416  string name = w.GetName();
417  name.Replace("PanelWidget", "Render");
418  iw = ItemPreviewWidget.Cast( w.FindAnyWidget(name) );
419  }
420  if(!iw)
421  {
422  iw = ItemPreviewWidget.Cast( w );
423  }
424  if( !iw || !iw.GetItem() )
425  {
426  return;
427  }
428 
429  ItemManager.GetInstance().ShowSourceDropzone( iw.GetItem() );
430  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
431  }
432 
433  /*override void CollapseButtonOnMouseButtonDown(Widget w)
434  {
435  super.CollapseButtonOnMouseButtonDown(w);
436  RecomputeOpenedContainers();
437  }*/
438  override void CollapseButtonOnMouseButtonDown( Widget w )
439  {
440  if( !m_Hidden )
441  {
442  for (int i = 1; i < m_Body.Count(); i++)
443  {
444  m_Body.Get( i ).OnHide();
445  Container c = Container.Cast(m_Body.Get(i));
446  if (c)
447  {
448  c.Close();
449  }
450  }
451 
452  //m_Hidden = true;
453  OnHide();
454  }
455  else
456  {
457  //m_Hidden = false;
458  OnShow();
459  }
460  m_Closed = m_Hidden;
461 
462  SetCollapsibleHeaderArrowState(m_Hidden);
463  if (m_CollapsibleHeader)
464  {
465  m_CollapsibleHeader.SetHeaderVisible(true);
466  }
467 
468  UpdateCollapseButtons();
469  RecomputeOpenedContainers();
470  }
471 
472  override void Open()
473  {
474  if( IsDisplayable() )
475  {
476  super.Open();
477  //ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), true );
478  SetOpenForSlotIcon(true);
479  OnShow();
480  //m_Parent.m_Parent.Refresh();
481  }
482  }
483 
484  override void Close()
485  {
486  //ItemManager.GetInstance().SetDefaultOpenState( m_Entity.GetType(), false );
487  super.Close();
488 
489  SlotsIcon icon = null;
490  if (m_CargoSlotsIcon && m_CargoSlotsIcon.GetObject())
491  {
492  icon = m_CargoSlotsIcon;
493  }
494  else if (m_SlotIcon && m_SlotIcon.GetObject())
495  {
496  icon = m_SlotIcon;
497  }
498  /*else
499  {
500  Print("Dbg | no object in icon here!");
501  }
502  */
503 
504  SetOpenForSlotIcon(false,icon);
505  OnHide();
506  }
507 
508  override void OnHide()
509  {
510  if (m_CollapsibleHeader)
511  {
512  bool b1 = !m_SlotIcon && !m_CargoSlotsIcon;
513  bool b2 = (!m_SlotIcon || !m_SlotIcon.IsVisible()) && m_CargoSlotsIcon && m_CargoSlotsIcon.IsVisible();
514  m_CollapsibleHeader.SetHeaderVisible(b1 || b2);
515  }
516  super.OnHide();
517  }
518 
519  override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
520  {
521  if (m_OpenedContainers.Count() > m_ActiveIndex)
522  {
524  SlotsIcon icon = GetFocusedSlotsIcon();
525 
526  if (icon)
527  {
528  c = ClosableContainer.Cast(icon.GetContainer());
529  }
530 
531  if (c && c.IsDisplayable())
532  {
533  return true;
534  }
535  }
536 
537  return false;
538  }
539 
540  override bool CanSplitEx(EntityAI focusedEntity)
541  {
542  return false;
543  }
544 }
SlotsContainer
Definition: slotscontainer.c:1
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
StaticGUIUtils
Definition: staticguiutils.c:1
y
Icon y
IsEmpty
override bool IsEmpty()
Definition: fireplacebase.c:2454
ITEMS_IN_ROW
const int ITEMS_IN_ROW
Definition: attachments.c:1
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
AttachmentCategoriesRow
Definition: attachmentcategoriesrow.c:1
AttachmentCategoriesContainer
Definition: attachmentcategoriescontainer.c:1
map
map
Definition: controlsxboxnew.c:3
AttachmentCategoriesSlotsContainer
Definition: attachmentcategoriesslotscontainer.c:1
ColorManager
Definition: colormanager.c:1
Container
Definition: cargocontainer.c:2
SlotsIcon
Definition: slotsicon.c:1
ItemManager
Definition: itemmanager.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
ItemPreviewWidget
Definition: gameplay.c:275
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
CollapsibleContainer
Definition: collapsiblecontainer.c:1
OnShow
override void OnShow()
Definition: controlsxbox.c:349
Widget
Definition: enwidgets.c:189
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5
ClosableContainer
Definition: containerwithcargo.c:1
m_Entity
EntityAI m_Entity
Definition: actiondebug.c:11
WidgetEventHandler
Definition: widgeteventhandler.c:1