Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_InventoryItemInfoUI.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/UI/Inventory", description: "Inventory Item Info UI class")]
2 
3 //------------------------------------------------------------------------------------------------
6 class SCR_InventoryItemInfoUI : ScriptedWidgetComponent
7 {
8 
9  private Widget m_infoWidget;
10  private VerticalLayoutWidget m_wHintWidget;
11  private TextWidget m_wTextName;
12  private TextWidget m_wTextDescription;
13  private TextWidget m_wTextWeight;
14  private ImageWidget m_wItemIcon;
15  protected SCR_SlotUIComponent m_pFrameSlotUI;
16  protected Widget m_wWidgetUnderCursor;
17  protected bool m_bForceShow;
18 
19  private string m_sHintLayout = "{9996B50BE8DFED5F}UI/layouts/Menus/Inventory/InventoryItemHintElement.layout";
20 
21 
22  //------------------------------------------------------------------------ USER METHODS ------------------------------------------------------------------------
23  //------------------------------------------------------------------------------------------------
24  protected void ShowInfoWidget( bool bShow )
25  {
26  if (m_bForceShow)
27  {
28  m_infoWidget.SetVisible( true );
29  return;
30  }
31 
32  if ( !m_wWidgetUnderCursor )
33  return;
34  if ( WidgetManager.GetWidgetUnderCursor() != m_wWidgetUnderCursor )
35  return; //the cursor is on different position already
36  m_infoWidget.SetVisible( true );
37  }
38 
39  //------------------------------------------------------------------------------------------------
40  void Show( float fDelay = 0.0, Widget w = null, bool forceShow = false )
41  {
42  m_bForceShow = forceShow;
43  m_wWidgetUnderCursor = w;
44  if ( fDelay == 0 )
45  ShowInfoWidget( true );
46  else
47  {
48  GetGame().GetCallqueue().Remove( ShowInfoWidget );
49  GetGame().GetCallqueue().CallLater( ShowInfoWidget, fDelay*1000, false, true );
50  }
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  void SetIcon(ResourceName iconPath, Color color = null)
55  {
56  if (iconPath.IsEmpty())
57  return;
58 
59  m_wItemIcon.SetVisible(m_wItemIcon.LoadImageTexture(0, iconPath));
60  if (color)
61  m_wItemIcon.SetColor(color);
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  void ShowIcon(bool isVisible)
66  {
67  m_wItemIcon.SetVisible(isVisible);
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  void Hide( float fDelay = 1.0 )
72  {
73  m_infoWidget.SetVisible( false );
74  m_infoWidget.SetEnabled( false );
75  m_wItemIcon.SetVisible(false);
76 
77  Widget childWidget = m_wHintWidget.GetChildren();
78  while (childWidget)
79  {
80  Widget next = childWidget.GetSibling();
81  m_wHintWidget.RemoveChild(childWidget);
82  childWidget = next;
83  }
84 
85  GetGame().GetCallqueue().Remove(ShowInfoWidget);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  void Move( float x, float y )
90  {
91  if ( !m_pFrameSlotUI )
92  return;
93  m_pFrameSlotUI.SetPosX( x );
94  m_pFrameSlotUI.SetPosY( y );
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  void SetName( string sName )
99  {
100  m_wTextName.SetText( sName );
101  }
102 
103  //------------------------------------------------------------------------------------------------
104  void SetDescription( string sDescr )
105  {
106  if( sDescr != "" )
107  {
108  m_wTextDescription.SetEnabled( true );
109  m_wTextDescription.SetVisible( true );
110  m_wTextDescription.SetText( sDescr );
111  }
112  else
113  {
114  m_wTextDescription.SetEnabled( false );
115  m_wTextDescription.SetVisible( false );
116  }
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  void SetItemHints(InventoryItemComponent item, array<SCR_InventoryItemHintUIInfo> itemHintArray, SCR_InventorySlotUI focusedSlot)
121  {
122  WorkspaceWidget workspace = GetGame().GetWorkspace();
123 
124  //~ Clear existing hints if any
125  Widget hintChild = m_wHintWidget.GetChildren();
126  Widget deleteHint;
127  while(hintChild)
128  {
129  deleteHint = hintChild;
130  hintChild = deleteHint.GetSibling();
131 
132  delete deleteHint;
133  }
134 
135  foreach (SCR_InventoryItemHintUIInfo hintUIInfo : itemHintArray)
136  {
137  if (!hintUIInfo.CanBeShown(item, focusedSlot))
138  continue;
139 
140  Widget createdWidget = workspace.CreateWidgets(m_sHintLayout, m_wHintWidget);
141  if (!createdWidget)
142  return;
143 
144  hintUIInfo.SetItemHintNameTo(item, RichTextWidget.Cast(createdWidget.FindAnyWidget("ItemInfo_hintText")));
145  hintUIInfo.SetIconTo(ImageWidget.Cast(createdWidget.FindAnyWidget("ItemInfo_hintIcon")));
146  }
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  void SetWeight( string sWeight )
151  {
152  if (!sWeight.IsEmpty())
153  {
154  m_wTextWeight.SetEnabled( true );
155  m_wTextWeight.SetVisible( true );
156  m_wTextWeight.SetTextFormat("#AR-ValueUnit_Short_Kilograms", sWeight);
157  }
158  else
159  {
160  m_wTextWeight.SetEnabled( false );
161  m_wTextWeight.SetVisible( false );
162  }
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  void SetWeight( float fWeight )
167  {
168  if( fWeight <= 0.0 )
169  SetWeight( "" );
170  else
171  SetWeight( fWeight.ToString() );
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  override void HandlerAttached( Widget w )
176  {
177  if( !w )
178  return;
179  m_infoWidget = w;
180  m_wHintWidget = VerticalLayoutWidget.Cast( w.FindAnyWidget( "VerticalHintParent" ) );
181  m_wTextName = TextWidget.Cast( w.FindAnyWidget( "ItemInfo_name" ) );
182  m_wTextDescription = TextWidget.Cast( w.FindAnyWidget( "ItemInfo_description" ) );
183  m_wTextWeight = TextWidget.Cast( w.FindAnyWidget( "ItemInfo_weight" ) );
184  m_wItemIcon = ImageWidget.Cast(w.FindAnyWidget("ItemInfo_icon"));
185  Widget wItemInfo = m_infoWidget.FindAnyWidget( "ItemInfo" );
186  if ( !wItemInfo )
187  return;
188  m_pFrameSlotUI = SCR_SlotUIComponent.Cast( wItemInfo.FindHandler( SCR_SlotUIComponent ) );
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  void Destroy()
193  {
194  if ( m_infoWidget )
195  {
196  GetGame().GetCallqueue().Remove( ShowInfoWidget );
197  m_infoWidget.RemoveHandler( m_pFrameSlotUI );
198  m_infoWidget.RemoveHandler( this );
199  m_infoWidget.RemoveFromHierarchy();
200  }
201  }
202 
203  //------------------------------------------------------------------------------------------------
204  Widget GetInfoWidget()
205  {
206  return m_infoWidget.FindAnyWidget("size");
207  }
208 
209  //------------------------------------------------------------------------ COMMON METHODS ----------------------------------------------------------------------
210 
211 
212  //------------------------------------------------------------------------------------------------
214  {
215  }
216 
217  //------------------------------------------------------------------------------------------------
219  {
220  }
221 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_InventoryItemInfoUI
Definition: SCR_InventoryItemInfoUI.c:6
SCR_SlotUIComponent
Definition: SCR_SlotUIComponent.c:6
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_InventorySlotUI
Definition: SCR_InventorySlotUI.c:27
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180