DayZ 1.24
Loading...
Searching...
No Matches
ContainerWithCargo.c
Go to the documentation of this file.
1class ContainerWithCargo extends ClosableContainer
2{
3 protected ref CargoContainer m_CargoGrid;
4 protected int m_CargoIndex = -1;
5
6 void ContainerWithCargo(Container parent, int sort = -1)
7 {
8 m_LockCargo = false;
9 m_Parent = parent;
10
11 m_CargoGrid = new CargoContainer(this);
12 Insert(m_CargoGrid);
13
14 m_CargoGrid.GetRootWidget().SetSort(1);
15
16 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(m_MainWidget, this, "DraggingOverGrid");
17 RecomputeOpenedContainers();
18 }
19
20 override bool IsDisplayable()
21 {
22 if (m_Entity)
23 return m_Entity.CanDisplayCargo();
24 return false;
25 }
26
27 override bool IsEmpty()
28 {
29 return m_CargoGrid.IsEmpty();
30 }
31
32 override bool IsItemActive()
33 {
34 return m_CargoGrid.IsItemActive();
35 }
36
37 override bool CanCombine()
38 {
39 return m_CargoGrid.CanCombine();
40 }
41
42 override bool CanCombineAmmo()
43 {
44 return m_CargoGrid.CanCombineAmmo();
45 }
46
48 {
49 return m_CargoGrid.IsItemWithQuantityActive();
50 }
51
52 void LockCargo(bool value)
53 {
54 if (value != m_LockCargo)
55 {
56 if (value)
57 {
58 m_LockCargo = true;
59 OnHide();
60 }
61 else
62 {
63 m_LockCargo = false;
64 SetOpenState(!m_Closed);
65 }
66 }
67 }
68
69 override void Open()
70 {
71 if (!m_LockCargo)
72 {
73 ItemManager.GetInstance().SetDefaultOpenState(m_Entity.GetType(), true);
74 m_Closed = false;
75 SetOpenForSlotIcon(true);
76 OnShow();
77 m_Parent.m_Parent.Refresh();
78 }
79
80 if (m_SlotIcon)
81 m_SlotIcon.GetRadialIconPanel().Show(!m_LockCargo);
82 }
83
84 override void Close()
85 {
86 if (!m_LockCargo)
87 {
88 ItemManager.GetInstance().SetDefaultOpenState(m_Entity.GetType(), false);
89 m_Closed = true;
90 SetOpenForSlotIcon(false);
91 OnHide();
92 m_Parent.m_Parent.Refresh();
93 }
94
95 if (m_SlotIcon)
96 m_SlotIcon.GetRadialIconPanel().Show(!m_LockCargo);
97 }
98
99 override bool IsOpened()
100 {
101 return !m_Closed && !m_LockCargo;
102 }
103
104 override void UpdateInterval()
105 {
106 if (m_Entity)
107 {
108 if (m_Entity.GetInventory().IsInventoryLockedForLockType(HIDE_INV_FROM_SCRIPT) || !m_Entity.CanDisplayCargo())
109 {
110 LockCargo(true);
111 if (m_CargoGrid.IsVisible())
112 RecomputeOpenedContainers();
113 }
114 else
115 {
116 LockCargo(false);
117 if (!m_CargoGrid.IsVisible())
118 RecomputeOpenedContainers();
119 }
120
121 super.UpdateInterval();
122 m_CargoGrid.UpdateInterval();
123
124 bool hide = m_LockCargo || ItemManager.GetInstance().GetDraggedItem() == m_Entity;
125 if (!hide)
126 SetOpenForSlotIcon(IsOpened());
127
128 if (m_SlotIcon)
129 m_SlotIcon.GetRadialIconPanel().Show(!hide);
130 }
131 }
132
134 {
135 return m_CargoGrid.IsFirstContainerFocused();
136 }
137
139 {
140 return m_CargoGrid.IsLastContainerFocused();
141 }
142
143 override void SetDefaultFocus(bool while_micromanagment_mode = false)
144 {
145 m_CargoGrid.SetDefaultFocus(while_micromanagment_mode);
146 }
147
148 override void UnfocusAll()
149 {
150 m_CargoGrid.Unfocus();
151 }
152
153 override bool SplitItem()
154 {
155 return m_CargoGrid.SplitItem();
156 }
157
158 override bool EquipItem()
159 {
160 return m_CargoGrid.EquipItem();
161 }
162
163 override bool TransferItem()
164 {
165 return m_CargoGrid.TransferItem();
166 }
167
169 {
170 return m_CargoGrid.TransferItemToVicinity();
171 }
172
173 override bool InspectItem()
174 {
175 return m_CargoGrid.InspectItem();
176 }
177
178 void SetEntity(EntityAI entity, int cargo_index = 0, bool immedUpdate = true)
179 {
181 m_CargoIndex = cargo_index;
182
183 SetOpenState(true);
184
185 m_CargoGrid.SetEntity(entity, immedUpdate);
186 m_CargoGrid.UpdateHeaderText();
187 m_ClosableHeader.SetItemPreview(entity);
188 CheckHeaderDragability();
189 (Container.Cast(m_Parent)).Insert(this, -1, false);
190
191 if (m_Entity.GetInventory().IsInventoryLockedForLockType(HIDE_INV_FROM_SCRIPT) || !m_Entity.CanDisplayCargo())
192 LockCargo(true);
193 else
194 LockCargo(false);
195
196 if (immedUpdate)
197 {
198 Refresh();
199 GetMainWidget().Update();
200 }
201 }
202
204 {
205 return m_Entity;
206 }
207
209 {
210 return m_Entity;
211 }
212
214 {
215 ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
216 if (!ipw)
217 {
218 string name = w.GetName();
219 name.Replace("PanelWidget", "Render");
220 ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
221 }
222 if (!ipw)
223 ipw = ItemPreviewWidget.Cast(w);
224 if (!ipw || !ipw.IsInherited(ItemPreviewWidget))
225 return null;
226 return ipw.GetItem();
227 }
228
230 {
231 if (w == null)
232 return false;
233
235 if (!player.CanManipulateInventory())
236 return false;
237
239
240 if (!item)
241 return false;
242
243 if (!item.GetInventory().CanRemoveEntity())
244 return false;
245
246 int color, c_x, c_y;
247
248#ifdef PLATFORM_CONSOLE
249 int idx = -1;
250#else
251 int idx = 0;
252#endif
253
254 CargoBase cargo = m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex);
255 if (cargo)
256 {
257 c_x = cargo.GetHeight();
258 c_y = cargo.GetWidth();
259 }
260
262#ifdef PLATFORM_CONSOLE
263 x = 0;
264 y = cargo.GetItemCount();
265 m_Entity.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.CARGO, dst);
266#else
267 dst.SetCargoAuto(cargo, item, x, y, item.GetInventory().GetFlipCargo());
268#endif
269
270#ifdef PLATFORM_CONSOLE
271 if (dst.IsValid() && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
272#else
273 if (m_Entity && c_x > x && c_y > y && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
274#endif
275 {
276 ItemManager.GetInstance().HideDropzones();
277 if (m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer())
278 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
279 else
280 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
282 }
283 else
284 {
286 ItemManager.GetInstance().ShowSourceDropzone(item);
287 }
288
289 if (w.FindAnyWidget("Cursor"))
290 w.FindAnyWidget("Cursor").SetColor(color);
291 else
292 {
293 string name = w.GetName();
294 name.Replace("PanelWidget", "Cursor");
295 if (w.FindAnyWidget(name))
296 w.FindAnyWidget(name).SetColor(color);
297 }
298
299 return true;
300 }
301
302 void DropReceived(Widget w, int x, int y)
303 {
304 float xx, yy;
305 GetMainWidget().Update();
306 GetMainWidget().GetScreenSize(xx, yy);
307 if (GetMainWidget().FindAnyWidget("Background"))
308 {
309 GetMainWidget().FindAnyWidget("Background").Show(true);
310 GetMainWidget().FindAnyWidget("Background").SetSize(xx, yy);
311 }
313 if (!item)
314 return;
315
316#ifdef PLATFORM_CONSOLE
317 if (m_CargoGrid.HasItem(item))
318 return;
319#endif
320
321#ifdef PLATFORM_CONSOLE
322 int idx = -1;
323#else
324 int idx = 0;
325#endif
326 int c_x, c_y;
327
328 CargoBase cargo = m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex);
329
330 if (cargo)
331 {
332 c_x = cargo.GetHeight();
333 c_y = cargo.GetWidth();
334 }
335
337#ifdef PLATFORM_CONSOLE
338 x = 0;
339 y = cargo.GetItemCount();
340 m_Entity.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.CARGO, dst);
341#else
342 dst.SetCargoAuto(cargo, item, x, y, item.GetInventory().GetFlipCargo());
343#endif
344
346 item.GetInventory().GetCurrentInventoryLocation(src);
347
348 if (src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
349 return;
350
351#ifdef PLATFORM_CONSOLE
352 if (dst.IsValid() && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
353#else
354 if (c_x > x && c_y > y && m_Entity.GetInventory().LocationCanAddEntityEx(dst))
355#endif
356 {
358
360
361 Icon icon = m_CargoGrid.GetIcon(item);
362
363 if (icon && w && w.FindAnyWidget("Cursor"))
364 {
365 w.FindAnyWidget("Cursor").SetColor(ColorManager.BASE_COLOR);
366 icon.Refresh();
367 Refresh();
368 }
369 }
370
371 ItemManager.GetInstance().HideDropzones();
372 ItemManager.GetInstance().SetIsDragging(false);
373 }
374
376 {
378
379 if (!item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory())
380 return;
381
382 float stackable = item_base.GetTargetQuantityMax();
383
384 if (stackable == 0 || stackable >= item_base.GetQuantity())
385 player.PredictiveTakeEntityToHands(item);
386 else if (stackable != 0 && stackable < item_base.GetQuantity())
387 item_base.SplitIntoStackMaxHandsClient(player);
388 }
389
390 override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
391 {
393 }
394
395 override void DraggingOver(Widget w, int x, int y, Widget receiver)
396 {
397 if (!w)
398 return;
400 if (!item)
401 return;
402
404 if (item.GetInventory().CanRemoveEntity() && player.CanManipulateInventory() && m_Entity.GetInventory().CanAddEntityInCargo(item, item.GetInventory().GetFlipCargo()) && !m_Entity.GetInventory().HasEntityInCargo(item))
405 {
407 ItemManager.GetInstance().HideDropzones();
408 if (m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer())
409 ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
410 else
411 ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
412 }
413 else
414 {
416 ItemManager.GetInstance().ShowSourceDropzone(item);
417 }
418 }
419
421 {
423 if (!item)
424 return;
425
428 if (GetEntity() && item.GetInventory().GetCurrentInventoryLocation(src))
429 {
431 if (m_Entity.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, dst))
432 player.PredictiveTakeToDst(src, dst);
433
434 bool can_add = m_Entity.GetInventory().CanAddEntityInCargo(item, item.GetInventory().GetFlipCargo());
435 bool in_cargo = !player.GetInventory().HasEntityInInventory(item) || !m_Entity.GetInventory().HasEntityInCargo(item);
436 if (can_add && in_cargo)
438 }
439 }
440}
EntityAI m_Entity
Definition ActionDebug.c:11
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
override void OnShow()
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
override void OnHide()
PlayerBase GetPlayer()
Widget m_Parent
Definition SizeToChild.c:86
void Refresh()
represents base for cargo storage for entities
Definition Cargo.c:7
override bool IsFirstContainerFocused()
override void SetDefaultFocus(bool while_micromanagment_mode=false)
override void Close()
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
override bool IsLastContainerFocused()
void DropReceived(Widget w, int x, int y)
override bool EquipItem()
override void DraggingOver(Widget w, int x, int y, Widget receiver)
override bool CanCombineAmmo()
override bool CanCombine()
void SetEntity(EntityAI entity, int cargo_index=0, bool immedUpdate=true)
override bool InspectItem()
override bool TransferItemToVicinity()
override bool IsOpened()
ref CargoContainer m_CargoGrid
override bool IsItemActive()
override bool IsItemWithQuantityActive()
override void UpdateInterval()
override bool TransferItem()
EntityAI GetItemPreviewItem(Widget w)
override bool IsEmpty()
void LockCargo(bool value)
override EntityAI GetFocusedContainerEntity()
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
override void Open()
override bool SplitItem()
void ContainerWithCargo(Container parent, int sort=-1)
override void UnfocusAll()
void TakeIntoHands(notnull PlayerBase player, notnull EntityAI item)
bool DraggingOverGrid(Widget w, int x, int y, Widget reciever)
override bool IsDisplayable()
static int BASE_COLOR
static int GREEN_COLOR
static int RED_COLOR
static ColorManager GetInstance()
Definition Icon.c:2
InventoryLocation.
static ItemManager GetInstance()
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
static WidgetEventHandler GetInstance()
proto native CGame GetGame()
proto native Widget FindAnyWidget(string pathname)