-
Notifications
You must be signed in to change notification settings - Fork 9
/
HUD.cs
254 lines (214 loc) · 9.12 KB
/
HUD.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
using System;
using CitizenFX.Core;
using CitizenFX.Core.UI;
using CitizenFX.Core.Native;
using static CitizenFX.Core.Native.API;
using System.Drawing;
using TinyTween;
namespace FRFuel
{
public class HUD
{
protected Scaleform buttons = new Scaleform("instructional_buttons");
protected float fuelBarWidth() { return GetBarWidth(); }
protected float fuelBarHeight = 6f;
protected Color fuelBarColourNormal;
protected Color fuelBarColourWarning;
protected CitizenFX.Core.UI.Rectangle fuelBarBackdrop;
protected CitizenFX.Core.UI.Rectangle fuelBarBack;
protected CitizenFX.Core.UI.Rectangle fuelBar;
protected Tween<float> fuelBarColorTween = new FloatTween();
protected bool fuelBarAnimationDir = true;
protected PointF basePosition = new PointF(0f, 584f);
protected SizeF fuelBarBackdropSize;
protected SizeF fuelBarBackSize;
protected SizeF fuelBarSize;
public PointF Position
{
set
{
fuelBarBackdrop.Position = value;
fuelBarBack.Position = new PointF(value.X, value.Y + 3f);
fuelBar.Position = fuelBarBack.Position;
}
}
public HUD()
{
PointF fuelBarBackdropPosition = basePosition;
PointF fuelBarBackPosition = new PointF(fuelBarBackdropPosition.X, fuelBarBackdropPosition.Y + 3f);
PointF fuelBarPosition = fuelBarBackPosition;
fuelBarBackdropSize = new SizeF(fuelBarWidth(), 12f);
fuelBarBackSize = new SizeF(fuelBarWidth(), fuelBarHeight);
fuelBarSize = fuelBarBackSize;
Color fuelBarBackdropColour = Color.FromArgb(100, 0, 0, 0);
Color fuelBarBackColour = Color.FromArgb(50, 255, 179, 0);
/// Default colors will be changed in the <see cref="FRFuel.LoadConfig"/> function, by calling the <see cref="UpdateBarColors"/> function.
fuelBarColourNormal = Color.FromArgb(150, 255, 179, 0);
fuelBarColourWarning = Color.FromArgb(255, 255, 245, 220);
fuelBarBackdrop = new CitizenFX.Core.UI.Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour);
fuelBarBack = new CitizenFX.Core.UI.Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour);
fuelBar = new CitizenFX.Core.UI.Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal);
}
/// <summary>
/// Updates the <see cref="fuelBarColourNormal"/> and <see cref="fuelBarColourWarning"/> colors.
/// </summary>
/// <param name="red"></param>
/// <param name="green"></param>
/// <param name="blue"></param>
/// <param name="warningRed"></param>
/// <param name="warningGreen"></param>
/// <param name="warningBlue"></param>
public void UpdateBarColors(int red, int green, int blue, int warningRed, int warningGreen, int warningBlue)
{
fuelBarColourNormal = Color.FromArgb(150, red, green, blue);
fuelBarColourWarning = Color.FromArgb(255, warningRed, warningGreen, warningBlue);
}
/// <summary>
/// Reloads scaleform movie to ensure that it will be rendered
/// Workaround for bug
/// Looks safe to span on every tick /shrug
/// </summary>
public void ReloadScaleformMovie()
{
buttons = new Scaleform("instructional_buttons");
}
/// <summary>
/// Renders fuel bar
/// </summary>
/// <param name="currentFuelLevel"></param>
/// <param name="maxFuelLevel"></param>
public void RenderBar(float currentFuelLevel, float maxFuelLevel)
{
float fuelLevelPercentage = (100f / maxFuelLevel) * currentFuelLevel;
PointF safeZone = GetSafezoneBounds();
if (IsBigmapActive())
{
Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y - 180f);
}
else
{
Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y);
}
fuelBarBackdropSize = new SizeF(fuelBarWidth(), 12f);
fuelBarSize = new SizeF((fuelBarWidth() / 100f) * fuelLevelPercentage, fuelBarHeight);
fuelBarBackSize = fuelBarSize;
fuelBar.Size = fuelBarSize;
fuelBarBackdrop.Size = fuelBarBackdropSize;
fuelBarBack.Size = fuelBarBackSize;
if (maxFuelLevel > 0 && currentFuelLevel < 9f)
{
if (fuelBarColorTween.State == TweenState.Stopped)
{
fuelBarAnimationDir = !fuelBarAnimationDir;
fuelBarColorTween.Start(
fuelBarAnimationDir ? 100f : 255f,
fuelBarAnimationDir ? 255f : 100f,
.5f, // seconds
ScaleFuncs.QuarticEaseOut
);
}
fuelBarColorTween.Update(Game.LastFrameTime);
fuelBar.Color = Color.FromArgb((int)Math.Floor(fuelBarColorTween.CurrentValue), fuelBarColourWarning);
}
else
{
fuelBar.Color = fuelBarColourNormal;
if (fuelBarColorTween.State != TweenState.Stopped)
{
fuelBarColorTween.Stop(StopBehavior.ForceComplete);
}
}
fuelBarBackdrop.Draw();
fuelBarBack.Draw();
fuelBar.Draw();
}
/// <summary>
/// Returns user-configured screen safe zone offset
/// </summary>
/// <returns></returns>
public static PointF GetSafezoneBounds()
{
float t = GetSafeZoneSize();
float w = Screen.Width;
float h = Screen.Height;
return new PointF(
(int)Math.Round((w - (w * t)) / 2 + 1),
(int)Math.Round((h - (h * t)) / 2 - 2)
);
}
/// <summary>
/// Change instructions for engine cut off
/// </summary>
public void InstructTurnOffEngine()
{
buttons.CallFunction("CLEAR_ALL");
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
buttons.CallFunction("CREATE_CONTAINER");
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash)0x0499D7B09FC9B407, 2, (int)FRFuel.engineToggleControl, false), "Turn engine off");
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
}
/// <summary>
/// Returns resolution specified bar width
/// </summary>
/// <returns></returns>
public static float GetBarWidth()
{
float width;
double aspect = Screen.AspectRatio;
bool bigMap = IsBigmapActive();
switch (aspect)
{
case (float)1.5: // 3:2
width = bigMap ? 336f : 212f;
break;
case (float)1.33333337306976: // 4:3
width = bigMap ? 378f : 240f;
break;
case (float)1.66666662693024: // 5:3
width = bigMap ? 302f : 191f;
break;
case (float)1.25: // 5:4
width = bigMap ? 405f : 255f;
break;
case (float)1.60000002384186: // 16:10
width = bigMap ? 316f : 200f;
break;
default:
width = bigMap ? 285f : 180f; // 16:9
break;
}
return width;
}
/// <summary>
/// Change instructions for refueling and engine spin up
/// </summary>
public void InstructRefuelOrTurnOnEngine()
{
buttons.CallFunction("CLEAR_ALL");
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
buttons.CallFunction("CREATE_CONTAINER");
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash)0x0499D7B09FC9B407, 2, (int)Control.Jump, false), "Refuel");
buttons.CallFunction("SET_DATA_SLOT", 1, Function.Call<string>((Hash)0x0499D7B09FC9B407, 2, (int)FRFuel.engineToggleControl, 0), "Turn engine on");
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
}
/// <summary>
/// Change instructions for manual refueling
/// </summary>
/// <param name="label"></param>
public void InstructManualRefuel(string label)
{
buttons.CallFunction("CLEAR_ALL");
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
buttons.CallFunction("CREATE_CONTAINER");
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash)0x0499D7B09FC9B407, 2, (int)Control.Attack, false), label);
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
}
/// <summary>
/// Renders instruction
/// </summary>
public void RenderInstructions()
{
buttons.Render2D();
}
}
}