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