Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
crosshairselector.c
Go to the documentation of this file.
1 class CrossHair
2 {
3  protected string m_Name;
4  protected bool m_Shown;
5  protected bool m_Current;
6 
7  protected Widget m_Widget;
8 
9  void CrossHair(Widget w)
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 
48  Widget GetWidget()
49  {
50  return m_Widget;
51  }
52 }
53 
55 {
56  protected PlayerBase m_Player;
58 
59  protected Widget m_Root;
60 
61  protected ref set<ref CrossHair> m_CrossHairs;
62 
65  protected bool m_PreviousDirectionSet;
66 
68  {
69  m_Player = null;
70  m_AM = null;
71  m_CrossHairs = new set<ref CrossHair>;
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  {
88  m_CrossHairs.Insert(CrossHair(child));
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  {
106  if(GetCurrentCrossHair())
107  ShowCrossHair(null);
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 
120  if(m_Player && m_Player.IsPlayerSelected())
121  {
122  SelectCrossHair();
123  }
124  }
125 
126  // getters
127  protected void GetPlayer()
128  {
129  Class.CastTo(m_Player, GetGame().GetPlayer());
130  }
131 
132  protected void GetActionManager()
133  {
134  if( m_Player && m_Player.IsPlayerSelected() )
135  {
136  Class.CastTo(m_AM, m_Player.GetActionManager());
137  }
138  else
139  m_AM = null;
140  }
141 
142  protected CrossHair GetCrossHairByName(string widgetName)
143  {
144  for(int i = 0; i < m_CrossHairs.Count(); i++)
145  {
146  if(m_CrossHairs.Get(i).GetName() == widgetName)
147  return m_CrossHairs.Get(i);
148  }
149 
150  return null;
151  }
152 
154  {
155  for(int i = 0; i < m_CrossHairs.Count(); i++)
156  {
157  if(m_CrossHairs.Get(i).IsCurrent())
158  return m_CrossHairs.Get(i);
159  }
160 
161  return null;
162  }
163 
164  protected void SelectCrossHair()
165  {
166  if(!m_AM) return;
167 
168  HumanInputController hic = m_Player.GetInputController();
169  ActionBase action = m_AM.GetRunningAction();
170 
171  bool firearmInHands = m_Player.GetItemInHands() && m_Player.GetItemInHands().IsWeapon();
172 
174  if ( firearmInHands && m_Player.IsRaised() && !m_Player.IsInIronsights() && !m_Player.IsInOptics() && !hic.CameraIsFreeLook() && !m_Player.GetCommand_Melee2() )
175  {
176  ShowCrossHair(GetCrossHairByName("crossT_128x128"));
177  }
179  else if (action && action.GetActionCategory() == AC_CONTINUOUS)
180  {
181  int actionState = m_AM.GetActionState(action);
182 
183  if ( actionState != UA_NONE )
184  ShowCrossHair(null);
185  }
187  else if ( m_Player.IsRaised() || m_Player.GetCommand_Melee2() || GetGame().GetUIManager().GetMenu() != null )
188  {
189  ShowCrossHair(null);
190  }
192  else if ( m_Player.GetCommand_Unconscious() )
193  {
194  ShowCrossHair(null);
195  }
197  else
198  {
200  }
201  }
202 
203  protected void ShowCrossHair(CrossHair crossHair)
204  {
206  if (!crossHair)
207  {
208  if (GetCurrentCrossHair())
209  GetCurrentCrossHair().Hide();
210 
211  return;
212  }
213  else
214  {
215  if (GetCurrentCrossHair() && GetCurrentCrossHair() != crossHair)
216  GetCurrentCrossHair().Hide();
217  }
218 
220  if (!crossHair.IsCurrent() && crossHair.IsShown())
221  crossHair.Show();
222 
223 #ifdef WIP_TRACKIR
224  FloatingCrossHair(crossHair.GetWidget());
225 #endif
226  }
227 
230  {
231  HumanInputController hic = m_Player.GetInputController();
232 
234  if (!hic.CameraIsTracking())
235  {
236  widget.SetPos(0, 0);
237  widget.Update();
238  return;
239  }
240 
241  ActionBase action = m_AM.GetRunningAction();
242 
243  float dt = GetDayZGame().GetDeltaT();
244 
245  HumanCommandWeapons hcw = m_Player.GetCommandModifier_Weapons();
246 
247  vector transform[4];
248  m_Player.GetTransformWS(transform);
249 
250  vector aimAngles = Vector(hcw.GetBaseAimingAngleLR(), hcw.GetBaseAimingAngleUD(), 0.0);
251  vector plrAngles = Math3D.MatrixToAngles(transform);
252 
253  aimAngles = Vector(0.0, hcw.GetBaseAimingAngleUD(), 0.0);
254  plrAngles = Vector(hic.GetHeadingAngle() * -Math.RAD2DEG, 0, 0);
255 
256  vector resAngle = aimAngles + plrAngles;
257 
258  vector start;
259  MiscGameplayFunctions.GetHeadBonePos(m_Player, start);
260 
261  vector direction = resAngle.AnglesToVector();
262 
263  int layer = ObjIntersectView;
264  float range = 1.0;
265 
266  Weapon_Base weapon;
267  if (Class.CastTo(weapon, m_Player.GetItemInHands()) && m_Player.IsRaised())
268  {
269  layer = ObjIntersectFire;
270  range = 10.0;
271 
272  vector usti_hlavne_position = weapon.GetSelectionPositionMS( "usti hlavne" );
273  vector konec_hlavne_position = weapon.GetSelectionPositionMS( "konec hlavne" );
274  usti_hlavne_position = m_Player.ModelToWorld(usti_hlavne_position);
275  konec_hlavne_position = m_Player.ModelToWorld(konec_hlavne_position);
276 
277  vector contact_dir;
278  int contact_component;
279 
280  direction = konec_hlavne_position - usti_hlavne_position;
281  direction.Normalize();
282 
283  start = konec_hlavne_position;
284 
285  m_PreviousDirectionSet = false;
286  }
287  else
288  {
290  {
291  m_PreviousDirectionSet = true;
292  m_PreviousDirection = direction;
293  }
294 
295  float r0[4];
296  float r1[4];
297 
298  vector t[4];
299 
300  Math3D.DirectionAndUpMatrix(m_PreviousDirection, vector.Up, t);
301  Math3D.MatrixToQuat(t, r0);
302 
303  Math3D.DirectionAndUpMatrix(direction, vector.Up, t);
304  Math3D.MatrixToQuat(t, r1);
305 
306  Math3D.QuatLerp(r0, r0, r1, 0.1);
307 
308  Math3D.QuatToMatrix(r0, t);
309 
310  direction = t[2];
311 
312  m_PreviousDirection = direction;
313  }
314 
315  vector end = start + (direction * range);
316  vector position = end;
317 
318  DayZPhysics.RaycastRV(start, end, position, contact_dir, contact_component, null, m_Player, m_Player, false, false, layer);
319 
320  /*
321  vector lines[2];
322  lines[0] = start;
323  lines[1] = end;
324 
325  Shape.CreateSphere(0xFFFFFF00, ShapeFlags.ONCE, usti_hlavne_position, 0.1);
326  Shape.CreateSphere(0xFFFFFF00, ShapeFlags.ONCE, konec_hlavne_position, 0.1);
327  Shape.CreateLines(0xFF00FF00, ShapeFlags.ONCE, lines, 2);
328  */
329 
330  vector screenSpace = GetGame().GetScreenPos(position);
331 
332  float sx, sy;
333  widget.GetScreenSize(sx, sy);
334  screenSpace[0] = screenSpace[0] - (sx * 0.5);
335  screenSpace[1] = screenSpace[1] - (sy * 0.5);
336 
337  widget.SetScreenPos(screenSpace[0], screenSpace[1]);
338  widget.Update();
339  }
340 }
GetGame
proto native CGame GetGame()
CrossHairSelector
void CrossHairSelector()
Definition: crosshairselector.c:67
OnWidgetScriptInit
protected void OnWidgetScriptInit(Widget w)
Definition: crosshairselector.c:93
EDayZProfilesOptions
EDayZProfilesOptions
Definition: edayzprofilesoptions.c:1
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
ShowCrossHair
protected void ShowCrossHair(CrossHair crossHair)
Definition: crosshairselector.c:203
GetCrossHairByName
protected CrossHair GetCrossHairByName(string widgetName)
Definition: crosshairselector.c:142
m_Name
string m_Name
Definition: bioslobbyservice.c:35
m_CrossHairs
protected ref set< ref CrossHair > m_CrossHairs
Definition: crosshairselector.c:61
AC_CONTINUOUS
const int AC_CONTINUOUS
Definition: _constants.c:3
FloatingCrossHair
void FloatingCrossHair(Widget widget)
Highly WIP, do not use.
Definition: crosshairselector.c:229
m_PreviousDirection
protected vector m_PreviousDirection
Floating crosshair.
Definition: crosshairselector.c:64
Init
protected void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: crosshairselector.c:81
ActionManagerBase
void ActionManagerBase(PlayerBase player)
Definition: actionmanagerbase.c:62
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition: tools.c:9
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
CrossHair
Definition: crosshairselector.c:1
~CrossHairSelector
void ~CrossHairSelector()
Definition: crosshairselector.c:76
m_AM
protected ActionManagerBase m_AM
Definition: crosshairselector.c:57
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
m_Root
protected Widget m_Root
Definition: crosshairselector.c:59
HumanInputController
Definition: human.c:17
GetCurrentCrossHair
protected CrossHair GetCurrentCrossHair()
Definition: crosshairselector.c:153
Update
protected void Update()
Definition: crosshairselector.c:101
ActionBase
void ActionBase()
Definition: actionbase.c:73
GetActionManager
protected void GetActionManager()
Definition: crosshairselector.c:132
HumanCommandWeapons
Definition: human.c:986
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
m_PreviousDirectionSet
protected bool m_PreviousDirectionSet
Definition: crosshairselector.c:65
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
DayZPhysics
Definition: dayzphysics.c:123
SelectCrossHair
protected void SelectCrossHair()
Definition: crosshairselector.c:164
Widget
Definition: enwidgets.c:189
UA_NONE
const int UA_NONE
Definition: constants.c:432
Math
Definition: enmath.c:6
m_Player
class CrossHair m_Player
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
Math3D
Definition: enmath3d.c:27