Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
projectedcrosshair.c
Go to the documentation of this file.
1 class ProjectedCrosshair extends ScriptedWidgetEventHandler
2 {
3  protected Widget m_Root;
4  protected vector m_Position;
5  protected bool m_Visible;
6  protected bool m_Debug;
7 
8  protected PlayerBase m_Player;
9  protected Weapon_Base m_Weapon;
10 
11  void ProjectedCrosshair()
12  {
13  m_Player = NULL;
14  m_Weapon = NULL;
15  m_Visible = false;
16  m_Debug = false;
17 
18  GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(this.Update);
19  }
20 
21  void ~ProjectedCrosshair()
22  {
23  GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(this.Update);
24  }
25 
27  {
28  m_Root = w;
29  m_Root.SetHandler(this);
30  m_Root.Update();
31  }
32 
34  protected void Update()
35  {
36 #ifdef DIAG_DEVELOPER
37  m_Debug = DiagMenu.GetBool( DiagMenuIDs.WEAPON_DEBUG );
38 #endif
39  if (!m_Debug) return;
40  if (!m_Player) GetPlayer();
41 
42  if ( m_Player && m_Player.IsPlayerSelected() && m_Player.IsRaised() && !m_Player.IsInIronsights() && !GetGame().IsInventoryOpen() )
43  {
44  float sx, sy;
45 
46  GetCrosshairPosition();
47  vector screenSpace = GetGame().GetScreenPos(m_Position);
48 
49  m_Root.GetSize(sx, sy);
50  screenSpace[0] = screenSpace[0] - sx/2;
51  screenSpace[1] = screenSpace[1] - sy/2;
52 
53  m_Root.SetPos(screenSpace[0], screenSpace[1]);
54  m_Root.Show(m_Visible);
55  }
56  else
57  {
58  m_Root.Show(false);
59  m_Position = vector.Zero;
60  }
61  }
62 
63  // getters
64  protected void GetPlayer()
65  {
66  Class.CastTo(m_Player, GetGame().GetPlayer());
67  }
68 
69  protected void GetCrosshairPosition()
70  {
71  m_Visible = false;
72  ItemBase itemInHands;
73  itemInHands = m_Player.GetItemInHands();
74  if ( itemInHands && itemInHands.IsWeapon() )
75  {
76  if( Class.CastTo(m_Weapon, itemInHands) )
77  {
78  //m_Visible = MiscGameplayFunctions.GetProjectedCursorPos3d(m_Position, m_Weapon);
79  }
80  }
81  }
82 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
OnWidgetScriptInit
void OnWidgetScriptInit(Widget w)
Definition: sizetochild.c:94
DiagMenu
Definition: endebug.c:232
m_Position
protected vector m_Position
Cached world position.
Definition: effect.c:41
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition: tools.c:9
m_Weapon
protected InventoryItem m_Weapon
Weapons - cache.
Definition: dayzplayerimplementmeleecombat.c:57
DiagMenuIDs
DiagMenuIDs
Definition: ediagmenuids.c:1
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
m_Visible
bool m_Visible
Definition: enentity.c:850
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
Widget
Definition: enwidgets.c:189
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650