3 protected string m_CategoryIdentifier;
4 protected string m_RowConfigPath;
5 protected bool m_Refreshing;
16 m_Body.Insert(m_AttachmentsContainer);
18 m_ClosableHeader.GetMainWidget().ClearFlags(
WidgetFlags.DRAGGABLE );
20 RecomputeOpenedContainers();
23 string GetCategoryIdentifier()
25 return m_CategoryIdentifier;
33 return icon.GetSlotID();
38 override bool Select()
40 Man player =
GetGame().GetPlayer();
41 SlotsIcon focused_icon = GetFocusedSlotsIcon();
42 EntityAI focused_item = GetFocusedItem();
43 Container focused_cont = GetFocusedContainer();
46 if( selected_item && focused_item != selected_item)
48 if( selected_item.GetInventory().CanRemoveEntity() )
56 focused_cont.Select();
59 else if( !focused_item &&
m_Entity &&
m_Entity.GetInventory().CanAddAttachmentEx( selected_item, focused_icon.GetSlotID() ) )
61 stack_max =
InventorySlots.GetStackMaxForSlotId( focused_icon.GetSlotID() );
62 float quantity = selected_item.GetQuantity();
63 if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
65 player.PredictiveTakeEntityToTargetAttachmentEx(
m_Entity, selected_item, focused_icon.GetSlotID() );
70 selected_item.SplitIntoStackMaxClient(
m_Entity, focused_icon.GetSlotID() );
74 else if (focused_icon.GetSlotID() != -1)
76 if (focused_item && focused_item.GetHierarchyParent() && focused_item.GetHierarchyParent().GetInventory().CanAddAttachment(selected_item))
79 focused_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
80 stack_max =
InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
81 quantity = focused_item.GetQuantity();
82 if( focused_item.CanBeCombined(
ItemBase.Cast( selected_item ) ) )
84 focused_item.CombineItemsClient( selected_item,
true );
87 else if( stack_max == 0 &&
GameInventory.CanSwapEntitiesEx( focused_item, selected_item ) )
89 player.PredictiveSwapEntities( selected_item, focused_item );
92 else if( m_AttachmentCargos.Contains( inv_loc.GetSlot() ) )
94 if( focused_item.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo() ) )
106 if( focused_item && focused_item.GetInventory().CanRemoveEntity() && (!focused_icon || !focused_icon.IsOutOfReach()) )
108 EntityAI item_in_hands =
GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
109 if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
111 if(
GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
113 player.PredictiveSwapEntities( item_in_hands, focused_item );
119 if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
121 player.PredictiveTakeEntityToHands( focused_item );
131 override bool TransferItem()
133 if (CanTakeToInventory())
136 SlotsIcon focused_icon = GetFocusedSlotsIcon();
137 if( entity && !entity.IsLockedInSlot() && (!focused_icon || !focused_icon.IsOutOfReach()) )
147 override bool TransferItemToVicinity()
153 SlotsIcon focused_icon = GetFocusedSlotsIcon();
155 if (item && !item.IsLockedInSlot() && (focused_icon && !focused_icon.IsOutOfReach()))
157 if (item.GetTargetQuantityMax() < item.GetQuantity())
158 item.SplitIntoStackMaxClient(
null, -1 );
160 player.PhysicalPredictiveDropItem( item );
167 override bool Combine()
171 Man player =
GetGame().GetPlayer();
173 ItemBase selected_item =
ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
174 SlotsIcon focused_icon = GetFocusedSlotsIcon();
178 int selected_slot = GetFocusedSlot();
180 if( selected_item && selected_item.GetInventory().CanRemoveEntity() && (focused_icon && !focused_icon.IsOutOfReach()) )
182 if( !prev_item &&
m_Entity.GetInventory().CanAddAttachmentEx( selected_item, selected_slot ) )
185 float quantity = selected_item.GetQuantity();
186 if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
188 player.PredictiveTakeEntityToTargetAttachmentEx(
m_Entity, selected_item, selected_slot );
193 selected_item.SplitIntoStackMaxClient(
m_Entity, selected_slot );
197 else if( selected_slot != -1 )
202 prev_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
203 stack_max =
InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
204 quantity = prev_item.GetQuantity();
205 if( prev_item.CanBeCombined(
ItemBase.Cast( selected_item ) ) )
207 prev_item.CombineItemsClient( selected_item,
true );
210 else if( stack_max == 0 &&
GameInventory.CanSwapEntitiesEx( prev_item, selected_item ) )
212 player.PredictiveSwapEntities( selected_item, prev_item );
215 else if( m_AttachmentCargos.Contains( inv_loc.GetSlot() ) )
217 if( prev_item.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo() ) )
231 override bool CanSplitEx(
EntityAI focusedItem)
236 override bool SplitItem()
241 override bool EquipItem()
246 override bool CanCombine()
248 Man player =
GetGame().GetPlayer();
250 ItemBase selected_item =
ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
251 SlotsIcon focused_icon = GetFocusedSlotsIcon();
255 int selected_slot = GetFocusedSlot();
257 if( selected_item && selected_item.GetInventory().CanRemoveEntity() && (focused_icon && !focused_icon.IsOutOfReach()) )
259 if(
m_Entity.GetInventory().CanAddAttachmentEx( selected_item, selected_slot ) )
262 float quantity = selected_item.GetQuantity();
263 if( stack_max == 0 || stack_max >= quantity || !selected_item.CanBeSplit() )
272 else if( selected_slot != -1 )
277 prev_item.GetInventory().GetCurrentInventoryLocation( inv_loc );
278 stack_max =
InventorySlots.GetStackMaxForSlotId( inv_loc.GetSlot() );
279 quantity = prev_item.GetQuantity();
280 if( prev_item.CanBeCombined(
ItemBase.Cast( selected_item ) ) )
291 override bool CanCombineAmmo()
296 override bool IsItemActive()
299 return GetFocusedItem() !=
null && (!icon || !icon.IsOutOfReach());
302 override bool IsItemWithQuantityActive()
306 return item && ( !icon || !icon.IsOutOfReach()) && item.CanBeSplit();
309 override void OnDropReceivedFromHeader(
Widget w,
int x,
int y,
Widget receiver )
316 bool is_reserved =
false;
318 receiver.GetUserData(slots_icon);
319 float stackable = 0.0;
324 receiver_item = slots_icon.GetEntity();
325 slot_id = slots_icon.GetSlotID();
326 attached_entity = slots_icon.GetSlotParent();
327 is_reserved = slots_icon.IsReserved();
330 EntityAI item = GetItemPreviewItem( w );
338 if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
346 if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
348 player.GetWeaponManager().AttachMagazine( mag );
351 else if( receiver_item && !is_reserved )
353 if( (
ItemBase.Cast( receiver_item ) ).CanBeCombined(
ItemBase.Cast( item ) ) )
357 else if(
GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
359 if( !receiver_item.GetInventory().CanRemoveEntity() )
361 GetGame().GetPlayer().PredictiveSwapEntities( receiver_item, item );
363 else if( receiver_item.GetInventory().CanAddAttachment( item ) )
365 player.PredictiveTakeEntityToTargetAttachment(receiver_item, item);
368 else if( attached_entity && slot_id != -1 && attached_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
371 stackable = item_base.GetTargetQuantityMax( slot_id );
373 if( stackable == 0 || stackable >= item_base.GetQuantity() )
375 player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, slot_id);
377 else if( stackable != 0 && stackable < item_base.GetQuantity() )
379 item_base.SplitIntoStackMaxClient(
m_Entity, slot_id );
382 else if(attached_entity && slot_id == -1 && attached_entity.GetInventory().FindFreeLocationFor(item,
FindInventoryLocationType.ATTACHMENT,il))
385 stackable = item_base.GetTargetQuantityMax( il.GetSlot() );
387 if( stackable == 0 || stackable >= item_base.GetQuantity() )
389 player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, il.GetSlot());
391 else if( stackable != 0 && stackable < item_base.GetQuantity() )
393 item_base.SplitIntoStackMaxClient(
m_Entity, il.GetSlot() );
402 override void UnfocusAll()
405 for ( i = 1; i <
Count(); i++ )
409 Widget w =
Get( i ).GetMainWidget().FindAnyWidget(
"Cursor" + j );
414 for ( i = 0; i < m_AttachmentCargos.Count(); i++ )
416 m_AttachmentCargos.GetElement( i ).Unfocus();
417 m_AttachmentCargos.GetElement( i ).SetActive(
false );
421 override void DraggingOverHeader(
Widget w,
int x,
int y,
Widget receiver )
430 string name = w.GetName();
431 name.Replace(
"PanelWidget",
"Render");
439 if( !iw || !iw.GetItem() || (iw.GetItem() ==
m_Entity) )
446 name = receiver.GetName();
447 name.Replace(
"PanelWidget",
"Render");
450 receiver_item =
ItemBase.Cast( receiver_iw.GetItem() );
453 receiver.GetUserData(slots_icon);
457 int stack_max =
InventorySlots.GetStackMaxForSlotId( receiver_item.GetInventory().GetSlotId(0) );
460 if( receiver_item.CanBeCombined(
ItemBase.Cast( iw.GetItem() ) ) )
463 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
466 else if( stack_max == 0 &&
GameInventory.CanSwapEntitiesEx( receiver_item, iw.GetItem() ) )
469 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
474 ItemManager.GetInstance().ShowSourceDropzone( iw.GetItem() );
478 else if( slots_icon && slots_icon.GetSlotID() != -1 )
480 item =
ItemBase.Cast( iw.GetItem() );
482 if( item &&
m_Entity.GetInventory().CanAddAttachmentEx( item, slots_icon.GetSlotID() ) )
485 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
490 ItemManager.GetInstance().ShowSourceDropzone( iw.GetItem() );
496 ItemManager.GetInstance().ShowSourceDropzone( iw.GetItem() );
501 bool DraggingOverGrid(
Widget w,
int x,
int y,
Widget reciever, CargoContainer cargo )
508 EntityAI item = GetItemPreviewItem( w );
522 target_entity = cargo.GetEntity() ;
525 target_cargo = target_entity.GetInventory().GetCargo();
530 if( target_cargo && target_entity )
532 c_x = target_cargo.GetHeight();
533 c_y = target_cargo.GetWidth();
538 if( c_x >
x && c_y >
y && target_entity.GetInventory().CanAddEntityInCargoEx( item, idx,
x,
y, item.GetInventory().GetFlipCargo() ) )
547 if( w.FindAnyWidget(
"Cursor") )
549 w.FindAnyWidget(
"Cursor").SetColor( color );
553 string name = w.GetName();
554 name.Replace(
"PanelWidget",
"Cursor" );
555 if( w.FindAnyWidget(
name ) )
557 w.FindAnyWidget(
name ).SetColor( color );
564 void DropReceived(
Widget w,
int x,
int y, CargoContainer cargo )
566 EntityAI item = GetItemPreviewItem( w );
578 target_entity = cargo.GetEntity();
581 target_cargo = target_entity.GetInventory().GetCargo();
586 if( target_cargo && target_entity )
588 c_x = target_cargo.GetHeight();
589 c_y = target_cargo.GetWidth();
595 dst.SetCargoAuto(target_cargo, item,
x,
y, item.GetInventory().GetFlipCargo());
597 if( c_x >
x && c_y >
y && target_entity.GetInventory().LocationCanAddEntity(dst))
603 Icon icon = cargo.GetIcon( item );
607 icon.GetCursorWidget().SetColor(
ColorManager.BASE_COLOR );
608 icon.RefreshPos(
x,
y );
620 string name = w.GetName();
621 name.Replace(
"PanelWidget",
"Render" );
632 return ipw.GetItem();
635 override void Refresh()
647 void RefreshAllSlots()
650 int row_count = m_AttachmentsContainer.GetRowCount();
652 for (row = 0; row < row_count; row++)
654 int col_count = m_AttachmentsContainer.GetColumnCountForRow(row);
656 for (col = 0; col < col_count; col++)
658 RefreshSlot(row, col, -1,
"");
661 m_Refreshing =
false;
665 void RefreshSlot(
int row,
int column,
int slot_id,
string slot_name )
667 SlotsIcon icon = m_AttachmentsContainer.GetSlotsIcon(row, column);
668 int slot_id_ = icon.GetSlotID();
670 ContainerWithCargo cont;
672 if (!
m_Entity.CanDisplayAttachmentSlot(slot_id_))
675 icon.GetMainWidget().Show(
false );
679 if (icon.GetEntity())
681 icon.ClearRemainSelected();
683 cont = m_AttachmentCargos.Get(slot_id_);
686 m_AttachmentCargos.Remove(slot_id_);
691 icon.GetMainWidget().Show(
true);
695 icon.GetMainWidget().Show(
true );
696 if (icon.GetEntity() != item)
705 cont = m_AttachmentCargos.Get(slot_id_);
706 if( cont && cont.GetEntity() != item)
708 m_AttachmentCargos.Remove(slot_id_);
716 if( item.GetInventory().GetCargo() && m_AttachmentCargos )
718 cont =
new ContainerWithCargo(
this,
true );
719 cont.GetRootWidget().SetSort( m_AttachmentCargos.Count() + 10 );
720 cont.SetEntity( item );
721 cont.SetSlotIcon( icon );
723 m_AttachmentCargos.Insert( slot_id_, cont );
724 icon.SetContainer(cont);
726 SetOpenForSlotIcon(cont.IsOpened(),icon);
732 icon.GetRadialIconPanel().Show( cont.IsDisplayable() );
736 bool draggable =
true;
737 bool can_be_removed = item.GetInventory().CanRemoveEntity();
738 bool in_hands_condition =
m_Entity.GetHierarchyRoot() ==
GetGame().GetPlayer();
740 if(
m_Entity.GetInventory().GetSlotLock( slot_id_ ) &&
ItemManager.GetInstance().GetDraggedItem() != item )
742 icon.GetMountedWidget().Show(
true );
747 icon.GetMountedWidget().Show(
false );
750 if( !
m_Entity.CanReleaseAttachment( item ) )
755 if ((in_hands_condition || in_vicinity_condition) && can_be_removed)
757 icon.GetOutOfReachWidget().Show(
false );
761 icon.GetOutOfReachWidget().Show(
true );
767 icon.GetRender().GetParent().SetFlags(
WidgetFlags.DRAGGABLE );
771 icon.GetRender().GetParent().ClearFlags(
WidgetFlags.DRAGGABLE );
776 void DoubleClick(
Widget w,
int x,
int y,
int button)
783 string name = w.GetName();
784 name.Replace(
"PanelWidget",
"Render");
794 if (icon &&
m_Entity.GetInventory().GetSlotLock(iw.GetUserID()))
797 if (icon.IsOutOfReach())
803 if (!item.GetInventory().CanRemoveEntity())
807 if (controlledPlayer.GetInventory().HasEntityInInventory(item) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
809 controlledPlayer.PredictiveTakeEntityToHands(item);
813 if (controlledPlayer.GetInventory().CanAddEntityToInventory(item) && item.GetInventory().CanRemoveEntity())
815 if (item.GetTargetQuantityMax() < item.GetQuantity())
816 item.SplitIntoStackMaxClient(controlledPlayer, -1);
822 if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
824 if (item.GetTargetQuantityMax() < item.GetQuantity())
825 item.SplitIntoStackMaxHandsClient(controlledPlayer);
827 controlledPlayer.PredictiveTakeEntityToHands(item);
835 name.Replace(
"PanelWidget",
"Temperature");
836 w.FindAnyWidget(
name).Show(
false);
841 void MouseClick(
Widget w,
int x,
int y,
int button)
847 selectedItem =
ItemBase.Cast(icon.GetEntity());
854 #ifdef DIAG_DEVELOPER
855 if (
g_Game.IsLeftCtrlDown())
856 ShowActionMenu(selectedItem);
862 InspectItem(selectedItem);
867 if (
g_Game.IsLeftCtrlDown())
869 if (icon.IsOutOfReach())
872 if (controlledPlayer.CanDropEntity(selectedItem))
874 if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
875 selectedItem.SplitIntoStackMaxClient(
null, -1);
877 controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
881 bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem,
null ) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
882 ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
897 void Init(
int attachments_categories_count,
int i,
string attachment_category,
string config_path_attachment_categories,
EntityAI entity,
int parent_m_Body_count )
902 m_CategoryIdentifier = attachment_category;
907 m_RowConfigPath = config_path_attachment_categories +
" " + attachment_category +
" attachmentSlots";
908 string config_path_category_name = config_path_attachment_categories +
" " + attachment_category +
" name";
909 GetGame().ConfigGetTextArray(m_RowConfigPath, player_ghosts_slots2);
910 GetGame().ConfigGetText(config_path_category_name, categoryName);
911 header.SetName(categoryName);
913 m_AttachmentsContainer.SetHeader(header);
916 int count = player_ghosts_slots2.Count();
920 for (
int j = 0; j < count; j++ )
922 string slotName = player_ghosts_slots2.Get(j);
928 GetGame().ConfigGetText(
path +
" ghostIcon", iconName);
936 slotsContainer.GetRootWidget().SetAlpha(0.7);
942 m_AttachmentsContainer.Insert(slotsContainer);
943 slotsContainer.GetRootWidget().SetSort(row);
946 SlotsIcon icon = slotsContainer.GetSlotIcon(column);
947 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetMainWidget(),
this,
"OnDropReceivedFromHeader");
948 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetGhostSlot(),
this,
"OnDropReceivedFromHeader");
949 WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetPanelWidget(),
this,
"OnDropReceivedFromHeader");
951 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetMainWidget(),
this,
"DraggingOverHeader");
952 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetGhostSlot(),
this,
"DraggingOverHeader");
953 WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetPanelWidget(),
this,
"DraggingOverHeader");
955 WidgetEventHandler.GetInstance().RegisterOnDrop(icon.GetMainWidget(),
this,
"OnIconDrop");
956 WidgetEventHandler.GetInstance().RegisterOnDrop(icon.GetPanelWidget(),
this,
"OnIconDrop");
958 WidgetEventHandler.GetInstance().RegisterOnDoubleClick(icon.GetPanelWidget(),
this,
"DoubleClick");
959 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(),
this,
"MouseClick");
962 icon.SetSlotID(slotId);
963 icon.SetSlotDisplayName(
InventorySlots.GetSlotDisplayName(slotId));
970 override void UpdateInterval()
972 super.UpdateInterval();