Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_InventoryInspectionUI.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/UI/Inventory", description: "Inventory Item Inspection UI class")]
2 
3 //------------------------------------------------------------------------------------------------
6 class SCR_InventoryInspectionUI : ScriptedWidgetComponent
7 {
8  protected WorkspaceWidget m_workspaceWidget = null;
9  Widget m_widget = null;
10  protected RenderTargetWidget m_wItemRender = null;
11  protected InputManager m_pInputmanager = null;
12  InventoryItemComponent m_pItem = null;
13  SCR_InventoryStorageBaseUI m_inventoryStorage = null;
14  BaseWorld m_PreviewWorld = null;
15  ref SharedItemRef m_PreviewSharedItemRef = null;
16  int m_PreviewCamera = -1;
17  GenericEntity m_PreviewEntity = null;
18  vector m_PreviewRotation = vector.Zero;
19  float m_PreviewDistance = 0;
20  vector m_PreviewTargetRotation = vector.Zero;
21  float m_PreviewTargetDistance = 0;
22  bool m_InputMouseRotate = false;
23  protected SCR_InventoryNavigationButtonBack m_wButtonTraverseBack;
24 
25 
26  const string ITEM_LAYOUT = "{9A9CCE3707075EF4}UI/layouts/Menus/Inventory/InventoryInspectionPanel.layout";
27 
28  //------------------------------------------------------------------------------------------------
29  override bool OnMouseButtonDown(Widget w, int x, int y, int button)
30  {
31  if (button == 1)
32  m_InputMouseRotate = true;
33  return true;
34  }
35 
36  //------------------------------------------------------------------------------------------------
37  override bool OnMouseButtonUp(Widget w, int x, int y, int button)
38  {
39  if (button == 1)
40  m_InputMouseRotate = false;
41  return true;
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  protected void Init()
46  {
47  m_widget = m_workspaceWidget.CreateWidgets( ITEM_LAYOUT ); //, m_inventoryStorage.GetInventoryMenuHandler().GetRootWidget() );
48  m_widget.AddHandler( this );
49  m_wItemRender = RenderTargetWidget.Cast( m_widget.FindAnyWidget( "InspectRender" ) );
50 
51  CreatePreview();
52 
53  m_wButtonTraverseBack = SCR_InventoryNavigationButtonBack.Cast( SCR_InventoryNavigationButtonBack.GetInputButtonComponent( "ButtonTraverseBack", m_widget ) );
54  if ( m_wButtonTraverseBack )
55  {
56  m_wButtonTraverseBack.SetVisible( true );
57  m_wButtonTraverseBack.m_OnActivated.Insert( m_inventoryStorage.GetInventoryMenuHandler().Action_Inspect );
58  }
59  }
60 
61  //------------------------------------------------------------------------------------------------
63  void DeletePreview()
64  {
65  if (m_PreviewSharedItemRef)
66  {
67  m_PreviewCamera = -1;
68  m_PreviewEntity = null;
69  m_PreviewWorld = null;
70  m_PreviewSharedItemRef = null;
71  }
72  }
73 
74  //------------------------------------------------------------------------------------------------
76  protected void CreatePreview()
77  {
78  DeletePreview();
79 
80  m_PreviewSharedItemRef = BaseWorld.CreateWorld("InspectionPreview", "InspectionPreview");
81  m_PreviewWorld = m_PreviewSharedItemRef.GetRef();
82  m_PreviewCamera = 0;
83 
84  m_PreviewWorld.SetCameraType(m_PreviewCamera, CameraType.PERSPECTIVE);
85  m_PreviewWorld.SetCameraFarPlane(m_PreviewCamera, 50);
86  m_PreviewWorld.SetCameraNearPlane(m_PreviewCamera, 0.001);
87  //m_PreviewWorld.SetCameraVerticalFOV(m_PreviewCamera, 60);
88 
89  //Create a preview world entity, this contains the lighting setup for the worlds.
90  //Resource rsc = Resource.Load("{43DA8BEC8468C7F5}worlds/TestMaps/PreviewWorld/PreviewWorld.et");
91  //Resource rsc = Resource.Load("{C63632BF8C1F7849}worlds/TestMaps/PreviewWorld/InspectionWorld.et");
92  Resource rsc = Resource.Load("{4391FE7994EE6FE2}worlds/Sandbox/InventoryPreviewWorld10.et");
93  if (rsc.IsValid())
94  GetGame().SpawnEntityPrefab(rsc, m_PreviewWorld);
95 
96  //Create a generic entity that the mesh resource can be assigned to.
97  m_PreviewEntity = GenericEntity.Cast(m_pItem.CreatePreviewEntity(m_PreviewWorld, m_PreviewCamera));
98  CenterPreviewObject(vector.Zero);
99  ResetPreviewCamera();
100 
101  m_wItemRender.SetWorld(m_PreviewWorld, m_PreviewCamera);
102  //m_wItemRender.Update();
103  }
104 
105  //------------------------------------------------------------------------------------------------
107  void Destroy()
108  {
109  DeletePreview();
110  m_widget.RemoveHandler( this );
111  m_widget.RemoveFromHierarchy();
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  Widget GetWidget() { return m_widget; }
116 
117  //------------------------------------------------------------------------------------------------
119  void CenterPreviewObject(vector center)
120  {
121  vector mins, maxs;
122  m_PreviewEntity.GetBounds(mins, maxs);
123  m_PreviewEntity.SetOrigin((mins - maxs) * 0.5 - mins + center);
124  m_PreviewEntity.Update();
125  }
126 
127  //------------------------------------------------------------------------------------------------
129  void ResetPreviewCamera()
130  {
131  vector mins, maxs;
132  m_PreviewEntity.GetBounds(mins, maxs);
133 
134  m_PreviewRotation = "-45 -20 0";
135  m_PreviewDistance = vector.Distance(mins, maxs);
136  m_PreviewTargetRotation = m_PreviewRotation;
137  m_PreviewTargetDistance = m_PreviewDistance;
138 
139  vector camMat[4];
140  Math3D.AnglesToMatrix(m_PreviewRotation, camMat);
141  camMat[3] = m_PreviewDistance * camMat[2] * -1;
142  m_PreviewWorld.SetCameraEx(m_PreviewCamera, camMat);
143  }
144 
145  //------------------------------------------------------------------------------------------------
147  void UpdateView(float timeSlice)
148  {
149  if (!m_PreviewWorld)
150  return;
151  m_PreviewTargetDistance += timeSlice * -0.003 * Math.Clamp(m_PreviewTargetDistance, 0, 1) * m_pInputmanager.GetActionValue("Inventory_InspectZoom");
152  m_PreviewTargetDistance = Math.Clamp(m_PreviewTargetDistance, 0.1, 2);
153 
154  if (m_InputMouseRotate)
155  {
156  m_PreviewTargetRotation[0] = timeSlice * 0.1 * m_pInputmanager.GetActionValue("Inventory_InspectPanX") + m_PreviewTargetRotation[0];
157  m_PreviewTargetRotation[1] = timeSlice * -0.1 * m_pInputmanager.GetActionValue("Inventory_InspectPanY") + m_PreviewTargetRotation[1];
158  }
159  else if (m_pInputmanager.GetLastUsedInputDevice() == EInputDeviceType.GAMEPAD)
160  {
161  m_PreviewTargetRotation[0] = timeSlice * 100.0 * m_pInputmanager.GetActionValue("Inventory_InspectPanX") + m_PreviewTargetRotation[0];
162  m_PreviewTargetRotation[1] = timeSlice * 100.0 * m_pInputmanager.GetActionValue("Inventory_InspectPanY") + m_PreviewTargetRotation[1];
163  }
164 
165  float lerpTime = Math.Clamp(timeSlice * 5, 0, 1);
166 
167  m_PreviewRotation += (m_PreviewTargetRotation - m_PreviewRotation) * lerpTime;
168  m_PreviewDistance += (m_PreviewTargetDistance - m_PreviewDistance) * lerpTime;
169 
170  vector camMat[4];
171  Math3D.AnglesToMatrix(m_PreviewRotation, camMat);
172  camMat[3] = m_PreviewDistance * camMat[2] * -1;
173  m_PreviewWorld.SetCameraEx(m_PreviewCamera, camMat);
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  void SCR_InventoryInspectionUI( InventoryItemComponent pComponent = null, SCR_InventoryStorageBaseUI pStorageUI = null, BaseWorld playerWorld = null )
178  {
179  if( !pComponent )
180  return;
181 
182  m_pItem = pComponent;
183  m_inventoryStorage = pStorageUI;
184 
185  m_workspaceWidget = GetGame().GetWorkspace();
186  m_pInputmanager = GetGame().GetInputManager();
187 
188 
189  Init();
190  }
191 
192  //------------------------------------------------------------------------------------------------
194  {
195  DeletePreview();
196  }
197 };
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_InventoryInspectionUI
Definition: SCR_InventoryInspectionUI.c:6
m_PreviewEntity
protected IEntity m_PreviewEntity
Definition: SCR_ItemPlacementComponent.c:23
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_InventoryStorageBaseUI
Definition: SCR_InventoryStorageBaseUI.c:6
SCR_InventoryNavigationButtonBack
Interactive non-focus button showing hint, and triggering actions.
Definition: SCR_InventoryNavigationButtonBack.c:4
InventoryItemComponent
Definition: InventoryItemComponent.c:12
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180