4 protected const int ROWS_NUMBER_XBOX = 5;
7 protected int m_CargoIndex = -1;
9 protected int m_FocusedItemPosition = -1;
15 protected float m_IconSize;
16 protected float m_SpaceSize;
18 protected bool m_IsAttachment;
20 protected TextWidget m_AlternateFalseHeaderTextWidget;
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;
27 protected ref SizeToChild m_Resizer2;
28 protected ref
Timer m_ResizeTimer;
30 void CargoContainer(
LayoutHolder parent,
bool is_attachment =
false )
32 m_IsAttachment = is_attachment;
38 m_CargoContainer =
m_RootWidget.FindAnyWidget(
"grid_background" );
39 m_ItemsContainer =
m_RootWidget.FindAnyWidget(
"grid_overlay" );
40 m_CargoHeader =
m_RootWidget.FindAnyWidget(
"grid_container_header_spacer" );
41 #ifndef PLATFORM_CONSOLE
44 m_RootWidget.FindAnyWidget(
"grid_container" ).GetScript( m_Resizer2 );
45 m_CargoHeader.Show( is_attachment );
46 m_FalseHeaderTextWidget =
TextWidget.Cast(m_CargoHeader.FindAnyWidget(
"TextWidget0" ));
48 m_MainWidget = m_CargoContainer;
49 m_FocusedItemPosition = -1;
52 void ~CargoContainer()
56 m_Entity.GetOnItemAddedIntoCargo().Remove( AddedToCargo );
57 m_Entity.GetOnItemRemovedFromCargo().Remove( RemovedFromCargo );
58 m_Entity.GetOnItemMovedInCargo().Remove( MovedInCargo );
60 m_Entity.GetOnReleaseLock().Remove( ReleaseLock );
64 int GetCargoIndex() {
return m_CargoIndex; }
66 void AddedToCargoEx(
EntityAI item,
bool refresh =
true )
69 item.GetInventory().GetCurrentInventoryLocation( il );
73 if ( m_ShowedItemPositions.Contains( item ) )
76 InitIconEx( item_pos.param1, item,
x,
y, refresh );
82 ref
Icon icon =
new Icon(
this,
false );
83 m_Icons.Insert( icon );
84 InitIconEx( icon, item,
x,
y, refresh );
91 #ifdef PLATFORM_CONSOLE
92 for (
int i = 0; i < m_Cargo.GetItemCount(); i++ )
94 EntityAI item2 = m_Cargo.GetItem( i );
98 data.param1.SetCargoPos( i );
103 m_FocusedItemPosition =
Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
112 AddedToCargoEx( item );
115 void RemovedFromCargo(
EntityAI item )
120 m_Icons.RemoveItem( data.param1 );
121 m_ShowedItemPositions.Remove( item );
126 #ifdef PLATFORM_CONSOLE
127 for(
int i = 0; i < m_Cargo.GetItemCount(); i++ )
129 EntityAI item2 = m_Cargo.GetItem( i );
130 data = m_ShowedItemPositions.Get( item2 );
131 if( data && data.param1 )
133 data.param1.SetCargoPos( i );
134 data.param1.SetPos();
138 m_FocusedItemPosition =
Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
147 item.GetInventory().GetCurrentInventoryLocation( il );
150 #ifdef PLATFORM_CONSOLE
151 int y = il.GetRow() - 1;
155 if( m_ShowedItemPositions.Contains( item ) )
160 if( data.param2 !=
x || data.param3 !=
y )
164 #ifdef PLATFORM_CONSOLE
165 data.param1.SetCargoPos( data.param3 );
167 #ifdef PLATFORM_WINDOWS
168 data.param1.SetPosX( data.param2 );
169 data.param1.SetPosY( data.param3 );
172 data.param1.UpdateInterval();
180 #ifndef PLATFORM_CONSOLE
184 int index =
GetGame().GetPlayer().GetHumanInventory().FindUserReservedLocationIndex( item );
187 GetGame().GetPlayer().GetHumanInventory().GetUserReservedLocation( index, il );
189 ref
Icon icon =
new Icon(
this,
false );
190 m_Icons.Insert( icon );
191 icon.InitLock(
m_Entity, item, il.GetCol(), il.GetRow(), il.GetFlip() );
193 item.GetOnReleaseLock().Insert( ReleaseLock );
201 #ifndef PLATFORM_CONSOLE
202 if( m_ShowedLockPositions.Contains( item ) )
204 Icon ic = m_ShowedLockPositions.Get( item ).param1;
205 m_Icons.RemoveItem( ic );
206 m_ShowedLockPositions.Remove( item );
207 item.GetOnReleaseLock().Remove( ReleaseLock );
214 #ifdef PLATFORM_CONSOLE
239 void SetEntity(
EntityAI item,
int cargo_index = 0,
bool immedUpdate =
true )
244 m_Cargo = item.GetInventory().GetCargoFromIndex(cargo_index);
245 m_CargoIndex = cargo_index;
247 m_Entity.GetOnItemAddedIntoCargo().Insert( AddedToCargo );
248 m_Entity.GetOnItemRemovedFromCargo().Insert( RemovedFromCargo );
249 m_Entity.GetOnItemMovedInCargo().Insert( MovedInCargo );
251 m_Entity.GetOnReleaseLock().Insert( ReleaseLock );
257 m_MainWidget = m_ItemsContainer;
262 int prev_count = m_ShowedItemPositions.Count();
265 for ( i = 0; i < m_Cargo.GetItemCount(); i++ )
267 EntityAI cargo_item = m_Cargo.GetItem( i );
270 AddedToCargoEx( cargo_item, immedUpdate );
274 #ifdef PLATFORM_CONSOLE
287 void UpdateHeaderText()
293 if (
m_Entity.CanDisplayCargo() &&
m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex) )
295 name =
name +
" (" + GetCargoCapacity().ToString() +
"/" + GetMaxCargoCapacity() +
")";
296 if ( m_IsAttachment && m_CargoHeader )
298 m_FalseHeaderTextWidget.SetText(
name);
300 m_FalseHeaderTextWidget.Update();
301 m_FalseHeaderTextWidget.GetScreenSize(
x,
y );
302 m_CargoHeader.FindAnyWidget(
"grid_container_header" ).SetSize( 1,
y +
InventoryMenu.GetHeightMultiplied( 10 ) );
303 m_CargoHeader.Update();
305 if (m_AlternateFalseHeaderTextWidget)
307 m_AlternateFalseHeaderTextWidget.SetText(
name);
317 void InitGridHeight()
320 m_ShowedItemPositions.Clear();
324 #ifdef PLATFORM_CONSOLE
325 int cargo_height = 1;
327 int cargo_height =
m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetHeight();
330 for (
int j = 0; j < cargo_height; j++ )
337 #ifdef PLATFORM_WINDOWS
338 #ifndef PLATFORM_CONSOLE
339 row.SetWidth(
m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetWidth(),
false );
343 row.GetRootWidget().SetSort( j,
false );
344 m_Rows.Insert( row );
348 row.GetRootWidget().FindAnyWidget(
"Icon0" ).GetScreenSize(
y, m_IconSize );
349 #ifdef PLATFORM_WINDOWS
350 #ifndef PLATFORM_CONSOLE
351 row.GetRootWidget().FindAnyWidget(
"Spacer0" ).GetScreenSize( m_SpaceSize,
y );
355 m_Resizer2.ResizeParentToChild();
356 #ifndef PLATFORM_CONSOLE
357 m_Resizer1.ResizeParentToChild();
363 #ifndef PLATFORM_CONSOLE
364 m_Resizer1.ResizeParentToChild();
366 m_Resizer2.ResizeParentToChild();
380 int GetCargoCapacity()
382 #ifdef PLATFORM_CONSOLE
383 #ifndef PLATFORM_WINDOWS
384 return CargoList.Cast( m_Cargo ).GetTotalWeight(
null );
388 for (
int i = 0; i < m_Cargo.GetItemCount(); ++i )
391 m_Cargo.GetItemSize( i,
x,
y );
397 int GetMaxCargoCapacity()
399 #ifdef PLATFORM_CONSOLE
400 #ifndef PLATFORM_WINDOWS
401 return CargoList.Cast( m_Cargo ).GetMaxWeight();
404 return m_Cargo.GetWidth() * m_Cargo.GetHeight();
409 if ( item && m_ShowedItemPositions.Contains( item ) )
419 if ( m_Cargo ==
null )
424 if ( index >= 0 && m_Cargo.GetItemCount() > index )
425 return GetIcon( m_Cargo.GetItem( index ) );
429 Icon GetFocusedIcon()
431 return GetIcon( m_FocusedItemPosition );
434 override float GetFocusedContainerHeight(
bool contents =
false )
437 if( contents && GetFocusedIcon() )
438 GetFocusedIcon().GetRootWidget().GetScreenSize(
x,
y );
440 GetRootWidget().GetScreenSize(
x,
y );
444 override float GetFocusedContainerYPos(
bool contents =
false )
447 if( contents && GetFocusedIcon() )
448 GetFocusedIcon().GetRootWidget().GetPos(
x,
y );
450 GetRootWidget().GetPos(
x,
y );
454 override float GetFocusedContainerYScreenPos(
bool contents =
false )
457 if( contents && GetFocusedIcon() )
458 GetFocusedIcon().GetRootWidget().GetScreenPos(
x,
y );
460 GetRootWidget().GetScreenPos(
x,
y );
464 void UpdateSelection()
468 if( m_FocusedItemPosition >= m_Icons.Count() )
469 m_FocusedItemPosition = m_Icons.Count() - 1;
471 if( icon && !icon.IsActive() )
473 icon.SetActive(
true );
474 Inventory.GetInstance().UpdateConsoleToolbar();
479 void UpdateRowVisibility(
int count )
482 int rows =
Math.Max( 1,
Math.Ceil( (count + 1) / ROWS_NUMBER_XBOX ) );
483 int diff = rows - m_Rows.Count();
487 for( i = m_Rows.Count() - 1; i >= rows; i-- )
494 m_MainWidget = m_CargoContainer;
495 for( i = m_Rows.Count(); i < rows; i++ )
501 row.GetRootWidget().SetSort( i );
502 m_Rows.Insert( row );
504 m_MainWidget = m_ItemsContainer;
507 m_Resizer2.ResizeParentToChild();
508 #ifndef PLATFORM_CONSOLE
509 m_Resizer1.ResizeParentToChild();
515 #ifdef PLATFORM_CONSOLE
516 if ( !m_ResizeTimer )
517 m_ResizeTimer =
new Timer();
518 if ( m_ResizeTimer.IsRunning() )
519 m_ResizeTimer.Stop();
520 m_ResizeTimer.Run( 0.05,
this,
"RefreshImpl" );
526 UpdateRowVisibility( m_ShowedItemPositions.Count() );
536 data.param1.UpdateInterval();
541 Icon InitIconEx(
Icon icon,
EntityAI item,
int pos_x,
int pos_y,
bool refresh =
true )
543 #ifdef PLATFORM_CONSOLE
544 icon.SetSize( 1, 1 );
545 #ifdef PLATFORM_WINDOWS
546 pos_y = pos_y * 5 + pos_x;
548 icon.SetCargoPos( pos_y );
549 icon.SetPosY( pos_y );
550 icon.SetPosEx( refresh );
555 if ( item.GetInventory().GetFlipCargo() )
556 icon.SetSize( size_y, size_x );
558 icon.SetSize( size_x, size_y );
560 icon.SetPosX( pos_x );
561 icon.SetPosY( pos_y );
562 icon.SetPosEx( refresh );
564 icon.InitEx( item, refresh );
570 return InitIconEx( icon, item, pos_x, pos_y );
575 return m_ShowedItemPositions.Contains( item );
578 override bool TransferItemToVicinity()
582 Man player =
GetGame().GetPlayer();
583 if( GetFocusedIcon() )
586 if( item && player.CanDropEntity( item ) )
588 if( item.GetTargetQuantityMax() < item.GetQuantity() )
589 item.SplitIntoStackMaxClient(
null, -1 );
591 player.PhysicalPredictiveDropItem( item );
599 override void SetDefaultFocus(
bool while_micromanagment_mode =
false )
601 super.SetDefaultFocus(while_micromanagment_mode);
604 m_FocusedItemPosition = 0;
608 override void SetLastFocus()
613 override void Unfocus()
615 Icon icon = GetFocusedIcon();
618 icon.SetActive(
false );
622 override void UnfocusAll()
626 foreach(
Icon icon : m_Icons )
628 icon.SetActive(
false );
631 m_FocusedItemPosition = 0;
634 override void SetNextActive()
637 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
638 int max_row = ( m_Icons.Count() - 1) / ROWS_NUMBER_XBOX;
640 if ( max_row > focused_row )
642 m_FocusedItemPosition += ROWS_NUMBER_XBOX;
643 if ( m_FocusedItemPosition >= m_Icons.Count() )
645 m_FocusedItemPosition = m_Icons.Count() - 1;
655 override void SetPreviousActive(
bool force =
false )
658 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
660 if ( focused_row > 0 )
662 m_FocusedItemPosition = m_FocusedItemPosition - ROWS_NUMBER_XBOX;
672 override void SetNextRightActive()
674 if ( m_Icons.Count() > 0)
677 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
678 int row_min = focused_row * ROWS_NUMBER_XBOX;
679 int row_max = row_min + ROWS_NUMBER_XBOX - 1;
681 if ( row_max >= m_Icons.Count() )
683 row_max = m_Icons.Count() - 1;
686 m_FocusedItemPosition++;
687 if( m_FocusedItemPosition > row_max )
689 m_FocusedItemPosition = row_min;
696 override void SetNextLeftActive()
698 if ( m_Icons.Count() > 0)
701 int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
702 int row_min = focused_row * ROWS_NUMBER_XBOX;
703 int row_max = row_min + ROWS_NUMBER_XBOX - 1;
705 if ( row_max >= m_Icons.Count() )
707 row_max = m_Icons.Count() - 1;
710 m_FocusedItemPosition--;
711 if( m_FocusedItemPosition < row_min )
713 m_FocusedItemPosition = row_max;
722 Icon icon = GetFocusedIcon();
725 return EntityAI.Cast( icon.GetObject() );
731 override void SetLastActive()
733 super.SetLastActive();
734 if( GetFocusedIcon() )
736 GetFocusedIcon().SetActive(
false );
738 m_FocusedItemPosition = ( ( m_Rows.Count() - 1 ) * ROWS_NUMBER_XBOX );
744 super.SetActive( active );
748 override bool IsItemActive()
750 if( GetFocusedIcon() )
753 return ( item !=
null );
758 override bool IsItemWithQuantityActive()
760 if( GetFocusedIcon() )
770 return m_Icons.Count() == 0;
775 PluginRecipesManager recipes_manager = PluginRecipesManager.Cast(
GetPlugin( PluginRecipesManager ) );
776 return recipes_manager.GetValidRecipes( entity1, entity2,
null, player );
779 override bool CanCombineAmmo()
781 if( GetFocusedIcon() )
788 return ( amc.CanPerformActionFromInventory( item_in_hands, entity ) || amc.CanSetActionFromInventory( item_in_hands, entity ) );
793 override bool TransferItem()
795 if (CanTakeToInventory())
797 if (GetFocusedIcon())
814 if ( GetFocusedIcon() )
819 if ( entity.HasQuantity() && entity.CanBeSplit() )
821 entity.OnRightClick();
822 Icon icon = m_ShowedItemPositions.Get( entity ).param1;
835 override bool EquipItem()
839 if (GetFocusedIcon())
852 override bool SelectItem()
854 Icon focused_item = GetFocusedIcon();
858 if (item && item.IsTakeable() && item.CanPutIntoHands(
null))
860 ItemManager.GetInstance().SetSelectedItemEx(item,
this, focused_item);
867 override bool Select()
869 EntityAI focused_item = GetFocusedItem();
874 if( focused_item != selected_item )
878 if( selected_item.GetInventory().CanRemoveEntity() &&
m_Entity )
880 bool can_add =
m_Entity.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo());
881 bool in_cargo = !player.GetInventory().HasEntityInInventory( selected_item ) || !
m_Entity.GetInventory().HasEntityInCargo( selected_item );
882 if( can_add && in_cargo )
884 player.PredictiveTakeEntityToTargetCargo(
m_Entity, selected_item );
888 selected_cont2.SetActive(
false );
892 m_FocusedItemPosition = 0;
900 selected_cont.SetActive(
false );
904 SetDefaultFocus(
true );
908 else if ( focused_item && focused_item.GetInventory().CanRemoveEntity() )
910 EntityAI item_in_hands =
GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
913 if(
GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
915 player.PredictiveSwapEntities( item_in_hands, focused_item );
921 if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
923 player.PredictiveTakeEntityToHands( focused_item );
932 override bool Combine()
936 if (GetFocusedIcon())
938 Icon icon = GetFocusedIcon();
941 EntityAI item_in_hands =
GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
943 if( item_in_hands && prev_item )
945 return icon.CombineItems( item_in_hands, prev_item );
953 void ShowFalseCargoHeader(
bool show)
955 m_CargoHeader.Show(show);
958 void SetAlternateFalseTextHeaderWidget(
TextWidget w)
960 bool update = !m_AlternateFalseHeaderTextWidget;
961 m_AlternateFalseHeaderTextWidget = w;