Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
projectedcrosshair.c
Go to the documentation of this file.
1class 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
26 void OnWidgetScriptInit(Widget w)
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};
Super root of all classes in Enforce script.
Definition enscript.c:11
InventoryItem m_Weapon
Weapons - cache.
DiagMenuIDs
Definition ediagmenuids.c:2
vector m_Position
Cached world position.
Definition effect.c:43
proto native CGame GetGame()
bool m_Visible
Definition enentity.c:852
const int CALL_CATEGORY_GUI
Definition tools.c:9
DayZPlayer m_Player
Definition hand_events.c:42
PlayerBase GetPlayer()
Widget m_Root
Definition sizetochild.c:91
void OnWidgetScriptInit(Widget w)
Definition sizetochild.c:94