4 protected ref CargoContainer m_CargoGrid;
9 protected ref
array<int> m_AttachmentSlotsSorted;
11 void ContainerWithCargoAndAttachments(
LayoutHolder parent,
int sort = -1 )
13 WidgetEventHandler.GetInstance().RegisterOnDraggingOver( m_MainWidget,
this,
"DraggingOverHeader2" );
16 void ~ContainerWithCargoAndAttachments()
20 m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
21 m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
32 if ( m_AttachmentAttachments )
33 m_AttachmentAttachments.Clear();
35 if ( m_AttachmentAttachmentsContainers )
36 m_AttachmentAttachmentsContainers.Clear();
38 if ( m_AttachmentCargos )
39 m_AttachmentCargos.Clear();
42 void RecomputeContainers()
48 m_Body.Insert(m_Atts.GetWrapper());
53 m_Body.Insert(m_CargoGrid);
57 for (
int i = 0; i < inv.AttachmentCount(); i++)
59 EntityAI ent = inv.GetAttachmentFromIndex(i);
68 CargoContainer cargo = m_AttachmentCargos.Get(ent);
77 void AttachmentAddedEx(
EntityAI item,
string slot,
EntityAI parent,
bool immedUpdate =
true)
81 bool updateNeeded =
false;
83 ref CargoContainer cont =
null;
85 if ( item.GetInventory().GetAttachmentSlotsCount() > 0 && item.CanDisplayAnyAttachmentSlot() )
90 sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_ATTACHMENTS_NEXT_OFFSET;
91 att_cont.InitAttachmentGrid( sort );
93 m_AttachmentAttachments.Insert( item, att_cont );
94 m_AttachmentAttachmentsContainers.Insert( item, att_cont.GetWrapper() );
96 att_cont.UpdateInterval();
99 if ( item.GetInventory().GetCargo() )
103 cont =
new CargoContainer(
this,
true );
104 sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_CARGO_NEXT_OFFSET;
105 cont.GetRootWidget().SetSort( sort );
106 cont.SetEntity( item,
false );
107 Insert( cont, m_Atts.GetAttachmentHeight() + m_AttachmentCargos.Count() + 1 );
109 m_AttachmentCargos.Insert( item, cont );
116 att_cont.ShowFalseAttachmentsHeader(
true);
119 cont.ShowFalseCargoHeader(
false);
121 cont.SetAlternateFalseTextHeaderWidget(att_cont.GetFalseHeaderTextWidget());
126 cont.SetAlternateFalseTextHeaderWidget(
null);
129 RecomputeContainers();
130 RecomputeOpenedContainers();
132 Inventory.GetInstance().UpdateConsoleToolbar();
141 AttachmentAddedEx(item, slot, parent);
148 CargoContainer old_cont = m_AttachmentCargos.Get( item );
151 m_AttachmentCargos.Remove( item );
156 Inventory.GetInstance().UpdateConsoleToolbar();
163 m_AttachmentAttachmentsContainers.Remove( item );
164 m_AttachmentAttachments.Remove( item );
169 Inventory.GetInstance().UpdateConsoleToolbar();
172 RecomputeContainers();
173 RecomputeOpenedContainers();
182 bool hideCargo =
m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !
m_Entity.CanDisplayCargo() || m_ForcedHide;
183 if (m_CargoGrid.IsVisible() && hideCargo)
187 else if (!m_CargoGrid.IsVisible() && !hideCargo)
192 m_CargoGrid.UpdateInterval();
202 m_SlotIcon.GetRadialIconPanel().Show( !hide );
206 super.UpdateInterval();
210 override EntityAI GetFocusedContainerEntity()
215 override void UnfocusAll()
224 m_CargoGrid.UnfocusAll();
227 foreach(
EntityAI e1, CargoContainer cargo : m_AttachmentCargos )
239 override bool IsLastIndex()
241 return m_ActiveIndex == ( m_OpenedContainers.Count() - 1 );
244 override bool IsFirstContainerFocused()
246 return IsFirstIndex();
249 override bool IsLastContainerFocused()
251 return IsLastIndex();
254 override void MoveGridCursor(
int direction )
259 c.MoveGridCursor( direction );
260 Inventory.GetInstance().UpdateConsoleToolbar();
264 void SetEntity(
EntityAI entity,
bool immedUpdate =
true )
269 m_Atts.InitAttachmentGrid( SORT_ATTACHMENTS_OWN );
270 m_AttachmentSlotsSorted = m_Atts.GetSlotsSorted();
272 m_Entity.GetOnItemAttached().Insert( AttachmentAdded );
273 m_Entity.GetOnItemDetached().Insert( AttachmentRemoved );
275 m_ClosableHeader.SetItemPreview(
m_Entity );
276 CheckHeaderDragability();
278 if (
m_Entity.GetInventory().GetCargo() )
280 m_CargoGrid =
new CargoContainer(
this,
false );
281 m_CargoGrid.GetRootWidget().SetSort( SORT_CARGO_OWN );
282 m_CargoGrid.SetEntity(
m_Entity, 0, immedUpdate );
283 m_CargoGrid.UpdateHeaderText();
284 Insert( m_CargoGrid );
290 m_ClosableHeader.SetName(
name );
299 foreach (
int slot_id : m_AttachmentSlotsSorted )
306 RecomputeContainers();
310 bool hideCargo =
m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !
m_Entity.CanDisplayCargo() || m_ForcedHide;
311 if (m_CargoGrid.IsVisible() && hideCargo)
315 else if (!m_CargoGrid.IsVisible() && !hideCargo)
321 if( IsDisplayable() )
322 SetOpenState(
true );
324 SetOpenState(
false );
329 RecomputeOpenedContainers();
336 if(m_CargoGrid.IsVisible())
338 m_CargoGrid.OnHide();
339 RecomputeOpenedContainers();
348 if(!m_CargoGrid.IsVisible())
350 m_CargoGrid.OnShow();
351 RecomputeOpenedContainers();
363 string name = w.GetName();
364 name.Replace(
"PanelWidget",
"Render" );
373 string name = w.GetName();
374 name.Replace(
"PanelWidget",
"Render" );
385 return ipw.GetItem();
393 string name = w.GetName();
394 name.Replace(
"PanelWidget",
"Render" );
404 void MouseClick2(
Widget w,
int x,
int y,
int button)
411 selectedItem =
ItemBase.Cast(icon.GetEntity());
415 bool isReserved = icon.IsReserved();
420 #ifdef DIAG_DEVELOPER
422 ShowActionMenu(selectedItem);
427 EntityAI attachmentParent = icon.GetSlotParent();
428 GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced(selectedItem);
429 attachmentParent.GetOnAttachmentReleaseLock().Invoke(selectedItem, icon.GetSlotID());
436 InspectItem(selectedItem);
444 if (
g_Game.IsLeftCtrlDown())
446 if (controlledPlayer.CanDropEntity(selectedItem))
448 if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
449 selectedItem.SplitIntoStackMaxClient(
null, -1);
451 controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
456 bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem,
null ) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
457 ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
467 void DropReceived(
Widget w,
int x,
int y, CargoContainer cargo)
469 EntityAI item = GetItemPreviewItem(w);
473 #ifndef PLATFORM_CONSOLE
480 if (cargo != m_CargoGrid)
482 targetEntity = m_AttachmentCargos.GetKeyByValue(cargo);
487 targetCargo = targetEntity.GetInventory().GetCargo();
488 #ifdef PLATFORM_CONSOLE
489 if (m_CargoGrid && m_CargoGrid.HasItem(item))
494 if (!targetCargo || !targetEntity)
498 #ifdef PLATFORM_CONSOLE
500 y = targetCargo.GetItemCount();
503 c_x = targetCargo.GetHeight();
504 c_y = targetCargo.GetWidth();
506 dst.SetCargoAuto(targetCargo, item,
x,
y, item.GetInventory().GetFlipCargo());
510 item.GetInventory().GetCurrentInventoryLocation(src);
511 if (src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
514 #ifdef PLATFORM_CONSOLE
515 if (dst.IsValid() && targetEntity.GetInventory().LocationCanAddEntity(dst))
517 if (c_x >
x && c_y >
y && targetEntity.GetInventory().LocationCanAddEntity(dst))
524 Icon icon = cargo.GetIcon(item);
527 if (w && w.FindAnyWidget(
"Cursor"))
528 w.FindAnyWidget(
"Cursor").SetColor(
ColorManager.BASE_COLOR);
546 bool is_reserved =
false;
548 receiver.GetUserData(slots_icon);
555 receiver_item = slots_icon.GetEntity();
556 slot_id = slots_icon.GetSlotID();
557 attached_entity = slots_icon.GetSlotParent();
558 is_reserved = slots_icon.IsReserved();
561 EntityAI item = GetItemPreviewItem( w );
571 if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
579 if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
581 player.GetWeaponManager().AttachMagazine( mag );
584 else if( receiver_item && !is_reserved )
586 if( (
ItemBase.Cast( receiver_item ) ).CanBeCombined(
ItemBase.Cast( item ) ) )
590 else if(
GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
592 if( !receiver_item.GetInventory().CanRemoveEntity() )
594 GetGame().GetPlayer().PredictiveSwapEntities( receiver_item, item );
596 else if( receiver_item.GetInventory().CanAddAttachment( item ) )
598 player.PredictiveTakeEntityToTargetAttachment(receiver_item, item);
601 else if( attached_entity && attached_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
603 stackable = item_base.GetTargetQuantityMax(slot_id);
604 if( stackable == 0 || stackable >= item_base.GetQuantity() )
606 player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, slot_id);
608 else if( stackable != 0 && stackable < item_base.GetQuantity() )
610 item_base.SplitIntoStackMaxClient( attached_entity, slot_id );
613 else if(attached_entity && attached_entity.GetInventory().CanAddAttachment(item))
616 stackable = item_base.GetTargetQuantityMax(il.GetSlot());
617 if( stackable == 0 || stackable >= item_base.GetQuantity() )
619 player.PredictiveTakeEntityToTargetAttachmentEx(attached_entity, item, il.GetSlot());
621 else if( stackable != 0 && stackable < item_base.GetQuantity() )
623 item_base.SplitIntoStackMaxClient( attached_entity, il.GetSlot() );
626 else if(
m_Entity.GetInventory().CanAddAttachment(item) )
629 stackable = item_base.GetTargetQuantityMax(il.GetSlot());
630 if( stackable == 0 || stackable >= item_base.GetQuantity() )
632 player.PredictiveTakeEntityToTargetAttachmentEx(
m_Entity, item, il.GetSlot());
634 else if( stackable != 0 && stackable < item_base.GetQuantity() )
636 item_base.SplitIntoStackMaxClient(
m_Entity, il.GetSlot() );
639 else if(
m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !
m_Entity.GetInventory().HasEntityInCargo( item ) )
649 override void OnDropReceivedFromHeader(
Widget w,
int x,
int y,
Widget receiver )
651 TakeAsAttachment( w, receiver );
654 void OnDropReceivedFromHeader2(
Widget w,
int x,
int y,
Widget receiver )
656 TakeAsAttachment( w, receiver );
659 void DoubleClick(
Widget w,
int x,
int y,
int button)
664 if( w == NULL || player.GetInventory().IsInventoryLocked() )
671 string name = w.GetName();
672 name.Replace(
"PanelWidget",
"Render" );
689 iw.GetUserData(icon);
691 if(icon && icon.IsReserved())
696 if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
699 if( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
701 player.PredictiveTakeEntityToHands( item );
705 if(player.GetInventory().CanAddEntityToInventory( item ) && item.GetInventory().CanRemoveEntity())
711 if( player.GetHumanInventory().CanAddEntityInHands( item ) )
713 player.PredictiveTakeEntityToHands( item );
721 name.Replace(
"PanelWidget",
"Temperature" );
722 w.FindAnyWidget(
name ).Show(
false );
726 bool DraggingOverGrid(
Widget w,
int x,
int y,
Widget reciever, CargoContainer cargo )
733 EntityAI item = GetItemPreviewItem( w );
747 if( cargo == m_CargoGrid )
750 target_cargo =
m_Entity.GetInventory().GetCargo();
754 target_entity = m_AttachmentCargos.GetKeyByValue( cargo );
757 target_cargo = target_entity.GetInventory().GetCargo();
763 if( target_cargo && target_entity )
765 c_x = target_cargo.GetHeight();
766 c_y = target_cargo.GetWidth();
771 if( c_x >
x && c_y >
y && target_entity.GetInventory().CanAddEntityInCargoEx( item, idx,
x,
y, item.GetInventory().GetFlipCargo() ) )
776 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
780 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
788 if( w.FindAnyWidget(
"Cursor") )
790 w.FindAnyWidget(
"Cursor").SetColor( color );
794 string name = w.GetName();
795 name.Replace(
"PanelWidget",
"Cursor" );
796 if( w.FindAnyWidget(
name ) )
798 w.FindAnyWidget(
name ).SetColor( color );
805 override void DraggingOver(
Widget w,
int x,
int y,
Widget receiver )
807 DraggingOverHeader( w,
x,
y, receiver );
810 override void DraggingOverHeader(
Widget w,
int x,
int y,
Widget receiver )
816 EntityAI item = GetItemPreviewItem( w );
823 receiver.GetUserData(slots_icon);
827 bool is_reserved =
false;
832 attached_entity = slots_icon.GetSlotParent();
833 slot_id = slots_icon.GetSlotID();
834 receiver_item = slots_icon.GetEntity();
835 is_reserved = slots_icon.IsReserved();
846 if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
851 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
855 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
860 else if( receiver_item && !is_reserved )
864 if( receiver_itemIB && itemIB && receiver_itemIB.CanBeCombined( itemIB ) )
869 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
873 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
877 else if(
GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
882 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
886 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
890 else if( receiver_itemIB.GetInventory().CanAddAttachment( item ) )
895 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
899 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
904 else if( attached_entity && attached_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
909 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
913 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
917 else if(
m_Entity.GetInventory().CanAddAttachment( item ) )
922 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
926 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
930 else if( (
m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !
m_Entity.GetInventory().HasEntityInCargo( item ) ) )
935 ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
939 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
945 ItemManager.GetInstance().ShowSourceDropzone( item );