123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110 |
- class PlayerContainer: CollapsibleContainer
- {
- protected ref AttachmentsGroupContainer m_PlayerAttachmentsContainer;
- protected ref map<int, SlotsIcon> m_InventorySlots;
- protected ref map<EntityAI, ref Container> m_ShowedItems = new map<EntityAI, ref Container>;
- protected ref map<int, ref Container> m_ShowedItemsIDs = new map<int, ref Container>;
- protected PlayerBase m_Player;
-
- protected const int HEADER_INDEX_OFFSET = 2;
-
- override void UpdateRadialIcon()
- {
- if ( m_SlotIcon )
- {
- bool show_radial_icon;
- show_radial_icon = IsHidden();
- Widget rip = m_SlotIcon.GetRadialIconPanel();
- rip.Show( !m_Player.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) && m_Player.CanDisplayCargo());
- SetOpenForSlotIcon(show_radial_icon);
- }
- }
-
- bool HasEntityContainerVisible( EntityAI entity )
- {
- ClosableContainer cont = ClosableContainer.Cast( m_ShowedItems.Get( entity ) );
- return ( cont && cont.IsOpened() );
- }
-
- SlotsIcon GetSlotsIcon( int row, int column )
- {
- return m_PlayerAttachmentsContainer.GetSlotsIcon(row, column);
- }
- void PlayerContainer( LayoutHolder parent, int sort = -1 )
- {
- m_InventorySlots = new map<int, SlotsIcon>;
- m_PlayerAttachmentsContainer = new AttachmentsGroupContainer(this);
-
- #ifndef PLATFORM_CONSOLE
- RightArea rightArea = RightArea.Cast(GetParent());
- if (rightArea)
- {
- rightArea.GetSlotsHeader().AddChild(GetHeader().GetRootWidget());
- rightArea.GetSlotsArea().AddChild(m_PlayerAttachmentsContainer.GetRootWidget());
- }
- #endif
-
- m_PlayerAttachmentsContainer.SetHeader(GetHeader());
- m_CollapsibleHeader.SetName( "#container_inventory" );
- SetHeader(null);
- m_Body.Insert( m_PlayerAttachmentsContainer );
- m_MainWidget = m_RootWidget.FindAnyWidget( "body" );
- m_PlayerAttachmentsContainer.GetRootWidget().SetColor(166 << 24 | 80 << 16 | 80 << 8 | 80);
- WidgetEventHandler.GetInstance().RegisterOnChildAdd( m_MainWidget, this, "OnChildAdd" );
- WidgetEventHandler.GetInstance().RegisterOnChildRemove( m_MainWidget, this, "OnChildRemove" );
- //START - InitGhostSlots
- string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
- ref array<string> player_ghosts_slots = new array<string>;
- GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
- for ( int i = 0; i < player_ghosts_slots.Count(); i++ )
- {
- string slot_name = player_ghosts_slots.Get ( i );
- string path = "CfgSlots" + " " + slot_name;
- if ( GetGame().ConfigIsExisting( path ) )
- {
- string icon_name; //icon_name must be in format "set:<setname> image:<imagename>"
- GetGame().ConfigGetText( path + " ghostIcon", icon_name );
- int slot_number = i;
- int column = slot_number % ITEMS_IN_ROW;
- //START - GetWidgetSlot
- int row = slot_number / ITEMS_IN_ROW;
- if( row >= m_PlayerAttachmentsContainer.Count() )
- {
- if( row < ( player_ghosts_slots.Count() / ITEMS_IN_ROW ) )
- AddSlotsContainer( ITEMS_IN_ROW );
- else
- AddSlotsContainer( player_ghosts_slots.Count() % ITEMS_IN_ROW );
- }
-
- SlotsIcon icon = GetSlotsIcon( row, column );
-
- icon.GetMainWidget().Show( true );
- icon.Clear();
-
- WidgetEventHandler.GetInstance().RegisterOnDoubleClick( icon.GetPanelWidget(), this, "DoubleClick" );
-
- //END - GetWidgetSlot
- WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetPanelWidget(), this, "OnDropReceivedFromGhostArea" );
- WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(), this, "OnDropReceivedFromGhostArea" );
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetGhostSlot(), this, "DraggingOver" );
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetPanelWidget(), this, "DraggingOver" );
- WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( icon.GetPanelWidget(), this, "MouseClick" );
-
- icon.GetGhostSlot().LoadImageFile( 0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY,icon_name) );
- //END - LoadIconIntoWidgetSlot
- GetGame().ConfigGetText( path + " name", slot_name );
- int slot_id = InventorySlots.GetSlotIdFromString( slot_name );
- icon.SetSlotID(slot_id);
- icon.SetSlotDisplayName(InventorySlots.GetSlotDisplayName(slot_id));
- m_InventorySlots.Set( slot_id, icon );
- }
- }
- m_PlayerAttachmentsContainer.GetMainWidget().Update();
- //END - InitGhostSlots
- RecomputeOpenedContainers();
- }
-
- void ~PlayerContainer()
- {
- if( m_Player )
- {
- m_Player.GetOnItemAttached().Remove(ItemAttached);
- m_Player.GetOnItemDetached().Remove(ItemDetached);
- m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
- m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
- }
- }
-
- void ItemAttached(EntityAI item, string slot_name)
- {
- int slot = InventorySlots.GetSlotIdFromString( slot_name );
- SlotsIcon icon = m_InventorySlots.Get( slot );
-
- if( icon )
- {
- if( icon.IsReserved())
- m_Player.GetOnAttachmentReleaseLock().Invoke(item, slot);
-
- icon.Init( item );
- if( m_ShowedItems.Contains( item ) == false )
- {
- string name;
- int sort_index = Inventory.GetPlayerAttachmentIndex( slot );
- int current_sort = 9999;
- if( GetFocusedContainer() )
- current_sort = GetFocusedContainer().GetRootWidget().GetSort();
-
- if( item.GetSlotsCountCorrect() > 0 )
- {
- ContainerWithCargoAndAttachments iwca = new ContainerWithCargoAndAttachments( this, sort_index );
- iwca.SetEntity( item );
- iwca.SetSlotIcon( icon );
- WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(), this, "ToggleWidget" );
- if( iwca.IsDisplayable() )
- {
- icon.GetRadialIconPanel().Show( true );
- }
- m_ShowedItems.Insert( item, iwca );
- RecomputeOpenedContainers();
- Refresh();
- }
- else if( item.GetInventory().GetCargo() )
- {
- ContainerWithCargo iwc = new ContainerWithCargo( this, sort_index );
- iwc.SetEntity( item );
- iwc.SetSlotIcon( icon );
- iwc.UpdateInterval();
- WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(), this, "ToggleWidget" );
- m_ShowedItems.Insert( item, iwc );
- RecomputeOpenedContainers();
- if( iwc.IsDisplayable() )
- icon.GetRadialIconPanel().Show(true);
-
- Refresh();
- }
- }
-
- ClosableContainer conta = ClosableContainer.Cast( m_ShowedItems.Get( item ) );
- string config = "CfgVehicles " + item.GetType() + " GUIInventoryAttachmentsProps";
- if( conta && conta.IsInherited( ClosableContainer ) )
- {
- bool show_radial_icon = ( item.GetInventory().GetCargo() || item.GetSlotsCountCorrect() > 0 ) && !GetGame().ConfigIsExisting( config );
- Widget rip = icon.GetRadialIconPanel();
- rip.Show( show_radial_icon );
- SetOpenForSlotIcon(conta.IsOpened(),icon);
- }
- }
- UpdateSelectionIcons();
- }
-
- void ItemDetached(EntityAI item, string slot_name)
- {
- int slot = InventorySlots.GetSlotIdFromString( slot_name );
- SlotsIcon icon = m_InventorySlots.Get( slot );
-
- if( icon )
- {
- Container con = m_ShowedItems.Get( item );
- if( con )
- {
- ( Container.Cast( con.m_Parent ) ).Remove( con );
- RecomputeOpenedContainers();
- GetMainWidget().Update();
- Refresh();
- m_ShowedItems.Remove( item );
- }
-
- icon.Clear();
- Inventory in = Inventory.Cast( GetRoot() );
- if( in )
- in.UpdateConsoleToolbar();
- }
- UpdateSelectionIcons();
- }
-
- void OnAttachmentReservationSet( EntityAI item, int slot_id )
- {
- SlotsIcon icon = m_InventorySlots.Get( slot_id );
-
- if( item )
- {
- icon.Init( item, true );
- }
- }
-
- void OnAttachmentReservationRelease( EntityAI item, int slot_id )
- {
- SlotsIcon icon = m_InventorySlots.Get( slot_id );
- icon.Clear();
- }
-
- void AddSlotsContainer( int row_count )
- {
- SlotsContainer container = new SlotsContainer(m_PlayerAttachmentsContainer, m_Player);
- container.SetColumnCount(row_count);
- m_PlayerAttachmentsContainer.Insert(container);
- }
-
- void MouseClick( Widget w, int x, int y, int button )
- {
- SlotsIcon icon;
- w.GetUserData(icon);
-
- ItemBase selectedItem;
- bool isReserved;
-
- if (icon)
- {
- selectedItem = ItemBase.Cast(icon.GetEntity());
- isReserved = icon.IsReserved();
-
- }
- if (selectedItem)
- {
- switch (button)
- {
- case MouseState.RIGHT:
- #ifdef DIAG_DEVELOPER
- if (GetDayZGame().IsLeftCtrlDown())
- ShowActionMenu(selectedItem);
- #endif
-
- if (isReserved)
- {
- GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced(selectedItem);
- m_Player.GetOnAttachmentReleaseLock().Invoke(selectedItem, icon.GetSlotID());
- }
- break;
- case MouseState.MIDDLE:
- if (!isReserved)
- InspectItem(selectedItem);
- break;
- case MouseState.LEFT:
- if (!isReserved)
- {
- PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
- if (g_Game.IsLeftCtrlDown())
- {
- if (controlledPlayer.CanDropEntity(selectedItem))
- {
- if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
- selectedItem.SplitIntoStackMaxClient(null, -1);
- else
- controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
- }
- }
- else
- {
- bool draggable = !m_Player.GetInventory().HasInventoryReservation(selectedItem, null ) && !m_Player.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !m_Player.IsItemsToDelete();
- ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
- }
- }
- break;
- }
- }
- }
-
- float GetMainContainerTopPos()
- {
- float x, y;
- GetRootWidget().GetScreenPos( x, y );
- return y;
- }
-
- float GetMainContainerBottomPos()
- {
- float x, y;
- float x2, y2;
- GetRootWidget().GetScreenPos( x, y );
- GetRootWidget().GetScreenSize( x2, y2 );
- y += y2;
- return y;
- }
-
- override void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
- {
- ClosableContainer c_cont = ClosableContainer.Cast( container );
- if (c_cont && m_Body.Count() > 1)
- {
- ClosableContainer prev = ClosableContainer.Cast(m_Body.Get( 1 ));
- int index = 1;
- int curr_sort = c_cont.GetRootWidget().GetSort();
- while ( prev )
- {
- int prev_sort = prev.GetRootWidget().GetSort();
- if ( prev_sort > curr_sort )
- break;
-
- if ( ++index < m_Body.Count() )
- prev = ClosableContainer.Cast( m_Body.Get( index ) );
- else
- break;
- }
-
- m_Body.InsertAt( container, index );
- }
- else
- {
- m_Body.Insert( container );
- }
-
- if ( immedUpdate )
- RecomputeOpenedContainers();
- }
-
- bool IsItemWithContainerActive()
- {
- EntityAI ent = GetFocusedItem();
- return ent && ( ent.GetInventory().GetCargo() || ent.GetSlotsCountCorrect() > 0 );
- }
-
- override bool IsItemWithQuantityActive()
- {
- EntityAI ent = GetFocusedItem();
- return ent && QuantityConversions.HasItemQuantity( ent ) && ent.CanBeSplit();
- }
-
- override bool IsItemActive()
- {
- EntityAI ent = GetFocusedItem();
- return ent && !IsItemWithQuantityActive() && !IsItemWithContainerActive();
- }
-
- bool IsEmptyItemActive()
- {
- EntityAI ent = GetFocusedItem();
- return ent == null;
- }
-
- void UnfocusPlayerAttachmentsContainer()
- {
- m_PlayerAttachmentsContainer.UnfocusAll();
- }
-
- void DoubleClick(Widget w, int x, int y, int button)
- {
- if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
-
- if( w == null || m_Player.GetInventory().IsInventoryLocked() )
- {
- return;
- }
- ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
- if( !iw )
- {
- string name = w.GetName();
- name.Replace( "PanelWidget", "Render" );
- iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
- }
- if( !iw )
- {
- iw = ItemPreviewWidget.Cast( w );
- }
- ItemBase item = ItemBase.Cast( iw.GetItem() );
-
- if( !item )
- {
- return;
- }
-
- SlotsIcon icon;
- iw.GetUserData(icon);
-
- if(icon && icon.IsReserved())
- {
- return;
- }
-
- if( !item.GetInventory().CanRemoveEntity() )
- return;
-
- if ( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
- {
- player.PredictiveTakeEntityToHands( item );
- }
- else
- {
- if (player.GetInventory().CanAddEntityToInventory( item ) && item.GetInventory().CanRemoveEntity())
- {
- if( item.GetTargetQuantityMax() < item.GetQuantity() )
- item.SplitIntoStackMaxClient( player, -1 );
- else
- player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ANY, item );
- }
- else
- {
- if( item.GetTargetQuantityMax() < item.GetQuantity() )
- item.SplitIntoStackMaxHandsClient( player );
- else
- player.PredictiveTakeEntityToHands( item );
- }
- }
- ToggleWidget( w );
- HideOwnedTooltip();
-
- InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
- if ( menu )
- {
- menu.RefreshQuickbar();
- }
- }
- }
-
- override void ExpandCollapseContainer()
- {
- if( m_PlayerAttachmentsContainer.IsActive() )
- {
- ToggleWidget(m_PlayerAttachmentsContainer.GetFocusedSlotsIcon().GetPanelWidget());
- }
- }
-
- bool IsContainerWithCargoActive()
- {
- return GetFocusedContainer().IsInherited( ContainerWithCargo );
- }
-
- bool IsItemWithAttachmentsActive()
- {
- return GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments );
- }
-
- override bool TransferItemToVicinity()
- {
- if (CanDrop())
- {
- if (GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
- {
- return GetFocusedContainer().TransferItemToVicinity();
- }
- else
- {
- Man player = GetGame().GetPlayer();
- ItemBase item = ItemBase.Cast(GetFocusedItem());
- if ( item && player.CanDropEntity( item ) )
- {
- if ( item.GetTargetQuantityMax() < item.GetQuantity() )
- item.SplitIntoStackMaxClient( null, -1 );
- else
- player.PhysicalPredictiveDropItem( item );
- return true;
- }
- }
- }
- return false;
- }
-
- override bool InspectItem()
- {
- if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
- {
- return GetFocusedContainer().InspectItem();
- }
- else
- {
- Man player = GetGame().GetPlayer();
- EntityAI item = GetFocusedItem();
- if( item )
- {
- InspectItem( item );
- return true;
- }
- }
- return false;
- }
-
- int GetRecipeCount( bool recipe_anywhere, EntityAI entity1, EntityAI entity2 )
- {
- PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
- return plugin_recipes_manager.GetValidRecipes( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ), null, PlayerBase.Cast( GetGame().GetPlayer() ) );
- }
-
- override bool TransferItem()
- {
- if (CanTakeToInventory())
- {
- LeftArea left_area = LeftArea.Cast( GetParent() );
- EntityAI item;
- if (left_area)
- {
- if (GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
- {
- return GetFocusedContainer().TransferItem();
- }
- else
- {
- item = GetFocusedItem();
- if( item )
- {
- GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
- return true;
- }
- }
- }
- else
- {
- if (!GetFocusedContainer().IsInherited( ContainerWithCargo ) && !GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
- {
- item = GetFocusedItem();
- if( item )
- {
- GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
- return true;
- }
- }
- }
- }
- return false;
- }
-
- override EntityAI GetFocusedItem()
- {
- return GetFocusedContainer().GetFocusedItem();
- }
-
- override bool Combine()
- {
- if (CanCombine())
- {
- if ( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
- {
- return GetFocusedContainer().Combine();
- }
- else
- {
- EntityAI item = GetFocusedItem();
- ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
-
- Icon hands_icon = ItemManager.GetInstance().GetHandsPreview().GetIcon();
-
- if( item_in_hands && item )
- {
- return hands_icon.CombineItems( item_in_hands, item );
- }
- }
- }
- return true;
- }
-
- override bool Select()
- {
- if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
- {
- return GetFocusedContainer().Select();
- }
- else
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- EntityAI selected_item = ItemManager.GetInstance().GetSelectedItem();
- SlotsIcon focused_slot = GetFocusedSlotsIcon();
- EntityAI focused_item = focused_slot.GetEntity();
- if( focused_slot.IsReserved() || focused_item != selected_item )
- {
- if( selected_item )
- {
- if( selected_item.GetInventory().CanRemoveEntity() )
- {
- if (m_Player.GetInventory().CanAddAttachmentEx( selected_item, focused_slot.GetSlotID() ))
- {
- player.PredictiveTakeEntityToTargetAttachmentEx( m_Player, selected_item, focused_slot.GetSlotID());
- //m_Player.PredictiveTakeEntityAsAttachmentEx( selected_item, focused_slot.GetSlotID() );
- ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
- return true;
-
- }
- else if (m_Player.GetInventory().CanAddAttachment( selected_item ))
- {
- player.PredictiveTakeEntityToTargetAttachment( m_Player, selected_item );
- //m_Player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, selected_item );
- ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
- return true;
- }
- }
- }
- else
- {
- if( focused_item && focused_item.GetInventory().CanRemoveEntity() )
- {
- EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
- if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
- {
- if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
- {
- player.PredictiveSwapEntities( item_in_hands, focused_item );
- return true;
- }
- else
- {
- InventoryLocation il_hands_dst = new InventoryLocation;
- if( player.GetHumanInventory().FindFreeLocationFor( item_in_hands, FindInventoryLocationType.ANY, il_hands_dst ) )
- {
- InventoryMode invMode = InventoryMode.PREDICTIVE;
-
- if ( player.NeedInventoryJunctureFromServer(item_in_hands, item_in_hands.GetHierarchyParent(), il_hands_dst.GetParent()) || GetGame().GetPlayer().NeedInventoryJunctureFromServer(focused_item, focused_item.GetHierarchyParent(), GetGame().GetPlayer()) )
- invMode = InventoryMode.JUNCTURE;
-
- player.GetHumanInventory().ForceSwapEntities( invMode, focused_item, item_in_hands, il_hands_dst );
- return true;
- }
- }
- }
- else
- {
- if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
- {
- player.PredictiveTakeEntityToHands( focused_item );
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
-
- void SetPlayer(PlayerBase player)
- {
- if (m_Player)
- {
- m_Player.GetOnItemAttached().Remove(ItemAttached);
- m_Player.GetOnItemDetached().Remove(ItemDetached);
- m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
- m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
- }
- m_Player = player;
- if (m_Player)
- {
- m_Player.GetOnItemAttached().Insert(ItemAttached);
- m_Player.GetOnItemDetached().Insert(ItemDetached);
- m_Player.GetOnAttachmentSetLock().Insert(OnAttachmentReservationSet);
- m_Player.GetOnAttachmentReleaseLock().Insert(OnAttachmentReservationRelease);
- }
-
- //START - InitGhostSlots
- string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
- ref array<string> player_ghosts_slots = new array<string>;
- GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
- for ( int i = 0; i < player_ghosts_slots.Count(); i++ )
- {
- string slot_name = player_ghosts_slots.Get ( i );
- int column = i % ITEMS_IN_ROW;
- int row = i / ITEMS_IN_ROW;
-
- SlotsIcon icon = GetSlotsIcon( row, column );
-
- icon.SetSlotParent(m_Player);
- icon.GetMainWidget().Show( true );
- icon.Clear();
-
- GetGame().ConfigGetText( "CfgSlots" + " " + slot_name + " name", slot_name );
- EntityAI item = m_Player.GetInventory().FindAttachment( InventorySlots.GetSlotIdFromString( slot_name ) );
- if( item )
- {
- ItemAttached( item, slot_name );
- }
- }
- }
- override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
- {
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast( GetItemPreviewWidget( w ) );
- if( !ipw.IsInherited( ItemPreviewWidget ) )
- {
- return;
- }
- EntityAI item = ipw.GetItem();
- if( !item )
- {
- return;
- }
- if( !item.GetInventory().CanRemoveEntity() )
- return;
-
- if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) )
- {
- m_Player.PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT, item );
- }
- }
- ItemPreviewWidget GetItemPreviewWidget( Widget w )
- {
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
- if( !ipw )
- {
- string name = w.GetName();
- name.Replace( "PanelWidget", "Render" );
- ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
- }
- if( !ipw )
- {
- ipw = ItemPreviewWidget.Cast( w );
- }
- return ipw;
- }
- override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
- {
- if( w == null )
- {
- return;
- }
- ItemPreviewWidget ipw = GetItemPreviewWidget( w );
- if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
- {
- return;
- }
- EntityAI item = ipw.GetItem();
- if( !item )
- {
- return;
- }
- if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && !m_Player.GetInventory().HasEntityInInventory( item ) )
- {
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
- }
- else
- {
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
- //ItemManager.GetInstance().ShowSourceDropzone( item );
- }
- }
- override void DraggingOver( Widget w, int x, int y, Widget receiver )
- {
- if( w == null )
- {
- return;
- }
-
- EntityAI receiver_item;
- bool is_reserved = false;
-
- SlotsIcon slots_icon;
- receiver.GetUserData(slots_icon);
-
- if(slots_icon)
- {
- receiver_item = slots_icon.GetEntity();
- is_reserved = slots_icon.IsReserved();
- }
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast( GetItemPreviewWidget( w ) );
- if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
- {
- return;
- }
- EntityAI item = ipw.GetItem();
- if( !item )
- {
- return;
- }
-
- if( receiver_item && !is_reserved )
- {
- if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- return;
- }
- else if( receiver_item.GetInventory().CanAddAttachment(item) || receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ))
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- return;
- }
- else if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.COMBINE_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- return;
- }
- }
-
- if( item.GetInventory().CanRemoveEntity() )
- {
- if( m_Player.GetInventory().CanAddAttachment( item) )
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) || m_Player.GetHumanInventory().HasEntityInHands( item ) )
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else if ( receiver_item && GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- }
- else
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- //ItemManager.GetInstance().ShowSourceDropzone( item );
- }
- }
- void OnDropReceivedFromGhostArea( Widget w, int x, int y, Widget receiver )
- {
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().SetIsDragging( false );
-
- EntityAI receiver_item;
- bool is_reserved = false;
- InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
- float stack_max;
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast( GetItemPreviewWidget( w ) );
- SlotsIcon slots_icon;
- receiver.GetUserData(slots_icon);
- int slot_id = slots_icon.GetSlotID();
-
- receiver_item = slots_icon.GetEntity();
- is_reserved = slots_icon.IsReserved();
- InventoryLocation il;
- if ( !ipw )
- {
- return;
- }
- ItemBase item = ItemBase.Cast(ipw.GetItem());
- PlayerBase real_player = PlayerBase.Cast( GetGame().GetPlayer() );
- if ( !item )
- {
- return;
- }
- if ( receiver_item && !is_reserved )
- {
- if ( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
- {
- GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
- if ( menu )
- {
- menu.RefreshQuickbar();
- }
- return;
- }
- else if ( receiver_item.GetInventory().CanAddAttachment( item ) )
- {
- GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment( receiver_item, item );
- if ( menu )
- {
- menu.RefreshQuickbar();
- }
- return;
- }
- else if ( receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ) )
- {
- SplitItemUtils.TakeOrSplitToInventory(real_player, receiver_item,item);
- if ( menu )
- {
- menu.RefreshQuickbar();
- }
- return;
- }
- else if ( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
- {
- ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
- return;
- }
- }
-
- if ( m_Player.GetInventory().CanAddAttachmentEx( item, slot_id ) )
- {
- if (item.GetQuantity() > item.GetTargetQuantityMax(slot_id))
- {
- item.SplitIntoStackMaxClient( real_player, slot_id );
- }
- else
- {
- real_player.PredictiveTakeEntityToTargetAttachmentEx( m_Player, item, slots_icon.GetSlotID() );
- }
- }
- else if ( m_Player.GetInventory().CanAddAttachment( item ) )
- {
- il = new InventoryLocation;
- m_Player.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ATTACHMENT, il );
- float stackable = item.GetTargetQuantityMax(-1);
-
- if( il.IsValid() )
- {
- if ( stackable == 0 || stackable >= item.GetQuantity() )
- {
- real_player.PredictiveTakeEntityToTargetAttachment( il.GetParent(), item );
- }
- else
- {
- ItemBase.Cast(item).SplitIntoStackMaxToInventoryLocationClient( il );
- }
- }
- }
- else if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) || m_Player.GetHumanInventory().HasEntityInHands( item ) )
- {
- SplitItemUtils.TakeOrSplitToInventory(m_Player, m_Player, item);
- }
- if ( menu )
- {
- menu.RefreshQuickbar();
- }
- }
-
- void SwapItemsInOrder( int slot1, int slot2 )
- {
- EntityAI item1 = m_Player.GetInventory().FindAttachment( slot1 );
- EntityAI item2 = m_Player.GetInventory().FindAttachment( slot2 );
-
- if( item1 && item2 )
- {
- Container cont1 = m_ShowedItems.Get( item1 );
- Container cont2 = m_ShowedItems.Get( item2 );
- if( cont1 && cont2 )
- {
- int sort1 = cont1.GetRootWidget().GetSort();
- int sort2 = cont2.GetRootWidget().GetSort();
-
- cont1.GetRootWidget().SetSort( sort2 );
- cont2.GetRootWidget().SetSort( sort1 );
-
- m_Body.SwapItems( m_Body.Find( cont1 ), m_Body.Find( cont2 ) );
- }
- }
- RecomputeOpenedContainers();
- }
- override void UpdateInterval()
- {
- int i;
- for ( i = 0; i < m_InventorySlots.Count(); i++ )
- {
- SlotsIcon icon = m_InventorySlots.GetElement( i );
- if ( icon )
- {
- icon.UpdateInterval();
- }
- }
- for ( i = 0; i < m_ShowedItems.Count(); i++ )
- {
- Container cont = m_ShowedItems.GetElement( i );
- if ( cont )
- {
- cont.UpdateInterval();
- }
- }
- }
- // Call from ToggleWidget
- void ToggleContainer( Widget w, EntityAI item )
- {
- InventoryLocation il = new InventoryLocation;
- item.GetInventory().GetCurrentInventoryLocation( il );
- SlotsIcon icon = m_InventorySlots.Get( il.GetSlot() );
- ClosableContainer c = ClosableContainer.Cast( m_ShowedItems.Get( item ) );
- if (c)
- {
- c.Toggle();
- Refresh();
- }
- }
-
- override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
- {
- if (focusedEntity)
- {
- ClosableContainer c = ClosableContainer.Cast( m_ShowedItems.Get( focusedEntity ) );
- if (c && c.IsDisplayable())
- {
- return true;
- }
- }
- return false;
- }
- // Mouse button UP or Call other fn
- void ToggleWidget( Widget w )
- {
- if( ItemManager.GetInstance().IsDragging() )
- {
- return;
- }
- string name = w.GetName();
- name.Replace( "PanelWidget", "Render" );
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
- if( ipw.GetItem() )
- {
- ToggleContainer( w, ipw.GetItem() );
- RecomputeOpenedContainers();
- }
-
- Refresh();
- }
- override void CollapseButtonOnMouseButtonDown(Widget w)
- {
- super.CollapseButtonOnMouseButtonDown(w);
- }
-
- bool IsPlayerEquipmentActive()
- {
- if( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
- {
- return false;
- }
-
- return true;
- }
-
- override void Refresh()
- {
- super.Refresh();
- m_MainWidget.Update();
- m_RootWidget.Update();
- UpdateSelectionIcons();
- }
-
- override bool OnChildRemove( Widget w, Widget child )
- {
- Refresh();
- return true;
- }
-
- override bool OnChildAdd( Widget w, Widget child )
- {
- Refresh();
- return true;
- }
- }
|