|
2 | 2 | using CitizenFX.Core;
|
3 | 3 | using CitizenFX.Core.UI;
|
4 | 4 | using CitizenFX.Core.Native;
|
5 |
| -using System.Threading.Tasks; |
6 | 5 | using System.Drawing;
|
7 | 6 | using TinyTween;
|
8 | 7 |
|
9 |
| -namespace FRFuel { |
10 |
| - public class HUD { |
11 |
| - protected Scaleform buttons = new Scaleform("instructional_buttons"); |
12 |
| - |
13 |
| - protected float fuelBarWidth = 180f; |
14 |
| - protected float fuelBarHeight = 6f; |
15 |
| - |
16 |
| - protected Color fuelBarColourNormal; |
17 |
| - protected Color fuelBarColourWarning; |
18 |
| - |
19 |
| - protected Rectangle fuelBarBackdrop; |
20 |
| - protected Rectangle fuelBarBack; |
21 |
| - protected Rectangle fuelBar; |
22 |
| - |
23 |
| - public Vector3 markerPutDown = new Vector3(0f, 0f, 3f); |
24 |
| - public Vector3 markerDir = new Vector3(); |
25 |
| - public Vector3 markerRot = new Vector3(); |
26 |
| - public Vector3 markerScale = new Vector3(15f); |
27 |
| - public Color markerColour = Color.FromArgb(50, 255, 179, 0); |
28 |
| - |
29 |
| - protected Tween<float> fuelBarColorTween = new FloatTween(); |
30 |
| - protected bool fuelBarAnimationDir = true; |
31 |
| - protected PointF basePosition = new PointF(0f, 584f); |
32 |
| - |
33 |
| - public PointF Position { |
34 |
| - set { |
35 |
| - fuelBarBackdrop.Position = value; |
36 |
| - fuelBarBack.Position = new PointF(value.X, value.Y + 3f); |
37 |
| - fuelBar.Position = fuelBarBack.Position; |
38 |
| - } |
39 |
| - } |
40 |
| - |
41 |
| - public HUD() { |
42 |
| - PointF fuelBarBackdropPosition = basePosition; |
43 |
| - PointF fuelBarBackPosition = new PointF(fuelBarBackdropPosition.X, fuelBarBackdropPosition.Y + 3f); |
44 |
| - PointF fuelBarPosition = fuelBarBackPosition; |
45 |
| - |
46 |
| - SizeF fuelBarBackdropSize = new SizeF(fuelBarWidth, 12f); |
47 |
| - SizeF fuelBarBackSize = new SizeF(fuelBarWidth, fuelBarHeight); |
48 |
| - SizeF fuelBarSize = fuelBarBackSize; |
| 8 | +namespace FRFuel |
| 9 | +{ |
| 10 | + public class HUD |
| 11 | + { |
| 12 | + protected Scaleform buttons = new Scaleform("instructional_buttons"); |
| 13 | + |
| 14 | + protected float fuelBarWidth = 180f; |
| 15 | + protected float fuelBarHeight = 6f; |
| 16 | + |
| 17 | + protected Color fuelBarColourNormal; |
| 18 | + protected Color fuelBarColourWarning; |
| 19 | + |
| 20 | + protected Rectangle fuelBarBackdrop; |
| 21 | + protected Rectangle fuelBarBack; |
| 22 | + protected Rectangle fuelBar; |
| 23 | + |
| 24 | + public Vector3 markerPutDown = new Vector3(0f, 0f, 3f); |
| 25 | + public Vector3 markerDir = new Vector3(); |
| 26 | + public Vector3 markerRot = new Vector3(); |
| 27 | + public Vector3 markerScale = new Vector3(15f); |
| 28 | + public Color markerColour = Color.FromArgb(50, 255, 179, 0); |
| 29 | + |
| 30 | + protected Tween<float> fuelBarColorTween = new FloatTween(); |
| 31 | + protected bool fuelBarAnimationDir = true; |
| 32 | + protected PointF basePosition = new PointF(0f, 584f); |
| 33 | + |
| 34 | + public PointF Position |
| 35 | + { |
| 36 | + set |
| 37 | + { |
| 38 | + fuelBarBackdrop.Position = value; |
| 39 | + fuelBarBack.Position = new PointF(value.X, value.Y + 3f); |
| 40 | + fuelBar.Position = fuelBarBack.Position; |
| 41 | + } |
| 42 | + } |
49 | 43 |
|
50 |
| - Color fuelBarBackdropColour = Color.FromArgb(100, 0, 0, 0); |
51 |
| - Color fuelBarBackColour = Color.FromArgb(50, 255, 179, 0); |
| 44 | + public HUD() |
| 45 | + { |
| 46 | + PointF fuelBarBackdropPosition = basePosition; |
| 47 | + PointF fuelBarBackPosition = new PointF(fuelBarBackdropPosition.X, fuelBarBackdropPosition.Y + 3f); |
| 48 | + PointF fuelBarPosition = fuelBarBackPosition; |
52 | 49 |
|
53 |
| - fuelBarColourNormal = Color.FromArgb(150, 255, 179, 0); |
54 |
| - fuelBarColourWarning = Color.FromArgb(255, 255, 245, 220); |
| 50 | + SizeF fuelBarBackdropSize = new SizeF(fuelBarWidth, 12f); |
| 51 | + SizeF fuelBarBackSize = new SizeF(fuelBarWidth, fuelBarHeight); |
| 52 | + SizeF fuelBarSize = fuelBarBackSize; |
55 | 53 |
|
56 |
| - fuelBarBackdrop = new Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour); |
57 |
| - fuelBarBack = new Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour); |
58 |
| - fuelBar = new Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal); |
59 |
| - } |
| 54 | + Color fuelBarBackdropColour = Color.FromArgb(100, 0, 0, 0); |
| 55 | + Color fuelBarBackColour = Color.FromArgb(50, 255, 179, 0); |
60 | 56 |
|
61 |
| - /// <summary> |
62 |
| - /// Reloads scaleform movie to ensure that it will be rendered |
63 |
| - /// Workaround for bug |
64 |
| - /// Looks safe to span on every tick /shrug |
65 |
| - /// </summary> |
66 |
| - public void ReloadScaleformMovie() { |
67 |
| - buttons = new Scaleform("instructional_buttons"); |
68 |
| - } |
| 57 | + fuelBarColourNormal = Color.FromArgb(150, 255, 179, 0); |
| 58 | + fuelBarColourWarning = Color.FromArgb(255, 255, 245, 220); |
69 | 59 |
|
70 |
| - /// <summary> |
71 |
| - /// Renders fuel bar |
72 |
| - /// </summary> |
73 |
| - /// <param name="currentFuelLevel"></param> |
74 |
| - /// <param name="maxFuelLevel"></param> |
75 |
| - public void RenderBar(float currentFuelLevel, float maxFuelLevel) { |
76 |
| - float fuelLevelPercentage = (100f / maxFuelLevel) * currentFuelLevel; |
77 |
| - PointF safeZone = GetSafezoneBounds(); |
78 |
| - |
79 |
| - Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y); |
80 |
| - |
81 |
| - fuelBar.Size = new SizeF( |
82 |
| - (fuelBarWidth / 100f) * fuelLevelPercentage, |
83 |
| - fuelBarHeight |
84 |
| - ); |
85 |
| - |
86 |
| - if (maxFuelLevel > 0 && currentFuelLevel < 9f) { |
87 |
| - if (fuelBarColorTween.State == TweenState.Stopped) { |
88 |
| - fuelBarAnimationDir = !fuelBarAnimationDir; |
89 |
| - |
90 |
| - fuelBarColorTween.Start( |
91 |
| - fuelBarAnimationDir ? 100f : 255f, |
92 |
| - fuelBarAnimationDir ? 255f : 100f, |
93 |
| - .5f, // seconds |
94 |
| - ScaleFuncs.QuarticEaseOut |
95 |
| - ); |
| 60 | + fuelBarBackdrop = new Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour); |
| 61 | + fuelBarBack = new Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour); |
| 62 | + fuelBar = new Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal); |
96 | 63 | }
|
97 | 64 |
|
98 |
| - fuelBarColorTween.Update(Game.LastFrameTime); |
| 65 | + /// <summary> |
| 66 | + /// Reloads scaleform movie to ensure that it will be rendered |
| 67 | + /// Workaround for bug |
| 68 | + /// Looks safe to span on every tick /shrug |
| 69 | + /// </summary> |
| 70 | + public void ReloadScaleformMovie() |
| 71 | + { |
| 72 | + buttons = new Scaleform("instructional_buttons"); |
| 73 | + } |
99 | 74 |
|
100 |
| - fuelBar.Color = Color.FromArgb((int) Math.Floor(fuelBarColorTween.CurrentValue), fuelBarColourWarning); |
101 |
| - } else { |
102 |
| - fuelBar.Color = fuelBarColourNormal; |
| 75 | + /// <summary> |
| 76 | + /// Renders fuel bar |
| 77 | + /// </summary> |
| 78 | + /// <param name="currentFuelLevel"></param> |
| 79 | + /// <param name="maxFuelLevel"></param> |
| 80 | + public void RenderBar(float currentFuelLevel, float maxFuelLevel) |
| 81 | + { |
| 82 | + float fuelLevelPercentage = (100f / maxFuelLevel) * currentFuelLevel; |
| 83 | + PointF safeZone = GetSafezoneBounds(); |
| 84 | + |
| 85 | + Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y); |
| 86 | + |
| 87 | + fuelBar.Size = new SizeF( |
| 88 | + (fuelBarWidth / 100f) * fuelLevelPercentage, |
| 89 | + fuelBarHeight |
| 90 | + ); |
| 91 | + |
| 92 | + if (maxFuelLevel > 0 && currentFuelLevel < 9f) |
| 93 | + { |
| 94 | + if (fuelBarColorTween.State == TweenState.Stopped) |
| 95 | + { |
| 96 | + fuelBarAnimationDir = !fuelBarAnimationDir; |
| 97 | + |
| 98 | + fuelBarColorTween.Start( |
| 99 | + fuelBarAnimationDir ? 100f : 255f, |
| 100 | + fuelBarAnimationDir ? 255f : 100f, |
| 101 | + .5f, // seconds |
| 102 | + ScaleFuncs.QuarticEaseOut |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + fuelBarColorTween.Update(Game.LastFrameTime); |
| 107 | + |
| 108 | + fuelBar.Color = Color.FromArgb((int) Math.Floor(fuelBarColorTween.CurrentValue), fuelBarColourWarning); |
| 109 | + } |
| 110 | + else |
| 111 | + { |
| 112 | + fuelBar.Color = fuelBarColourNormal; |
| 113 | + |
| 114 | + if (fuelBarColorTween.State != TweenState.Stopped) |
| 115 | + { |
| 116 | + fuelBarColorTween.Stop(StopBehavior.ForceComplete); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + fuelBarBackdrop.Draw(); |
| 121 | + fuelBarBack.Draw(); |
| 122 | + fuelBar.Draw(); |
| 123 | + } |
103 | 124 |
|
104 |
| - if (fuelBarColorTween.State != TweenState.Stopped) { |
105 |
| - fuelBarColorTween.Stop(StopBehavior.ForceComplete); |
| 125 | + /// <summary> |
| 126 | + /// Returns user-configured screen safe zone offset |
| 127 | + /// </summary> |
| 128 | + /// <returns></returns> |
| 129 | + public static PointF GetSafezoneBounds() |
| 130 | + { |
| 131 | + float t = Function.Call<float>(Hash.GET_SAFE_ZONE_SIZE); |
| 132 | + |
| 133 | + return new PointF( |
| 134 | + (int) Math.Round((1280 - (1280 * t)) / 2), |
| 135 | + (int) Math.Round((720 - (720 * t)) / 2) |
| 136 | + ); |
106 | 137 | }
|
107 |
| - } |
108 | 138 |
|
109 |
| - fuelBarBackdrop.Draw(); |
110 |
| - fuelBarBack.Draw(); |
111 |
| - fuelBar.Draw(); |
112 |
| - } |
| 139 | + /// <summary> |
| 140 | + /// Renders gas station marker |
| 141 | + /// </summary> |
| 142 | + /// <param name="pos"></param> |
| 143 | + public void RenderMarker(Vector3 pos) |
| 144 | + { |
| 145 | + World.DrawMarker( |
| 146 | + MarkerType.VerticalCylinder, |
| 147 | + pos - markerPutDown, |
| 148 | + markerDir, |
| 149 | + markerRot, |
| 150 | + markerScale, |
| 151 | + markerColour |
| 152 | + ); |
| 153 | + } |
113 | 154 |
|
114 |
| - /// <summary> |
115 |
| - /// Returns user-configure screen safe zone offset |
116 |
| - /// </summary> |
117 |
| - /// <returns></returns> |
118 |
| - public static PointF GetSafezoneBounds() { |
119 |
| - float t = Function.Call<float>(Hash.GET_SAFE_ZONE_SIZE); |
120 |
| - |
121 |
| - return new PointF( |
122 |
| - (int) Math.Round((1280 - (1280 * t)) / 2), |
123 |
| - (int) Math.Round((720 - (720 * t)) / 2) |
124 |
| - ); |
125 |
| - } |
| 155 | + /// <summary> |
| 156 | + /// Change instructions for engine cut off |
| 157 | + /// </summary> |
| 158 | + public void InstructTurnOffEngine() |
| 159 | + { |
| 160 | + buttons.CallFunction("CLEAR_ALL"); |
| 161 | + buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0); |
| 162 | + buttons.CallFunction("CREATE_CONTAINER"); |
126 | 163 |
|
127 |
| - /// <summary> |
128 |
| - /// Renders gas station marker |
129 |
| - /// </summary> |
130 |
| - /// <param name="pos"></param> |
131 |
| - public void RenderMarker(Vector3 pos) { |
132 |
| - World.DrawMarker( |
133 |
| - MarkerType.VerticalCylinder, |
134 |
| - pos - markerPutDown, |
135 |
| - markerDir, |
136 |
| - markerRot, |
137 |
| - markerScale, |
138 |
| - markerColour |
139 |
| - ); |
140 |
| - } |
| 164 | + buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn off engine"); |
141 | 165 |
|
142 |
| - /// <summary> |
143 |
| - /// Change instructions for engine cut off |
144 |
| - /// </summary> |
145 |
| - public void InstructTurnOffEngine() { |
146 |
| - buttons.CallFunction("CLEAR_ALL"); |
147 |
| - buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0); |
148 |
| - buttons.CallFunction("CREATE_CONTAINER"); |
149 |
| - |
150 |
| - buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn off engine"); |
151 |
| - |
152 |
| - buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1); |
153 |
| - } |
| 166 | + buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1); |
| 167 | + } |
154 | 168 |
|
155 |
| - /// <summary> |
156 |
| - /// Change instructions for refueling and engine spin up |
157 |
| - /// </summary> |
158 |
| - public void InstructRefuelOrTurnOnEngine() { |
159 |
| - buttons.CallFunction("CLEAR_ALL"); |
160 |
| - buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0); |
161 |
| - buttons.CallFunction("CREATE_CONTAINER"); |
| 169 | + /// <summary> |
| 170 | + /// Change instructions for refueling and engine spin up |
| 171 | + /// </summary> |
| 172 | + public void InstructRefuelOrTurnOnEngine() |
| 173 | + { |
| 174 | + buttons.CallFunction("CLEAR_ALL"); |
| 175 | + buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0); |
| 176 | + buttons.CallFunction("CREATE_CONTAINER"); |
162 | 177 |
|
163 |
| - buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Jump, 0), "Refuel"); |
164 |
| - buttons.CallFunction("SET_DATA_SLOT", 1, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn on engine"); |
| 178 | + buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Jump, 0), "Refuel"); |
| 179 | + buttons.CallFunction("SET_DATA_SLOT", 1, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn on engine"); |
165 | 180 |
|
166 |
| - buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1); |
167 |
| - } |
| 181 | + buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1); |
| 182 | + } |
168 | 183 |
|
169 |
| - /// <summary> |
170 |
| - /// Change instructions for manual refueling |
171 |
| - /// </summary> |
172 |
| - /// <param name="label"></param> |
173 |
| - public void InstructManualRefuel(string label) { |
174 |
| - buttons.CallFunction("CLEAR_ALL"); |
175 |
| - buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0); |
176 |
| - buttons.CallFunction("CREATE_CONTAINER"); |
| 184 | + /// <summary> |
| 185 | + /// Change instructions for manual refueling |
| 186 | + /// </summary> |
| 187 | + /// <param name="label"></param> |
| 188 | + public void InstructManualRefuel(string label) |
| 189 | + { |
| 190 | + buttons.CallFunction("CLEAR_ALL"); |
| 191 | + buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0); |
| 192 | + buttons.CallFunction("CREATE_CONTAINER"); |
177 | 193 |
|
178 |
| - buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Attack, 0), label); |
| 194 | + buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Attack, 0), label); |
179 | 195 |
|
180 |
| - buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1); |
181 |
| - } |
| 196 | + buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1); |
| 197 | + } |
182 | 198 |
|
183 |
| - /// <summary> |
184 |
| - /// Renders instruction |
185 |
| - /// </summary> |
186 |
| - public void RenderInstructions() { |
187 |
| - buttons.Render2D(); |
| 199 | + /// <summary> |
| 200 | + /// Renders instruction |
| 201 | + /// </summary> |
| 202 | + public void RenderInstructions() |
| 203 | + { |
| 204 | + buttons.Render2D(); |
| 205 | + } |
188 | 206 | }
|
189 |
| - } |
190 | 207 | }
|
0 commit comments