DayZ 1.24
Loading...
Searching...
No Matches
CrossHairSelector.c File Reference

Go to the source code of this file.

Classes

class  CrossHair
 

Functions

void CrossHairSelector ()
 
void ~CrossHairSelector ()
 
void Init ()
 Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside of a non-static system)
 
void OnWidgetScriptInit (Widget w)
 
void Update ()
 
void GetPlayer ()
 
void GetActionManager ()
 
CrossHair GetCrossHairByName (string widgetName)
 
CrossHair GetCurrentCrossHair ()
 
void SelectCrossHair ()
 
void ShowCrossHair (CrossHair crossHair)
 
void FloatingCrossHair (Widget widget)
 Highly WIP, do not use.
 

Variables

class CrossHair m_Player
 
ActionManagerBase m_AM
 
Widget m_Root
 
ref set< ref CrossHairm_CrossHairs
 
vector m_PreviousDirection
 Floating crosshair.
 
bool m_PreviousDirectionSet
 

Function Documentation

◆ CrossHairSelector()

void CrossHairSelector ( )
protected

Definition at line 67 of file CrossHairSelector.c.

68 {
69 m_Player = null;
70 m_AM = null;
72
73 GetGame().GetPostUpdateQueue(CALL_CATEGORY_GUI).Insert(Update);
74 }
ActionManagerBase m_AM
class CrossHair m_Player
ref set< ref CrossHair > m_CrossHairs
proto native CGame GetGame()
const int CALL_CATEGORY_GUI
Definition tools.c:9
void Update()

References CALL_CATEGORY_GUI, GetGame(), m_AM, m_CrossHairs, m_Player, and Update().

◆ FloatingCrossHair()

void FloatingCrossHair ( Widget widget)
protected

Highly WIP, do not use.

Only intended to be used with track IR

Definition at line 217 of file CrossHairSelector.c.

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 }
vector m_PreviousDirection
Floating crosshair.
bool m_PreviousDirectionSet
DayZGame GetDayZGame()
Definition DayZGame.c:3530
Super root of all classes in Enforce script.
Definition EnScript.c:11
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
static const vector Up
Definition EnConvert.c:107
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

References Class::CastTo(), Math3D::DirectionAndUpMatrix(), GetDayZGame(), GetGame(), DayZPlayer::IsRaised(), m_AM, m_Player, m_PreviousDirection, m_PreviousDirectionSet, Math3D::MatrixToAngles(), Math3D::MatrixToQuat(), Math3D::QuatLerp(), Math3D::QuatToMatrix(), Math::RAD2DEG, DayZPhysics::RaycastRV(), vector::Up, and Vector().

Referenced by ShowCrossHair().

◆ GetActionManager()

◆ GetCrossHairByName()

CrossHair GetCrossHairByName ( string widgetName)
protected

Definition at line 138 of file CrossHairSelector.c.

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 }

References m_CrossHairs.

Referenced by SelectCrossHair().

◆ GetCurrentCrossHair()

CrossHair GetCurrentCrossHair ( )
protected

Definition at line 149 of file CrossHairSelector.c.

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 }

References m_CrossHairs.

Referenced by ShowCrossHair(), and Update().

◆ GetPlayer()

void GetPlayer ( )
protected

Definition at line 125 of file CrossHairSelector.c.

126 {
128 }
void GetPlayer()

References Class::CastTo(), GetGame(), ScriptedWidgetEventHandler::GetPlayer(), and m_Player.

◆ Init()

void Init ( )
protected

Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside of a non-static system)

pre-init arrays

Definition at line 81 of file CrossHairSelector.c.

82 {
83 m_CrossHairs.Clear();
84
85 Widget child = m_Root.GetChildren();
86 while (child)
87 {
89 child = child.GetSibling();
90 }
91 }
Widget m_Root

References m_CrossHairs, and m_Root.

◆ OnWidgetScriptInit()

void OnWidgetScriptInit ( Widget w)
protected

Definition at line 93 of file CrossHairSelector.c.

94 {
95 m_Root = w;
96 m_Root.SetHandler(this);
97 Init();
98 m_Root.Update();
99 }
void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...

References ScriptedWidgetEventHandler::Init(), and m_Root.

◆ SelectCrossHair()

void SelectCrossHair ( )
protected

firearms

On Continuous Actions

raised hands(bare + non-firearm) + melee cmd

handle unconscious state

default

Definition at line 160 of file CrossHairSelector.c.

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 }
const int AC_CONTINUOUS
Definition _constants.c:3
CrossHair GetCrossHairByName(string widgetName)
void ShowCrossHair(CrossHair crossHair)
const int UA_NONE
Definition constants.c:432

References AC_CONTINUOUS, GetCrossHairByName(), GetGame(), DayZPlayer::IsInIronsights(), DayZPlayer::IsInOptics(), DayZPlayer::IsRaised(), m_AM, m_Player, ShowCrossHair(), and UA_NONE.

Referenced by Update().

◆ ShowCrossHair()

void ShowCrossHair ( CrossHair crossHair)
protected

no crosshair + clean + hide the previous

hide prev crosshair

show the new one

Definition at line 191 of file CrossHairSelector.c.

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 }
void FloatingCrossHair(Widget widget)
Highly WIP, do not use.
CrossHair GetCurrentCrossHair()

References FloatingCrossHair(), GetCurrentCrossHair(), and CrossHair::Hide().

Referenced by SelectCrossHair(), and Update().

◆ ~CrossHairSelector()

void ~CrossHairSelector ( )
protected

Definition at line 76 of file CrossHairSelector.c.

77 {
78 GetGame().GetPostUpdateQueue(CALL_CATEGORY_GUI).Remove(Update);
79 }

References CALL_CATEGORY_GUI, GetGame(), and Update().

Variable Documentation

◆ m_AM

◆ m_CrossHairs

ref set<ref CrossHair> m_CrossHairs
protected

◆ m_Player

class CrossHair m_Player

◆ m_PreviousDirection

vector m_PreviousDirection
protected

Floating crosshair.

Definition at line 64 of file CrossHairSelector.c.

Referenced by FloatingCrossHair().

◆ m_PreviousDirectionSet

bool m_PreviousDirectionSet
protected

Definition at line 65 of file CrossHairSelector.c.

Referenced by FloatingCrossHair().

◆ m_Root

Widget m_Root
protected

Definition at line 59 of file CrossHairSelector.c.