9 protected const int HEADER_INDEX_OFFSET = 2;
11 override void UpdateRadialIcon()
15 bool show_radial_icon;
16 show_radial_icon = IsHidden();
17 Widget rip = m_SlotIcon.GetRadialIconPanel();
18 rip.Show( !
m_Player.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) &&
m_Player.CanDisplayCargo());
19 SetOpenForSlotIcon(show_radial_icon);
23 bool HasEntityContainerVisible(
EntityAI entity )
26 return ( cont && cont.IsOpened() );
29 SlotsIcon GetSlotsIcon(
int row,
int column )
31 return m_PlayerAttachmentsContainer.GetSlotsIcon(row, column);
39 m_PlayerAttachmentsContainer.SetHeader(
GetHeader());
40 m_CollapsibleHeader.SetName(
"#container_inventory" );
42 m_Body.Insert( m_PlayerAttachmentsContainer );
44 m_PlayerAttachmentsContainer.GetRootWidget().SetColor(166 << 24 | 80 << 16 | 80 << 8 | 80);
45 WidgetEventHandler.GetInstance().RegisterOnChildAdd( m_MainWidget,
this,
"OnChildAdd" );
46 WidgetEventHandler.GetInstance().RegisterOnChildRemove( m_MainWidget,
this,
"OnChildRemove" );
49 string config_path_ghosts_slots =
"CfgVehicles SurvivorBase InventoryEquipment playerSlots";
51 GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
53 for (
int i = 0; i < player_ghosts_slots.Count(); i++ )
55 string slot_name = player_ghosts_slots.Get ( i );
56 string path =
"CfgSlots" +
" " + slot_name;
61 GetGame().ConfigGetText(
path +
" ghostIcon", icon_name );
67 if( row >= m_PlayerAttachmentsContainer.Count() )
69 if( row < ( player_ghosts_slots.Count() /
ITEMS_IN_ROW ) )
72 AddSlotsContainer( player_ghosts_slots.Count() %
ITEMS_IN_ROW );
75 SlotsIcon icon = GetSlotsIcon( row, column );
77 icon.GetMainWidget().Show(
true );
80 WidgetEventHandler.GetInstance().RegisterOnDoubleClick( icon.GetPanelWidget(),
this,
"DoubleClick" );
83 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetPanelWidget(),
this,
"OnDropReceivedFromGhostArea" );
84 WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(),
this,
"OnDropReceivedFromGhostArea" );
85 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetGhostSlot(),
this,
"DraggingOver" );
86 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetPanelWidget(),
this,
"DraggingOver" );
87 WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( icon.GetPanelWidget(),
this,
"MouseClick" );
92 GetGame().ConfigGetText(
path +
" name", slot_name );
94 icon.SetSlotID(slot_id);
95 icon.SetSlotDisplayName(
InventorySlots.GetSlotDisplayName(slot_id));
96 m_InventorySlots.Set( slot_id, icon );
99 m_PlayerAttachmentsContainer.GetMainWidget().Update();
101 RecomputeOpenedContainers();
108 m_Player.GetOnItemAttached().Remove(ItemAttached);
109 m_Player.GetOnItemDetached().Remove(ItemDetached);
110 m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
111 m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
115 void ItemAttached(
EntityAI item,
string slot_name)
118 SlotsIcon icon = m_InventorySlots.Get( slot );
122 if( icon.IsReserved())
123 m_Player.GetOnAttachmentReleaseLock().Invoke(item, slot);
127 if( m_ShowedItems.Contains( item ) ==
false )
130 int sort_index =
Inventory.GetPlayerAttachmentIndex( slot );
131 int current_sort = 9999;
132 if( GetFocusedContainer() )
133 current_sort = GetFocusedContainer().GetRootWidget().GetSort();
135 if( item.GetSlotsCountCorrect() > 0 )
137 ContainerWithCargoAndAttachments iwca =
new ContainerWithCargoAndAttachments(
this, sort_index );
138 iwca.SetEntity( item );
139 iwca.SetSlotIcon( icon );
140 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(),
this,
"ToggleWidget" );
142 if( iwca.IsDisplayable() )
144 icon.GetRadialIconPanel().Show(
true );
146 m_ShowedItems.Insert( item, iwca );
147 RecomputeOpenedContainers();
150 else if( item.GetInventory().GetCargo() )
152 ContainerWithCargo iwc =
new ContainerWithCargo(
this, sort_index );
153 iwc.SetEntity( item );
154 iwc.SetSlotIcon( icon );
155 iwc.UpdateInterval();
156 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(),
this,
"ToggleWidget" );
157 m_ShowedItems.Insert( item, iwc );
158 RecomputeOpenedContainers();
159 if( iwc.IsDisplayable() )
160 icon.GetRadialIconPanel().Show(
true);
167 string config =
"CfgVehicles " + item.GetType() +
" GUIInventoryAttachmentsProps";
170 bool show_radial_icon = ( item.GetInventory().GetCargo() || item.GetSlotsCountCorrect() > 0 ) && !
GetGame().ConfigIsExisting( config );
171 Widget rip = icon.GetRadialIconPanel();
173 rip.Show( show_radial_icon );
174 SetOpenForSlotIcon(conta.IsOpened(),icon);
177 UpdateSelectionIcons();
180 void ItemDetached(
EntityAI item,
string slot_name)
183 SlotsIcon icon = m_InventorySlots.Get( slot );
187 Container con = m_ShowedItems.Get( item );
191 RecomputeOpenedContainers();
192 GetMainWidget().Update();
194 m_ShowedItems.Remove( item );
200 in.UpdateConsoleToolbar();
202 UpdateSelectionIcons();
205 void OnAttachmentReservationSet(
EntityAI item,
int slot_id )
207 SlotsIcon icon = m_InventorySlots.Get( slot_id );
211 icon.Init( item,
true );
215 void OnAttachmentReservationRelease(
EntityAI item,
int slot_id )
217 SlotsIcon icon = m_InventorySlots.Get( slot_id );
221 void AddSlotsContainer(
int row_count )
224 container.SetColumnCount(row_count);
225 m_PlayerAttachmentsContainer.Insert(container);
228 void MouseClick(
Widget w,
int x,
int y,
int button )
238 selectedItem =
ItemBase.Cast(icon.GetEntity());
239 isReserved = icon.IsReserved();
248 #ifdef DIAG_DEVELOPER
250 ShowActionMenu(selectedItem);
255 GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced(selectedItem);
256 m_Player.GetOnAttachmentReleaseLock().Invoke(selectedItem, icon.GetSlotID());
262 InspectItem(selectedItem);
270 if (
g_Game.IsLeftCtrlDown())
272 if (controlledPlayer.CanDropEntity(selectedItem))
274 if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
275 selectedItem.SplitIntoStackMaxClient(
null, -1);
277 controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
282 bool draggable = !
m_Player.GetInventory().HasInventoryReservation(selectedItem,
null ) && !
m_Player.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !
m_Player.IsItemsToDelete();
283 ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
291 float GetMainContainerTopPos()
294 GetRootWidget().GetScreenPos(
x,
y );
298 float GetMainContainerBottomPos()
302 GetRootWidget().GetScreenPos(
x,
y );
303 GetRootWidget().GetScreenSize( x2, y2 );
308 override void Insert(
LayoutHolder container,
int pos = -1,
bool immedUpdate =
true )
311 if (c_cont && m_Body.Count() > 1)
315 int curr_sort = c_cont.GetRootWidget().GetSort();
318 int prev_sort = prev.GetRootWidget().GetSort();
319 if ( prev_sort > curr_sort )
322 if ( ++index < m_Body.Count() )
328 m_Body.InsertAt( container, index );
332 m_Body.Insert( container );
336 RecomputeOpenedContainers();
339 bool IsItemWithContainerActive()
342 return ent && ( ent.GetInventory().GetCargo() || ent.GetSlotsCountCorrect() > 0 );
345 override bool IsItemWithQuantityActive()
351 override bool IsItemActive()
354 return ent && !IsItemWithQuantityActive() && !IsItemWithContainerActive();
357 bool IsEmptyItemActive()
363 void UnfocusPlayerAttachmentsContainer()
365 m_PlayerAttachmentsContainer.UnfocusAll();
368 void DoubleClick(
Widget w,
int x,
int y,
int button)
374 if( w ==
null ||
m_Player.GetInventory().IsInventoryLocked() )
381 string name = w.GetName();
382 name.Replace(
"PanelWidget",
"Render" );
398 iw.GetUserData(icon);
400 if(icon && icon.IsReserved())
405 if( !item.GetInventory().CanRemoveEntity() )
408 if ( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
410 player.PredictiveTakeEntityToHands( item );
414 if (player.GetInventory().CanAddEntityToInventory( item ) && item.GetInventory().CanRemoveEntity())
416 if( item.GetTargetQuantityMax() < item.GetQuantity() )
417 item.SplitIntoStackMaxClient( player, -1 );
423 if( item.GetTargetQuantityMax() < item.GetQuantity() )
424 item.SplitIntoStackMaxHandsClient( player );
426 player.PredictiveTakeEntityToHands( item );
435 menu.RefreshQuickbar();
440 override void ExpandCollapseContainer()
442 if( m_PlayerAttachmentsContainer.IsActive() )
444 ToggleWidget(m_PlayerAttachmentsContainer.GetFocusedSlotsIcon().GetPanelWidget());
448 bool IsContainerWithCargoActive()
450 return GetFocusedContainer().IsInherited( ContainerWithCargo );
453 bool IsItemWithAttachmentsActive()
455 return GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments );
458 override bool TransferItemToVicinity()
462 if (GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
464 return GetFocusedContainer().TransferItemToVicinity();
468 Man player =
GetGame().GetPlayer();
470 if ( item && player.CanDropEntity( item ) )
472 if ( item.GetTargetQuantityMax() < item.GetQuantity() )
473 item.SplitIntoStackMaxClient(
null, -1 );
475 player.PhysicalPredictiveDropItem( item );
483 override bool InspectItem()
485 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
487 return GetFocusedContainer().InspectItem();
491 Man player =
GetGame().GetPlayer();
502 int GetRecipeCount(
bool recipe_anywhere,
EntityAI entity1,
EntityAI entity2 )
504 PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(
GetPlugin( PluginRecipesManager ) );
508 override bool SplitItem()
512 if ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
514 return GetFocusedContainer().SplitItem();
521 override bool EquipItem()
525 if ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
527 return GetFocusedContainer().EquipItem();
542 override bool TransferItem()
544 if (CanTakeToInventory())
550 if (GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
552 return GetFocusedContainer().TransferItem();
556 item = GetFocusedItem();
566 if (!GetFocusedContainer().IsInherited( ContainerWithCargo ) && !GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
568 item = GetFocusedItem();
582 return GetFocusedContainer().GetFocusedItem();
585 override bool Combine()
589 if ( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
591 return GetFocusedContainer().Combine();
598 Icon hands_icon =
ItemManager.GetInstance().GetHandsPreview().GetIcon();
600 if( item_in_hands && item )
602 return hands_icon.CombineItems( item_in_hands, item );
609 override bool Select()
611 if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
613 return GetFocusedContainer().Select();
619 SlotsIcon focused_slot = GetFocusedSlotsIcon();
620 EntityAI focused_item = focused_slot.GetEntity();
621 if( focused_slot.IsReserved() || focused_item != selected_item )
625 if( selected_item.GetInventory().CanRemoveEntity() )
627 if (
m_Player.GetInventory().CanAddAttachmentEx( selected_item, focused_slot.GetSlotID() ))
629 player.PredictiveTakeEntityToTargetAttachmentEx(
m_Player, selected_item, focused_slot.GetSlotID());
631 ItemManager.GetInstance().SetSelectedItemEx(
null,
null,
null);
635 else if (
m_Player.GetInventory().CanAddAttachment( selected_item ))
637 player.PredictiveTakeEntityToTargetAttachment(
m_Player, selected_item );
639 ItemManager.GetInstance().SetSelectedItemEx(
null,
null,
null);
646 if( focused_item && focused_item.GetInventory().CanRemoveEntity() )
648 EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
649 if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
651 if(
GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
653 player.PredictiveSwapEntities( item_in_hands, focused_item );
663 if ( player.NeedInventoryJunctureFromServer(item_in_hands, item_in_hands.GetHierarchyParent(), il_hands_dst.GetParent()) ||
GetGame().
GetPlayer().NeedInventoryJunctureFromServer(focused_item, focused_item.GetHierarchyParent(),
GetGame().
GetPlayer()) )
666 player.GetHumanInventory().ForceSwapEntities( invMode, focused_item, item_in_hands, il_hands_dst );
673 if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
675 player.PredictiveTakeEntityToHands( focused_item );
690 m_Player.GetOnItemAttached().Remove(ItemAttached);
691 m_Player.GetOnItemDetached().Remove(ItemDetached);
692 m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
693 m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
699 m_Player.GetOnItemAttached().Insert(ItemAttached);
700 m_Player.GetOnItemDetached().Insert(ItemDetached);
701 m_Player.GetOnAttachmentSetLock().Insert(OnAttachmentReservationSet);
702 m_Player.GetOnAttachmentReleaseLock().Insert(OnAttachmentReservationRelease);
706 string config_path_ghosts_slots =
"CfgVehicles SurvivorBase InventoryEquipment playerSlots";
708 GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
710 for (
int i = 0; i < player_ghosts_slots.Count(); i++ )
712 string slot_name = player_ghosts_slots.Get ( i );
717 SlotsIcon icon = GetSlotsIcon( row, column );
720 icon.GetMainWidget().Show(
true );
723 GetGame().ConfigGetText(
"CfgSlots" +
" " + slot_name +
" name", slot_name );
727 ItemAttached( item, slot_name );
732 override void OnDropReceivedFromHeader(
Widget w,
int x,
int y,
Widget receiver )
747 if( !item.GetInventory().CanRemoveEntity() )
761 string name = w.GetName();
762 name.Replace(
"PanelWidget",
"Render" );
773 override void DraggingOverHeader(
Widget w,
int x,
int y,
Widget receiver )
795 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
801 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
807 override void DraggingOver(
Widget w,
int x,
int y,
Widget receiver )
815 bool is_reserved =
false;
818 receiver.GetUserData(slots_icon);
822 receiver_item = slots_icon.GetEntity();
823 is_reserved = slots_icon.IsReserved();
839 if( receiver_item && !is_reserved )
845 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
848 else if( receiver_item.GetInventory().CanAddAttachment(item) || receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ))
852 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
855 else if( (
ItemBase.Cast( receiver_item ) ).CanBeCombined(
ItemBase.Cast( item ) ) )
859 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
865 if( item.GetInventory().CanRemoveEntity() )
867 if(
m_Player.GetInventory().CanAddAttachment( item) )
871 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
877 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
879 else if ( receiver_item &&
GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
883 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
889 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
896 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
901 void OnDropReceivedFromGhostArea(
Widget w,
int x,
int y,
Widget receiver )
907 bool is_reserved =
false;
913 receiver.GetUserData(slots_icon);
914 int slot_id = slots_icon.GetSlotID();
916 receiver_item = slots_icon.GetEntity();
917 is_reserved = slots_icon.IsReserved();
931 if ( receiver_item && !is_reserved )
933 if (
GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
935 GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
939 menu.RefreshQuickbar();
943 else if ( receiver_item.GetInventory().CanAddAttachment( item ) )
945 GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment( receiver_item, item );
949 menu.RefreshQuickbar();
953 else if ( receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ) )
955 SplitItemUtils.TakeOrSplitToInventory(real_player, receiver_item,item);
959 menu.RefreshQuickbar();
963 else if ( (
ItemBase.Cast( receiver_item ) ).CanBeCombined(
ItemBase.Cast( item ) ) )
970 if (
m_Player.GetInventory().CanAddAttachmentEx( item, slot_id ) )
972 if (item.GetQuantity() > item.GetTargetQuantityMax(slot_id))
974 item.SplitIntoStackMaxClient( real_player, slot_id );
978 real_player.PredictiveTakeEntityToTargetAttachmentEx(
m_Player, item, slots_icon.GetSlotID() );
981 else if (
m_Player.GetInventory().CanAddAttachment( item ) )
985 float stackable = item.GetTargetQuantityMax(-1);
989 if ( stackable == 0 || stackable >= item.GetQuantity() )
991 real_player.PredictiveTakeEntityToTargetAttachment( il.GetParent(), item );
996 ItemBase.Cast(item).SplitIntoStackMaxToInventoryLocationClient( il );
1007 menu.RefreshQuickbar();
1011 void SwapItemsInOrder(
int slot1,
int slot2 )
1016 if( item1 && item2 )
1018 Container cont1 = m_ShowedItems.Get( item1 );
1019 Container cont2 = m_ShowedItems.Get( item2 );
1020 if( cont1 && cont2 )
1022 int sort1 = cont1.GetRootWidget().GetSort();
1023 int sort2 = cont2.GetRootWidget().GetSort();
1025 cont1.GetRootWidget().SetSort( sort2 );
1026 cont2.GetRootWidget().SetSort( sort1 );
1028 m_Body.SwapItems( m_Body.Find( cont1 ), m_Body.Find( cont2 ) );
1031 RecomputeOpenedContainers();
1034 override void UpdateInterval()
1037 for ( i = 0; i < m_InventorySlots.Count(); i++ )
1039 SlotsIcon icon = m_InventorySlots.GetElement( i );
1042 icon.UpdateInterval();
1045 for ( i = 0; i < m_ShowedItems.Count(); i++ )
1047 Container cont = m_ShowedItems.GetElement( i );
1050 cont.UpdateInterval();
1059 item.GetInventory().GetCurrentInventoryLocation( il );
1060 SlotsIcon icon = m_InventorySlots.Get( il.GetSlot() );
1069 override bool CanOpenCloseContainerEx(
EntityAI focusedEntity)
1074 if (c && c.IsDisplayable())
1083 void ToggleWidget(
Widget w )
1089 string name = w.GetName();
1090 name.Replace(
"PanelWidget",
"Render" );
1094 ToggleContainer( w, ipw.GetItem() );
1095 RecomputeOpenedContainers();
1101 override void CollapseButtonOnMouseButtonDown(
Widget w)
1103 super.CollapseButtonOnMouseButtonDown(w);
1106 bool IsPlayerEquipmentActive()
1108 if( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
1116 override void Refresh()
1119 m_MainWidget.Update();
1121 UpdateSelectionIcons();