12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598 |
- 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 )
- {
- DayZPlayer player = GetGame().GetPlayer();
- if (player && player.GetHumanInventory().CanRemoveEntityInHands() && !player.GetInventory().HasInventoryReservation(item_in_hands, null))
- {
- bool res = player.PredictiveTakeOrSwapAttachment(item_in_hands);
- if (!res)
- {
- res = player.PredictiveTakeEntityToInventory(FindInventoryLocationType.ATTACHMENT, item_in_hands);
- }
- if (res)
- {
- 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
- if (CanSplitEx(selectedItem))
- {
- selectedItem.OnRightClick();
- }
- 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();
- }
- }
- }
|