8 protected bool m_IsProcessing =
false;
10 const float DISTANCE_TO_ENTITIES = 1.0;
11 const float DISTANCE_TO_THE_REST = 0.5;
16 m_Body.Insert( m_VicinityIconsContainer );
17 m_VicinityIconsContainer.GetRootWidget().SetColor(166 << 24 | 120 << 16 | 120 << 8 | 120);
19 WidgetEventHandler.GetInstance().RegisterOnChildAdd( m_MainWidget,
this,
"OnChildAdd" );
20 WidgetEventHandler.GetInstance().RegisterOnChildRemove( m_MainWidget,
this,
"OnChildRemove" );
22 RecomputeOpenedContainers();
23 m_CollapsibleHeader.SetName(
"#container_vicinity");
27 bool IsVicinityContainerIconsActive()
29 return m_VicinityIconsContainer.IsActive();
34 return m_VicinityIconsContainer;
37 bool IsContainerWithCargoActive()
39 return ( ContainerWithCargo.Cast( GetFocusedContainer() ) !=
null );
42 bool IsItemWithAttachmentsActive()
44 return ( ContainerWithCargoAndAttachments.Cast( GetFocusedContainer() ) !=
null );
47 bool IsItemWithCategoriesActive()
52 void TraverseShowedItems()
55 for (
int i = 0; i < m_ShowedItems.Count(); i++ )
57 EntityAI entity = m_ShowedItems.GetKey( i );
58 Container container = m_ShowedItems.GetElement( i );
59 string type = entity.GetType();
60 if ( container.IsInherited( ContainerWithCargo ) )
62 if ( !serialized_types.Contains( type ) )
64 ContainerWithCargo item_with_cargo = ContainerWithCargo.Cast( container );
65 serialized_types.Insert( type, item_with_cargo.IsOpened() );
70 if ( serialized_types.Count() > 0 )
73 if ( file.Open(
"inventory_state.save",
FileMode.APPEND ) )
75 file.Write( serialized_types.Count() );
77 for ( i = 0; i < serialized_types.Count(); i++ )
79 file.Write( serialized_types.GetKey( i ) );
80 file.Write( serialized_types.GetElement( i ) );
87 override void DraggingOverHeader(
Widget w,
int x,
int y,
Widget receiver )
97 string name = w.GetName();
98 name.Replace(
"PanelWidget",
"Render" );
107 if ( !ipw || !ipw.GetItem() )
112 if ( ipw.GetItem() &&
GetGame().
GetPlayer().CanDropEntity( ipw.GetItem() ) && ipw.GetItem().GetInventory().CanRemoveEntity() && m_ShowedItemIcons.Find( ipw.GetItem() ) == -1 )
116 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
121 ItemManager.GetInstance().ShowSourceDropzone( ipw.GetItem() );
127 string name = receiver.GetName();
128 name.Replace(
"PanelWidget",
"Render");
130 EntityAI receiver_item = receiver_iw.GetItem();
136 name.Replace(
"PanelWidget",
"Render" );
150 if ( !
ItemBase.Cast( receiver_item ) || !ipw.GetItem() )
155 if ( ipw.GetItem().GetInventory().CanRemoveEntity() || m_ShowedItemIcons.Find( ipw.GetItem() ) > -1 )
157 if ( (
ItemBase.Cast( receiver_item ) ).CanBeCombined(
ItemBase.Cast( ipw.GetItem() ) ) )
161 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
164 else if (
GameInventory.CanSwapEntitiesEx( receiver_item, ipw.GetItem() ) )
168 ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
181 ItemManager.GetInstance().ShowSourceDropzone( ipw.GetItem() );
184 void OnDropReceivedFromIcon(
Widget w,
int x,
int y,
Widget receiver )
186 string name = receiver.GetName();
187 name.Replace(
"PanelWidget",
"Render");
189 EntityAI receiver_item = receiver_iw.GetItem();
195 name.Replace(
"PanelWidget",
"Render" );
199 if ( !
ItemBase.Cast( receiver_item ) || !ipw.GetItem() )
205 bool equal_typed = item.GetType() == receiver_item.GetType();
206 if ( !receiver_item.IsInherited(
ItemBase ) || item ==
null )
213 if ( !item.GetInventory().CanRemoveEntity() )
216 if ( (
ItemBase.Cast( receiver_item ) ).CanBeCombined(
ItemBase.Cast( item ) ) )
220 else if(
GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
224 receiver_item.GetInventory().GetCurrentInventoryLocation( il1 );
225 item.GetInventory().GetCurrentInventoryLocation( il2 );
229 player.PredictiveSwapEntities( item, receiver_item );
234 PrepareOwnedTooltip(item);
239 menu.RefreshQuickbar();
243 void OnLeftPanelDropReceived(
Widget w,
int x,
int y,
Widget receiver )
245 OnDropReceivedFromHeader( w,
x,
y, receiver );
248 void OnDropReceivedFromEmptySpace(
Widget w,
int x,
int y,
Widget receiver )
250 OnDropReceivedFromHeader( w,
x,
y, receiver );
253 override void OnDropReceivedFromHeader(
Widget w,
int x,
int y,
Widget receiver)
265 string name = w.GetName();
266 name.Replace(
"PanelWidget",
"Render");
281 if (!item.GetInventory().CanRemoveEntity() || m_ShowedItemIcons.Find(item) > -1)
285 if (player.CanDropEntity(item))
290 if (itemBase.GetTargetQuantityMax() < itemBase.GetQuantity())
291 itemBase.SplitIntoStackMaxClient(
null, -1);
293 player.PhysicalPredictiveDropItem(itemBase);
300 menu.RefreshQuickbar();
304 override void UpdateInterval()
311 super.UpdateInterval();
314 vector pos = player.GetPosition();
322 int m_OldShowedItemIconsCount = m_ShowedItemIcons.Count();
323 m_ShowedItemIcons.Clear();
326 for (
int i = 0; i < objects.Count(); i++ )
328 eai = objects.Get( i );
329 if ( eai ==
null || game_inventory.IsPlaceholderEntity( eai ) )
333 if (base_building && !base_building.IsPlayerInside(player,
""))
336 if ( eai.IsInventoryVisible() )
338 showable_items.Insert( eai );
342 m_ShowedItemIcons.Insert( eai );
352 for ( i = 0; i < showable_items.Count(); i++ )
354 new_showed_items.Insert(showable_items[i],
null);
358 bool need_update_focus =
false;
359 for ( i = 0; i < m_ShowedItems.Count(); i++ )
361 EntityAI ent = m_ShowedItems.GetKey( i );
362 m_ShowedItems.GetElement( i ).UpdateInterval();
363 con = m_ShowedItems.GetElement( i );
364 if ( !new_showed_items.Contains( ent ) )
366 GetMainWidget().Update();
367 if ( con.IsActive() )
368 need_update_focus =
true;
374 UpdateHeader(ent,con,player);
379 bool accessInventory =
PlayerBase.DEBUG_INVENTORY_ACCESS;
380 accessInventory |= FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive();
384 new_showed_items.Clear();
386 for ( i = 0; i < showable_items.Count(); i++ )
388 EntityAI entity = showable_items.Get( i );
391 if ( game_inventory && !m_ShowedItems.Contains( entity ) )
393 string config =
"CfgVehicles " + entity.GetType() +
" GUIInventoryAttachmentsProps";
395 if (
GetGame().ConfigIsExisting( config ) )
398 ac.SetEntity( entity );
399 new_showed_items.Insert( entity, ac );
400 showed_items_IDs.Insert( entity.GetID(), ac);
402 else if ( entity.GetSlotsCountCorrect() > 0 && entity.GetInventory().GetCargo() )
406 if ( entity.IsAlive() )
411 zmb_cnt.SetEntity( entity );
412 new_showed_items.Insert( entity, zmb_cnt );
413 showed_items_IDs.Insert( entity.GetID(), zmb_cnt );
418 ContainerWithCargoAndAttachments iwca =
new ContainerWithCargoAndAttachments(
this, -1 );
419 iwca.SetEntity( entity,
false );
420 new_showed_items.Insert( entity, iwca );
421 showed_items_IDs.Insert( entity.GetID(), iwca );
424 else if ( entity.GetInventory().GetCargo() )
426 ContainerWithCargo iwc =
new ContainerWithCargo(
this, -1 );
427 iwc.SetEntity( entity, 0,
false );
428 new_showed_items.Insert( entity, iwc );
429 showed_items_IDs.Insert( entity.GetID(), iwc );
430 iwc.UpdateInterval();
432 else if ( entity.GetSlotsCountCorrect() > 0 )
434 if ( entity.HasEnergyManager() )
437 iwem.SetEntity( entity,
false );
438 new_showed_items.Insert( entity, iwem );
439 showed_items_IDs.Insert( entity.GetID(), iwem );
446 if (accessInventory ==
false)
448 if ( entity.IsAlive() && ( !
PlayerBase.Cast( entity ).IsUnconscious() && !
PlayerBase.Cast( entity ).IsRestrained() ) )
455 plyr_cnt.SetPlayer(
PlayerBase.Cast( entity ) );
458 new_showed_items.Insert( entity, plyr_cnt );
459 showed_items_IDs.Insert( entity.GetID(), plyr_cnt);
463 ContainerWithCargoAndAttachments iwcas =
new ContainerWithCargoAndAttachments(
this, -1 );
464 iwcas.SetEntity( entity,
false );
465 new_showed_items.Insert( entity, iwcas );
466 showed_items_IDs.Insert( entity.GetID(), iwcas );
467 iwcas.UpdateInterval();
475 con = m_ShowedItems.Get( entity );
481 if ( !accessInventory && entity.IsAlive() && ( !
PlayerBase.Cast( entity ).IsUnconscious() && !
PlayerBase.Cast( entity ).IsRestrained() ) )
483 GetMainWidget().Update();
484 if ( con.IsActive() )
485 need_update_focus =
true;
496 GetMainWidget().Update();
497 if ( con.IsActive() )
498 need_update_focus =
true;
505 new_showed_items.Insert( entity, m_ShowedItems.Get( entity ) );
506 showed_items_IDs.Insert( entity.GetID(), m_ShowedItemsIDs.Get( entity.GetID() ) );
514 for ( i = 0; i < cargoes.Count(); i++ )
519 if (game_inventory && !m_ShowedCargos.Contains( cgo ) )
521 ContainerWithCargo pxc =
new ContainerWithCargo(
this, -1 );
522 pxc.SetEntity( cgo.GetCargoOwner(), cgo.GetOwnerCargoIndex(),
false );
523 new_showed_cargos.Insert( cgo, pxc );
524 pxc.UpdateInterval();
528 if ( m_ShowedCargos.Get( cgo ) )
530 new_showed_cargos.Insert( cgo, m_ShowedCargos.Get( cgo ) );
536 for (
int ic = 0; ic < m_ShowedCargos.Count(); ic++ )
538 CargoBase cgo2 = m_ShowedCargos.GetKey( ic );
539 m_ShowedCargos.GetElement( ic ).UpdateInterval();
540 if ( !new_showed_cargos.Contains( cgo2 ) )
542 Container con2 = m_ShowedCargos.GetElement( ic );
543 if( con2.IsActive() )
544 need_update_focus =
true;
545 GetMainWidget().Update();
551 m_ShowedItems = new_showed_items;
552 m_ShowedItemsIDs = showed_items_IDs;
553 m_ShowedCargos = new_showed_cargos;
556 if (need_update_focus)
559 UpdateCollapseButtons();
560 m_VicinityIconsContainer.ShowItemsInContainers( m_ShowedItemIcons );
562 if ( m_ShowedItemIcons.Count() != m_OldShowedItemIconsCount )
566 in.UpdateConsoleToolbar();
574 w.GetUserData(slots_icon);
578 c =
Container.Cast( m_ShowedItems.Get( item ) );
587 override bool CanOpenCloseContainerEx(
EntityAI focusedEntity)
592 if (c && c.IsDisplayable())
601 void ToggleContainer( notnull
Container conta )
606 override void ExpandCollapseContainer()
611 if (m_ShowedItems && item)
613 conta = m_ShowedItems.Get( item );
616 ToggleContainer( conta );
625 w.GetScreenSize(
x,
y );
626 if ( w == GetMainWidget() )
628 GetMainWidget().Update();
636 if ( w == GetMainWidget() )
638 GetMainWidget().Update();
644 override void CollapseButtonOnMouseButtonDown(
Widget w)
646 super.CollapseButtonOnMouseButtonDown(w);
647 ItemManager.GetInstance().SetDefaultHeaderOpenState(
"VICINITY", !m_Hidden );
653 bool draggable =
ItemManager.GetInstance().EvaluateContainerDragabilityDefault(entity);
655 if (cont.GetHeader())
661 ItemManager.GetInstance().SetWidgetDraggable(cont.GetHeader().GetMainWidget(),draggable);
665 override bool SplitItem()
672 if (item.HasQuantity() && item.CanBeSplit())