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