DayZ 1.24
Loading...
Searching...
No Matches
VicinityContainer.c
Go to the documentation of this file.
2{
8 protected bool m_IsProcessing = false; // Prevents refreshing every time a child is added while it is still processing
9
10 const float DISTANCE_TO_ENTITIES = 1.0;
11 const float DISTANCE_TO_THE_REST = 0.5;
12
13 void VicinityContainer(LayoutHolder parent, int sort = -1)
14 {
16 m_Body.Insert(m_VicinityIconsContainer);
17 m_VicinityIconsContainer.GetRootWidget().SetColor(166 << 24 | 120 << 16 | 120 << 8 | 120);
18 m_MainWidget = m_RootWidget.FindAnyWidget("body");
19 WidgetEventHandler.GetInstance().RegisterOnChildAdd(m_MainWidget, this, "OnChildAdd");
20 WidgetEventHandler.GetInstance().RegisterOnChildRemove(m_MainWidget, this, "OnChildRemove");
21
22 RecomputeOpenedContainers();
23 m_CollapsibleHeader.SetName("#container_vicinity");
25 }
26
28 {
29 return m_VicinityIconsContainer.IsActive();
30 }
31
36
38 {
39 return (ContainerWithCargo.Cast(GetFocusedContainer()) != null);
40 }
41
43 {
44 return (ContainerWithCargoAndAttachments.Cast(GetFocusedContainer()) != null);
45 }
46
48 {
49 return (AttachmentCategoriesContainer.Cast(GetFocusedContainer()) != null);
50 }
51
53 {
55 for (int i = 0; i < m_ShowedItems.Count(); i++)
56 {
58 Container container = m_ShowedItems.GetElement(i);
59 string type = entity.GetType();
60 if (container.IsInherited(ContainerWithCargo))
61 {
62 if (!serialized_types.Contains(type))
63 {
64 ContainerWithCargo item_with_cargo = ContainerWithCargo.Cast(container);
65 serialized_types.Insert(type, item_with_cargo.IsOpened());
66 }
67 }
68 }
69
70 if (serialized_types.Count() > 0)
71 {
73 if (file.Open("inventory_state.save", FileMode.APPEND))
74 {
75 file.Write(serialized_types.Count());
76
77 for (i = 0; i < serialized_types.Count(); i++)
78 {
79 file.Write(serialized_types.GetKey(i));
80 file.Write(serialized_types.GetElement(i));
81 }
82 }
83 file.Close();
84 }
85 }
86
87 override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
88 {
89 if (w == null)
90 return;
91
92 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
93 if (!ipw)
94 {
95 string name = w.GetName();
96 name.Replace("PanelWidget", "Render");
97 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
98 }
99
100 if (!ipw && ItemPreviewWidget.Cast(w))
101 ipw = ItemPreviewWidget.Cast(w);
102
103 if (!ipw || !ipw.GetItem())
104 return;
105
106 if (ipw.GetItem() && GetGame().GetPlayer().CanDropEntity(ipw.GetItem()) && ipw.GetItem().GetInventory().CanRemoveEntity() && m_ShowedItemIcons.Find(ipw.GetItem()) == -1)
107 {
109 ItemManager.GetInstance().HideDropzones();
110 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
111 }
112 else
113 {
115 ItemManager.GetInstance().ShowSourceDropzone(ipw.GetItem());
116 }
117 }
118
120 {
121 string name = receiver.GetName();
122 name.Replace("PanelWidget", "Render");
125
126 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
127 if (!ipw)
128 {
129 name = w.GetName();
130 name.Replace("PanelWidget", "Render");
131 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
132 }
133
134 if (!ipw && ItemPreviewWidget.Cast(w))
135 ipw = ItemPreviewWidget.Cast(w);
136
137 if (!ipw)
138 return;
139
140 if (!ItemBase.Cast(receiver_item) || !ipw.GetItem())
141 return;
142
143 if (ipw.GetItem().GetInventory().CanRemoveEntity() || m_ShowedItemIcons.Find(ipw.GetItem()) > -1)
144 {
145 if ((ItemBase.Cast(receiver_item)).CanBeCombined(ItemBase.Cast(ipw.GetItem())))
146 {
148 ItemManager.GetInstance().HideDropzones();
149 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
150 return;
151 }
153 {
155 ItemManager.GetInstance().HideDropzones();
156 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
157 return;
158 }
159 /*else if( GetGame().GetPlayer().CanDropEntity( ipw.GetItem() ) )
160 {
161 ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
162 ItemManager.GetInstance().HideDropzones();
163 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
164 return;
165 }*/
166 }
167
169 ItemManager.GetInstance().ShowSourceDropzone(ipw.GetItem());
170 }
171
173 {
174 string name = receiver.GetName();
175 name.Replace("PanelWidget", "Render");
178
179 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
180 if (!ipw)
181 {
182 name = w.GetName();
183 name.Replace("PanelWidget", "Render");
184 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
185 }
186
187 if (!ItemBase.Cast(receiver_item) || !ipw.GetItem())
188 return;
189
190 EntityAI item = ipw.GetItem();
191 bool equal_typed = item.GetType() == receiver_item.GetType();
192 if (!receiver_item.IsInherited(ItemBase) || item == null)
193 return;
194
196
197 if (!item.GetInventory().CanRemoveEntity())
198 return;
199
200 if ((ItemBase.Cast(receiver_item)).CanBeCombined(ItemBase.Cast(item)))
203 {
206 receiver_item.GetInventory().GetCurrentInventoryLocation(il1);
207 item.GetInventory().GetCurrentInventoryLocation(il2);
208
209 if (!receiver_item.GetInventory().CanRemoveEntity() || (il1.GetType() == InventoryLocationType.GROUND && il2.GetType() == InventoryLocationType.GROUND))
210 return;
211 player.PredictiveSwapEntities(item, receiver_item);
212 }
213
214 ItemManager.GetInstance().HideDropzones();
215 ItemManager.GetInstance().SetIsDragging(false);
216 PrepareOwnedTooltip(item);
217
218 InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
219 if (menu)
220 menu.RefreshQuickbar();
221 }
222
227
232
234 {
235 if (!w)
236 return;
237
238 ItemManager.GetInstance().HideDropzones();
239 ItemManager.GetInstance().SetIsDragging(false);
240
241 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
242
243 if (!ipw)
244 {
245 string name = w.GetName();
246 name.Replace("PanelWidget", "Render");
247 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
248 }
249
250 if (!ipw)
251 {
252 ipw = ItemPreviewWidget.Cast(w);
253 if (!ipw)
254 return;
255 }
256
257 EntityAI item = ipw.GetItem();
258 if (!ipw.IsInherited(ItemPreviewWidget) || !item)
259 return;
260
261 if (!item.GetInventory().CanRemoveEntity() || m_ShowedItemIcons.Find(item) > -1)
262 return;
263
265 if (player.CanDropEntity(item))
266 {
268 if (itemBase)
269 {
270 if (itemBase.GetTargetQuantityMax() < itemBase.GetQuantity())
271 itemBase.SplitIntoStackMaxClient(null, -1);
272 else
273 player.PhysicalPredictiveDropItem(itemBase);
274 }
275 }
276
277 InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
278 if (menu)
279 menu.RefreshQuickbar();
280 }
281
282 override void UpdateInterval()
283 {
285
286 if (!player)
287 return;
288
289 super.UpdateInterval();
290
292 vector pos = player.GetPosition();
294
295 VicinityItemManager.GetInstance().Update(player.GetDeltaT());
296 objects = VicinityItemManager.GetInstance().GetVicinityItems();
297
298 //GetItemsShowableInInventory
301 m_ShowedItemIcons.Clear();
302
303 GameInventory game_inventory = player.GetInventory();
304 for (int i = 0; i < objects.Count(); i++)
305 {
306 eai = objects.Get(i);
307 if (eai == null || game_inventory.IsPlaceholderEntity(eai))
308 continue; // noproxy: ignore body placeholder
309
311 if (base_building && !base_building.IsPlayerInside(player, ""))
312 continue;
313
314 if (eai.IsInventoryVisible())
315 {
316 showable_items.Insert(eai);
317
318 if (!eai.IsInherited(DayZInfected) && !eai.IsInherited(PlayerBase) && !eai.IsInherited(AnimalBase) && !eai.DisableVicinityIcon())
319 m_ShowedItemIcons.Insert(eai);
320 }
321 }
322
323
324 //MW HOTFIX - old containers must be removed before new one are added (part of initialize are refreshed whole structure - need proper fix to avoid it)
327
328 for (i = 0; i < showable_items.Count(); i++)
330
331
332 bool need_update_focus = false;
333 for (i = 0; i < m_ShowedItems.Count(); i++)
334 {
335 EntityAI ent = m_ShowedItems.GetKey(i);
336 m_ShowedItems.GetElement(i).UpdateInterval();
337 con = m_ShowedItems.GetElement(i);
338 if (!new_showed_items.Contains(ent))
339 {
340 GetMainWidget().Update();
341 if (con.IsActive())
342 need_update_focus = true;
343 Container.Cast(GetParent()).Remove(con);
344 Remove(con);
345 }
346 else
347 {
348 UpdateHeader(ent, con, player); //squeezed here, the map is iterated over enough already..
349 }
350 }
352
353 bool accessInventory = PlayerBase.DEBUG_INVENTORY_ACCESS;
354 accessInventory |= FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive();
355
356
357 //ref map<EntityAI, ref Container> new_showed_items = new ref map<EntityAI, ref Container>;
358 new_showed_items.Clear();
360 for (i = 0; i < showable_items.Count(); i++)
361 {
363 if (entity)
364 {
365 if (game_inventory && !m_ShowedItems.Contains(entity))
366 {
367 string config = "CfgVehicles " + entity.GetType() + " GUIInventoryAttachmentsProps";
368
369 if (GetGame().ConfigIsExisting(config))
370 {
372 ac.SetEntity(entity);
373 new_showed_items.Insert(entity, ac);
374 showed_items_IDs.Insert(entity.GetID(), ac);
375 }
376 else if (entity.GetSlotsCountCorrect() > 0 && entity.GetInventory().GetCargo())
377 {
378 if (entity.IsInherited(DayZInfected))
379 {
380 if (entity.IsAlive())
381 continue;
383 zmb_cnt.SetEntity(entity);
385 showed_items_IDs.Insert(entity.GetID(), zmb_cnt);
386 Container.Cast(GetParent()).Insert(zmb_cnt);
387 }
388 else
389 {
390 ContainerWithCargoAndAttachments iwca = new ContainerWithCargoAndAttachments(this, -1);
391 iwca.SetEntity(entity, false);
393 showed_items_IDs.Insert(entity.GetID(), iwca);
394 }
395 }
396 else if (entity.GetInventory().GetCargo())
397 {
398 ContainerWithCargo iwc = new ContainerWithCargo(this, -1);
399 iwc.SetEntity(entity, 0, false);
400 new_showed_items.Insert(entity, iwc);
401 showed_items_IDs.Insert(entity.GetID(), iwc);
402 iwc.UpdateInterval();
403 }
404 else if (entity.GetSlotsCountCorrect() > 0)
405 {
406 if (entity.HasEnergyManager())
407 {
409 iwem.SetEntity(entity, false);
411 showed_items_IDs.Insert(entity.GetID(), iwem);
412 }
413 else
414 {
415 if (entity.IsInherited(PlayerBase))
416 {
418 if (accessInventory == false)
419 {
420 if (entity.IsAlive() && (!PlayerBase.Cast(entity).IsUnconscious() && !PlayerBase.Cast(entity).IsRestrained()))
421 continue;
422 }
423
425 plyr_cnt.SetPlayer(PlayerBase.Cast(entity));
426 Container.Cast(GetParent()).Insert(plyr_cnt);
427 (Container.Cast(m_Parent)).Refresh();
429 showed_items_IDs.Insert(entity.GetID(), plyr_cnt);
430 }
431 else
432 {
433 ContainerWithCargoAndAttachments iwcas = new ContainerWithCargoAndAttachments(this, -1);
434 iwcas.SetEntity(entity, false);
436 showed_items_IDs.Insert(entity.GetID(), iwcas);
437 iwcas.UpdateInterval();
438 }
439 }
440 }
441 }
442 else
443 {
444 //TODO MW: remove old containers on one spot (hotfix)
445 con = m_ShowedItems.Get(entity);
446 if (con)
447 {
448 if (entity.IsInherited(PlayerBase))
449 {
451 if (!accessInventory && entity.IsAlive() && (!PlayerBase.Cast(entity).IsUnconscious() && !PlayerBase.Cast(entity).IsRestrained()))
452 {
453 GetMainWidget().Update();
454 if (con.IsActive())
455 need_update_focus = true;
456 Container.Cast(GetParent()).Remove(con);
457 Remove(con);
458 continue;
459 }
460 }
461
462 if (entity.IsInherited(BaseBuildingBase))
463 {
465 {
466 GetMainWidget().Update();
467 if (con.IsActive())
468 need_update_focus = true;
469 Container.Cast(GetParent()).Remove(con);
470 Remove(con);
471 continue;
472 }
473 }
474
476 showed_items_IDs.Insert(entity.GetID(), m_ShowedItemsIDs.Get(entity.GetID()));
477 }
478 }
479 }
480 }
481
483 auto cargoes = VicinityItemManager.GetInstance().GetVicinityCargos();
484 for (i = 0; i < cargoes.Count(); i++)
485 {
486 CargoBase cgo = cargoes.Get(i);
487 if (cgo)
488 {
489 if (game_inventory && !m_ShowedCargos.Contains(cgo))
490 {
491 ContainerWithCargo pxc = new ContainerWithCargo(this, -1);
492 pxc.SetEntity(cgo.GetCargoOwner(), cgo.GetOwnerCargoIndex(), false);
493 new_showed_cargos.Insert(cgo, pxc);
494 pxc.UpdateInterval();
495 }
496 else
497 {
498 if (m_ShowedCargos.Get(cgo))
500 }
501 }
502 }
503
504 for (int ic = 0; ic < m_ShowedCargos.Count(); ic++)
505 {
507 m_ShowedCargos.GetElement(ic).UpdateInterval();
508 if (!new_showed_cargos.Contains(cgo2))
509 {
510 Container con2 = m_ShowedCargos.GetElement(ic);
511 if (con2.IsActive())
512 need_update_focus = true;
513 GetMainWidget().Update();
514 Container.Cast(GetParent()).Remove(con2);
515 Remove(con2);
516 }
517 }
518
522 //Because WTF (zombie container)
523 Container.Cast(GetParent()).RecomputeOpenedContainers();
525 SetFirstActive();
526 //RecomputeOpenedContainers();
528 m_VicinityIconsContainer.ShowItemsInContainers(m_ShowedItemIcons);
529
531 {
532 Inventory in = Inventory.Cast(GetRoot());
533 if (in)
534 in.UpdateConsoleToolbar();
535 }
536 }
537
539 {
541 Container c;
542 w.GetUserData(slots_icon);
543
544 if (item)
545 c = Container.Cast(m_ShowedItems.Get(item));
546
547 if (c)
549 }
550
552 {
553 if (focusedEntity)
554 {
556 if (c && c.IsDisplayable())
557 return true;
558 }
559 return false;
560 }
561
562 //Call from ExpandCollapseContainer - not call
564 {
565 conta.Toggle();
566 }
567
569 {
572
573 if (m_ShowedItems && item)
574 {
575 conta = m_ShowedItems.Get(item);
576 if (conta)
578 }
579 }
580
582 {
583 w.Update();
584 float x, y;
585 w.GetScreenSize(x, y);
586 if (w == GetMainWidget())
587 {
588 GetMainWidget().Update();
589 m_Parent.OnChildRemove(w, child);
590 }
591 return true;
592 }
593
595 {
596 if (w == GetMainWidget())
597 {
598 GetMainWidget().Update();
599 m_Parent.OnChildAdd(w, child);
600 }
601 return true;
602 }
603
605 {
606 super.CollapseButtonOnMouseButtonDown(w);
607 ItemManager.GetInstance().SetDefaultHeaderOpenState("VICINITY", !m_Hidden);
608 }
609
612 {
613 bool draggable = ItemManager.GetInstance().EvaluateContainerDragabilityDefault(entity);
614
615 if (cont.GetHeader())
616 {
617 if (GetDragWidget() == cont.GetHeader())
619 ItemManager.GetInstance().SetWidgetDraggable(cont.GetHeader().GetMainWidget(), draggable);
620 }
621 }
622
623 override bool SplitItem()
624 {
625 if (CanSplit())
626 {
628 if (item)
629 {
630 if (item.HasQuantity() && item.CanBeSplit())
631 item.OnRightClick();
632 }
633 }
634 return false;
635 }
636}
void Inventory(LayoutHolder parent)
Definition Inventory.c:76
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Icon x
Icon y
InventoryLocationType
types of Inventory Location
void InventoryMenu()
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition ItemBase.c:5528
PlayerBase GetPlayer()
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Widget m_Parent
Definition SizeToChild.c:86
override bool IsPlayerInside(PlayerBase player, string selection)
Definition Fence.c:577
represents base for cargo storage for entities
Definition Cargo.c:7
override void Remove(LayoutHolder container)
ref CollapsibleHeader m_CollapsibleHeader
static int COMBINE_COLOR
static int SWAP_COLOR
static int GREEN_COLOR
static int RED_COLOR
static ColorManager GetInstance()
override EntityAI GetFocusedItem()
Serializer API implementation for File IO. See Serializer for more info. usage:
Definition Serializer.c:104
script counterpart to engine's class Inventory
Definition Inventory.c:79
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:610
InventoryLocation.
static ItemManager GetInstance()
override bool OnChildAdd(Widget w, Widget child)
void OnDropReceivedFromEmptySpace(Widget w, int x, int y, Widget receiver)
override bool SplitItem()
override void CollapseButtonOnMouseButtonDown(Widget w)
const float DISTANCE_TO_THE_REST
void UpdateHeader(EntityAI entity, Container cont, PlayerBase player)
Updates header dragability to be consistent with current 'icon' behaviour.
void OnLeftPanelDropReceived(Widget w, int x, int y, Widget receiver)
ref VicinitySlotsContainer m_VicinityIconsContainer
ref map< int, ref Container > m_ShowedItemsIDs
override bool OnChildRemove(Widget w, Widget child)
override void UpdateInterval()
ref map< CargoBase, ref Container > m_ShowedCargos
bool IsVicinityContainerIconsActive()
void OnDropReceivedFromIcon(Widget w, int x, int y, Widget receiver)
void VicinityContainer(LayoutHolder parent, int sort=-1)
ref array< EntityAI > m_ShowedItemIcons
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
const float DISTANCE_TO_ENTITIES
void DraggingOverIcon(Widget w, int x, int y, Widget receiver)
ref map< EntityAI, ref Container > m_ShowedItems
void ToggleContainer(Widget w, EntityAI item)
void ToggleContainer(notnull Container conta)
override void ExpandCollapseContainer()
VicinitySlotsContainer GetVicinityIconsContainer()
override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
static VicinityItemManager GetInstance()
static WidgetEventHandler GetInstance()
proto native CGame GetGame()
FileMode
Definition EnSystem.c:383
const int MENU_INVENTORY
Definition constants.c:170
proto native Widget GetParent()
Get parent of the Effect.
Definition Effect.c:389
proto native Widget CancelWidgetDragging()
proto native Widget GetDragWidget()