Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InventoryCharacterWidgetHelper.c
Go to the documentation of this file.
1
2class SCR_InventoryCharacterWidgetHelper: ScriptedWidgetComponent
3{
4 private InputManager m_pInputmanager = null;
5 private bool m_InputMouseRotate = false;
6 private bool m_InputMouseWheel = false;
7 private ItemPreviewWidget m_pCharacterWidget = null;
8 private WorkspaceWidget m_pWorkspaceWidget = null;
9 private float m_fZoomInput = 0;
10 private vector m_vRotationInput = vector.Zero;
11 //------------------------------------------------------------------------------------------------
12 private bool CanProcessEvent(int x, int y)
13 {
14 if (m_pCharacterWidget)
15 {
16 float sizeX, sizeY;
17 float posX, posY;
18 m_pCharacterWidget.GetScreenSize(sizeX, sizeY);
19 m_pCharacterWidget.GetScreenPos(posX, posY);
20 return (x >= posX && x <= posX + sizeX && y >= posY && y <= posY + sizeY);
21 }
22 return false;
23 }
24 //------------------------------------------------------------------------------------------------
25 private void ProcessInput()
26 {
27 // Reset input to prevent update for "fuzzy zero" values
28 const float inputResetEpsilon = 10;
29 if (m_vRotationInput[0] * m_vRotationInput[0] < inputResetEpsilon)
30 {
31 m_vRotationInput[0] = 0;
32 }
33 if (m_vRotationInput[1] * m_vRotationInput[1] < inputResetEpsilon)
34 {
35 m_vRotationInput[1] = 0;
36 }
37 if (m_fZoomInput * m_fZoomInput < inputResetEpsilon)
38 {
39 m_fZoomInput = 0;
40 }
41
42 if (m_InputMouseRotate)
43 {
44 m_vRotationInput[1] = Math.Clamp(m_vRotationInput[1] + m_pInputmanager.GetActionValue("Inventory_InspectPanX"), -10, 10);
45 }
46 if (m_InputMouseWheel)
47 {
48 m_fZoomInput += 0.01 * m_pInputmanager.GetActionValue("Inventory_InspectZoom");
49 }
50
51 if (!m_pInputmanager.IsUsingMouseAndKeyboard())
52 {
53 m_vRotationInput[1] = 1000.0 * m_vRotationInput[1] + m_pInputmanager.GetActionValue("Inventory_InspectPanX");
54 m_fZoomInput += 0.01 * m_pInputmanager.GetActionValue("Inventory_InspectZoom");
55 }
56 }
57
58 //------------------------------------------------------------------------------------------------
59 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
60 {
61 if (button == 0 && w.GetName() == "playerRender" )
62 {
63 m_InputMouseRotate = CanProcessEvent(x, y);
64 }
65 return true;
66 }
67
68 //------------------------------------------------------------------------------------------------
69 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
70 {
71 if (button == 0)
72 m_InputMouseRotate = false;
73 return true;
74 }
75
76 override bool OnMouseWheel(Widget w, int x, int y, int wheel)
77 {
78 m_InputMouseWheel = CanProcessEvent(x, y);
79 return true;
80 }
81
82 bool Update(float ts, inout PreviewRenderAttributes playerRenderAttributes)
83 {
84
85 const float rotSensitivity = 500;
86 const float zoomSensitivity = -64.0;
87 const bool extrapolateInput = false;
88
89 ProcessInput();
90
91 float zoom = 0;
92 vector updatedRotation = "0 0 0";
93
94 if (extrapolateInput)
95 {
96 const float maxRotConsume = 400;
97 const float maxZoomConsume = 1;
98 const float easing = 0.1;
99
100 updatedRotation[0] = Math.Clamp(m_vRotationInput[0], -maxRotConsume, maxRotConsume);
101 updatedRotation[1] = Math.Clamp(m_vRotationInput[1], -maxRotConsume, maxRotConsume);
102
103 float rotXDelta = Math.AbsFloat(updatedRotation[1] / maxRotConsume);
104 float rotYDelta = Math.AbsFloat(updatedRotation[0] / maxRotConsume);
105
106 updatedRotation[1] = updatedRotation[1] * rotXDelta * Math.Pow(rotXDelta, easing);
107 updatedRotation[0] = updatedRotation[0] * rotYDelta * Math.Pow(rotYDelta, easing);
108
109 zoom = Math.Clamp(m_fZoomInput, -maxZoomConsume, maxZoomConsume);
110
111 float zoomAlpha = Math.AbsFloat(zoom / maxZoomConsume);
112 zoom = zoom * zoomAlpha * Math.Pow(zoomAlpha, easing);
113 }
114 else
115 {
116 const float interpolationAlpha = 0.15;
117
118 updatedRotation[0] = m_vRotationInput[0] * interpolationAlpha;
119 updatedRotation[1] = m_vRotationInput[1] * interpolationAlpha;
120 zoom = m_fZoomInput * interpolationAlpha;
121 }
122
123 m_vRotationInput[0] = m_vRotationInput[0] - updatedRotation[0];
124 m_vRotationInput[1] = m_vRotationInput[1] - updatedRotation[1];
125
126 updatedRotation[2] = 0;
127
128 m_fZoomInput -= zoom;
129
130 updatedRotation[1] = updatedRotation[1] * ts * rotSensitivity;
131 updatedRotation[0] = updatedRotation[0] * ts * rotSensitivity;
132
133 zoom = zoom * ts * zoomSensitivity;
134
135 bool changesApplied = false;
136
137 if (updatedRotation[0] * updatedRotation[0] + updatedRotation[1] * updatedRotation[1] > 0)
138 {
139 const vector limitsMin = "-30 -180 0";
140 const vector limitsMax = "0 180 0";
141 playerRenderAttributes.RotateItemCamera(updatedRotation, limitsMin, limitsMax);
142 changesApplied = true;
143 }
144 if (zoom != 0)
145 {
146 playerRenderAttributes.ZoomCamera(zoom);
147 changesApplied = true;
148 }
149
150 return changesApplied;
151 }
152
153 //------------------------------------------------------------------------------------------------
155 void Destroy()
156 {
157 if (m_pWorkspaceWidget)
158 {
159 m_pWorkspaceWidget.RemoveHandler( this );
160 m_pWorkspaceWidget.RemoveFromHierarchy();
161 }
162 }
163
164 //------------------------------------------------------------------------------------------------
165 void SCR_InventoryCharacterWidgetHelper( ItemPreviewWidget charWidget, WorkspaceWidget ww )
166 {
167 if( !charWidget || !ww)
168 return;
169
170 m_pInputmanager = GetGame().GetInputManager();
171 m_pWorkspaceWidget = ww;
172 m_pCharacterWidget = charWidget;
173 m_pWorkspaceWidget.AddHandler(this);
174
175 }
176};
ArmaReforgerScripted GetGame()
Definition game.c:1398
Input management system for user interactions.
Definition Math.c:13