File size: 1,759 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class ProjectedCrosshair extends ScriptedWidgetEventHandler
{
	protected Widget		m_Root;
	protected vector		m_Position;
	protected bool 			m_Visible;
	protected bool			m_Debug;
	
	protected PlayerBase	m_Player;
	protected Weapon_Base	m_Weapon;		

	void ProjectedCrosshair()
	{
		m_Player = NULL;
		m_Weapon = NULL;
		m_Visible = false;
		m_Debug = false;

		GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(this.Update);
	}

	void ~ProjectedCrosshair()
	{
		GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(this.Update);
	}
	
	void OnWidgetScriptInit(Widget w)
	{
		m_Root = w;
		m_Root.SetHandler(this);
		m_Root.Update();
	}
	
	//! Update
	protected void Update()
	{
#ifdef DIAG_DEVELOPER
		m_Debug = DiagMenu.GetBool( DiagMenuIDs.WEAPON_DEBUG );
#endif
		if (!m_Debug) return;
		if (!m_Player) GetPlayer();

		if ( m_Player && m_Player.IsPlayerSelected() && m_Player.IsRaised() && !m_Player.IsInIronsights() && !GetGame().IsInventoryOpen() )
		{
			float sx, sy;

			GetCrosshairPosition();
			vector screenSpace = GetGame().GetScreenPos(m_Position);

			m_Root.GetSize(sx, sy);
			screenSpace[0] = screenSpace[0] - sx/2;
			screenSpace[1] = screenSpace[1] - sy/2;
			
			m_Root.SetPos(screenSpace[0], screenSpace[1]);
			m_Root.Show(m_Visible);
		}
		else
		{
			m_Root.Show(false);
			m_Position = vector.Zero;
		}
	}

	// getters
  	protected void GetPlayer()
	{
		Class.CastTo(m_Player, GetGame().GetPlayer());
	}

	protected void GetCrosshairPosition()
	{
		m_Visible = false;
		ItemBase itemInHands;
		itemInHands = m_Player.GetItemInHands();
		if ( itemInHands && itemInHands.IsWeapon() )
		{
			if(  Class.CastTo(m_Weapon, itemInHands) )
			{
				//m_Visible = MiscGameplayFunctions.GetProjectedCursorPos3d(m_Position, m_Weapon);
			}
		}
	}
};