DayZ 1.24
Loading...
Searching...
No Matches
CrossHairSelector.c
Go to the documentation of this file.
2{
3 protected string m_Name;
4 protected bool m_Shown;
5 protected bool m_Current;
6
7 protected Widget m_Widget;
8
10 {
11 m_Widget = w;
12 m_Name = w.GetName();
13 m_Shown = true;
14 m_Current = false;
15 }
16
17 void ~CrossHair() {}
18
19 string GetName()
20 {
21 return m_Name;
22 }
23
24 bool IsCurrent()
25 {
26 return m_Current;
27 }
28
29 bool IsShown()
30 {
31 return m_Shown;
32 }
33
34 void Show()
35 {
36 m_Shown = false;
37 m_Current = true;
38 m_Widget.Show(true);
39 }
40
41 void Hide()
42 {
43 m_Shown = true;
44 m_Current = false;
45 m_Widget.Show(false);
46 }
47
49 {
50 return m_Widget;
51 }
52}
53
55{
57 protected ActionManagerBase m_AM;
58
59 protected Widget m_Root;
60
62
65 protected bool m_PreviousDirectionSet;
66
68 {
69 m_Player = null;
70 m_AM = null;
72
73 GetGame().GetPostUpdateQueue(CALL_CATEGORY_GUI).Insert(Update);
74 }
75
77 {
78 GetGame().GetPostUpdateQueue(CALL_CATEGORY_GUI).Remove(Update);
79 }
80
81 protected void Init()
82 {
83 m_CrossHairs.Clear();
84
85 Widget child = m_Root.GetChildren();
86 while (child)
87 {
89 child = child.GetSibling();
90 }
91 }
92
93 protected void OnWidgetScriptInit(Widget w)
94 {
95 m_Root = w;
96 m_Root.SetHandler(this);
97 Init();
98 m_Root.Update();
99 }
100
101 protected void Update()
102 {
104 if (!g_Game.GetProfileOption(EDayZProfilesOptions.CROSSHAIR) || g_Game.GetWorld().IsCrosshairDisabled())
105 {
108
109 return;
110 };
111
112 if (m_Player && !m_Player.IsAlive()) // handle respawn
113 {
114 m_Player = null;
115 m_AM = null;
116 }
117 if (!m_Player) GetPlayer();
118 if (!m_AM) GetActionManager();
119
122 }
123
124 // getters
125 protected void GetPlayer()
126 {
128 }
129
130 protected void GetActionManager()
131 {
133 Class.CastTo(m_AM, m_Player.GetActionManager());
134 else
135 m_AM = null;
136 }
137
139 {
140 for (int i = 0; i < m_CrossHairs.Count(); i++)
141 {
142 if (m_CrossHairs.Get(i).GetName() == widgetName)
143 return m_CrossHairs.Get(i);
144 }
145
146 return null;
147 }
148
150 {
151 for (int i = 0; i < m_CrossHairs.Count(); i++)
152 {
153 if (m_CrossHairs.Get(i).IsCurrent())
154 return m_CrossHairs.Get(i);
155 }
156
157 return null;
158 }
159
160 protected void SelectCrossHair()
161 {
162 if (!m_AM) return;
163
164 HumanInputController hic = m_Player.GetInputController();
165 ActionBase action = m_AM.GetRunningAction();
166
167 bool firearmInHands = m_Player.GetItemInHands() && m_Player.GetItemInHands().IsWeapon();
168
170 if (firearmInHands && m_Player.IsRaised() && !m_Player.IsInIronsights() && !m_Player.IsInOptics() && !hic.CameraIsFreeLook() && !m_Player.GetCommand_Melee2())
171 ShowCrossHair(GetCrossHairByName("crossT_128x128"));
173 else if (action && action.GetActionCategory() == AC_CONTINUOUS)
174 {
175 int actionState = m_AM.GetActionState(action);
176
177 if (actionState != UA_NONE)
179 }
181 else if (m_Player.IsRaised() || m_Player.GetCommand_Melee2() || GetGame().GetUIManager().GetMenu() != null)
184 else if (m_Player.GetCommand_Unconscious())
187 else
189 }
190
192 {
194 if (!crossHair)
195 {
198
199 return;
200 }
201 else
202 {
205 }
206
208 if (!crossHair.IsCurrent() && crossHair.IsShown())
209 crossHair.Show();
210
211#ifdef WIP_TRACKIR
212 FloatingCrossHair(crossHair.GetWidget());
213#endif
214 }
215
218 {
219 HumanInputController hic = m_Player.GetInputController();
220
222 if (!hic.CameraIsTracking())
223 {
224 widget.SetPos(0, 0);
225 widget.Update();
226 return;
227 }
228
229 ActionBase action = m_AM.GetRunningAction();
230
231 float dt = GetDayZGame().GetDeltaT();
232
233 HumanCommandWeapons hcw = m_Player.GetCommandModifier_Weapons();
234
235 vector transform[4];
236 m_Player.GetTransformWS(transform);
237
238 vector aimAngles = Vector(hcw.GetBaseAimingAngleLR(), hcw.GetBaseAimingAngleUD(), 0.0);
240
241 aimAngles = Vector(0.0, hcw.GetBaseAimingAngleUD(), 0.0);
242 plrAngles = Vector(hic.GetHeadingAngle() * -Math.RAD2DEG, 0, 0);
243
245
247 MiscGameplayFunctions.GetHeadBonePos(m_Player, start);
248
249 vector direction = resAngle.AnglesToVector();
250
252 float range = 1.0;
253
255 if (Class.CastTo(weapon, m_Player.GetItemInHands()) && m_Player.IsRaised())
256 {
258 range = 10.0;
259
260 vector usti_hlavne_position = weapon.GetSelectionPositionMS("usti hlavne");
261 vector konec_hlavne_position = weapon.GetSelectionPositionMS("konec hlavne");
264
267
269 direction.Normalize();
270
272
274 }
275 else
276 {
278 {
281 }
282
283 float r0[4];
284 float r1[4];
285
286 vector t[4];
287
290
293
294 Math3D.QuatLerp(r0, r0, r1, 0.1);
295
297
298 direction = t[2];
299
301 }
302
305
307
308 /*
309 vector lines[2];
310 lines[0] = start;
311 lines[1] = end;
312
313 Shape.CreateSphere(0xFFFFFF00, ShapeFlags.ONCE, usti_hlavne_position, 0.1);
314 Shape.CreateSphere(0xFFFFFF00, ShapeFlags.ONCE, konec_hlavne_position, 0.1);
315 Shape.CreateLines(0xFF00FF00, ShapeFlags.ONCE, lines, 2);
316 */
317
318 vector screenSpace = GetGame().GetScreenPos(position);
319
320 float sx, sy;
321 widget.GetScreenSize(sx, sy);
322 screenSpace[0] = screenSpace[0] - (sx * 0.5);
323 screenSpace[1] = screenSpace[1] - (sy * 0.5);
324
325 widget.SetScreenPos(screenSpace[0], screenSpace[1]);
326 widget.Update();
327 }
328}
const int AC_CONTINUOUS
Definition _constants.c:3
ActionManagerBase m_AM
void SelectCrossHair()
vector m_PreviousDirection
Floating crosshair.
void CrossHairSelector()
CrossHair GetCrossHairByName(string widgetName)
void FloatingCrossHair(Widget widget)
Highly WIP, do not use.
void ShowCrossHair(CrossHair crossHair)
CrossHair GetCurrentCrossHair()
bool m_PreviousDirectionSet
ref set< ref CrossHair > m_CrossHairs
void ~CrossHairSelector()
DayZGame g_Game
Definition DayZGame.c:3528
DayZGame GetDayZGame()
Definition DayZGame.c:3530
EDayZProfilesOptions
DayZPlayer m_Player
Definition Hand_Events.c:42
Widget m_Root
Definition SizeToChild.c:85
Super root of all classes in Enforce script.
Definition EnScript.c:11
Widget GetWidget()
string GetName()
void CrossHair(Widget w)
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
Definition EnMath.c:7
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void OnWidgetScriptInit(Widget w)
Definition SizeToChild.c:14
static const vector Up
Definition EnConvert.c:107
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto void QuatToMatrix(float q[4], out vector mat[3])
Converts quaternion to rotation matrix.
static proto vector MatrixToAngles(vector mat[3])
Returns angles of rotation matrix.
static proto void QuatLerp(out float qout[4], float q1[4], float q2[4], float frac)
Linear interpolation between q1 and q2 with weight 'frac' (0...1)
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto void MatrixToQuat(vector mat[3], out float d[4])
Converts rotation matrix to quaternion.
static proto void DirectionAndUpMatrix(vector dir, vector up, out vector mat[4])
Creates rotation matrix from direction and up vector.
static const float RAD2DEG
Definition EnMath.c:16
const int CALL_CATEGORY_GUI
Definition tools.c:9
const int UA_NONE
Definition constants.c:432
proto native volatile void Update()