4 protected int m_ItemsCount;
5 protected int m_SlotsCount;
12 m_Container.Insert( con );
13 m_Body.Insert( m_Container );
25 WidgetEventHandler.GetInstance().RegisterOnDoubleClick( icon.GetPanelWidget(),
this,
"DoubleClick" );
26 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(),
this,
"MouseClick" );
27 WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( icon.GetPanelWidget(),
this,
"MouseButtonDown" );
30 con.SetColumnCount(0);
31 con.SetForceShow(
true);
39 bool IsItemWithContainerActive()
42 return ent && ( ent.GetInventory().GetCargo() || (ent.GetSlotsCountCorrect() > 0 && ent.CanDisplayAnyAttachmentSlot()) );
46 override bool IsItemWithQuantityActive()
52 override bool IsItemActive()
55 return ent && !IsItemWithQuantityActive() && !IsItemWithContainerActive();
58 bool IsEmptyItemActive()
65 override bool IsDisplayable()
73 return ent.IsTakeable();
76 override bool CanCombineAmmo()
84 return ( amc.CanPerformActionFromInventory( item_in_hands, ent ) || amc.CanSetActionFromInventory( item_in_hands, ent ) );
87 override bool EquipItem()
94 if( ent && !ent.IsInherited( Magazine ))
96 res =
GetGame().GetPlayer().PredictiveTakeOrSwapAttachment( ent );
107 override bool InspectItem()
119 override bool TransferItem()
121 if (CanTakeToInventory())
126 if (ent.IsTakeable())
130 if (il.IsValid() &&
GetGame().
GetPlayer().GetInventory().LocationCanAddEntity( il ))
141 override bool Combine()
147 Icon hands_icon =
ItemManager.GetInstance().GetHandsPreview().GetIcon();
149 if( item_in_hands && ent && hands_icon )
151 return hands_icon.CombineItems( item_in_hands, ent );
156 override bool Select()
162 if( !(selected_slot && selected_slot.IsOutOfReach() ) )
166 if( ent != selected_item)
170 bool draggable =
false;
173 draggable = !player.GetInventory().HasInventoryReservation( selected_item,
null ) && !player.IsItemsToDelete();
174 draggable = draggable && selected_item.GetInventory().CanRemoveEntity();
176 if( draggable && m_ShowedItems.Find( selected_item ) == -1 )
178 if( selected_item.GetTargetQuantityMax() < selected_item.GetQuantity() )
179 selected_item.SplitIntoStackMaxClient(
null, -1 );
181 player.PhysicalPredictiveDropItem( selected_item );
182 ItemManager.GetInstance().SetSelectedItemEx(
null,
null,
null);
190 if( ent && ent.GetInventory().CanRemoveEntity())
192 EntityAI item_in_hands =
GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
197 GetGame().GetPlayer().PredictiveSwapEntities( item_in_hands, ent );
205 GetGame().GetPlayer().PredictiveTakeEntityToHands( ent );
218 for (
int i = 0; i < m_Container.Count(); i++ )
221 if( c && c.GetMainWidget() )
223 delete m_Container.Get( i /
ITEMS_IN_ROW ).GetMainWidget();
228 override void SetLayoutName()
233 override void OnShow()
238 int GetRowSlotCount()
240 return GetFocusedContainer().GetColumnCount();
244 bool ExcludeFromContainer (
EntityAI item)
246 int mask = item.GetHideIconMask();
247 return mask & EInventoryIconVisibility.HIDE_VICINITY;
255 int visible_items_count = 0;
256 int visible_rows = 0;
259 for (
x = 0;
x < items.Count(); ++
x )
261 item = items.Get(
x );
263 if ( item ==
null || ExcludeFromContainer(item) )
266 visible_items.Insert( item );
267 visible_items_count++;
270 RecomputeNumberOfContainers( visible_items );
272 for (
x = 0;
x < visible_items_count; ++
x )
274 item = visible_items.Get(
x );
277 icon =
SlotsContainer.Cast( m_Container.Get( row ) ).GetSlotIcon( column );
279 icon.GetMainWidget().Show(
true );
280 icon.GetPanelWidget().SetUserID( item.GetID() );
282 if ( m_ShowedItems.Find( item ) !=
x )
284 icon.UpdateInterval();
288 ItemManager.GetInstance().SetTemperature( item, icon.GetRender() );
291 bool draggable =
ItemManager.GetInstance().EvaluateContainerDragabilityDefault(item);
292 if ( !draggable &&
GetDragWidget() == icon.GetPanelWidget() )
294 ItemManager.GetInstance().SetWidgetDraggable( icon.GetPanelWidget(), draggable );
301 conta.SetSlotIcon(icon);
304 if ( conta && conta.IsDisplayable() )
306 conta.UpdateRadialIcon();
310 icon.GetRadialIconPanel().Show(
false );
320 icon = slots_last.GetSlotIcon( c );
321 icon.GetMainWidget().Show(
false );
328 slots_last =
SlotsContainer.Cast( m_Container.Get( m_Container.Count() - 1 ) );
329 slots_last.GetSlotIcon( 0 ).GetMainWidget().Show(
true );
330 slots_last.GetSlotIcon( 0 ).GetGhostSlot().Show(
false );
331 slots_last.GetMainWidget().Update();
335 m_ShowedItems = visible_items;
338 void DoubleClick(
Widget w,
int x,
int y,
int button)
349 string name = w.GetName();
350 name.Replace(
"PanelWidget",
"Render" );
365 if( !item.IsTakeable() )
370 if(
GetGame().
GetPlayer().GetInventory().HasInventoryReservation( item,
null ) )
375 if( !item.GetInventory().CanRemoveEntity() )
380 if ( player.GetInventory().HasEntityInInventory( item ) &&
GetGame().
GetPlayer().GetHumanInventory().CanAddEntityInHands( item ) )
382 player.PredictiveTakeEntityToHands( item );
388 if( dst.IsValid() && player.GetInventory().LocationCanAddEntity( dst ) )
398 menu.RefreshQuickbar();
403 string GetItemQuantityText(
EntityAI item )
405 string quantity_text =
"";
409 float quantity = item_base.GetQuantity();
411 if ( item.IsInherited( Magazine ) )
413 Magazine magazine_item = Magazine.Cast( item );
414 ammo = magazine_item.GetAmmoCount();
415 quantity_text = ammo.ToString();
416 return quantity_text;
418 else if ( item.IsInherited( ItemBook ) )
422 int max = item.GetQuantityMax();
429 float tmp =
Math.Round( ( quantity / max ) * 100 );
430 quantity_text = tmp.ToString() +
"%";
434 quantity_text = quantity.ToString();
438 return quantity_text;
441 int HasItemQuantity(
EntityAI item )
446 if ( item.IsInherited( Magazine ) )
450 else if ( item.IsInherited( ItemBook ) )
454 int max = item.GetQuantityMax();
455 bool bar = item.ConfigGetBool(
"quantityBar" );
458 if ( max == 1 || bar )
477 if ( item.IsInherited( Magazine ) )
479 Magazine magazine_item = Magazine.Cast( item );
480 quantity = magazine_item.GetAmmoCount();
484 quantity = item_base.GetQuantity();
491 void MouseButtonDown(
Widget w,
int x,
int y,
int button)
493 string name = w.GetName();
494 name.Replace(
"PanelWidget",
"Render" );
497 bool draggable =
ItemManager.GetInstance().EvaluateContainerDragabilityDefault(item);
498 ItemManager.GetInstance().SetWidgetDraggable( w, draggable );
502 void MouseClick(
Widget w,
int x,
int y,
int button)
504 string name = w.GetName();
505 name.Replace(
"PanelWidget",
"Render" );
507 EntityAI item = item_preview.GetItem();
511 #ifdef DIAG_DEVELOPER
515 ShowActionMenu(
ItemBase.Cast(item) );
523 if( item && showed_items )
525 conta = showed_items.Get( item.GetID() );
532 itemAtPos.OnRightClick();
537 InspectItem( itemAtPos );
544 override void OnDropReceivedFromHeader(
Widget w,
int x,
int y,
Widget receiver )
549 string name = w.GetName();
550 name.Replace(
"PanelWidget",
"Render" );
568 if( !item.GetInventory().CanRemoveEntity() )
571 if( player.CanDropEntity( item ) )
573 if( item.GetTargetQuantityMax() < item.GetQuantity() )
574 item.SplitIntoStackMaxClient(
null, -1 );
576 player.PhysicalPredictiveDropItem( item );
583 int number_of_containers = m_Container.m_Body.Count();
584 int number_of_containers_needed = ( items.Count() /
ITEMS_IN_ROW ) + 1;
585 int difference = number_of_containers_needed - number_of_containers;
588 for (g = number_of_containers; g < number_of_containers_needed; g++)
591 m_Container.Insert(con, -1,
false);
603 WidgetEventHandler.GetInstance().RegisterOnDoubleClick(icon.GetPanelWidget(),
this,
"DoubleClick");
604 WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(),
this,
"MouseClick");
605 WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown(icon.GetPanelWidget(),
this,
"MouseButtonDown");
611 for (g = number_of_containers - 1 ; g >= number_of_containers_needed ; g--)
613 Widget w = m_Container.m_Body.Get(g).GetMainWidget();
615 m_Container.m_Body.Remove(g);
627 for (
int i = 0; i < number_of_containers_needed - 1; i++ )
632 RecomputeOpenedContainers();
633 m_Container.RecomputeOpenedContainers();