Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
attachmentcategoriesrow.c
Go to the documentation of this file.
2 {
3  protected string m_CategoryIdentifier;
4  protected string m_RowConfigPath;
5  protected bool m_Refreshing;
6 
7  protected ref AttachmentsGroupContainer m_AttachmentsContainer;
8  protected ref map<int, ref ContainerWithCargo> m_AttachmentCargos;
9 
10  void AttachmentCategoriesRow( LayoutHolder parent, int sort = -1 )
11  {
12  m_Refreshing = false;
13  m_AttachmentCargos = new map<int, ref ContainerWithCargo>;
14  m_AttachmentsContainer = new AttachmentsGroupContainer(this);
15 
16  m_Body.Insert(m_AttachmentsContainer);
17 
18  m_ClosableHeader.GetMainWidget().ClearFlags( WidgetFlags.DRAGGABLE );
19 
20  RecomputeOpenedContainers();
21  }
22 
23  string GetCategoryIdentifier()
24  {
25  return m_CategoryIdentifier;
26  }
27 
28  int GetFocusedSlot()
29  {
30  SlotsIcon icon = GetFocusedSlotsIcon();
31  if (icon)
32  {
33  return icon.GetSlotID();
34  }
35  return -1;
36  }
37 
38  override bool Select()
39  {
40  Man player = GetGame().GetPlayer();
41  SlotsIcon focused_icon = GetFocusedSlotsIcon();
42  EntityAI focused_item = GetFocusedItem();
43  Container focused_cont = GetFocusedContainer();
44  ItemBase selected_item = ItemBase.Cast( ItemManager.GetInstance().GetSelectedItem() ); // == dragged item
45 
46  if( selected_item && focused_item != selected_item)//dropping from micromanagement
47  {
48  if( selected_item.GetInventory().CanRemoveEntity() )
49  {
50  int stack_max;
51 
52  if (!focused_icon)
53  {
54  if (focused_cont)
55  {
56  focused_cont.Select();
57  }
58  }
59  else if( !focused_item && m_Entity && m_Entity.GetInventory().CanAddAttachmentEx( selected_item, focused_icon.GetSlotID() ) )
60  {
61  stack_max = InventorySlots.GetStackMaxForSlotId( focused_icon.GetSlotID() );
62  float quantity = selected_item.GetQuantity();
63  if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
64  {
65  player.PredictiveTakeEntityToTargetAttachmentEx( m_Entity, selected_item, focused_icon.GetSlotID() );
66  return true;
67  }
68  else
69  {
70  selected_item.SplitIntoStackMaxClient( m_Entity, focused_icon.GetSlotID() );
71  return true;
72  }
73  }
74  else if (focused_icon.GetSlotID() != -1)
75  {
76  if (focused_item && focused_item.GetHierarchyParent() && focused_item.GetHierarchyParent().GetInventory().CanAddAttachment(selected_item))
77  {
79  focused_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
80  stack_max = InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
81  quantity = focused_item.GetQuantity();
82  if( focused_item.CanBeCombined( ItemBase.Cast( selected_item ) ) )
83  {
84  focused_item.CombineItemsClient( selected_item, true );
85  return true;
86  }
87  else if( stack_max == 0 && GameInventory.CanSwapEntitiesEx( focused_item, selected_item ) )
88  {
89  player.PredictiveSwapEntities( selected_item, focused_item );
90  return true;
91  }
92  else if( m_AttachmentCargos.Contains( inv_loc.GetSlot() ) )
93  {
94  if( focused_item.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo() ) )
95  {
96  SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( player ), focused_item, selected_item );
97  return true;
98  }
99  }
100  }
101  }
102  }
103  }
104  else //clicking
105  {
106  if( focused_item && focused_item.GetInventory().CanRemoveEntity() && (!focused_icon || !focused_icon.IsOutOfReach()) )
107  {
108  EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
109  if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
110  {
111  if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
112  {
113  player.PredictiveSwapEntities( item_in_hands, focused_item );
114  return true;
115  }
116  }
117  else
118  {
119  if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
120  {
121  player.PredictiveTakeEntityToHands( focused_item );
122  return true;
123  }
124  }
125  }
126  }
127 
128  return false;
129  }
130 
131  override bool TransferItem()
132  {
133  if (CanTakeToInventory())
134  {
135  EntityAI entity = GetFocusedItem();
136  SlotsIcon focused_icon = GetFocusedSlotsIcon();
137  if( entity && !entity.IsLockedInSlot() && (!focused_icon || !focused_icon.IsOutOfReach()) )
138  {
139  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
140  GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, entity );
141  return true;
142  }
143  }
144  return false;
145  }
146 
147  override bool TransferItemToVicinity()
148  {
149  if (CanDrop())
150  {
151  ItemBase item = ItemBase.Cast(GetFocusedItem());
152  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
153  SlotsIcon focused_icon = GetFocusedSlotsIcon();
154 
155  if (item && !item.IsLockedInSlot() && (focused_icon && !focused_icon.IsOutOfReach()))
156  {
157  if (item.GetTargetQuantityMax() < item.GetQuantity())
158  item.SplitIntoStackMaxClient( null, -1 );
159  else
160  player.PhysicalPredictiveDropItem( item );
161  return true;
162  }
163  }
164  return false;
165  }
166 
167  override bool Combine()
168  {
169  if (CanCombine())
170  {
171  Man player = GetGame().GetPlayer();
172  ItemBase prev_item = ItemBase.Cast( GetFocusedItem() );
173  ItemBase selected_item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
174  SlotsIcon focused_icon = GetFocusedSlotsIcon();
175 
176  if( selected_item )
177  {
178  int selected_slot = GetFocusedSlot();
179  int stack_max;
180  if( selected_item && selected_item.GetInventory().CanRemoveEntity() && (focused_icon && !focused_icon.IsOutOfReach()) )
181  {
182  if( !prev_item && m_Entity.GetInventory().CanAddAttachmentEx( selected_item, selected_slot ) )
183  {
184  stack_max = InventorySlots.GetStackMaxForSlotId( selected_slot );
185  float quantity = selected_item.GetQuantity();
186  if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
187  {
188  player.PredictiveTakeEntityToTargetAttachmentEx( m_Entity, selected_item, selected_slot );
189  return true;
190  }
191  else
192  {
193  selected_item.SplitIntoStackMaxClient( m_Entity, selected_slot );
194  return true;
195  }
196  }
197  else if( selected_slot != -1 )
198  {
199  if( prev_item )
200  {
201  InventoryLocation inv_loc = new InventoryLocation;
202  prev_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
203  stack_max = InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
204  quantity = prev_item.GetQuantity();
205  if( prev_item.CanBeCombined( ItemBase.Cast( selected_item ) ) )
206  {
207  prev_item.CombineItemsClient( selected_item, true );
208  return true;
209  }
210  else if( stack_max == 0 && GameInventory.CanSwapEntitiesEx( prev_item, selected_item ) )
211  {
212  player.PredictiveSwapEntities( selected_item, prev_item );
213  return true;
214  }
215  else if( m_AttachmentCargos.Contains( inv_loc.GetSlot() ) )
216  {
217  if( prev_item.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo() ) )
218  {
219  SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( player ), prev_item, selected_item );
220  return true;
221  }
222  }
223  }
224  }
225  }
226  }
227  }
228  return false;
229  }
230 
231  override bool CanSplitEx(EntityAI focusedItem)
232  {
233  return false;
234  }
235 
236  override bool SplitItem()
237  {
238  return false;
239  }
240 
241  override bool EquipItem() //TODO: may be possible, but the hint doesn't reflect it anyway
242  {
243  return false;
244  }
245 
246  override bool CanCombine()
247  {
248  Man player = GetGame().GetPlayer();
249  ItemBase prev_item = ItemBase.Cast( GetFocusedItem() );
250  ItemBase selected_item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
251  SlotsIcon focused_icon = GetFocusedSlotsIcon();
252 
253  if( selected_item )
254  {
255  int selected_slot = GetFocusedSlot();
256  int stack_max;
257  if( selected_item && selected_item.GetInventory().CanRemoveEntity() && (focused_icon && !focused_icon.IsOutOfReach()) )
258  {
259  if( m_Entity.GetInventory().CanAddAttachmentEx( selected_item, selected_slot ) )
260  {
261  stack_max = InventorySlots.GetStackMaxForSlotId( selected_slot );
262  float quantity = selected_item.GetQuantity();
263  if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
264  {
265  return true;
266  }
267  else
268  {
269  return true;
270  }
271  }
272  else if( selected_slot != -1 )
273  {
274  if( prev_item )
275  {
276  InventoryLocation inv_loc = new InventoryLocation;
277  prev_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
278  stack_max = InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
279  quantity = prev_item.GetQuantity();
280  if( prev_item.CanBeCombined( ItemBase.Cast( selected_item ) ) )
281  {
282  return true;
283  }
284  }
285  }
286  }
287  }
288  return false;
289  }
290 
291  override bool CanCombineAmmo()
292  {
293  return false;
294  }
295 
296  override bool IsItemActive()
297  {
298  SlotsIcon icon = GetFocusedSlotsIcon();
299  return GetFocusedItem() != null && (!icon || !icon.IsOutOfReach());
300  }
301 
302  override bool IsItemWithQuantityActive()
303  {
304  ItemBase item = ItemBase.Cast(GetFocusedItem());
305  SlotsIcon icon = GetFocusedSlotsIcon();
306  return item && ( !icon || !icon.IsOutOfReach()) && item.CanBeSplit();
307  }
308 
309  override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
310  {
311  ItemManager.GetInstance().HideDropzones();
312  ItemManager.GetInstance().SetIsDragging( false );
313  SlotsIcon slots_icon;
314  EntityAI receiver_item;
315  int slot_id = -1;
316  bool is_reserved = false;
317  EntityAI attached_entity;
318  receiver.GetUserData(slots_icon);
319  float stackable = 0.0;
321 
322  if( slots_icon )
323  {
324  receiver_item = slots_icon.GetEntity();
325  slot_id = slots_icon.GetSlotID();
326  attached_entity = slots_icon.GetSlotParent();
327  is_reserved = slots_icon.IsReserved();
328  }
329 
330  EntityAI item = GetItemPreviewItem( w );
331  if( !item )
332  {
333  return;
334  }
335  ItemBase item_base = ItemBase.Cast( item );
336 
337  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
338  if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
339  return;
340 
341  EntityAI target_att_entity = m_Entity;
342  Weapon_Base wpn;
343  Magazine mag;
344  if( Class.CastTo(wpn, m_Entity ) && Class.CastTo(mag, item ) )
345  {
346  if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
347  {
348  player.GetWeaponManager().AttachMagazine( mag );
349  }
350  }
351  else if( receiver_item && !is_reserved )
352  {
353  if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
354  {
355  ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
356  }
357  else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
358  {
359  if( !receiver_item.GetInventory().CanRemoveEntity() )
360  return;
361  GetGame().GetPlayer().PredictiveSwapEntities( receiver_item, item );
362  }
363  else if( receiver_item.GetInventory().CanAddAttachment( item ) )
364  {
365  player.PredictiveTakeEntityToTargetAttachment(receiver_item, item);
366  }
367  }
368  else if( attached_entity && slot_id != -1 && attached_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
369  {
370  item_base = ItemBase.Cast( item );
371  stackable = item_base.GetTargetQuantityMax( slot_id );
372 
373  if( stackable == 0 || stackable >= item_base.GetQuantity() )
374  {
375  player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, slot_id);
376  }
377  else if( stackable != 0 && stackable < item_base.GetQuantity() )
378  {
379  item_base.SplitIntoStackMaxClient( m_Entity, slot_id );
380  }
381  }
382  else if(attached_entity && slot_id == -1 && attached_entity.GetInventory().FindFreeLocationFor(item,FindInventoryLocationType.ATTACHMENT,il))
383  {
384  item_base = ItemBase.Cast( item );
385  stackable = item_base.GetTargetQuantityMax( il.GetSlot() );
386 
387  if( stackable == 0 || stackable >= item_base.GetQuantity() )
388  {
389  player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, il.GetSlot());
390  }
391  else if( stackable != 0 && stackable < item_base.GetQuantity() )
392  {
393  item_base.SplitIntoStackMaxClient( m_Entity, il.GetSlot() );
394  }
395  }
396  /*else if( ( m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && ( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item )) ) )
397  {
398  SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
399  }*/
400  }
401 
402  override void UnfocusAll()
403  {
404  int i;
405  for ( i = 1; i < Count(); i++ )
406  {
407  for ( int j = 0; j < ITEMS_IN_ROW; j++ )
408  {
409  Widget w = Get( i ).GetMainWidget().FindAnyWidget( "Cursor" + j );
410  if( w )
411  w.Show( false );
412  }
413  }
414  for ( i = 0; i < m_AttachmentCargos.Count(); i++ )
415  {
416  m_AttachmentCargos.GetElement( i ).Unfocus();
417  m_AttachmentCargos.GetElement( i ).SetActive( false );
418  }
419  }
420 
421  override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
422  {
423  if( w == null )
424  {
425  return;
426  }
427  ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
428  if(!iw)
429  {
430  string name = w.GetName();
431  name.Replace("PanelWidget", "Render");
432  iw = ItemPreviewWidget.Cast( w.FindAnyWidget(name) );
433  }
434  if(!iw)
435  {
436  iw = ItemPreviewWidget.Cast( w );
437  }
438 
439  if( !iw || !iw.GetItem() || (iw.GetItem() == m_Entity) )
440  {
441  return;
442  }
443 
444  ItemBase item;
445  ItemBase receiver_item;
446  name = receiver.GetName();
447  name.Replace("PanelWidget", "Render");
448  ItemPreviewWidget receiver_iw = ItemPreviewWidget.Cast( receiver.FindAnyWidget(name) );
449  if(receiver_iw)
450  receiver_item = ItemBase.Cast( receiver_iw.GetItem() );
451 
452  SlotsIcon slots_icon;
453  receiver.GetUserData(slots_icon);
454 
455  if( receiver_item )
456  {
457  int stack_max = InventorySlots.GetStackMaxForSlotId( receiver_item.GetInventory().GetSlotId(0) );
458  //int quantity = receiver_item.GetQuantity();
459  //bool combinable = ( quantity < stack_max ) && ( ItemBase.Cast( receiver_item ).CanBeCombined( ItemBase.Cast( iw.GetItem() ) ) );
460  if( receiver_item.CanBeCombined( ItemBase.Cast( iw.GetItem() ) ) )
461  {
462  ItemManager.GetInstance().HideDropzones();
463  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
464  ColorManager.GetInstance().SetColor( w, ColorManager.COMBINE_COLOR );
465  }
466  else if( stack_max == 0 && GameInventory.CanSwapEntitiesEx( receiver_item, iw.GetItem() ) )
467  {
468  ItemManager.GetInstance().HideDropzones();
469  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
470  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
471  }
472  else
473  {
474  ItemManager.GetInstance().ShowSourceDropzone( iw.GetItem() );
475  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
476  }
477  }
478  else if( slots_icon && slots_icon.GetSlotID() != -1 )
479  {
480  item = ItemBase.Cast( iw.GetItem() );
481 
482  if( item && m_Entity.GetInventory().CanAddAttachmentEx( item, slots_icon.GetSlotID() ) )
483  {
484  ItemManager.GetInstance().HideDropzones();
485  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
486  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
487  }
488  else
489  {
490  ItemManager.GetInstance().ShowSourceDropzone( iw.GetItem() );
491  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
492  }
493  }
494  else
495  {
496  ItemManager.GetInstance().ShowSourceDropzone( iw.GetItem() );
497  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
498  }
499  }
500 
501  bool DraggingOverGrid( Widget w, int x, int y, Widget reciever, CargoContainer cargo )
502  {
503  if( w == null )
504  {
505  return false;
506  }
507 
508  EntityAI item = GetItemPreviewItem( w );
509 
510  if( !item )
511  {
512  return false;
513  }
514 
515  int color;
516  int idx = 0;
517  int c_x, c_y;
518 
519  EntityAI target_entity;
520  CargoBase target_cargo;
521 
522  target_entity = cargo.GetEntity() ;
523  if( target_entity )
524  {
525  target_cargo = target_entity.GetInventory().GetCargo();
526  }
527  else
528  return false;
529 
530  if( target_cargo && target_entity )
531  {
532  c_x = target_cargo.GetHeight();
533  c_y = target_cargo.GetWidth();
534  }
535  else
536  return false;
537 
538  if( c_x > x && c_y > y && target_entity.GetInventory().CanAddEntityInCargoEx( item, idx, x, y, item.GetInventory().GetFlipCargo() ) )
539  {
540  color = ColorManager.GREEN_COLOR;
541  }
542  else
543  {
544  color = ColorManager.RED_COLOR;
545  }
546 
547  if( w.FindAnyWidget("Cursor") )
548  {
549  w.FindAnyWidget("Cursor").SetColor( color );
550  }
551  else
552  {
553  string name = w.GetName();
554  name.Replace( "PanelWidget", "Cursor" );
555  if( w.FindAnyWidget( name ) )
556  {
557  w.FindAnyWidget( name ).SetColor( color );
558  }
559  }
560 
561  return true;
562  }
563 
564  void DropReceived( Widget w, int x, int y, CargoContainer cargo )
565  {
566  EntityAI item = GetItemPreviewItem( w );
567  if( !item )
568  {
569  return;
570  }
571 
572  int idx = 0;
573  int c_x, c_y;
574 
575  EntityAI target_entity;
576  CargoBase target_cargo;
577 
578  target_entity = cargo.GetEntity();
579  if( target_entity )
580  {
581  target_cargo = target_entity.GetInventory().GetCargo();
582  }
583  else
584  return;
585 
586  if( target_cargo && target_entity )
587  {
588  c_x = target_cargo.GetHeight();
589  c_y = target_cargo.GetWidth();
590  }
591  else
592  return;
593 
595  dst.SetCargoAuto(target_cargo, item, x, y, item.GetInventory().GetFlipCargo());
596 
597  if( c_x > x && c_y > y && target_entity.GetInventory().LocationCanAddEntity(dst))
598  {
599  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
600 
601  SplitItemUtils.TakeOrSplitToInventoryLocation( player, dst);
602 
603  Icon icon = cargo.GetIcon( item );
604 
605  if( icon )
606  {
607  icon.GetCursorWidget().SetColor( ColorManager.BASE_COLOR );
608  icon.RefreshPos( x, y );
609  icon.Refresh();
610  Refresh();
611  }
612  }
613  }
614 
615  EntityAI GetItemPreviewItem( Widget w )
616  {
617  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
618  if( !ipw )
619  {
620  string name = w.GetName();
621  name.Replace( "PanelWidget", "Render" );
622  ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
623  }
624  if( !ipw )
625  {
626  ipw = ItemPreviewWidget.Cast( w );
627  }
628  if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
629  {
630  return null;
631  }
632  return ipw.GetItem();
633  }
634 
635  override void Refresh()
636  {
637  if (!m_Refreshing)
638  {
639  if( !m_Closed )
640  {
641  super.Refresh();
642  RefreshAllSlots();
643  }
644  }
645  }
646 
647  void RefreshAllSlots()
648  {
649  m_Refreshing = true;
650  int row_count = m_AttachmentsContainer.GetRowCount();
651  int row;
652  for (row = 0; row < row_count; row++)
653  {
654  int col_count = m_AttachmentsContainer.GetColumnCountForRow(row);
655  int col;
656  for (col = 0; col < col_count; col++)
657  {
658  RefreshSlot(row, col, -1, "");
659  }
660  }
661  m_Refreshing = false;
662  }
663 
664  //slot_id and slot_name parametr is not used
665  void RefreshSlot( int row, int column, int slot_id, string slot_name )
666  {
667  SlotsIcon icon = m_AttachmentsContainer.GetSlotsIcon(row, column);
668  int slot_id_ = icon.GetSlotID();
669  EntityAI item = m_Entity.GetInventory().FindAttachment( slot_id_ );
670  ContainerWithCargo cont;
671 
672  if (!m_Entity.CanDisplayAttachmentSlot(slot_id_))
673  {
674  icon.Clear();
675  icon.GetMainWidget().Show( false );
676  }
677  else if (!item)
678  {
679  if (icon.GetEntity())
680  {
681  icon.ClearRemainSelected();
682 
683  cont = m_AttachmentCargos.Get(slot_id_);
684  if (cont)
685  {
686  m_AttachmentCargos.Remove(slot_id_);
687  this.Remove(cont);
688  ( Container.Cast( cont.m_Parent ) ).Remove( cont );
689  }
690  }
691  icon.GetMainWidget().Show(true);
692  }
693  else
694  {
695  icon.GetMainWidget().Show( true );
696  if (icon.GetEntity() != item)
697  {
698  icon.Init( item );
699  }
700  else
701  {
702  icon.Refresh();
703  }
704 
705  cont = m_AttachmentCargos.Get(slot_id_);
706  if( cont && cont.GetEntity() != item)
707  {
708  m_AttachmentCargos.Remove(slot_id_);
709  ( Container.Cast( cont.m_Parent ) ).Remove( cont );
710  this.Remove(cont);
711  cont = null;
712  }
713 
714  if( !cont )
715  {
716  if( item.GetInventory().GetCargo() && m_AttachmentCargos )
717  {
718  cont = new ContainerWithCargo( this, true );
719  cont.GetRootWidget().SetSort( m_AttachmentCargos.Count() + 10 );
720  cont.SetEntity( item );
721  cont.SetSlotIcon( icon );
722 
723  m_AttachmentCargos.Insert( slot_id_, cont );
724  icon.SetContainer(cont);
725 
726  SetOpenForSlotIcon(cont.IsOpened(),icon);
727  }
728  }
729 
730  if (cont)
731  {
732  icon.GetRadialIconPanel().Show( cont.IsDisplayable() );
733  }
734 
735  string slot_name_ = InventorySlots.GetSlotName(slot_id_);
736  bool draggable = true;
737  bool can_be_removed = item.GetInventory().CanRemoveEntity();
738  bool in_hands_condition = m_Entity.GetHierarchyRoot() == GetGame().GetPlayer();
739  bool in_vicinity_condition = AttachmentsOutOfReach.IsAttachmentReachable( m_Entity, slot_name_ );
740  if( m_Entity.GetInventory().GetSlotLock( slot_id_ ) && ItemManager.GetInstance().GetDraggedItem() != item )
741  {
742  icon.GetMountedWidget().Show( true );
743  draggable = false;
744  }
745  else
746  {
747  icon.GetMountedWidget().Show( false );
748  }
749 
750  if( !m_Entity.CanReleaseAttachment( item ) )
751  {
752  draggable = false;
753  }
754 
755  if ((in_hands_condition || in_vicinity_condition) && can_be_removed)
756  {
757  icon.GetOutOfReachWidget().Show( false );
758  }
759  else
760  {
761  icon.GetOutOfReachWidget().Show( true );
762  draggable = false;
763  }
764 
765  if( draggable )
766  {
767  icon.GetRender().GetParent().SetFlags( WidgetFlags.DRAGGABLE );
768  }
769  else
770  {
771  icon.GetRender().GetParent().ClearFlags( WidgetFlags.DRAGGABLE );
772  }
773  }
774  }
775 
776  void DoubleClick(Widget w, int x, int y, int button)
777  {
778  if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
779  {
780  ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
781  if (!iw)
782  {
783  string name = w.GetName();
784  name.Replace("PanelWidget", "Render");
785  iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
786  }
787 
788  if (!iw)
789  iw = ItemPreviewWidget.Cast(w);
790 
791  SlotsIcon icon;
792  w.GetUserData(icon);
793 
794  if (icon && m_Entity.GetInventory().GetSlotLock(iw.GetUserID()))
795  return;
796 
797  if (icon.IsOutOfReach())
798  return;
799 
800  ItemBase item = ItemBase.Cast(iw.GetItem());
801  if (item)
802  {
803  if (!item.GetInventory().CanRemoveEntity())
804  return;
805 
806  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
807  if (controlledPlayer.GetInventory().HasEntityInInventory(item) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
808  {
809  controlledPlayer.PredictiveTakeEntityToHands(item);
810  }
811  else
812  {
813  if (controlledPlayer.GetInventory().CanAddEntityToInventory(item) && item.GetInventory().CanRemoveEntity())
814  {
815  if (item.GetTargetQuantityMax() < item.GetQuantity())
816  item.SplitIntoStackMaxClient(controlledPlayer, -1);
817  else
818  controlledPlayer.PredictiveTakeEntityToInventory(FindInventoryLocationType.ANY, item);
819  }
820  else
821  {
822  if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
823  {
824  if (item.GetTargetQuantityMax() < item.GetQuantity())
825  item.SplitIntoStackMaxHandsClient(controlledPlayer);
826  else
827  controlledPlayer.PredictiveTakeEntityToHands(item);
828  }
829  }
830  }
831 
832  HideOwnedTooltip();
833 
834  name = w.GetName();
835  name.Replace("PanelWidget", "Temperature");
836  w.FindAnyWidget(name).Show(false);
837  }
838  }
839  }
840 
841  void MouseClick(Widget w, int x, int y, int button)
842  {
843  ItemBase selectedItem;
844  SlotsIcon icon;
845  w.GetUserData(icon);
846  if (icon)
847  selectedItem = ItemBase.Cast(icon.GetEntity());
848 
849  if (selectedItem)
850  {
851  switch (button)
852  {
853  case MouseState.RIGHT:
854  #ifdef DIAG_DEVELOPER
855  if (g_Game.IsLeftCtrlDown())
856  ShowActionMenu(selectedItem);
857  #endif
858 
859  break;
860 
861  case MouseState.MIDDLE:
862  InspectItem(selectedItem);
863  break;
864 
865  case MouseState.LEFT:
866  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
867  if (g_Game.IsLeftCtrlDown())
868  {
869  if (icon.IsOutOfReach())
870  return;
871 
872  if (controlledPlayer.CanDropEntity(selectedItem))
873  {
874  if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
875  selectedItem.SplitIntoStackMaxClient(null, -1);
876  else
877  controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
878  }
879  else
880  {
881  bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem, null ) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
882  ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
883  }
884  }
885  else
886  {
887  ClosableContainer c = ClosableContainer.Cast(icon.GetContainer());
888  if (c)
889  c.Toggle();
890  }
891 
892  break;
893  }
894  }
895  }
896 
897  void Init(int attachments_categories_count, int i, string attachment_category, string config_path_attachment_categories, EntityAI entity, int parent_m_Body_count )
898  {
899  m_Entity = entity;
900  Header header = GetHeader();
901 
902  m_CategoryIdentifier = attachment_category;
903 
904  array<string> player_ghosts_slots2 = new array<string>();
905  string categoryName;
906 
907  m_RowConfigPath = config_path_attachment_categories + " " + attachment_category + " attachmentSlots";
908  string config_path_category_name = config_path_attachment_categories + " " + attachment_category + " name";
909  GetGame().ConfigGetTextArray(m_RowConfigPath, player_ghosts_slots2);
910  GetGame().ConfigGetText(config_path_category_name, categoryName);
911  header.SetName(categoryName);
912 
913  m_AttachmentsContainer.SetHeader(header);
914  SetHeader(null);
915 
916  int count = player_ghosts_slots2.Count();
917  int lastRow = count / ITEMS_IN_ROW;
918  SlotsContainer slotsContainer;
919 
920  for ( int j = 0; j < count; j++ )
921  {
922  string slotName = player_ghosts_slots2.Get(j);
923  string iconName; //must be in format "set:<setname> image:<imagename>"
924  string path = "CfgSlots" + " Slot_" + slotName;
925 
926  int slotId = InventorySlots.GetSlotIdFromString(slotName);
927 
928  GetGame().ConfigGetText(path + " ghostIcon", iconName);
929  GetGame().ConfigGetText(path + " name", slotName);
930 
931  int row = j / ITEMS_IN_ROW;
932  int column = j % ITEMS_IN_ROW;
933  if (column == 0)
934  {
935  slotsContainer = new SlotsContainer(m_AttachmentsContainer, m_Entity);
936  slotsContainer.GetRootWidget().SetAlpha(0.7);
937  if (row == lastRow)
938  slotsContainer.SetColumnCount(count % ITEMS_IN_ROW);
939  else
940  slotsContainer.SetColumnCount(ITEMS_IN_ROW);
941 
942  m_AttachmentsContainer.Insert(slotsContainer);
943  slotsContainer.GetRootWidget().SetSort(row);
944  }
945 
946  SlotsIcon icon = slotsContainer.GetSlotIcon(column);
947  WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetMainWidget(), this, "OnDropReceivedFromHeader");
948  WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetGhostSlot(), this, "OnDropReceivedFromHeader");
949  WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetPanelWidget(), this, "OnDropReceivedFromHeader");
950 
951  WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetMainWidget(), this, "DraggingOverHeader");
952  WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetGhostSlot(), this, "DraggingOverHeader");
953  WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetPanelWidget(), this, "DraggingOverHeader");
954 
955  WidgetEventHandler.GetInstance().RegisterOnDrop(icon.GetMainWidget(), this, "OnIconDrop");
956  WidgetEventHandler.GetInstance().RegisterOnDrop(icon.GetPanelWidget(), this, "OnIconDrop");
957 
958  WidgetEventHandler.GetInstance().RegisterOnDoubleClick(icon.GetPanelWidget(), this, "DoubleClick");
959  WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(), this, "MouseClick");
960 
961  icon.GetGhostSlot().LoadImageFile(0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY, iconName));
962  icon.SetSlotID(slotId);
963  icon.SetSlotDisplayName(InventorySlots.GetSlotDisplayName(slotId));
964 
965  icon.Clear();
966  }
967  RefreshAllSlots();
968  }
969 
970  override void UpdateInterval()
971  {
972  super.UpdateInterval();
973  RefreshAllSlots();
974  }
975 }
ItemBase
Definition: inventoryitem.c:730
SlotsContainer
Definition: slotscontainer.c:1
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
Remove
void Remove(Object object)
Definition: actiontargets.c:95
StaticGUIUtils
Definition: staticguiutils.c:1
y
Icon y
AttachmentsOutOfReach
Definition: attachmentsoutofreach.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ITEMS_IN_ROW
const int ITEMS_IN_ROW
Definition: attachments.c:1
SplitItemUtils
Definition: splititemutils.c:1
AttachmentCategoriesRow
Definition: attachmentcategoriesrow.c:1
CombineItemsClient
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition: itembase.c:849
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
Header
Definition: header.c:1
GetHeader
string GetHeader()
Definition: errorproperties.c:76
ColorManager
Definition: colormanager.c:1
CargoBase
represents base for cargo storage for entities
Definition: cargo.c:6
Container
Definition: cargocontainer.c:2
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
slotName
PlayerSpawnPreset slotName
SlotsIcon
Definition: slotsicon.c:1
ItemManager
Definition: itemmanager.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
AttachmentsGroupContainer
Definition: attachmentsgroupcontainer.c:1
Get
array< ref PlayerStatBase > Get()
Definition: playerstatspco.c:103
MouseState
MouseState
Definition: ensystem.c:310
array< string >
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Icon
Definition: icon.c:1
ItemPreviewWidget
Definition: gameplay.c:275
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
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
Count
@ Count
Definition: randomgeneratorsyncmanager.c:7
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
WidgetEventHandler
Definition: widgeteventhandler.c:1
path
string path
Definition: optionselectormultistate.c:135