1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588 |
- class HandsContainer: Container
- {
- protected bool m_Hidden;
- protected ref HandsHeader m_CollapsibleHeader;
- protected ref HandsPreview m_HandsPreview;
-
- protected ref Attachments m_Atts;
- protected ref CargoContainer m_CargoGrid;
-
- protected ref map<EntityAI, ref CargoContainer> m_AttachmentCargos;
- protected ref map<EntityAI, AttachmentsWrapper> m_AttachmentAttachmentsContainers;
- protected ref map<EntityAI, ref Attachments> m_AttachmentAttachments;
- protected ref array<int> m_AttachmentSlotsSorted;
-
- protected int m_StaticAttCount = 0;
- protected int m_StaticCargoCount = 0;
-
- protected ScrollWidget m_ScrollWidget;
- void HandsContainer( LayoutHolder parent )
- {
- m_AttachmentCargos = new map<EntityAI, ref CargoContainer>;
- m_AttachmentAttachmentsContainers = new map<EntityAI, AttachmentsWrapper>;
- m_AttachmentAttachments = new map<EntityAI, ref Attachments>;
-
- m_CollapsibleHeader = new HandsHeader( this, "CollapseButtonOnMouseButtonDown" );
- GetMainWidget().SetFlags( WidgetFlags.IGNOREPOINTER );
- m_MainWidget = m_MainWidget.FindWidget( "body" );
- GetMainWidget().SetFlags( WidgetFlags.IGNOREPOINTER );
- m_Body = new array<ref LayoutHolder>;
- m_HandsPreview = new HandsPreview( this );
- ItemManager.GetInstance().SetHandsPreview( m_HandsPreview );
- m_Body.Insert( m_HandsPreview );
-
- ItemBase hands_item = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
- if ( hands_item )
- m_HandsPreview.CreateNewIcon( hands_item );
-
- m_ScrollWidget = ScrollWidget.Cast( m_RootWidget.GetParent().GetParent() );
- RecomputeOpenedContainers();
- }
-
- void ~HandsContainer()
- {
- if ( m_Entity )
- {
- m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
- m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
- }
-
- m_AttachmentCargos.Clear();
- m_AttachmentAttachmentsContainers.Clear();
- m_AttachmentAttachments.Clear();
- }
-
- void ResetContainer()
- {
- m_Body.Clear();
- m_Body.Insert( m_HandsPreview );
- }
-
- override Header GetHeader()
- {
- return m_CollapsibleHeader;
- }
-
- override bool IsLastIndex()
- {
- return m_ActiveIndex == m_OpenedContainers.Count() - 1;
- }
-
- void SetFocusToIndex()
- {
- int index = m_ActiveIndex - 1;
- int attachment_start_index = -1;
- int cargo_start_index = -1;
- int attachment_end_index = -1;
- int cargo_end_index = -1;
-
- if ( m_Atts || m_AttachmentAttachments.Count() > 0 )
- {
- attachment_start_index = 0;
- if ( m_Atts )
- attachment_end_index++;
- attachment_end_index += m_AttachmentAttachments.Count();
- }
-
- if ( m_CargoGrid || m_AttachmentCargos.Count() > 0 )
- {
- cargo_start_index = attachment_end_index + 1;
- if ( m_CargoGrid )
- cargo_end_index++;
- cargo_end_index += cargo_start_index + m_AttachmentCargos.Count();
- }
-
- if ( m_ActiveIndex > m_OpenedContainers.Count() )
- {
- m_ActiveIndex = m_OpenedContainers.Count();
- }
-
- if ( index == -1 )
- {
- #ifdef PLATFORM_CONSOLE
- if ( m_MainWidget.FindAnyWidget("Cursor") )
- m_MainWidget.FindAnyWidget("Cursor").Show( true );
- #endif
- m_ScrollWidget.VScrollToPos01( 0 );
- }
- else
- {
- if( index.InRange( 0, attachment_end_index ) )
- {
- if( m_Atts )
- {
- if( index == 0 )
- {
- m_Atts.SetDefaultFocus();
- SetFocusedContainer( m_Atts.GetWrapper() );
- }
- else
- {
- m_AttachmentAttachments.GetElement( index - 1 ).SetDefaultFocus();
- SetFocusedContainer( m_AttachmentAttachments.GetElement( index - 1 ).GetWrapper() );
- }
- }
- else
- {
- m_AttachmentAttachments.GetElement( index ).SetDefaultFocus();
- SetFocusedContainer( m_AttachmentAttachments.GetElement( index ).GetWrapper() );
- }
- }
- else if( index.InRange( cargo_start_index, cargo_end_index ) )
- {
- if( m_CargoGrid )
- {
- if( index == cargo_start_index )
- {
- m_CargoGrid.SetDefaultFocus();
- SetFocusedContainer( m_CargoGrid );
- }
- else
- {
- m_AttachmentCargos.GetElement( index - 1 - cargo_start_index ).SetDefaultFocus();
- SetFocusedContainer( m_AttachmentCargos.GetElement( index - 1 - cargo_start_index ) );
- }
- }
- else
- {
- m_AttachmentCargos.GetElement( index - cargo_start_index ).SetDefaultFocus();
- SetFocusedContainer( m_AttachmentCargos.GetElement( index - cargo_start_index ) );
- }
- }
-
- if( m_MainWidget.FindAnyWidget("Cursor") )
- m_MainWidget.FindAnyWidget("Cursor").Show( false );
- ScrollToActiveContainer( GetFocusedContainer() );
- }
- }
-
- void ScrollToActiveContainer( Container active_container )
- {
- if( !active_container )
- return;
- float x, y, y_s;
- m_ScrollWidget.GetScreenPos( x, y );
- m_ScrollWidget.GetScreenSize( x, y_s );
- float amount;
- float next_pos = active_container.GetFocusedContainerYScreenPos( true ) + active_container.GetFocusedContainerHeight( true );
-
- if( next_pos > ( y + y_s ) )
- {
- amount = y + active_container.GetFocusedContainerYScreenPos( true );
- m_ScrollWidget.VScrollToPos( m_ScrollWidget.GetVScrollPos() + active_container.GetFocusedContainerHeight( true ) + 2 );
- }
- else if( active_container.GetFocusedContainerYScreenPos( true ) < y )
- {
- amount = active_container.GetFocusedContainerYScreenPos( true ) - y;
- m_ScrollWidget.VScrollToPos( m_ScrollWidget.GetVScrollPos() + amount - 2 );
- }
- }
-
- override void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
- {
- super.Insert( container, pos, immedUpdate );
- }
- override bool TransferItem()
- {
- if (m_ActiveIndex == 0)
- {
- if (CanTakeToInventory())
- {
- EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
- if (item_in_hands && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null))
- {
- if (GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item_in_hands ))
- {
- m_MainWidget.FindAnyWidget("Cursor").Show( false );
- m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
- return true;
- }
- }
- }
- }
- else if (GetFocusedContainer())
- {
- return GetFocusedContainer().TransferItem();
- }
- return false;
- }
-
- override bool SplitItem()
- {
- if (CanSplit())
- {
- if (m_ActiveIndex == 0)
- {
- ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
- if ( item_in_hands )
- {
- if ( item_in_hands.CanBeSplit() )
- {
- item_in_hands.OnRightClick();
- }
- }
- }
- else if( GetFocusedContainer() )
- {
- return GetFocusedContainer().SplitItem();
- }
- }
- return false;
- }
-
- override bool EquipItem()
- {
- if (CanEquip())
- {
- if (m_ActiveIndex == 0)
- {
- ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
- if ( item_in_hands )
- {
- if ( GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null) )
- {
- if ( GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, item_in_hands ) )
- {
- m_MainWidget.FindAnyWidget("Cursor").Show( false );
- m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
- return true;
- }
- }
- }
- }
- else if (GetFocusedContainer())
- {
- return GetFocusedContainer().EquipItem();
- }
- }
- return false;
- }
-
- override void SetActive( bool active )
- {
- super.SetActive(active);
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
- if( item_in_hands )
- {
- if( m_MainWidget.FindAnyWidget( "Cursor" ) )
- {
- m_MainWidget.FindAnyWidget( "Cursor" ).Show( active );
- }
-
- if( active )
- {
- float x, y;
- GetMainWidget().GetScreenPos( x, y );
- PrepareOwnedTooltip( item_in_hands, -1, y );
- }
- }
- else
- {
- if (active)
- m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
- else
- m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.7 );
- }
- }
-
- override void SetLastActive()
- {
- super.SetLastActive();
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
- if( item_in_hands )
- {
- if ( m_ActiveIndex == 0)
- {
- if( m_MainWidget.FindAnyWidget( "Cursor" ) )
- {
- m_MainWidget.FindAnyWidget( "Cursor" ).Show( true );
- }
-
- float x, y;
- GetMainWidget().GetScreenPos( x, y );
- PrepareOwnedTooltip( item_in_hands, x, y );
- }
- }
- else
- {
- m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
- }
- }
-
- override void Refresh()
- {
- super.Refresh();
- SetActive( m_IsActive );
- }
-
- override bool IsItemActive()
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
- if( item == null )
- {
- return false;
- }
- return !IsEmpty() && ( !QuantityConversions.HasItemQuantity( item ) || ( QuantityConversions.HasItemQuantity( item ) && !item.CanBeSplit() ) );
- }
-
- override bool IsItemWithQuantityActive()
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
- if( item == null )
- {
- return false;
- }
- return !IsEmpty() && QuantityConversions.HasItemQuantity( item ) && item.CanBeSplit();
- }
-
- override bool IsEmpty()
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- return player.GetHumanInventory().GetEntityInHands() == null;
- }
-
- override bool TransferItemToVicinity()
- {
- if (CanDrop())
- {
- if (m_ActiveIndex == 0)
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- ItemBase item_in_hands = ItemBase.Cast(player.GetHumanInventory().GetEntityInHands());
- if ( item_in_hands && player.CanDropEntity( item_in_hands ) && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !player.GetInventory().HasInventoryReservation(item_in_hands, null) )
- {
- if ( item_in_hands.GetTargetQuantityMax() < item_in_hands.GetQuantity() )
- item_in_hands.SplitIntoStackMaxClient( null, -1 );
- else
- player.PhysicalPredictiveDropItem( item_in_hands );
- m_MainWidget.FindAnyWidget("Cursor").Show( false );
- m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
- return true;
- }
- }
- else if ( GetFocusedContainer() )
- {
- return GetFocusedContainer().TransferItemToVicinity();
- }
- }
- return false;
- }
-
- override bool InspectItem()
- {
- if(m_ActiveIndex == 0)
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
- if( item_in_hands )
- {
- InspectItem( item_in_hands );
- return true;
- }
- }
- else if( GetFocusedContainer() )
- {
- return GetFocusedContainer().InspectItem();
- }
- return false;
- }
-
- override bool OnSelectButton()
- {
- if(m_ActiveIndex == 0)
- {
- if (ItemManager.GetInstance().IsMicromanagmentMode())
- {
- EntityAI selectedItem = ItemManager.GetInstance().GetSelectedItem();
- if( selectedItem == GetFocusedItem() )
- {
- Inventory.GetInstance().DisableMicromanagement();
- return true;
- }
- else
- {
- return Select();
- }
- }
- else
- {
- Inventory.GetInstance().EnableMicromanagement();
- return true;
- }
- }
- else
- {
- if( GetFocusedContainer() )
- {
- return GetFocusedContainer().OnSelectButton();
- }
- }
- return false;
- }
-
- EntityAI GetItemPreviewItem( 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 );
- }
-
- if( !ipw )
- {
- return null;
- }
-
- return ipw.GetItem();
- }
- override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
- {
- if( w == null )
- {
- return;
- }
- EntityAI receiver_item;
- EntityAI slot_owner;
- int slot_id = -1;
-
- string name = w.GetName();
- name.Replace( "PanelWidget", "Render" );
- ItemPreviewWidget w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
- if( w_ipw == null )
- {
- w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
- }
- if( w_ipw == null )
- {
- return;
- }
-
- SlotsIcon slots_icon;
- receiver.GetUserData(slots_icon);
-
- if(slots_icon)
- {
- receiver_item = slots_icon.GetEntity();
- slot_id = slots_icon.GetSlotID();
- slot_owner = slots_icon.GetSlotParent();
- }
-
- PlayerBase p = PlayerBase.Cast( GetGame().GetPlayer() );
- InventoryItem receiver_entity = InventoryItem.Cast( p.GetHumanInventory().GetEntityInHands() );
- InventoryItem w_entity = InventoryItem.Cast( w_ipw.GetItem() );
- if( !w_entity )
- {
- return;
- }
- if( receiver_entity )
- {
- if( receiver_item )
- {
- ItemBase receiver_itemIB = ItemBase.Cast( receiver_item );
- ItemBase itemIB = ItemBase.Cast( receiver_item );
- if( receiver_itemIB && itemIB && receiver_itemIB.CanBeCombined( itemIB ) )
- {
- ItemManager.GetInstance().HideDropzones();
- if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
- {
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else
- {
- ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
- }
- ColorManager.GetInstance().SetColor( w, ColorManager.COMBINE_COLOR );
- }
- else
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- Magazine mag = Magazine.Cast(receiver_item);
- Weapon_Base wpn = Weapon_Base.Cast(receiver_item.GetHierarchyParent());
-
- if( wpn && mag )
- {
- if( player.GetWeaponManager().CanSwapMagazine( wpn, Magazine.Cast(w_entity) ) )
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
- if( w_entity.GetHierarchyRootPlayer() == player )
- {
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else
- {
- ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
- }
- }
- else
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
- ItemManager.GetInstance().ShowSourceDropzone( w_entity );
- }
- }
- else
- {
- if( GameInventory.CanSwapEntitiesEx( receiver_item, w_entity ) )
- {
- ItemManager.GetInstance().HideDropzones();
- if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
- {
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else
- {
- ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
- }
- ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
- }
- else if( receiver_itemIB.GetInventory().CanAddAttachment( w_entity ) )
- {
- ItemManager.GetInstance().HideDropzones();
- if( receiver_itemIB.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
- {
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else
- {
- ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
- }
- ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
- }
- }
- }
- }
- else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( w_entity ) )
- {
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
- ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
- }
- else if( receiver_entity.GetInventory().CanAddAttachment( w_entity ) )
- {
- ItemManager.GetInstance().HideDropzones();
- if( receiver_entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
- {
- ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
- }
- else
- {
- ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
- }
- ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
- }
- else
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
- ItemManager.GetInstance().ShowSourceDropzone( w_entity );
- }
- }
- else
- {
- /*if( m_HandsIcon )
- {
- ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
- }
-
- else
- {*/
- ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
- ItemManager.GetInstance().ShowSourceDropzone( w_entity );
- //}
- }
- }
- void OnDropReceivedFromHeader2( Widget w, int x, int y, Widget receiver )
- {
- TakeAsAttachment( w, receiver );
- }
-
- void OnPerformCombination(int combinationFlags)
- {
- PlayerBase m_player = PlayerBase.Cast( GetGame().GetPlayer() );
- if ( m_am_entity1 == null || m_am_entity2 == null ) return;
- if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
- if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
- {
- Magazine mag;
- if ( Class.CastTo(mag, m_am_entity2 ) )
- {
- m_player.GetWeaponManager().LoadBullet( mag );
- return;
- }
- }
- if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
- {
- if( m_Atts )
- {
- m_Body.RemoveItem( m_Atts.GetWrapper() );
- delete m_Atts;
- }
- if( m_am_entity2.GetSlotsCountCorrect() > 0 )
- {
- m_Atts = new Attachments( this, m_am_entity2 );
- m_Atts.InitAttachmentGrid( 1 );
- }
- Refresh();
- m_Parent.Refresh();
- Weapon_Base wpn1;
- Magazine mag1;
- if ( Class.CastTo(wpn1, m_am_entity1 ) && Class.CastTo(mag1, m_am_entity2 ) )
- {
- if( m_player.GetWeaponManager().CanAttachMagazine(wpn1, mag1) )
- {
- m_player.GetWeaponManager().AttachMagazine(mag1);
- return;
- }
- }
-
- SplitItemUtils.TakeOrSplitToInventory(m_player, m_am_entity1, m_am_entity2);
- //m_player.PredictiveTakeEntityToTargetAttachment( m_am_entity1, m_am_entity2 );
- }
- if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
- {
- m_player.PredictiveTakeEntityToTargetCargo( m_am_entity1, m_am_entity2 );
- }
- if ( combinationFlags & InventoryCombinationFlags.SWAP )
- {
- Magazine swapmag1;
- Magazine swapmag2;
- if (Class.CastTo(swapmag1, m_am_entity1) && Class.CastTo(swapmag2, m_am_entity2 ) )
- {
- if( m_player.GetWeaponManager().CanSwapMagazine( Weapon_Base.Cast( swapmag1.GetParent() ), Magazine.Cast( swapmag2 ) ) )
- {
- m_player.GetWeaponManager().SwapMagazine(swapmag2);
- return;
- }
- if( m_player.GetWeaponManager().CanSwapMagazine(Weapon_Base.Cast( swapmag2.GetParent() ), Magazine.Cast( swapmag1 )) )
- {
- m_player.GetWeaponManager().SwapMagazine(swapmag1);
- return;
- }
- }
- if ( !m_player.PredictiveSwapEntities( m_am_entity1, m_am_entity2 ) && m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity1 ) )
- {
- m_player.PredictiveTakeEntityToHands( m_am_entity1 );
- }
- }
- if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
- {
- if ( m_Atts )
- {
- m_Body.RemoveItem( m_Atts.GetWrapper() );
- delete m_Atts;
- }
- if ( m_am_entity2.GetSlotsCountCorrect() > 0 )
- {
- m_Atts = new Attachments( this, m_am_entity2 );
- m_Atts.InitAttachmentGrid( 1 );
- }
- Refresh();
- m_Parent.Refresh();
-
- if ( m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity2 ) )
- {
- m_player.PredictiveTakeEntityToHands( m_am_entity2 );
- }
- }
- }
- void ShowActionMenuCombine( EntityAI entity1, EntityAI entity2, int combinationFlags )
- {
- if ( entity1 && entity2 ) PrintString( "Showing action menu for " + entity1.GetDisplayName() + " and " + entity2.GetDisplayName() );
- ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());
- m_am_entity1 = entity1;
- m_am_entity2 = entity2;
- cmenu.Hide();
- cmenu.Clear();
- if( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
- {
- ItemBase entity = ItemBase.Cast( entity1 );
- entity.CombineItemsClient( ItemBase.Cast( entity2 ) );
- return;
- }
- if ( entity1 == null || entity2 == null ) return;
- if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
- if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
- {
- cmenu.Add( "#inv_context_add_as_attachment", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_ATTACHMENT ) );
- }
- if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
- {
- cmenu.Add( "#inv_context_load_chamber", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.LOAD_CHAMBER ) );
- }
- if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
- {
- cmenu.Add( "#inv_context_add_as_cargo", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_CARGO ) );
- }
- if ( combinationFlags & InventoryCombinationFlags.SWAP )
- {
- cmenu.Add( "#inv_context_swap", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.SWAP ) );
- }
- if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
- {
- cmenu.Add( "#inv_context_take_to_hands", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.TAKE_TO_HANDS ) );
- }
- if ( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
- {
- cmenu.Add( "#inv_context_combine", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.COMBINE_QUANTITY2 ) );
- }
- int m_am_pos_x, m_am_pos_y;
- GetMousePos( m_am_pos_x, m_am_pos_y );
- m_am_pos_x -= 5;
- m_am_pos_y -= 5;
- cmenu.Show( m_am_pos_x, m_am_pos_y );
- }
- override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
- {
- TakeAsAttachment( w, receiver );
- }
- int GetCombinationFlags( EntityAI entity1, EntityAI entity2 )
- {
- int flags = 0;
- PlayerBase m_player = PlayerBase.Cast( GetGame().GetPlayer() );
- EntityAI entity_in_hands = m_player.GetHumanInventory().GetEntityInHands();
- if (!entity1 || !entity2) return flags;
- Magazine swapmag1;
- Magazine swapmag2;
- bool skipSwap = false;
- if (Class.CastTo(swapmag1, entity1) && Class.CastTo(swapmag2, entity2))
- {
- Weapon_Base parentWpn;
- if (Class.CastTo(parentWpn, swapmag1.GetHierarchyParent()))
- {
- skipSwap = true;
- if (m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag2))
- flags = flags | InventoryCombinationFlags.SWAP;
- }
- if (Class.CastTo(parentWpn, swapmag2.GetHierarchyParent()))
- {
- skipSwap = true;
- if (m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag1))
- flags = flags | InventoryCombinationFlags.SWAP;
- }
- }
- if ( !skipSwap )
- {
- if (entity1 == m_player.GetHumanInventory().GetEntityInHands() ) flags = flags | InventoryCombinationFlags.TAKE_TO_HANDS;
- else if (GameInventory.CanSwapEntitiesEx( entity1, entity2 ))
- {
- if (!entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ))
- {
- flags = flags | InventoryCombinationFlags.SWAP;
- }
- }
- }
- if (entity1.IsInherited( ItemBase) && entity2.IsInherited( ItemBase ))
- {
- ItemBase ent1 = ItemBase.Cast( entity1 );
- if (ent1.CanBeCombined( ItemBase.Cast( entity2 ) )) flags = flags | InventoryCombinationFlags.COMBINE_QUANTITY2;
- }
- else if (entity1.GetInventory().CanAddAttachment( entity2 ))
- {
- if (!entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ) && !entity2.IsInherited( ZombieBase ) && !entity2.IsInherited( Car ))
- {
- flags = flags | InventoryCombinationFlags.ADD_AS_ATTACHMENT;
- }
- }
- if (!entity1.GetInventory().HasEntityInInventory(entity2) && entity1.GetInventory().CanAddEntityInCargo( entity2, entity2.GetInventory().GetFlipCargo() )) flags = flags | InventoryCombinationFlags.ADD_AS_CARGO;
- if (entity1 == m_player.GetHumanInventory().GetEntityInHands() || entity2 == m_player.GetHumanInventory().GetEntityInHands())
- {
- ActionManagerClient amc;
- Class.CastTo(amc, m_player.GetActionManager());
- if (entity1 == m_player.GetHumanInventory().GetEntityInHands())
- {
- if (amc.CanSetActionFromInventory( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ) ))
- {
- flags = flags | InventoryCombinationFlags.SET_ACTION;
- }
- }
- else
- {
- if (amc.CanSetActionFromInventory( ItemBase.Cast( entity2 ), ItemBase.Cast( entity1 ) ))
- {
- flags = flags | InventoryCombinationFlags.SET_ACTION;
- }
- }
- }
- if (GetRecipeCount( true, entity1, entity2 ) > 0)
- {
- flags = flags | InventoryCombinationFlags.RECIPE_ANYWHERE;
- }
- return flags;
- }
- 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() ) );
- }
-
- void RemoveItem()
- {
- m_Entity = null;
- m_CollapsibleHeader.ShowCollapseButtons( false, true );
- }
-
- void DestroyAtt()
- {
- if( m_Atts )
- {
- m_Body.RemoveItem( m_Atts.GetWrapper() );
- delete m_Atts;
-
- if( m_Entity )
- {
- m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
- m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
- }
- }
-
- if( m_AttachmentAttachmentsContainers )
- {
- foreach( EntityAI ent, AttachmentsWrapper att : m_AttachmentAttachmentsContainers )
- {
- m_Body.RemoveItem( att );
- m_AttachmentAttachments.Remove( ent );
- delete att;
- }
- }
-
- m_AttachmentAttachmentsContainers.Clear();
- Refresh();
- m_Parent.Refresh();
- RecomputeOpenedContainers();
- }
-
- override void UnfocusGrid()
- {
- if( m_Atts )
- {
- m_Atts.UnfocusAll();
- }
-
- if( m_CargoGrid )
- {
- m_CargoGrid.UnfocusAll();
- }
-
- if( m_AttachmentCargos )
- {
- foreach( EntityAI e1, CargoContainer cargo : m_AttachmentCargos )
- {
- cargo.UnfocusAll();
-
- }
- }
-
- if( m_AttachmentCargos )
- {
- foreach( EntityAI e2, Attachments att : m_AttachmentAttachments )
- {
- att.UnfocusAll();
- }
- }
- }
-
- override void UnfocusAll()
- {
- UnfocusGrid();
- }
-
- void DestroyCargo()
- {
- if( m_CargoGrid )
- {
- m_Body.RemoveItem( m_CargoGrid );
- delete m_CargoGrid;
- }
-
- if( m_AttachmentCargos )
- {
- foreach( CargoContainer cargo : m_AttachmentCargos )
- {
- m_Body.RemoveItem( cargo );
- delete cargo;
- }
- }
- m_AttachmentCargos.Clear();
- Refresh();
- m_Parent.Refresh();
- RecomputeOpenedContainers();
- }
-
- void DropReceived( Widget w, int x, int y, CargoContainer cargo )
- {
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
-
- EntityAI item = GetItemPreviewItem( w );
- if( !item )
- {
- return;
- }
- int idx = 0;
- int c_x, c_y;
-
- EntityAI target_entity;
- CargoBase target_cargo;
-
- if( cargo == m_CargoGrid )
- {
- target_entity = m_Entity;
- target_cargo = m_Entity.GetInventory().GetCargo();
- #ifdef PLATFORM_CONSOLE
- if( m_CargoGrid.HasItem( item ) )
- {
- return;
- }
- #endif
- }
- else
- {
- target_entity = m_AttachmentCargos.GetKeyByValue( cargo );
- if( target_entity )
- {
- target_cargo = target_entity.GetInventory().GetCargo();
- #ifdef PLATFORM_CONSOLE
- if( cargo.HasItem( item ) )
- {
- return;
- }
- #endif
- }
- else
- return;
- }
-
- if( target_cargo && target_entity )
- {
- c_x = target_cargo.GetHeight();
- c_y = target_cargo.GetWidth();
- }
- else
- return;
- InventoryLocation dst = new InventoryLocation;
- #ifdef PLATFORM_CONSOLE
- x = 0;
- y = target_cargo.GetItemCount();
- target_entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.CARGO, dst );
- #else
- dst.SetCargoAuto(target_cargo, item, x, y, item.GetInventory().GetFlipCargo());
- #endif
-
- InventoryLocation src = new InventoryLocation;
- item.GetInventory().GetCurrentInventoryLocation(src);
- if(src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
- return;
-
- #ifdef PLATFORM_CONSOLE
- if(dst.IsValid() && target_entity.GetInventory().LocationCanAddEntity(dst))
- #else
- if( c_x > x && c_y > y && target_entity.GetInventory().LocationCanAddEntity(dst))
- #endif
- {
- SplitItemUtils.TakeOrSplitToInventoryLocation( player, dst );
- Icon icon = cargo.GetIcon( item );
-
- if( icon )
- {
- if( w && w.FindAnyWidget("Cursor") )
- w.FindAnyWidget("Cursor").SetColor( ColorManager.BASE_COLOR );
- icon.Refresh();
- Refresh();
- }
- }
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().SetIsDragging( false );
- }
-
- bool DraggingOverGrid( Widget w, int x, int y, Widget reciever, CargoContainer cargo )
- {
- EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
- if( w == null )
- {
- return false;
- }
- EntityAI item = GetItemPreviewItem( w );
- if( !item || !item_in_hands )
- {
- return false;
- }
- int color;
- int idx = 0;
- int c_x, c_y;
-
- if( item_in_hands.GetInventory().GetCargo() )
- {
- c_x = item_in_hands.GetInventory().GetCargo().GetHeight();
- c_y = item_in_hands.GetInventory().GetCargo().GetWidth();
- }
-
- if( c_x > x && c_y > y && item_in_hands.GetInventory().CanAddEntityInCargoEx( item, 0, x, y, item.GetInventory().GetFlipCargo() ) )
- {
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
- color = ColorManager.GREEN_COLOR;
- }
- else
- {
- color = ColorManager.RED_COLOR;
- ItemManager.GetInstance().ShowSourceDropzone( item );
- }
- if( w.FindAnyWidget("Cursor") )
- {
- w.FindAnyWidget("Cursor").SetColor( color );
- }
- else
- {
- string name = w.GetName();
- name.Replace( "PanelWidget", "Cursor" );
- w.FindAnyWidget( name ).SetColor( color );
- }
- return true;
- }
-
- void TakeAsAttachment( Widget w, Widget receiver )
- {
- EntityAI receiver_item;
- EntityAI slot_owner;
- int slot_id = -1;
- SlotsIcon slots_icon;
- receiver.GetUserData(slots_icon);
- if( slots_icon )
- {
- receiver_item = slots_icon.GetEntity();
- slot_id = slots_icon.GetSlotID();
- slot_owner = slots_icon.GetSlotParent();
- }
-
- EntityAI item = GetItemPreviewItem( w );
- if( !item )
- {
- return;
- }
-
- ItemBase item_base = ItemBase.Cast( item );
- float stack_max = item_base.GetTargetQuantityMax(slot_id);
-
- PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
- if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
- return;
-
- EntityAI target_att_entity = m_Entity;
- Weapon_Base wpn;
- Magazine mag;
- if( Class.CastTo(wpn, target_att_entity ) && Class.CastTo(mag, item ) )
- {
- if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
- {
- player.GetWeaponManager().AttachMagazine( mag );
- }
- else if(player.GetWeaponManager().CanSwapMagazine( wpn, mag ))
- {
- player.GetWeaponManager().SwapMagazine( mag );
- }
- }
- else if( receiver_item )
- {
- if( receiver_item != item )
- {
- if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
- {
- ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
- }
- else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
- {
- if( !receiver_item.GetInventory().CanRemoveEntity() )
- return;
- GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
- }
- }
- }
- else if( slot_owner && slot_owner.GetInventory().CanAddAttachmentEx( item, slot_id ) )
- {
- if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
- {
- player.PredictiveTakeEntityToTargetAttachmentEx(slot_owner, item, slot_id);
- }
- else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
- {
- item_base.SplitIntoStackMaxClient( slot_owner, slot_id );
- }
- }
- else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( item ) )
- {
- if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
- {
- player.PredictiveTakeEntityToTargetAttachment(slot_owner, item);
- }
- else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
- {
- item_base.SplitIntoStackMaxClient( slot_owner, -1 );
- }
- }
- else if( target_att_entity.GetInventory().CanAddAttachment( item ) )
- {
- if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
- {
- player.PredictiveTakeEntityToTargetAttachment(target_att_entity, item);
- }
- else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
- {
- item_base.SplitIntoStackMaxClient( target_att_entity, -1 );
- }
- }
- else if( ( target_att_entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && ( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item )) ) || player.GetHumanInventory().HasEntityInHands( item ) )
- {
- SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), target_att_entity, item );
- }
- /*else if( !player.GetInventory().HasEntityInInventory( item ) || !target_att_entity.GetInventory().HasEntityInCargo( item ) )
- {
- SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), target_att_entity, item );
- }*/
-
- ItemManager.GetInstance().HideDropzones();
- ItemManager.GetInstance().SetIsDragging( false );
- }
- void ShowAtt( EntityAI entity )
- {
- ResetContainer();
- m_StaticCargoCount = 0;
- m_Entity = entity;
- m_ActiveIndex = 0;
- if( entity.GetSlotsCountCorrect() > 0 )
- {
- m_Atts = new Attachments( this, entity );
- m_Atts.InitAttachmentGrid( 1 );
- m_AttachmentSlotsSorted = m_Atts.GetSlotsSorted();
- m_StaticAttCount = m_Atts.GetAttachmentHeight();
- m_Entity.GetOnItemAttached().Insert( AttachmentAdded );
- m_Entity.GetOnItemDetached().Insert( AttachmentRemoved );
- }
- else
- {
- m_StaticAttCount = 0;
- }
-
- if( entity.GetInventory().GetCargo() )
- {
- m_CargoGrid = new CargoContainer( this, false );
- m_CargoGrid.SetEntity( entity );
- m_CargoGrid.GetRootWidget().SetSort( 1 );
- Insert( m_CargoGrid );
- m_StaticCargoCount++;
- }
-
- if (m_AttachmentSlotsSorted)
- {
- foreach( int slot_id : m_AttachmentSlotsSorted )
- {
- EntityAI item = m_Entity.GetInventory().FindAttachment( slot_id );
- if( item )
- AttachmentAdded( item, InventorySlots.GetSlotName( slot_id ), m_Entity );
- }
- }
- if (m_CargoGrid)
- {
- bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
- if (m_CargoGrid.IsVisible() && hideCargo)
- {
- HideCargo();
- }
- else if (!m_CargoGrid.IsVisible() && !hideCargo)
- {
- ShowCargo();
- }
- }
-
- m_CollapsibleHeader.ShowCollapseButtons(false);
- //m_CollapsibleHeader.ShowCollapseButtons( m_Atts || m_CargoGrid, m_Atts || m_CargoGrid );
- RecomputeOpenedContainers();
- Refresh();
- m_Parent.Refresh();
- }
-
- void RefreshHands()
- {
- for (int i = 0; i < m_Body.Count(); i++)
- {
- m_Body.Get( i ).OnShow();
- }
- Refresh();
- m_Parent.Refresh();
- }
-
- void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
- {
- int slot_id = InventorySlots.GetSlotIdFromString( slot );
- int sort = -1;
- Attachments att_cont = null;
- CargoContainer cont = null;
-
- if( item.GetInventory().GetAttachmentSlotsCount() > 0 )
- {
- att_cont = new Attachments( this, item );
- sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_ATTACHMENTS_NEXT_OFFSET;
- att_cont.InitAttachmentGrid( sort );
-
- m_AttachmentAttachments.Insert( item, att_cont );
- m_AttachmentAttachmentsContainers.Insert( item, att_cont.GetWrapper() );
-
- att_cont.UpdateInterval();
- if( m_Parent )
- m_Parent.Refresh();
- Inventory.GetInstance().UpdateConsoleToolbar();
- }
-
- if( item.GetInventory().GetCargo() )
- {
- cont = new CargoContainer( this, true );
- sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_CARGO_NEXT_OFFSET; //m_AttachmentSlotsSorted.Find( slot_id ) + 50
- cont.GetRootWidget().SetSort( sort );
- cont.SetEntity( item );
-
- Insert(cont, -1);
-
- m_AttachmentCargos.Insert( item, cont );
- if( m_Parent )
- m_Parent.Refresh();
- Inventory.GetInstance().UpdateConsoleToolbar();
- }
-
- if (att_cont)
- {
- att_cont.ShowFalseAttachmentsHeader(true);
- if (cont)
- {
- cont.ShowFalseCargoHeader(false);
- cont.UpdateSize();
- cont.SetAlternateFalseTextHeaderWidget(att_cont.GetFalseHeaderTextWidget());
- }
- }
- else if (cont)
- {
- cont.SetAlternateFalseTextHeaderWidget(null); //just to be safe..
- }
-
- RecomputeOpenedContainers();
- }
-
- void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
- {
- int slot_id = InventorySlots.GetSlotIdFromString( slot );
-
- CargoContainer old_cont = m_AttachmentCargos.Get( item );
- if( old_cont )
- {
- m_Body.RemoveItem( old_cont );
- m_AttachmentCargos.Remove( item );
- delete old_cont;
- if( m_Parent )
- m_Parent.Refresh();
- Inventory.GetInstance().UpdateConsoleToolbar();
- }
-
- AttachmentsWrapper old_att_cont = m_AttachmentAttachmentsContainers.Get( item );
- if( old_att_cont )
- {
- m_AttachmentAttachmentsContainers.Remove( item );
- m_AttachmentAttachments.Remove( item );
- m_Body.RemoveItem( old_att_cont );
- delete old_att_cont;
- if( m_Parent )
- m_Parent.Refresh();
- Inventory.GetInstance().UpdateConsoleToolbar();
- }
- RecomputeOpenedContainers();
- }
- override void UpdateInterval()
- {
- super.UpdateInterval();
-
- if ( m_Entity )
- {
- if (m_CargoGrid)
- {
- bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
- if (m_CargoGrid.IsVisible() && hideCargo)
- {
- HideCargo();
- }
- else if (!m_CargoGrid.IsVisible() && !hideCargo)
- {
- ShowCargo();
- }
-
- m_CargoGrid.UpdateInterval();
- }
-
- if ( m_Atts )
- {
- m_Atts.UpdateInterval();
- }
-
- for ( int i = 0; i < m_AttachmentCargos.Count(); i++ )
- {
- m_AttachmentCargos.GetElement( i ).UpdateInterval();
- }
- }
-
- ElectricityIcon();
- m_CollapsibleHeader.UpdateInterval();
- }
- override void SetLayoutName()
- {
- m_LayoutName = WidgetLayoutName.ClosableContainer;
- }
- override void OnShow()
- {
- super.OnShow();
- for ( int i = 0; i < m_Body.Count(); i++ )
- {
- m_Body.Get( i ).OnShow();
- }
- }
- void MouseClick2(Widget w, int x, int y, int button)
- {
- string name = w.GetName();
- name.Replace("PanelWidget", "Render");
- ItemPreviewWidget itemPreview = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
-
- if (itemPreview)
- {
- ItemBase selectedItem = ItemBase.Cast(itemPreview.GetItem());
-
- if (selectedItem)
- {
- switch (button)
- {
- case MouseState.RIGHT:
- #ifdef DIAG_DEVELOPER
- if (g_Game.IsLeftCtrlDown())
- ShowActionMenu(selectedItem);
- #endif
- break;
-
- case MouseState.MIDDLE:
- InspectItem(selectedItem);
- break;
-
- case MouseState.LEFT:
- 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 = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem, null ) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
- ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
- }
- }
- break;
- }
- }
- }
- }
-
- void DoubleClick(Widget w, int x, int y, int button)
- {
- if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
- {
- 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)
- {
- PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
- EntityAI itemInHands = controlledPlayer.GetHumanInventory().GetEntityInHands();
-
- if (!item.GetInventory().CanRemoveEntity())
- return;
-
- if (controlledPlayer.GetInventory().HasEntityInInventory(item) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
- {
- controlledPlayer.PredictiveTakeEntityToHands(item);
- }
- else
- {
- if (controlledPlayer.GetInventory().CanAddEntityToInventory(item) && controlledPlayer.GetHumanInventory().CanRemoveEntityInHands())
- {
- controlledPlayer.PredictiveTakeEntityToInventory(FindInventoryLocationType.ANY, item);
- }
- else
- {
- if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
- controlledPlayer.PredictiveTakeEntityToHands(item);
- }
- }
-
- HideOwnedTooltip();
-
- name = w.GetName();
- name.Replace("PanelWidget", "Temperature");
- w.FindAnyWidget(name).Show(false);
- }
- }
- }
- void DraggingOverHeader2(Widget w, int x, int y, Widget receiver )
- {
- DraggingOverHeader(w, x, y, receiver );
- }
-
- void ElectricityIcon()
- {
- EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
- if( item_in_hands && item_in_hands.GetCompEM() )
- {
- if( GetRootWidget().FindAnyWidget( "electricity" ) )
- {
- bool show_electricity_icon = item_in_hands.GetCompEM().HasElectricityIcon();
- GetRootWidget().FindAnyWidget( "electricity" ).Show( show_electricity_icon );
- }
-
- if( GetRootWidget().FindAnyWidget( "electricity_can_work" ) )
- {
- bool show_electricity_can_work_icon = item_in_hands.GetCompEM().CanWork() && !item_in_hands.IsRuined();
- GetRootWidget().FindAnyWidget( "electricity_can_work" ).Show( show_electricity_can_work_icon );
- }
- }
- else
- {
- GetRootWidget().FindAnyWidget( "electricity" ).Show( false );
- }
- }
- void CollapseButtonOnMouseButtonDown( Widget w )
- {
- int i;
- if( !m_Hidden )
- {
- for (i = 0; i < m_Body.Count(); i++)
- {
- m_Body.Get( i ).OnHide();
- }
- m_Hidden = true;
- }
- else
- {
- for (i = 0; i < m_Body.Count(); i++)
- {
- m_Body.Get( i ).OnShow();
- }
- m_Hidden = false;
- }
- w.FindAnyWidget("opened").Show(m_Hidden);
- w.FindAnyWidget("closed").Show(!m_Hidden);
-
- m_Parent.Refresh();
- }
-
- void HideCargo()
- {
- if( m_CargoGrid )
- {
- m_CargoGrid.OnHide();
- RecomputeOpenedContainers();
- }
- }
-
- void ShowCargo()
- {
- if( m_CargoGrid )
- {
- m_CargoGrid.OnShow();
- RecomputeOpenedContainers();
- }
- }
- }
|