DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
CargoContainer.c
Go to the documentation of this file.
1//cargo grid wrapper
2class CargoContainer extends Container
3{
4 protected const int ROWS_NUMBER_XBOX = 5;
5
6 protected CargoBase m_Cargo;
7 protected int m_CargoIndex = -1;
8
9 protected int m_FocusedItemPosition = -1;
11 protected ref array<ref Icon> m_Icons;
14
15 protected float m_IconSize;
16 protected float m_SpaceSize;
17
18 protected bool m_IsAttachment;
20 protected TextWidget m_AlternateFalseHeaderTextWidget; //to be set and updated along with the main one
24 protected ref SizeToChild m_Resizer1;
25 protected ref SizeToChild m_Resizer2;
26 protected ref Timer m_ResizeTimer;
27
28 void CargoContainer( LayoutHolder parent, bool is_attachment = false )
29 {
30 m_IsAttachment = is_attachment;
32 m_Icons = new array<ref Icon>;
33 m_ShowedItemPositions = new map<EntityAI, ref Param3<ref Icon, int, int>>;
34 m_ShowedLockPositions = new map<EntityAI, ref Param3<ref Icon, int, int>>;
35
36 m_CargoContainer = m_RootWidget.FindAnyWidget( "grid_background" );
37 m_ItemsContainer = m_RootWidget.FindAnyWidget( "grid_overlay" );
38 m_CargoHeader = m_RootWidget.FindAnyWidget( "grid_container_header_spacer" );
39
40 m_RootWidget.GetScript( m_Resizer1 );
41
42 m_RootWidget.FindAnyWidget( "grid_container" ).GetScript( m_Resizer2 );
43 m_CargoHeader.Show( is_attachment );
44 m_FalseHeaderTextWidget = TextWidget.Cast(m_CargoHeader.FindAnyWidget( "TextWidget0" ));
45
46 m_MainWidget = m_CargoContainer;
47 m_FocusedItemPosition = -1;
48 }
49
51 {
52 if ( m_Entity )
53 {
54 m_Entity.GetOnItemAddedIntoCargo().Remove( AddedToCargo );
55 m_Entity.GetOnItemRemovedFromCargo().Remove( RemovedFromCargo );
56 m_Entity.GetOnItemMovedInCargo().Remove( MovedInCargo );
57 m_Entity.GetOnSetLock().Remove( SetLock );
58 m_Entity.GetOnReleaseLock().Remove( ReleaseLock );
59 }
60 }
61
62 int GetCargoIndex() { return m_CargoIndex; }
63
64 void AddedToCargoEx( EntityAI item, bool refresh = true )
65 {
67 item.GetInventory().GetCurrentInventoryLocation( il );
68 int x = il.GetCol();
69 int y = il.GetRow();
70
71 if ( m_ShowedItemPositions.Contains( item ) )
72 {
73 Param3<ref Icon, int, int> item_pos = m_ShowedItemPositions.Get( item );
74 InitIconEx( item_pos.param1, item, x, y, refresh );
75 item_pos.param2 = x;
76 item_pos.param3 = y;
77 }
78 else
79 {
80 ref Icon icon = new Icon( this, false );
81 m_Icons.Insert( icon );
82 InitIconEx( icon, item, x, y, refresh );
83 m_ShowedItemPositions.Insert( item, new Param3<ref Icon, int, int>( icon, x, y ) );
84 }
85
86 if (refresh)
88
89 #ifdef PLATFORM_CONSOLE
90 for ( int i = 0; i < m_Cargo.GetItemCount(); i++ )
91 {
92 EntityAI item2 = m_Cargo.GetItem( i );
93 Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item2 );
94 if ( data )
95 {
96 data.param1.SetCargoPos( i );
97 data.param1.SetPos();
98 }
99 }
100
101 m_FocusedItemPosition = Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
102
103 if (refresh)
104 Refresh();
105 #endif
106 }
107
109 {
110 AddedToCargoEx( item );
111 }
112
114 {
115 Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
116 if( data )
117 {
118 m_Icons.RemoveItem( data.param1 );
119 m_ShowedItemPositions.Remove( item );
120 }
121
123
124 #ifdef PLATFORM_CONSOLE
125 for( int i = 0; i < m_Cargo.GetItemCount(); i++ )
126 {
127 EntityAI item2 = m_Cargo.GetItem( i );
128 data = m_ShowedItemPositions.Get( item2 );
129 if( data && data.param1 )
130 {
131 data.param1.SetCargoPos( i );
132 data.param1.SetPos();
133 }
134 }
135
136 m_FocusedItemPosition = Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
137
138 Refresh();
139 #endif
140 }
141
143 {
145 item.GetInventory().GetCurrentInventoryLocation( il );
146
147 int x = il.GetCol();
148 #ifdef PLATFORM_CONSOLE
149 int y = il.GetRow() - 1;
150 #else
151 int y = il.GetRow();
152 #endif
153 if( m_ShowedItemPositions.Contains( item ) )
154 {
155 ref Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
156 if( data.param1 )
157 {
158 if( data.param2 != x || data.param3 != y )
159 {
160 data.param2 = x;
161 data.param3 = y;
162 #ifdef PLATFORM_CONSOLE
163 data.param1.SetCargoPos( data.param3 );
164 #endif
165 #ifdef PLATFORM_WINDOWS
166 data.param1.SetPosX( data.param2 );
167 data.param1.SetPosY( data.param3 );
168 #endif
169 }
170 data.param1.UpdateInterval();
171 }
172 }
174 }
175
176 void SetLock( EntityAI item )
177 {
178 #ifndef PLATFORM_CONSOLE
179 if( GetGame().GetPlayer() )
180 {
182 int index = GetGame().GetPlayer().GetHumanInventory().FindUserReservedLocationIndex( item );
183 if( index >= 0 )
184 {
185 GetGame().GetPlayer().GetHumanInventory().GetUserReservedLocation( index, il );
186
187 ref Icon icon = new Icon( this, false );
188 m_Icons.Insert( icon );
189 icon.InitLock( m_Entity, item, il.GetCol(), il.GetRow(), il.GetFlip() );
190 m_ShowedLockPositions.Insert( item, new Param3<ref Icon, int, int>( icon, 1, 1 ) );
191 item.GetOnReleaseLock().Insert( ReleaseLock );
192 }
193 }
194 #endif
195 }
196
198 {
199 #ifndef PLATFORM_CONSOLE
200 if( m_ShowedLockPositions.Contains( item ) )
201 {
202 Icon ic = m_ShowedLockPositions.Get( item ).param1;
203 m_Icons.RemoveItem( ic );
204 m_ShowedLockPositions.Remove( item );
205 item.GetOnReleaseLock().Remove( ReleaseLock );
206 }
207 #endif
208 }
209
210 override void SetLayoutName()
211 {
212 #ifdef PLATFORM_CONSOLE
214 #else
215 switch( InventoryMenu.GetWidthType() )
216 {
217 case ScreenWidthType.NARROW:
218 {
220 break;
221 }
222 case ScreenWidthType.MEDIUM:
223 {
225 break;
226 }
227 case ScreenWidthType.WIDE:
228 {
230 break;
231 }
232 }
233 #endif
234
235 }
236
237 void SetEntity( EntityAI item, int cargo_index = 0, bool immedUpdate = true )
238 {
239 if ( item )
240 {
241 m_Entity = item;
242 m_Cargo = item.GetInventory().GetCargoFromIndex(cargo_index);
243 m_CargoIndex = cargo_index;
244
245 m_Entity.GetOnItemAddedIntoCargo().Insert( AddedToCargo );
246 m_Entity.GetOnItemRemovedFromCargo().Insert( RemovedFromCargo );
247 m_Entity.GetOnItemMovedInCargo().Insert( MovedInCargo );
248 m_Entity.GetOnSetLock().Insert( SetLock );
249 m_Entity.GetOnReleaseLock().Insert( ReleaseLock );
250
251 if (immedUpdate)
253
255 m_MainWidget = m_ItemsContainer;
256
257 if ( m_Cargo )
258 {
259 int i;
260 int prev_count = m_ShowedItemPositions.Count();
261
262 //START - Add new item Icons
263 for ( i = 0; i < m_Cargo.GetItemCount(); i++ )
264 {
265 EntityAI cargo_item = m_Cargo.GetItem( i );
266 if ( cargo_item )
267 {
268 AddedToCargoEx( cargo_item, immedUpdate );
269 }
270 }
271
272 #ifdef PLATFORM_CONSOLE
273 if (immedUpdate)
274 Refresh();
275 #endif
276 }
277 }
278 }
279
281 {
282 return m_Entity;
283 }
284
286 {
287 Widget header;
288 string name = m_Entity.GetDisplayName();
289 name.ToUpper();
290
291 if ( m_Entity.CanDisplayCargo() && m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex) )
292 {
293 name = name + " (" + GetCargoCapacity().ToString() + "/" + GetMaxCargoCapacity() + ")";
294 if ( m_IsAttachment && m_CargoHeader )
295 {
296 m_FalseHeaderTextWidget.SetText(name);
297 float x, y;
298 m_FalseHeaderTextWidget.Update();
299 m_FalseHeaderTextWidget.GetScreenSize( x, y );
300 m_CargoHeader.FindAnyWidget( "grid_container_header" ).SetSize( 1, y + InventoryMenu.GetHeightMultiplied( 10 ) );
301 m_CargoHeader.Update();
302
303 if (m_AlternateFalseHeaderTextWidget)
304 {
305 m_AlternateFalseHeaderTextWidget.SetText(name);
306 }
307 return;
308 }
309 }
310
311 if ( Container.Cast( GetParent() ) && Container.Cast( GetParent() ).GetHeader() )
313 }
314
316 {
317 m_Rows.Clear();
318 m_ShowedItemPositions.Clear();
319
320 ref CargoContainerRow row;
321
322 #ifdef PLATFORM_CONSOLE
323 int cargo_height = 1;
324 #else
325 int cargo_height = m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetHeight();
326 #endif
327
328 for ( int j = 0; j < cargo_height; j++ )
329 {
330 row = new CargoContainerRow( this );
331
332 row.SetNumber( j );
333 row.SetEntity( m_Entity );
334
335 #ifdef PLATFORM_WINDOWS
336 #ifndef PLATFORM_CONSOLE
337 row.SetWidth( m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetWidth(), false );
338 #endif
339 #endif
340
341 row.GetRootWidget().SetSort( j, false );
342 m_Rows.Insert( row );
343 }
344
345 float y;
346 row.GetRootWidget().FindAnyWidget( "Icon0" ).GetScreenSize( y, m_IconSize );
347 #ifdef PLATFORM_WINDOWS
348 #ifndef PLATFORM_CONSOLE
349 row.GetRootWidget().FindAnyWidget( "Spacer0" ).GetScreenSize( m_SpaceSize, y );
350 #endif
351 #endif
352
353 m_Resizer2.ResizeParentToChild();
354 m_Resizer1.ResizeParentToChild();
355 }
356
358 {
359 m_Resizer1.ResizeParentToChild();
360 }
361
363 {
364 return m_IconSize;
365 }
366
368 {
369 return m_SpaceSize;
370 }
371
373 {
374 #ifdef PLATFORM_CONSOLE
375 #ifndef PLATFORM_WINDOWS
376 return CargoList.Cast( m_Cargo ).GetTotalWeight( null );
377 #endif
378 #endif
379 int total_size = 0;
380 for ( int i = 0; i < m_Cargo.GetItemCount(); ++i )
381 {
382 int x, y;
383 m_Cargo.GetItemSize( i, x, y );
384 total_size += x * y;
385 }
386 return total_size;
387 }
388
390 {
391 #ifdef PLATFORM_CONSOLE
392 #ifndef PLATFORM_WINDOWS
393 return CargoList.Cast( m_Cargo ).GetMaxWeight();
394 #endif
395 #endif
396 return m_Cargo.GetWidth() * m_Cargo.GetHeight();
397 }
398
400 {
401 if ( item && m_ShowedItemPositions.Contains( item ) )
402 {
403 Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
404 return data.param1;
405 }
406 return null;
407 }
408
409 Icon GetIcon( int index )
410 {
411 if ( m_Cargo == null )
412 {
413 Print("Attempted to get icon on cargo container, but cargo was null!");
414 return null;
415 }
416
417 if ( index >= 0 && m_Cargo.GetItemCount() > index )
418 return GetIcon( m_Cargo.GetItem( index ) );
419 return null;
420 }
421
423 {
424 return GetIcon( m_FocusedItemPosition );
425 }
426
427 override float GetFocusedContainerHeight( bool contents = false )
428 {
429 float x, y;
430 if( contents && GetFocusedIcon() )
431 GetFocusedIcon().GetRootWidget().GetScreenSize( x, y );
432 else
433 GetRootWidget().GetScreenSize( x, y );
434 return y;
435 }
436
437 override float GetFocusedContainerYPos( bool contents = false )
438 {
439 float x, y;
440 if( contents && GetFocusedIcon() )
441 GetFocusedIcon().GetRootWidget().GetPos( x, y );
442 else
443 GetRootWidget().GetPos( x, y );
444 return y;
445 }
446
447 override float GetFocusedContainerYScreenPos( bool contents = false )
448 {
449 float x, y;
450 if( contents && GetFocusedIcon() )
451 GetFocusedIcon().GetRootWidget().GetScreenPos( x, y );
452 else
453 GetRootWidget().GetScreenPos( x, y );
454 return y;
455 }
456
458 {
459 if( m_IsActive )
460 {
461 if( m_FocusedItemPosition >= m_Icons.Count() )
462 m_FocusedItemPosition = m_Icons.Count() - 1;
463 Icon icon = GetIcon( m_FocusedItemPosition );
464 if( icon && !icon.IsActive() )
465 {
466 icon.SetActive( true );
467 Inventory.GetInstance().UpdateConsoleToolbar();
468 }
469 }
470 }
471
472 void UpdateRowVisibility( int count )
473 {
474 int i;
475 int rows = Math.Max( 1, Math.Ceil( (count + 1) / ROWS_NUMBER_XBOX ) );
476 int diff = rows - m_Rows.Count();
477
478 if( diff < 0 )
479 {
480 for( i = m_Rows.Count() - 1; i >= rows; i-- )
481 {
482 m_Rows.Remove( i );
483 }
484 }
485 else if( diff > 0 )
486 {
487 m_MainWidget = m_CargoContainer;
488 for( i = m_Rows.Count(); i < rows; i++ )
489 {
490 ref CargoContainerRow row = new CargoContainerRow( this );
491
492 row.SetNumber( i );
493 row.SetEntity( m_Entity );
494 row.GetRootWidget().SetSort( i );
495 m_Rows.Insert( row );
496 }
497 m_MainWidget = m_ItemsContainer;
498 }
499
500 m_Resizer2.ResizeParentToChild();
501 m_Resizer1.ResizeParentToChild();
502 }
503
504 override void Refresh()
505 {
506 #ifdef PLATFORM_CONSOLE
507 if ( !m_ResizeTimer )
508 m_ResizeTimer = new Timer();
509 if ( m_ResizeTimer.IsRunning() )
510 m_ResizeTimer.Stop();
511 m_ResizeTimer.Run( 0.05, this, "RefreshImpl" );
512 #endif
513 }
514
516 {
517 UpdateRowVisibility( m_ShowedItemPositions.Count() );
519 }
520
521 override void UpdateInterval()
522 {
523 foreach( Param3<ref Icon, int, int> data : m_ShowedItemPositions )
524 {
525 if( data.param1 )
526 {
527 data.param1.UpdateInterval();
528 }
529 }
530 }
531
532 Icon InitIconEx( Icon icon, EntityAI item, int pos_x, int pos_y, bool refresh = true )
533 {
534 #ifdef PLATFORM_CONSOLE
535 icon.SetSize( 1, 1 );
536 #ifdef PLATFORM_WINDOWS
537 pos_y = pos_y * 5 + pos_x;
538 #endif
539 icon.SetCargoPos( pos_y );
540 icon.SetPosY( pos_y );
541 icon.SetPosEx( refresh );
542 #else
543 int size_x, size_y;
544 GetGame().GetInventoryItemSize( InventoryItem.Cast( item ), size_x, size_y );
545
546 if ( item.GetInventory().GetFlipCargo() )
547 icon.SetSize( size_y, size_x );
548 else
549 icon.SetSize( size_x, size_y );
550
551 icon.SetPosX( pos_x );
552 icon.SetPosY( pos_y );
553 icon.SetPosEx( refresh );
554 #endif
555 icon.InitEx( item, refresh );
556 return icon;
557 }
558
559 Icon InitIcon( Icon icon, EntityAI item, int pos_x, int pos_y )
560 {
561 return InitIconEx( icon, item, pos_x, pos_y );
562 }
563
564 bool HasItem( EntityAI item )
565 {
566 return m_ShowedItemPositions.Contains( item );
567 }
568
570 {
571 Man player = GetGame().GetPlayer();
572 if( GetFocusedIcon() )
573 {
574 ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
575 if( item && player.CanDropEntity( item ) )
576 {
577 if( item.GetTargetQuantityMax() < item.GetQuantity() )
578 item.SplitIntoStackMaxClient( null, -1 );
579 else
580 player.PhysicalPredictiveDropItem( item );
581 return true;
582 }
583 }
584 return false;
585 }
586
587 override void SetDefaultFocus( bool while_micromanagment_mode = false )
588 {
589 super.SetDefaultFocus(while_micromanagment_mode);
590
591 Unfocus();
592 m_FocusedItemPosition = 0;
594 }
595
596 override void SetLastFocus()
597 {
599 }
600
601 override void Unfocus()
602 {
603 Icon icon = GetFocusedIcon();
604 if ( icon )
605 {
606 icon.SetActive( false );
607 }
608 }
609
610 override void UnfocusAll()
611 {
612 if( m_Icons )
613 {
614 foreach( Icon icon : m_Icons )
615 {
616 icon.SetActive( false );
617 }
618 }
619 m_FocusedItemPosition = 0;
620 }
621
622 override void SetNextActive()
623 {
624 Unfocus();
625 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
626 int max_row = ( m_Icons.Count() - 1) / ROWS_NUMBER_XBOX;
627
628 if ( max_row > focused_row )
629 {
630 m_FocusedItemPosition += ROWS_NUMBER_XBOX;
631 if ( m_FocusedItemPosition >= m_Icons.Count() )
632 {
633 m_FocusedItemPosition = m_Icons.Count() - 1;
634 }
636 }
637 else
638 {
639 SetActive(false);
640 }
641 }
642
643 override void SetPreviousActive( bool force = false )
644 {
645 Unfocus();
646 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
647
648 if ( focused_row > 0 )
649 {
650 m_FocusedItemPosition = m_FocusedItemPosition - ROWS_NUMBER_XBOX;
652 }
653 else
654 {
655 SetActive(false);
656 }
657 }
658
659
660 override void SetNextRightActive()
661 {
662 if ( m_Icons.Count() > 0)
663 {
664 Unfocus();
665 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
666 int row_min = focused_row * ROWS_NUMBER_XBOX;
667 int row_max = row_min + ROWS_NUMBER_XBOX - 1;
668
669 if ( row_max >= m_Icons.Count() )
670 {
671 row_max = m_Icons.Count() - 1;
672 }
673
674 m_FocusedItemPosition++;
675 if( m_FocusedItemPosition > row_max )
676 {
677 m_FocusedItemPosition = row_min;
678 }
679
681 }
682 }
683
684 override void SetNextLeftActive()
685 {
686 if ( m_Icons.Count() > 0)
687 {
688 Unfocus();
689 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
690 int row_min = focused_row * ROWS_NUMBER_XBOX;
691 int row_max = row_min + ROWS_NUMBER_XBOX - 1;
692
693 if ( row_max >= m_Icons.Count() )
694 {
695 row_max = m_Icons.Count() - 1;
696 }
697
698 m_FocusedItemPosition--;
699 if( m_FocusedItemPosition < row_min )
700 {
701 m_FocusedItemPosition = row_max;
702 }
703
705 }
706 }
707
709 {
710 Icon icon = GetFocusedIcon();
711 if( icon )
712 {
713 return EntityAI.Cast( icon.GetObject() );
714 }
715
716 return null;
717 }
718
719 override void SetLastActive()
720 {
721 super.SetLastActive();
722 if( GetFocusedIcon() )
723 {
724 GetFocusedIcon().SetActive( false );
725 }
726 m_FocusedItemPosition = ( ( m_Rows.Count() - 1 ) * ROWS_NUMBER_XBOX );
728 }
729
730 override void SetActive( bool active )
731 {
732 super.SetActive( active );
734 }
735
736 override bool IsItemActive()
737 {
738 if( GetFocusedIcon() )
739 {
740 ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
741 return ( item != null );
742 }
743 return false;
744 }
745
747 {
748 if( GetFocusedIcon() )
749 {
750 ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
751 return ( !IsEmpty() && QuantityConversions.HasItemQuantity( item ) && item.CanBeSplit() );
752 }
753 return false;
754 }
755
756 override bool IsEmpty()
757 {
758 return m_Icons.Count() == 0;
759 }
760
761 int GetRecipeCount( bool recipe_anywhere, ItemBase entity1, ItemBase entity2, PlayerBase player )
762 {
763 PluginRecipesManager recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
764 return recipes_manager.GetValidRecipes( entity1, entity2, null, player );
765 }
766
767 override bool CanCombineAmmo()
768 {
769 if( GetFocusedIcon() )
770 {
772
773 ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
774 ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
775
776 return ( amc.CanPerformActionFromInventory( item_in_hands, entity ) || amc.CanSetActionFromInventory( item_in_hands, entity ) );
777 }
778 return false;
779 }
780
781 override bool TransferItem()
782 {
783 if( GetFocusedIcon() )
784 {
785 EntityAI entity = EntityAI.Cast( GetFocusedIcon().GetObject() );
786 if( entity )
787 {
788 GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, entity );
789 return true;
790 }
791 }
792 return false;
793 }
794
795 override bool SplitItem()
796 {
797 if( GetFocusedIcon() )
798 {
799 ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
800 if( entity )
801 {
802 if( entity.HasQuantity() && entity.CanBeSplit() )
803 {
804 entity.OnRightClick();
805 Icon icon = m_ShowedItemPositions.Get( entity ).param1;
806
807 if ( icon )
808 {
809 icon.SetQuantity();
810 }
811 }
812 }
813 }
814 return false;
815 }
816
817 override bool EquipItem()
818 {
819 if( GetFocusedIcon() )
820 {
821 ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
822 if( entity )
823 {
824 GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, entity );
825 return true;
826 }
827 }
828 return false;
829 }
830
831 override bool SelectItem()
832 {
833 Icon focused_item = GetFocusedIcon();
834 if( focused_item )
835 {
836 ItemBase item = ItemBase.Cast(focused_item.GetObject());
837 if (item && item.IsTakeable())
838 {
839 ItemManager.GetInstance().SetSelectedItem( item, this, null, null );
840 return true;
841 }
842 }
843 return false;
844 }
845
846 override bool Select()
847 {
848 EntityAI focused_item = GetFocusedItem();
850 DayZPlayer player = GetGame().GetPlayer();
851
852
853 if( focused_item != selected_item )
854 {
855 if( selected_item )
856 {
857 if( selected_item.GetInventory().CanRemoveEntity() && m_Entity )
858 {
859 bool can_add = m_Entity.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo());
860 bool in_cargo = !player.GetInventory().HasEntityInInventory( selected_item ) || !m_Entity.GetInventory().HasEntityInCargo( selected_item );
861 if( can_add && in_cargo )
862 {
863 player.PredictiveTakeEntityToTargetCargo( m_Entity, selected_item );
865 if( selected_cont2 )
866 {
867 selected_cont2.SetActive( false );
868 }
869
870 SetActive( true );
871 m_FocusedItemPosition = 0;
872 return true;
873 }
874 else
875 {
877 if( selected_cont )
878 {
879 selected_cont.SetActive( false );
880 }
881
882 SetActive( true );
883 SetDefaultFocus( true );
884 }
885 }
886 }
887 else if ( focused_item && focused_item.GetInventory().CanRemoveEntity() )
888 {
889 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
890 if( item_in_hands )
891 {
892 if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
893 {
894 player.PredictiveSwapEntities( item_in_hands, focused_item );
895 return true;
896 }
897 }
898 else
899 {
900 if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
901 {
902 player.PredictiveTakeEntityToHands( focused_item );
903 return true;
904 }
905 }
906 }
907 }
908 return false;
909 }
910
911 override bool Combine()
912 {
913 if( GetFocusedIcon() )
914 {
915 Icon icon = GetFocusedIcon();
916 if( icon )
917 {
918 EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
919 EntityAI prev_item = EntityAI.Cast( icon.GetObject() );
920 if( item_in_hands && prev_item )
921 {
922 return icon.CombineItems( item_in_hands, prev_item );
923 }
924 }
925 }
926 return false;
927 }
928
929 void ShowFalseCargoHeader(bool show)
930 {
931 m_CargoHeader.Show(show);
932 }
933
935 {
937 m_AlternateFalseHeaderTextWidget = w;
938 if (update)
939 {
941 }
942 }
943}
void Inventory(LayoutHolder parent)
Definition Inventory.c:75
Object GetObject()
protected void GetActionManager()
Icon x
Icon y
FindInventoryLocationType
flags for searching locations in inventory
ScreenWidthType
void InventoryMenu()
void SetLock(bool state)
bool m_IsActive
PlayerBase GetPlayer()
string GetIcon()
string name
class PluginItemDiagnosticEventHandler extends ScriptedWidgetEventHandler m_Entity
PluginBase GetPlugin(typename plugin_type)
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
void SetActive()
Definition TrapBase.c:463
bool CanSetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
bool CanPerformActionFromInventory(ItemBase mainItem, ItemBase targetItem)
proto void GetInventoryItemSize(InventoryItem item, out int width, out int height)
proto native DayZPlayer GetPlayer()
represents base for cargo storage for entities
Definition Cargo.c:7
proto native int GetHeight()
proto bool GetItemSize(int index, out int w, out int h)
proto native int GetItemCount()
proto native EntityAI GetItem(int index)
proto native int GetWidth()
override void SetPreviousActive(bool force=false)
int GetRecipeCount(bool recipe_anywhere, ItemBase entity1, ItemBase entity2, PlayerBase player)
override void UnfocusAll()
void MovedInCargo(EntityAI item)
void UpdateRowVisibility(int count)
Icon InitIcon(Icon icon, EntityAI item, int pos_x, int pos_y)
void UpdateSelection()
void ~CargoContainer()
override float GetFocusedContainerYPos(bool contents=false)
void ShowFalseCargoHeader(bool show)
protected ref SizeToChild m_Resizer1
float GetIconSize()
void SetLock(EntityAI item)
protected int m_CargoIndex
override bool IsItemActive()
override void SetNextActive()
protected Widget m_CargoContainer
override void Refresh()
int GetMaxCargoCapacity()
Icon GetIcon(int index)
void AddedToCargoEx(EntityAI item, bool refresh=true)
override bool SelectItem()
protected CargoBase m_Cargo
override void UpdateInterval()
Icon InitIconEx(Icon icon, EntityAI item, int pos_x, int pos_y, bool refresh=true)
override bool TransferItem()
EntityAI GetEntity()
int GetCargoIndex()
void SetAlternateFalseTextHeaderWidget(TextWidget w)
override bool TransferItemToVicinity()
void AddedToCargo(EntityAI item)
Icon GetFocusedIcon()
Icon GetIcon(EntityAI item)
bool HasItem(EntityAI item)
void CargoContainer(LayoutHolder parent, bool is_attachment=false)
protected ref array< ref CargoContainerRow > m_Rows
protected float m_SpaceSize
override float GetFocusedContainerYScreenPos(bool contents=false)
void SetEntity(EntityAI item, int cargo_index=0, bool immedUpdate=true)
override void SetLastFocus()
protected ref Timer m_ResizeTimer
override void SetActive(bool active)
protected ref map< EntityAI, ref Param3< ref Icon, int, int > > m_ShowedLockPositions
protected ref SizeToChild m_Resizer2
void UpdateSize()
protected Widget m_ItemsContainer
protected ref array< ref Icon > m_Icons
protected bool m_IsAttachment
override void SetNextRightActive()
void UpdateHeaderText()
override Header GetHeader()
override bool CanCombineAmmo()
override bool Combine()
override bool EquipItem()
void RemovedFromCargo(EntityAI item)
override void Unfocus()
override float GetFocusedContainerHeight(bool contents=false)
override bool IsItemWithQuantityActive()
void RefreshImpl()
protected TextWidget m_AlternateFalseHeaderTextWidget
protected TextWidget m_FalseHeaderTextWidget
float GetSpaceSize()
override void SetDefaultFocus(bool while_micromanagment_mode=false)
protected ref map< EntityAI, ref Param3< ref Icon, int, int > > m_ShowedItemPositions
protected const int ROWS_NUMBER_XBOX
override void SetLastActive()
void InitGridHeight()
override bool Select()
override bool IsEmpty()
override void SetNextLeftActive()
override void SetLayoutName()
override EntityAI GetFocusedItem()
void ReleaseLock(EntityAI item)
override bool SplitItem()
protected float m_IconSize
int GetCargoCapacity()
protected Widget m_CargoHeader
script counterpart to engine's class Inventory
Definition Inventory.c:77
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:601
void SetName(string name)
Definition Header.c:33
Definition Icon.c:2
void SetPosX(int x)
Definition Icon.c:1850
void SetSize(int x, int y)
Definition Icon.c:1223
override void SetActive(bool active)
Definition Icon.c:89
Object GetObject()
Definition Icon.c:1420
void SetCargoPos(int x)
Definition Icon.c:1240
void InitEx(EntityAI obj, bool refresh=true)
Definition Icon.c:1659
void SetPosEx(bool refresh=true)
Definition Icon.c:1890
bool CombineItems(EntityAI entity1, EntityAI entity2)
Definition Icon.c:794
void SetQuantity()
Definition Icon.c:1533
void SetPosY(int y)
Definition Icon.c:1855
InventoryLocation.
proto native int GetCol()
returns column of cargo if current type is Cargo / ProxyCargo
proto native int GetRow()
returns row of cargo if current type is Cargo / ProxyCargo
proto native bool GetFlip()
returns flip status of cargo
override bool IsTakeable()
EntityAI GetSelectedItem()
Definition ItemManager.c:82
Container GetSelectedContainer()
Definition ItemManager.c:87
void SetSelectedItem(EntityAI selected_item, Container selected_container, Widget selected_widget, SlotsIcon selected_icon)
static ItemManager GetInstance()
void Remove(LayoutHolder container)
Definition Container.c:981
LayoutHolder Get(int x)
Definition Container.c:1011
Definition EnMath.c:7
static int HasItemQuantity(notnull EntityAI item)
const string CargoContainerWide
const string CargoContainerXbox
const string CargoContainerNarrow
const string CargoContainerMedium
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float Min(float x, float y)
Returns smaller of two given values.
static proto float Ceil(float f)
Returns ceil of value.
proto int ToUpper()
Changes string to uppercase. Returns length.
proto native Widget GetParent()
Get parent of the Effect.
Definition Effect.c:396