Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InventorySlotUI.c
Go to the documentation of this file.
1const string SLOT_LAYOUT_1x1 = "{F437ACE2BD5F11E2}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
2
3const int CURRENT_AMMO_MAGAZINE = ARGB( 255, 255, 255, 255 );
4const int CURRENT_AMMO_TEXT = ARGB( 255, 142, 142, 142 );
5const int CURRENT_AMMO_EMPTY = ARGB( 255, 255, 75, 75 );
6
7const float CURRENT_AMMO_OPACITY = 0.432;
8
20
21
22//------------------------------------------------------------------------------------------------
26{
27 [Attribute("1", UIWidgets.ComboBox, "Slot size", "", ParamEnumArray.FromEnum(ESlotSize) )]
28 private ESlotSize m_ESlotSize;
29 protected int m_iSizeX;
30 protected int m_iSizeY;
31 protected int m_iPage; //helper variable telling us what page the slot should be stored on
32
33 private WorkspaceWidget m_workspaceWidget = null;
34 Widget m_widget = null;
35 private ButtonWidget m_wButton;
36 private ImageWidget m_wIcon = null;
37 private RenderTargetWidget m_wPreviewImage = null;
38
40
43 protected bool m_bEnabled = true;
44 protected bool m_bSelected = false;
45 protected bool m_bBlocked = false;
47 protected TextWidget m_wTextQuickSlot = null;
49 protected int m_iQuickSlotIndex;
50
52 protected int m_iStackNumber = 1;
55 protected string m_sItemName = "";
56 protected int m_aAmmoCountActual = -1;
57 protected int m_aAmmoCountMax = -1;
58
59
60 protected bool m_bVisible;
66
67 //~ FUEL
69
70 #ifdef DEBUG_INVENTORY20
71 protected TextWidget m_wDbgClassText1;
72 protected TextWidget m_wDbgClassText2;
73 protected TextWidget m_wDbgClassText3;
74 #endif
75
76 //------------------------------------------------------------------------ USER METHODS ------------------------------------------------------------------------
77 //------------------------------------------------------------------------------------------------
79 {
80 return m_pStorageUI.GetAnalyticalItemSlotType();
81 }
82
83 //------------------------------------------------------------------------------------------------
85 {
86 m_pItem = iic;
87 }
88
89 //------------------------------------------------------------------------------------------------
91 {
92 if ( m_widget )
93 Destroy();
94 m_pItem = pComponent;
95
96 if (attributes)
97 m_Attributes = attributes;
98
99 if (m_pItem && m_pItem.GetAttributes())
100 m_Attributes = SCR_ItemAttributeCollection.Cast( m_pItem.GetAttributes() ); //set the slot attributes (size) based on the information stored in the item
101 if (!m_Attributes)
102 return;
103 if (m_pItem && !m_Attributes.IsVisible(m_pItem))
104 return;
105
107 if (vehicleAttributes && !ShouldVehicleSlotBeVisible(vehicleAttributes))
108 return;
109
110 m_workspaceWidget = GetGame().GetWorkspace();
111 Widget wGrid = m_pStorageUI.GetStorageGrid();
112
113 if (!wGrid)
114 return;
115
116 m_widget = m_workspaceWidget.CreateWidgets( SetSlotSize(), wGrid );
117 m_widget.AddHandler( this ); //calls the HandlerAttached()
118 }
119
120 //------------------------------------------------------------------------------------------------
121 void UpdateInventorySlot(InventoryItemComponent comp, int stackNumber)
122 {
123 m_pItem = comp;
124 m_iStackNumber = stackNumber;
125 Refresh();
126 }
127
128 //------------------------------------------------------------------------------------------------
130 {
131 if (!m_Attributes)
132 return true;
133
134 return m_Attributes.IsDraggable();
135 }
136
137 //------------------------------------------------------------------------------------------------
138 protected string SetSlotSize()
139 {
140 string slotLayout = SLOT_LAYOUT_1x1;
141 switch ( m_Attributes.GetItemSize() )
142 {
143 case ESlotSize.SLOT_1x1: { m_iSizeX = 1; m_iSizeY = 1; } break;
144 case ESlotSize.SLOT_2x1: { m_iSizeX = 2; m_iSizeY = 1; } break;
145 case ESlotSize.SLOT_2x2: { m_iSizeX = 2; m_iSizeY = 2; } break;
146 case ESlotSize.SLOT_3x3: { m_iSizeX = 3; m_iSizeY = 3; } break;
147 }
148 return slotLayout;
149 }
150 //------------------------------------------------------------------------------------------------
151 protected void Init()
152 {
153 m_iPage = -1; //no page placement by default
154 //and create the visual slot
155
156 m_wTextQuickSlot = TextWidget.Cast( m_widget.FindAnyWidget( "TextQuickSlot" ) );
157 m_sItemName = GetItemName(); //debug purposes
158
159 if (m_pItem)
160 m_pItem.m_OnLockedStateChangedInvoker.Insert(OnChangeLockState);
161
163 if (m_eSlotFunction == ESlotFunction.TYPE_WEAPON)
164 {
165 m_wMagazineNumber = TextWidget.Cast( m_widget.FindAnyWidget( "magazineCount" ) );
166 m_wCurrentMagazine = m_widget.FindAnyWidget("currentMagazine");
168 {
169 m_wCurrentMagazineAmmoCount = ImageWidget.Cast(m_widget.FindAnyWidget("currentMagazineAmmoCount"));
170 ImageWidget outline = ImageWidget.Cast(m_wCurrentMagazine.FindAnyWidget("Outline"));
171 if (outline && m_pItem)
172 {
173 BaseMuzzleComponent muzzleComp = BaseMuzzleComponent.Cast(m_pItem.GetOwner().FindComponent(BaseMuzzleComponent));
174 if (muzzleComp)
175 {
176 MuzzleUIInfo info = MuzzleUIInfo.Cast(muzzleComp.GetUIInfo());
177 if (muzzleComp.IsInherited(MuzzleInMagComponent))
178 {
179 m_wCurrentMagazineAmmoCount.LoadImageFromSet(0, info.m_MagIndicator.m_sImagesetIcons, info.m_MagIndicator.m_sOutline);
180 outline.LoadImageFromSet(0, info.m_MagIndicator.m_sImagesetIcons, info.m_MagIndicator.m_sOutline);
181 }
182 else
183 {
184 m_wCurrentMagazineAmmoCount.LoadImageFromSet(0, info.m_MagIndicator.m_sImagesetIcons, info.m_MagIndicator.m_sProgress);
185 outline.LoadImageFromSet(0, info.m_MagIndicator.m_sImagesetIcons, info.m_MagIndicator.m_sProgress);
186 }
187 }
188 }
189 }
190 }
191
193
194 // If is it storage or attachment, register it to the array for the future use
195 if (!BaseInventoryStorageComponent.Cast(m_pItem) && !WeaponAttachmentsStorageComponent.Cast(m_pItem))
196 return;
197
198 if (m_pStorageUI && m_pStorageUI.GetInventoryMenuHandler())
199 m_pStorageUI.GetInventoryMenuHandler().RegisterUIStorage(this);
200 }
201
202 //------------------------------------------------------------------------------------------------
204 BaseInventoryStorageComponent GetStorageComponent() { return BaseInventoryStorageComponent.Cast(m_pItem); }
205
206 //------------------------------------------------------------------------------------------------
208 {
209 if ( !m_pItem )
210 return null;
211 auto pClothComponent = BaseLoadoutClothComponent.Cast( m_pItem.GetOwner().FindComponent( BaseLoadoutClothComponent ) );
212 if ( !pClothComponent )
213 return null;
214
215 return pClothComponent.GetAreaType();
216 }
217
218 //------------------------------------------------------------------------------------------------
219 void SetStackNumber(int i)
220 {
221 m_iStackNumber = i;
222 }
223
224 //------------------------------------------------------------------------------------------------
226 {
227 return m_iStackNumber;
228 }
229
230 //------------------------------------------------------------------------------------------------
232 {
234 }
235
236 //------------------------------------------------------------------------------------------------
241
242 //------------------------------------------------------------------------------------------------
244
245 //------------------------------------------------------------------------------------------------
247 protected void SetAmmoCount()
248 {
249 if (!m_pItem)
250 return;
251
252 MagazineComponent magComp = MagazineComponent.Cast(m_pItem.GetOwner().FindComponent(MagazineComponent));
253 if (!magComp)
254 return;
255
256 m_aAmmoCountActual = magComp.GetAmmoCount();
257 m_aAmmoCountMax = magComp.GetMaxAmmoCount();
258
259 if (m_ProgressBar)
260 {
261 if (m_aAmmoCountMax == 1)
262 {
263 m_wProgressBar.SetVisible(false);
264 return;
265 }
266
267 m_ProgressBar.FlipColors();
268 m_ProgressBar.SetProgressRange(0, magComp.GetMaxAmmoCount());
269 m_ProgressBar.SetCurrentProgress(magComp.GetAmmoCount());
270 }
271 }
272
273 protected void SetAmmoType()
274 {
275 Widget ammoType = m_widget.FindAnyWidget("AmmoTypeSize");
276 if (!ammoType)
277 return;
279 if (indicator)
280 indicator.SetAmmoType(m_pItem);
281 }
282
283 //------------------------------------------------------------------------------------------------
284 protected void OnFuelAmountChanged(float newFuelValue)
285 {
286 m_ProgressBar.SetProgressRange(0, m_FuelManager.GetTotalMaxFuel());
287 m_ProgressBar.SetCurrentProgress(newFuelValue);
288 }
289
290 //------------------------------------------------------------------------------------------------
291 protected void InitFuelAmount()
292 {
293 if (!m_wProgressBar)
294 m_wProgressBar = m_widget.FindAnyWidget("ProgressBar");
295
296 if (m_wProgressBar)
297 {
299 m_ProgressBar.FlipColors();
300 m_wProgressBar.SetVisible(true);
301 }
302 }
303
304 //------------------------------------------------------------------------------------------------
305 Widget GetButtonWidget() { return m_wButton; }
306 //------------------------------------------------------------------------------------------------
307 bool IsSlotEnabled() { return m_bEnabled; }
308 //------------------------------------------------------------------------------------------------
309 bool IsSlotBlocked() { return m_bBlocked; }
310 //------------------------------------------------------------------------------------------------
311 bool IsSelected() { return m_bSelected; }
312 //------------------------------------------------------------------------------------------------
314 void SetSlotVisible( bool bVisible )
315 {
316 m_bVisible = bVisible;
317 m_widget.SetEnabled(bVisible);
318 m_widget.SetVisible(bVisible);
319
320 if(bVisible)
321 {
322 m_wPreviewImage = RenderTargetWidget.Cast( m_widget.FindAnyWidget( "item" ) );
323 ImageWidget iconImage = ImageWidget.Cast(m_widget.FindAnyWidget("icon"));
324 RichTextWidget iconText = RichTextWidget.Cast(m_widget.FindAnyWidget("itemName"));
325 TextWidget quickslotNumber = TextWidget.Cast(m_widget.FindAnyWidget("TextQuickSlotLarge"));
326
327 //filter out 1-4 quickslots as they are in fact storages :harold:
329 {
331 if (controlled)
332 {
334 if (storage)
335 {
337 if (container)
338 container.HandleVisualization(iconImage, m_wPreviewImage, iconText, quickslotNumber);
339 }
340 }
341 }
342
343 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
344 if (world)
345 {
346 ItemPreviewManagerEntity manager = world.GetItemPreviewManager();
347 if (manager)
348 {
349 ItemPreviewWidget renderPreview = ItemPreviewWidget.Cast( m_wPreviewImage );
350 IEntity previewEntity = null;
351 if (m_pItem)
352 {
353 previewEntity = m_pItem.GetOwner();
354 m_wPreviewImage.SetVisible(true);
355 }
356
357 if (renderPreview)
358 manager.SetPreviewItem(renderPreview, previewEntity, null, true);
359 }
360 }
361
362 //if the slot has storage, then show its volume bar
364 {
365 m_wProgressBar = m_widget.FindAnyWidget("ProgressBar");
366 if (m_wProgressBar)
367 {
369 m_wProgressBar.SetVisible(m_eSlotFunction != ESlotFunction.TYPE_WEAPON);
370 }
371 }
372 m_wSelectedEffect = m_widget.FindAnyWidget("SelectedOverlay");
373 m_wSelectedIcon = m_widget.FindAnyWidget("SelectedIcon");
374 m_wMoveEffect = m_widget.FindAnyWidget( "IconMove" );
375 m_wDimmerEffect = m_widget.FindAnyWidget( "Dimmer" );
376 m_wBlockedEffect = m_widget.FindAnyWidget("Blocker");
377 m_wButton = ButtonWidget.Cast( m_widget.FindAnyWidget( "ItemButton" ) );
378 m_wStackNumber = TextWidget.Cast( m_widget.FindAnyWidget( "stackNumber" ) );
379 m_wItemLockThrobber = OverlayWidget.Cast(m_widget.FindAnyWidget("itemLockThrobber"));
380
381 if ( m_iStackNumber > 1 )
382 {
383 m_wStackNumber.SetText( m_iStackNumber.ToString() );
384 m_wStackNumber.SetVisible( true );
385 }
386 else
387 {
388 m_wStackNumber.SetVisible( false );
389 }
390
391 if (m_eSlotFunction == ESlotFunction.TYPE_MAGAZINE )
392 {
393 SetAmmoCount();
395 }
396
397 if (m_FuelManager)
398 OnFuelAmountChanged(m_FuelManager.GetTotalFuel());
399
400
402 {
404 }
405
406 #ifdef DEBUG_INVENTORY20
407 if ( !m_pItem )
408 {
409 array<string> dbgText = new array<string>();
410 this.ToString().Split( "<", dbgText, false );
411 m_wDbgClassText1 = TextWidget.Cast( m_widget.FindAnyWidget( "dbgTextClass1" ) );
412 m_wDbgClassText2 = TextWidget.Cast( m_widget.FindAnyWidget( "dbgTextClass2" ) );
413 m_wDbgClassText3 = TextWidget.Cast( m_widget.FindAnyWidget( "dbgTextClass3" ) );
414 m_wDbgClassText1.SetText( dbgText[0] );
415 m_wDbgClassText1.SetEnabled( true );
416 m_wDbgClassText1.SetVisible( true );
417 m_wDbgClassText2.SetText( dbgText[1] );
418 m_wDbgClassText2.SetEnabled( true );
419 m_wDbgClassText2.SetVisible( true );
420 m_pItem.ToString().Split( "<", dbgText, false );
421 if ( dbgText.Count() > 1 )
422 {
423 m_wDbgClassText3.SetText( dbgText[1] );
424 m_wDbgClassText3.SetEnabled( true );
425 m_wDbgClassText3.SetVisible( true );
426 }
427 }
428 #endif
430
431 }
432 else
433 {
434 m_wPreviewImage = null;
435 m_wSelectedEffect = null;
436 m_wSelectedIcon = null;
437 m_wMoveEffect = null;
438 m_wDimmerEffect = null;
439 m_wButton = null;
440 m_wVolumeBar = null;
441 m_wTextQuickSlot = null;
443 m_wStackNumber = null;
444 #ifdef DEBUG_INVENTORY20
445 m_wDbgClassText1 = null;
446 m_wDbgClassText2 = null;
447 m_wDbgClassText3 = null;
448 #endif
449 }
450 }
451
452 //------------------------------------------------------------------------------------------------
454 void SetSlotBlocked(bool bBlocked)
455 {
456 m_bBlocked = bBlocked;
457
459 return;
460
461 if (m_wBlockedEffect.IsVisible() == bBlocked)
462 return;
463
464 m_wDimmerEffect.SetVisible(bBlocked);
465 m_wBlockedEffect.SetVisible(bBlocked);
466 }
467
468 //------------------------------------------------------------------------------------------------
469 // !
471
472 //------------------------------------------------------------------------------------------------
473 // !
474 void SetQuickSlotIndexVisible( TextWidget textQuickSlot, bool bVisible )
475 {
476 if ( textQuickSlot && GetGame().GetInputManager().IsUsingMouseAndKeyboard() )
477 {
478 textQuickSlot.SetText( ( (m_iQuickSlotIndex + 1) % 10 ).ToString() );
479 textQuickSlot.SetVisible( bVisible );
480 }
481 }
482
483
484 //------------------------------------------------------------------------------------------------
486 {
487 if ( !m_pStorageUI )
488 return;
489 m_pStorageUI.SetSlotFocused( this, true );
490 SCR_InventoryMenuUI pMenuManager = m_pStorageUI.GetInventoryMenuHandler();
491 if ( pMenuManager )
492 {
493 #ifdef DEBUG_INVENTORY20
494
495 BaseInventoryStorageComponent dbgStorage;
496 InventoryStorageSlot dbgStorageParentSlot;
497
498 if ( m_pStorageUI.GetStorage() )
499 {
500 dbgStorage = m_pStorageUI.GetStorage();
501 if ( m_pStorageUI.GetStorage().GetParentSlot() )
502 dbgStorageParentSlot = m_pStorageUI.GetStorage().GetParentSlot();
503 }
504
505 PrintFormat( "INV:OnSlotFocused | m_pStorageUI: %1 | Focused slotUI: %2 | Parent storage: %3 | from parent slot: %4", m_pStorageUI, this, dbgStorage, dbgStorageParentSlot );
506 #endif
507 pMenuManager.SetSlotFocused( this, GetStorageUI(), true );
508 }
509 }
510
511 //------------------------------------------------------------------------------------------------
512 override bool OnMouseEnter( Widget w, int x, int y )
513 {
515 if ( m_wButton )
516 if ( m_wButton.FindHandler( SCR_ButtonComponent ) )
517 m_wButton.FindHandler( SCR_ButtonComponent ).OnFocus( w, x, y );
518 return false;
519 }
520
521 //------------------------------------------------------------------------------------------------
522 override bool OnMouseLeave( Widget w, Widget enterW, int x, int y )
523 {
525 if ( m_wButton )
526 if ( m_wButton.FindHandler( SCR_ButtonComponent ) )
527 m_wButton.FindHandler( SCR_ButtonComponent ).OnFocusLost( w, x, y );
528 return false;
529 }
530
531 //------------------------------------------------------------------------------------------------
533 {
534 if (!m_pStorageUI)
535 return;
536 m_pStorageUI.SetSlotFocused( this, false );
537 SCR_InventoryMenuUI pMenuManager = m_pStorageUI.GetInventoryMenuHandler();
538 if ( pMenuManager )
539 pMenuManager.SetSlotFocused( this, m_pStorageUI, false );
540 }
541
542 //------------------------------------------------------------------------------------------------
544 {
547 return;
548
549 m_wSelectedEffect.SetVisible( m_bSelected );
550 m_wSelectedIcon.SetVisible(false);
551 m_pStorageUI.SetSlotSelected( this, m_bSelected );
552 }
553 //------------------------------------------------------------------------------------------------
554 void SetSelected( bool select )
555 {
556 //TODO: show the selected effect should be done as a component
557 if (!m_pItem)
558 {
559 m_bSelected = false;
560 return;
561 }
562
563 m_bSelected = select;
565 return;
566
567 m_wSelectedEffect.SetVisible(select);
568 }
569
570 //------------------------------------------------------------------------------------------------
571 void SetEnabled( bool enable )
572 {
573 if( enable )
574 m_widget.SetOpacity( BUTTON_OPACITY_ENABLED );
575 else
576 m_widget.SetOpacity( BUTTON_OPACITY_DISABLED );
577
578 m_widget.SetEnabled( enable );
579 }
580
582 {
583 return false;
584 }
585
586 //------------------------------------------------------------------------------------------------
587 // ! 0 - Disable for move
588 // ! 1 - Enable for move
589 // ! 2 - Reset
590 void SetEnabledForMove( int iSelect )
591 {
592 switch ( iSelect )
593 {
594 case 0:
595 {
596 m_widget.SetEnabled( false );
597 if ( m_wMoveEffect )
598 m_wMoveEffect.SetVisible( false );
599 } break;
600
601 case 1:
602 {
603 m_widget.SetEnabled( true );
604 if ( m_wMoveEffect )
605 m_wMoveEffect.SetVisible( true );
606
607 } break;
608
609 case 2:
610 {
611 m_widget.SetEnabled( true );
612 if ( m_wMoveEffect )
613 m_wMoveEffect.SetVisible( false );
614 } break;
615
616 }
617
618 }
619
620 //------------------------------------------------------------------------------------------------
622 //------------------------------------------------------------------------------------------------
623 BaseInventoryStorageComponent GetAsStorage() { return BaseInventoryStorageComponent.Cast( m_pItem ); }
624
625 //------------------------------------------------------------------------------------------------
626 // ! Returns the UI storage the slot is associated with
628
629
630 //------------------------------------------------------------------------------------------------
632 {
633 if( !m_Attributes )
634 return null;
635 return m_Attributes.GetUIInfo();
636 }
637
638 //------------------------------------------------------------------------------------------------
639 string GetItemName()
640 {
641 UIInfo itemDetails = GetItemDetails();
642 if( !itemDetails )
643 return string.Empty;
644 return itemDetails.GetName();
645 }
646
647 //------------------------------------------------------------------------------------------------
648 protected void SetItemDetails()
649 {
650 UIInfo itemDetails = GetItemDetails();
651 if(!itemDetails)
652 return;
653
654 if(m_pStorageUI)
655 {
656 SCR_InventoryUIInfo inventoryItemDetails = SCR_InventoryUIInfo.Cast(itemDetails);
657
658 if (inventoryItemDetails)
659 m_pStorageUI.ShowItemDetails(inventoryItemDetails.GetInventoryItemName(m_pItem), inventoryItemDetails.GetInventoryItemDescription(m_pItem), m_Attributes.GetWeight().ToString());
660 else
661 m_pStorageUI.ShowItemDetails(itemDetails.GetName(), itemDetails.GetDescription(), m_Attributes.GetWeight().ToString());
662 }
663 }
664
665 //------------------------------------------------------------------------------------------------
667 {
668 if( m_pStorageUI )
669 m_pStorageUI.ShowItemDetails( "", "", "" );
670 }
671
672
673 //------------------------------------------------------------------------------------------------
674 protected void SetImage( string resource, string imageName )
675 {
676 if ( resource == string.Empty || imageName == string.Empty || m_wIcon == null )
677 return;
678
679 m_wIcon.LoadImageFromSet( 0, resource, imageName );
680 int width, height;
681 m_wIcon.GetImageSize( 0, width, height );
682 m_wIcon.SetSize( 32, 32 ); //TODO force this
683 }
684
685 //------------------------------------------------------------------------------------------------
686 protected SCR_InventoryStorageManagerComponent GetInventoryManager() { return m_pStorageUI.GetInventoryManager(); }
687
688 //------------------------------------------------------------------------------------------------
690 {
691 SCR_InventoryStorageManagerComponent invMan = GetInventoryManager();
692 if (!invMan || !invMan.CanMoveItem(m_pItem.GetOwner()))
693 return false;
694 InventoryStorageSlot pSlot = m_pItem.GetParentSlot();
695 if( !pSlot )
696 return false;
697 auto pStorage = pSlot.GetStorage();
698 if( !pStorage )
699 return false;
700 if(!invMan.CanRemoveItemFromStorage(m_pItem.GetOwner(), pStorage))
701 return false;
702
703 //TODO: return the check back once the true/false issue is solved
704 //if(!invMan().TryRemoveItemFromInventory(m_pItem.GetOwner(), pStorage))
705 //return false; //can't be removed, exit
706
707 invMan.TryRemoveItemFromInventory(m_pItem.GetOwner(), pStorage);
708
709 if( !m_pStorageUI )
710 return false;
711 if ( m_widget )
712 {
713 m_widget.RemoveHandler( this );
714 m_widget.RemoveFromHierarchy();
715 }
716 m_pStorageUI.RemoveSlotUI( this );
717 //delete this;
718
719 return true;
720 }
721
722 //------------------------------------------------------------------------------------------------
725 {
726 if(!m_pItem)
727 return;
728 IEntity item = m_pItem.GetOwner();
729 if (!item)
730 return;
731
732 m_FuelManager = SCR_FuelManagerComponent.Cast(item.FindComponent(FuelManagerComponent));
733 if (m_FuelManager && m_FuelManager.GetTotalMaxFuel() > 0)
734 {
736 return;
737 }
738
739 if (SCR_GadgetComponent.Cast(item.FindComponent(SCR_GadgetComponent)))
740 {
741 m_eSlotFunction = ESlotFunction.TYPE_GADGET;
743 SetAmmoType();
744
745 return;
746 }
747
749 {
750 m_eSlotFunction = ESlotFunction.TYPE_MAGAZINE;
751 SetAmmoCount();
752 SetAmmoType();
753
754 return;
755 }
756
758 {
759 m_eSlotFunction = ESlotFunction.TYPE_WEAPON;
760 SetAmmoType();
761 return;
762 }
763 }
764
765 //------------------------------------------------------------------------------------------------
767 {
768 ChimeraCharacter character = ChimeraCharacter.Cast(entity);
769 if (!character)
770 return null;
771
772 CharacterControllerComponent controller = character.GetCharacterController();
773 if (!controller)
774 return null;
775
776 SCR_InventoryStorageManagerComponent storageManager = GetInventoryManager();
777 if (!storageManager)
778 return null;
779
780 return storageManager.GetCharacterStorage();
781 }
782
783 //------------------------------------------------------------------------------------------------
784 void UseItem(IEntity player, SCR_EUseContext context)
785 {
786 if (!m_pItem)
787 return;
788
789 IEntity item = m_pItem.GetOwner();
790 if (!item)
791 return;
792
794 if (!storage)
795 return;
796
797 if (storage.UseItem(item, m_eSlotFunction, context))
798 Refresh();
799
800 // if we are using a bandage from inventory, inform analytics.
801 //SCR_ConsumableItemComponent consumableComp = SCR_ConsumableItemComponent.Cast(item.FindComponent(SCR_ConsumableItemComponent));
802 //if (consumableComp && consumableComp.GetConsumableType() == SCR_EConsumableType.BANDAGE && context == SCR_EUseContext.FROM_INVENTORY)
803 // SCR_AnalyticsApplication.GetInstance().UseHealingFromInventory();
804 }
805
806 //------------------------------------------------------------------------------------------------
807 bool CanUseItem(IEntity player)
808 {
809 if (!m_pItem)
810 return false;
811
812 IEntity item = m_pItem.GetOwner();
813 if (!item)
814 return false;
815
817 if (!storage)
818 return false;
819
820 return storage.CanUseItem(item, m_eSlotFunction);
821 }
822
823 //------------------------------------------------------------------------------------------------
825 {
826 IEntity vehicle = m_pItem.GetOwner();
828 if (dm && dm.IsDestroyed())
829 return false;
830
832
833 if (attr.GetVisibleInVehicleOnly() && !player.IsInVehicle())
834 return false;
835
837 return false;
838
839 if (!Vehicle.Cast(vehicle))
840 vehicle = vehicle.GetParent();
841
842 FactionAffiliationComponent vehicleFaction = FactionAffiliationComponent.Cast(vehicle.FindComponent(FactionAffiliationComponent));
843 if (!vehicleFaction || !vehicleFaction.GetAffiliatedFaction())
844 return true;
845
846 FactionAffiliationComponent playerFaction = FactionAffiliationComponent.Cast(player.FindComponent(FactionAffiliationComponent));
847 if (!playerFaction || !playerFaction.GetAffiliatedFaction())
848 return false;
849
850 return (playerFaction.GetAffiliatedFaction() == vehicleFaction.GetAffiliatedFaction());
851 }
852
853 //------------------------------------------------------------------------------------------------
854 // !
855 protected void UpdateVolumeBarValue()
856 {
857 if ( m_ProgressBar && m_pItem )
858 {
859 BaseInventoryStorageComponent pStorage = GetAsStorage();
860 if ( !pStorage )
861 return;
862
863 string name = "";
864 if ( pStorage.GetAttributes() && pStorage.GetAttributes().GetUIInfo() )
865 {
866 name = pStorage.GetAttributes().GetUIInfo().GetName();
867 }
868
869 float fOccupied = 0.0;
870 //TODO: The folowing part needs refactor! This enumeration of attached storages is used on more places.
871 if ( pStorage.Type() == ClothNodeStorageComponent )
872 {
873 array<BaseInventoryStorageComponent> pOwnedStorages = new array<BaseInventoryStorageComponent>();
874 pStorage.GetOwnedStorages( pOwnedStorages, 1, false );
875 foreach ( BaseInventoryStorageComponent pSubStorage : pOwnedStorages )
876 {
877 if (SCR_UniversalInventoryStorageComponent.Cast(pSubStorage))
878 fOccupied += pSubStorage.GetOccupiedSpace();
879 }
880 }
881 else
882 {
883 fOccupied = pStorage.GetOccupiedSpace();
884 }
885 float fCapacity = pStorage.GetMaxVolumeCapacity();
886 m_ProgressBar.SetProgressRange(0, fCapacity);
887 m_ProgressBar.SetCurrentProgress(fOccupied);
888 }
889 }
890
891 //------------------------------------------------------------------------------------------------
892 protected void UpdateAmmoCount()
893 {
894 if (!m_ProgressBar)
895 return;
896 if ( m_eSlotFunction != ESlotFunction.TYPE_MAGAZINE )
897 return;
898 if( !m_pItem )
899 return;
900
901 if ( m_aAmmoCountActual > -1 && m_aAmmoCountMax != 1 )
902 {
903 m_ProgressBar.SetProgressRange(0, m_aAmmoCountMax);
904 m_ProgressBar.SetCurrentProgress(m_aAmmoCountActual);
905 }
906 }
907
908 //------------------------------------------------------------------------------------------------
911
912 //------------------------------------------------------------------------------------------------
913 protected void UpdateStackNumber()
914 {
915 if ( !m_wStackNumber )
916 return;
917
918 m_wStackNumber.SetVisible(m_iStackNumber > 1);
919 m_wStackNumber.SetText( m_iStackNumber.ToString() );
920 }
921
922 //------------------------------------------------------------------------------------------------
923 protected void UpdateWeaponAmmoCount()
924 {
925 if (!m_pItem)
926 return;
928 return;
929 // Check if the storage is vicinity. We don't want to display ammo counts for weapons that are on the ground.
931 return;
932 BaseWeaponComponent weaponComp = BaseWeaponComponent.Cast( m_pItem.GetOwner().FindComponent( BaseWeaponComponent ) );
933 if (!weaponComp)
934 return;
935 BaseMuzzleComponent weaponMuzzleComp = weaponComp.GetCurrentMuzzle();
936 if (!weaponMuzzleComp)
937 return;
938
939
940 int currentAmmoCount = weaponMuzzleComp.GetAmmoCount();
941 int maxAmmoCount = weaponMuzzleComp.GetMaxAmmoCount();
942 int magazineCount = GetInventoryManager().GetMagazineCountByWeapon(weaponComp);
943
944 m_wMagazineNumber.SetText("+" + magazineCount);
945 m_wMagazineNumber.SetVisible(true);
946
947 if (magazineCount > 0 && maxAmmoCount > 0)
948 m_wCurrentMagazineAmmoCount.SetMaskProgress(Math.InverseLerp(0, maxAmmoCount, currentAmmoCount));
949 else if (maxAmmoCount == 0)
950 m_wCurrentMagazineAmmoCount.SetMaskProgress(0);
951
952 m_wMagazineNumber.SetVisible(magazineCount > 0);
953
954 if (weaponMuzzleComp.IsInherited(MuzzleInMagComponent))
955 m_wCurrentMagazine.SetVisible(weaponMuzzleComp.IsCurrentBarrelChambered());
956 else
957 m_wCurrentMagazine.SetVisible(true);
958 }
959
960 //------------------------------------------------------------------------------------------------
968
969
970 //------------------------------------------------------------------------------------------------
972 void Destroy()
973 {
974 if (m_pStorageUI.GetInventoryMenuHandler())
975 m_pStorageUI.GetInventoryMenuHandler().UnregisterUIStorage( this );
976
977 if (m_widget)
978 {
979 m_widget.RemoveHandler( this );
980 m_widget.RemoveFromHierarchy();
981 m_widget = null;
982 }
983
984 if (m_wPreviewImage)
985 {
986 ItemPreviewManagerEntity manager = m_pStorageUI.GetInventoryMenuHandler().GetItemPreviewManager();
987 if (manager)
988 {
989 ItemPreviewWidget renderPreview = ItemPreviewWidget.Cast( m_wPreviewImage );
990 if (renderPreview)
991 manager.SetPreviewItem(renderPreview, null);
992 }
993 }
994 }
995
996 //------------------------------------------------------------------------------------------------
998 {
999 if (!m_pItem)
1000 return;
1001
1003 m_wItemLockThrobber.SetVisible(m_pItem.IsLocked());
1004 }
1005
1006 //------------------------------------------------------------------------------------------------
1007 void SetSelectedQuickSlot( bool select )
1008 {
1009 m_bSelected = select;
1011 return;
1012 m_wSelectedEffect.SetVisible( select );
1013 m_wSelectedIcon.SetVisible(false);
1014 }
1015
1016 //------------------------------------------------------------------------------------------------
1018 {
1019 if ( !m_Attributes )
1020 return ECommonItemType.NONE;
1021 return m_Attributes.GetCommonType();
1022 }
1023
1024 //------------------------------------------------------------------------------------------------
1025
1026
1027 //------------------------------------------------------------------------ COMMON METHODS ----------------------------------------------------------------------
1028
1029 //------------------------------------------------------------------------------------------------
1030 override bool OnFocus(Widget w, int x, int y)
1031 {
1032 OnSlotFocused();
1033 return false;
1034 }
1035
1036 //------------------------------------------------------------------------------------------------
1037 override bool OnFocusLost(Widget w, int x, int y)
1038 {
1040 return false;
1041 }
1042
1043 //------------------------------------------------------------------------------------------------
1044 override bool OnChange(Widget w, bool finished)
1045 {
1047 return false;
1048 }
1049 /*
1050 //------------------------------------------------------------------------------------------------
1051 override bool OnMouseButtonDown( Widget w, int x, int y, int button )
1052 {
1053 m_mouseButtonDown = true;
1054 PrintFormat( "INV: widget: %1, ( %2, %3 ), button: %4 DOWN", w, x, y, button );
1055 return false;
1056 }
1057
1058 //------------------------------------------------------------------------------------------------
1059 override bool OnMouseButtonUp( Widget w, int x, int y, int button )
1060 {
1061 m_mouseButtonDown = false;
1062 PrintFormat( "INV: widget: %1, ( %2, %3 ), button: %4 UP", w, x, y, button );
1063 return false;
1064 }
1065 */
1066
1067 //------------------------------------------------------------------------------------------------
1068 Widget GetWidget() { return m_widget; }
1069
1070 //------------------------------------------------------------------------------------------------
1071 int GetColumnSize() { return m_iSizeX; }
1072
1073 //------------------------------------------------------------------------------------------------
1074 int GetRowSize() { return m_iSizeY; }
1075
1076 //------------------------------------------------------------------------------------------------
1077 void SetSlotSize( ESlotSize slotSize) { m_ESlotSize = slotSize; }
1078
1079 //------------------------------------------------------------------------------------------------
1080 ESlotSize GetSlotSize() { return m_ESlotSize; }
1081
1082 //------------------------------------------------------------------------------------------------
1083 void SetPage( int iPage ) { m_iPage = iPage; }
1084
1085 //------------------------------------------------------------------------------------------------
1086 int GetPage() { return m_iPage; }
1087
1088 //------------------------------------------------------------------------------------------------
1091
1092 //------------------------------------------------------------------------------------------------
1093 void SetIcon( ResourceName texture )
1094 {
1095 m_wIcon = ImageWidget.Cast( m_widget.FindAnyWidget( "icon" ) );
1096 if ( !m_wIcon )
1097 return;
1098 m_wIcon.LoadImageTexture( 0, texture );
1099 m_wIcon.SetVisible( true );
1100 }
1101
1102 //------------------------------------------------------------------------------------------------
1103 override void HandlerAttached( Widget w )
1104 {
1105 Init();
1106 }
1107
1108 //------------------------------------------------------------------------------------------------
1110 {
1111 if (!m_pItem)
1112 return ResourceName.Empty;
1113 return m_pItem.GetOwner().GetPrefabData().GetPrefabName();
1114 }
1115
1116 //------------------------------------------------------------------------------------------------
1118 {
1119 return (m_iStackNumber > 1);
1120 }
1121
1122 //------------------------------------------------------------------------------------------------
1124 {
1125 if (!m_widget)
1126 return;
1127
1128 SCR_InventoryMenuUI menu = SCR_InventoryMenuUI.Cast(GetGame().GetMenuManager().FindMenuByPreset(ChimeraMenuPreset.Inventory20Menu));
1129 if (!menu)
1130 return;
1131
1132 Widget incompatible = m_widget.FindAnyWidget("Incompatible");
1133 if (!incompatible)
1134 return;
1135
1136 if (!slot)
1137 {
1138 incompatible.SetVisible(false);
1139 return;
1140 }
1141
1142 if (slot == this)
1143 return;
1144
1145 if (slot.GetSlotedItemFunction() != ESlotFunction.TYPE_MAGAZINE)
1146 return;
1147
1148 if (!m_pItem)
1149 return;
1150
1151 IEntity owner = m_pItem.GetOwner();
1153 if (!weapon)
1154 return;
1155
1157 if (!itemComp)
1158 return;
1159
1160 MagazineComponent magComp = MagazineComponent.Cast(itemComp.GetOwner().FindComponent(MagazineComponent));
1161 if (!magComp)
1162 return;
1163
1164 BaseMagazineWell well = magComp.GetMagazineWell();
1165 if (!well)
1166 return;
1167
1168 BaseMuzzleComponent muzzle = weapon.GetCurrentMuzzle();
1169 if (!muzzle)
1170 return;
1171
1172 BaseMagazineWell muzzleWell = muzzle.GetMagazineWell();
1173 if (!muzzleWell)
1174 return;
1175
1176 if (!Turret.Cast(owner) && !menu.IsWeaponEquipped(owner) || slot.IsInherited(SCR_ArsenalInventorySlotUI))
1177 {
1178 incompatible.SetVisible(true);
1179 return;
1180 }
1181
1182 incompatible.SetVisible(!well.Type().IsInherited(muzzleWell.Type()));
1183 }
1184
1185 //------------------------------------------------------------------------------------------------
1187 {
1188 Widget incompatible = m_widget.FindAnyWidget("Incompatible");
1189 if (!incompatible)
1190 return false;
1191
1192 return !incompatible.IsVisible();
1193 }
1194
1195 //------------------------------------------------------------------------------------------------
1196 void SCR_InventorySlotUI( InventoryItemComponent pComponent = null, SCR_InventoryStorageBaseUI pStorageUI = null, bool bVisible = true, int iSlotIndex = -1, SCR_ItemAttributeCollection pAttributes = null )
1197 {
1198 m_pStorageUI = pStorageUI;
1199 m_bVisible = bVisible;
1200 m_iQuickSlotIndex = iSlotIndex;
1201 m_Attributes = pAttributes;
1202 UpdateReferencedComponent( pComponent );
1203 }
1204
1205 //------------------------------------------------------------------------------------------------
1207 {
1208 }
1209
1210 //------------------------------------------------------------------------------------------------
1211 override void HandlerDeattached(Widget w)
1212 {
1213 super.HandlerDeattached(w);
1214
1216 m_FuelManager.GetOnFuelChanged().Remove(OnFuelAmountChanged);
1217 }
1218};
ChimeraMenuPreset
Menu presets.
ArmaReforgerScripted GetGame()
Definition game.c:1398
ECommonItemType
const float BUTTON_OPACITY_DISABLED
const float BUTTON_OPACITY_ENABLED
SCR_EAnalyticalItemSlotType
InputManager GetInputManager()
SCR_EUseContext
void SCR_FuelManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
@ TYPE_MAGAZINE
@ TYPE_GADGET
@ TYPE_HEALTH
@ TYPE_CLOTHES
@ TYPE_GENERIC
@ TYPE_CONSUMABLE
@ TYPE_WEAPON
@ TYPE_STORAGE
const int CURRENT_AMMO_TEXT
const string SLOT_LAYOUT_1x1
const int CURRENT_AMMO_EMPTY
const float CURRENT_AMMO_OPACITY
const int CURRENT_AMMO_MAGAZINE
void SCR_UniversalInventoryStorageComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_VehicleDamageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
Definition Math.c:13
ref SCR_MagazineIndicatorConfiguration m_MagIndicator
Replication item identifier.
Definition RplId.c:14
Deprecated button component. Still used in many prefabs, so it works, it's just stripped of most of t...
bool UseItem(notnull IEntity item, ESlotFunction slotFunction=ESlotFunction.TYPE_GENERIC, SCR_EUseContext context=SCR_EUseContext.FROM_QUICKSLOT)
SCR_QuickslotBaseContainer GetContainerFromQuickslot(int index)
bool CanUseItem(notnull IEntity item, ESlotFunction slotFunction=ESlotFunction.TYPE_GENERIC)
bool SetAmmoType(InventoryItemComponent item)
bool IsWeaponEquipped(IEntity weapon)
void SetSlotFocused(SCR_InventorySlotUI pFocusedSlot, SCR_InventoryStorageBaseUI pFromStorageUI, bool bFocused)
BaseInventoryStorageComponent GetStorageComponent()
returns the storage component associated with this UI component
void SetSelected(bool select)
void SetSelectedQuickSlot(bool select)
void Destroy()
Removes just the UI slot.
override bool OnChange(Widget w, bool finished)
void SCR_InventorySlotUI(InventoryItemComponent pComponent=null, SCR_InventoryStorageBaseUI pStorageUI=null, bool bVisible=true, int iSlotIndex=-1, SCR_ItemAttributeCollection pAttributes=null)
SCR_CharacterInventoryStorageComponent GetCharacterStorage(IEntity entity)
ImageWidget m_wCurrentMagazineAmmoCount
ESlotFunction m_eSlotFunction
bool CanUseItem(IEntity player)
void IncreaseStackNumberWithRplId(RplId id)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
InventoryItemComponent GetInventoryItemComponent()
ESlotFunction GetSlotedItemFunction()
What functionality the item in the slot has? ( weapon, magazine, health, consumable....
override void HandlerAttached(Widget w)
void OverrideReferencedComponent(notnull InventoryItemComponent iic)
ProgressBarWidget m_wVolumeBar
SCR_InventoryProgressBar m_ProgressBar
ref SCR_ItemAttributeCollection m_Attributes
void SetEnabledForMove(int iSelect)
void UpdateInventorySlot(InventoryItemComponent comp, int stackNumber)
void SetQuickSlotIndexVisible(TextWidget textQuickSlot, bool bVisible)
BaseInventoryStorageComponent GetAsStorage()
bool ShouldVehicleSlotBeVisible(SCR_InventoryVehicleVisibilityAttribute attr)
void SetSlotBlocked(bool bBlocked)
should be the slot be blocked?
OverlayWidget m_wItemLockThrobber
ECommonItemType GetCommonItemType()
void CheckCompatibility(SCR_InventorySlotUI slot)
SCR_InventoryStorageBaseUI GetStorageUI()
ProgressBarWidget m_wAmmoCount
InventoryItemComponent m_pItem
SCR_FuelManagerComponent m_FuelManager
override bool OnFocusLost(Widget w, int x, int y)
SCR_InventoryStorageManagerComponent GetInventoryManager()
void SetIcon(ResourceName texture)
void SetSlotSize(ESlotSize slotSize)
override void HandlerDeattached(Widget w)
void OnFuelAmountChanged(float newFuelValue)
void SetImage(string resource, string imageName)
SCR_InventoryStorageBaseUI m_pStorageUI
void UpdateReferencedComponent(InventoryItemComponent pComponent, SCR_ItemAttributeCollection attributes=null)
void SetItemFunctionality()
stores the type of the functionality of the item in the slot
override bool OnMouseEnter(Widget w, int x, int y)
SCR_EAnalyticalItemSlotType GetAnalyticalItemSlotType()
void SetSlotVisible(bool bVisible)
should be the slot visible?
LoadoutAreaType GetLoadoutArea()
override bool OnFocus(Widget w, int x, int y)
void SetEnabled(bool enable)
void UseItem(IEntity player, SCR_EUseContext context)
bool OnDrop(SCR_InventorySlotUI slot)
string GetInventoryItemName(InventoryItemComponent item)
Function to override to get custom inventory name.
string GetInventoryItemDescription(InventoryItemComponent item)
Function to override to get custom inventory description.
static IEntity GetLocalControlledEntity()
SCR_QuickslotBaseContainer is intended to be used for quickslots, to allow quickslotting of non-item ...
void HandleVisualization(ImageWidget iconImage, RenderTargetWidget renderTarget, RichTextWidget text, TextWidget quickslotNumber)
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
SCR_EditableEntityComponent GetControlledEntity()
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
proto int ARGB(int a, int r, int g, int b)