DayZ 1.24
Loading...
Searching...
No Matches
VicinitySlotsContainer.c
Go to the documentation of this file.
2{
4 protected int m_ItemsCount;
5 protected int m_SlotsCount;
7
9 {
12 m_Container.Insert(con);
13 m_Body.Insert(m_Container);
14 for (int j = 0; j < ITEMS_IN_ROW; j++)
15 {
16 SlotsIcon icon = con.GetSlotIcon(j);
17 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetPanelWidget(), m_Parent, "OnDropReceivedFromIcon");
18 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetGhostSlot(), m_Parent, "OnDropReceivedFromHeader");
19 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader");
20
21 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetPanelWidget(), m_Parent, "DraggingOverIcon");
22 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetGhostSlot(), m_Parent, "DraggingOverHeader");
23 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetMainWidget(), m_Parent, "DraggingOverHeader");
24
25 WidgetEventHandler.GetInstance().RegisterOnDoubleClick(icon.GetPanelWidget(), this, "DoubleClick");
26 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(), this, "MouseClick");
27 WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown(icon.GetPanelWidget(), this, "MouseButtonDown");
28 }
29
30 con.SetColumnCount(0);
31 con.SetForceShow(true);
32
33 WidgetEventHandler.GetInstance().RegisterOnDropReceived(m_Container.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader");
34 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(m_Container.GetMainWidget(), m_Parent, "DraggingOverHeader");
35
37 }
38
40 {
42 return ent && (ent.GetInventory().GetCargo() || (ent.GetSlotsCountCorrect() > 0 && ent.CanDisplayAnyAttachmentSlot()));
43 //TODO: also check for cargo visibility maybe?
44 }
45
47 {
49 return ent && QuantityConversions.HasItemQuantity(ent) && ent.CanBeSplit();
50 }
51
52 override bool IsItemActive()
53 {
56 }
57
59 {
61 return ent == null;
62 }
63
64 //TODO MW Adjust this
65 override bool IsDisplayable()
66 {
67 return true;
68 }
69
71 {
73 return ent.IsTakeable();
74 }
75
76 override bool CanCombineAmmo()
77 {
80 ItemBase item_in_hands = ItemBase.Cast(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
82 Class.CastTo(amc, m_player.GetActionManager());
83
84 return (amc.CanPerformActionFromInventory(item_in_hands, ent) || amc.CanSetActionFromInventory(item_in_hands, ent));
85 }
86
87 override bool EquipItem()
88 {
89 if (CanEquip())
90 {
92 bool res = false;
93
94 if (ent && !ent.IsInherited(Magazine))
95 {
96 res = GetGame().GetPlayer().PredictiveTakeOrSwapAttachment(ent);
97 if (!res)
98 res = GetGame().GetPlayer().GetInventory().TakeEntityToInventory(InventoryMode.JUNCTURE, FindInventoryLocationType.ATTACHMENT, ent);
99 }
100 return res;
101 }
102 return false;
103 }
104
105 override bool InspectItem()
106 {
108
109 if (ent)
110 {
112 return true;
113 }
114 return false;
115 }
116
117 override bool TransferItem()
118 {
119 if (CanTakeToInventory())
120 {
122 if (ent)
123 {
124 if (ent.IsTakeable())
125 {
127 GetGame().GetPlayer().GetInventory().FindFreeLocationFor(ent, FindInventoryLocationType.CARGO, il);
128 if (il.IsValid() && GetGame().GetPlayer().GetInventory().LocationCanAddEntity(il))
129 {
131 return true;
132 }
133 }
134 }
135 }
136 return false;
137 }
138
139 override bool Combine()
140 {
142
143 ItemBase item_in_hands = ItemBase.Cast(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
144
145 Icon hands_icon = ItemManager.GetInstance().GetHandsPreview().GetIcon();
146
147 if (item_in_hands && ent && hands_icon)
148 return hands_icon.CombineItems(item_in_hands, ent);
149 return false;
150 }
151
152 override bool Select()
153 {
154 SlotsIcon selected_slot = ItemManager.GetInstance().GetSelectedIcon();
156 ItemBase selected_item = ItemBase.Cast(ItemManager.GetInstance().GetSelectedItem());
157
158 if (!(selected_slot && selected_slot.IsOutOfReach()))
159 {
160 if (selected_item)
161 {
162 if (ent != selected_item)
163 {
164 if (selected_item && GetGame().GetPlayer().CanDropEntity(selected_item))
165 {
166 bool draggable = false;
167
169 draggable = !player.GetInventory().HasInventoryReservation(selected_item, null) && !player.IsItemsToDelete();
170 draggable = draggable && selected_item.GetInventory().CanRemoveEntity();
171
172 if (draggable && m_ShowedItems.Find(selected_item) == -1)
173 {
174 if (selected_item.GetTargetQuantityMax() < selected_item.GetQuantity())
175 selected_item.SplitIntoStackMaxClient(null, -1);
176 else
177 player.PhysicalPredictiveDropItem(selected_item);
178 ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
179 return true;
180 }
181 }
182 }
183 }
184 else
185 {
186 if (ent && ent.GetInventory().CanRemoveEntity())
187 {
188 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
189 if (item_in_hands)
190 {
192 {
193 GetGame().GetPlayer().PredictiveSwapEntities(item_in_hands, ent);
194 return true;
195 }
196 }
197 else
198 {
199 if (GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands(ent))
200 {
201 GetGame().GetPlayer().PredictiveTakeEntityToHands(ent);
202 return true;
203 }
204 }
205 }
206 }
207 }
208
209 return false;
210 }
211
213 {
214 for (int i = 0; i < m_Container.Count(); i++)
215 {
217 if (c && c.GetMainWidget())
218 delete m_Container.Get(i / ITEMS_IN_ROW).GetMainWidget();
219 }
220 }
221
222 override void SetLayoutName()
223 {
224 m_LayoutName = WidgetLayoutName.Container;
225 }
226
227 override void OnShow()
228 {
229 super.OnShow();
230 }
231
233 {
234 return GetFocusedContainer().GetColumnCount();
235 }
236
239 {
240 int mask = item.GetHideIconMask();
241 return mask & EInventoryIconVisibility.HIDE_VICINITY;
242 }
243
245 {
248 int x;
249 int visible_items_count = 0;
250 int visible_rows = 0;
252
253 for (x = 0; x < items.Count(); ++x)
254 {
255 item = items.Get(x);
256
258 continue;
259
260 visible_items.Insert(item);
262 }
263
265
266 for (x = 0; x < visible_items_count; ++x)
267 {
268 item = visible_items.Get(x);
269 int row = (int)Math.Floor(x / ITEMS_IN_ROW);
270 int column = x % ITEMS_IN_ROW;
271 icon = SlotsContainer.Cast(m_Container.Get(row)).GetSlotIcon(column);
272
273 icon.GetMainWidget().Show(true);
274 icon.GetPanelWidget().SetUserID(item.GetID());
275
276 if (m_ShowedItems.Find(item) != x)
277 icon.Init(item);
278 icon.UpdateInterval();
279
280 if (!ItemManager.GetInstance().IsDragging())
281 ItemManager.GetInstance().SetTemperature(item, icon.GetRender());
282
283 bool draggable = ItemManager.GetInstance().EvaluateContainerDragabilityDefault(item);
284 if (!draggable && GetDragWidget() == icon.GetPanelWidget())
286 ItemManager.GetInstance().SetWidgetDraggable(icon.GetPanelWidget(), draggable);
287
289
290 Container conta = Container.Cast(showed_items.Get(item.GetID()));
291 if (conta)
292 conta.SetSlotIcon(icon);
293
294 if (conta && conta.IsDisplayable())
295 conta.UpdateRadialIcon();
296 else
297 {
298 icon.GetRadialIconPanel().Show(false);
299 if (conta)
300 conta.OnHide();
301 }
302 }
303
305
307 {
308 icon = slots_last.GetSlotIcon(c);
309 icon.GetMainWidget().Show(false);
310 icon.Clear();
311 }
312
313 //#ifndef PLATFORM_CONSOLE
315 {
316 slots_last = SlotsContainer.Cast(m_Container.Get(m_Container.Count() - 1));
317 slots_last.GetSlotIcon(0).GetMainWidget().Show(true);
318 slots_last.GetSlotIcon(0).GetGhostSlot().Show(false);
319 slots_last.GetMainWidget().Update();
320 }
321 //#endif
322
324 }
325
326 void DoubleClick(Widget w, int x, int y, int button)
327 {
328 if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
329 {
330 if (w == null)
331 return;
332 ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
333 if (!iw)
334 {
335 string name = w.GetName();
336 name.Replace("PanelWidget", "Render");
337 iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
338 }
339
340 if (!iw)
341 iw = ItemPreviewWidget.Cast(w);
342
343 ItemBase item = ItemBase.Cast(iw.GetItem());
344 if (!item)
345 return;
346
347 if (!item.IsTakeable())
348 return;
349
350 if (GetGame().GetPlayer().GetInventory().HasInventoryReservation(item, null))
351 return;
352
353 if (!item.GetInventory().CanRemoveEntity())
354 return;
355
357
358 if (player.GetInventory().HasEntityInInventory(item) && GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands(item))
359 player.PredictiveTakeEntityToHands(item);
360 else
361 {
363 player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ANY, dst);
364 if (dst.IsValid() && player.GetInventory().LocationCanAddEntity(dst))
366 }
367
368 HideOwnedTooltip();
369 InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
370 if (menu)
371 menu.RefreshQuickbar();
372 }
373 }
374
376 {
377 string quantity_text = "";
378 if (item.IsInherited(InventoryItem))
379 {
381 float quantity = item_base.GetQuantity();
382 int ammo;
383 if (item.IsInherited(Magazine))
384 {
386 ammo = magazine_item.GetAmmoCount();
387 quantity_text = ammo.ToString();
388 return quantity_text;
389 }
390 else if (item.IsInherited(ItemBook))
391 return "";
392 int max = item.GetQuantityMax();
393 //string unit = item.ConfigGetString( "stackedUnit" );
394
395 if (max > 0)
396 {
397 if (max == 1)
398 {
399 float tmp = Math.Round((quantity / max) * 100);
400 quantity_text = tmp.ToString() + "%";
401 }
402 else
403 quantity_text = quantity.ToString();
404 }
405 }
406 return quantity_text;
407 }
408
410 {
411 if (item.IsInherited(InventoryItem))
412 {
414 if (item.IsInherited(Magazine))
415 return QUANTITY_COUNT;
416 else if (item.IsInherited(ItemBook))
417 return QUANTITY_HIDDEN;
418 int max = item.GetQuantityMax();
419 bool bar = item.ConfigGetBool("quantityBar");
420 if (max > 0)
421 {
422 if (max == 1 || bar)
423 return QUANTITY_PROGRESS;
424 else
425 return QUANTITY_COUNT;
426 }
427 }
428 return QUANTITY_HIDDEN;
429 }
430
432 {
433 float quantity = 0;
434 if (item.IsInherited(InventoryItem))
435 {
437 if (item.IsInherited(Magazine))
438 {
440 quantity = magazine_item.GetAmmoCount();
441 }
442 else
443 quantity = item_base.GetQuantity();
444 }
445 return quantity;
446 }
447
448 // Mouse button DOWN
449 void MouseButtonDown(Widget w, int x, int y, int button)
450 {
451 string name = w.GetName();
452 name.Replace("PanelWidget", "Render");
454 ItemBase item = ItemBase.Cast(item_preview.GetItem());
455 bool draggable = ItemManager.GetInstance().EvaluateContainerDragabilityDefault(item);
456 ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
457 }
458
459 // Mouse button UP <---- exist button down MouseButtonDown ^
460 void MouseClick(Widget w, int x, int y, int button)
461 {
462 string name = w.GetName();
463 name.Replace("PanelWidget", "Render");
465 EntityAI item = item_preview.GetItem();
468
469#ifdef DIAG_DEVELOPER
470 if (ItemBase.Cast(item))
471 {
472 if (GetDayZGame().IsLeftCtrlDown() && button == MouseState.RIGHT)
473 ShowActionMenu(ItemBase.Cast(item));
474 }
475#endif
476
477 if (m_Parent)
478 {
480
481 if (item && showed_items)
482 {
483 conta = showed_items.Get(item.GetID());
484
485 (VicinityContainer.Cast(m_Parent)).ToggleContainer(w, item);
486 if (button == MouseState.RIGHT)
487 {
488 if (itemAtPos)
489 itemAtPos.OnRightClick();
490 }
491 else if (button == MouseState.MIDDLE)
492 {
494 return;
495 }
496 }
497 }
498 }
499
501 {
502 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
503 if (!ipw)
504 {
505 string name = w.GetName();
506 name.Replace("PanelWidget", "Render");
507 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
508 }
509 if (!ipw)
510 ipw = ItemPreviewWidget.Cast(w);
511
512 if (!ipw.IsInherited(ItemPreviewWidget))
513 return;
514
516 ItemBase item = ItemBase.Cast(ipw.GetItem());
517
518 if (item)
519 {
520 if (!item.GetInventory().CanRemoveEntity())
521 return;
522
523 if (player.CanDropEntity(item))
524 {
525 if (item.GetTargetQuantityMax() < item.GetQuantity())
526 item.SplitIntoStackMaxClient(null, -1);
527 else
528 player.PhysicalPredictiveDropItem(item);
529 }
530 }
531 }
532
534 {
535 int number_of_containers = m_Container.m_Body.Count();
536 int number_of_containers_needed = (items.Count() / ITEMS_IN_ROW) + 1;
538 int g;
539
541 {
543 m_Container.Insert(con, -1, false);
544 for (int j = 0; j < ITEMS_IN_ROW; j++)
545 {
546 SlotsIcon icon = con.GetSlotIcon(j);
547 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetPanelWidget(), m_Parent, "OnDropReceivedFromIcon");
548 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetGhostSlot(), m_Parent, "OnDropReceivedFromHeader");
549 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader");
550
551 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetPanelWidget(), m_Parent, "DraggingOverIcon");
552 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetGhostSlot(), m_Parent, "DraggingOverHeader");
553 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetMainWidget(), m_Parent, "DraggingOverHeader");
554
555 WidgetEventHandler.GetInstance().RegisterOnDoubleClick(icon.GetPanelWidget(), this, "DoubleClick");
556 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(), this, "MouseClick");
557 WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown(icon.GetPanelWidget(), this, "MouseButtonDown");
558 }
559
560 con.SetColumnCount(items.Count() % ITEMS_IN_ROW);
561 }
562
563 for (g = number_of_containers - 1 ; g >= number_of_containers_needed ; g--)
564 {
565 Widget w = m_Container.m_Body.Get(g).GetMainWidget();
566 delete w;
567 m_Container.m_Body.Remove(g);
568 }
569
570 if ((items.Count() % ITEMS_IN_ROW) == 0)
572 else
573 SlotsContainer.Cast(m_Container.Get(number_of_containers_needed - 1)).SetColumnCount(items.Count() % ITEMS_IN_ROW);
574
575 for (int i = 0; i < number_of_containers_needed - 1; i++)
576 SlotsContainer.Cast(m_Container.Get(i)).SetColumnCount(ITEMS_IN_ROW);
577
578 RecomputeOpenedContainers();
579 m_Container.RecomputeOpenedContainers();
580 }
581}
Param3 int
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
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()
PlayerBase GetPlayer()
DayZPlayer m_player
Widget m_Parent
Definition SizeToChild.c:86
Super root of all classes in Enforce script.
Definition EnScript.c:11
override EntityAI GetFocusedItem()
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.
static ItemManager GetInstance()
Definition EnMath.c:7
static int HasItemQuantity(notnull EntityAI item)
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
bool ExcludeFromContainer(EntityAI item)
Decides on the icon visibility.
int HasItemQuantity(EntityAI item)
void ShowItemsInContainers(array< EntityAI > items)
float GetItemQuantity(InventoryItem item)
string GetItemQuantityText(EntityAI item)
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
override bool IsItemWithQuantityActive()
void VicinitySlotsContainer(LayoutHolder parent)
void DoubleClick(Widget w, int x, int y, int button)
void MouseButtonDown(Widget w, int x, int y, int button)
ref array< EntityAI > m_ShowedItems
void RecomputeNumberOfContainers(array< EntityAI > items)
void MouseClick(Widget w, int x, int y, int button)
ref AttachmentsGroupContainer m_Container
static WidgetEventHandler GetInstance()
const string Container
proto native CGame GetGame()
const int QUANTITY_PROGRESS
Definition constants.c:484
const int QUANTITY_COUNT
Definition constants.c:483
const int QUANTITY_HIDDEN
Definition constants.c:482
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Floor(float f)
Returns floor of value.
static proto float Round(float f)
Returns mathematical round of value.
const int MENU_INVENTORY
Definition constants.c:170
MouseState
Definition EnSystem.c:311
proto native Widget CancelWidgetDragging()
proto native Widget GetDragWidget()