123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998 |
- //cargo grid wrapper
- class CargoContainer extends Container
- {
- protected const int ROWS_NUMBER_XBOX = 5;
-
- protected CargoBase m_Cargo;
- protected int m_CargoIndex = -1;
-
- protected int m_FocusedItemPosition = -1;
- protected ref array<ref CargoContainerRow> m_Rows;
- protected ref array<ref Icon> m_Icons;
- protected ref map<EntityAI, ref Param3<ref Icon, int, int>> m_ShowedItemPositions;
- protected ref map<EntityAI, ref Param3<ref Icon, int, int>> m_ShowedLockPositions;
-
- protected float m_IconSize;
- protected float m_SpaceSize;
-
- protected bool m_IsAttachment;
- protected TextWidget m_FalseHeaderTextWidget;
- protected TextWidget m_AlternateFalseHeaderTextWidget; //to be set and updated along with the main one
- protected Widget m_CargoHeader;
- protected Widget m_CargoContainer;
- protected Widget m_ItemsContainer;
- #ifndef PLATFORM_CONSOLE
- protected ref SizeToChild m_Resizer1;
- #endif
- protected ref SizeToChild m_Resizer2;
- protected ref Timer m_ResizeTimer;
-
- protected int m_AttachmentSlotID = -1;
-
- void CargoContainer( LayoutHolder parent, bool is_attachment = false )
- {
- m_IsAttachment = is_attachment;
- m_Rows = new array<ref CargoContainerRow>;
- m_Icons = new array<ref Icon>;
- m_ShowedItemPositions = new map<EntityAI, ref Param3<ref Icon, int, int>>;
- m_ShowedLockPositions = new map<EntityAI, ref Param3<ref Icon, int, int>>;
-
- m_CargoContainer = m_RootWidget.FindAnyWidget( "grid_background" );
- m_ItemsContainer = m_RootWidget.FindAnyWidget( "grid_overlay" );
- m_CargoHeader = m_RootWidget.FindAnyWidget( "grid_container_header_spacer" );
- #ifndef PLATFORM_CONSOLE
- m_RootWidget.GetScript( m_Resizer1 );
- #endif
- m_RootWidget.FindAnyWidget( "grid_container" ).GetScript( m_Resizer2 );
- m_CargoHeader.Show( is_attachment );
- m_FalseHeaderTextWidget = TextWidget.Cast(m_CargoHeader.FindAnyWidget( "TextWidget0" ));
-
- m_MainWidget = m_CargoContainer;
- m_FocusedItemPosition = -1;
- }
-
- void ~CargoContainer()
- {
- if ( m_Entity )
- {
- m_Entity.GetOnItemAddedIntoCargo().Remove( AddedToCargo );
- m_Entity.GetOnItemRemovedFromCargo().Remove( RemovedFromCargo );
- m_Entity.GetOnItemMovedInCargo().Remove( MovedInCargo );
- m_Entity.GetOnSetLock().Remove( SetLock );
- m_Entity.GetOnReleaseLock().Remove( ReleaseLock );
- }
- }
-
- int GetCargoIndex() { return m_CargoIndex; }
-
- void AddedToCargoEx( EntityAI item, bool refresh = true )
- {
- InventoryLocation il = new InventoryLocation;
- item.GetInventory().GetCurrentInventoryLocation( il );
- int x = il.GetCol();
- int y = il.GetRow();
-
- if ( m_ShowedItemPositions.Contains( item ) )
- {
- Param3<ref Icon, int, int> item_pos = m_ShowedItemPositions.Get( item );
- InitIconEx( item_pos.param1, item, x, y, refresh );
- item_pos.param2 = x;
- item_pos.param3 = y;
- }
- else
- {
- ref Icon icon = new Icon( this, false );
- m_Icons.Insert( icon );
- InitIconEx( icon, item, x, y, refresh );
- m_ShowedItemPositions.Insert( item, new Param3<ref Icon, int, int>( icon, x, y ) );
- }
-
- if (refresh)
- UpdateHeaderText();
-
- #ifdef PLATFORM_CONSOLE
- for ( int i = 0; i < m_Cargo.GetItemCount(); i++ )
- {
- EntityAI item2 = m_Cargo.GetItem( i );
- Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item2 );
- if ( data )
- {
- data.param1.SetCargoPos( i );
- data.param1.SetPos();
- }
- }
-
- m_FocusedItemPosition = Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
-
- if (refresh)
- Refresh();
- #endif
- }
-
- void AddedToCargo( EntityAI item )
- {
- AddedToCargoEx( item );
- }
-
- void RemovedFromCargo( EntityAI item )
- {
- Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
- if( data )
- {
- m_Icons.RemoveItem( data.param1 );
- m_ShowedItemPositions.Remove( item );
- }
-
- UpdateHeaderText();
-
- #ifdef PLATFORM_CONSOLE
- for( int i = 0; i < m_Cargo.GetItemCount(); i++ )
- {
- EntityAI item2 = m_Cargo.GetItem( i );
- data = m_ShowedItemPositions.Get( item2 );
- if( data && data.param1 )
- {
- data.param1.SetCargoPos( i );
- data.param1.SetPos();
- }
- }
-
- m_FocusedItemPosition = Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
-
- Refresh();
- #endif
- }
-
- void MovedInCargo( EntityAI item )
- {
- InventoryLocation il = new InventoryLocation;
- item.GetInventory().GetCurrentInventoryLocation( il );
-
- int x = il.GetCol();
- #ifdef PLATFORM_CONSOLE
- int y = il.GetRow() - 1;
- #else
- int y = il.GetRow();
- #endif
- if( m_ShowedItemPositions.Contains( item ) )
- {
- ref Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
- if( data.param1 )
- {
- if( data.param2 != x || data.param3 != y )
- {
- data.param2 = x;
- data.param3 = y;
- #ifdef PLATFORM_CONSOLE
- data.param1.SetCargoPos( data.param3 );
- #endif
- #ifdef PLATFORM_WINDOWS
- data.param1.SetPosX( data.param2 );
- data.param1.SetPosY( data.param3 );
- #endif
- }
- data.param1.UpdateInterval();
- }
- }
- UpdateSelection();
- }
-
- void SetLock( EntityAI item )
- {
- #ifndef PLATFORM_CONSOLE
- if( GetGame().GetPlayer() )
- {
- InventoryLocation il = new InventoryLocation;
- int index = GetGame().GetPlayer().GetHumanInventory().FindUserReservedLocationIndex( item );
- if( index >= 0 )
- {
- GetGame().GetPlayer().GetHumanInventory().GetUserReservedLocation( index, il );
-
- ref Icon icon = new Icon( this, false );
- m_Icons.Insert( icon );
- icon.InitLock( m_Entity, item, il.GetCol(), il.GetRow(), il.GetFlip() );
- m_ShowedLockPositions.Insert( item, new Param3<ref Icon, int, int>( icon, 1, 1 ) );
- item.GetOnReleaseLock().Insert( ReleaseLock );
- }
- }
- #endif
- }
-
- void ReleaseLock( EntityAI item )
- {
- #ifndef PLATFORM_CONSOLE
- if( m_ShowedLockPositions.Contains( item ) )
- {
- Icon ic = m_ShowedLockPositions.Get( item ).param1;
- m_Icons.RemoveItem( ic );
- m_ShowedLockPositions.Remove( item );
- item.GetOnReleaseLock().Remove( ReleaseLock );
- }
- #endif
- }
-
- override void SetLayoutName()
- {
- #ifdef PLATFORM_CONSOLE
- m_LayoutName = WidgetLayoutName.CargoContainerXbox;
- #else
- switch( InventoryMenu.GetWidthType() )
- {
- case ScreenWidthType.NARROW:
- {
- m_LayoutName = WidgetLayoutName.CargoContainerNarrow;
- break;
- }
- case ScreenWidthType.MEDIUM:
- {
- m_LayoutName = WidgetLayoutName.CargoContainerMedium;
- break;
- }
- case ScreenWidthType.WIDE:
- {
- m_LayoutName = WidgetLayoutName.CargoContainerWide;
- break;
- }
- }
- #endif
-
- }
-
- void SetEntity( EntityAI item, int cargo_index = 0, bool immedUpdate = true )
- {
- if ( item )
- {
- m_Entity = item;
- m_Cargo = item.GetInventory().GetCargoFromIndex(cargo_index);
- m_CargoIndex = cargo_index;
-
- m_Entity.GetOnItemAddedIntoCargo().Insert( AddedToCargo );
- m_Entity.GetOnItemRemovedFromCargo().Insert( RemovedFromCargo );
- m_Entity.GetOnItemMovedInCargo().Insert( MovedInCargo );
- m_Entity.GetOnSetLock().Insert( SetLock );
- m_Entity.GetOnReleaseLock().Insert( ReleaseLock );
-
- if (immedUpdate)
- UpdateHeaderText();
- InitGridHeight();
- m_MainWidget = m_ItemsContainer;
-
- if ( m_Cargo )
- {
- int i;
- int prev_count = m_ShowedItemPositions.Count();
-
- //START - Add new item Icons
- for ( i = 0; i < m_Cargo.GetItemCount(); i++ )
- {
- EntityAI cargo_item = m_Cargo.GetItem( i );
- if ( cargo_item )
- {
- AddedToCargoEx( cargo_item, immedUpdate );
- }
- }
-
- #ifdef PLATFORM_CONSOLE
- if (immedUpdate)
- Refresh();
- #endif
- }
- }
- }
-
- EntityAI GetEntity()
- {
- return m_Entity;
- }
-
- void UpdateHeaderText()
- {
- Widget header;
- string name = m_Entity.GetDisplayName();
- name.ToUpper();
-
- if ( m_Entity.CanDisplayCargo() && m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex) )
- {
- name = name + " (" + GetCargoCapacity().ToString() + "/" + GetMaxCargoCapacity() + ")";
- if ( m_IsAttachment && m_CargoHeader )
- {
- m_FalseHeaderTextWidget.SetText(name);
- float x, y;
- m_FalseHeaderTextWidget.Update();
- m_FalseHeaderTextWidget.GetScreenSize( x, y );
- m_CargoHeader.FindAnyWidget( "grid_container_header" ).SetSize( 1, y + InventoryMenu.GetHeightMultiplied( 10 ) );
- m_CargoHeader.Update();
-
- if (m_AlternateFalseHeaderTextWidget)
- {
- m_AlternateFalseHeaderTextWidget.SetText(name);
- }
- return;
- }
- }
-
- if ( Container.Cast( GetParent() ) && Container.Cast( GetParent() ).GetHeader() )
- Container.Cast( GetParent() ).GetHeader().SetName(name);
- }
-
- void InitGridHeight()
- {
- m_Rows.Clear();
- m_ShowedItemPositions.Clear();
-
- ref CargoContainerRow row;
-
- #ifdef PLATFORM_CONSOLE
- int cargo_height = 1;
- #else
- int cargo_height = m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetHeight();
- #endif
-
- for ( int j = 0; j < cargo_height; j++ )
- {
- row = new CargoContainerRow( this );
-
- row.SetNumber( j );
- row.SetEntity( m_Entity );
-
- #ifdef PLATFORM_WINDOWS
- #ifndef PLATFORM_CONSOLE
- row.SetWidth( m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetWidth(), false );
- #endif
- #endif
-
- row.GetRootWidget().SetSort( j, false );
- m_Rows.Insert( row );
- }
-
- float y;
- row.GetRootWidget().FindAnyWidget( "Icon0" ).GetScreenSize( y, m_IconSize );
- #ifdef PLATFORM_WINDOWS
- #ifndef PLATFORM_CONSOLE
- row.GetRootWidget().FindAnyWidget( "Spacer0" ).GetScreenSize( m_SpaceSize, y );
- #endif
- #endif
-
- m_Resizer2.ResizeParentToChild();
- #ifndef PLATFORM_CONSOLE
- m_Resizer1.ResizeParentToChild();
- #endif
- }
-
- void UpdateSize()
- {
- #ifndef PLATFORM_CONSOLE
- m_Resizer1.ResizeParentToChild();
- #else
- m_Resizer2.ResizeParentToChild();
- #endif
- }
-
- float GetIconSize()
- {
- return m_IconSize;
- }
-
- float GetSpaceSize()
- {
- return m_SpaceSize;
- }
-
- int GetCargoCapacity()
- {
- #ifdef PLATFORM_CONSOLE
- #ifndef PLATFORM_WINDOWS
- return CargoList.Cast( m_Cargo ).GetTotalWeight( null );
- #endif
- #endif
- int total_size = 0;
- for ( int i = 0; i < m_Cargo.GetItemCount(); ++i )
- {
- int x, y;
- m_Cargo.GetItemSize( i, x, y );
- total_size += x * y;
- }
- return total_size;
- }
-
- int GetMaxCargoCapacity()
- {
- #ifdef PLATFORM_CONSOLE
- #ifndef PLATFORM_WINDOWS
- return CargoList.Cast( m_Cargo ).GetMaxWeight();
- #endif
- #endif
- return m_Cargo.GetWidth() * m_Cargo.GetHeight();
- }
-
- Icon GetIcon( EntityAI item )
- {
- if ( item && m_ShowedItemPositions.Contains( item ) )
- {
- Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
- return data.param1;
- }
- return null;
- }
-
- Icon GetIcon( int index )
- {
- if ( m_Cargo == null )
- {
- return null;
- }
- if ( index >= 0 && m_Cargo.GetItemCount() > index )
- return GetIcon( m_Cargo.GetItem( index ) );
- return null;
- }
-
- Icon GetFocusedIcon()
- {
- return GetIcon( m_FocusedItemPosition );
- }
-
- override float GetFocusedContainerHeight( bool contents = false )
- {
- float x, y;
- if( contents && GetFocusedIcon() )
- GetFocusedIcon().GetRootWidget().GetScreenSize( x, y );
- else
- GetRootWidget().GetScreenSize( x, y );
- return y;
- }
-
- override float GetFocusedContainerYPos( bool contents = false )
- {
- float x, y;
- if( contents && GetFocusedIcon() )
- GetFocusedIcon().GetRootWidget().GetPos( x, y );
- else
- GetRootWidget().GetPos( x, y );
- return y;
- }
-
- override float GetFocusedContainerYScreenPos( bool contents = false )
- {
- float x, y;
- if( contents && GetFocusedIcon() )
- GetFocusedIcon().GetRootWidget().GetScreenPos( x, y );
- else
- GetRootWidget().GetScreenPos( x, y );
- return y;
- }
-
- void UpdateSelection()
- {
- if( m_IsActive )
- {
- if( m_FocusedItemPosition >= m_Icons.Count() )
- m_FocusedItemPosition = m_Icons.Count() - 1;
- Icon icon = GetIcon( m_FocusedItemPosition );
- if( icon && !icon.IsActive() )
- {
- icon.SetActive( true );
- Inventory.GetInstance().UpdateConsoleToolbar();
- }
- }
- }
-
- void UpdateRowVisibility( int count )
- {
- int i;
- int rows = Math.Max( 1, Math.Ceil( (count + 1) / ROWS_NUMBER_XBOX ) );
- int diff = rows - m_Rows.Count();
-
- if( diff < 0 )
- {
- for( i = m_Rows.Count() - 1; i >= rows; i-- )
- {
- m_Rows.Remove( i );
- }
- }
- else if( diff > 0 )
- {
- m_MainWidget = m_CargoContainer;
- for( i = m_Rows.Count(); i < rows; i++ )
- {
- ref CargoContainerRow row = new CargoContainerRow( this );
-
- row.SetNumber( i );
- row.SetEntity( m_Entity );
- row.GetRootWidget().SetSort( i );
- m_Rows.Insert( row );
- }
- m_MainWidget = m_ItemsContainer;
- }
-
- m_Resizer2.ResizeParentToChild();
- #ifndef PLATFORM_CONSOLE
- m_Resizer1.ResizeParentToChild();
- #endif
- }
-
- override void Refresh()
- {
- #ifdef PLATFORM_CONSOLE
- if ( !m_ResizeTimer )
- m_ResizeTimer = new Timer();
- if ( m_ResizeTimer.IsRunning() )
- m_ResizeTimer.Stop();
- m_ResizeTimer.Run( 0.05, this, "RefreshImpl" );
- #endif
- }
-
- void RefreshImpl()
- {
- UpdateRowVisibility( m_ShowedItemPositions.Count() );
- UpdateSelection();
- }
-
- override void UpdateInterval()
- {
- foreach( Param3<ref Icon, int, int> data : m_ShowedItemPositions )
- {
- if( data.param1 )
- {
- data.param1.UpdateInterval();
- }
- }
- }
- Icon InitIconEx( Icon icon, EntityAI item, int pos_x, int pos_y, bool refresh = true )
- {
- #ifdef PLATFORM_CONSOLE
- icon.SetSize( 1, 1 );
- #ifdef PLATFORM_WINDOWS
- pos_y = pos_y * 5 + pos_x;
- #endif
- icon.SetCargoPos( pos_y );
- icon.SetPosY( pos_y );
- icon.SetPosEx( refresh );
- #else
- int size_x, size_y;
- GetGame().GetInventoryItemSize( InventoryItem.Cast( item ), size_x, size_y );
-
- if ( item.GetInventory().GetFlipCargo() )
- icon.SetSize( size_y, size_x );
- else
- icon.SetSize( size_x, size_y );
-
- icon.SetPosX( pos_x );
- icon.SetPosY( pos_y );
- icon.SetPosEx( refresh );
- #endif
- icon.InitEx( item, refresh );
- return icon;
- }
-
- Icon InitIcon( Icon icon, EntityAI item, int pos_x, int pos_y )
- {
- return InitIconEx( icon, item, pos_x, pos_y );
- }
-
- bool HasItem( EntityAI item )
- {
- return m_ShowedItemPositions.Contains( item );
- }
-
- override bool TransferItemToVicinity()
- {
- if (CanDrop())
- {
- Man player = GetGame().GetPlayer();
- if( GetFocusedIcon() )
- {
- ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
- if( item && player.CanDropEntity( item ) )
- {
- if( item.GetTargetQuantityMax() < item.GetQuantity() )
- item.SplitIntoStackMaxClient( null, -1 );
- else
- player.PhysicalPredictiveDropItem( item );
- return true;
- }
- }
- }
- return false;
- }
-
- override void SetDefaultFocus( bool while_micromanagment_mode = false )
- {
- super.SetDefaultFocus(while_micromanagment_mode);
-
- Unfocus();
- m_FocusedItemPosition = 0;
- UpdateSelection();
- }
-
- override void SetLastFocus()
- {
- SetDefaultFocus();
- }
-
- override void Unfocus()
- {
- Icon icon = GetFocusedIcon();
- if ( icon )
- {
- icon.SetActive( false );
- }
- }
-
- override void UnfocusAll()
- {
- if( m_Icons )
- {
- foreach( Icon icon : m_Icons )
- {
- icon.SetActive( false );
- }
- }
- m_FocusedItemPosition = 0;
- }
-
- override void SetNextActive()
- {
- Unfocus();
- int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
- int max_row = ( m_Icons.Count() - 1) / ROWS_NUMBER_XBOX;
-
- if ( max_row > focused_row )
- {
- m_FocusedItemPosition += ROWS_NUMBER_XBOX;
- if ( m_FocusedItemPosition >= m_Icons.Count() )
- {
- m_FocusedItemPosition = m_Icons.Count() - 1;
- }
- UpdateSelection();
- }
- else
- {
- SetActive(false);
- }
- }
-
- override void SetPreviousActive( bool force = false )
- {
- Unfocus();
- int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
-
- if ( focused_row > 0 )
- {
- m_FocusedItemPosition = m_FocusedItemPosition - ROWS_NUMBER_XBOX;
- UpdateSelection();
- }
- else
- {
- SetActive(false);
- }
- }
-
- override void SetNextRightActive()
- {
- if ( m_Icons.Count() > 0)
- {
- Unfocus();
- int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
- int row_min = focused_row * ROWS_NUMBER_XBOX;
- int row_max = row_min + ROWS_NUMBER_XBOX - 1;
-
- if ( row_max >= m_Icons.Count() )
- {
- row_max = m_Icons.Count() - 1;
- }
-
- m_FocusedItemPosition++;
- if( m_FocusedItemPosition > row_max )
- {
- m_FocusedItemPosition = row_min;
- }
-
- UpdateSelection();
- }
- }
-
- override void SetNextLeftActive()
- {
- if ( m_Icons.Count() > 0)
- {
- Unfocus();
- int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
- int row_min = focused_row * ROWS_NUMBER_XBOX;
- int row_max = row_min + ROWS_NUMBER_XBOX - 1;
-
- if ( row_max >= m_Icons.Count() )
- {
- row_max = m_Icons.Count() - 1;
- }
-
- m_FocusedItemPosition--;
- if( m_FocusedItemPosition < row_min )
- {
- m_FocusedItemPosition = row_max;
- }
-
- UpdateSelection();
- }
- }
-
- override EntityAI GetFocusedItem()
- {
- Icon icon = GetFocusedIcon();
- if( icon )
- {
- return EntityAI.Cast( icon.GetObject() );
- }
-
- return null;
- }
-
- override void SetLastActive()
- {
- super.SetLastActive();
- if( GetFocusedIcon() )
- {
- GetFocusedIcon().SetActive( false );
- }
-
- int focusedIconCount = m_Icons.Count();
- int columCount = m_Icons.Count() / ROWS_NUMBER_XBOX;
- if (focusedIconCount > ROWS_NUMBER_XBOX)
- {
- int iconMax = columCount * ROWS_NUMBER_XBOX;
- int diff = focusedIconCount - iconMax;
- if (diff == 0)
- diff = ROWS_NUMBER_XBOX;
- m_FocusedItemPosition = focusedIconCount - diff;
- }
- else
- {
- m_FocusedItemPosition = 0;
- }
- UpdateSelection();
- }
-
- override void SetActive( bool active )
- {
- super.SetActive( active );
- UpdateSelection();
- }
-
- override bool IsItemActive()
- {
- if( GetFocusedIcon() )
- {
- ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
- return ( item != null );
- }
- return false;
- }
-
- override bool IsItemWithQuantityActive()
- {
- if( GetFocusedIcon() )
- {
- ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
- return ( !IsEmpty() && QuantityConversions.HasItemQuantity( item ) && item.CanBeSplit() );
- }
- return false;
- }
-
- override bool IsEmpty()
- {
- return m_Icons.Count() == 0;
- }
-
- int GetRecipeCount( bool recipe_anywhere, ItemBase entity1, ItemBase entity2, PlayerBase player )
- {
- PluginRecipesManager recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
- return recipes_manager.GetValidRecipes( entity1, entity2, null, player );
- }
-
- override bool CanCombineAmmo()
- {
- if( GetFocusedIcon() )
- {
- ActionManagerClient amc = ActionManagerClient.Cast( PlayerBase.Cast( GetGame().GetPlayer() ).GetActionManager() );
-
- ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
- ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
-
- return ( amc.CanPerformActionFromInventory( item_in_hands, entity ) || amc.CanSetActionFromInventory( item_in_hands, entity ) );
- }
- return false;
- }
-
- override bool TransferItem()
- {
- if (CanTakeToInventory())
- {
- if (GetFocusedIcon())
- {
- EntityAI entity = EntityAI.Cast( GetFocusedIcon().GetObject() );
- if (entity)
- {
- GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, entity );
- return true;
- }
- }
- }
- return false;
- }
-
- override bool SplitItem()
- {
- if (CanSplit())
- {
- if ( GetFocusedIcon() )
- {
- ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
- if ( entity )
- {
- if ( entity.HasQuantity() && entity.CanBeSplit() )
- {
- entity.OnRightClick();
- Icon icon = m_ShowedItemPositions.Get( entity ).param1;
-
- if ( icon )
- {
- icon.SetQuantity();
- }
- }
- }
- }
- }
- return false;
- }
-
- override bool EquipItem()
- {
- if (CanEquip())
- {
- if (GetFocusedIcon())
- {
- ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
- if( entity )
- {
- GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, entity );
- return true;
- }
- }
- }
- return false;
- }
-
- override bool SelectItem()
- {
- Icon focused_item = GetFocusedIcon();
- if (focused_item)
- {
- ItemBase item = ItemBase.Cast(focused_item.GetObject());
- if (item && item.IsTakeable() && item.CanPutIntoHands(null))
- {
- ItemManager.GetInstance().SetSelectedItemEx(item, this, focused_item);
- return true;
- }
- }
- return false;
- }
- override bool Select()
- {
- EntityAI focused_item = GetFocusedItem();
- EntityAI selected_item = ItemManager.GetInstance().GetSelectedItem();
- DayZPlayer player = GetGame().GetPlayer();
-
-
- if( focused_item != selected_item )
- {
- if( selected_item )
- {
- if( selected_item.GetInventory().CanRemoveEntity() && m_Entity )
- {
- bool can_add = m_Entity.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo());
- bool in_cargo = !player.GetInventory().HasEntityInInventory( selected_item ) || !m_Entity.GetInventory().HasEntityInCargo( selected_item );
- if( can_add && in_cargo )
- {
- player.PredictiveTakeEntityToTargetCargo( m_Entity, selected_item );
- Container selected_cont2 = ItemManager.GetInstance().GetSelectedContainer();
- if( selected_cont2 )
- {
- selected_cont2.SetActive( false );
- }
-
- SetActive( true );
- m_FocusedItemPosition = 0;
- return true;
- }
- else
- {
- Container selected_cont = ItemManager.GetInstance().GetSelectedContainer();
- if( selected_cont )
- {
- selected_cont.SetActive( false );
- }
-
- SetActive( true );
- SetDefaultFocus( true );
- }
- }
- }
- else if ( focused_item && focused_item.GetInventory().CanRemoveEntity() )
- {
- EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
- if( item_in_hands )
- {
- if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
- {
- player.PredictiveSwapEntities( item_in_hands, focused_item );
- return true;
- }
- }
- else
- {
- if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
- {
- player.PredictiveTakeEntityToHands( focused_item );
- return true;
- }
- }
- }
- }
- return false;
- }
-
- override bool Combine()
- {
- if (CanCombine())
- {
- if (GetFocusedIcon())
- {
- Icon icon = GetFocusedIcon();
- if( icon )
- {
- EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
- EntityAI prev_item = EntityAI.Cast( icon.GetObject() );
- if( item_in_hands && prev_item )
- {
- return icon.CombineItems( item_in_hands, prev_item );
- }
- }
- }
- }
- return false;
- }
-
- void ShowFalseCargoHeader(bool show)
- {
- m_CargoHeader.Show(show);
- }
-
- void SetAlternateFalseTextHeaderWidget(TextWidget w)
- {
- bool update = !m_AlternateFalseHeaderTextWidget;
- m_AlternateFalseHeaderTextWidget = w;
- if (update)
- {
- UpdateHeaderText();
- }
- }
-
- void SetAttachmentSlotID(int slotID)
- {
- m_AttachmentSlotID = slotID;
- }
-
- int GetAttachmentSlotID()
- {
- return m_AttachmentSlotID;
- }
-
- int GetIconsCount()
- {
- return m_Icons.Count();
- }
- }
|