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