DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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 {
11 ref SlotsContainer con = new SlotsContainer( m_Container, null );
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 );
18 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(), m_Parent, "OnDropReceivedFromHeader" );
19 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader" );
20
23 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetMainWidget(), m_Parent, "DraggingOverHeader" );
24
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 {
79 ItemBase ent = ItemBase.Cast( GetFocusedItem() );
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 {
90 bool res = false;
91
92 if( ent && !ent.IsInherited( Magazine ))
93 {
94 res = GetGame().GetPlayer().PredictiveTakeOrSwapAttachment( ent );
95 if(!res)
96 {
97 res = GetGame().GetPlayer().GetInventory().TakeEntityToInventory(InventoryMode.PREDICTIVE,FindInventoryLocationType.ATTACHMENT,ent);
98 }
99 }
100 return res;
101 }
102
103 override bool InspectItem()
104 {
105 EntityAI ent = GetFocusedItem();
106
107 if( ent )
108 {
109 InspectItem( ent );
110 return true;
111 }
112 return false;
113 }
114
115 override bool TransferItem()
116 {
117 ItemBase ent = ItemBase.Cast( GetFocusedItem() );
118 if( ent )
119 {
120 if ( ent.IsTakeable() )
121 {
123 GetGame().GetPlayer().GetInventory().FindFreeLocationFor( ent, FindInventoryLocationType.CARGO, il );
124 if( il.IsValid() && GetGame().GetPlayer().GetInventory().LocationCanAddEntity( il ) )
125 {
127 return true;
128 }
129 }
130 }
131 return false;
132 }
133
134 override bool Combine( )
135 {
136 ItemBase ent = ItemBase.Cast( GetFocusedItem() );
137
138 ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
139
141
142 if( item_in_hands && ent && hands_icon )
143 {
144 return hands_icon.CombineItems( item_in_hands, ent );
145 }
146 return false;
147 }
148
149 override bool Select()
150 {
152 EntityAI ent = GetFocusedItem();
153 ItemBase selected_item = ItemBase.Cast(ItemManager.GetInstance().GetSelectedItem());
154
155 if( !(selected_slot && selected_slot.IsOutOfReach() ) )
156 {
157 if( selected_item )
158 {
159 if( ent != selected_item)
160 {
161 if( selected_item && GetGame().GetPlayer().CanDropEntity( selected_item ) )
162 {
163 bool draggable = false;
164
165 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
166 draggable = !player.GetInventory().HasInventoryReservation( selected_item, null ) && !player.IsItemsToDelete();
167 draggable = draggable && selected_item.GetInventory().CanRemoveEntity();
168
169 if( draggable && m_ShowedItems.Find( selected_item ) == -1 )
170 {
171 if( selected_item.GetTargetQuantityMax() < selected_item.GetQuantity() )
172 selected_item.SplitIntoStackMaxClient( null, -1 );
173 else
174 player.PhysicalPredictiveDropItem( selected_item );
175 ItemManager.GetInstance().SetSelectedItem( null, null, null, null );
176 return true;
177 }
178 }
179 }
180 }
181 else
182 {
183 if( ent && ent.GetInventory().CanRemoveEntity())
184 {
185 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
186 if( item_in_hands )
187 {
188 if( GameInventory.CanSwapEntitiesEx( item_in_hands, ent ) )
189 {
190 GetGame().GetPlayer().PredictiveSwapEntities( item_in_hands, ent );
191 return true;
192 }
193 }
194 else
195 {
196 if( GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands( ent ) )
197 {
198 GetGame().GetPlayer().PredictiveTakeEntityToHands( ent );
199 return true;
200 }
201 }
202 }
203 }
204 }
205
206 return false;
207 }
208
210 {
211 for ( int i = 0; i < m_Container.Count(); i++ )
212 {
214 if( c && c.GetMainWidget() )
215 {
216 delete m_Container.Get( i / ITEMS_IN_ROW ).GetMainWidget();
217 }
218 }
219 }
220
221 override void SetLayoutName()
222 {
223 m_LayoutName = WidgetLayoutName.Container;
224 }
225
226 override void OnShow()
227 {
228 super.OnShow();
229 }
230
232 {
233 return GetFocusedContainer().GetColumnCount();
234 }
235
238 {
239 int mask = item.GetHideIconMask();
240 return mask & EInventoryIconVisibility.HIDE_VICINITY;
241 }
242
244 {
245 EntityAI item;
246 SlotsIcon icon;
247 int x;
248 int visible_items_count = 0;
249 int visible_rows = 0;
250 ref array<EntityAI> visible_items = new array<EntityAI>;
251
252 for ( x = 0; x < items.Count(); ++x )
253 {
254 item = items.Get( x );
255
256 if ( item == null || ExcludeFromContainer(item) )
257 continue;
258
259 visible_items.Insert( item );
260 visible_items_count++;
261 }
262
263 RecomputeNumberOfContainers( visible_items );
264
265 for ( x = 0; x < visible_items_count; ++x )
266 {
267 item = visible_items.Get( x );
268 int row = (int)Math.Floor( x / ITEMS_IN_ROW );
269 int column = x % ITEMS_IN_ROW;
270 icon = SlotsContainer.Cast( m_Container.Get( row ) ).GetSlotIcon( column );
271
272 icon.GetMainWidget().Show( true );
273 icon.GetPanelWidget().SetUserID( item.GetID() );
274
275 if ( m_ShowedItems.Find( item ) != x )
276 icon.Init( item );
277 icon.UpdateInterval();
278
280 {
282 }
283
285 if ( !draggable && GetDragWidget() == icon.GetPanelWidget() )
288
289 ref map<int, ref Container> showed_items = ( VicinityContainer.Cast( m_Parent ) ).m_ShowedItemsIDs;
290
291 Container conta = Container.Cast( showed_items.Get( item.GetID() ) );
292 if ( conta )
293 {
294 conta.SetSlotIcon(icon);
295 }
296
297 if ( conta && conta.IsDisplayable() )
298 {
299 conta.UpdateRadialIcon();
300 }
301 else
302 {
303 icon.GetRadialIconPanel().Show( false );
304 if ( conta )
305 conta.OnHide();
306 }
307 }
308
309 SlotsContainer slots_last = SlotsContainer.Cast( m_Container.Get( visible_items.Count() / ITEMS_IN_ROW ) );
310
311 for ( int c = visible_items_count % ITEMS_IN_ROW; c < ITEMS_IN_ROW; ++c )
312 {
313 icon = slots_last.GetSlotIcon( c );
314 icon.GetMainWidget().Show( false );
315 icon.Clear();
316 }
317
318 //#ifndef PLATFORM_CONSOLE
319 if ( visible_items_count % ITEMS_IN_ROW == 0 )
320 {
321 slots_last = SlotsContainer.Cast( m_Container.Get( m_Container.Count() - 1 ) );
322 slots_last.GetSlotIcon( 0 ).GetMainWidget().Show( true );
323 slots_last.GetSlotIcon( 0 ).GetGhostSlot().Show( false );
324 slots_last.GetMainWidget().Update();
325 }
326 //#endif
327
328 m_ShowedItems = visible_items;
329 }
330
331 void DoubleClick(Widget w, int x, int y, int button)
332 {
333 if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
334 {
335 if( w == null )
336 {
337 return;
338 }
339 ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
340 if( !iw )
341 {
342 string name = w.GetName();
343 name.Replace( "PanelWidget", "Render" );
344 iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
345 }
346
347 if( !iw )
348 {
349 iw = ItemPreviewWidget.Cast( w );
350 }
351
352 ItemBase item = ItemBase.Cast( iw.GetItem() );
353 if( !item )
354 {
355 return;
356 }
357
358 if( !item.IsTakeable() )
359 {
360 return;
361 }
362
363 if( GetGame().GetPlayer().GetInventory().HasInventoryReservation( item, null ) )
364 {
365 return;
366 }
367
368 if( !item.GetInventory().CanRemoveEntity() )
369 return;
370
371 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
372
373 if ( player.GetInventory().HasEntityInInventory( item ) && GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands( item ) )
374 {
375 player.PredictiveTakeEntityToHands( item );
376 }
377 else
378 {
380 player.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ANY, dst );
381 if( dst.IsValid() && player.GetInventory().LocationCanAddEntity( dst ) )
382 {
384 }
385 }
386
387 HideOwnedTooltip();
388 InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
389 if( menu )
390 {
391 menu.RefreshQuickbar();
392 }
393 }
394 }
395
397 {
398 string quantity_text = "";
399 if ( item.IsInherited( InventoryItem ) )
400 {
401 ItemBase item_base = ItemBase.Cast( item );
402 float quantity = item_base.GetQuantity();
403 int ammo;
404 if ( item.IsInherited( Magazine ) )
405 {
406 Magazine magazine_item = Magazine.Cast( item );
407 ammo = magazine_item.GetAmmoCount();
408 quantity_text = ammo.ToString();
409 return quantity_text;
410 }
411 else if ( item.IsInherited( ItemBook ) )
412 {
413 return "";
414 }
415 int max = item.GetQuantityMax();
416 //string unit = item.ConfigGetString( "stackedUnit" );
417
418 if ( max > 0 )
419 {
420 if ( max == 1 )
421 {
422 float tmp = Math.Round( ( quantity / max ) * 100 );
423 quantity_text = tmp.ToString() + "%";
424 }
425 else
426 {
427 quantity_text = quantity.ToString();
428 }
429 }
430 }
431 return quantity_text;
432 }
433
435 {
436 if ( item.IsInherited( InventoryItem ) )
437 {
438 ItemBase item_base = ItemBase.Cast( item );
439 if ( item.IsInherited( Magazine ) )
440 {
441 return QUANTITY_COUNT;
442 }
443 else if ( item.IsInherited( ItemBook ) )
444 {
445 return QUANTITY_HIDDEN;
446 }
447 int max = item.GetQuantityMax();
448 bool bar = item.ConfigGetBool( "quantityBar" );
449 if ( max > 0 )
450 {
451 if ( max == 1 || bar )
452 {
453 return QUANTITY_PROGRESS;
454 }
455 else
456 {
457 return QUANTITY_COUNT;
458 }
459 }
460 }
461 return QUANTITY_HIDDEN;
462 }
463
465 {
466 float quantity = 0;
467 if ( item.IsInherited( InventoryItem ) )
468 {
469 ItemBase item_base = ItemBase.Cast( item );
470 if ( item.IsInherited( Magazine ) )
471 {
472 Magazine magazine_item = Magazine.Cast( item );
473 quantity = magazine_item.GetAmmoCount();
474 }
475 else
476 {
477 quantity = item_base.GetQuantity();
478 }
479 }
480 return quantity;
481 }
482
483 // Mouse button DOWN
484 void MouseButtonDown( Widget w, int x, int y, int button)
485 {
486 string name = w.GetName();
487 name.Replace( "PanelWidget", "Render" );
488 ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
489 ItemBase item = ItemBase.Cast( item_preview.GetItem() );
492 }
493
494 // Mouse button UP <---- exist button down MouseButtonDown ^
495 void MouseClick( Widget w, int x, int y, int button)
496 {
497 string name = w.GetName();
498 name.Replace( "PanelWidget", "Render" );
499 ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
500 EntityAI item = item_preview.GetItem();
501 InventoryItem itemAtPos = InventoryItem.Cast( item );
502 Container conta;
503
504 #ifdef DIAG_DEVELOPER
505 if ( ItemBase.Cast(item) )
506 {
507 if ( GetDayZGame().IsLeftCtrlDown() && button == MouseState.RIGHT )
508 ShowActionMenu( ItemBase.Cast(item) );
509 }
510 #endif
511
512 if( m_Parent )
513 {
514 ref map<int, ref Container> showed_items = ( VicinityContainer.Cast( m_Parent ) ).m_ShowedItemsIDs;
515
516 if( item && showed_items )
517 {
518 conta = showed_items.Get( item.GetID() );
519
520 ( VicinityContainer.Cast( m_Parent ) ).ToggleContainer( w, item );
521 if ( button == MouseState.RIGHT )
522 {
523 if ( itemAtPos )
524 {
525 itemAtPos.OnRightClick();
526 }
527 }
528 else if ( button == MouseState.MIDDLE )
529 {
530 InspectItem( itemAtPos );
531 return;
532 }
533 }
534 }
535 }
536
537 override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
538 {
539 ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
540 if( !ipw )
541 {
542 string name = w.GetName();
543 name.Replace( "PanelWidget", "Render" );
544 ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
545 }
546 if( !ipw )
547 {
548 ipw = ItemPreviewWidget.Cast( w );
549 }
550
551 if( !ipw.IsInherited( ItemPreviewWidget ) )
552 {
553 return;
554 }
555
556 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
557 ItemBase item = ItemBase.Cast(ipw.GetItem());
558
559 if( item )
560 {
561 if( !item.GetInventory().CanRemoveEntity() )
562 return;
563
564 if( player.CanDropEntity( item ) )
565 {
566 if( item.GetTargetQuantityMax() < item.GetQuantity() )
567 item.SplitIntoStackMaxClient( null, -1 );
568 else
569 player.PhysicalPredictiveDropItem( item );
570 }
571 }
572 }
573
575 {
576 int number_of_containers = m_Container.m_Body.Count();
577 int number_of_containers_needed = ( items.Count() / ITEMS_IN_ROW ) + 1;
578 int difference = number_of_containers_needed - number_of_containers;
579 int g;
580
581 for (g = number_of_containers; g < number_of_containers_needed; g++)
582 {
583 SlotsContainer con = new SlotsContainer( m_Container, null );
584 m_Container.Insert(con, -1, false);
585 for (int j = 0; j < ITEMS_IN_ROW; j++)
586 {
587 SlotsIcon icon = con.GetSlotIcon(j);
589 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetGhostSlot(), m_Parent, "OnDropReceivedFromHeader");
590 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader");
591
594 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetMainWidget(), m_Parent, "DraggingOverHeader");
595
599 }
600
601 con.SetColumnCount(items.Count() % ITEMS_IN_ROW);
602 }
603
604 for (g = number_of_containers - 1 ; g >= number_of_containers_needed ; g--)
605 {
606 Widget w = m_Container.m_Body.Get(g).GetMainWidget();
607 delete w;
608 m_Container.m_Body.Remove(g);
609 }
610
611 if ( (items.Count() % ITEMS_IN_ROW) == 0 )
612 {
613 SlotsContainer.Cast( m_Container.Get( number_of_containers_needed - 1 ) ).SetColumnCount( ITEMS_IN_ROW );
614 }
615 else
616 {
617 SlotsContainer.Cast( m_Container.Get( number_of_containers_needed - 1 ) ).SetColumnCount( items.Count() % ITEMS_IN_ROW );
618 }
619
620 for ( int i = 0; i < number_of_containers_needed - 1; i++ )
621 {
622 SlotsContainer.Cast( m_Container.Get( i ) ).SetColumnCount( ITEMS_IN_ROW );
623 }
624
625 RecomputeOpenedContainers();
626 m_Container.RecomputeOpenedContainers();
627 }
628}
InventoryMode
Definition Inventory.c:20
const int ITEMS_IN_ROW
Definition Attachments.c:1
class RecipeCacheData int
DayZGame g_Game
Definition DayZGame.c:3654
DayZGame GetDayZGame()
Definition DayZGame.c:3656
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
void InventoryMenu()
PlayerBase GetPlayer()
string name
DayZPlayer m_player
protected Widget m_Parent
Definition SizeToChild.c:92
bool CanSetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
bool CanPerformActionFromInventory(ItemBase mainItem, ItemBase targetItem)
proto native DayZPlayer GetPlayer()
Super root of all classes in Enforce script.
Definition EnScript.c:11
override void UpdateRadialIcon()
override LayoutHolder Get(int x)
override EntityAI GetFocusedItem()
override bool IsDisplayable()
script counterpart to engine's class Inventory
Definition Inventory.c:77
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:601
Definition Icon.c:2
bool CombineItems(EntityAI entity1, EntityAI entity2)
Definition Icon.c:794
override void OnRightClick()
Definition ItemBase.c:1863
InventoryLocation.
proto native bool IsValid()
verify current set inventory location
override bool IsTakeable()
EntityAI GetSelectedItem()
Definition ItemManager.c:82
HandsPreview GetHandsPreview()
Definition ItemManager.c:72
void SetWidgetDraggable(Widget w, bool draggable)
bool IsDragging()
void SetTemperature(EntityAI item, Widget item_w)
bool EvaluateContainerDragabilityDefault(EntityAI entity)
void SetSelectedItem(EntityAI selected_item, Container selected_container, Widget selected_widget, SlotsIcon selected_icon)
SlotsIcon GetSelectedIcon()
Definition ItemManager.c:97
static ItemManager GetInstance()
proto native EntityAI GetItem()
Definition EnMath.c:7
static int HasItemQuantity(notnull EntityAI item)
SlotsIcon GetSlotIcon(int index)
Widget GetRadialIconPanel()
Definition SlotsIcon.c:295
override void UpdateInterval()
Definition SlotsIcon.c:669
ItemPreviewWidget GetRender()
Definition SlotsIcon.c:230
void Clear()
Definition SlotsIcon.c:502
Widget GetPanelWidget()
Definition SlotsIcon.c:205
ImageWidget GetGhostSlot()
Definition SlotsIcon.c:235
void Init(EntityAI obj, bool reservation=false)
Definition SlotsIcon.c:460
bool IsOutOfReach()
Definition SlotsIcon.c:607
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
protected ref AttachmentsGroupContainer m_Container
int HasItemQuantity(EntityAI item)
void VicinitySlotsContainer(LayoutHolder parent)
void MouseButtonDown(Widget w, int x, int y, int button)
bool ExcludeFromContainer(EntityAI item)
Decides on the icon visibility.
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
void MouseClick(Widget w, int x, int y, int button)
void DoubleClick(Widget w, int x, int y, int button)
string GetItemQuantityText(EntityAI item)
float GetItemQuantity(InventoryItem item)
override bool IsItemWithQuantityActive()
void ShowItemsInContainers(array< EntityAI > items)
void RecomputeNumberOfContainers(array< EntityAI > items)
protected ref array< EntityAI > m_ShowedItems
void RegisterOnMouseButtonDown(Widget w, Managed eventHandler, string functionName)
void RegisterOnMouseButtonUp(Widget w, Managed eventHandler, string functionName)
static WidgetEventHandler GetInstance()
void RegisterOnDoubleClick(Widget w, Managed eventHandler, string functionName)
void RegisterOnDropReceived(Widget w, Managed eventHandler, string functionName)
void RegisterOnDraggingOver(Widget w, Managed eventHandler, string functionName)
const string Container
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto string ToString()
proto native CGame GetGame()
const int QUANTITY_PROGRESS
Definition constants.c:468
const int QUANTITY_COUNT
Definition constants.c:467
const int QUANTITY_HIDDEN
Definition constants.c:466
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Floor(float f)
Returns floor of value.
const int MENU_INVENTORY
Definition constants.c:158
MouseState
Definition EnSystem.c:311
proto int Replace(string sample, string replace)
Replace all occurrances of 'sample' in 'str' by 'replace'.
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.
proto native Widget CancelWidgetDragging()
proto native Widget GetDragWidget()