DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
HandsContainer.c
См. документацию.
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("Cursor") )
105 m_MainWidget.FindAnyWidget("Cursor").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 {
117 m_Atts.SetDefaultFocus();
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("Cursor") )
155 m_MainWidget.FindAnyWidget("Cursor").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 override bool TransferItem()
188 {
189 if (m_ActiveIndex == 0)
190 {
191 if (CanTakeToInventory())
192 {
193 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
194 if (item_in_hands && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null))
195 {
196 if (GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item_in_hands ))
197 {
198 m_MainWidget.FindAnyWidget("Cursor").Show( false );
199 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
200 return true;
201 }
202 }
203 }
204 }
205 else if (GetFocusedContainer())
206 {
207 return GetFocusedContainer().TransferItem();
208 }
209 return false;
210 }
211
212 override bool SplitItem()
213 {
214 if (CanSplit())
215 {
216 if (m_ActiveIndex == 0)
217 {
218 ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
219 if ( item_in_hands )
220 {
221 if ( item_in_hands.CanBeSplit() )
222 {
223 item_in_hands.OnRightClick();
224 }
225 }
226 }
227 else if( GetFocusedContainer() )
228 {
229 return GetFocusedContainer().SplitItem();
230 }
231 }
232 return false;
233 }
234
235 override bool EquipItem()
236 {
237 if (CanEquip())
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 ( GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null) )
245 {
246 bool res = GetGame().GetPlayer().PredictiveTakeOrSwapAttachment( item_in_hands );
247 if(!res)
248 {
249 res = GetGame().GetPlayer().PredictiveTakeEntityToInventory(FindInventoryLocationType.ATTACHMENT, item_in_hands);
250 }
251 if(res)
252 {
253 m_MainWidget.FindAnyWidget("Cursor").Show( false );
254 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
255 return true;
256 }
257 }
258 }
259 }
260 else if (GetFocusedContainer())
261 {
262 return GetFocusedContainer().EquipItem();
263 }
264 }
265 return false;
266 }
267
268 override void SetActive( bool active )
269 {
270 super.SetActive(active);
271 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
272 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
273
274 if( item_in_hands )
275 {
276 if( m_MainWidget.FindAnyWidget( "Cursor" ) )
277 {
278 m_MainWidget.FindAnyWidget( "Cursor" ).Show( active );
279 }
280
281 if( active )
282 {
283 float x, y;
284 GetMainWidget().GetScreenPos( x, y );
285 PrepareOwnedTooltip( item_in_hands, -1, y );
286 }
287 }
288 else
289 {
290 if (active)
291 m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
292 else
293 m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.7 );
294 }
295 }
296
297 override void SetLastActive()
298 {
299 super.SetLastActive();
300 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
301 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
302
303 if( item_in_hands )
304 {
305 if ( m_ActiveIndex == 0)
306 {
307 if( m_MainWidget.FindAnyWidget( "Cursor" ) )
308 {
309 m_MainWidget.FindAnyWidget( "Cursor" ).Show( true );
310 }
311
312 float x, y;
313 GetMainWidget().GetScreenPos( x, y );
314 PrepareOwnedTooltip( item_in_hands, x, y );
315 }
316 }
317 else
318 {
319 m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
320 }
321 }
322
323 override void Refresh()
324 {
325 super.Refresh();
327 }
328
329 override bool IsItemActive()
330 {
331 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
332 ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
333 if( item == null )
334 {
335 return false;
336 }
337 return !IsEmpty() && ( !QuantityConversions.HasItemQuantity( item ) || ( QuantityConversions.HasItemQuantity( item ) && !item.CanBeSplit() ) );
338 }
339
341 {
342 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
343 ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
344 if( item == null )
345 {
346 return false;
347 }
348 return !IsEmpty() && QuantityConversions.HasItemQuantity( item ) && item.CanBeSplit();
349 }
350
351 override bool IsEmpty()
352 {
353 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
354 return player.GetHumanInventory().GetEntityInHands() == null;
355 }
356
358 {
359 if (CanDrop())
360 {
361 if (m_ActiveIndex == 0)
362 {
363 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
364 ItemBase item_in_hands = ItemBase.Cast(player.GetHumanInventory().GetEntityInHands());
365 if ( item_in_hands && player.CanDropEntity( item_in_hands ) && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !player.GetInventory().HasInventoryReservation(item_in_hands, null) )
366 {
367 if ( item_in_hands.GetTargetQuantityMax() < item_in_hands.GetQuantity() )
368 item_in_hands.SplitIntoStackMaxClient( null, -1 );
369 else
370 player.PhysicalPredictiveDropItem( item_in_hands );
371 m_MainWidget.FindAnyWidget("Cursor").Show( false );
372 m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
373 return true;
374 }
375 }
376 else if ( GetFocusedContainer() )
377 {
378 return GetFocusedContainer().TransferItemToVicinity();
379 }
380 }
381 return false;
382 }
383
384 override bool InspectItem()
385 {
386 if(m_ActiveIndex == 0)
387 {
388 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
389 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
390 if( item_in_hands )
391 {
392 InspectItem( item_in_hands );
393 return true;
394 }
395 }
396 else if( GetFocusedContainer() )
397 {
398 return GetFocusedContainer().InspectItem();
399 }
400 return false;
401 }
402
403 override bool OnSelectButton()
404 {
405 if(m_ActiveIndex == 0)
406 {
408 {
410 if( selectedItem == GetFocusedItem() )
411 {
412 Inventory.GetInstance().DisableMicromanagement();
413 return true;
414 }
415 else
416 {
417 return Select();
418 }
419 }
420 else
421 {
422 Inventory.GetInstance().EnableMicromanagement();
423 return true;
424 }
425 }
426 else
427 {
428 if( GetFocusedContainer() )
429 {
430 return GetFocusedContainer().OnSelectButton();
431 }
432 }
433 return false;
434 }
435
437 {
438 ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
439 if( !ipw )
440 {
441 string name = w.GetName();
442 name.Replace( "PanelWidget", "Render" );
443 ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
444 }
445
446 if( !ipw )
447 {
448 ipw = ItemPreviewWidget.Cast( w );
449 }
450
451 if( !ipw )
452 {
453 return null;
454 }
455
456 return ipw.GetItem();
457 }
458
459 override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
460 {
461 if( w == null )
462 {
463 return;
464 }
465 EntityAI receiver_item;
466 EntityAI slot_owner;
467 int slot_id = -1;
468
469 string name = w.GetName();
470 name.Replace( "PanelWidget", "Render" );
471
472 ItemPreviewWidget w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
473 if( w_ipw == null )
474 {
475 w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
476 }
477 if( w_ipw == null )
478 {
479 return;
480 }
481
482 SlotsIcon slots_icon;
483 receiver.GetUserData(slots_icon);
484
485 if(slots_icon)
486 {
487 receiver_item = slots_icon.GetEntity();
488 slot_id = slots_icon.GetSlotID();
489 slot_owner = slots_icon.GetSlotParent();
490 }
491
492
493 PlayerBase p = PlayerBase.Cast( GetGame().GetPlayer() );
494 InventoryItem receiver_entity = InventoryItem.Cast( p.GetHumanInventory().GetEntityInHands() );
495 InventoryItem w_entity = InventoryItem.Cast( w_ipw.GetItem() );
496 if( !w_entity )
497 {
498 return;
499 }
500
501 if( receiver_entity )
502 {
503 if( receiver_item )
504 {
505 ItemBase receiver_itemIB = ItemBase.Cast( receiver_item );
506 ItemBase itemIB = ItemBase.Cast( receiver_item );
507 if( receiver_itemIB && itemIB && receiver_itemIB.CanBeCombined( itemIB ) )
508 {
510 if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
511 {
512 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
513 }
514 else
515 {
516 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
517 }
519 }
520 else
521 {
522 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
523 Magazine mag = Magazine.Cast(receiver_item);
524 Weapon_Base wpn = Weapon_Base.Cast(receiver_item.GetHierarchyParent());
525
526 if( wpn && mag )
527 {
528 if( player.GetWeaponManager().CanSwapMagazine( wpn, Magazine.Cast(w_entity) ) )
529 {
531 if( w_entity.GetHierarchyRootPlayer() == player )
532 {
533 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
534 }
535 else
536 {
537 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
538 }
539 }
540 else
541 {
544 }
545 }
546 else
547 {
548 if( GameInventory.CanSwapEntitiesEx( receiver_item, w_entity ) )
549 {
551 if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
552 {
553 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
554 }
555 else
556 {
557 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
558 }
560 }
561 else if( receiver_itemIB.GetInventory().CanAddAttachment( w_entity ) )
562 {
564 if( receiver_itemIB.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
565 {
566 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
567 }
568 else
569 {
570 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
571 }
573 }
574 }
575 }
576 }
577 else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( w_entity ) )
578 {
580 ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
582 }
583 else if( receiver_entity.GetInventory().CanAddAttachment( w_entity ) )
584 {
586 if( receiver_entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
587 {
588 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
589 }
590 else
591 {
592 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
593 }
595 }
596 else
597 {
600 }
601 }
602 else
603 {
604 /*if( m_HandsIcon )
605 {
606 ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
607 ItemManager.GetInstance().HideDropzones();
608 ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
609 }
610
611 else
612 {*/
615 //}
616 }
617 }
618
619 void OnDropReceivedFromHeader2( Widget w, int x, int y, Widget receiver )
620 {
621 TakeAsAttachment( w, receiver );
622 }
623
624 void OnPerformCombination(int combinationFlags)
625 {
627 if ( m_am_entity1 == null || m_am_entity2 == null ) return;
628
629 if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
630
631 if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
632 {
633 Magazine mag;
634 if ( Class.CastTo(mag, m_am_entity2 ) )
635 {
636 m_player.GetWeaponManager().LoadBullet( mag );
637 return;
638 }
639 }
640
641 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
642 {
643 if( m_Atts )
644 {
645 m_Body.RemoveItem( m_Atts.GetWrapper() );
646 delete m_Atts;
647 }
648 if( m_am_entity2.GetSlotsCountCorrect() > 0 )
649 {
650 m_Atts = new Attachments( this, m_am_entity2 );
651 m_Atts.InitAttachmentGrid( 1 );
652
653 }
654
655 Refresh();
656 m_Parent.Refresh();
657
658 Weapon_Base wpn1;
659 Magazine mag1;
660 if ( Class.CastTo(wpn1, m_am_entity1 ) && Class.CastTo(mag1, m_am_entity2 ) )
661 {
662 if( m_player.GetWeaponManager().CanAttachMagazine(wpn1, mag1) )
663 {
664 m_player.GetWeaponManager().AttachMagazine(mag1);
665 return;
666 }
667 }
668
669 SplitItemUtils.TakeOrSplitToInventory(m_player, m_am_entity1, m_am_entity2);
670 //m_player.PredictiveTakeEntityToTargetAttachment( m_am_entity1, m_am_entity2 );
671 }
672
673 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
674 {
675 m_player.PredictiveTakeEntityToTargetCargo( m_am_entity1, m_am_entity2 );
676 }
677
678 if ( combinationFlags & InventoryCombinationFlags.SWAP )
679 {
680 Magazine swapmag1;
681 Magazine swapmag2;
682 if (Class.CastTo(swapmag1, m_am_entity1) && Class.CastTo(swapmag2, m_am_entity2 ) )
683 {
684 if( m_player.GetWeaponManager().CanSwapMagazine( Weapon_Base.Cast( swapmag1.GetParent() ), Magazine.Cast( swapmag2 ) ) )
685 {
686 m_player.GetWeaponManager().SwapMagazine(swapmag2);
687 return;
688 }
689
690 if( m_player.GetWeaponManager().CanSwapMagazine(Weapon_Base.Cast( swapmag2.GetParent() ), Magazine.Cast( swapmag1 )) )
691 {
692 m_player.GetWeaponManager().SwapMagazine(swapmag1);
693 return;
694 }
695 }
696 if ( !m_player.PredictiveSwapEntities( m_am_entity1, m_am_entity2 ) && m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity1 ) )
697 {
698 m_player.PredictiveTakeEntityToHands( m_am_entity1 );
699 }
700 }
701
702 if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
703 {
704 if ( m_Atts )
705 {
706 m_Body.RemoveItem( m_Atts.GetWrapper() );
707 delete m_Atts;
708 }
709
710 if ( m_am_entity2.GetSlotsCountCorrect() > 0 )
711 {
712 m_Atts = new Attachments( this, m_am_entity2 );
713 m_Atts.InitAttachmentGrid( 1 );
714
715 }
716 Refresh();
717 m_Parent.Refresh();
718
719 if ( m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity2 ) )
720 {
721 m_player.PredictiveTakeEntityToHands( m_am_entity2 );
722 }
723 }
724 }
725
726 void ShowActionMenuCombine( EntityAI entity1, EntityAI entity2, int combinationFlags )
727 {
728 if ( entity1 && entity2 ) PrintString( "Showing action menu for " + entity1.GetDisplayName() + " and " + entity2.GetDisplayName() );
729
730 ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());
731 m_am_entity1 = entity1;
732 m_am_entity2 = entity2;
733 cmenu.Hide();
734 cmenu.Clear();
735
736 if( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
737 {
738 ItemBase entity = ItemBase.Cast( entity1 );
739 entity.CombineItemsClient( ItemBase.Cast( entity2 ) );
740 return;
741 }
742
743 if ( entity1 == null || entity2 == null ) return;
744
745 if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
746
747 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
748 {
749 cmenu.Add( "#inv_context_add_as_attachment", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_ATTACHMENT ) );
750 }
751 if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
752 {
753 cmenu.Add( "#inv_context_load_chamber", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.LOAD_CHAMBER ) );
754 }
755
756 if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
757 {
758 cmenu.Add( "#inv_context_add_as_cargo", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_CARGO ) );
759 }
760
761 if ( combinationFlags & InventoryCombinationFlags.SWAP )
762 {
763 cmenu.Add( "#inv_context_swap", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.SWAP ) );
764 }
765
766 if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
767 {
768 cmenu.Add( "#inv_context_take_to_hands", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.TAKE_TO_HANDS ) );
769 }
770
771 if ( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
772 {
773 cmenu.Add( "#inv_context_combine", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.COMBINE_QUANTITY2 ) );
774 }
775
776 int m_am_pos_x, m_am_pos_y;
777 GetMousePos( m_am_pos_x, m_am_pos_y );
778 m_am_pos_x -= 5;
779 m_am_pos_y -= 5;
780
781 cmenu.Show( m_am_pos_x, m_am_pos_y );
782 }
783
784
785 override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
786 {
787 TakeAsAttachment( w, receiver );
788 }
789
790 int GetCombinationFlags( EntityAI entity1, EntityAI entity2 )
791 {
792 int flags = 0;
794 EntityAI entity_in_hands = m_player.GetHumanInventory().GetEntityInHands();
795
796 if (!entity1 || !entity2) return flags;
797
798 Magazine swapmag1;
799 Magazine swapmag2;
800 bool skipSwap = false;
801
802 if (Class.CastTo(swapmag1, entity1) && Class.CastTo(swapmag2, entity2))
803 {
804 Weapon_Base parentWpn;
805
806 if (Class.CastTo(parentWpn, swapmag1.GetHierarchyParent()))
807 {
808 skipSwap = true;
809 if (m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag2))
810 flags = flags | InventoryCombinationFlags.SWAP;
811 }
812
813 if (Class.CastTo(parentWpn, swapmag2.GetHierarchyParent()))
814 {
815 skipSwap = true;
816 if (m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag1))
817 flags = flags | InventoryCombinationFlags.SWAP;
818
819 }
820 }
821
822 if ( !skipSwap )
823 {
824 if (entity1 == m_player.GetHumanInventory().GetEntityInHands() ) flags = flags | InventoryCombinationFlags.TAKE_TO_HANDS;
825 else if (GameInventory.CanSwapEntitiesEx( entity1, entity2 ))
826 {
827 if (!entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ))
828 {
829 flags = flags | InventoryCombinationFlags.SWAP;
830 }
831 }
832 }
833
834 if (entity1.IsInherited( ItemBase) && entity2.IsInherited( ItemBase ))
835 {
836 ItemBase ent1 = ItemBase.Cast( entity1 );
837 if (ent1.CanBeCombined( ItemBase.Cast( entity2 ) )) flags = flags | InventoryCombinationFlags.COMBINE_QUANTITY2;
838 }
839
840 else if (entity1.GetInventory().CanAddAttachment( entity2 ))
841 {
842 if (!entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ) && !entity2.IsInherited( ZombieBase ) && !entity2.IsInherited( Car ))
843 {
845 }
846 }
847 if (!entity1.GetInventory().HasEntityInInventory(entity2) && entity1.GetInventory().CanAddEntityInCargo( entity2, entity2.GetInventory().GetFlipCargo() )) flags = flags | InventoryCombinationFlags.ADD_AS_CARGO;
848
849 if (entity1 == m_player.GetHumanInventory().GetEntityInHands() || entity2 == m_player.GetHumanInventory().GetEntityInHands())
850 {
852 Class.CastTo(amc, m_player.GetActionManager());
853 if (entity1 == m_player.GetHumanInventory().GetEntityInHands())
854 {
855 if (amc.CanSetActionFromInventory( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ) ))
856 {
858 }
859 }
860 else
861 {
862 if (amc.CanSetActionFromInventory( ItemBase.Cast( entity2 ), ItemBase.Cast( entity1 ) ))
863 {
865 }
866 }
867 }
868
869 if (GetRecipeCount( true, entity1, entity2 ) > 0)
870 {
872 }
873 return flags;
874 }
875
876 int GetRecipeCount( bool recipe_anywhere, EntityAI entity1, EntityAI entity2 )
877 {
878 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
879 return plugin_recipes_manager.GetValidRecipes( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ), null, PlayerBase.Cast( GetGame().GetPlayer() ) );
880 }
881
883 {
884 m_Entity = null;
885 m_CollapsibleHeader.ShowCollapseButtons( false, true );
886 }
887
889 {
890 if( m_Atts )
891 {
892 m_Body.RemoveItem( m_Atts.GetWrapper() );
893 delete m_Atts;
894
895 if( m_Entity )
896 {
897 m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
898 m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
899 }
900 }
901
903 {
905 {
906 m_Body.RemoveItem( att );
907 m_AttachmentAttachments.Remove( ent );
908 delete att;
909 }
910 }
911
913 Refresh();
914 m_Parent.Refresh();
915 RecomputeOpenedContainers();
916 }
917
918 override void UnfocusGrid()
919 {
920 if( m_Atts )
921 {
922 m_Atts.UnfocusAll();
923 }
924
925 if( m_CargoGrid )
926 {
927 m_CargoGrid.UnfocusAll();
928 }
929
931 {
932 foreach( EntityAI e1, CargoContainer cargo : m_AttachmentCargos )
933 {
934 cargo.UnfocusAll();
935
936 }
937 }
938
940 {
941 foreach( EntityAI e2, Attachments att : m_AttachmentAttachments )
942 {
943 att.UnfocusAll();
944 }
945 }
946 }
947
948 override void UnfocusAll()
949 {
950 UnfocusGrid();
951 }
952
954 {
955 if( m_CargoGrid )
956 {
957 m_Body.RemoveItem( m_CargoGrid );
958 delete m_CargoGrid;
959 }
960
962 {
963 foreach( CargoContainer cargo : m_AttachmentCargos )
964 {
965 m_Body.RemoveItem( cargo );
966 delete cargo;
967 }
968 }
969
970 m_AttachmentCargos.Clear();
971 Refresh();
972 m_Parent.Refresh();
973 RecomputeOpenedContainers();
974 }
975
976 void DropReceived( Widget w, int x, int y, CargoContainer cargo )
977 {
978 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
979 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
980
981 EntityAI item = GetItemPreviewItem( w );
982 if( !item )
983 {
984 return;
985 }
986
987 int idx = 0;
988 int c_x, c_y;
989
990 EntityAI target_entity;
991 CargoBase target_cargo;
992
993 if( cargo == m_CargoGrid )
994 {
995 target_entity = m_Entity;
996 target_cargo = m_Entity.GetInventory().GetCargo();
997 #ifdef PLATFORM_CONSOLE
998 if( m_CargoGrid.HasItem( item ) )
999 {
1000 return;
1001 }
1002 #endif
1003 }
1004 else
1005 {
1006 target_entity = m_AttachmentCargos.GetKeyByValue( cargo );
1007 if( target_entity )
1008 {
1009 target_cargo = target_entity.GetInventory().GetCargo();
1010 #ifdef PLATFORM_CONSOLE
1011 if( cargo.HasItem( item ) )
1012 {
1013 return;
1014 }
1015 #endif
1016 }
1017 else
1018 return;
1019 }
1020
1021 if( target_cargo && target_entity )
1022 {
1023 c_x = target_cargo.GetHeight();
1024 c_y = target_cargo.GetWidth();
1025 }
1026 else
1027 return;
1028
1030 #ifdef PLATFORM_CONSOLE
1031 x = 0;
1032 y = target_cargo.GetItemCount();
1033 target_entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.CARGO, dst );
1034 #else
1035 dst.SetCargoAuto(target_cargo, item, x, y, item.GetInventory().GetFlipCargo());
1036 #endif
1037
1039 item.GetInventory().GetCurrentInventoryLocation(src);
1040 if(src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
1041 return;
1042
1043 #ifdef PLATFORM_CONSOLE
1044 if(dst.IsValid() && target_entity.GetInventory().LocationCanAddEntity(dst))
1045 #else
1046 if( c_x > x && c_y > y && target_entity.GetInventory().LocationCanAddEntity(dst))
1047 #endif
1048 {
1050
1051 Icon icon = cargo.GetIcon( item );
1052
1053 if( icon )
1054 {
1055 if( w && w.FindAnyWidget("Cursor") )
1056 w.FindAnyWidget("Cursor").SetColor( ColorManager.BASE_COLOR );
1057 icon.Refresh();
1058 Refresh();
1059 }
1060 }
1063 }
1064
1065 bool DraggingOverGrid( Widget w, int x, int y, Widget reciever, CargoContainer cargo )
1066 {
1067 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
1068 if( w == null )
1069 {
1070 return false;
1071 }
1072 EntityAI item = GetItemPreviewItem( w );
1073 if( !item || !item_in_hands )
1074 {
1075 return false;
1076 }
1077
1078 int color;
1079 int idx = 0;
1080 int c_x, c_y;
1081
1082 if( item_in_hands.GetInventory().GetCargo() )
1083 {
1084 c_x = item_in_hands.GetInventory().GetCargo().GetHeight();
1085 c_y = item_in_hands.GetInventory().GetCargo().GetWidth();
1086 }
1087
1088 if( c_x > x && c_y > y && item_in_hands.GetInventory().CanAddEntityInCargoEx( item, 0, x, y, item.GetInventory().GetFlipCargo() ) )
1089 {
1091 ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
1092 color = ColorManager.GREEN_COLOR;
1093 }
1094 else
1095 {
1096 color = ColorManager.RED_COLOR;
1098 }
1099
1100 if( w.FindAnyWidget("Cursor") )
1101 {
1102 w.FindAnyWidget("Cursor").SetColor( color );
1103 }
1104 else
1105 {
1106 string name = w.GetName();
1107 name.Replace( "PanelWidget", "Cursor" );
1108 w.FindAnyWidget( name ).SetColor( color );
1109 }
1110
1111 return true;
1112 }
1113
1114 void TakeAsAttachment( Widget w, Widget receiver )
1115 {
1116 EntityAI receiver_item;
1117 EntityAI slot_owner;
1118 int slot_id = -1;
1119
1120 SlotsIcon slots_icon;
1121 receiver.GetUserData(slots_icon);
1122 if( slots_icon )
1123 {
1124 receiver_item = slots_icon.GetEntity();
1125 slot_id = slots_icon.GetSlotID();
1126 slot_owner = slots_icon.GetSlotParent();
1127 }
1128
1129 EntityAI item = GetItemPreviewItem( w );
1130 if( !item )
1131 {
1132 return;
1133 }
1134
1135 ItemBase item_base = ItemBase.Cast( item );
1136 float stack_max = item_base.GetTargetQuantityMax(slot_id);
1137
1138 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
1139 if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
1140 return;
1141
1142 EntityAI target_att_entity = m_Entity;
1143 Weapon_Base wpn;
1144 Magazine mag;
1145 if( Class.CastTo(wpn, target_att_entity ) && Class.CastTo(mag, item ) )
1146 {
1147 if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
1148 {
1149 player.GetWeaponManager().AttachMagazine( mag );
1150 }
1151 else if(player.GetWeaponManager().CanSwapMagazine( wpn, mag ))
1152 {
1153 player.GetWeaponManager().SwapMagazine( mag );
1154 }
1155 }
1156 else if( receiver_item )
1157 {
1158 if( receiver_item != item )
1159 {
1160 if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
1161 {
1162 ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
1163 }
1164 else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
1165 {
1166 if( !receiver_item.GetInventory().CanRemoveEntity() )
1167 return;
1168 GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
1169 }
1170 }
1171 }
1172 else if( slot_owner && slot_owner.GetInventory().CanAddAttachmentEx( item, slot_id ) )
1173 {
1174 if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1175 {
1176 player.PredictiveTakeEntityToTargetAttachmentEx(slot_owner, item, slot_id);
1177 }
1178 else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1179 {
1180 item_base.SplitIntoStackMaxClient( slot_owner, slot_id );
1181 }
1182 }
1183 else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( item ) )
1184 {
1185 if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1186 {
1187 player.PredictiveTakeEntityToTargetAttachment(slot_owner, item);
1188 }
1189 else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1190 {
1191 item_base.SplitIntoStackMaxClient( slot_owner, -1 );
1192 }
1193 }
1194 else if( target_att_entity.GetInventory().CanAddAttachment( item ) )
1195 {
1196 if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1197 {
1198 player.PredictiveTakeEntityToTargetAttachment(target_att_entity, item);
1199 }
1200 else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1201 {
1202 item_base.SplitIntoStackMaxClient( target_att_entity, -1 );
1203 }
1204 }
1205 else if( ( target_att_entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && ( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item )) ) || player.GetHumanInventory().HasEntityInHands( item ) )
1206 {
1207 SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), target_att_entity, item );
1208 }
1209 /*else if( !player.GetInventory().HasEntityInInventory( item ) || !target_att_entity.GetInventory().HasEntityInCargo( item ) )
1210 {
1211 SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), target_att_entity, item );
1212 }*/
1213
1216 }
1217
1218 void ShowAtt( EntityAI entity )
1219 {
1222 m_Entity = entity;
1223 m_ActiveIndex = 0;
1224 if( entity.GetSlotsCountCorrect() > 0 )
1225 {
1226 m_Atts = new Attachments( this, entity );
1227 m_Atts.InitAttachmentGrid( 1 );
1228 m_AttachmentSlotsSorted = m_Atts.GetSlotsSorted();
1229 m_StaticAttCount = m_Atts.GetAttachmentHeight();
1230 m_Entity.GetOnItemAttached().Insert( AttachmentAdded );
1231 m_Entity.GetOnItemDetached().Insert( AttachmentRemoved );
1232 }
1233 else
1234 {
1235 m_StaticAttCount = 0;
1236 }
1237
1238 if( entity.GetInventory().GetCargo() )
1239 {
1240 m_CargoGrid = new CargoContainer( this, false );
1241 m_CargoGrid.SetEntity( entity );
1242 m_CargoGrid.GetRootWidget().SetSort( 1 );
1245 }
1246
1248 {
1249 foreach( int slot_id : m_AttachmentSlotsSorted )
1250 {
1251 EntityAI item = m_Entity.GetInventory().FindAttachment( slot_id );
1252 if( item )
1254 }
1255 }
1256
1257 if (m_CargoGrid)
1258 {
1259 bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1260 if (m_CargoGrid.IsVisible() && hideCargo)
1261 {
1262 HideCargo();
1263 }
1264 else if (!m_CargoGrid.IsVisible() && !hideCargo)
1265 {
1266 ShowCargo();
1267 }
1268 }
1269
1270 m_CollapsibleHeader.ShowCollapseButtons(false);
1271 //m_CollapsibleHeader.ShowCollapseButtons( m_Atts || m_CargoGrid, m_Atts || m_CargoGrid );
1272 RecomputeOpenedContainers();
1273 Refresh();
1274 m_Parent.Refresh();
1275 }
1276
1278 {
1279 for (int i = 0; i < m_Body.Count(); i++)
1280 {
1281 m_Body.Get( i ).OnShow();
1282 }
1283 Refresh();
1284 m_Parent.Refresh();
1285 }
1286
1287 void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
1288 {
1289 int slot_id = InventorySlots.GetSlotIdFromString( slot );
1290 int sort = -1;
1291 Attachments att_cont = null;
1292 CargoContainer cont = null;
1293
1294 if( item.GetInventory().GetAttachmentSlotsCount() > 0 )
1295 {
1296 att_cont = new Attachments( this, item );
1297 sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_ATTACHMENTS_NEXT_OFFSET;
1298 att_cont.InitAttachmentGrid( sort );
1299
1300 m_AttachmentAttachments.Insert( item, att_cont );
1301 m_AttachmentAttachmentsContainers.Insert( item, att_cont.GetWrapper() );
1302
1303 att_cont.UpdateInterval();
1304 if( m_Parent )
1305 m_Parent.Refresh();
1306 Inventory.GetInstance().UpdateConsoleToolbar();
1307 }
1308
1309 if( item.GetInventory().GetCargo() )
1310 {
1311 cont = new CargoContainer( this, true );
1312 sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_CARGO_NEXT_OFFSET; //m_AttachmentSlotsSorted.Find( slot_id ) + 50
1313 cont.GetRootWidget().SetSort( sort );
1314 cont.SetEntity( item );
1315
1316 Insert(cont, -1);
1317
1318 m_AttachmentCargos.Insert( item, cont );
1319 if( m_Parent )
1320 m_Parent.Refresh();
1321 Inventory.GetInstance().UpdateConsoleToolbar();
1322 }
1323
1324 if (att_cont)
1325 {
1326 att_cont.ShowFalseAttachmentsHeader(true);
1327 if (cont)
1328 {
1329 cont.ShowFalseCargoHeader(false);
1330 cont.UpdateSize();
1331 cont.SetAlternateFalseTextHeaderWidget(att_cont.GetFalseHeaderTextWidget());
1332 }
1333 }
1334 else if (cont)
1335 {
1336 cont.SetAlternateFalseTextHeaderWidget(null); //just to be safe..
1337 }
1338
1339 RecomputeOpenedContainers();
1340 }
1341
1342 void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
1343 {
1344 int slot_id = InventorySlots.GetSlotIdFromString( slot );
1345
1346 CargoContainer old_cont = m_AttachmentCargos.Get( item );
1347 if( old_cont )
1348 {
1349 m_Body.RemoveItem( old_cont );
1350 m_AttachmentCargos.Remove( item );
1351 delete old_cont;
1352 if( m_Parent )
1353 m_Parent.Refresh();
1354 Inventory.GetInstance().UpdateConsoleToolbar();
1355 }
1356
1357 AttachmentsWrapper old_att_cont = m_AttachmentAttachmentsContainers.Get( item );
1358 if( old_att_cont )
1359 {
1360 m_AttachmentAttachmentsContainers.Remove( item );
1361 m_AttachmentAttachments.Remove( item );
1362 m_Body.RemoveItem( old_att_cont );
1363 delete old_att_cont;
1364 if( m_Parent )
1365 m_Parent.Refresh();
1366 Inventory.GetInstance().UpdateConsoleToolbar();
1367 }
1368 RecomputeOpenedContainers();
1369 }
1370
1371 override void UpdateInterval()
1372 {
1373 super.UpdateInterval();
1374
1375 if ( m_Entity )
1376 {
1377 if (m_CargoGrid)
1378 {
1379 bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1380 if (m_CargoGrid.IsVisible() && hideCargo)
1381 {
1382 HideCargo();
1383 }
1384 else if (!m_CargoGrid.IsVisible() && !hideCargo)
1385 {
1386 ShowCargo();
1387 }
1388
1389 m_CargoGrid.UpdateInterval();
1390 }
1391
1392 if ( m_Atts )
1393 {
1394 m_Atts.UpdateInterval();
1395 }
1396
1397 for ( int i = 0; i < m_AttachmentCargos.Count(); i++ )
1398 {
1399 m_AttachmentCargos.GetElement( i ).UpdateInterval();
1400 }
1401 }
1402
1404 m_CollapsibleHeader.UpdateInterval();
1405 }
1406
1407 override void SetLayoutName()
1408 {
1409 m_LayoutName = WidgetLayoutName.ClosableContainer;
1410 }
1411
1412 override void OnShow()
1413 {
1414 super.OnShow();
1415
1416 for ( int i = 0; i < m_Body.Count(); i++ )
1417 {
1418 m_Body.Get( i ).OnShow();
1419 }
1420 }
1421
1422 void MouseClick2(Widget w, int x, int y, int button)
1423 {
1424 string name = w.GetName();
1425 name.Replace("PanelWidget", "Render");
1426 ItemPreviewWidget itemPreview = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
1427
1428 if (itemPreview)
1429 {
1430 ItemBase selectedItem = ItemBase.Cast(itemPreview.GetItem());
1431
1432 if (selectedItem)
1433 {
1434 switch (button)
1435 {
1436 case MouseState.RIGHT:
1437 #ifdef DIAG_DEVELOPER
1438 if (g_Game.IsLeftCtrlDown())
1439 ShowActionMenu(selectedItem);
1440 #endif
1441 if (CanSplitEx(selectedItem))
1442 {
1443 selectedItem.OnRightClick();
1444 }
1445
1446 break;
1447
1448 case MouseState.MIDDLE:
1449 InspectItem(selectedItem);
1450 break;
1451
1452 case MouseState.LEFT:
1453 PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
1454 if (g_Game.IsLeftCtrlDown())
1455 {
1456 if (controlledPlayer.CanDropEntity(selectedItem))
1457 {
1458 if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
1459 selectedItem.SplitIntoStackMaxClient(null, -1);
1460 else
1461 controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
1462 }
1463 else
1464 {
1465 bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem, null ) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
1467 }
1468 }
1469
1470 break;
1471 }
1472 }
1473 }
1474 }
1475
1476 void DoubleClick(Widget w, int x, int y, int button)
1477 {
1478 if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
1479 {
1480 ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
1481 if (!iw)
1482 {
1483 string name = w.GetName();
1484 name.Replace("PanelWidget", "Render");
1485 iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
1486 }
1487
1488 if (!iw)
1489 iw = ItemPreviewWidget.Cast(w);
1490
1491 ItemBase item = ItemBase.Cast(iw.GetItem());
1492 if (item)
1493 {
1494 PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
1495 EntityAI itemInHands = controlledPlayer.GetHumanInventory().GetEntityInHands();
1496
1497 if (!item.GetInventory().CanRemoveEntity())
1498 return;
1499
1500 if (controlledPlayer.GetInventory().HasEntityInInventory(item) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
1501 {
1502 controlledPlayer.PredictiveTakeEntityToHands(item);
1503 }
1504 else
1505 {
1506 if (controlledPlayer.GetInventory().CanAddEntityToInventory(item) && controlledPlayer.GetHumanInventory().CanRemoveEntityInHands())
1507 {
1508 controlledPlayer.PredictiveTakeEntityToInventory(FindInventoryLocationType.ANY, item);
1509 }
1510 else
1511 {
1512 if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
1513 controlledPlayer.PredictiveTakeEntityToHands(item);
1514 }
1515 }
1516
1517 HideOwnedTooltip();
1518
1519 name = w.GetName();
1520 name.Replace("PanelWidget", "Temperature");
1521 w.FindAnyWidget(name).Show(false);
1522 }
1523 }
1524 }
1525
1526 void DraggingOverHeader2(Widget w, int x, int y, Widget receiver )
1527 {
1528 DraggingOverHeader(w, x, y, receiver );
1529 }
1530
1532 {
1533 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
1534 if( item_in_hands && item_in_hands.GetCompEM() )
1535 {
1536 if( GetRootWidget().FindAnyWidget( "electricity" ) )
1537 {
1538 bool show_electricity_icon = item_in_hands.GetCompEM().HasElectricityIcon();
1539 GetRootWidget().FindAnyWidget( "electricity" ).Show( show_electricity_icon );
1540 }
1541
1542 if( GetRootWidget().FindAnyWidget( "electricity_can_work" ) )
1543 {
1544 bool show_electricity_can_work_icon = item_in_hands.GetCompEM().CanWork() && !item_in_hands.IsRuined();
1545 GetRootWidget().FindAnyWidget( "electricity_can_work" ).Show( show_electricity_can_work_icon );
1546 }
1547 }
1548 else
1549 {
1550 GetRootWidget().FindAnyWidget( "electricity" ).Show( false );
1551 }
1552 }
1553
1555 {
1556 int i;
1557 if( !m_Hidden )
1558 {
1559 for (i = 0; i < m_Body.Count(); i++)
1560 {
1561 m_Body.Get( i ).OnHide();
1562 }
1563 m_Hidden = true;
1564 }
1565 else
1566 {
1567 for (i = 0; i < m_Body.Count(); i++)
1568 {
1569 m_Body.Get( i ).OnShow();
1570 }
1571 m_Hidden = false;
1572 }
1573
1574 w.FindAnyWidget("opened").Show(m_Hidden);
1575 w.FindAnyWidget("closed").Show(!m_Hidden);
1576
1577 m_Parent.Refresh();
1578 }
1579
1581 {
1582 if( m_CargoGrid )
1583 {
1584 m_CargoGrid.OnHide();
1585 RecomputeOpenedContainers();
1586 }
1587 }
1588
1590 {
1591 if( m_CargoGrid )
1592 {
1593 m_CargoGrid.OnShow();
1594 RecomputeOpenedContainers();
1595 }
1596 }
1597}
void Inventory(LayoutHolder parent)
Определения Inventory.c:74
EntityAI m_Entity
Определения ActionDebug.c:11
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
map
Определения ControlsXboxNew.c:4
DayZGame g_Game
Определения DayZGame.c:3868
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
Определения InventoryLocation.c:17
override ContextMenu GetContextMenu()
Определения InventoryMenu.c:80
bool m_IsActive
Определения ModifierBase.c:19
PlayerBase GetPlayer()
Определения ModifierBase.c:51
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:316
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Определения PluginRemotePlayerDebugClient.c:14
DayZPlayer m_player
Определения RandomGeneratorSyncManager.c:16
Widget m_Parent
Определения SizeToChild.c:92
void SetActive()
Определения TrapBase.c:414
bool CanSetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
Определения ActionManagerClient.c:1138
void UpdateInterval()
Определения Attachments.c:321
AttachmentsWrapper GetWrapper()
Определения Attachments.c:44
TextWidget GetFalseHeaderTextWidget()
Определения Attachments.c:606
void InitAttachmentGrid(int att_row_index)
Определения Attachments.c:458
void ShowFalseAttachmentsHeader(bool show)
Определения Attachments.c:596
Определения Attachments.c:4
proto native DayZPlayer GetPlayer()
proto native int GetItemCount()
proto native int GetWidth()
proto native int GetHeight()
represents base for cargo storage for entities
Определения Cargo.c:7
Super root of all classes in Enforce script.
Определения EnScript.c:11
void SetColor(Widget w, int color)
Определения ColorManager.c:32
static int BASE_COLOR
Определения ColorManager.c:15
static int COMBINE_COLOR
Определения ColorManager.c:20
static int SWAP_COLOR
Определения ColorManager.c:18
static int GREEN_COLOR
Определения ColorManager.c:17
static int RED_COLOR
Определения ColorManager.c:16
static ColorManager GetInstance()
Определения ColorManager.c:27
Определения ColorManager.c:2
override EntityAI GetFocusedItem()
Определения CargoContainer.c:733
override bool Select()
Определения CargoContainer.c:852
override float GetFocusedContainerHeight(bool contents=false)
Определения CargoContainer.c:436
override float GetFocusedContainerYScreenPos(bool contents=false)
Определения CargoContainer.c:456
void CargoContainer(LayoutHolder parent, bool is_attachment=false)
Определения CargoContainer.c:32
Определения CargoContainer.c:3
Определения Building.c:6
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Определения Inventory.c:628
script counterpart to engine's class Inventory
Определения Inventory.c:79
void ResetContainer()
Определения HandsContainer.c:56
override void OnDropReceivedFromHeader(Widget w, int x, int y, Widget receiver)
Определения HandsContainer.c:785
void SetFocusToIndex()
Определения HandsContainer.c:72
ref map< EntityAI, ref CargoContainer > m_AttachmentCargos
Определения HandsContainer.c:10
void DropReceived(Widget w, int x, int y, CargoContainer cargo)
Определения HandsContainer.c:976
void HideCargo()
Определения HandsContainer.c:1580
override bool InspectItem()
Определения HandsContainer.c:384
ref map< EntityAI, AttachmentsWrapper > m_AttachmentAttachmentsContainers
Определения HandsContainer.c:11
void ShowAtt(EntityAI entity)
Определения HandsContainer.c:1218
void ScrollToActiveContainer(Container active_container)
Определения HandsContainer.c:160
ref map< EntityAI, ref Attachments > m_AttachmentAttachments
Определения HandsContainer.c:12
override bool TransferItem()
Определения HandsContainer.c:187
void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
Определения HandsContainer.c:1342
void DoubleClick(Widget w, int x, int y, int button)
Определения HandsContainer.c:1476
void DestroyAtt()
Определения HandsContainer.c:888
void OnPerformCombination(int combinationFlags)
Определения HandsContainer.c:624
int GetRecipeCount(bool recipe_anywhere, EntityAI entity1, EntityAI entity2)
Определения HandsContainer.c:876
void DraggingOverHeader2(Widget w, int x, int y, Widget receiver)
Определения HandsContainer.c:1526
void ~HandsContainer()
Определения HandsContainer.c:43
ref HandsHeader m_CollapsibleHeader
Определения HandsContainer.c:4
override bool IsEmpty()
Определения HandsContainer.c:351
override bool OnSelectButton()
Определения HandsContainer.c:403
override bool TransferItemToVicinity()
Определения HandsContainer.c:357
EntityAI GetItemPreviewItem(Widget w)
Определения HandsContainer.c:436
void ShowActionMenuCombine(EntityAI entity1, EntityAI entity2, int combinationFlags)
Определения HandsContainer.c:726
ScrollWidget m_ScrollWidget
Определения HandsContainer.c:18
override bool IsLastIndex()
Определения HandsContainer.c:67
override void SetLayoutName()
Определения HandsContainer.c:1407
override void SetLastActive()
Определения HandsContainer.c:297
ref HandsPreview m_HandsPreview
Определения HandsContainer.c:5
override void UpdateInterval()
Определения HandsContainer.c:1371
void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
Определения HandsContainer.c:1287
bool DraggingOverGrid(Widget w, int x, int y, Widget reciever, CargoContainer cargo)
Определения HandsContainer.c:1065
override bool EquipItem()
Определения HandsContainer.c:235
override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
Определения HandsContainer.c:459
void RemoveItem()
Определения HandsContainer.c:882
void RefreshHands()
Определения HandsContainer.c:1277
ref Attachments m_Atts
Определения HandsContainer.c:7
void DestroyCargo()
Определения HandsContainer.c:953
override bool IsItemWithQuantityActive()
Определения HandsContainer.c:340
void TakeAsAttachment(Widget w, Widget receiver)
Определения HandsContainer.c:1114
void OnDropReceivedFromHeader2(Widget w, int x, int y, Widget receiver)
Определения HandsContainer.c:619
void HandsContainer(LayoutHolder parent)
Определения HandsContainer.c:20
override Header GetHeader()
Определения HandsContainer.c:62
override void UnfocusGrid()
Определения HandsContainer.c:918
override void Refresh()
Определения HandsContainer.c:323
void CollapseButtonOnMouseButtonDown(Widget w)
Определения HandsContainer.c:1554
ref CargoContainer m_CargoGrid
Определения HandsContainer.c:8
int GetCombinationFlags(EntityAI entity1, EntityAI entity2)
Определения HandsContainer.c:790
void ElectricityIcon()
Определения HandsContainer.c:1531
bool m_Hidden
Определения HandsContainer.c:3
override void UnfocusAll()
Определения HandsContainer.c:948
override void Insert(LayoutHolder container, int pos=-1, bool immedUpdate=true)
Определения HandsContainer.c:182
void ShowCargo()
Определения HandsContainer.c:1589
int m_StaticAttCount
Определения HandsContainer.c:15
void MouseClick2(Widget w, int x, int y, int button)
Определения HandsContainer.c:1422
override void OnShow()
Определения HandsContainer.c:1412
override void SetActive(bool active)
Определения HandsContainer.c:268
override bool SplitItem()
Определения HandsContainer.c:212
override bool IsItemActive()
Определения HandsContainer.c:329
int m_StaticCargoCount
Определения HandsContainer.c:16
ref array< int > m_AttachmentSlotsSorted
Определения HandsContainer.c:13
Определения HandsHeader.c:2
Определения HandsPreview.c:2
Определения Header.c:2
override void Refresh()
Определения Icon.c:1216
Определения Icon.c:2
static const int LOAD_CHAMBER
Определения InventoryCombinationFlags.c:16
static const int ADD_AS_CARGO
Определения InventoryCombinationFlags.c:5
static const int TAKE_TO_HANDS
Определения InventoryCombinationFlags.c:11
static const int NONE
Определения InventoryCombinationFlags.c:3
static const int SET_ACTION
Определения InventoryCombinationFlags.c:19
static const int ADD_AS_ATTACHMENT
Определения InventoryCombinationFlags.c:4
static const int RECIPE_ANYWHERE
Определения InventoryCombinationFlags.c:14
static const int COMBINE_QUANTITY2
Определения InventoryCombinationFlags.c:13
static const int SWAP
Определения InventoryCombinationFlags.c:6
Определения ItemBase.c:15
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
InventoryLocation.
Определения InventoryLocation.c:29
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
provides access to slot configuration
Определения InventorySlots.c:6
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Определения Rag.c:61
override bool CanBeSplit()
Определения Rag.c:34
Определения InventoryItem.c:731
Widget GetCenterDropzone()
Определения ItemManager.c:351
void ShowSourceDropzone(EntityAI item)
Определения ItemManager.c:302
Widget GetLeftDropzone()
Определения ItemManager.c:336
void SetHandsPreview(HandsPreview hansd_preview)
Определения ItemManager.c:80
EntityAI GetSelectedItem()
Определения ItemManager.c:85
Widget GetRightDropzone()
Определения ItemManager.c:344
void HideDropzones()
Определения ItemManager.c:287
bool IsMicromanagmentMode()
Определения ItemManager.c:70
void SetWidgetDraggable(Widget w, bool draggable)
Определения ItemManager.c:693
void SetIsDragging(bool is_dragging)
Определения ItemManager.c:383
static ItemManager GetInstance()
Определения ItemManager.c:282
Определения ItemManager.c:2
proto native EntityAI GetItem()
Определения gameplay.c:277
Определения Container.c:2
Определения PlayerBaseClient.c:2
static int HasItemQuantity(notnull EntityAI item)
Определения QuantityConversions.c:143
EntityAI GetEntity()
Определения SlotsIcon.c:365
EntityAI GetSlotParent()
Определения SlotsIcon.c:185
int GetSlotID()
Определения SlotsIcon.c:190
Определения SlotsIcon.c:2
static void TakeOrSplitToInventoryLocation(notnull PlayerBase player, notnull InventoryLocation dst)
Определения SplitItemUtils.c:34
static void TakeOrSplitToInventory(notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
Определения SplitItemUtils.c:3
Определения SplitItemUtils.c:2
shorthand
Определения BoltActionRifle_Base.c:6
Определения EnWidgets.c:190
const string ClosableContainer
Определения WidgetLayoutName.c:49
Определения ZombieFemaleBase.c:2
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);.
Определения EnScript.c:345
MouseState
Определения EnSystem.c:311
proto void GetMousePos(out int x, out int y)
WidgetFlags
Определения EnWidgets.c:58
proto native Widget FindAnyWidget(string pathname)