DayZ 1.24
Loading...
Searching...
No Matches
HandsContainer.c
Go to the documentation of this file.
2{
3 protected bool m_Hidden;
6
9
14
15 protected int m_StaticAttCount = 0;
16 protected int m_StaticCargoCount = 0;
17
19
21 {
25
26 m_CollapsibleHeader = new HandsHeader(this, "CollapseButtonOnMouseButtonDown");
27 GetMainWidget().SetFlags(WidgetFlags.IGNOREPOINTER);
28 m_MainWidget = m_MainWidget.FindWidget("body");
29 GetMainWidget().SetFlags(WidgetFlags.IGNOREPOINTER);
30 m_Body = new array<ref LayoutHolder>;
31 m_HandsPreview = new HandsPreview(this);
32 ItemManager.GetInstance().SetHandsPreview(m_HandsPreview);
33 m_Body.Insert(m_HandsPreview);
34
35 ItemBase hands_item = ItemBase.Cast(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
36 if (hands_item)
37 m_HandsPreview.CreateNewIcon(hands_item);
38
39 m_ScrollWidget = ScrollWidget.Cast(m_RootWidget.GetParent().GetParent());
40 RecomputeOpenedContainers();
41 }
42
44 {
45 if (m_Entity)
46 {
47 m_Entity.GetOnItemAttached().Remove(AttachmentAdded);
48 m_Entity.GetOnItemDetached().Remove(AttachmentRemoved);
49 }
50
51 m_AttachmentCargos.Clear();
54 }
55
57 {
58 m_Body.Clear();
59 m_Body.Insert(m_HandsPreview);
60 }
61
62 override Header GetHeader()
63 {
65 }
66
67 override bool IsLastIndex()
68 {
69 return m_ActiveIndex == m_OpenedContainers.Count() - 1;
70 }
71
73 {
74 int index = m_ActiveIndex - 1;
76 int cargo_start_index = -1;
77 int attachment_end_index = -1;
78 int cargo_end_index = -1;
79
80 if (m_Atts || m_AttachmentAttachments.Count() > 0)
81 {
83 if (m_Atts)
86 }
87
88 if (m_CargoGrid || m_AttachmentCargos.Count() > 0)
89 {
91 if (m_CargoGrid)
94 }
95
96 if (m_ActiveIndex > m_OpenedContainers.Count())
97 m_ActiveIndex = m_OpenedContainers.Count();
98
99 if (index == -1)
100 {
101#ifdef PLATFORM_CONSOLE
102 if (m_MainWidget.FindAnyWidget("Cursor"))
103 m_MainWidget.FindAnyWidget("Cursor").Show(true);
104#endif
105 m_ScrollWidget.VScrollToPos01(0);
106 }
107 else
108 {
109 if (index.InRange(0, attachment_end_index))
110 {
111 if (m_Atts)
112 {
113 if (index == 0)
114 {
115 m_Atts.SetDefaultFocus();
116 SetFocusedContainer(m_Atts.GetWrapper());
117 }
118 else
119 {
120 m_AttachmentAttachments.GetElement(index - 1).SetDefaultFocus();
121 SetFocusedContainer(m_AttachmentAttachments.GetElement(index - 1).GetWrapper());
122 }
123 }
124 else
125 {
126 m_AttachmentAttachments.GetElement(index).SetDefaultFocus();
127 SetFocusedContainer(m_AttachmentAttachments.GetElement(index).GetWrapper());
128 }
129 }
130 else if (index.InRange(cargo_start_index, cargo_end_index))
131 {
132 if (m_CargoGrid)
133 {
135 {
136 m_CargoGrid.SetDefaultFocus();
137 SetFocusedContainer(m_CargoGrid);
138 }
139 else
140 {
141 m_AttachmentCargos.GetElement(index - 1 - cargo_start_index).SetDefaultFocus();
142 SetFocusedContainer(m_AttachmentCargos.GetElement(index - 1 - cargo_start_index));
143 }
144 }
145 else
146 {
147 m_AttachmentCargos.GetElement(index - cargo_start_index).SetDefaultFocus();
148 SetFocusedContainer(m_AttachmentCargos.GetElement(index - cargo_start_index));
149 }
150 }
151
152 if (m_MainWidget.FindAnyWidget("Cursor"))
153 m_MainWidget.FindAnyWidget("Cursor").Show(false);
154 ScrollToActiveContainer(GetFocusedContainer());
155 }
156 }
157
159 {
160 if (!active_container)
161 return;
162 float x, y, y_s;
163 m_ScrollWidget.GetScreenPos(x, y);
164 m_ScrollWidget.GetScreenSize(x, y_s);
165 float amount;
166 float next_pos = active_container.GetFocusedContainerYScreenPos(true) + active_container.GetFocusedContainerHeight(true);
167
168 if (next_pos > (y + y_s))
169 {
170 amount = y + active_container.GetFocusedContainerYScreenPos(true);
171 m_ScrollWidget.VScrollToPos(m_ScrollWidget.GetVScrollPos() + active_container.GetFocusedContainerHeight(true) + 2);
172 }
173 else if (active_container.GetFocusedContainerYScreenPos(true) < y)
174 {
175 amount = active_container.GetFocusedContainerYScreenPos(true) - y;
176 m_ScrollWidget.VScrollToPos(m_ScrollWidget.GetVScrollPos() + amount - 2);
177 }
178 }
179
180 override void Insert(LayoutHolder container, int pos = -1, bool immedUpdate = true)
181 {
182 super.Insert(container, pos, immedUpdate);
183 }
184
185 override bool TransferItem()
186 {
187 if (m_ActiveIndex == 0)
188 {
189 if (CanTakeToInventory())
190 {
191 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
192 if (item_in_hands && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null))
193 {
194 if (GetGame().GetPlayer().PredictiveTakeEntityToInventory(FindInventoryLocationType.CARGO, item_in_hands))
195 {
196 m_MainWidget.FindAnyWidget("Cursor").Show(false);
197 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha(0.7);
198 return true;
199 }
200 }
201 }
202 }
203 else if (GetFocusedContainer())
204 return GetFocusedContainer().TransferItem();
205 return false;
206 }
207
208 override bool SplitItem()
209 {
210 if (CanSplit())
211 {
212 if (m_ActiveIndex == 0)
213 {
214 ItemBase item_in_hands = ItemBase.Cast(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
215 if (item_in_hands)
216 {
217 if (item_in_hands.CanBeSplit())
218 item_in_hands.OnRightClick();
219 }
220 }
221 else if (GetFocusedContainer())
222 return GetFocusedContainer().SplitItem();
223 }
224 return false;
225 }
226
227 override bool EquipItem()
228 {
229 if (CanEquip())
230 {
231 if (m_ActiveIndex == 0)
232 {
233 ItemBase item_in_hands = ItemBase.Cast(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
234 if (item_in_hands)
235 {
236 if (GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null))
237 {
238 if (GetGame().GetPlayer().PredictiveTakeEntityToInventory(FindInventoryLocationType.ATTACHMENT, item_in_hands))
239 {
240 m_MainWidget.FindAnyWidget("Cursor").Show(false);
241 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha(0.7);
242 return true;
243 }
244 }
245 }
246 }
247 else if (GetFocusedContainer())
248 return GetFocusedContainer().EquipItem();
249 }
250 return false;
251 }
252
253 override void SetActive(bool active)
254 {
255 super.SetActive(active);
257 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
258
259 if (item_in_hands)
260 {
261 if (m_MainWidget.FindAnyWidget("Cursor"))
262 m_MainWidget.FindAnyWidget("Cursor").Show(active);
263
264 if (active)
265 {
266 float x, y;
267 GetMainWidget().GetScreenPos(x, y);
268 PrepareOwnedTooltip(item_in_hands, -1, y);
269 }
270 }
271 else
272 {
273 if (active)
274 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha(0.85);
275 else
276 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha(0.7);
277 }
278 }
279
280 override void SetLastActive()
281 {
282 super.SetLastActive();
284 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
285
286 if (item_in_hands)
287 {
288 if (m_ActiveIndex == 0)
289 {
290 if (m_MainWidget.FindAnyWidget("Cursor"))
291 m_MainWidget.FindAnyWidget("Cursor").Show(true);
292
293 float x, y;
294 GetMainWidget().GetScreenPos(x, y);
295 PrepareOwnedTooltip(item_in_hands, x, y);
296 }
297 }
298 else
299 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha(0.85);
300 }
301
302 override void Refresh()
303 {
304 super.Refresh();
306 }
307
308 override bool IsItemActive()
309 {
311 ItemBase item = ItemBase.Cast(player.GetHumanInventory().GetEntityInHands());
312 if (item == null)
313 return false;
315 }
316
318 {
320 ItemBase item = ItemBase.Cast(player.GetHumanInventory().GetEntityInHands());
321 if (item == null)
322 return false;
323 return !IsEmpty() && QuantityConversions.HasItemQuantity(item) && item.CanBeSplit();
324 }
325
326 override bool IsEmpty()
327 {
329 return player.GetHumanInventory().GetEntityInHands() == null;
330 }
331
333 {
334 if (CanDrop())
335 {
336 if (m_ActiveIndex == 0)
337 {
339 ItemBase item_in_hands = ItemBase.Cast(player.GetHumanInventory().GetEntityInHands());
340 if (item_in_hands && player.CanDropEntity(item_in_hands) && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !player.GetInventory().HasInventoryReservation(item_in_hands, null))
341 {
342 if (item_in_hands.GetTargetQuantityMax() < item_in_hands.GetQuantity())
343 item_in_hands.SplitIntoStackMaxClient(null, -1);
344 else
345 player.PhysicalPredictiveDropItem(item_in_hands);
346 m_MainWidget.FindAnyWidget("Cursor").Show(false);
347 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha(0.7);
348 return true;
349 }
350 }
351 else if (GetFocusedContainer())
352 return GetFocusedContainer().TransferItemToVicinity();
353 }
354 return false;
355 }
356
357 override bool InspectItem()
358 {
359 if (m_ActiveIndex == 0)
360 {
362 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
363 if (item_in_hands)
364 {
366 return true;
367 }
368 }
369 else if (GetFocusedContainer())
370 return GetFocusedContainer().InspectItem();
371 return false;
372 }
373
374 override bool OnSelectButton()
375 {
376 if (m_ActiveIndex == 0)
377 {
378 if (ItemManager.GetInstance().IsMicromanagmentMode())
379 {
380 EntityAI selectedItem = ItemManager.GetInstance().GetSelectedItem();
382 {
383 Inventory.GetInstance().DisableMicromanagement();
384 return true;
385 }
386 else
387 return Select();
388 }
389 else
390 {
391 Inventory.GetInstance().EnableMicromanagement();
392 return true;
393 }
394 }
395 else
396 {
397 if (GetFocusedContainer())
398 return GetFocusedContainer().OnSelectButton();
399 }
400 return false;
401 }
402
404 {
405 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
406 if (!ipw)
407 {
408 string name = w.GetName();
409 name.Replace("PanelWidget", "Render");
410 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
411 }
412
413 if (!ipw)
414 ipw = ItemPreviewWidget.Cast(w);
415
416 if (!ipw)
417 return null;
418
419 return ipw.GetItem();
420 }
421
422 override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
423 {
424 if (w == null)
425 return;
428 int slot_id = -1;
429
430 string name = w.GetName();
431 name.Replace("PanelWidget", "Render");
432
433 ItemPreviewWidget w_ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
434 if (w_ipw == null)
435 w_ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
436 if (w_ipw == null)
437 return;
438
440 receiver.GetUserData(slots_icon);
441
442 if (slots_icon)
443 {
444 receiver_item = slots_icon.GetEntity();
445 slot_id = slots_icon.GetSlotID();
446 slot_owner = slots_icon.GetSlotParent();
447 }
448
449
451 InventoryItem receiver_entity = InventoryItem.Cast(p.GetHumanInventory().GetEntityInHands());
452 InventoryItem w_entity = InventoryItem.Cast(w_ipw.GetItem());
453 if (!w_entity)
454 return;
455
456 if (receiver_entity)
457 {
458 if (receiver_item)
459 {
462 if (receiver_itemIB && itemIB && receiver_itemIB.CanBeCombined(itemIB))
463 {
464 ItemManager.GetInstance().HideDropzones();
465 if (m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer())
466 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
467 else
468 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
470 }
471 else
472 {
475 Weapon_Base wpn = Weapon_Base.Cast(receiver_item.GetHierarchyParent());
476
477 if (wpn && mag)
478 {
479 if (player.GetWeaponManager().CanSwapMagazine(wpn, Magazine.Cast(w_entity)))
480 {
482 if (w_entity.GetHierarchyRootPlayer() == player)
483 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
484 else
485 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
486 }
487 else
488 {
490 ItemManager.GetInstance().ShowSourceDropzone(w_entity);
491 }
492 }
493 else
494 {
496 {
497 ItemManager.GetInstance().HideDropzones();
498 if (m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer())
499 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
500 else
501 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
503 }
504 else if (receiver_itemIB.GetInventory().CanAddAttachment(w_entity))
505 {
506 ItemManager.GetInstance().HideDropzones();
507 if (receiver_itemIB.GetHierarchyRootPlayer() == GetGame().GetPlayer())
508 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
509 else
510 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
512 }
513 }
514 }
515 }
516 else if (slot_owner && slot_owner.GetInventory().CanAddAttachment(w_entity))
517 {
518 ItemManager.GetInstance().HideDropzones();
519 ItemManager.GetInstance().GetCenterDropzone().SetAlpha(1);
521 }
522 else if (receiver_entity.GetInventory().CanAddAttachment(w_entity))
523 {
524 ItemManager.GetInstance().HideDropzones();
525 if (receiver_entity.GetHierarchyRootPlayer() == GetGame().GetPlayer())
526 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
527 else
528 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
530 }
531 else
532 {
534 ItemManager.GetInstance().ShowSourceDropzone(w_entity);
535 }
536 }
537 else
538 {
539 /*if( m_HandsIcon )
540 {
541 ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
542 ItemManager.GetInstance().HideDropzones();
543 ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
544 }
545
546 else
547 {*/
549 ItemManager.GetInstance().ShowSourceDropzone(w_entity);
550 //}
551 }
552 }
553
558
560 {
562 if (m_am_entity1 == null || m_am_entity2 == null) return;
563
565
567 {
569 if (Class.CastTo(mag, m_am_entity2))
570 {
572 return;
573 }
574 }
575
577 {
578 if (m_Atts)
579 {
580 m_Body.RemoveItem(m_Atts.GetWrapper());
581 delete m_Atts;
582 }
583 if (m_am_entity2.GetSlotsCountCorrect() > 0)
584 {
585 m_Atts = new Attachments(this, m_am_entity2);
586 m_Atts.InitAttachmentGrid(1);
587
588 }
589
590 Refresh();
591 m_Parent.Refresh();
592
595 if (Class.CastTo(wpn1, m_am_entity1) && Class.CastTo(mag1, m_am_entity2))
596 {
598 {
600 return;
601 }
602 }
603
604 SplitItemUtils.TakeOrSplitToInventory(m_player, m_am_entity1, m_am_entity2);
605 //m_player.PredictiveTakeEntityToTargetAttachment( m_am_entity1, m_am_entity2 );
606 }
607
609 m_player.PredictiveTakeEntityToTargetCargo(m_am_entity1, m_am_entity2);
610
612 {
615 if (Class.CastTo(swapmag1, m_am_entity1) && Class.CastTo(swapmag2, m_am_entity2))
616 {
618 {
620 return;
621 }
622
624 {
626 return;
627 }
628 }
629 if (!m_player.PredictiveSwapEntities(m_am_entity1, m_am_entity2) && m_player.GetHumanInventory().CanAddEntityInHands(m_am_entity1))
630 m_player.PredictiveTakeEntityToHands(m_am_entity1);
631 }
632
634 {
635 if (m_Atts)
636 {
637 m_Body.RemoveItem(m_Atts.GetWrapper());
638 delete m_Atts;
639 }
640
641 if (m_am_entity2.GetSlotsCountCorrect() > 0)
642 {
643 m_Atts = new Attachments(this, m_am_entity2);
644 m_Atts.InitAttachmentGrid(1);
645
646 }
647 Refresh();
648 m_Parent.Refresh();
649
650 if (m_player.GetHumanInventory().CanAddEntityInHands(m_am_entity2))
651 m_player.PredictiveTakeEntityToHands(m_am_entity2);
652 }
653 }
654
656 {
657 if (entity1 && entity2) PrintString("Showing action menu for " + entity1.GetDisplayName() + " and " + entity2.GetDisplayName());
658
659 ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());
660 m_am_entity1 = entity1;
661 m_am_entity2 = entity2;
662 cmenu.Hide();
663 cmenu.Clear();
664
666 {
668 entity.CombineItemsClient(ItemBase.Cast(entity2));
669 return;
670 }
671
672 if (entity1 == null || entity2 == null) return;
673
675
677 cmenu.Add("#inv_context_add_as_attachment", this, "OnPerformCombination", new Param1<int>(InventoryCombinationFlags.ADD_AS_ATTACHMENT));
679 cmenu.Add("#inv_context_load_chamber", this, "OnPerformCombination", new Param1<int>(InventoryCombinationFlags.LOAD_CHAMBER));
680
682 cmenu.Add("#inv_context_add_as_cargo", this, "OnPerformCombination", new Param1<int>(InventoryCombinationFlags.ADD_AS_CARGO));
683
685 cmenu.Add("#inv_context_swap", this, "OnPerformCombination", new Param1<int>(InventoryCombinationFlags.SWAP));
686
688 cmenu.Add("#inv_context_take_to_hands", this, "OnPerformCombination", new Param1<int>(InventoryCombinationFlags.TAKE_TO_HANDS));
689
691 cmenu.Add("#inv_context_combine", this, "OnPerformCombination", new Param1<int>(InventoryCombinationFlags.COMBINE_QUANTITY2));
692
695 m_am_pos_x -= 5;
696 m_am_pos_y -= 5;
697
699 }
700
701
703 {
705 }
706
708 {
709 int flags = 0;
711 EntityAI entity_in_hands = m_player.GetHumanInventory().GetEntityInHands();
712
713 if (!entity1 || !entity2) return flags;
714
717 bool skipSwap = false;
718
720 {
722
723 if (Class.CastTo(parentWpn, swapmag1.GetHierarchyParent()))
724 {
725 skipSwap = true;
727 flags = flags | InventoryCombinationFlags.SWAP;
728 }
729
730 if (Class.CastTo(parentWpn, swapmag2.GetHierarchyParent()))
731 {
732 skipSwap = true;
734 flags = flags | InventoryCombinationFlags.SWAP;
735
736 }
737 }
738
739 if (!skipSwap)
740 {
741 if (entity1 == m_player.GetHumanInventory().GetEntityInHands()) flags = flags | InventoryCombinationFlags.TAKE_TO_HANDS;
743 {
744 if (!entity1.IsInherited(ZombieBase) && !entity1.IsInherited(Car))
745 flags = flags | InventoryCombinationFlags.SWAP;
746 }
747 }
748
749 if (entity1.IsInherited(ItemBase) && entity2.IsInherited(ItemBase))
750 {
752 if (ent1.CanBeCombined(ItemBase.Cast(entity2))) flags = flags | InventoryCombinationFlags.COMBINE_QUANTITY2;
753 }
754
755 else if (entity1.GetInventory().CanAddAttachment(entity2))
756 {
757 if (!entity1.IsInherited(ZombieBase) && !entity1.IsInherited(Car) && !entity2.IsInherited(ZombieBase) && !entity2.IsInherited(Car))
759 }
760 if (!entity1.GetInventory().HasEntityInInventory(entity2) && entity1.GetInventory().CanAddEntityInCargo(entity2, entity2.GetInventory().GetFlipCargo())) flags = flags | InventoryCombinationFlags.ADD_AS_CARGO;
761
762 if (entity1 == m_player.GetHumanInventory().GetEntityInHands() || entity2 == m_player.GetHumanInventory().GetEntityInHands())
763 {
765 Class.CastTo(amc, m_player.GetActionManager());
766 if (entity1 == m_player.GetHumanInventory().GetEntityInHands())
767 {
768 if (amc.CanSetActionFromInventory(ItemBase.Cast(entity1), ItemBase.Cast(entity2)))
770 }
771 else
772 {
773 if (amc.CanSetActionFromInventory(ItemBase.Cast(entity2), ItemBase.Cast(entity1)))
775 }
776 }
777
778 if (GetRecipeCount(true, entity1, entity2) > 0)
780 return flags;
781 }
782
784 {
785 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
786 return plugin_recipes_manager.GetValidRecipes(ItemBase.Cast(entity1), ItemBase.Cast(entity2), null, PlayerBase.Cast(GetGame().GetPlayer()));
787 }
788
790 {
791 m_Entity = null;
792 m_CollapsibleHeader.ShowCollapseButtons(false, true);
793 }
794
796 {
797 if (m_Atts)
798 {
799 m_Body.RemoveItem(m_Atts.GetWrapper());
800 delete m_Atts;
801
802 if (m_Entity)
803 {
804 m_Entity.GetOnItemAttached().Remove(AttachmentAdded);
805 m_Entity.GetOnItemDetached().Remove(AttachmentRemoved);
806 }
807 }
808
810 {
812 {
813 m_Body.RemoveItem(att);
815 delete att;
816 }
817 }
818
820 Refresh();
821 m_Parent.Refresh();
822 RecomputeOpenedContainers();
823 }
824
825 override void UnfocusGrid()
826 {
827 if (m_Atts)
828 m_Atts.UnfocusAll();
829
830 if (m_CargoGrid)
831 m_CargoGrid.UnfocusAll();
832
834 {
836 cargo.UnfocusAll();
837
838 }
839
841 {
843 att.UnfocusAll();
844 }
845 }
846
847 override void UnfocusAll()
848 {
849 UnfocusGrid();
850 }
851
853 {
854 if (m_CargoGrid)
855 {
856 m_Body.RemoveItem(m_CargoGrid);
857 delete m_CargoGrid;
858 }
859
861 {
863 {
864 m_Body.RemoveItem(cargo);
865 delete cargo;
866 }
867 }
868
869 m_AttachmentCargos.Clear();
870 Refresh();
871 m_Parent.Refresh();
872 RecomputeOpenedContainers();
873 }
874
876 {
878 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
879
881 if (!item)
882 return;
883
884 int idx = 0;
885 int c_x, c_y;
886
889
890 if (cargo == m_CargoGrid)
891 {
893 target_cargo = m_Entity.GetInventory().GetCargo();
894#ifdef PLATFORM_CONSOLE
895 if (m_CargoGrid.HasItem(item))
896 return;
897#endif
898 }
899 else
900 {
901 target_entity = m_AttachmentCargos.GetKeyByValue(cargo);
902 if (target_entity)
903 {
904 target_cargo = target_entity.GetInventory().GetCargo();
905#ifdef PLATFORM_CONSOLE
906 if (cargo.HasItem(item))
907 return;
908#endif
909 }
910 else
911 return;
912 }
913
915 {
916 c_x = target_cargo.GetHeight();
917 c_y = target_cargo.GetWidth();
918 }
919 else
920 return;
921
923#ifdef PLATFORM_CONSOLE
924 x = 0;
925 y = target_cargo.GetItemCount();
926 target_entity.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.CARGO, dst);
927#else
928 dst.SetCargoAuto(target_cargo, item, x, y, item.GetInventory().GetFlipCargo());
929#endif
930
932 item.GetInventory().GetCurrentInventoryLocation(src);
933 if (src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
934 return;
935
936#ifdef PLATFORM_CONSOLE
937 if (dst.IsValid() && target_entity.GetInventory().LocationCanAddEntity(dst))
938#else
939 if (c_x > x && c_y > y && target_entity.GetInventory().LocationCanAddEntity(dst))
940#endif
941 {
943
944 Icon icon = cargo.GetIcon(item);
945
946 if (icon)
947 {
948 if (w && w.FindAnyWidget("Cursor"))
949 w.FindAnyWidget("Cursor").SetColor(ColorManager.BASE_COLOR);
950 icon.Refresh();
951 Refresh();
952 }
953 }
954 ItemManager.GetInstance().HideDropzones();
955 ItemManager.GetInstance().SetIsDragging(false);
956 }
957
959 {
960 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
961 if (w == null)
962 return false;
964 if (!item || !item_in_hands)
965 return false;
966
967 int color;
968 int idx = 0;
969 int c_x, c_y;
970
971 if (item_in_hands.GetInventory().GetCargo())
972 {
973 c_x = item_in_hands.GetInventory().GetCargo().GetHeight();
974 c_y = item_in_hands.GetInventory().GetCargo().GetWidth();
975 }
976
977 if (c_x > x && c_y > y && item_in_hands.GetInventory().CanAddEntityInCargoEx(item, 0, x, y, item.GetInventory().GetFlipCargo()))
978 {
979 ItemManager.GetInstance().HideDropzones();
980 ItemManager.GetInstance().GetCenterDropzone().SetAlpha(1);
982 }
983 else
984 {
986 ItemManager.GetInstance().ShowSourceDropzone(item);
987 }
988
989 if (w.FindAnyWidget("Cursor"))
990 w.FindAnyWidget("Cursor").SetColor(color);
991 else
992 {
993 string name = w.GetName();
994 name.Replace("PanelWidget", "Cursor");
995 w.FindAnyWidget(name).SetColor(color);
996 }
997
998 return true;
999 }
1000
1002 {
1005 int slot_id = -1;
1006
1008 receiver.GetUserData(slots_icon);
1009 if (slots_icon)
1010 {
1011 receiver_item = slots_icon.GetEntity();
1012 slot_id = slots_icon.GetSlotID();
1013 slot_owner = slots_icon.GetSlotParent();
1014 }
1015
1017 if (!item)
1018 return;
1019
1021 float stack_max = item_base.GetTargetQuantityMax(slot_id);
1022
1024 if (!item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory())
1025 return;
1026
1029 Magazine mag;
1031 {
1032 if (player.GetWeaponManager().CanAttachMagazine(wpn, mag))
1033 player.GetWeaponManager().AttachMagazine(mag);
1034 else if (player.GetWeaponManager().CanSwapMagazine(wpn, mag))
1035 player.GetWeaponManager().SwapMagazine(mag);
1036 }
1037 else if (receiver_item)
1038 {
1039 if (receiver_item != item)
1040 {
1041 if ((ItemBase.Cast(receiver_item)).CanBeCombined(ItemBase.Cast(item)))
1044 {
1045 if (!receiver_item.GetInventory().CanRemoveEntity())
1046 return;
1047 GetGame().GetPlayer().PredictiveSwapEntities(item, receiver_item);
1048 }
1049 }
1050 }
1051 else if (slot_owner && slot_owner.GetInventory().CanAddAttachmentEx(item, slot_id))
1052 {
1053 if (stack_max == 0 || stack_max >= item_base.GetQuantity())
1054 player.PredictiveTakeEntityToTargetAttachmentEx(slot_owner, item, slot_id);
1055 else if (stack_max != 0 && stack_max < item_base.GetQuantity())
1056 item_base.SplitIntoStackMaxClient(m_Entity, slot_id);
1057 }
1058 else if (slot_owner && slot_owner.GetInventory().CanAddAttachment(item))
1059 {
1060 if (stack_max == 0 || stack_max >= item_base.GetQuantity())
1061 player.PredictiveTakeEntityToTargetAttachment(slot_owner, item);
1062 else if (stack_max != 0 && stack_max < item_base.GetQuantity())
1063 item_base.SplitIntoStackMaxClient(m_Entity, -1);
1064 }
1065 else if (m_Entity.GetInventory().CanAddAttachment(item))
1066 {
1067 if (stack_max == 0 || stack_max >= item_base.GetQuantity())
1068 player.PredictiveTakeEntityToTargetAttachment(m_Entity, item);
1069 else if (stack_max != 0 && stack_max < item_base.GetQuantity())
1070 item_base.SplitIntoStackMaxClient(m_Entity, -1);
1071 }
1072 else if ((m_Entity.GetInventory().CanAddEntityInCargo(item, item.GetInventory().GetFlipCargo()) && (!player.GetInventory().HasEntityInInventory(item) || !m_Entity.GetInventory().HasEntityInCargo(item))) || player.GetHumanInventory().HasEntityInHands(item))
1074 /*else if( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item ) )
1075 {
1076 SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
1077 }*/
1078
1079 ItemManager.GetInstance().HideDropzones();
1080 ItemManager.GetInstance().SetIsDragging(false);
1081 }
1082
1084 {
1087 m_Entity = entity;
1088 m_ActiveIndex = 0;
1089 if (entity.GetSlotsCountCorrect() > 0)
1090 {
1091 m_Atts = new Attachments(this, entity);
1092 m_Atts.InitAttachmentGrid(1);
1093 m_AttachmentSlotsSorted = m_Atts.GetSlotsSorted();
1094 m_StaticAttCount = m_Atts.GetAttachmentHeight();
1095 m_Entity.GetOnItemAttached().Insert(AttachmentAdded);
1096 m_Entity.GetOnItemDetached().Insert(AttachmentRemoved);
1097 }
1098 else
1099 m_StaticAttCount = 0;
1100
1101 if (entity.GetInventory().GetCargo())
1102 {
1103 m_CargoGrid = new CargoContainer(this, false);
1104 m_CargoGrid.SetEntity(entity);
1105 m_CargoGrid.GetRootWidget().SetSort(1);
1108 }
1109
1111 {
1112 foreach (int slot_id : m_AttachmentSlotsSorted)
1113 {
1114 EntityAI item = m_Entity.GetInventory().FindAttachment(slot_id);
1115 if (item)
1117 }
1118 }
1119
1120 if (m_CargoGrid)
1121 {
1122 bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType(HIDE_INV_FROM_SCRIPT) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1123 if (m_CargoGrid.IsVisible() && hideCargo)
1124 HideCargo();
1125 else if (!m_CargoGrid.IsVisible() && !hideCargo)
1126 ShowCargo();
1127 }
1128
1129 m_CollapsibleHeader.ShowCollapseButtons(false);
1130 //m_CollapsibleHeader.ShowCollapseButtons( m_Atts || m_CargoGrid, m_Atts || m_CargoGrid );
1131 RecomputeOpenedContainers();
1132 Refresh();
1133 m_Parent.Refresh();
1134 }
1135
1137 {
1138 for (int i = 0; i < m_Body.Count(); i++)
1139 m_Body.Get(i).OnShow();
1140 Refresh();
1141 m_Parent.Refresh();
1142 }
1143
1144 void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
1145 {
1147 int sort = -1;
1150
1151 if (item.GetInventory().GetAttachmentSlotsCount() > 0)
1152 {
1153 att_cont = new Attachments(this, item);
1154 sort = (m_AttachmentSlotsSorted.Find(slot_id) * 2) + SORT_ATTACHMENTS_NEXT_OFFSET;
1155 att_cont.InitAttachmentGrid(sort);
1156
1158 m_AttachmentAttachmentsContainers.Insert(item, att_cont.GetWrapper());
1159
1160 att_cont.UpdateInterval();
1161 if (m_Parent)
1162 m_Parent.Refresh();
1163 Inventory.GetInstance().UpdateConsoleToolbar();
1164 }
1165
1166 if (item.GetInventory().GetCargo())
1167 {
1168 cont = new CargoContainer(this, true);
1169 sort = (m_AttachmentSlotsSorted.Find(slot_id) * 2) + SORT_CARGO_NEXT_OFFSET; //m_AttachmentSlotsSorted.Find( slot_id ) + 50
1170 cont.GetRootWidget().SetSort(sort);
1171 cont.SetEntity(item);
1172
1173 Insert(cont, -1);
1174
1175 m_AttachmentCargos.Insert(item, cont);
1176 if (m_Parent)
1177 m_Parent.Refresh();
1178 Inventory.GetInstance().UpdateConsoleToolbar();
1179 }
1180
1181 if (att_cont)
1182 {
1183 att_cont.ShowFalseAttachmentsHeader(true);
1184 if (cont)
1185 {
1186 cont.ShowFalseCargoHeader(false);
1187 cont.UpdateSize();
1188 cont.SetAlternateFalseTextHeaderWidget(att_cont.GetFalseHeaderTextWidget());
1189 }
1190 }
1191 else if (cont)
1192 {
1193 cont.SetAlternateFalseTextHeaderWidget(null); //just to be safe..
1194 }
1195
1196 RecomputeOpenedContainers();
1197 }
1198
1199 void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
1200 {
1202
1204 if (old_cont)
1205 {
1206 m_Body.RemoveItem(old_cont);
1207 m_AttachmentCargos.Remove(item);
1208 delete old_cont;
1209 if (m_Parent)
1210 m_Parent.Refresh();
1211 Inventory.GetInstance().UpdateConsoleToolbar();
1212 }
1213
1215 if (old_att_cont)
1216 {
1219 m_Body.RemoveItem(old_att_cont);
1220 delete old_att_cont;
1221 if (m_Parent)
1222 m_Parent.Refresh();
1223 Inventory.GetInstance().UpdateConsoleToolbar();
1224 }
1225 RecomputeOpenedContainers();
1226 }
1227
1228 override void UpdateInterval()
1229 {
1230 super.UpdateInterval();
1231
1232 if (m_Entity)
1233 {
1234 if (m_CargoGrid)
1235 {
1236 bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType(HIDE_INV_FROM_SCRIPT) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1237 if (m_CargoGrid.IsVisible() && hideCargo)
1238 HideCargo();
1239 else if (!m_CargoGrid.IsVisible() && !hideCargo)
1240 ShowCargo();
1241
1242 m_CargoGrid.UpdateInterval();
1243 }
1244
1245 if (m_Atts)
1246 m_Atts.UpdateInterval();
1247
1248 for (int i = 0; i < m_AttachmentCargos.Count(); i++)
1249 m_AttachmentCargos.GetElement(i).UpdateInterval();
1250 }
1251
1253 m_CollapsibleHeader.UpdateInterval();
1254 }
1255
1256 override void SetLayoutName()
1257 {
1258 m_LayoutName = WidgetLayoutName.ClosableContainer;
1259 }
1260
1261 override void OnShow()
1262 {
1263 super.OnShow();
1264
1265 for (int i = 0; i < m_Body.Count(); i++)
1266 m_Body.Get(i).OnShow();
1267 }
1268
1269 void MouseClick2(Widget w, int x, int y, int button)
1270 {
1271 string name = w.GetName();
1272 name.Replace("PanelWidget", "Render");
1273 ItemPreviewWidget itemPreview = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
1274
1275 if (itemPreview)
1276 {
1277 ItemBase selectedItem = ItemBase.Cast(itemPreview.GetItem());
1278
1279 if (selectedItem)
1280 {
1281 switch (button)
1282 {
1283 case MouseState.RIGHT:
1284#ifdef DIAG_DEVELOPER
1285 if (g_Game.IsLeftCtrlDown())
1286 ShowActionMenu(selectedItem);
1287#endif
1288
1289 break;
1290
1291 case MouseState.MIDDLE:
1293 break;
1294
1295 case MouseState.LEFT:
1297 if (g_Game.IsLeftCtrlDown())
1298 {
1299 if (controlledPlayer.CanDropEntity(selectedItem))
1300 {
1301 if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
1302 selectedItem.SplitIntoStackMaxClient(null, -1);
1303 else
1304 controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
1305 }
1306 else
1307 {
1308 bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem, null) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
1309 ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
1310 }
1311 }
1312
1313 break;
1314 }
1315 }
1316 }
1317 }
1318
1319 void DoubleClick(Widget w, int x, int y, int button)
1320 {
1321 if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
1322 {
1323 ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
1324 if (!iw)
1325 {
1326 string name = w.GetName();
1327 name.Replace("PanelWidget", "Render");
1328 iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
1329 }
1330
1331 if (!iw)
1332 iw = ItemPreviewWidget.Cast(w);
1333
1334 ItemBase item = ItemBase.Cast(iw.GetItem());
1335 if (item)
1336 {
1338 EntityAI itemInHands = controlledPlayer.GetHumanInventory().GetEntityInHands();
1339
1340 if (!item.GetInventory().CanRemoveEntity())
1341 return;
1342
1343 if (controlledPlayer.GetInventory().HasEntityInInventory(item) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
1344 controlledPlayer.PredictiveTakeEntityToHands(item);
1345 else
1346 {
1347 if (controlledPlayer.GetInventory().CanAddEntityToInventory(item) && controlledPlayer.GetHumanInventory().CanRemoveEntityInHands())
1348 controlledPlayer.PredictiveTakeEntityToInventory(FindInventoryLocationType.ANY, item);
1349 else
1350 {
1351 if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
1352 controlledPlayer.PredictiveTakeEntityToHands(item);
1353 }
1354 }
1355
1356 HideOwnedTooltip();
1357
1358 name = w.GetName();
1359 name.Replace("PanelWidget", "Temperature");
1360 w.FindAnyWidget(name).Show(false);
1361 }
1362 }
1363 }
1364
1366 {
1368 }
1369
1371 {
1372 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
1373 if (item_in_hands && item_in_hands.GetCompEM())
1374 {
1375 if (GetRootWidget().FindAnyWidget("electricity"))
1376 {
1377 bool show_electricity_icon = item_in_hands.GetCompEM().HasElectricityIcon();
1378 GetRootWidget().FindAnyWidget("electricity").Show(show_electricity_icon);
1379 }
1380
1381 if (GetRootWidget().FindAnyWidget("electricity_can_work"))
1382 {
1383 bool show_electricity_can_work_icon = item_in_hands.GetCompEM().CanWork() && !item_in_hands.IsRuined();
1384 GetRootWidget().FindAnyWidget("electricity_can_work").Show(show_electricity_can_work_icon);
1385 }
1386 }
1387 else
1388 GetRootWidget().FindAnyWidget("electricity").Show(false);
1389 }
1390
1392 {
1393 int i;
1394 if (!m_Hidden)
1395 {
1396 for (i = 0; i < m_Body.Count(); i++)
1397 m_Body.Get(i).OnHide();
1398 m_Hidden = true;
1399 }
1400 else
1401 {
1402 for (i = 0; i < m_Body.Count(); i++)
1403 m_Body.Get(i).OnShow();
1404 m_Hidden = false;
1405 }
1406
1407 w.FindAnyWidget("opened").Show(m_Hidden);
1408 w.FindAnyWidget("closed").Show(!m_Hidden);
1409
1410 m_Parent.Refresh();
1411 }
1412
1414 {
1415 if (m_CargoGrid)
1416 {
1417 m_CargoGrid.OnHide();
1418 RecomputeOpenedContainers();
1419 }
1420 }
1421
1423 {
1424 if (m_CargoGrid)
1425 {
1426 m_CargoGrid.OnShow();
1427 RecomputeOpenedContainers();
1428 }
1429 }
1430}
void Inventory(LayoutHolder parent)
Definition Inventory.c:76
EntityAI m_Entity
Definition ActionDebug.c:11
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
DayZGame g_Game
Definition DayZGame.c:3528
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
override ContextMenu GetContextMenu()
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition ItemBase.c:5528
bool m_IsActive
PlayerBase GetPlayer()
PluginBase GetPlugin(typename plugin_type)
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
DayZPlayer m_player
Widget m_Parent
Definition SizeToChild.c:86
void SetActive()
Definition TrapBase.c:409
represents base for cargo storage for entities
Definition Cargo.c:7
Super root of all classes in Enforce script.
Definition EnScript.c:11
static int BASE_COLOR
static int COMBINE_COLOR
static int SWAP_COLOR
static int GREEN_COLOR
static int RED_COLOR
static ColorManager GetInstance()
override EntityAI GetFocusedItem()
override bool Select()
void CargoContainer(LayoutHolder parent, bool is_attachment=false)
WeaponManager GetWeaponManager()
script counterpart to engine's class Inventory
Definition Inventory.c:79
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:610
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
ref map< EntityAI, ref CargoContainer > m_AttachmentCargos
void DropReceived(Widget w, int x, int y, CargoContainer cargo)
override bool InspectItem()
ref map< EntityAI, AttachmentsWrapper > m_AttachmentAttachmentsContainers
void ShowAtt(EntityAI entity)
void ScrollToActiveContainer(Container active_container)
ref map< EntityAI, ref Attachments > m_AttachmentAttachments
override bool TransferItem()
void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
void DoubleClick(Widget w, int x, int y, int button)
void OnPerformCombination(int combinationFlags)
int GetRecipeCount(bool recipe_anywhere, EntityAI entity1, EntityAI entity2)
void DraggingOverHeader2(Widget w, int x, int y, Widget receiver)
ref HandsHeader m_CollapsibleHeader
override bool IsEmpty()
override bool OnSelectButton()
override bool TransferItemToVicinity()
EntityAI GetItemPreviewItem(Widget w)
void ShowActionMenuCombine(EntityAI entity1, EntityAI entity2, int combinationFlags)
ScrollWidget m_ScrollWidget
override bool IsLastIndex()
override void SetLayoutName()
override void SetLastActive()
ref HandsPreview m_HandsPreview
override void UpdateInterval()
void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
bool DraggingOverGrid(Widget w, int x, int y, Widget reciever, CargoContainer cargo)
override bool EquipItem()
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
ref Attachments m_Atts
override bool IsItemWithQuantityActive()
void TakeAsAttachment(Widget w, Widget receiver)
void OnDropReceivedFromHeader2(Widget w, int x, int y, Widget receiver)
void HandsContainer(LayoutHolder parent)
override Header GetHeader()
override void UnfocusGrid()
override void Refresh()
void CollapseButtonOnMouseButtonDown(Widget w)
ref CargoContainer m_CargoGrid
int GetCombinationFlags(EntityAI entity1, EntityAI entity2)
override void UnfocusAll()
override void Insert(LayoutHolder container, int pos=-1, bool immedUpdate=true)
void MouseClick2(Widget w, int x, int y, int button)
override void OnShow()
override void SetActive(bool active)
override bool SplitItem()
override bool IsItemActive()
ref array< int > m_AttachmentSlotsSorted
Definition Header.c:2
Definition Icon.c:2
InventoryLocation.
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static ItemManager GetInstance()
static int HasItemQuantity(notnull EntityAI item)
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
bool CanAttachMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
bool AttachMagazine(Magazine mag, ActionBase control_action=NULL)
bool LoadBullet(Magazine mag, ActionBase control_action=NULL)
bool CanSwapMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
bool SwapMagazine(Magazine mag, ActionBase control_action=NULL)
const string ClosableContainer
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:344
MouseState
Definition EnSystem.c:311
proto void GetMousePos(out int x, out int y)
WidgetFlags
Definition EnWidgets.c:58
proto native Widget FindAnyWidget(string pathname)