DayZ 1.24
Loading...
Searching...
No Matches
PlayerContainer.c
Go to the documentation of this file.
2{
8
9 protected const int HEADER_INDEX_OFFSET = 2;
10
11 override void UpdateRadialIcon()
12 {
13 if (m_SlotIcon)
14 {
17 Widget rip = m_SlotIcon.GetRadialIconPanel();
18 rip.Show(!m_Player.GetInventory().IsInventoryLockedForLockType(HIDE_INV_FROM_SCRIPT) && m_Player.CanDisplayCargo());
19 SetOpenForSlotIcon(show_radial_icon);
20 }
21 }
22
28
30 {
31 return m_PlayerAttachmentsContainer.GetSlotsIcon(row, column);
32 }
33
34 void PlayerContainer(LayoutHolder parent, int sort = -1)
35 {
38
40 m_CollapsibleHeader.SetName("#container_inventory");
42 m_Body.Insert(m_PlayerAttachmentsContainer);
43 m_MainWidget = m_RootWidget.FindAnyWidget("body");
44 m_PlayerAttachmentsContainer.GetRootWidget().SetColor(166 << 24 | 80 << 16 | 80 << 8 | 80);
45 WidgetEventHandler.GetInstance().RegisterOnChildAdd(m_MainWidget, this, "OnChildAdd");
46 WidgetEventHandler.GetInstance().RegisterOnChildRemove(m_MainWidget, this, "OnChildRemove");
47
48 //START - InitGhostSlots
49 string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
52
53 for (int i = 0; i < player_ghosts_slots.Count(); i++)
54 {
55 string slot_name = player_ghosts_slots.Get(i);
56 string path = "CfgSlots" + " " + slot_name;
57
58 if (GetGame().ConfigIsExisting(path))
59 {
60 string icon_name; //icon_name must be in format "set:<setname> image:<imagename>"
61 GetGame().ConfigGetText(path + " ghostIcon", icon_name);
62 int slot_number = i;
64
65 //START - GetWidgetSlot
67 if (row >= m_PlayerAttachmentsContainer.Count())
68 {
69 if (row < (player_ghosts_slots.Count() / ITEMS_IN_ROW))
71 else
73 }
74
76
77 icon.GetMainWidget().Show(true);
78 icon.Clear();
79
80 WidgetEventHandler.GetInstance().RegisterOnDoubleClick(icon.GetPanelWidget(), this, "DoubleClick");
81
82 //END - GetWidgetSlot
83 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetPanelWidget(), this, "OnDropReceivedFromGhostArea");
84 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetGhostSlot(), this, "OnDropReceivedFromGhostArea");
85 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetGhostSlot(), this, "DraggingOver");
86 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetPanelWidget(), this, "DraggingOver");
87 WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown(icon.GetPanelWidget(), this, "MouseClick");
88
90 //END - LoadIconIntoWidgetSlot
91
92 GetGame().ConfigGetText(path + " name", slot_name);
94 icon.SetSlotID(slot_id);
95 icon.SetSlotDisplayName(InventorySlots.GetSlotDisplayName(slot_id));
97 }
98 }
99 m_PlayerAttachmentsContainer.GetMainWidget().Update();
100 //END - InitGhostSlots
101 RecomputeOpenedContainers();
102 }
103
105 {
106 if (m_Player)
107 {
108 m_Player.GetOnItemAttached().Remove(ItemAttached);
109 m_Player.GetOnItemDetached().Remove(ItemDetached);
110 m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
111 m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
112 }
113 }
114
116 {
118 SlotsIcon icon = m_InventorySlots.Get(slot);
119
120 if (icon)
121 {
122 if (icon.IsReserved())
123 m_Player.GetOnAttachmentReleaseLock().Invoke(item, slot);
124
125 icon.Init(item);
126
127 if (m_ShowedItems.Contains(item) == false)
128 {
129 string name;
130 int sort_index = Inventory.GetPlayerAttachmentIndex(slot);
131 int current_sort = 9999;
132 if (GetFocusedContainer())
133 current_sort = GetFocusedContainer().GetRootWidget().GetSort();
134
135 if (item.GetSlotsCountCorrect() > 0)
136 {
137 ContainerWithCargoAndAttachments iwca = new ContainerWithCargoAndAttachments(this, sort_index);
138 iwca.SetEntity(item);
139 iwca.SetSlotIcon(icon);
140 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(), this, "ToggleWidget");
141
142 if (iwca.IsDisplayable())
143 icon.GetRadialIconPanel().Show(true);
144 m_ShowedItems.Insert(item, iwca);
145 RecomputeOpenedContainers();
146 Refresh();
147 }
148 else if (item.GetInventory().GetCargo())
149 {
150 ContainerWithCargo iwc = new ContainerWithCargo(this, sort_index);
151 iwc.SetEntity(item);
152 iwc.SetSlotIcon(icon);
153 iwc.UpdateInterval();
154 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(), this, "ToggleWidget");
155 m_ShowedItems.Insert(item, iwc);
156 RecomputeOpenedContainers();
157 if (iwc.IsDisplayable())
158 icon.GetRadialIconPanel().Show(true);
159
160 Refresh();
161 }
162 }
163
165 string config = "CfgVehicles " + item.GetType() + " GUIInventoryAttachmentsProps";
166 if (conta && conta.IsInherited(ClosableContainer))
167 {
168 bool show_radial_icon = (item.GetInventory().GetCargo() || item.GetSlotsCountCorrect() > 0) && !GetGame().ConfigIsExisting(config);
169 Widget rip = icon.GetRadialIconPanel();
170
171 rip.Show(show_radial_icon);
172 SetOpenForSlotIcon(conta.IsOpened(), icon);
173 }
174 }
175 UpdateSelectionIcons();
176 }
177
179 {
181 SlotsIcon icon = m_InventorySlots.Get(slot);
182
183 if (icon)
184 {
186 if (con)
187 {
188 (Container.Cast(con.m_Parent)).Remove(con);
189 RecomputeOpenedContainers();
190 GetMainWidget().Update();
191 Refresh();
192 m_ShowedItems.Remove(item);
193 }
194
195 icon.Clear();
196 Inventory in = Inventory.Cast(GetRoot());
197 if (in)
198 in.UpdateConsoleToolbar();
199 }
200 UpdateSelectionIcons();
201 }
202
204 {
206
207 if (item)
208 icon.Init(item, true);
209 }
210
216
223
224 void MouseClick(Widget w, int x, int y, int button)
225 {
227 w.GetUserData(icon);
228
230 bool isReserved;
231
232 if (icon)
233 {
234 selectedItem = ItemBase.Cast(icon.GetEntity());
235 isReserved = icon.IsReserved();
236
237 }
238
239 if (selectedItem)
240 {
241 switch (button)
242 {
243 case MouseState.RIGHT:
244#ifdef DIAG_DEVELOPER
245 if (GetDayZGame().IsLeftCtrlDown())
246 ShowActionMenu(selectedItem);
247#endif
248
249 if (isReserved)
250 {
251 GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced(selectedItem);
252 m_Player.GetOnAttachmentReleaseLock().Invoke(selectedItem, icon.GetSlotID());
253 }
254 break;
255
256 case MouseState.MIDDLE:
257 if (!isReserved)
259
260 break;
261
262 case MouseState.LEFT:
263 if (!isReserved)
264 {
266 if (g_Game.IsLeftCtrlDown())
267 {
268 if (controlledPlayer.CanDropEntity(selectedItem))
269 {
270 if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
271 selectedItem.SplitIntoStackMaxClient(null, -1);
272 else
273 controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
274 }
275 }
276 else
277 {
278 bool draggable = !m_Player.GetInventory().HasInventoryReservation(selectedItem, null) && !m_Player.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !m_Player.IsItemsToDelete();
279 ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
280 }
281 }
282 break;
283 }
284 }
285 }
286
288 {
289 float x, y;
290 GetRootWidget().GetScreenPos(x, y);
291 return y;
292 }
293
295 {
296 float x, y;
297 float x2, y2;
298 GetRootWidget().GetScreenPos(x, y);
299 GetRootWidget().GetScreenSize(x2, y2);
300 y += y2;
301 return y;
302 }
303
304 override void Insert(LayoutHolder container, int pos = -1, bool immedUpdate = true)
305 {
307 if (c_cont && m_Body.Count() > 1)
308 {
309 ClosableContainer prev = ClosableContainer.Cast(m_Body.Get(1));
310 int index = 1;
311 int curr_sort = c_cont.GetRootWidget().GetSort();
312 while (prev)
313 {
314 int prev_sort = prev.GetRootWidget().GetSort();
315 if (prev_sort > curr_sort)
316 break;
317
318 if (++index < m_Body.Count())
319 prev = ClosableContainer.Cast(m_Body.Get(index));
320 else
321 break;
322 }
323
324 m_Body.InsertAt(container, index);
325 }
326 else
327 m_Body.Insert(container);
328
329 if (immedUpdate)
330 RecomputeOpenedContainers();
331 }
332
334 {
336 return ent && (ent.GetInventory().GetCargo() || ent.GetSlotsCountCorrect() > 0);
337 }
338
340 {
342 return ent && QuantityConversions.HasItemQuantity(ent) && ent.CanBeSplit();
343 }
344
345 override bool IsItemActive()
346 {
349 }
350
352 {
354 return ent == null;
355 }
356
361
362 void DoubleClick(Widget w, int x, int y, int button)
363 {
364 if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
365 {
367
368 if (w == null || m_Player.GetInventory().IsInventoryLocked())
369 return;
370 ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
371 if (!iw)
372 {
373 string name = w.GetName();
374 name.Replace("PanelWidget", "Render");
375 iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
376 }
377 if (!iw)
378 iw = ItemPreviewWidget.Cast(w);
379
380 ItemBase item = ItemBase.Cast(iw.GetItem());
381
382 if (!item)
383 return;
384
386 iw.GetUserData(icon);
387
388 if (icon && icon.IsReserved())
389 return;
390
391 if (!item.GetInventory().CanRemoveEntity())
392 return;
393
394 if (player.GetInventory().HasEntityInInventory(item) && player.GetHumanInventory().CanAddEntityInHands(item))
395 player.PredictiveTakeEntityToHands(item);
396 else
397 {
398 if (player.GetInventory().CanAddEntityToInventory(item) && item.GetInventory().CanRemoveEntity())
399 {
400 if (item.GetTargetQuantityMax() < item.GetQuantity())
401 item.SplitIntoStackMaxClient(player, -1);
402 else
403 player.PredictiveTakeEntityToInventory(FindInventoryLocationType.ANY, item);
404 }
405 else
406 {
407 if (item.GetTargetQuantityMax() < item.GetQuantity())
408 item.SplitIntoStackMaxHandsClient(player);
409 else
410 player.PredictiveTakeEntityToHands(item);
411 }
412 }
414 HideOwnedTooltip();
415
416 InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
417 if (menu)
418 menu.RefreshQuickbar();
419 }
420 }
421
423 {
424 if (m_PlayerAttachmentsContainer.IsActive())
425 ToggleWidget(m_PlayerAttachmentsContainer.GetFocusedSlotsIcon().GetPanelWidget());
426 }
427
429 {
430 return GetFocusedContainer().IsInherited(ContainerWithCargo);
431 }
432
434 {
435 return GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments);
436 }
437
439 {
440 if (CanDrop())
441 {
442 if (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments))
443 return GetFocusedContainer().TransferItemToVicinity();
444 else
445 {
446 Man player = GetGame().GetPlayer();
448 if (item && player.CanDropEntity(item))
449 {
450 if (item.GetTargetQuantityMax() < item.GetQuantity())
451 item.SplitIntoStackMaxClient(null, -1);
452 else
453 player.PhysicalPredictiveDropItem(item);
454 return true;
455 }
456 }
457 }
458 return false;
459 }
460
461 override bool InspectItem()
462 {
463 if (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments))
464 return GetFocusedContainer().InspectItem();
465 else
466 {
467 Man player = GetGame().GetPlayer();
469 if (item)
470 {
472 return true;
473 }
474 }
475 return false;
476 }
477
479 {
480 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
481 return plugin_recipes_manager.GetValidRecipes(ItemBase.Cast(entity1), ItemBase.Cast(entity2), null, PlayerBase.Cast(GetGame().GetPlayer()));
482 }
483
484 override bool SplitItem()
485 {
486 if (CanSplit())
487 {
488 if (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments))
489 return GetFocusedContainer().SplitItem();
490 }
491
492 return false;
493 }
494
495 override bool EquipItem()
496 {
497 if (CanEquip())
498 {
499 if (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments))
500 return GetFocusedContainer().EquipItem();
501 else
502 {
504 if (item)
505 {
506 GetGame().GetPlayer().PredictiveTakeEntityToInventory(FindInventoryLocationType.ATTACHMENT, item);
507 return true;
508 }
509 }
510 }
511 return false;
512 }
513
514 override bool TransferItem()
515 {
516 if (CanTakeToInventory())
517 {
520 if (left_area)
521 {
522 if (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments))
523 return GetFocusedContainer().TransferItem();
524 else
525 {
527 if (item)
528 {
529 GetGame().GetPlayer().PredictiveTakeEntityToInventory(FindInventoryLocationType.CARGO, item);
530 return true;
531 }
532 }
533 }
534 else
535 {
536 if (!GetFocusedContainer().IsInherited(ContainerWithCargo) && !GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments))
537 {
539 if (item)
540 {
541 GetGame().GetPlayer().PredictiveTakeEntityToInventory(FindInventoryLocationType.CARGO, item);
542 return true;
543 }
544 }
545 }
546 }
547 return false;
548 }
549
551 {
552 return GetFocusedContainer().GetFocusedItem();
553 }
554
555 override bool Combine()
556 {
557 if (CanCombine())
558 {
559 if (GetFocusedContainer() && (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments)))
560 return GetFocusedContainer().Combine();
561 else
562 {
564 ItemBase item_in_hands = ItemBase.Cast(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
565
566 Icon hands_icon = ItemManager.GetInstance().GetHandsPreview().GetIcon();
567
568 if (item_in_hands && item)
569 return hands_icon.CombineItems(item_in_hands, item);
570 }
571 }
572 return true;
573 }
574
575 override bool Select()
576 {
577 if (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments))
578 return GetFocusedContainer().Select();
579 else
580 {
582 EntityAI selected_item = ItemManager.GetInstance().GetSelectedItem();
583 SlotsIcon focused_slot = GetFocusedSlotsIcon();
584 EntityAI focused_item = focused_slot.GetEntity();
585 if (focused_slot.IsReserved() || focused_item != selected_item)
586 {
587 if (selected_item)
588 {
589 if (selected_item.GetInventory().CanRemoveEntity())
590 {
591 if (m_Player.GetInventory().CanAddAttachmentEx(selected_item, focused_slot.GetSlotID()))
592 {
593 player.PredictiveTakeEntityToTargetAttachmentEx(m_Player, selected_item, focused_slot.GetSlotID());
594 //m_Player.PredictiveTakeEntityAsAttachmentEx( selected_item, focused_slot.GetSlotID() );
595 ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
596 return true;
597
598 }
599 else if (m_Player.GetInventory().CanAddAttachment(selected_item))
600 {
601 player.PredictiveTakeEntityToTargetAttachment(m_Player, selected_item);
602 //m_Player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, selected_item );
603 ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
604 return true;
605 }
606 }
607 }
608 else
609 {
610 if (focused_item && focused_item.GetInventory().CanRemoveEntity())
611 {
612 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
613 if (item_in_hands && item_in_hands.GetInventory().CanRemoveEntity())
614 {
616 {
617 player.PredictiveSwapEntities(item_in_hands, focused_item);
618 return true;
619 }
620 else
621 {
623 if (player.GetHumanInventory().FindFreeLocationFor(item_in_hands, FindInventoryLocationType.ANY, il_hands_dst))
624 {
626
627 if (player.NeedInventoryJunctureFromServer(item_in_hands, item_in_hands.GetHierarchyParent(), il_hands_dst.GetParent()) || GetGame().GetPlayer().NeedInventoryJunctureFromServer(focused_item, focused_item.GetHierarchyParent(), GetGame().GetPlayer()))
628 invMode = InventoryMode.JUNCTURE;
629
630 player.GetHumanInventory().ForceSwapEntities(invMode, focused_item, item_in_hands, il_hands_dst);
631 return true;
632 }
633 }
634 }
635 else
636 {
637 if (player.GetHumanInventory().CanAddEntityInHands(focused_item))
638 {
639 player.PredictiveTakeEntityToHands(focused_item);
640 return true;
641 }
642 }
643 }
644 }
645 }
646 }
647 return false;
648 }
649
651 {
652 if (m_Player)
653 {
654 m_Player.GetOnItemAttached().Remove(ItemAttached);
655 m_Player.GetOnItemDetached().Remove(ItemDetached);
656 m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
657 m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
658 }
659
661 if (m_Player)
662 {
663 m_Player.GetOnItemAttached().Insert(ItemAttached);
664 m_Player.GetOnItemDetached().Insert(ItemDetached);
665 m_Player.GetOnAttachmentSetLock().Insert(OnAttachmentReservationSet);
666 m_Player.GetOnAttachmentReleaseLock().Insert(OnAttachmentReservationRelease);
667 }
668
669 //START - InitGhostSlots
670 string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
673
674 for (int i = 0; i < player_ghosts_slots.Count(); i++)
675 {
676 string slot_name = player_ghosts_slots.Get(i);
677
678 int column = i % ITEMS_IN_ROW;
679 int row = i / ITEMS_IN_ROW;
680
682
683 icon.SetSlotParent(m_Player);
684 icon.GetMainWidget().Show(true);
685 icon.Clear();
686
687 GetGame().ConfigGetText("CfgSlots" + " " + slot_name + " name", slot_name);
688 EntityAI item = m_Player.GetInventory().FindAttachment(InventorySlots.GetSlotIdFromString(slot_name));
689 if (item)
691 }
692 }
693
695 {
697
698 if (!ipw.IsInherited(ItemPreviewWidget))
699 return;
700
701 EntityAI item = ipw.GetItem();
702 if (!item)
703 return;
704
705 if (!item.GetInventory().CanRemoveEntity())
706 return;
707
708 if (m_Player.GetInventory().CanAddEntityToInventory(item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT) && (!m_Player.GetInventory().HasEntityInInventory(item)))
709 m_Player.PredictiveTakeEntityToInventory(FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT, item);
710 }
711
713 {
714 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
715 if (!ipw)
716 {
717 string name = w.GetName();
718 name.Replace("PanelWidget", "Render");
719 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
720 }
721 if (!ipw)
722 ipw = ItemPreviewWidget.Cast(w);
723
724 return ipw;
725 }
726
727 override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
728 {
729 if (w == null)
730 return;
732
733 if (!ipw || !ipw.IsInherited(ItemPreviewWidget))
734 return;
735
736 EntityAI item = ipw.GetItem();
737 if (!item)
738 return;
739
740 if (m_Player.GetInventory().CanAddEntityToInventory(item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT) && !m_Player.GetInventory().HasEntityInInventory(item))
741 {
742 ItemManager.GetInstance().HideDropzones();
743 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
745 }
746 else
747 {
748 ItemManager.GetInstance().HideDropzones();
749 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
751 //ItemManager.GetInstance().ShowSourceDropzone( item );
752 }
753 }
754
755 override void DraggingOver(Widget w, int x, int y, Widget receiver)
756 {
757 if (w == null)
758 return;
759
761 bool is_reserved = false;
762
764 receiver.GetUserData(slots_icon);
765
766 if (slots_icon)
767 {
768 receiver_item = slots_icon.GetEntity();
769 is_reserved = slots_icon.IsReserved();
770 }
771
773
774 if (!ipw || !ipw.IsInherited(ItemPreviewWidget))
775 return;
776
777 EntityAI item = ipw.GetItem();
778 if (!item)
779 return;
780
782 {
784 {
786 ItemManager.GetInstance().HideDropzones();
787 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
788 return;
789 }
790 else if (receiver_item.GetInventory().CanAddAttachment(item) || receiver_item.GetInventory().CanAddEntityInCargo(item, item.GetInventory().GetFlipCargo()) && !receiver_item.GetInventory().HasEntityInCargo(item))
791 {
793 ItemManager.GetInstance().HideDropzones();
794 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
795 return;
796 }
797 else if ((ItemBase.Cast(receiver_item)).CanBeCombined(ItemBase.Cast(item)))
798 {
800 ItemManager.GetInstance().HideDropzones();
801 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
802 return;
803 }
804
805 }
806
807 if (item.GetInventory().CanRemoveEntity())
808 {
809 if (m_Player.GetInventory().CanAddAttachment(item))
810 {
812 ItemManager.GetInstance().HideDropzones();
813 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
814 }
815 else if (m_Player.GetInventory().CanAddEntityToInventory(item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT) && (!m_Player.GetInventory().HasEntityInInventory(item)) || m_Player.GetHumanInventory().HasEntityInHands(item))
816 {
818 ItemManager.GetInstance().HideDropzones();
819 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
820 }
822 {
824 ItemManager.GetInstance().HideDropzones();
825 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
826 }
827 else
828 {
830 ItemManager.GetInstance().HideDropzones();
831 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
832 }
833 }
834 else
835 {
837 ItemManager.GetInstance().HideDropzones();
838 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
839 //ItemManager.GetInstance().ShowSourceDropzone( item );
840 }
841 }
842
844 {
845 ItemManager.GetInstance().HideDropzones();
846 ItemManager.GetInstance().SetIsDragging(false);
847
849 bool is_reserved = false;
850 InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
851 float stack_max;
852
855 receiver.GetUserData(slots_icon);
856 int slot_id = slots_icon.GetSlotID();
857
858 receiver_item = slots_icon.GetEntity();
859 is_reserved = slots_icon.IsReserved();
861
862 if (!ipw)
863 return;
864
865 ItemBase item = ItemBase.Cast(ipw.GetItem());
867 if (!item)
868 return;
870 {
872 {
873 GetGame().GetPlayer().PredictiveSwapEntities(item, receiver_item);
874
875 if (menu)
876 menu.RefreshQuickbar();
877 return;
878 }
879 else if (receiver_item.GetInventory().CanAddAttachment(item))
880 {
881 GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment(receiver_item, item);
882
883 if (menu)
884 menu.RefreshQuickbar();
885 return;
886 }
887 else if (receiver_item.GetInventory().CanAddEntityInCargo(item, item.GetInventory().GetFlipCargo()) && !receiver_item.GetInventory().HasEntityInCargo(item))
888 {
890
891 if (menu)
892 menu.RefreshQuickbar();
893 return;
894 }
895 else if ((ItemBase.Cast(receiver_item)).CanBeCombined(ItemBase.Cast(item)))
896 {
898 return;
899 }
900 }
901
902 if (m_Player.GetInventory().CanAddAttachmentEx(item, slot_id))
903 {
904 if (item.GetQuantity() > item.GetTargetQuantityMax(slot_id))
905 item.SplitIntoStackMaxClient(real_player, slot_id);
906 else
907 real_player.PredictiveTakeEntityToTargetAttachmentEx(m_Player, item, slots_icon.GetSlotID());
908 }
909 else if (m_Player.GetInventory().CanAddAttachment(item))
910 {
911 il = new InventoryLocation;
912 m_Player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, il);
913 float stackable = item.GetTargetQuantityMax(-1);
914
915 if (il.IsValid())
916 {
917 if (stackable == 0 || stackable >= item.GetQuantity())
918 real_player.PredictiveTakeEntityToTargetAttachment(il.GetParent(), item);
919 else
920
921 ItemBase.Cast(item).SplitIntoStackMaxToInventoryLocationClient(il);
922 }
923 }
924 else if (m_Player.GetInventory().CanAddEntityToInventory(item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT) && (!m_Player.GetInventory().HasEntityInInventory(item)) || m_Player.GetHumanInventory().HasEntityInHands(item))
926
927 if (menu)
928 menu.RefreshQuickbar();
929 }
930
932 {
933 EntityAI item1 = m_Player.GetInventory().FindAttachment(slot1);
934 EntityAI item2 = m_Player.GetInventory().FindAttachment(slot2);
935
936 if (item1 && item2)
937 {
940 if (cont1 && cont2)
941 {
942 int sort1 = cont1.GetRootWidget().GetSort();
943 int sort2 = cont2.GetRootWidget().GetSort();
944
945 cont1.GetRootWidget().SetSort(sort2);
946 cont2.GetRootWidget().SetSort(sort1);
947
948 m_Body.SwapItems(m_Body.Find(cont1), m_Body.Find(cont2));
949 }
950 }
951 RecomputeOpenedContainers();
952 }
953
954 override void UpdateInterval()
955 {
956 int i;
957 for (i = 0; i < m_InventorySlots.Count(); i++)
958 {
959 SlotsIcon icon = m_InventorySlots.GetElement(i);
960 if (icon)
961 icon.UpdateInterval();
962 }
963 for (i = 0; i < m_ShowedItems.Count(); i++)
964 {
965 Container cont = m_ShowedItems.GetElement(i);
966 if (cont)
967 cont.UpdateInterval();
968 }
969 }
970
971 // Call from ToggleWidget
973 {
975 item.GetInventory().GetCurrentInventoryLocation(il);
976 SlotsIcon icon = m_InventorySlots.Get(il.GetSlot());
978 if (c)
979 {
980 c.Toggle();
981 Refresh();
982 }
983 }
984
986 {
987 if (focusedEntity)
988 {
990 if (c && c.IsDisplayable())
991 return true;
992 }
993 return false;
994 }
995
996 // Mouse button UP or Call other fn
998 {
999 if (ItemManager.GetInstance().IsDragging())
1000 return;
1001 string name = w.GetName();
1002 name.Replace("PanelWidget", "Render");
1003 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
1004 if (ipw.GetItem())
1005 {
1006 ToggleContainer(w, ipw.GetItem());
1007 RecomputeOpenedContainers();
1008 }
1009
1010 Refresh();
1011 }
1012
1014 {
1015 super.CollapseButtonOnMouseButtonDown(w);
1016 }
1017
1019 {
1020 if (GetFocusedContainer() && (GetFocusedContainer().IsInherited(ContainerWithCargo) || GetFocusedContainer().IsInherited(ContainerWithCargoAndAttachments)))
1021 return false;
1022
1023 return true;
1024 }
1025
1026 override void Refresh()
1027 {
1028 super.Refresh();
1029 m_MainWidget.Update();
1030 m_RootWidget.Update();
1031 UpdateSelectionIcons();
1032 }
1033
1035 {
1036 Refresh();
1037 return true;
1038 }
1039
1041 {
1042 Refresh();
1043 return true;
1044 }
1045}
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
const int ITEMS_IN_ROW
Definition Attachments.c:1
void Inventory(LayoutHolder parent)
Definition Inventory.c:76
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
DayZGame g_Game
Definition DayZGame.c:3528
DayZGame GetDayZGame()
Definition DayZGame.c:3530
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
void InventoryMenu()
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition ItemBase.c:5528
PlayerBase GetPlayer()
PluginBase GetPlugin(typename plugin_type)
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
override void Remove(LayoutHolder container)
ref CollapsibleHeader m_CollapsibleHeader
override Header GetHeader()
override void SetHeader(Header header)
static int COMBINE_COLOR
static int SWAP_COLOR
static int GREEN_COLOR
static int RED_COLOR
static ColorManager GetInstance()
script counterpart to engine's class Inventory
Definition Inventory.c:79
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:610
Definition Icon.c:2
InventoryLocation.
provides access to slot configuration
static proto native owned string GetSlotDisplayName(int id)
converts slot_id to string
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static ItemManager GetInstance()
override void ExpandCollapseContainer()
void OnAttachmentReservationRelease(EntityAI item, int slot_id)
override bool IsItemWithQuantityActive()
override void UpdateRadialIcon()
const int HEADER_INDEX_OFFSET
override bool OnChildRemove(Widget w, Widget child)
override void Refresh()
override bool OnChildAdd(Widget w, Widget child)
float GetMainContainerTopPos()
override void DraggingOver(Widget w, int x, int y, Widget receiver)
override bool InspectItem()
override bool Select()
override void CollapseButtonOnMouseButtonDown(Widget w)
void ItemAttached(EntityAI item, string slot_name)
SlotsIcon GetSlotsIcon(int row, int column)
override void Insert(LayoutHolder container, int pos=-1, bool immedUpdate=true)
void SetPlayer(PlayerBase player)
override bool EquipItem()
ref map< int, ref Container > m_ShowedItemsIDs
override EntityAI GetFocusedItem()
void ToggleWidget(Widget w)
override bool TransferItem()
void OnAttachmentReservationSet(EntityAI item, int slot_id)
PlayerBase m_Player
override bool Combine()
bool HasEntityContainerVisible(EntityAI entity)
float GetMainContainerBottomPos()
bool IsItemWithContainerActive()
override void UpdateInterval()
void UnfocusPlayerAttachmentsContainer()
override bool SplitItem()
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
override bool TransferItemToVicinity()
int GetRecipeCount(bool recipe_anywhere, EntityAI entity1, EntityAI entity2)
bool IsContainerWithCargoActive()
override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
ref AttachmentsGroupContainer m_PlayerAttachmentsContainer
void MouseClick(Widget w, int x, int y, int button)
bool IsItemWithAttachmentsActive()
void AddSlotsContainer(int row_count)
void ToggleContainer(Widget w, EntityAI item)
void ItemDetached(EntityAI item, string slot_name)
void SwapItemsInOrder(int slot1, int slot2)
void PlayerContainer(LayoutHolder parent, int sort=-1)
void OnDropReceivedFromGhostArea(Widget w, int x, int y, Widget receiver)
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
ItemPreviewWidget GetItemPreviewWidget(Widget w)
override bool IsItemActive()
void DoubleClick(Widget w, int x, int y, int button)
ref map< int, SlotsIcon > m_InventorySlots
ref map< EntityAI, ref Container > m_ShowedItems
static int HasItemQuantity(notnull EntityAI item)
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
static const int IMAGESETGROUP_INVENTORY
static string VerifyIconImageString(int imageset_group=IMAGESETGROUP_INVENTORY, string icon_name="")
Checks for improperly formated, legacy image names and corrects them to default format.
static WidgetEventHandler GetInstance()
proto native CGame GetGame()
const int MENU_INVENTORY
Definition constants.c:170
MouseState
Definition EnSystem.c:311
proto native Widget GetParent()
Get parent of the Effect.
Definition Effect.c:389