1 const string SLOT_LAYOUT_1x1 =
"{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
2 const string SLOT_LAYOUT_2x1 =
"{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
3 const string SLOT_LAYOUT_2x2 =
"{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
4 const string SLOT_LAYOUT_3x3 =
"{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
29 [
Attribute(
"1", UIWidgets.ComboBox,
"Slot size",
"", ParamEnumArray.FromEnum(
ESlotSize) )]
31 protected int m_iSizeX;
32 protected int m_iSizeY;
33 protected int m_iPage;
35 private WorkspaceWidget m_workspaceWidget =
null;
36 Widget m_widget =
null;
37 private ButtonWidget m_wButton;
38 private ImageWidget m_wIcon =
null;
39 private RenderTargetWidget m_wPreviewImage =
null;
46 const string ITEM_LAYOUT =
"{0921F9EB5F3843BA}UI/layouts/Menus/Inventory/Inventory20Item.layout";
47 const int LMB_CLICK = 0;
48 const int RMB_CLICK = 1;
49 const int MID_CLICK = 2;
50 protected bool m_bEnabled =
true;
51 protected bool m_bSelected =
false;
52 protected bool m_bBlocked =
false;
53 protected Widget m_wSelectedEffect, m_wSelectedIcon , m_wMoveEffect, m_wDimmerEffect, m_wBlockedEffect;
54 protected TextWidget m_wTextQuickSlot =
null;
55 protected TextWidget m_wTextQuickSlotLarge =
null;
56 protected int m_iQuickSlotIndex;
58 protected ProgressBarWidget m_wVolumeBar, m_wAmmoCount, m_wCurrentMagazineAmmoCount;
59 protected int m_iStackNumber = 1;
60 protected TextWidget m_wStackNumber, m_wMagazineNumber;
61 protected OverlayWidget m_wItemLockThrobber;
62 protected string m_sItemName =
"";
63 protected int m_aAmmoCountActual = -1;
64 protected int m_aAmmoCountMax = -1;
67 protected bool m_bVisible;
71 protected const string FUEL_WIDGET_HOLDER_NAME =
"FuelCountHolder";
72 protected const string FUEL_WIDGET_FILL_NAME =
"FuelFill";
73 protected ImageWidget m_wFuelCount;
76 #ifdef DEBUG_INVENTORY20
77 protected TextWidget m_wDbgClassText1;
78 protected TextWidget m_wDbgClassText2;
79 protected TextWidget m_wDbgClassText3;
93 if (m_pItem && m_pItem.GetAttributes())
101 if (vehicleAttributes && !ShouldVehicleSlotBeVisible(vehicleAttributes))
104 m_workspaceWidget =
GetGame().GetWorkspace();
105 Widget wGrid = m_pStorageUI.GetStorageGrid();
110 m_widget = m_workspaceWidget.CreateWidgets( SetSlotSize(), wGrid );
111 m_widget.AddHandler(
this );
118 m_iStackNumber = stackNumber;
132 protected string SetSlotSize()
145 protected void Init()
150 m_wTextQuickSlot = TextWidget.Cast( m_widget.FindAnyWidget(
"TextQuickSlot" ) );
151 m_sItemName = GetItemName();
154 m_pItem.m_OnLockedStateChangedInvoker.Insert(OnChangeLockState);
158 SetItemFunctionality();
160 if (!BaseInventoryStorageComponent.Cast(m_pItem) && !WeaponAttachmentsStorageComponent.Cast(m_pItem))
163 if (m_pStorageUI && m_pStorageUI.GetInventoryMenuHandler())
164 m_pStorageUI.GetInventoryMenuHandler().RegisterUIStorage(
this);
169 BaseInventoryStorageComponent GetStorageComponent() {
return BaseInventoryStorageComponent.Cast(m_pItem); }
177 if ( !pClothComponent )
180 return pClothComponent.GetAreaType();
185 void SetStackNumber(
int i ) { m_iStackNumber = i; }
186 void IncreaseStackNumber() { m_iStackNumber++; }
187 void IncreaseStackNumber(
int i ) { m_iStackNumber = m_iStackNumber + i; }
191 protected void SetAmmoCount()
193 Widget ammoSizeCountHolder = GetWidget().FindAnyWidget(
"SizeAmmoCount");
198 MagazineComponent pMagazineComponent = MagazineComponent.Cast( m_pItem.GetOwner().FindComponent( MagazineComponent ) );
199 if (!pMagazineComponent)
202 m_aAmmoCountActual = pMagazineComponent.GetAmmoCount();
203 m_aAmmoCountMax = pMagazineComponent.GetMaxAmmoCount();
205 if (ammoSizeCountHolder)
206 ammoSizeCountHolder.SetVisible(
true);
210 protected void OnFuelAmountChanged(
float newFuelValue)
215 m_wFuelCount.SetMaskProgress(1 - (newFuelValue /
m_FuelManager.GetTotalMaxFuel()));
219 protected void InitFuelAmount()
221 m_wFuelCount = ImageWidget.Cast(m_widget.FindAnyWidget(FUEL_WIDGET_FILL_NAME));
225 m_FuelManager.GetOnFuelChanged().Insert(OnFuelAmountChanged);
228 Widget fuelCountHolder = m_widget.FindAnyWidget(FUEL_WIDGET_HOLDER_NAME);
230 fuelCountHolder.SetVisible(
true);
234 Widget GetButtonWidget() {
return m_wButton; }
238 bool IsSlotBlocked() {
return m_bBlocked; }
243 void SetSlotVisible(
bool bVisible )
246 m_widget.SetEnabled(bVisible);
247 m_widget.SetVisible(bVisible);
251 m_wPreviewImage = RenderTargetWidget.Cast( m_widget.FindAnyWidget(
"item" ) );
256 ItemPreviewManagerEntity manager = world.GetItemPreviewManager();
260 IEntity previewEntity =
null;
262 previewEntity = m_pItem.GetOwner();
264 manager.SetPreviewItem(renderPreview, previewEntity,
null,
true);
269 BaseInventoryStorageComponent pStorageTo = GetStorageComponent();
272 m_wVolumeBar = ProgressBarWidget.Cast( m_widget.FindAnyWidget(
"VolumeBar" ) );
273 m_wVolumeBar.SetVisible(
true );
275 m_wSelectedEffect = m_widget.FindAnyWidget(
"SelectedOverlay");
276 m_wSelectedIcon = m_widget.FindAnyWidget(
"SelectedIcon");
277 m_wMoveEffect = m_widget.FindAnyWidget(
"IconMove" );
278 m_wDimmerEffect = m_widget.FindAnyWidget(
"Dimmer" );
279 m_wBlockedEffect = m_widget.FindAnyWidget(
"Blocker");
280 m_wButton = ButtonWidget.Cast( m_widget.FindAnyWidget(
"ItemButton" ) );
281 m_wStackNumber = TextWidget.Cast( m_widget.FindAnyWidget(
"stackNumber" ) );
282 m_wItemLockThrobber = OverlayWidget.Cast(m_widget.FindAnyWidget(
"itemLockThrobber"));
284 if ( m_iStackNumber > 1 )
286 m_wStackNumber.SetText( m_iStackNumber.ToString() );
287 m_wStackNumber.SetVisible(
true );
291 m_wStackNumber.SetVisible(
false );
294 m_wAmmoCount = ProgressBarWidget.Cast( m_widget.FindAnyWidget(
"ammoCount" ) );
304 m_wMagazineNumber = TextWidget.Cast( m_widget.FindAnyWidget(
"magazineCount" ) );
305 m_wCurrentMagazineAmmoCount = ProgressBarWidget.Cast( m_widget.FindAnyWidget(
"currentMagazineAmmoCount" ) );
306 if ( m_wMagazineNumber && m_wCurrentMagazineAmmoCount )
308 UpdateWeaponAmmoCount();
311 #ifdef DEBUG_INVENTORY20
314 array<string> dbgText =
new array<string>();
315 this.ToString().Split(
"<", dbgText,
false );
316 m_wDbgClassText1 = TextWidget.Cast( m_widget.FindAnyWidget(
"dbgTextClass1" ) );
317 m_wDbgClassText2 = TextWidget.Cast( m_widget.FindAnyWidget(
"dbgTextClass2" ) );
318 m_wDbgClassText3 = TextWidget.Cast( m_widget.FindAnyWidget(
"dbgTextClass3" ) );
319 m_wDbgClassText1.SetText( dbgText[0] );
320 m_wDbgClassText1.SetEnabled(
true );
321 m_wDbgClassText1.SetVisible(
true );
322 m_wDbgClassText2.SetText( dbgText[1] );
323 m_wDbgClassText2.SetEnabled(
true );
324 m_wDbgClassText2.SetVisible(
true );
325 m_pItem.ToString().Split(
"<", dbgText,
false );
326 if ( dbgText.Count() > 1 )
328 m_wDbgClassText3.SetText( dbgText[1] );
329 m_wDbgClassText3.SetEnabled(
true );
330 m_wDbgClassText3.SetVisible(
true );
334 UpdateVolumeBarValue();
339 m_wPreviewImage =
null;
340 m_wSelectedEffect =
null;
341 m_wSelectedIcon =
null;
342 m_wMoveEffect =
null;
343 m_wDimmerEffect =
null;
346 m_wTextQuickSlot =
null;
347 m_wTextQuickSlotLarge =
null;
348 m_wStackNumber =
null;
349 #ifdef DEBUG_INVENTORY20
350 m_wDbgClassText1 =
null;
351 m_wDbgClassText2 =
null;
352 m_wDbgClassText3 =
null;
359 void SetSlotBlocked(
bool bBlocked)
361 m_bBlocked = bBlocked;
363 if (!m_wBlockedEffect || !m_wDimmerEffect)
366 if (m_wBlockedEffect.IsVisible() == bBlocked)
369 m_wDimmerEffect.SetVisible(bBlocked);
370 m_wBlockedEffect.SetVisible(bBlocked);
375 int GetSlotIndex() {
return m_iQuickSlotIndex; }
379 void SetQuickSlotIndexVisible( TextWidget textQuickSlot,
bool bVisible )
383 textQuickSlot.SetText( ( (m_iQuickSlotIndex + 1) % 10 ).ToString() );
384 textQuickSlot.SetVisible( bVisible );
394 m_pStorageUI.SetSlotFocused(
this,
true );
398 #ifdef DEBUG_INVENTORY20
400 BaseInventoryStorageComponent dbgStorage;
403 if ( m_pStorageUI.GetStorage() )
405 dbgStorage = m_pStorageUI.GetStorage();
406 if ( m_pStorageUI.GetStorage().GetParentSlot() )
407 dbgStorageParentSlot = m_pStorageUI.GetStorage().GetParentSlot();
410 PrintFormat(
"INV:OnSlotFocused | m_pStorageUI: %1 | Focused slotUI: %2 | Parent storage: %3 | from parent slot: %4", m_pStorageUI,
this, dbgStorage, dbgStorageParentSlot );
412 pMenuManager.SetSlotFocused(
this, GetStorageUI(),
true );
417 override bool OnMouseEnter( Widget w,
int x,
int y )
427 override bool OnMouseLeave( Widget w, Widget enterW,
int x,
int y )
437 void OnSlotFocusLost()
441 m_pStorageUI.SetSlotFocused(
this,
false );
444 pMenuManager.SetSlotFocused(
this, m_pStorageUI,
false );
448 void ToggleSelected()
451 if (!m_wSelectedEffect || !m_wSelectedIcon)
455 m_wSelectedIcon.SetVisible(
false);
459 void SetSelected(
bool select )
466 if (!m_wSelectedEffect || !m_wSelectedIcon)
469 m_wSelectedEffect.SetVisible(select);
473 void SetEnabled(
bool enable )
480 m_widget.SetEnabled( enable );
492 void SetEnabledForMove(
int iSelect )
498 m_widget.SetEnabled(
false );
500 m_wMoveEffect.SetVisible(
false );
505 m_widget.SetEnabled(
true );
507 m_wMoveEffect.SetVisible(
true );
513 m_widget.SetEnabled(
true );
515 m_wMoveEffect.SetVisible(
false );
525 BaseInventoryStorageComponent GetAsStorage() {
return BaseInventoryStorageComponent.Cast( m_pItem ); }
535 protected UIInfo GetItemDetails()
545 UIInfo itemDetails = GetItemDetails();
548 return itemDetails.GetName();
552 protected void SetItemDetails()
554 UIInfo itemDetails = GetItemDetails();
562 if (inventoryItemDetails)
563 m_pStorageUI.ShowItemDetails(inventoryItemDetails.GetInventoryItemName(m_pItem), inventoryItemDetails.GetInventoryItemDescription(m_pItem),
m_Attributes.GetWeight().ToString());
565 m_pStorageUI.ShowItemDetails(itemDetails.GetName(), itemDetails.GetDescription(),
m_Attributes.GetWeight().ToString());
570 void ClearItemDetails()
573 m_pStorageUI.ShowItemDetails(
"",
"",
"" );
578 protected void SetImage(
string resource,
string imageName )
580 if ( resource ==
string.Empty || imageName ==
string.Empty ||
m_wIcon ==
null )
583 m_wIcon.LoadImageFromSet( 0, resource, imageName );
585 m_wIcon.GetImageSize( 0, width, height );
590 protected SCR_InventoryStorageManagerComponent GetInventoryManager() {
return m_pStorageUI.GetInventoryManager(); }
595 SCR_InventoryStorageManagerComponent invMan = GetInventoryManager();
596 if (!invMan || !invMan.CanMoveItem(m_pItem.GetOwner()))
601 auto pStorage = pSlot.GetStorage();
604 if(!invMan.CanRemoveItemFromStorage(m_pItem.GetOwner(), pStorage))
611 invMan.TryRemoveItemFromInventory(m_pItem.GetOwner(), pStorage);
617 m_widget.RemoveHandler(
this );
618 m_widget.RemoveFromHierarchy();
620 m_pStorageUI.RemoveSlotUI(
this );
628 void SetItemFunctionality()
632 IEntity item = m_pItem.GetOwner();
643 if (MagazineComponent.Cast(item.FindComponent(MagazineComponent)))
650 if (WeaponComponent.Cast(item.FindComponent(WeaponComponent)))
656 if (SCR_GadgetComponent.Cast(item.FindComponent(SCR_GadgetComponent)))
664 SCR_CharacterInventoryStorageComponent GetCharacterStorage(IEntity entity)
666 ChimeraCharacter character = ChimeraCharacter.Cast(entity);
670 CharacterControllerComponent controller = character.GetCharacterController();
674 SCR_InventoryStorageManagerComponent storageManager = GetInventoryManager();
678 return storageManager.GetCharacterStorage();
682 void UseItem(IEntity player)
687 IEntity item = m_pItem.GetOwner();
691 SCR_CharacterInventoryStorageComponent storage = GetCharacterStorage(player);
695 if (storage.UseItem(item, m_eSlotFunction))
700 bool CanUseItem(IEntity player)
705 IEntity item = m_pItem.GetOwner();
709 SCR_CharacterInventoryStorageComponent storage = GetCharacterStorage(player);
713 return storage.CanUseItem(item, m_eSlotFunction);
719 IEntity vehicle = m_pItem.GetOwner();
721 if (dm && dm.IsDestroyed())
726 if (attr.GetVisibleInVehicleOnly() && !player.IsInVehicle())
729 if (!attr.GetVisibleForVehicleFactionOnly())
732 if (!Vehicle.Cast(vehicle))
733 vehicle = vehicle.GetParent();
735 FactionAffiliationComponent vehicleFaction = FactionAffiliationComponent.Cast(vehicle.FindComponent(FactionAffiliationComponent));
736 if (!vehicleFaction || !vehicleFaction.GetAffiliatedFaction())
739 FactionAffiliationComponent playerFaction = FactionAffiliationComponent.Cast(player.FindComponent(FactionAffiliationComponent));
740 if (!playerFaction || !playerFaction.GetAffiliatedFaction())
743 return (playerFaction.GetAffiliatedFaction() == vehicleFaction.GetAffiliatedFaction());
748 protected void UpdateVolumeBarValue()
750 if ( m_wVolumeBar && m_pItem )
752 BaseInventoryStorageComponent pStorage = GetAsStorage();
757 if ( pStorage.GetAttributes() && pStorage.GetAttributes().GetUIInfo() )
759 name = pStorage.GetAttributes().GetUIInfo().GetName();
762 float fOccupied = 0.0;
764 if ( pStorage.Type() == ClothNodeStorageComponent )
766 array<BaseInventoryStorageComponent> pOwnedStorages =
new array<BaseInventoryStorageComponent>();
767 pStorage.GetOwnedStorages( pOwnedStorages, 1,
false );
768 foreach ( BaseInventoryStorageComponent pSubStorage : pOwnedStorages )
769 fOccupied += pSubStorage.GetOccupiedSpace();
773 fOccupied = pStorage.GetOccupiedSpace();
775 float fCapacity = pStorage.GetMaxVolumeCapacity();
776 m_wVolumeBar.SetMax( fCapacity );
777 m_wVolumeBar.SetCurrent( fOccupied );
783 protected void UpdateAmmoCount()
790 if ( m_aAmmoCountActual > -1 && m_aAmmoCountMax != 1 )
792 m_wAmmoCount.SetMax( m_aAmmoCountMax );
793 m_wAmmoCount.SetCurrent( m_aAmmoCountActual );
794 m_wAmmoCount.SetVisible(
true );
798 m_wAmmoCount.SetVisible(
false );
804 int GetAmmoCount() {
return m_aAmmoCountActual; }
807 protected void UpdateStackNumber()
809 if ( !m_wStackNumber )
812 m_wStackNumber.SetVisible(m_iStackNumber > 1);
813 m_wStackNumber.SetText( m_iStackNumber.ToString() );
817 protected void UpdateWeaponAmmoCount()
821 if (!m_wMagazineNumber)
830 if (!weaponMuzzleComp)
833 int currentAmmoCount = weaponMuzzleComp.GetAmmoCount();
834 int maxAmmoCount = weaponMuzzleComp.GetMaxAmmoCount();
835 int magazineCount = GetInventoryManager().GetMagazineCountByWeapon(weaponComp);
837 m_wMagazineNumber.SetText(
"+" + magazineCount);
839 m_wCurrentMagazineAmmoCount.SetMax(maxAmmoCount);
840 m_wCurrentMagazineAmmoCount.SetCurrent(currentAmmoCount);
842 m_wMagazineNumber.SetVisible(
true);
843 m_wCurrentMagazineAmmoCount.SetVisible(
true);
845 if (currentAmmoCount > 0 && magazineCount == 0)
848 m_wMagazineNumber.SetOpacity( 0 );
850 else if (currentAmmoCount == 0 && magazineCount == 0)
853 m_wMagazineNumber.SetOpacity( 1 );
856 m_wCurrentMagazineAmmoCount.SetCurrent( maxAmmoCount );
862 m_wMagazineNumber.SetOpacity( 1 );
872 UpdateVolumeBarValue();
875 UpdateWeaponAmmoCount();
883 if (m_pStorageUI.GetInventoryMenuHandler())
884 m_pStorageUI.GetInventoryMenuHandler().UnregisterUIStorage(
this );
886 m_widget.RemoveHandler(
this );
887 m_widget.RemoveFromHierarchy();
890 ItemPreviewManagerEntity manager = m_pStorageUI.GetInventoryMenuHandler().GetItemPreviewManager();
895 manager.SetPreviewItem(renderPreview,
null);
901 void OnChangeLockState()
906 if (m_wItemLockThrobber)
907 m_wItemLockThrobber.SetVisible(m_pItem.IsLocked());
911 void SetSelectedQuickSlot(
bool select )
914 if (!m_wSelectedEffect || !m_wSelectedIcon)
916 m_wSelectedEffect.SetVisible( select );
917 m_wSelectedIcon.SetVisible(
false);
934 override bool OnSelect(Widget w,
int x,
int y)
942 override bool OnFocus(Widget w,
int x,
int y)
949 override bool OnFocusLost(Widget w,
int x,
int y)
956 override bool OnChange(Widget w,
int x,
int y,
bool finished)
980 Widget GetWidget() {
return m_widget; }
983 int GetColumnSize() {
return m_iSizeX; }
986 int GetRowSize() {
return m_iSizeY; }
989 void SetSlotSize(
ESlotSize slotSize) { m_ESlotSize = slotSize; }
992 ESlotSize GetSlotSize() {
return m_ESlotSize; }
995 void SetPage(
int iPage ) {
m_iPage = iPage; }
998 int GetPage() {
return m_iPage; }
1002 ESlotFunction GetSlotedItemFunction() {
return m_eSlotFunction; }
1005 void SetIcon( ResourceName texture )
1007 m_wIcon = ImageWidget.Cast( m_widget.FindAnyWidget(
"icon" ) );
1010 m_wIcon.LoadImageTexture( 0, texture );
1015 override void HandlerAttached( Widget w )
1021 ResourceName GetItemResource()
1024 return ResourceName.Empty;
1025 return m_pItem.GetOwner().GetPrefabData().GetPrefabName();
1031 return (m_iStackNumber > 1);
1037 m_pStorageUI = pStorageUI;
1039 m_iQuickSlotIndex = iSlotIndex;
1041 UpdateReferencedComponent( pComponent );
1050 override void HandlerDeattached(Widget w)
1052 super.HandlerDeattached(w);
1055 m_FuelManager.GetOnFuelChanged().Remove(OnFuelAmountChanged);