DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
HandsContainer.c
Go to the documentation of this file.
2{
3 protected bool m_Hidden;
6
7 protected ref Attachments m_Atts;
9
14
15 protected int m_StaticAttCount = 0;
16 protected int m_StaticCargoCount = 0;
17
18 protected ScrollWidget m_ScrollWidget;
19
21 {
25
26 m_CollapsibleHeader = new HandsHeader( this, "CollapseButtonOnMouseButtonDown" );
27 GetMainWidget().SetFlags( WidgetFlags.IGNOREPOINTER );
28 m_MainWidget = m_MainWidget.FindWidget( "body" );
29 GetMainWidget().SetFlags( WidgetFlags.IGNOREPOINTER );
30 m_Body = new array<ref LayoutHolder>;
31 m_HandsPreview = new HandsPreview( this );
33 m_Body.Insert( m_HandsPreview );
34
35 ItemBase hands_item = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
36 if ( hands_item )
37 m_HandsPreview.CreateNewIcon( hands_item );
38
39 m_ScrollWidget = ScrollWidget.Cast( m_RootWidget.GetParent().GetParent() );
40 RecomputeOpenedContainers();
41 }
42
44 {
45 if ( m_Entity )
46 {
47 m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
48 m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
49 }
50
51 m_AttachmentCargos.Clear();
54 }
55
57 {
58 m_Body.Clear();
59 m_Body.Insert( m_HandsPreview );
60 }
61
62 override Header GetHeader()
63 {
65 }
66
67 override bool IsLastIndex()
68 {
69 return m_ActiveIndex == m_OpenedContainers.Count() - 1;
70 }
71
73 {
74 int index = m_ActiveIndex - 1;
75 int attachment_start_index = -1;
76 int cargo_start_index = -1;
77 int attachment_end_index = -1;
78 int cargo_end_index = -1;
79
80 if ( m_Atts || m_AttachmentAttachments.Count() > 0 )
81 {
82 attachment_start_index = 0;
83 if ( m_Atts )
84 attachment_end_index++;
85 attachment_end_index += m_AttachmentAttachments.Count();
86 }
87
88 if ( m_CargoGrid || m_AttachmentCargos.Count() > 0 )
89 {
90 cargo_start_index = attachment_end_index + 1;
91 if ( m_CargoGrid )
92 cargo_end_index++;
93 cargo_end_index += cargo_start_index + m_AttachmentCargos.Count();
94 }
95
96 if ( m_ActiveIndex > m_OpenedContainers.Count() )
97 {
98 m_ActiveIndex = m_OpenedContainers.Count();
99 }
100
101 if ( index == -1 )
102 {
103 #ifdef PLATFORM_CONSOLE
104 if ( m_MainWidget.FindAnyWidget("Selected") )
105 m_MainWidget.FindAnyWidget("Selected").Show( true );
106 #endif
107 m_ScrollWidget.VScrollToPos01( 0 );
108 }
109 else
110 {
111 if( index.InRange( 0, attachment_end_index ) )
112 {
113 if( m_Atts )
114 {
115 if( index == 0 )
116 {
118 SetFocusedContainer( m_Atts.GetWrapper() );
119 }
120 else
121 {
122 m_AttachmentAttachments.GetElement( index - 1 ).SetDefaultFocus();
123 SetFocusedContainer( m_AttachmentAttachments.GetElement( index - 1 ).GetWrapper() );
124 }
125 }
126 else
127 {
128 m_AttachmentAttachments.GetElement( index ).SetDefaultFocus();
129 SetFocusedContainer( m_AttachmentAttachments.GetElement( index ).GetWrapper() );
130 }
131 }
132 else if( index.InRange( cargo_start_index, cargo_end_index ) )
133 {
134 if( m_CargoGrid )
135 {
136 if( index == cargo_start_index )
137 {
138 m_CargoGrid.SetDefaultFocus();
139 SetFocusedContainer( m_CargoGrid );
140 }
141 else
142 {
143 m_AttachmentCargos.GetElement( index - 1 - cargo_start_index ).SetDefaultFocus();
144 SetFocusedContainer( m_AttachmentCargos.GetElement( index - 1 - cargo_start_index ) );
145 }
146 }
147 else
148 {
149 m_AttachmentCargos.GetElement( index - cargo_start_index ).SetDefaultFocus();
150 SetFocusedContainer( m_AttachmentCargos.GetElement( index - cargo_start_index ) );
151 }
152 }
153
154 if( m_MainWidget.FindAnyWidget("Selected") )
155 m_MainWidget.FindAnyWidget("Selected").Show( false );
156 ScrollToActiveContainer( GetFocusedContainer() );
157 }
158 }
159
160 void ScrollToActiveContainer( Container active_container )
161 {
162 if( !active_container )
163 return;
164 float x, y, y_s;
165 m_ScrollWidget.GetScreenPos( x, y );
166 m_ScrollWidget.GetScreenSize( x, y_s );
167 float amount;
168 float next_pos = active_container.GetFocusedContainerYScreenPos( true ) + active_container.GetFocusedContainerHeight( true );
169
170 if( next_pos > ( y + y_s ) )
171 {
172 amount = y + active_container.GetFocusedContainerYScreenPos( true );
173 m_ScrollWidget.VScrollToPos( m_ScrollWidget.GetVScrollPos() + active_container.GetFocusedContainerHeight( true ) + 2 );
174 }
175 else if( active_container.GetFocusedContainerYScreenPos( true ) < y )
176 {
177 amount = active_container.GetFocusedContainerYScreenPos( true ) - y;
178 m_ScrollWidget.VScrollToPos( m_ScrollWidget.GetVScrollPos() + amount - 2 );
179 }
180 }
181
182 override void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
183 {
184 super.Insert( container, pos, immedUpdate );
185 }
186
187 void MouseClick2( Widget w, int x, int y, int button )
188 {
189 string name = w.GetName();
190 name.Replace( "PanelWidget", "Render" );
191 ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
192
193 if( !item_preview )
194 {
195 return;
196 }
197
198 EntityAI item = item_preview.GetItem();
199 InventoryItem itemAtPos = InventoryItem.Cast( item );
200
201 if( item )
202 {
203 if ( button == MouseState.MIDDLE )
204 {
205 InspectItem( itemAtPos );
206 }
207 }
208 }
209
210 void DraggingOverHeader2(Widget w, int x, int y, Widget receiver )
211 {
212 DraggingOverHeader(w, x, y, receiver );
213 }
214
215 override bool TransferItem()
216 {
217 if(m_ActiveIndex == 0)
218 {
219 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
220 if( item_in_hands && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null) )
221 {
222 if( GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item_in_hands ) )
223 {
224 m_MainWidget.FindAnyWidget("Selected").Show( false );
225 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
226 return true;
227 }
228 }
229 }
230 else if( GetFocusedContainer() )
231 {
232 return GetFocusedContainer().TransferItem();
233 }
234 return false;
235 }
236
237 override bool SplitItem()
238 {
239 if (m_ActiveIndex == 0)
240 {
241 ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
242 if ( item_in_hands )
243 {
244 if ( item_in_hands.CanBeSplit() )
245 {
246 item_in_hands.OnRightClick();
247 }
248 }
249 }
250 else if( GetFocusedContainer() )
251 {
252 return GetFocusedContainer().SplitItem();
253 }
254 return false;
255 }
256
257 override bool EquipItem()
258 {
259 if (m_ActiveIndex == 0)
260 {
261 ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
262 if ( item_in_hands )
263 {
264 if ( GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null) )
265 {
266 if ( GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, item_in_hands ) )
267 {
268 m_MainWidget.FindAnyWidget("Selected").Show( false );
269 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
270 return true;
271 }
272 }
273 }
274 }
275 else if( GetFocusedContainer() )
276 {
277 return GetFocusedContainer().EquipItem();
278 }
279 return false;
280 }
281
282 override void SetActive( bool active )
283 {
284 super.SetActive(active);
285 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
286 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
287
288 if( item_in_hands )
289 {
290 if( m_MainWidget.FindAnyWidget( "Selected" ) )
291 {
292 m_MainWidget.FindAnyWidget( "Selected" ).Show( active );
293 }
294
295 if( active )
296 {
297 float x, y;
298 GetMainWidget().GetScreenPos( x, y );
299 PrepareOwnedTooltip( item_in_hands, -1, y );
300 }
301 }
302 else
303 {
304 if( active )
305 m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
306 else
307 m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.7 );
308 }
309 }
310
311 override void SetLastActive()
312 {
313 super.SetLastActive();
314 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
315 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
316
317 if( item_in_hands )
318 {
319 if ( m_ActiveIndex == 0)
320 {
321 if( m_MainWidget.FindAnyWidget( "Selected" ) )
322 {
323 m_MainWidget.FindAnyWidget( "Selected" ).Show( true );
324 }
325
326 float x, y;
327 GetMainWidget().GetScreenPos( x, y );
328 PrepareOwnedTooltip( item_in_hands, x, y );
329 }
330 }
331 else
332 {
333 m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
334 }
335 }
336
337 override void Refresh()
338 {
339 super.Refresh();
341 }
342
343 override bool IsItemActive()
344 {
345 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
346 ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
347 if( item == null )
348 {
349 return false;
350 }
351 return !IsEmpty() && ( !QuantityConversions.HasItemQuantity( item ) || ( QuantityConversions.HasItemQuantity( item ) && !item.CanBeSplit() ) );
352 }
353
355 {
356 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
357 ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
358 if( item == null )
359 {
360 return false;
361 }
362 return !IsEmpty() && QuantityConversions.HasItemQuantity( item ) && item.CanBeSplit();
363 }
364
365 override bool IsEmpty()
366 {
367 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
368 return player.GetHumanInventory().GetEntityInHands() == null;
369 }
370
372 {
373 if (m_ActiveIndex == 0)
374 {
375 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
376 ItemBase item_in_hands = ItemBase.Cast(player.GetHumanInventory().GetEntityInHands());
377 if ( item_in_hands && player.CanDropEntity( item_in_hands ) && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !player.GetInventory().HasInventoryReservation(item_in_hands, null) )
378 {
379 if ( item_in_hands.GetTargetQuantityMax() < item_in_hands.GetQuantity() )
380 item_in_hands.SplitIntoStackMaxClient( null, -1 );
381 else
382 player.PhysicalPredictiveDropItem( item_in_hands );
383 m_MainWidget.FindAnyWidget("Selected").Show( false );
384 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
385 return true;
386 }
387 }
388 else if ( GetFocusedContainer() )
389 {
390 return GetFocusedContainer().TransferItemToVicinity();
391 }
392 return false;
393 }
394
395 override bool InspectItem()
396 {
397 if(m_ActiveIndex == 0)
398 {
399 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
400 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
401 if( item_in_hands )
402 {
403 InspectItem( item_in_hands );
404 return true;
405 }
406 }
407 else if( GetFocusedContainer() )
408 {
409 return GetFocusedContainer().InspectItem();
410 }
411 return false;
412 }
413
414 override bool OnSelectButton()
415 {
416 if(m_ActiveIndex == 0)
417 {
419 {
421 if( selectedItem == GetFocusedItem() )
422 {
423 Inventory.GetInstance().DisableMicromanagement();
424 return true;
425 }
426 else
427 {
428 return Select();
429 }
430 }
431 else
432 {
433 Inventory.GetInstance().EnableMicromanagement();
434 return true;
435 }
436 }
437 else
438 {
439 if( GetFocusedContainer() )
440 {
441 return GetFocusedContainer().OnSelectButton();
442 }
443 }
444 return false;
445 }
446
448 {
449 ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
450 if( !ipw )
451 {
452 string name = w.GetName();
453 name.Replace( "PanelWidget", "Render" );
454 ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
455 }
456
457 if( !ipw )
458 {
459 ipw = ItemPreviewWidget.Cast( w );
460 }
461
462 if( !ipw )
463 {
464 return null;
465 }
466
467 return ipw.GetItem();
468 }
469
470 override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
471 {
472 if( w == null )
473 {
474 return;
475 }
476 EntityAI receiver_item;
477 EntityAI slot_owner;
478 int slot_id = -1;
479
480 string name = w.GetName();
481 name.Replace( "PanelWidget", "Render" );
482
483 ItemPreviewWidget w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
484 if( w_ipw == null )
485 {
486 w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
487 }
488 if( w_ipw == null )
489 {
490 return;
491 }
492
493 SlotsIcon slots_icon;
494 receiver.GetUserData(slots_icon);
495
496 if(slots_icon)
497 {
498 receiver_item = slots_icon.GetEntity();
499 slot_id = slots_icon.GetSlotID();
500 slot_owner = slots_icon.GetSlotParent();
501 }
502
503
504 PlayerBase p = PlayerBase.Cast( GetGame().GetPlayer() );
505 InventoryItem receiver_entity = InventoryItem.Cast( p.GetHumanInventory().GetEntityInHands() );
506 InventoryItem w_entity = InventoryItem.Cast( w_ipw.GetItem() );
507 if( !w_entity )
508 {
509 return;
510 }
511
512 if( receiver_entity )
513 {
514 if( receiver_item )
515 {
516 ItemBase receiver_itemIB = ItemBase.Cast( receiver_item );
517 ItemBase itemIB = ItemBase.Cast( receiver_item );
518 if( receiver_itemIB && itemIB && receiver_itemIB.CanBeCombined( itemIB ) )
519 {
521 if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
522 {
523 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
524 }
525 else
526 {
527 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
528 }
530 }
531 else
532 {
533 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
534 Magazine mag = Magazine.Cast(receiver_item);
535 Weapon_Base wpn = Weapon_Base.Cast(receiver_item.GetHierarchyParent());
536
537 if( wpn && mag )
538 {
539 if( player.GetWeaponManager().CanSwapMagazine( wpn, Magazine.Cast(w_entity) ) )
540 {
542 if( w_entity.GetHierarchyRootPlayer() == player )
543 {
544 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
545 }
546 else
547 {
548 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
549 }
550 }
551 else
552 {
555 }
556 }
557 else
558 {
559 if( GameInventory.CanSwapEntitiesEx( receiver_item, w_entity ) )
560 {
562 if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
563 {
564 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
565 }
566 else
567 {
568 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
569 }
571 }
572 else if( receiver_itemIB.GetInventory().CanAddAttachment( w_entity ) )
573 {
575 if( receiver_itemIB.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
576 {
577 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
578 }
579 else
580 {
581 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
582 }
584 }
585 }
586 }
587 }
588 else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( w_entity ) )
589 {
591 ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
593 }
594 else if( receiver_entity.GetInventory().CanAddAttachment( w_entity ) )
595 {
597 if( receiver_entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
598 {
599 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
600 }
601 else
602 {
603 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
604 }
606 }
607 else
608 {
611 }
612 }
613 else
614 {
615 /*if( m_HandsIcon )
616 {
617 ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
618 ItemManager.GetInstance().HideDropzones();
619 ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
620 }
621
622 else
623 {*/
626 //}
627 }
628 }
629
630 void OnDropReceivedFromHeader2( Widget w, int x, int y, Widget receiver )
631 {
632 TakeAsAttachment( w, receiver );
633 }
634
635 void OnPerformCombination(int combinationFlags)
636 {
638 if ( m_am_entity1 == null || m_am_entity2 == null ) return;
639
640 if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
641
642 if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
643 {
644 Magazine mag;
645 if ( Class.CastTo(mag, m_am_entity2 ) )
646 {
648 return;
649 }
650 }
651
652 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
653 {
654 if( m_Atts )
655 {
656 m_Body.RemoveItem( m_Atts.GetWrapper() );
657 delete m_Atts;
658 }
659 if( m_am_entity2.GetSlotsCountCorrect() > 0 )
660 {
661 m_Atts = new Attachments( this, m_am_entity2 );
663
664 }
665
666 Refresh();
667 m_Parent.Refresh();
668
669 Weapon_Base wpn1;
670 Magazine mag1;
671 if ( Class.CastTo(wpn1, m_am_entity1 ) && Class.CastTo(mag1, m_am_entity2 ) )
672 {
674 {
676 return;
677 }
678 }
679
680 SplitItemUtils.TakeOrSplitToInventory(m_player, m_am_entity1, m_am_entity2);
681 //m_player.PredictiveTakeEntityToTargetAttachment( m_am_entity1, m_am_entity2 );
682 }
683
684 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
685 {
686 m_player.PredictiveTakeEntityToTargetCargo( m_am_entity1, m_am_entity2 );
687 }
688
689 if ( combinationFlags & InventoryCombinationFlags.SWAP )
690 {
691 Magazine swapmag1;
692 Magazine swapmag2;
693 if (Class.CastTo(swapmag1, m_am_entity1 ) && Class.CastTo(swapmag2, m_am_entity2 ) )
694 {
695 if( m_player.GetWeaponManager().CanSwapMagazine( Weapon_Base.Cast( swapmag1.GetParent() ), Magazine.Cast( swapmag2 ) ) )
696 {
698 return;
699 }
700
701 if( m_player.GetWeaponManager().CanSwapMagazine(Weapon_Base.Cast( swapmag2.GetParent() ), Magazine.Cast( swapmag1 )) )
702 {
704 return;
705 }
706 }
707 if ( !m_player.PredictiveSwapEntities( m_am_entity1, m_am_entity2 ) && m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity1 ) )
708 {
709 m_player.PredictiveTakeEntityToHands( m_am_entity1 );
710 }
711 }
712
713 if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
714 {
715 if ( m_Atts )
716 {
717 m_Body.RemoveItem( m_Atts.GetWrapper() );
718 delete m_Atts;
719 }
720
721 if ( m_am_entity2.GetSlotsCountCorrect() > 0 )
722 {
723 m_Atts = new Attachments( this, m_am_entity2 );
725
726 }
727 Refresh();
728 m_Parent.Refresh();
729
730 if ( m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity2 ) )
731 {
732 m_player.PredictiveTakeEntityToHands( m_am_entity2 );
733 }
734 }
735 }
736
737 void ShowActionMenuCombine( EntityAI entity1, EntityAI entity2, int combinationFlags )
738 {
739 if ( entity1 && entity2 ) PrintString( "Showing action menu for " + entity1.GetDisplayName() + " and " + entity2.GetDisplayName() );
740
741 ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());
742 m_am_entity1 = entity1;
743 m_am_entity2 = entity2;
744 cmenu.Hide();
745 cmenu.Clear();
746
747 if( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
748 {
749 ItemBase entity = ItemBase.Cast( entity1 );
750 entity.CombineItemsClient( ItemBase.Cast( entity2 ) );
751 return;
752 }
753
754 if ( entity1 == null || entity2 == null ) return;
755
756 if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
757
758 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
759 {
760 cmenu.Add( "#inv_context_add_as_attachment", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_ATTACHMENT ) );
761 }
762 if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
763 {
764 cmenu.Add( "#inv_context_load_chamber", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.LOAD_CHAMBER ) );
765 }
766
767 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
768 {
769 cmenu.Add( "#inv_context_add_as_cargo", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_CARGO ) );
770 }
771
772 if ( combinationFlags & InventoryCombinationFlags.SWAP )
773 {
774 cmenu.Add( "#inv_context_swap", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.SWAP ) );
775 }
776
777 if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
778 {
779 cmenu.Add( "#inv_context_take_to_hands", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.TAKE_TO_HANDS ) );
780 }
781
782 if ( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY )
783 {
784 cmenu.Add( "#inv_context_combine", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.COMBINE_QUANTITY ) );
785 }
786
787 int m_am_pos_x, m_am_pos_y;
788 GetMousePos( m_am_pos_x, m_am_pos_y );
789 m_am_pos_x -= 5;
790 m_am_pos_y -= 5;
791
792 cmenu.Show( m_am_pos_x, m_am_pos_y );
793 }
794
795
796 override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
797 {
798 TakeAsAttachment( w, receiver );
799 }
800
801 int GetCombinationFlags( EntityAI entity1, EntityAI entity2 )
802 {
803 int flags = 0;
805 EntityAI entity_in_hands = m_player.GetHumanInventory().GetEntityInHands();
806
807 if ( !entity1 || !entity2 ) return flags;
808
809 Magazine swapmag1;
810 Magazine swapmag2;
811 bool skipSwap = false;
812
813 if( Class.CastTo(swapmag1, entity1) && Class.CastTo(swapmag2, entity2) )
814 {
815 Weapon_Base parentWpn;
816
817 if( Class.CastTo(parentWpn, swapmag1.GetHierarchyParent()) )
818 {
819 skipSwap = true;
820 if( m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag2) )
821 flags = flags | InventoryCombinationFlags.SWAP;
822 }
823
824 if( Class.CastTo(parentWpn, swapmag2.GetHierarchyParent()) )
825 {
826 skipSwap = true;
827 if( m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag1) )
828 flags = flags | InventoryCombinationFlags.SWAP;
829
830 }
831 }
832
833 if ( !skipSwap )
834 {
835 if ( entity1 == m_player.GetHumanInventory().GetEntityInHands() ) flags = flags | InventoryCombinationFlags.TAKE_TO_HANDS;
836 else if ( GameInventory.CanSwapEntitiesEx( entity1, entity2 ) )
837 {
838 if ( !entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ) )
839 {
840 flags = flags | InventoryCombinationFlags.SWAP;
841 }
842 }
843 }
844
845 if ( entity1.IsInherited( ItemBase) && entity2.IsInherited( ItemBase ) )
846 {
847 ItemBase ent1 = ItemBase.Cast( entity1 );
848 if ( ent1.CanBeCombined( ItemBase.Cast( entity2 ) ) ) flags = flags | InventoryCombinationFlags.COMBINE_QUANTITY2;
849 }
850
851 else if ( entity1.GetInventory().CanAddAttachment( entity2 ) )
852 {
853 if ( !entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ) && !entity2.IsInherited( ZombieBase ) && !entity2.IsInherited( Car ) )
854 {
856 }
857 }
858 if ( entity1.GetInventory().CanAddEntityInCargo( entity2, entity2.GetInventory().GetFlipCargo() ) ) flags = flags | InventoryCombinationFlags.ADD_AS_CARGO;
859
860 if( entity1 == m_player.GetHumanInventory().GetEntityInHands() || entity2 == m_player.GetHumanInventory().GetEntityInHands() )
861 {
863 Class.CastTo(amc, m_player.GetActionManager());
864 if( entity1 == m_player.GetHumanInventory().GetEntityInHands() )
865 {
866 if( amc.CanSetActionFromInventory( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ) ) )
867 {
869 }
870 }
871 else
872 {
873 if( amc.CanSetActionFromInventory( ItemBase.Cast( entity2 ), ItemBase.Cast( entity1 ) ) )
874 {
876 }
877 }
878 }
879
880 if( GetRecipeCount( true, entity1, entity2 ) > 0 )
881 {
883 }
884 return flags;
885 }
886
887 int GetRecipeCount( bool recipe_anywhere, EntityAI entity1, EntityAI entity2 )
888 {
889 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
890 return plugin_recipes_manager.GetValidRecipes( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ), null, PlayerBase.Cast( GetGame().GetPlayer() ) );
891 }
892
894 {
895 m_Entity = null;
897 }
898
900 {
901 if( m_Atts )
902 {
903 m_Body.RemoveItem( m_Atts.GetWrapper() );
904 delete m_Atts;
905
906 if( m_Entity )
907 {
908 m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
909 m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
910 }
911 }
912
914 {
916 {
917 m_Body.RemoveItem( att );
918 m_AttachmentAttachments.Remove( ent );
919 delete att;
920 }
921 }
922
924 Refresh();
925 m_Parent.Refresh();
926 RecomputeOpenedContainers();
927 }
928
929 override void UnfocusGrid()
930 {
931 if( m_Atts )
932 {
934 }
935
936 if( m_CargoGrid )
937 {
938 m_CargoGrid.UnfocusAll();
939 }
940
942 {
943 foreach( EntityAI e1, CargoContainer cargo : m_AttachmentCargos )
944 {
945 cargo.UnfocusAll();
946
947 }
948 }
949
951 {
952 foreach( EntityAI e2, Attachments att : m_AttachmentAttachments )
953 {
954 att.UnfocusAll();
955 }
956 }
957 }
958
959 override void UnfocusAll()
960 {
961 UnfocusGrid();
962 }
963
965 {
966 if( m_CargoGrid )
967 {
968 m_Body.RemoveItem( m_CargoGrid );
969 delete m_CargoGrid;
970 }
971
973 {
974 foreach( CargoContainer cargo : m_AttachmentCargos )
975 {
976 m_Body.RemoveItem( cargo );
977 delete cargo;
978 }
979 }
980
981 m_AttachmentCargos.Clear();
982 Refresh();
983 m_Parent.Refresh();
984 RecomputeOpenedContainers();
985 }
986
987 void DropReceived( Widget w, int x, int y, CargoContainer cargo )
988 {
989 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
990 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
991
992 EntityAI item = GetItemPreviewItem( w );
993 if( !item )
994 {
995 return;
996 }
997
998 int idx = 0;
999 int c_x, c_y;
1000
1001 EntityAI target_entity;
1002 CargoBase target_cargo;
1003
1004 if( cargo == m_CargoGrid )
1005 {
1006 target_entity = m_Entity;
1007 target_cargo = m_Entity.GetInventory().GetCargo();
1008 #ifdef PLATFORM_CONSOLE
1009 if( m_CargoGrid.HasItem( item ) )
1010 {
1011 return;
1012 }
1013 #endif
1014 }
1015 else
1016 {
1017 target_entity = m_AttachmentCargos.GetKeyByValue( cargo );
1018 if( target_entity )
1019 {
1020 target_cargo = target_entity.GetInventory().GetCargo();
1021 #ifdef PLATFORM_CONSOLE
1022 if( cargo.HasItem( item ) )
1023 {
1024 return;
1025 }
1026 #endif
1027 }
1028 else
1029 return;
1030 }
1031
1032 if( target_cargo && target_entity )
1033 {
1034 c_x = target_cargo.GetHeight();
1035 c_y = target_cargo.GetWidth();
1036 }
1037 else
1038 return;
1039
1041 #ifdef PLATFORM_CONSOLE
1042 x = 0;
1043 y = target_cargo.GetItemCount();
1044 target_entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.CARGO, dst );
1045 #else
1046 dst.SetCargoAuto(target_cargo, item, x, y, item.GetInventory().GetFlipCargo());
1047 #endif
1048
1050 item.GetInventory().GetCurrentInventoryLocation(src);
1051 if(src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
1052 return;
1053
1054 #ifdef PLATFORM_CONSOLE
1055 if(dst.IsValid() && target_entity.GetInventory().LocationCanAddEntity(dst))
1056 #else
1057 if( c_x > x && c_y > y && target_entity.GetInventory().LocationCanAddEntity(dst))
1058 #endif
1059 {
1061
1062 Icon icon = cargo.GetIcon( item );
1063
1064 if( icon )
1065 {
1066 if( w && w.FindAnyWidget("Selected") )
1067 w.FindAnyWidget("Selected").SetColor( ColorManager.BASE_COLOR );
1068 icon.Refresh();
1069 Refresh();
1070 }
1071 }
1074 }
1075
1076 bool DraggingOverGrid( Widget w, int x, int y, Widget reciever, CargoContainer cargo )
1077 {
1078 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
1079 if( w == null )
1080 {
1081 return false;
1082 }
1083 EntityAI item = GetItemPreviewItem( w );
1084 if( !item || !item_in_hands )
1085 {
1086 return false;
1087 }
1088
1089 int color;
1090 int idx = 0;
1091 int c_x, c_y;
1092
1093 if( item_in_hands.GetInventory().GetCargo() )
1094 {
1095 c_x = item_in_hands.GetInventory().GetCargo().GetHeight();
1096 c_y = item_in_hands.GetInventory().GetCargo().GetWidth();
1097 }
1098
1099 if( c_x > x && c_y > y && item_in_hands.GetInventory().CanAddEntityInCargoEx( item, 0, x, y, item.GetInventory().GetFlipCargo() ) )
1100 {
1102 ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
1103 color = ColorManager.GREEN_COLOR;
1104 }
1105 else
1106 {
1107 color = ColorManager.RED_COLOR;
1109 }
1110
1111 if( w.FindAnyWidget("Selected") )
1112 {
1113 w.FindAnyWidget("Selected").SetColor( color );
1114 }
1115 else
1116 {
1117 string name = w.GetName();
1118 name.Replace( "PanelWidget", "Selected" );
1119 w.FindAnyWidget( name ).SetColor( color );
1120 }
1121
1122 return true;
1123 }
1124
1125 void TakeAsAttachment( Widget w, Widget receiver )
1126 {
1127 EntityAI receiver_item;
1128 EntityAI slot_owner;
1129 int slot_id = -1;
1130
1131 SlotsIcon slots_icon;
1132 receiver.GetUserData(slots_icon);
1133 if( slots_icon )
1134 {
1135 receiver_item = slots_icon.GetEntity();
1136 slot_id = slots_icon.GetSlotID();
1137 slot_owner = slots_icon.GetSlotParent();
1138 }
1139
1140 EntityAI item = GetItemPreviewItem( w );
1141 if( !item )
1142 {
1143 return;
1144 }
1145
1146 ItemBase item_base = ItemBase.Cast( item );
1147 float stack_max = item_base.GetTargetQuantityMax(slot_id);
1148
1149 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
1150 if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
1151 return;
1152
1153 EntityAI target_att_entity = m_Entity;
1154 Weapon_Base wpn;
1155 Magazine mag;
1156 if( Class.CastTo(wpn, m_Entity ) && Class.CastTo(mag, item ) )
1157 {
1158 if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
1159 {
1160 player.GetWeaponManager().AttachMagazine( mag );
1161 }
1162 else if(player.GetWeaponManager().CanSwapMagazine( wpn, mag ))
1163 {
1164 player.GetWeaponManager().SwapMagazine( mag );
1165 }
1166 }
1167 else if( receiver_item )
1168 {
1169 if( receiver_item != item )
1170 {
1171 if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
1172 {
1173 ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
1174 }
1175 else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
1176 {
1177 if( !receiver_item.GetInventory().CanRemoveEntity() )
1178 return;
1179 GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
1180 }
1181 }
1182 }
1183 else if( slot_owner && slot_owner.GetInventory().CanAddAttachmentEx( item, slot_id ) )
1184 {
1185 if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1186 {
1187 player.PredictiveTakeEntityToTargetAttachmentEx(slot_owner, item, slot_id);
1188 }
1189 else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1190 {
1191 item_base.SplitIntoStackMaxClient( m_Entity, slot_id );
1192 }
1193 }
1194 else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( item ) )
1195 {
1196 if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1197 {
1198 player.PredictiveTakeEntityToTargetAttachment(slot_owner, item);
1199 }
1200 else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1201 {
1202 item_base.SplitIntoStackMaxClient( m_Entity, -1 );
1203 }
1204 }
1205 else if( m_Entity.GetInventory().CanAddAttachment( item ) )
1206 {
1207 if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1208 {
1209 player.PredictiveTakeEntityToTargetAttachment(m_Entity, item);
1210 }
1211 else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1212 {
1213 item_base.SplitIntoStackMaxClient( m_Entity, -1 );
1214 }
1215 }
1216 else if( ( m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && ( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item )) ) || player.GetHumanInventory().HasEntityInHands( item ) )
1217 {
1219 }
1220 /*else if( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item ) )
1221 {
1222 SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
1223 }*/
1224
1227 }
1228
1229 void ShowAtt( EntityAI entity )
1230 {
1233 m_Entity = entity;
1234 m_ActiveIndex = 0;
1235 if( entity.GetSlotsCountCorrect() > 0 )
1236 {
1237 m_Atts = new Attachments( this, entity );
1241 m_Entity.GetOnItemAttached().Insert( AttachmentAdded );
1242 m_Entity.GetOnItemDetached().Insert( AttachmentRemoved );
1243 }
1244 else
1245 {
1246 m_StaticAttCount = 0;
1247 }
1248
1249 if( entity.GetInventory().GetCargo() )
1250 {
1251 m_CargoGrid = new CargoContainer( this, false );
1252 m_CargoGrid.SetEntity( entity );
1253 m_CargoGrid.GetRootWidget().SetSort( 1 );
1256 }
1257
1259 {
1260 foreach( int slot_id : m_AttachmentSlotsSorted )
1261 {
1262 EntityAI item = m_Entity.GetInventory().FindAttachment( slot_id );
1263 if( item )
1265 }
1266 }
1267
1268 if (m_CargoGrid)
1269 {
1270 bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1271 if (m_CargoGrid.IsVisible() && hideCargo)
1272 {
1273 HideCargo();
1274 }
1275 else if (!m_CargoGrid.IsVisible() && !hideCargo)
1276 {
1277 ShowCargo();
1278 }
1279 }
1280
1282 RecomputeOpenedContainers();
1283 Refresh();
1284 m_Parent.Refresh();
1285 }
1286
1288 {
1289 for (int i = 0; i < m_Body.Count(); i++)
1290 {
1291 m_Body.Get( i ).OnShow();
1292 }
1293 Refresh();
1294 m_Parent.Refresh();
1295 }
1296
1297 void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
1298 {
1299 int slot_id = InventorySlots.GetSlotIdFromString( slot );
1300 int sort = -1;
1301 Attachments att_cont = null;
1302 CargoContainer cont = null;
1303
1304 if( item.GetInventory().GetAttachmentSlotsCount() > 0 )
1305 {
1306 att_cont = new Attachments( this, item );
1307 sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_ATTACHMENTS_NEXT_OFFSET;
1308 att_cont.InitAttachmentGrid( sort );
1309
1310 m_AttachmentAttachments.Insert( item, att_cont );
1311 m_AttachmentAttachmentsContainers.Insert( item, att_cont.GetWrapper() );
1312
1313 att_cont.UpdateInterval();
1314 if( m_Parent )
1315 m_Parent.Refresh();
1316 Inventory.GetInstance().UpdateConsoleToolbar();
1317 }
1318
1319 if( item.GetInventory().GetCargo() )
1320 {
1321 cont = new CargoContainer( this, true );
1322 sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_CARGO_NEXT_OFFSET; //m_AttachmentSlotsSorted.Find( slot_id ) + 50
1323 cont.GetRootWidget().SetSort( sort );
1324 cont.SetEntity( item );
1325
1326 Insert(cont, -1);
1327
1328 m_AttachmentCargos.Insert( item, cont );
1329 if( m_Parent )
1330 m_Parent.Refresh();
1331 Inventory.GetInstance().UpdateConsoleToolbar();
1332 }
1333
1334 if (att_cont)
1335 {
1336 att_cont.ShowFalseAttachmentsHeader(true);
1337 if (cont)
1338 {
1339 cont.ShowFalseCargoHeader(false);
1340 cont.UpdateSize();
1341 cont.SetAlternateFalseTextHeaderWidget(att_cont.GetFalseHeaderTextWidget());
1342 }
1343 }
1344 else if (cont)
1345 {
1346 cont.SetAlternateFalseTextHeaderWidget(null); //just to be safe..
1347 }
1348
1349 RecomputeOpenedContainers();
1350 }
1351
1352 void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
1353 {
1354 int slot_id = InventorySlots.GetSlotIdFromString( slot );
1355
1356 CargoContainer old_cont = m_AttachmentCargos.Get( item );
1357 if( old_cont )
1358 {
1359 m_Body.RemoveItem( old_cont );
1360 m_AttachmentCargos.Remove( item );
1361 delete old_cont;
1362 if( m_Parent )
1363 m_Parent.Refresh();
1364 Inventory.GetInstance().UpdateConsoleToolbar();
1365 }
1366
1367 AttachmentsWrapper old_att_cont = m_AttachmentAttachmentsContainers.Get( item );
1368 if( old_att_cont )
1369 {
1370 m_AttachmentAttachmentsContainers.Remove( item );
1371 m_AttachmentAttachments.Remove( item );
1372 m_Body.RemoveItem( old_att_cont );
1373 delete old_att_cont;
1374 if( m_Parent )
1375 m_Parent.Refresh();
1376 Inventory.GetInstance().UpdateConsoleToolbar();
1377 }
1378 RecomputeOpenedContainers();
1379 }
1380
1381 override void UpdateInterval()
1382 {
1383 super.UpdateInterval();
1384
1385 if ( m_Entity )
1386 {
1387 if (m_CargoGrid)
1388 {
1389 bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1390 if (m_CargoGrid.IsVisible() && hideCargo)
1391 {
1392 HideCargo();
1393 }
1394 else if (!m_CargoGrid.IsVisible() && !hideCargo)
1395 {
1396 ShowCargo();
1397 }
1398
1399 m_CargoGrid.UpdateInterval();
1400 }
1401
1402 if ( m_Atts )
1403 {
1405 }
1406
1407 for ( int i = 0; i < m_AttachmentCargos.Count(); i++ )
1408 {
1409 m_AttachmentCargos.GetElement( i ).UpdateInterval();
1410 }
1411 }
1412
1415 }
1416
1417 override void SetLayoutName()
1418 {
1419 m_LayoutName = WidgetLayoutName.ClosableContainer;
1420 }
1421
1422 override void OnShow()
1423 {
1424 super.OnShow();
1425
1426 for ( int i = 0; i < m_Body.Count(); i++ )
1427 {
1428 m_Body.Get( i ).OnShow();
1429 }
1430 }
1431
1432 void DoubleClick(Widget w, int x, int y, int button)
1433 {
1434 if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
1435 {
1436 if( w == null )
1437 {
1438 return;
1439 }
1440 ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
1441 if( !iw )
1442 {
1443 string name = w.GetName();
1444 name.Replace( "PanelWidget", "Render" );
1445 iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
1446 }
1447 if( !iw )
1448 {
1449 iw = ItemPreviewWidget.Cast( w );
1450 }
1451 if( !iw.GetItem() )
1452 {
1453 return;
1454 }
1455
1456 ItemBase item = ItemBase.Cast( iw.GetItem() );
1457
1458 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
1459 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
1460 Weapon_Base wpn;
1461 Magazine mag;
1462 if( Class.CastTo(wpn, item_in_hands ) )
1463 {
1464 return;
1465 }
1466
1467 if( !item.GetInventory().CanRemoveEntity() )
1468 return;
1469
1470 if( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
1471 {
1472 player.PredictiveTakeEntityToHands( item );
1473 }
1474 else
1475 {
1476 if( player.GetInventory().CanAddEntityToInventory( item ) && player.GetHumanInventory().CanRemoveEntityInHands() )
1477 {
1478 player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ANY, item );
1479 }
1480 else
1481 {
1482 if( player.GetHumanInventory().CanAddEntityInHands( item ) )
1483 {
1484 player.PredictiveTakeEntityToHands( item );
1485 }
1486 }
1487 }
1488
1489 HideOwnedTooltip();
1490
1491 name = w.GetName();
1492 name.Replace( "PanelWidget", "Temperature" );
1493 w.FindAnyWidget( name ).Show( false );
1494 }
1495 }
1496
1498 {
1499 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
1500 if( item_in_hands && item_in_hands.GetCompEM() )
1501 {
1502 if( GetRootWidget().FindAnyWidget( "electricity" ) )
1503 {
1504 bool show_electricity_icon = item_in_hands.GetCompEM().HasElectricityIcon();
1505 GetRootWidget().FindAnyWidget( "electricity" ).Show( show_electricity_icon );
1506 }
1507
1508 if( GetRootWidget().FindAnyWidget( "electricity_can_work" ) )
1509 {
1510 bool show_electricity_can_work_icon = item_in_hands.GetCompEM().CanWork() && !item_in_hands.IsRuined();
1511 GetRootWidget().FindAnyWidget( "electricity_can_work" ).Show( show_electricity_can_work_icon );
1512 }
1513 }
1514 else
1515 {
1516 GetRootWidget().FindAnyWidget( "electricity" ).Show( false );
1517 }
1518 }
1519
1521 {
1522 int i;
1523 if( !m_Hidden )
1524 {
1525 for (i = 0; i < m_Body.Count(); i++)
1526 {
1527 m_Body.Get( i ).OnHide();
1528 }
1529 m_Hidden = true;
1530 }
1531 else
1532 {
1533 for (i = 0; i < m_Body.Count(); i++)
1534 {
1535 m_Body.Get( i ).OnShow();
1536 }
1537 m_Hidden = false;
1538 }
1539
1540 w.FindAnyWidget("opened").Show(m_Hidden);
1541 w.FindAnyWidget("closed").Show(!m_Hidden);
1542
1543 m_Parent.Refresh();
1544 }
1545
1547 {
1548 if( m_CargoGrid )
1549 {
1550 m_CargoGrid.OnHide();
1551 RecomputeOpenedContainers();
1552 }
1553 }
1554
1556 {
1557 if( m_CargoGrid )
1558 {
1559 m_CargoGrid.OnShow();
1560 RecomputeOpenedContainers();
1561 }
1562 }
1563}
void Inventory(LayoutHolder parent)
Definition Inventory.c:75
DayZGame g_Game
Definition DayZGame.c:3654
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
override ContextMenu GetContextMenu()
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition ItemBase.c:5444
bool m_IsActive
PlayerBase GetPlayer()
string name
class PluginItemDiagnosticEventHandler extends ScriptedWidgetEventHandler m_Entity
PluginBase GetPlugin(typename plugin_type)
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
DayZPlayer m_player
protected Widget m_Parent
Definition SizeToChild.c:92
void SetActive()
Definition TrapBase.c:463
bool CanSetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
AttachmentsWrapper GetWrapper()
Definition Attachments.c:43
void SetDefaultFocus(bool while_micromanagment_mode=false)
Definition Attachments.c:78
void UpdateInterval()
TextWidget GetFalseHeaderTextWidget()
void UnfocusAll()
Definition Attachments.c:73
void InitAttachmentGrid(int att_row_index)
void ShowFalseAttachmentsHeader(bool show)
int GetAttachmentHeight()
array< int > GetSlotsSorted()
proto native DayZPlayer GetPlayer()
represents base for cargo storage for entities
Definition Cargo.c:7
proto native int GetHeight()
proto native int GetItemCount()
proto native int GetWidth()
Super root of all classes in Enforce script.
Definition EnScript.c:11
static int GREEN_COLOR
static ColorManager GetInstance()
static int RED_COLOR
static int SWAP_COLOR
static int BASE_COLOR
static int COMBINE_COLOR
void SetColor(Widget w, int color)
void CargoContainer(LayoutHolder parent, bool is_attachment=false)
override float GetFocusedContainerYScreenPos(bool contents=false)
override float GetFocusedContainerHeight(bool contents=false)
override bool Select()
override EntityAI GetFocusedItem()
WeaponManager GetWeaponManager()
script counterpart to engine's class Inventory
Definition Inventory.c:77
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:601
override void UnfocusGrid()
protected ref map< EntityAI, AttachmentsWrapper > m_AttachmentAttachmentsContainers
override void UnfocusAll()
void ScrollToActiveContainer(Container active_container)
protected ref map< EntityAI, ref Attachments > m_AttachmentAttachments
void HandsContainer(LayoutHolder parent)
protected int m_StaticAttCount
protected int m_StaticCargoCount
override bool IsItemActive()
void TakeAsAttachment(Widget w, Widget receiver)
override bool InspectItem()
protected ScrollWidget m_ScrollWidget
void DropReceived(Widget w, int x, int y, CargoContainer cargo)
override void Refresh()
void ShowActionMenuCombine(EntityAI entity1, EntityAI entity2, int combinationFlags)
override void UpdateInterval()
override void OnShow()
override bool TransferItem()
void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
protected ref map< EntityAI, ref CargoContainer > m_AttachmentCargos
override bool TransferItemToVicinity()
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
EntityAI GetItemPreviewItem(Widget w)
protected ref HandsHeader m_CollapsibleHeader
protected ref Attachments m_Atts
override void SetActive(bool active)
protected ref HandsPreview m_HandsPreview
void DoubleClick(Widget w, int x, int y, int button)
override bool IsLastIndex()
override Header GetHeader()
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
override bool EquipItem()
void MouseClick2(Widget w, int x, int y, int button)
protected ref CargoContainer m_CargoGrid
override bool IsItemWithQuantityActive()
void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
protected ref array< int > m_AttachmentSlotsSorted
bool DraggingOverGrid(Widget w, int x, int y, Widget reciever, CargoContainer cargo)
int GetCombinationFlags(EntityAI entity1, EntityAI entity2)
void OnPerformCombination(int combinationFlags)
override void Insert(LayoutHolder container, int pos=-1, bool immedUpdate=true)
override void SetLastActive()
void DraggingOverHeader2(Widget w, int x, int y, Widget receiver)
override bool IsEmpty()
override void SetLayoutName()
void OnDropReceivedFromHeader2(Widget w, int x, int y, Widget receiver)
override bool OnSelectButton()
void ShowAtt(EntityAI entity)
protected bool m_Hidden
override bool SplitItem()
void CollapseButtonOnMouseButtonDown(Widget w)
int GetRecipeCount(bool recipe_anywhere, EntityAI entity1, EntityAI entity2)
override void UpdateInterval()
Definition HandsHeader.c:23
void ShowCollapseButtons(bool show, bool force=false)
Definition HandsHeader.c:45
void CreateNewIcon(ItemBase item)
Definition Header.c:2
Definition Icon.c:2
override void Refresh()
Definition Icon.c:1370
InventoryLocation.
proto native bool IsValid()
verify current set inventory location
proto native void SetCargoAuto(notnull CargoBase cargo, EntityAI e, int row, int col, bool flip)
based on Cargo.IsProxyCargo uses SetProxyCargo or SetCargo respectively
proto native bool CompareLocationOnly(notnull InventoryLocation other)
proto native bool GetFlip()
returns flip status of cargo
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static proto native owned string GetSlotName(int id)
converts slot_id to string
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Definition Rag.c:52
Widget GetCenterDropzone()
EntityAI GetSelectedItem()
Definition ItemManager.c:82
bool IsMicromanagmentMode()
Definition ItemManager.c:67
void ShowSourceDropzone(EntityAI item)
Widget GetLeftDropzone()
void HideDropzones()
void SetHandsPreview(HandsPreview hansd_preview)
Definition ItemManager.c:77
Widget GetRightDropzone()
void SetIsDragging(bool is_dragging)
static ItemManager GetInstance()
proto native EntityAI GetItem()
static int HasItemQuantity(notnull EntityAI item)
EntityAI GetEntity()
Definition SlotsIcon.c:353
EntityAI GetSlotParent()
Definition SlotsIcon.c:185
int GetSlotID()
Definition SlotsIcon.c:190
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
bool CanAttachMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
bool AttachMagazine(Magazine mag, ActionBase control_action=NULL)
bool CanSwapMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
bool LoadBullet(Magazine mag, ActionBase control_action=NULL)
bool SwapMagazine(Magazine mag, ActionBase control_action=NULL)
const string ClosableContainer
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:345
MouseState
Definition EnSystem.c:311
proto void GetMousePos(out int x, out int y)
proto int Replace(string sample, string replace)
Replace all occurrances of 'sample' in 'str' by 'replace'.
WidgetFlags
Definition EnWidgets.c:57
proto native Widget FindAnyWidget(string pathname)