Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
containerwithcargoandattachments.c
Go to the documentation of this file.
1 class ContainerWithCargoAndAttachments extends ClosableContainer
2 {
3  protected ref Attachments m_Atts;
4  protected ref CargoContainer m_CargoGrid;
5 
6  protected ref map<EntityAI, ref CargoContainer> m_AttachmentCargos;
7  protected ref map<EntityAI, ref AttachmentsWrapper> m_AttachmentAttachmentsContainers;
8  protected ref map<EntityAI, ref Attachments> m_AttachmentAttachments;
9  protected ref array<int> m_AttachmentSlotsSorted;
10 
11  void ContainerWithCargoAndAttachments( LayoutHolder parent, int sort = -1 )
12  {
13  WidgetEventHandler.GetInstance().RegisterOnDraggingOver( m_MainWidget, this, "DraggingOverHeader2" );
14  }
15 
16  void ~ContainerWithCargoAndAttachments()
17  {
18  if ( m_Entity )
19  {
20  m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
21  m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
22  }
23 
24  if ( m_Atts )
25  delete m_Atts;
26 
27  foreach ( EntityAI e, Attachments att : m_AttachmentAttachments )
28  {
29  delete att;
30  }
31 
32  if ( m_AttachmentAttachments )
33  m_AttachmentAttachments.Clear();
34 
35  if ( m_AttachmentAttachmentsContainers )
36  m_AttachmentAttachmentsContainers.Clear();
37 
38  if ( m_AttachmentCargos )
39  m_AttachmentCargos.Clear();
40  }
41 
42  void RecomputeContainers()
43  {
44  m_Body.Clear();
45 
46  if(m_Atts)
47  {
48  m_Body.Insert(m_Atts.GetWrapper());
49  }
50 
51  if(m_CargoGrid)
52  {
53  m_Body.Insert(m_CargoGrid);
54  }
55 
56  GameInventory inv = m_Entity.GetInventory();
57  for (int i = 0; i < inv.AttachmentCount(); i++)
58  {
59  EntityAI ent = inv.GetAttachmentFromIndex(i);
60  if(ent)
61  {
62  AttachmentsWrapper att = m_AttachmentAttachmentsContainers.Get(ent);
63  if(att)
64  {
65  m_Body.Insert(att);
66  }
67 
68  CargoContainer cargo = m_AttachmentCargos.Get(ent);
69  if(cargo)
70  {
71  m_Body.Insert(cargo);
72  }
73  }
74  }
75  }
76 
77  void AttachmentAddedEx(EntityAI item, string slot, EntityAI parent, bool immedUpdate = true)
78  {
79  int slot_id = InventorySlots.GetSlotIdFromString( slot );
80  int sort = -1;
81  bool updateNeeded = false;
82  ref Attachments att_cont = null;
83  ref CargoContainer cont = null;
84 
85  if ( item.GetInventory().GetAttachmentSlotsCount() > 0 && item.CanDisplayAnyAttachmentSlot() )
86  {
87  updateNeeded = true;
88 
89  att_cont = new Attachments( this, item );
90  sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_ATTACHMENTS_NEXT_OFFSET;
91  att_cont.InitAttachmentGrid( sort );
92 
93  m_AttachmentAttachments.Insert( item, att_cont );
94  m_AttachmentAttachmentsContainers.Insert( item, att_cont.GetWrapper() );
95 
96  att_cont.UpdateInterval();
97  }
98 
99  if ( item.GetInventory().GetCargo() )
100  {
101  updateNeeded = true;
102 
103  cont = new CargoContainer( this, true );
104  sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_CARGO_NEXT_OFFSET;
105  cont.GetRootWidget().SetSort( sort );
106  cont.SetEntity( item, false );
107  Insert( cont, m_Atts.GetAttachmentHeight() + m_AttachmentCargos.Count() + 1 );
108 
109  m_AttachmentCargos.Insert( item, cont );
110  }
111 
112  if (updateNeeded)
113  {
114  if (att_cont)
115  {
116  att_cont.ShowFalseAttachmentsHeader(true);
117  if (cont)
118  {
119  cont.ShowFalseCargoHeader(false);
120  cont.UpdateSize();
121  cont.SetAlternateFalseTextHeaderWidget(att_cont.GetFalseHeaderTextWidget());
122  }
123  }
124  else if (cont)
125  {
126  cont.SetAlternateFalseTextHeaderWidget(null); //just to be safe..
127  }
128 
129  RecomputeContainers();
130  RecomputeOpenedContainers();
131 
132  Inventory.GetInstance().UpdateConsoleToolbar();
133 
134  if (m_Parent && immedUpdate)
135  m_Parent.Refresh();
136  }
137  }
138 
139  void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
140  {
141  AttachmentAddedEx(item, slot, parent);
142  }
143 
144  void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
145  {
146  int slot_id = InventorySlots.GetSlotIdFromString( slot );
147 
148  CargoContainer old_cont = m_AttachmentCargos.Get( item );
149  if( old_cont )
150  {
151  m_AttachmentCargos.Remove( item );
152  delete old_cont;
153 
154  if( m_Parent )
155  m_Parent.Refresh();
156  Inventory.GetInstance().UpdateConsoleToolbar();
157  }
158 
159 
160  AttachmentsWrapper old_att_cont = m_AttachmentAttachmentsContainers.Get( item );
161  if( old_att_cont )
162  {
163  m_AttachmentAttachmentsContainers.Remove( item );
164  m_AttachmentAttachments.Remove( item );
165  delete old_att_cont;
166 
167  if( m_Parent )
168  m_Parent.Refresh();
169  Inventory.GetInstance().UpdateConsoleToolbar();
170  }
171 
172  RecomputeContainers();
173  RecomputeOpenedContainers();
174  }
175 
176  override void UpdateInterval()
177  {
178  if ( m_Entity )
179  {
180  if (m_CargoGrid)
181  {
182  bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
183  if (m_CargoGrid.IsVisible() && hideCargo)
184  {
185  HideCargo();
186  }
187  else if (!m_CargoGrid.IsVisible() && !hideCargo)
188  {
189  ShowCargo();
190  }
191 
192  m_CargoGrid.UpdateInterval();
193  }
194 
195  if ( m_SlotIcon )
196  {
197  bool hide = m_LockCargo || ItemManager.GetInstance().GetDraggedItem() == m_Entity;
198  if (!hide)
199  {
200  SetOpenForSlotIcon(IsOpened());
201  }
202  m_SlotIcon.GetRadialIconPanel().Show( !hide );
203 
204  }
205 
206  super.UpdateInterval();
207  }
208  }
209 
210  override EntityAI GetFocusedContainerEntity()
211  {
212  return m_Entity;
213  }
214 
215  override void UnfocusAll()
216  {
217  if( m_Atts )
218  {
219  m_Atts.UnfocusAll();
220  }
221 
222  if( m_CargoGrid )
223  {
224  m_CargoGrid.UnfocusAll();
225  }
226 
227  foreach( EntityAI e1, CargoContainer cargo : m_AttachmentCargos )
228  {
229  cargo.UnfocusAll();
230 
231  }
232 
233  foreach( EntityAI e2, Attachments att : m_AttachmentAttachments )
234  {
235  att.UnfocusAll();
236  }
237  }
238 
239  override bool IsLastIndex()
240  {
241  return m_ActiveIndex == ( m_OpenedContainers.Count() - 1 );
242  }
243 
244  override bool IsFirstContainerFocused()
245  {
246  return IsFirstIndex();
247  }
248 
249  override bool IsLastContainerFocused()
250  {
251  return IsLastIndex();
252  }
253 
254  override void MoveGridCursor( int direction )
255  {
256  Container c = GetFocusedContainer();
257  if ( c )
258  {
259  c.MoveGridCursor( direction );
260  Inventory.GetInstance().UpdateConsoleToolbar();
261  }
262  }
263 
264  void SetEntity( EntityAI entity, bool immedUpdate = true )
265  {
266  m_Entity = entity;
267 
268  m_Atts = new Attachments( this, m_Entity );
269  m_Atts.InitAttachmentGrid( SORT_ATTACHMENTS_OWN );
270  m_AttachmentSlotsSorted = m_Atts.GetSlotsSorted();
271 
272  m_Entity.GetOnItemAttached().Insert( AttachmentAdded );
273  m_Entity.GetOnItemDetached().Insert( AttachmentRemoved );
274 
275  m_ClosableHeader.SetItemPreview( m_Entity );
276  CheckHeaderDragability();
277 
278  if ( m_Entity.GetInventory().GetCargo() )
279  {
280  m_CargoGrid = new CargoContainer( this, false );
281  m_CargoGrid.GetRootWidget().SetSort( SORT_CARGO_OWN );
282  m_CargoGrid.SetEntity( m_Entity, 0, immedUpdate );
283  m_CargoGrid.UpdateHeaderText(); // TODO: refresh?
284  Insert( m_CargoGrid );
285  }
286  else
287  {
288  string name = m_Entity.GetDisplayName();
289  name.ToUpper();
290  m_ClosableHeader.SetName( name );
291  }
292 
293  m_AttachmentCargos = new map<EntityAI, ref CargoContainer>;
294  m_AttachmentAttachmentsContainers = new map<EntityAI, ref AttachmentsWrapper>;
295  m_AttachmentAttachments = new map<EntityAI, ref Attachments>;
296 
297  (Container.Cast( m_Parent )).Insert( this );
298 
299  foreach ( int slot_id : m_AttachmentSlotsSorted )
300  {
301  EntityAI item = m_Entity.GetInventory().FindAttachment( slot_id );
302  if ( item )
303  AttachmentAddedEx( item, InventorySlots.GetSlotName( slot_id ), m_Entity, false );
304  }
305 
306  RecomputeContainers();
307 
308  if (m_CargoGrid)
309  {
310  bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
311  if (m_CargoGrid.IsVisible() && hideCargo)
312  {
313  HideCargo();
314  }
315  else if (!m_CargoGrid.IsVisible() && !hideCargo)
316  {
317  ShowCargo();
318  }
319  }
320 
321  if( IsDisplayable() )
322  SetOpenState( true );
323  else
324  SetOpenState( false );
325 
326  if (immedUpdate)
327  m_Parent.m_Parent.Refresh();
328 
329  RecomputeOpenedContainers();
330  }
331 
332  void HideCargo()
333  {
334  if( m_CargoGrid )
335  {
336  if(m_CargoGrid.IsVisible())
337  {
338  m_CargoGrid.OnHide();
339  RecomputeOpenedContainers();
340  }
341  }
342  }
343 
344  void ShowCargo()
345  {
346  if( m_CargoGrid )
347  {
348  if(!m_CargoGrid.IsVisible())
349  {
350  m_CargoGrid.OnShow();
351  RecomputeOpenedContainers();
352  }
353  }
354  }
355 
357  {
358  return m_Entity;
359  }
360 
361  ItemPreviewWidget GetItemPreviewWidgetDragOrDrop( Widget w )
362  {
363  string name = w.GetName();
364  name.Replace( "PanelWidget", "Render" );
365  return ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
366  }
367 
368  EntityAI GetItemPreviewItem( Widget w )
369  {
370  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
371  if( !ipw )
372  {
373  string name = w.GetName();
374  name.Replace( "PanelWidget", "Render" );
375  ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
376  }
377  if( !ipw )
378  {
379  ipw = ItemPreviewWidget.Cast( w );
380  }
381  if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
382  {
383  return NULL;
384  }
385  return ipw.GetItem();
386  }
387 
388  Widget GetItemPreviewWidget( Widget w )
389  {
390  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
391  if( !ipw )
392  {
393  string name = w.GetName();
394  name.Replace( "PanelWidget", "Render" );
395  ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
396  }
397  if( !ipw )
398  {
399  ipw = ItemPreviewWidget.Cast( w );
400  }
401  return ipw;
402  }
403 
404  void MouseClick2(Widget w, int x, int y, int button)
405  {
406  SlotsIcon icon;
407  w.GetUserData(icon);
408 
409  ItemBase selectedItem;
410  if (icon)
411  selectedItem = ItemBase.Cast(icon.GetEntity());
412 
413  if (selectedItem)
414  {
415  bool isReserved = icon.IsReserved();
416 
417  switch (button)
418  {
419  case MouseState.RIGHT:
420  #ifdef DIAG_DEVELOPER
421  if (GetDayZGame().IsLeftCtrlDown())
422  ShowActionMenu(selectedItem);
423  #endif
424 
425  if (isReserved)
426  {
427  EntityAI attachmentParent = icon.GetSlotParent();
428  GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced(selectedItem);
429  attachmentParent.GetOnAttachmentReleaseLock().Invoke(selectedItem, icon.GetSlotID());
430  }
431 
432  break;
433 
434  case MouseState.MIDDLE:
435  if (!isReserved)
436  InspectItem(selectedItem);
437 
438  break;
439 
440  case MouseState.LEFT:
441  if (!isReserved)
442  {
443  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
444  if (g_Game.IsLeftCtrlDown())
445  {
446  if (controlledPlayer.CanDropEntity(selectedItem))
447  {
448  if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
449  selectedItem.SplitIntoStackMaxClient(null, -1);
450  else
451  controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
452  }
453  }
454  else
455  {
456  bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem, null ) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
457  ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
458  }
459  }
460 
461  break;
462  }
463  }
464  }
465 
467  void DropReceived(Widget w, int x, int y, CargoContainer cargo)
468  {
469  EntityAI item = GetItemPreviewItem(w);
470  if (!item)
471  return;
472 
473  #ifndef PLATFORM_CONSOLE
474  int c_x, c_y;
475  #endif
476 
477  EntityAI targetEntity = m_Entity;
478  CargoBase targetCargo;
479 
480  if (cargo != m_CargoGrid)
481  {
482  targetEntity = m_AttachmentCargos.GetKeyByValue(cargo);
483  }
484 
485  if (targetEntity)
486  {
487  targetCargo = targetEntity.GetInventory().GetCargo();
488  #ifdef PLATFORM_CONSOLE
489  if (m_CargoGrid && m_CargoGrid.HasItem(item))
490  return;
491  #endif
492  }
493 
494  if (!targetCargo || !targetEntity)
495  return;
496 
498  #ifdef PLATFORM_CONSOLE
499  x = 0;
500  y = targetCargo.GetItemCount();
501  targetEntity.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.CARGO, dst);
502  #else
503  c_x = targetCargo.GetHeight();
504  c_y = targetCargo.GetWidth();
505 
506  dst.SetCargoAuto(targetCargo, item, x, y, item.GetInventory().GetFlipCargo());
507  #endif
508 
510  item.GetInventory().GetCurrentInventoryLocation(src);
511  if (src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
512  return;
513 
514  #ifdef PLATFORM_CONSOLE
515  if (dst.IsValid() && targetEntity.GetInventory().LocationCanAddEntity(dst))
516  #else
517  if (c_x > x && c_y > y && targetEntity.GetInventory().LocationCanAddEntity(dst))
518  #endif
519  {
520  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
521 
522  SplitItemUtils.TakeOrSplitToInventoryLocation(player, dst);
523 
524  Icon icon = cargo.GetIcon(item);
525  if (icon)
526  {
527  if (w && w.FindAnyWidget("Cursor"))
528  w.FindAnyWidget("Cursor").SetColor(ColorManager.BASE_COLOR);
529 
530  icon.Refresh();
531  Refresh();
532  }
533  }
534 
535  ItemManager.GetInstance().HideDropzones();
536  ItemManager.GetInstance().SetIsDragging(false);
537  }
538 
539  void TakeAsAttachment( Widget w, Widget receiver )
540  {
541  ItemManager.GetInstance().HideDropzones();
542  ItemManager.GetInstance().SetIsDragging( false );
543  SlotsIcon slots_icon;
544  EntityAI receiver_item;
545  int slot_id = -1;
546  bool is_reserved = false;
547  EntityAI attached_entity;
548  receiver.GetUserData(slots_icon);
549  //string name = receiver.GetName();
550  //name.Replace("PanelWidget", "Render");
551 
552  //ItemPreviewWidget receiver_iw = ItemPreviewWidget.Cast( receiver.FindAnyWidget(name) );
553  if( slots_icon )
554  {
555  receiver_item = slots_icon.GetEntity();
556  slot_id = slots_icon.GetSlotID();
557  attached_entity = slots_icon.GetSlotParent();
558  is_reserved = slots_icon.IsReserved();
559  }
560 
561  EntityAI item = GetItemPreviewItem( w );
562  if( !item )
563  {
564  return;
565  }
566  ItemBase item_base = ItemBase.Cast( item );
568  float stackable;
569 
570  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
571  if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
572  return;
573 
574  EntityAI target_att_entity = m_Entity;
575  Weapon_Base wpn;
576  Magazine mag;
577  if( Class.CastTo(wpn, m_Entity ) && Class.CastTo(mag, item ) )
578  {
579  if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
580  {
581  player.GetWeaponManager().AttachMagazine( mag );
582  }
583  }
584  else if( receiver_item && !is_reserved )
585  {
586  if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
587  {
588  ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
589  }
590  else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
591  {
592  if( !receiver_item.GetInventory().CanRemoveEntity() )
593  return;
594  GetGame().GetPlayer().PredictiveSwapEntities( receiver_item, item );
595  }
596  else if( receiver_item.GetInventory().CanAddAttachment( item ) )
597  {
598  player.PredictiveTakeEntityToTargetAttachment(receiver_item, item);
599  }
600  }
601  else if( attached_entity && attached_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
602  {
603  stackable = item_base.GetTargetQuantityMax(slot_id);
604  if( stackable == 0 || stackable >= item_base.GetQuantity() )
605  {
606  player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, slot_id);
607  }
608  else if( stackable != 0 && stackable < item_base.GetQuantity() )
609  {
610  item_base.SplitIntoStackMaxClient( attached_entity, slot_id );
611  }
612  }
613  else if(attached_entity && attached_entity.GetInventory().CanAddAttachment(item))
614  {
615  attached_entity.GetInventory().FindFreeLocationFor(item,FindInventoryLocationType.ATTACHMENT,il);
616  stackable = item_base.GetTargetQuantityMax(il.GetSlot());
617  if( stackable == 0 || stackable >= item_base.GetQuantity() )
618  {
619  player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, il.GetSlot());
620  }
621  else if( stackable != 0 && stackable < item_base.GetQuantity() )
622  {
623  item_base.SplitIntoStackMaxClient( attached_entity, il.GetSlot() );
624  }
625  }
626  else if( m_Entity.GetInventory().CanAddAttachment(item) )
627  {
628  m_Entity.GetInventory().FindFreeLocationFor(item,FindInventoryLocationType.ATTACHMENT,il);
629  stackable = item_base.GetTargetQuantityMax(il.GetSlot());
630  if( stackable == 0 || stackable >= item_base.GetQuantity() )
631  {
632  player.PredictiveTakeEntityToTargetAttachmentEx(m_Entity, item, il.GetSlot());
633  }
634  else if( stackable != 0 && stackable < item_base.GetQuantity() )
635  {
636  item_base.SplitIntoStackMaxClient( m_Entity, il.GetSlot() );
637  }
638  }
639  else if( m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !m_Entity.GetInventory().HasEntityInCargo( item ) )
640  {
641  SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
642  }
643  /*else if( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item ) )
644  {
645  SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
646  }*/
647  }
648 
649  override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
650  {
651  TakeAsAttachment( w, receiver );
652  }
653 
654  void OnDropReceivedFromHeader2( Widget w, int x, int y, Widget receiver )
655  {
656  TakeAsAttachment( w, receiver );
657  }
658 
659  void DoubleClick(Widget w, int x, int y, int button)
660  {
661  if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
662  {
663  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
664  if( w == NULL || player.GetInventory().IsInventoryLocked() )
665  {
666  return;
667  }
668  ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
669  if( !iw )
670  {
671  string name = w.GetName();
672  name.Replace( "PanelWidget", "Render" );
673  iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
674  }
675 
676  if( !iw )
677  {
678  iw = ItemPreviewWidget.Cast( w );
679  }
680 
681  EntityAI item = iw.GetItem();
682 
683  if( !item )
684  {
685  return;
686  }
687 
688  SlotsIcon icon;
689  iw.GetUserData(icon);
690 
691  if(icon && icon.IsReserved())
692  {
693  return;
694  }
695 
696  if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
697  return;
698 
699  if( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
700  {
701  player.PredictiveTakeEntityToHands( item );
702  }
703  else
704  {
705  if(player.GetInventory().CanAddEntityToInventory( item ) && item.GetInventory().CanRemoveEntity())
706  {
707  player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ANY, InventoryItem.Cast( item ) );
708  }
709  else
710  {
711  if( player.GetHumanInventory().CanAddEntityInHands( item ) )
712  {
713  player.PredictiveTakeEntityToHands( item );
714  }
715  }
716  }
717 
718  HideOwnedTooltip();
719 
720  name = w.GetName();
721  name.Replace( "PanelWidget", "Temperature" );
722  w.FindAnyWidget( name ).Show( false );
723  }
724  }
725 
726  bool DraggingOverGrid( Widget w, int x, int y, Widget reciever, CargoContainer cargo )
727  {
728  if( w == NULL )
729  {
730  return false;
731  }
732 
733  EntityAI item = GetItemPreviewItem( w );
734 
735  if( !item )
736  {
737  return false;
738  }
739 
740  int color;
741  int idx = 0;
742  int c_x, c_y;
743 
744  EntityAI target_entity;
745  CargoBase target_cargo;
746 
747  if( cargo == m_CargoGrid )
748  {
749  target_entity = m_Entity;
750  target_cargo = m_Entity.GetInventory().GetCargo();
751  }
752  else
753  {
754  target_entity = m_AttachmentCargos.GetKeyByValue( cargo );
755  if( target_entity )
756  {
757  target_cargo = target_entity.GetInventory().GetCargo();
758  }
759  else
760  return false;
761  }
762 
763  if( target_cargo && target_entity )
764  {
765  c_x = target_cargo.GetHeight();
766  c_y = target_cargo.GetWidth();
767  }
768  else
769  return false;
770 
771  if( c_x > x && c_y > y && target_entity.GetInventory().CanAddEntityInCargoEx( item, idx, x, y, item.GetInventory().GetFlipCargo() ) )
772  {
773  color = ColorManager.GREEN_COLOR;
774  if( target_entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
775  {
776  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
777  }
778  else
779  {
780  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
781  }
782  }
783  else
784  {
785  color = ColorManager.RED_COLOR;
786  }
787 
788  if( w.FindAnyWidget("Cursor") )
789  {
790  w.FindAnyWidget("Cursor").SetColor( color );
791  }
792  else
793  {
794  string name = w.GetName();
795  name.Replace( "PanelWidget", "Cursor" );
796  if( w.FindAnyWidget( name ) )
797  {
798  w.FindAnyWidget( name ).SetColor( color );
799  }
800  }
801 
802  return true;
803  }
804 
805  override void DraggingOver( Widget w, int x, int y, Widget receiver )
806  {
807  DraggingOverHeader( w, x, y, receiver );
808  }
809 
810  override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
811  {
812  if( w == NULL )
813  {
814  return;
815  }
816  EntityAI item = GetItemPreviewItem( w );
817  if( !item )
818  {
819  return;
820  }
821 
822  SlotsIcon slots_icon;
823  receiver.GetUserData(slots_icon);
824 
825  EntityAI attached_entity;
826  EntityAI receiver_item;
827  bool is_reserved = false;
828  int slot_id = -1;
829 
830  if(slots_icon)
831  {
832  attached_entity = slots_icon.GetSlotParent();
833  slot_id = slots_icon.GetSlotID();
834  receiver_item = slots_icon.GetEntity();
835  is_reserved = slots_icon.IsReserved();
836  }
837 
838 
839  Weapon_Base wpn;
840  Magazine mag;
841  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
842  if( m_Entity )
843  {
844  if( Class.CastTo(wpn, m_Entity ) && Class.CastTo(mag, item ) )
845  {
846  if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
847  {
848  ItemManager.GetInstance().HideDropzones();
849  if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
850  {
851  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
852  }
853  else
854  {
855  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
856  }
857  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
858  }
859  }
860  else if( receiver_item && !is_reserved )
861  {
862  ItemBase receiver_itemIB = ItemBase.Cast( receiver_item );
863  ItemBase itemIB = ItemBase.Cast( item );
864  if( receiver_itemIB && itemIB && receiver_itemIB.CanBeCombined( itemIB ) )
865  {
866  ItemManager.GetInstance().HideDropzones();
867  if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
868  {
869  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
870  }
871  else
872  {
873  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
874  }
875  ColorManager.GetInstance().SetColor( w, ColorManager.COMBINE_COLOR );
876  }
877  else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
878  {
879  ItemManager.GetInstance().HideDropzones();
880  if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
881  {
882  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
883  }
884  else
885  {
886  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
887  }
888  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
889  }
890  else if( receiver_itemIB.GetInventory().CanAddAttachment( item ) )
891  {
892  ItemManager.GetInstance().HideDropzones();
893  if( receiver_itemIB.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
894  {
895  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
896  }
897  else
898  {
899  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
900  }
901  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
902  }
903  }
904  else if( attached_entity && attached_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
905  {
906  ItemManager.GetInstance().HideDropzones();
907  if( attached_entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
908  {
909  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
910  }
911  else
912  {
913  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
914  }
915  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
916  }
917  else if( m_Entity.GetInventory().CanAddAttachment( item ) )
918  {
919  ItemManager.GetInstance().HideDropzones();
920  if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
921  {
922  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
923  }
924  else
925  {
926  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
927  }
928  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
929  }
930  else if( ( m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !m_Entity.GetInventory().HasEntityInCargo( item ) ) /*|| player.GetHumanInventory().HasEntityInHands( item )*/ )
931  {
932  ItemManager.GetInstance().HideDropzones();
933  if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
934  {
935  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
936  }
937  else
938  {
939  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
940  }
941  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
942  }
943  else
944  {
945  ItemManager.GetInstance().ShowSourceDropzone( item );
946  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
947  }
948  }
949  }
950 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
y
Icon y
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
SplitItemUtils
Definition: splititemutils.c:1
InventoryItem
Definition: itembase.c:13
Refresh
void Refresh()
Definition: sizetochild.c:108
CombineItemsClient
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition: itembase.c:849
Attachments
Definition: attachments.c:3
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
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
SlotsIcon
Definition: slotsicon.c:1
ItemManager
Definition: itemmanager.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
MouseState
MouseState
Definition: ensystem.c:310
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
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
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
UpdateInterval
override void UpdateInterval()
Definition: inventory.c:672
Inventory
void Inventory(LayoutHolder parent)
Definition: inventory.c:76
GetEntity
EntityAI GetEntity(int index)
Definition: quickbarbase.c:78
Widget
Definition: enwidgets.c:189
AttachmentsWrapper
Definition: attachmentswrapper.c:1
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
IsOpened
bool IsOpened()
Definition: inventorymenu.c:136
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
WidgetEventHandler
Definition: widgeteventhandler.c:1