-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCheckpointCounter.as
216 lines (182 loc) · 5.22 KB
/
CheckpointCounter.as
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
/*
* author: Phlarx
*/
[Setting name="Show counter"]
bool showCounter = true;
[Setting name="Show drop shadow"]
bool showDropShadow = true;
[Setting name="Show background"]
bool showBackground = false;
[Setting name="Hide counter when interface is hidden"]
bool hideWithIFace = true;
[Setting name="Hide counter when the Openplanet overlay is hidden"]
bool hideWithOverlay = false;
[Setting name="Hide the counter if there are no checkpoints on the current map"]
bool hideIfZeroCP = false;
[Setting name="Anchor X position" min=0 max=1]
float anchorX = .5;
[Setting name="Anchor Y position" min=0 max=1]
#if TMNEXT
float anchorY = .91;
#elif TURBO
float anchorY = .895;
#elif MP4
float anchorY = .88;
#endif
[Setting name="Font size" min=8 max=72]
int fontSize = 24;
[Setting name="Font face" description="To access a custom font, place the font file in the 'Fonts' folder\
under your Openplanet user directory (create it if it does not exist).\
Then, enter the full file name in this box."]
string fontFace = "";
[Setting name="Display mode"]
EDispMode dispMode = EDispMode::ShowCompletedAndTotal;
[Setting name="Custom display format" description="%c is completed CPs\
%d is next CP\
%r is remaining CPs\
%t is total CPs\
%C is completed laps\
%D is current lap\
%R is remaining laps\
%T is total laps\
%% is a literal %"]
string customFormat = "%c / -%r / %t";
[Setting name="Change color when go-to-finish"]
bool finishColorChange = false;
[Setting name="Change color only on last lap"]
bool finishColorChangeLastLapOnly = false;
[Setting color name="Normal color"]
vec4 colorNormal = vec4(1, 1, 1, 1);
[Setting color name="Go-to-finish color"]
vec4 colorGoToFinish = vec4(1, 0, 0, 1);
enum EDispMode {
ShowCompletedAndTotal,
ShowRemainingAndTotal,
ShowCompletedAndRemaining,
ShowCompletedAndLaps,
ShowCompletedAndLapsOnMultilap,
ShowLaps,
ShowCustom
}
string curFontFace = "";
nvg::Font font;
void Main() {
// load any custom fonts
OnSettingsChanged();
CP::Main();
}
void Update(float dt) {
CP::Update();
}
void OnSettingsChanged() {
if(fontFace != curFontFace) {
font = nvg::LoadFont(fontFace, true);
curFontFace = fontFace;
}
}
void RenderMenu() {
if (UI::MenuItem("\\$09f" + Icons::Flag + "\\$z Checkpoint Counter", "", showCounter)) {
showCounter = !showCounter;
}
}
string getDisplayText() {
switch(dispMode) {
case EDispMode::ShowCompletedAndTotal:
return doFormat("%c / %t");
case EDispMode::ShowRemainingAndTotal:
return doFormat("-%r / %t");
case EDispMode::ShowCompletedAndRemaining:
return doFormat("%c / -%r");
case EDispMode::ShowCompletedAndLaps:
return doFormat("CP: %c / %t Lap: %D / %T");
case EDispMode::ShowCompletedAndLapsOnMultilap:
if (CP::maxLap > 1) {
return doFormat("CP: %c / %t Lap: %D / %T");
} else {
return doFormat("%c / %t");
}
case EDispMode::ShowLaps:
return doFormat("%D / %T");
case EDispMode::ShowCustom:
return doFormat(customFormat);
}
return "";
}
void Render() {
if(hideWithIFace && !UI::IsGameUIVisible()) {
return;
}
if(hideWithOverlay && !UI::IsOverlayShown()) {
return;
}
if(showCounter && CP::inGame && (CP::maxCP > 0 || !hideIfZeroCP)) {
string text = getDisplayText();
nvg::FontSize(fontSize);
nvg::FontFace(font);
nvg::TextAlign(nvg::Align::Center | nvg::Align::Middle);
vec2 size = nvg::TextBounds(text);
if(showBackground) {
nvg::FillColor(vec4(0, 0, 0, 0.8));
nvg::BeginPath();
nvg::RoundedRect(anchorX * Draw::GetWidth() - size.x * 0.5 - 8, anchorY * Draw::GetHeight() - size.y * 0.5 - 6, size.x + 16, size.y + 8, 5);
nvg::Fill();
nvg::ClosePath();
}
if(showDropShadow) {
nvg::FillColor(vec4(0, 0, 0, 1));
int shadowOffset = 2;
nvg::Text(anchorX * Draw::GetWidth() + shadowOffset, anchorY * Draw::GetHeight() + shadowOffset, text);
}
if(finishColorChange && CP::curCP == CP::maxCP && (!finishColorChangeLastLapOnly || CP::curLap + 1 == CP::maxLap)) {
nvg::FillColor(colorGoToFinish);
} else {
nvg::FillColor(colorNormal);
}
nvg::Text(anchorX * Draw::GetWidth(), anchorY * Draw::GetHeight(), text);
}
}
string doFormat(const string &in format) {
string result = "";
int idx = 0;
while(idx < format.Length) {
if(format[idx] == 37 /*"%"[0]*/ && idx + 1 < format.Length) {
switch(format[idx + 1]) {
case 67 /*"C"[0]*/:
result += "" + CP::curLap;
break;
case 68 /*"D"[0]*/:
result += "" + (CP::curLap + 1);
break;
case 82 /*"R"[0]*/:
result += "" + int(CP::maxLap - CP::curLap);
break;
case 84 /*"T"[0]*/:
result += "" + CP::maxLap;
break;
case 99 /*"c"[0]*/:
result += "" + CP::curCP;
break;
case 100 /*"d"[0]*/:
result += "" + (CP::curCP + 1);
break;
case 114 /*"r"[0]*/:
result += "" + int(CP::maxCP - CP::curCP);
break;
case 116 /*"t"[0]*/:
result += "" + CP::maxCP;
break;
case 37 /*"%"[0]*/:
result += "%";
break;
default:
result += format.SubStr(idx, 2);
break;
}
idx += 2;
} else {
result += format.SubStr(idx, 1);
idx += 1;
}
}
return result;
}