Markers.cs 2.74 KB
Newer Older
Jitnaught's avatar
init  
Jitnaught committed
1
2
3
using GTA;
using GTA.Math;
using System;
4
using System.Collections.Generic;
Jitnaught's avatar
init  
Jitnaught committed
5
6
7
8
9
10
11
12
13
using System.Drawing;

namespace RopeCreator
{
	class Markers : Script
	{
		readonly Vector3 aimMarkerScale = new Vector3(0.05f, 0.05f, 0.05f), ropeMarkerScale = new Vector3(0.2f, 0.2f, 0.2f);

		Vector3 aimMarkerPos = Vector3.Zero;
14
		List<Vector3> ropeMarkerPositions = new List<Vector3>();
Jitnaught's avatar
init  
Jitnaught committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

		int nextGetMarkerPos = 0;

		public Markers()
		{
			Interval = 0;
			Tick += Markers_Tick;
		}

		private void GetAimMarkerPos()
		{
			if (Menu.showAimMarker)
			{
				var ray = Helper.CreateRaycastFromCam();

				aimMarkerPos = ray.HitCoords;
			}
		}

		private void GetEditRopeMarkerPos()
		{
36
			ropeMarkerPositions.Clear();
Jitnaught's avatar
init  
Jitnaught committed
37

38
39
40
			if (Menu.showEditMarkers)
			{
				if ((Menu.mainMenu.Visible && Menu.mainMenu.SelectedItem == Menu.liGroupIndex) || Menu.editGroupMenu.Visible || Menu.editRopeMenu.Visible)
Jitnaught's avatar
init  
Jitnaught committed
41
				{
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
					var group = RopeCreator.ropeGroups[Menu.liGroupIndex.SelectedIndex];

					if ((Menu.mainMenu.Visible && Menu.mainMenu.SelectedItem == Menu.liGroupIndex) || Menu.editGroupMenu.Visible)
					{
						if (group.ropes.Count > 0)
						{
							foreach (var rope in group.ropes)
							{
								ropeMarkerPositions.Add(rope.firstEntity.GetOffsetInWorldCoords(rope.firstOffset));
								ropeMarkerPositions.Add(rope.secondEntity.GetOffsetInWorldCoords(rope.secondOffset));
							}
						}
					}
					else
					{
						int selectedRopeIndex = Menu.liRopeIndex.SelectedItem;
Jitnaught's avatar
init  
Jitnaught committed
58

59
60
61
62
63
64
65
66
						if (selectedRopeIndex > -1)
						{
							var selectedRope = group.ropes[selectedRopeIndex];

							ropeMarkerPositions.Add(selectedRope.firstEntity.GetOffsetInWorldCoords(selectedRope.firstOffset));
							ropeMarkerPositions.Add(selectedRope.secondEntity.GetOffsetInWorldCoords(selectedRope.secondOffset));
						}
					}
Jitnaught's avatar
init  
Jitnaught committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
				}
			}
		}

		private void GetAllMarkerPos()
		{
			if (Game.GameTime >= nextGetMarkerPos)
			{
				GetAimMarkerPos();
				GetEditRopeMarkerPos();

				nextGetMarkerPos = Game.GameTime + 10;
			}
		}
81

Jitnaught's avatar
init  
Jitnaught committed
82
83
84
85
86
87
88
89
90
		private void DrawMarkers()
		{
			if (Game.IsScreenFadedIn && Game.Player.CanControlCharacter && Menu.modEnabled)
			{
				if (Menu.showAimMarker && (!INI.onlyShowMarkerWhenAiming || Helper.IsAiming()))
				{
					World.DrawMarker(MarkerType.DebugSphere, aimMarkerPos, Vector3.Zero, Vector3.Zero, aimMarkerScale, Color.Blue);
				}

91
				if (Menu.showEditMarkers && ropeMarkerPositions.Count > 0)
Jitnaught's avatar
init  
Jitnaught committed
92
				{
93
94
95
96
					foreach (var pos in ropeMarkerPositions)
					{
						World.DrawMarker(MarkerType.DebugSphere, pos, Vector3.Zero, Vector3.Zero, ropeMarkerScale, Color.Purple);
					}
Jitnaught's avatar
init  
Jitnaught committed
97
98
99
100
101
102
103
104
105
106
107
				}
			}
		}

		private void Markers_Tick(object sender, EventArgs e)
		{
			GetAllMarkerPos();
			DrawMarkers();
		}
	}
}