DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
PlayerContainer.c
Go to the documentation of this file.
2{
8
9 protected const int HEADER_INDEX_OFFSET = 2;
10
11 override void UpdateRadialIcon()
12 {
13 if ( m_SlotIcon )
14 {
15 bool show_radial_icon;
16 show_radial_icon = IsHidden();
17 Widget rip = m_SlotIcon.GetRadialIconPanel();
18 rip.Show( !m_Player.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) && m_Player.CanDisplayCargo());
19 SetOpenForSlotIcon(show_radial_icon);
20 }
21 }
22
24 {
25 ClosableContainer cont = ClosableContainer.Cast( m_ShowedItems.Get( entity ) );
26 return ( cont && cont.IsOpened() );
27 }
28
29 SlotsIcon GetSlotsIcon( int row, int column )
30 {
32 }
33
34 void PlayerContainer( LayoutHolder parent, int sort = -1 )
35 {
38
40 m_CollapsibleHeader.SetName( "#container_inventory" );
41 SetHeader(null);
42 m_Body.Insert( m_PlayerAttachmentsContainer );
43 m_MainWidget = m_RootWidget.FindAnyWidget( "body" );
44 m_PlayerAttachmentsContainer.GetRootWidget().SetColor(166 << 24 | 80 << 16 | 80 << 8 | 80);
45 WidgetEventHandler.GetInstance().RegisterOnChildAdd( m_MainWidget, this, "OnChildAdd" );
46 WidgetEventHandler.GetInstance().RegisterOnChildRemove( m_MainWidget, this, "OnChildRemove" );
47
48 //START - InitGhostSlots
49 string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
50 ref array<string> player_ghosts_slots = new array<string>;
51 GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
52
53 for ( int i = 0; i < player_ghosts_slots.Count(); i++ )
54 {
55 string slot_name = player_ghosts_slots.Get ( i );
56 string path = "CfgSlots" + " " + slot_name;
57
58 if ( GetGame().ConfigIsExisting( path ) )
59 {
60 string icon_name; //icon_name must be in format "set:<setname> image:<imagename>"
61 GetGame().ConfigGetText( path + " ghostIcon", icon_name );
62 int slot_number = i;
63 int column = slot_number % ITEMS_IN_ROW;
64
65 //START - GetWidgetSlot
66 int row = slot_number / ITEMS_IN_ROW;
67 if( row >= m_PlayerAttachmentsContainer.Count() )
68 {
69 if( row < ( player_ghosts_slots.Count() / ITEMS_IN_ROW ) )
71 else
72 AddSlotsContainer( player_ghosts_slots.Count() % ITEMS_IN_ROW );
73 }
74
75 SlotsIcon icon = GetSlotsIcon( row, column );
76
77 icon.GetMainWidget().Show( true );
78 icon.Clear();
79
81
82 //END - GetWidgetSlot
83 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetPanelWidget(), this, "OnDropReceivedFromGhostArea" );
84 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(), this, "OnDropReceivedFromGhostArea" );
85 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetGhostSlot(), this, "DraggingOver" );
88
90 //END - LoadIconIntoWidgetSlot
91
92 GetGame().ConfigGetText( path + " name", slot_name );
93 int slot_id = InventorySlots.GetSlotIdFromString( slot_name );
94 icon.SetSlotID(slot_id);
96 m_InventorySlots.Set( slot_id, icon );
97 }
98 }
99 m_PlayerAttachmentsContainer.GetMainWidget().Update();
100 //END - InitGhostSlots
101 RecomputeOpenedContainers();
102 }
103
105 {
106 if( m_Player )
107 {
108 m_Player.GetOnItemAttached().Remove(ItemAttached);
109 m_Player.GetOnItemDetached().Remove(ItemDetached);
110 m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
111 m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
112 }
113 }
114
115 void ItemAttached(EntityAI item, string slot_name)
116 {
117 int slot = InventorySlots.GetSlotIdFromString( slot_name );
118 SlotsIcon icon = m_InventorySlots.Get( slot );
119
120 if( icon )
121 {
122 if( icon.IsReserved())
123 m_Player.GetOnAttachmentReleaseLock().Invoke(item, slot);
124
125 icon.Init( item );
126
127 if( m_ShowedItems.Contains( item ) == false )
128 {
129 string name;
130 int sort_index = Inventory.GetPlayerAttachmentIndex( slot );
131 int current_sort = 9999;
132 if( GetFocusedContainer() )
133 current_sort = GetFocusedContainer().GetRootWidget().GetSort();
134
135 if( item.GetSlotsCountCorrect() > 0 )
136 {
137 ContainerWithCargoAndAttachments iwca = new ContainerWithCargoAndAttachments( this, sort_index );
138 iwca.SetEntity( item );
139 iwca.SetSlotIcon( icon );
141
142 if( iwca.IsDisplayable() )
143 {
144 icon.GetRadialIconPanel().Show( true );
145 }
146 m_ShowedItems.Insert( item, iwca );
147 RecomputeOpenedContainers();
148 Refresh();
149 }
150 else if( item.GetInventory().GetCargo() )
151 {
152 ContainerWithCargo iwc = new ContainerWithCargo( this, sort_index );
153 iwc.SetEntity( item );
154 iwc.SetSlotIcon( icon );
155 iwc.UpdateInterval();
157 m_ShowedItems.Insert( item, iwc );
158 RecomputeOpenedContainers();
159 if( iwc.IsDisplayable() )
160 icon.GetRadialIconPanel().Show(true);
161
162 Refresh();
163 }
164 }
165
166 ClosableContainer conta = ClosableContainer.Cast( m_ShowedItems.Get( item ) );
167 string config = "CfgVehicles " + item.GetType() + " GUIInventoryAttachmentsProps";
168 if( conta && conta.IsInherited( ClosableContainer ) )
169 {
170 bool show_radial_icon = ( item.GetInventory().GetCargo() || item.GetSlotsCountCorrect() > 0 ) && !GetGame().ConfigIsExisting( config );
171 Widget rip = icon.GetRadialIconPanel();
172
173 rip.Show( show_radial_icon );
174 SetOpenForSlotIcon(conta.IsOpened(),icon);
175 }
176 }
177 UpdateSelectionIcons();
178 }
179
180 void ItemDetached(EntityAI item, string slot_name)
181 {
182 int slot = InventorySlots.GetSlotIdFromString( slot_name );
183 SlotsIcon icon = m_InventorySlots.Get( slot );
184
185 if( icon )
186 {
187 Container con = m_ShowedItems.Get( item );
188 if( con )
189 {
190 ( Container.Cast( con.m_Parent ) ).Remove( con );
191 RecomputeOpenedContainers();
192 GetMainWidget().Update();
193 Refresh();
194 m_ShowedItems.Remove( item );
195 }
196
197 icon.Clear();
198 Inventory in = Inventory.Cast( GetRoot() );
199 if( in )
200 in.UpdateConsoleToolbar();
201 }
202 UpdateSelectionIcons();
203 }
204
205 void OnAttachmentReservationSet( EntityAI item, int slot_id )
206 {
207 SlotsIcon icon = m_InventorySlots.Get( slot_id );
208
209 if( item )
210 {
211 icon.Init( item, true );
212 }
213 }
214
215 void OnAttachmentReservationRelease( EntityAI item, int slot_id )
216 {
217 SlotsIcon icon = m_InventorySlots.Get( slot_id );
218 icon.Clear();
219 }
220
221 void AddSlotsContainer( int row_count )
222 {
224 s_cont.SetColumnCount( row_count );
225 m_PlayerAttachmentsContainer.Insert( s_cont );
226 }
227
228 void MouseClick( Widget w, int x, int y, int button )
229 {
230 SlotsIcon slots_icon;
231 w.GetUserData(slots_icon);
232
233 EntityAI item;
234 bool reserved;
235
236 if (slots_icon)
237 {
238 item = slots_icon.GetEntity();
239 reserved = slots_icon.IsReserved();
240
241 }
242
243 ItemBase itemAtPos = ItemBase.Cast( item );
244
245 if ( item )
246 {
247 if ( button == MouseState.RIGHT )
248 {
249 #ifdef DIAG_DEVELOPER
250 if ( GetDayZGame().IsLeftCtrlDown() )
251 ShowActionMenu( InventoryItem.Cast(item) );
252 #endif
253
254 if ( reserved )
255 {
256 GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced( item );
257 m_Player.GetOnAttachmentReleaseLock().Invoke(item, slots_icon.GetSlotID());
258 }
259 }
260 else if ( button == MouseState.MIDDLE )
261 {
262 if ( !reserved )
263 {
264 InspectItem( itemAtPos );
265 }
266 }
267 else if ( button == MouseState.LEFT )
268 {
269 if ( !reserved )
270 {
271 if ( g_Game.IsLeftCtrlDown() )
272 {
273 if ( itemAtPos && itemAtPos.GetInventory().CanRemoveEntity() && m_Player.CanDropEntity(itemAtPos) )
274 {
275 if ( itemAtPos.GetTargetQuantityMax() < itemAtPos.GetQuantity() )
276 itemAtPos.SplitIntoStackMaxClient( null, -1 );
277 else
278 m_Player.PhysicalPredictiveDropItem( itemAtPos );
279 }
280 }
281 else
282 {
283 bool draggable = !m_Player.GetInventory().HasInventoryReservation( item, null ) && !m_Player.GetInventory().IsInventoryLocked() && item.GetInventory().CanRemoveEntity() && !m_Player.IsItemsToDelete();
285 }
286 }
287 }
288 }
289 }
290
292 {
293 float x, y;
294 GetRootWidget().GetScreenPos( x, y );
295 return y;
296 }
297
299 {
300 float x, y;
301 float x2, y2;
302 GetRootWidget().GetScreenPos( x, y );
303 GetRootWidget().GetScreenSize( x2, y2 );
304 y += y2;
305 return y;
306 }
307
308 override void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
309 {
310 ClosableContainer c_cont = ClosableContainer.Cast( container );
311 if (c_cont && m_Body.Count() > 1)
312 {
313 ClosableContainer prev = ClosableContainer.Cast(m_Body.Get( 1 ));
314 int index = 1;
315 int curr_sort = c_cont.GetRootWidget().GetSort();
316 while ( prev )
317 {
318 int prev_sort = prev.GetRootWidget().GetSort();
319 if ( prev_sort > curr_sort )
320 break;
321
322 if ( ++index < m_Body.Count() )
323 prev = ClosableContainer.Cast( m_Body.Get( index ) );
324 else
325 break;
326 }
327
328 m_Body.InsertAt( container, index );
329 }
330 else
331 {
332 m_Body.Insert( container );
333 }
334
335 if ( immedUpdate )
336 RecomputeOpenedContainers();
337 }
338
340 {
341 EntityAI ent = GetFocusedItem();
342 return ent && ( ent.GetInventory().GetCargo() || ent.GetSlotsCountCorrect() > 0 );
343 }
344
346 {
347 EntityAI ent = GetFocusedItem();
348 return ent && QuantityConversions.HasItemQuantity( ent ) && ent.CanBeSplit();
349 }
350
351 override bool IsItemActive()
352 {
353 EntityAI ent = GetFocusedItem();
355 }
356
358 {
359 EntityAI ent = GetFocusedItem();
360 return ent == null;
361 }
362
364 {
366 }
367
368 void DoubleClick(Widget w, int x, int y, int button)
369 {
370 if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
371 {
372 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
373
374 if( w == null || m_Player.GetInventory().IsInventoryLocked() )
375 {
376 return;
377 }
378 ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
379 if( !iw )
380 {
381 string name = w.GetName();
382 name.Replace( "PanelWidget", "Render" );
383 iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
384 }
385 if( !iw )
386 {
387 iw = ItemPreviewWidget.Cast( w );
388 }
389
390 ItemBase item = ItemBase.Cast( iw.GetItem() );
391
392 if( !item )
393 {
394 return;
395 }
396
397 SlotsIcon icon;
398 iw.GetUserData(icon);
399
400 if(icon && icon.IsReserved())
401 {
402 return;
403 }
404
405 if( !item.GetInventory().CanRemoveEntity() )
406 return;
407
408 if ( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
409 {
410 player.PredictiveTakeEntityToHands( item );
411 }
412 else
413 {
414 if (player.GetInventory().CanAddEntityToInventory( item ) && item.GetInventory().CanRemoveEntity())
415 {
416 if( item.GetTargetQuantityMax() < item.GetQuantity() )
417 item.SplitIntoStackMaxClient( player, -1 );
418 else
419 player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ANY, item );
420 }
421 else
422 {
423 if( item.GetTargetQuantityMax() < item.GetQuantity() )
424 item.SplitIntoStackMaxHandsClient( player );
425 else
426 player.PredictiveTakeEntityToHands( item );
427 }
428 }
429 ToggleWidget( w );
430 HideOwnedTooltip();
431
432 InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
433 if ( menu )
434 {
435 menu.RefreshQuickbar();
436 }
437 }
438 }
439
441 {
442 if( m_PlayerAttachmentsContainer.IsActive() )
443 {
444 ToggleWidget(m_PlayerAttachmentsContainer.GetFocusedSlotsIcon().GetPanelWidget());
445 }
446 }
447
449 {
450 return GetFocusedContainer().IsInherited( ContainerWithCargo );
451 }
452
454 {
455 return GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments );
456 }
457
459 {
460 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
461 {
462 return GetFocusedContainer().TransferItemToVicinity();
463 }
464 else
465 {
466 Man player = GetGame().GetPlayer();
467 ItemBase item = ItemBase.Cast(GetFocusedItem());
468 if( item && player.CanDropEntity( item ) )
469 {
470 if( item.GetTargetQuantityMax() < item.GetQuantity() )
471 item.SplitIntoStackMaxClient( null, -1 );
472 else
473 player.PhysicalPredictiveDropItem( item );
474 return true;
475 }
476 }
477 return false;
478 }
479
480 override bool InspectItem()
481 {
482 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
483 {
484 return GetFocusedContainer().InspectItem();
485 }
486 else
487 {
488 Man player = GetGame().GetPlayer();
489 EntityAI item = GetFocusedItem();
490 if( item )
491 {
492 InspectItem( item );
493 return true;
494 }
495 }
496 return false;
497 }
498
499 int GetRecipeCount( bool recipe_anywhere, EntityAI entity1, EntityAI entity2 )
500 {
501 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
502 return plugin_recipes_manager.GetValidRecipes( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ), null, PlayerBase.Cast( GetGame().GetPlayer() ) );
503 }
504
505 override bool SplitItem()
506 {
507 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
508 {
509 return GetFocusedContainer().SplitItem();
510 }
511
512 return false;
513 }
514
515 override bool EquipItem()
516 {
517 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
518 {
519 return GetFocusedContainer().EquipItem();
520 }
521 else
522 {
523 EntityAI item = GetFocusedItem();
524 if( item )
525 {
526 GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, item );
527 return true;
528 }
529 }
530 return false;
531 }
532
533 override bool TransferItem()
534 {
535 LeftArea left_area = LeftArea.Cast( GetParent() );
536 EntityAI item;
537 if( left_area )
538 {
539 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
540 {
541 return GetFocusedContainer().TransferItem();
542 }
543 else
544 {
545 item = GetFocusedItem();
546 if( item )
547 {
548 GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
549 return true;
550 }
551 }
552 }
553 else
554 {
555 if( !GetFocusedContainer().IsInherited( ContainerWithCargo ) && !GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
556 {
557 item = GetFocusedItem();
558 if( item )
559 {
560 GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
561 return true;
562 }
563 }
564 }
565 return false;
566 }
567
569 {
570 return GetFocusedContainer().GetFocusedItem();
571 }
572
573 override bool Combine()
574 {
575 if( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
576 {
577 return GetFocusedContainer().Combine();
578 }
579 else
580 {
581 EntityAI item = GetFocusedItem();
582 ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
583
585
586 if( item_in_hands && item )
587 {
588 return hands_icon.CombineItems( item_in_hands, item );
589 }
590 }
591 return true;
592 }
593
594 override bool Select()
595 {
596 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
597 {
598 return GetFocusedContainer().Select();
599 }
600 else
601 {
602 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
604 SlotsIcon focused_slot = GetFocusedSlotsIcon();
605 EntityAI focused_item = focused_slot.GetEntity();
606 if( focused_slot.IsReserved() || focused_item != selected_item )
607 {
608 if( selected_item )
609 {
610 if( selected_item.GetInventory().CanRemoveEntity() )
611 {
612 if( m_Player.GetInventory().CanAddAttachmentEx( selected_item, focused_slot.GetSlotID() ) )
613 {
614 player.PredictiveTakeEntityToTargetAttachmentEx( m_Player, selected_item, focused_slot.GetSlotID());
615 //m_Player.PredictiveTakeEntityAsAttachmentEx( selected_item, focused_slot.GetSlotID() );
616 ItemManager.GetInstance().SetSelectedItem( null, null, null, null );
617 return true;
618
619 }
620 else if( m_Player.GetInventory().CanAddAttachment( selected_item ) )
621 {
622 player.PredictiveTakeEntityToTargetAttachment( m_Player, selected_item );
623 //m_Player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, selected_item );
624 ItemManager.GetInstance().SetSelectedItem( null, null, null, null );
625 return true;
626 }
627 }
628 }
629 else
630 {
631 if( focused_item && focused_item.GetInventory().CanRemoveEntity() )
632 {
633 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
634 if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
635 {
636 if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
637 {
638 player.PredictiveSwapEntities( item_in_hands, focused_item );
639 return true;
640 }
641 else
642 {
643 InventoryLocation il_hands_dst = new InventoryLocation;
644 if( player.GetHumanInventory().FindFreeLocationFor( item_in_hands, FindInventoryLocationType.ANY, il_hands_dst ) )
645 {
646 InventoryMode invMode = InventoryMode.PREDICTIVE;
647
648 if ( player.NeedInventoryJunctureFromServer(item_in_hands, item_in_hands.GetHierarchyParent(), il_hands_dst.GetParent()) || GetGame().GetPlayer().NeedInventoryJunctureFromServer(focused_item, focused_item.GetHierarchyParent(), GetGame().GetPlayer()) )
649 invMode = InventoryMode.JUNCTURE;
650
651 player.GetHumanInventory().ForceSwapEntities( invMode, focused_item, item_in_hands, il_hands_dst );
652 return true;
653 }
654 }
655 }
656 else
657 {
658 if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
659 {
660 player.PredictiveTakeEntityToHands( focused_item );
661 return true;
662 }
663 }
664 }
665 }
666 }
667 }
668 return false;
669 }
670
671 void SetPlayer( PlayerBase player )
672 {
673 if( m_Player )
674 {
675 m_Player.GetOnItemAttached().Remove(ItemAttached);
676 m_Player.GetOnItemDetached().Remove(ItemDetached);
677 m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
678 m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
679 }
680 m_Player = player;
681 if( m_Player )
682 {
683 m_Player.GetOnItemAttached().Insert(ItemAttached);
684 m_Player.GetOnItemDetached().Insert(ItemDetached);
685 m_Player.GetOnAttachmentSetLock().Insert(OnAttachmentReservationSet);
686 m_Player.GetOnAttachmentReleaseLock().Insert(OnAttachmentReservationRelease);
687 }
688
689 //START - InitGhostSlots
690 string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
691 ref array<string> player_ghosts_slots = new array<string>;
692 GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
693
694 for ( int i = 0; i < player_ghosts_slots.Count(); i++ )
695 {
696 string slot_name = player_ghosts_slots.Get ( i );
697
698 int column = i % ITEMS_IN_ROW;
699 int row = i / ITEMS_IN_ROW;
700
701 SlotsIcon icon = GetSlotsIcon( row, column );
702
704 icon.GetMainWidget().Show( true );
705 icon.Clear();
706
707 GetGame().ConfigGetText( "CfgSlots" + " " + slot_name + " name", slot_name );
708 EntityAI item = m_Player.GetInventory().FindAttachment( InventorySlots.GetSlotIdFromString( slot_name ) );
709 if( item )
710 {
711 ItemAttached( item, slot_name );
712 }
713 }
714 }
715
716 override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
717 {
719
720 if( !ipw.IsInherited( ItemPreviewWidget ) )
721 {
722 return;
723 }
724
725 EntityAI item = ipw.GetItem();
726 if( !item )
727 {
728 return;
729 }
730
731 if( !item.GetInventory().CanRemoveEntity() )
732 return;
733
734 if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) )
735 {
736 m_Player.PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT, item );
737 }
738 }
739
741 {
742 ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
743 if( !ipw )
744 {
745 string name = w.GetName();
746 name.Replace( "PanelWidget", "Render" );
747 ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
748 }
749 if( !ipw )
750 {
751 ipw = ItemPreviewWidget.Cast( w );
752 }
753
754 return ipw;
755 }
756
757 override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
758 {
759 if( w == null )
760 {
761 return;
762 }
764
765 if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
766 {
767 return;
768 }
769
770 EntityAI item = ipw.GetItem();
771 if( !item )
772 {
773 return;
774 }
775
776 if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && !m_Player.GetInventory().HasEntityInInventory( item ) )
777 {
779 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
781 }
782 else
783 {
785 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
787 //ItemManager.GetInstance().ShowSourceDropzone( item );
788 }
789 }
790
791 override void DraggingOver( Widget w, int x, int y, Widget receiver )
792 {
793 if( w == null )
794 {
795 return;
796 }
797
798 EntityAI receiver_item;
799 bool is_reserved = false;
800
801 SlotsIcon slots_icon;
802 receiver.GetUserData(slots_icon);
803
804 if(slots_icon)
805 {
806 receiver_item = slots_icon.GetEntity();
807 is_reserved = slots_icon.IsReserved();
808 }
809
811
812 if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
813 {
814 return;
815 }
816
817 EntityAI item = ipw.GetItem();
818 if( !item )
819 {
820 return;
821 }
822
823 if( receiver_item && !is_reserved )
824 {
825 if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
826 {
829 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
830 return;
831 }
832 else if( receiver_item.GetInventory().CanAddAttachment(item) || receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ))
833 {
836 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
837 return;
838 }
839 else if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
840 {
843 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
844 return;
845 }
846
847 }
848
849 if( item.GetInventory().CanRemoveEntity() )
850 {
851 if( m_Player.GetInventory().CanAddAttachment( item) )
852 {
855 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
856 }
857 else if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) || m_Player.GetHumanInventory().HasEntityInHands( item ) )
858 {
861 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
862 }
863 else if ( receiver_item && GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
864 {
867 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
868 }
869 else
870 {
873 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
874 }
875 }
876 else
877 {
880 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
881 //ItemManager.GetInstance().ShowSourceDropzone( item );
882 }
883 }
884
885 void OnDropReceivedFromGhostArea( Widget w, int x, int y, Widget receiver )
886 {
889
890 EntityAI receiver_item;
891 bool is_reserved = false;
892 InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
893 float stack_max;
894
896 SlotsIcon slots_icon;
897 receiver.GetUserData(slots_icon);
898 int slot_id = slots_icon.GetSlotID();
899
900 receiver_item = slots_icon.GetEntity();
901 is_reserved = slots_icon.IsReserved();
903
904 if ( !ipw )
905 {
906 return;
907 }
908
909 ItemBase item = ItemBase.Cast(ipw.GetItem());
910 PlayerBase real_player = PlayerBase.Cast( GetGame().GetPlayer() );
911 if ( !item )
912 {
913 return;
914 }
915 if ( receiver_item && !is_reserved )
916 {
917 if ( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
918 {
919 GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
920
921 if ( menu )
922 {
923 menu.RefreshQuickbar();
924 }
925 return;
926 }
927 else if ( receiver_item.GetInventory().CanAddAttachment( item ) )
928 {
929 GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment( receiver_item, item );
930
931 if ( menu )
932 {
933 menu.RefreshQuickbar();
934 }
935 return;
936 }
937 else if ( receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ) )
938 {
939 SplitItemUtils.TakeOrSplitToInventory(real_player, receiver_item,item);
940
941 if ( menu )
942 {
943 menu.RefreshQuickbar();
944 }
945 return;
946 }
947 else if ( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
948 {
949 ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
950 return;
951 }
952 }
953
954 if ( m_Player.GetInventory().CanAddAttachmentEx( item, slot_id ) )
955 {
956 if (item.GetQuantity() > item.GetTargetQuantityMax(slot_id))
957 {
958 item.SplitIntoStackMaxClient( real_player, slot_id );
959 }
960 else
961 {
962 real_player.PredictiveTakeEntityToTargetAttachmentEx( m_Player, item, slots_icon.GetSlotID() );
963 }
964 }
965 else if ( m_Player.GetInventory().CanAddAttachment( item ) )
966 {
967 il = new InventoryLocation;
968 m_Player.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ATTACHMENT, il );
969 float stackable = item.GetTargetQuantityMax(-1);
970
971 if( il.IsValid() )
972 {
973 if ( stackable == 0 || stackable >= item.GetQuantity() )
974 {
975 real_player.PredictiveTakeEntityToTargetAttachment( il.GetParent(), item );
976 }
977 else
978 {
979
980 ItemBase.Cast(item).SplitIntoStackMaxToInventoryLocationClient( il );
981 }
982 }
983 }
984 else if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) || m_Player.GetHumanInventory().HasEntityInHands( item ) )
985 {
987 }
988
989 if ( menu )
990 {
991 menu.RefreshQuickbar();
992 }
993 }
994
995 void SwapItemsInOrder( int slot1, int slot2 )
996 {
997 EntityAI item1 = m_Player.GetInventory().FindAttachment( slot1 );
998 EntityAI item2 = m_Player.GetInventory().FindAttachment( slot2 );
999
1000 if( item1 && item2 )
1001 {
1002 Container cont1 = m_ShowedItems.Get( item1 );
1003 Container cont2 = m_ShowedItems.Get( item2 );
1004 if( cont1 && cont2 )
1005 {
1006 int sort1 = cont1.GetRootWidget().GetSort();
1007 int sort2 = cont2.GetRootWidget().GetSort();
1008
1009 cont1.GetRootWidget().SetSort( sort2 );
1010 cont2.GetRootWidget().SetSort( sort1 );
1011
1012 m_Body.SwapItems( m_Body.Find( cont1 ), m_Body.Find( cont2 ) );
1013 }
1014 }
1015 RecomputeOpenedContainers();
1016 }
1017
1018 override void UpdateInterval()
1019 {
1020 int i;
1021 for ( i = 0; i < m_InventorySlots.Count(); i++ )
1022 {
1023 SlotsIcon icon = m_InventorySlots.GetElement( i );
1024 if ( icon )
1025 {
1026 icon.UpdateInterval();
1027 }
1028 }
1029 for ( i = 0; i < m_ShowedItems.Count(); i++ )
1030 {
1031 Container cont = m_ShowedItems.GetElement( i );
1032 if ( cont )
1033 {
1034 cont.UpdateInterval();
1035 }
1036 }
1037 }
1038
1039 // Call from ToggleWidget
1041 {
1043 item.GetInventory().GetCurrentInventoryLocation( il );
1044 SlotsIcon icon = m_InventorySlots.Get( il.GetSlot() );
1045 ClosableContainer c = ClosableContainer.Cast( m_ShowedItems.Get( item ) );
1046 if (c)
1047 {
1048 c.Toggle();
1049 Refresh();
1050 }
1051 }
1052
1053 override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
1054 {
1055 if (focusedEntity)
1056 {
1057 ClosableContainer c = ClosableContainer.Cast( m_ShowedItems.Get( focusedEntity ) );
1058 if (c && c.IsDisplayable())
1059 {
1060 return true;
1061 }
1062 }
1063 return false;
1064 }
1065
1066 // Mouse button UP or Call other fn
1068 {
1070 {
1071 return;
1072 }
1073 string name = w.GetName();
1074 name.Replace( "PanelWidget", "Render" );
1075 ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
1076 if( ipw.GetItem() )
1077 {
1078 ToggleContainer( w, ipw.GetItem() );
1079 RecomputeOpenedContainers();
1080 }
1081
1082 Refresh();
1083 }
1084
1086 {
1087 super.CollapseButtonOnMouseButtonDown(w);
1088 }
1089
1091 {
1092 if( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
1093 {
1094 return false;
1095 }
1096
1097 return true;
1098 }
1099
1100 override void Refresh()
1101 {
1102 super.Refresh();
1103 m_MainWidget.Update();
1104 m_RootWidget.Update();
1105 UpdateSelectionIcons();
1106 }
1107
1108 override bool OnChildRemove( Widget w, Widget child )
1109 {
1110 Refresh();
1111 return true;
1112 }
1113
1114 override bool OnChildAdd( Widget w, Widget child )
1115 {
1116 Refresh();
1117 return true;
1118 }
1119}
InventoryMode
Definition Inventory.c:20
const int ITEMS_IN_ROW
Definition Attachments.c:1
void Inventory(LayoutHolder parent)
Definition Inventory.c:75
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()
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition ItemBase.c:5444
PlayerBase GetPlayer()
string name
PluginBase GetPlugin(typename plugin_type)
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
override void SetHeader(Header header)
SlotsIcon GetSlotsIcon(int row, int column, bool include_invisible=true)
proto native DayZPlayer GetPlayer()
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native void ConfigGetTextArray(string path, out TStringArray values)
Get array of strings from config on path.
proto native bool ConfigIsExisting(string path)
override bool IsOpened()
override bool IsDisplayable()
protected ref CollapsibleHeader m_CollapsibleHeader
override void Remove(LayoutHolder container)
override Header GetHeader()
override void SetHeader(Header header)
static int GREEN_COLOR
static ColorManager GetInstance()
static int RED_COLOR
static int SWAP_COLOR
static int COMBINE_COLOR
void SetColor(Widget w, int color)
override void UnfocusAll()
override void UpdateInterval()
script counterpart to engine's class Inventory
Definition Inventory.c:77
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:601
void SetName(string name)
Definition Header.c:33
Definition Icon.c:2
bool CombineItems(EntityAI entity1, EntityAI entity2)
Definition Icon.c:794
InventoryLocation.
proto native bool IsValid()
verify current set inventory location
proto native EntityAI GetParent()
returns parent of current inventory location
proto native int GetSlot()
returns slot id if current type is Attachment
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static proto native owned string GetSlotDisplayName(int id)
converts slot_id to string
EntityAI GetSelectedItem()
Definition ItemManager.c:82
HandsPreview GetHandsPreview()
Definition ItemManager.c:72
void SetWidgetDraggable(Widget w, bool draggable)
void HideDropzones()
bool IsDragging()
void SetSelectedItem(EntityAI selected_item, Container selected_container, Widget selected_widget, SlotsIcon selected_icon)
Widget GetRightDropzone()
void SetIsDragging(bool is_dragging)
static ItemManager GetInstance()
proto native EntityAI GetItem()
bool HasEntityContainerVisible(EntityAI entity)
override void DraggingOver(Widget w, int x, int y, Widget receiver)
override bool IsItemActive()
override bool OnChildAdd(Widget w, Widget child)
override bool InspectItem()
float GetMainContainerBottomPos()
override void Refresh()
protected ref AttachmentsGroupContainer m_PlayerAttachmentsContainer
protected ref map< int, SlotsIcon > m_InventorySlots
void ToggleContainer(Widget w, EntityAI item)
void ToggleWidget(Widget w)
void OnDropReceivedFromGhostArea(Widget w, int x, int y, Widget receiver)
override void UpdateInterval()
bool IsItemWithAttachmentsActive()
override bool TransferItem()
protected ref map< int, ref Container > m_ShowedItemsIDs
ItemPreviewWidget GetItemPreviewWidget(Widget w)
override bool TransferItemToVicinity()
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
void PlayerContainer(LayoutHolder parent, int sort=-1)
override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
override bool OnChildRemove(Widget w, Widget child)
override void UpdateRadialIcon()
void MouseClick(Widget w, int x, int y, int button)
void DoubleClick(Widget w, int x, int y, int button)
void SetPlayer(PlayerBase player)
override void ExpandCollapseContainer()
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
protected PlayerBase m_Player
SlotsIcon GetSlotsIcon(int row, int column)
override bool Combine()
override bool EquipItem()
override bool IsItemWithQuantityActive()
bool IsItemWithContainerActive()
void AddSlotsContainer(int row_count)
override void CollapseButtonOnMouseButtonDown(Widget w)
void SwapItemsInOrder(int slot1, int slot2)
protected ref map< EntityAI, ref Container > m_ShowedItems
override void Insert(LayoutHolder container, int pos=-1, bool immedUpdate=true)
void ItemAttached(EntityAI item, string slot_name)
void OnAttachmentReservationSet(EntityAI item, int slot_id)
override bool Select()
protected const int HEADER_INDEX_OFFSET
void ItemDetached(EntityAI item, string slot_name)
void OnAttachmentReservationRelease(EntityAI item, int slot_id)
bool IsContainerWithCargoActive()
override EntityAI GetFocusedItem()
void UnfocusPlayerAttachmentsContainer()
override bool SplitItem()
float GetMainContainerTopPos()
int GetRecipeCount(bool recipe_anywhere, EntityAI entity1, EntityAI entity2)
static int HasItemQuantity(notnull EntityAI item)
void SetSlotDisplayName(string text)
Definition SlotsIcon.c:144
Widget GetRadialIconPanel()
Definition SlotsIcon.c:295
override void UpdateInterval()
Definition SlotsIcon.c:669
EntityAI GetEntity()
Definition SlotsIcon.c:353
int GetSlotID()
Definition SlotsIcon.c:190
void Clear()
Definition SlotsIcon.c:502
void SetSlotParent(EntityAI parent)
Definition SlotsIcon.c:134
bool IsReserved()
Definition SlotsIcon.c:200
Widget GetPanelWidget()
Definition SlotsIcon.c:205
ImageWidget GetGhostSlot()
Definition SlotsIcon.c:235
void SetSlotID(int slot_ID)
Definition SlotsIcon.c:195
void Init(EntityAI obj, bool reservation=false)
Definition SlotsIcon.c:460
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
static const int IMAGESETGROUP_INVENTORY
static string VerifyIconImageString(int imageset_group=IMAGESETGROUP_INVENTORY, string icon_name="")
Checks for improperly formated, legacy image names and corrects them to default format.
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 RegisterOnChildRemove(Widget w, Managed eventHandler, string functionName)
void RegisterOnDropReceived(Widget w, Managed eventHandler, string functionName)
void RegisterOnChildAdd(Widget w, Managed eventHandler, string functionName)
void RegisterOnDraggingOver(Widget w, Managed eventHandler, string functionName)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
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'.
proto native Widget GetParent()
Get parent of the Effect.
Definition Effect.c:396