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
|
#ifndef TRACKBROWSER_H
#define TRACKBROWSER_H
#include <libultraship.h>
#include "port/Game.h"
#ifdef __cplusplus
#include <vector>
/**
* Allows exploring tracks in the menus
*/
class TrackBrowser {
private:
// Holds all available tracks
std::vector<const TrackInfo*> mTracks;
size_t mTrackIndex = 0;
public:
static TrackBrowser* Instance;
TrackBrowser(const Registry<TrackInfo>& registry) {
mTracks = registry.GetAllInfo();
RemovePodiumCeremony();
std::sort(mTracks.begin(), mTracks.end(), [](const TrackInfo* a, const TrackInfo* b) {
return a->Id < b->Id;
});
Instance = this;
}
void FindCustomTracks();
void Refresh(const Registry<TrackInfo>& registry) {
mTracks.clear();
mTracks = registry.GetAllInfo();
RemovePodiumCeremony();
std::sort(mTracks.begin(), mTracks.end(), [](const TrackInfo* a, const TrackInfo* b) {
return a->Id < b->Id;
});
mTrackIndex = 0;
}
void Reset() {
mTrackIndex = 0;
}
// Podium is not a valid user selectable option in the menus, remove it.
void RemovePodiumCeremony() {
mTracks.erase(
std::remove_if(mTracks.begin(), mTracks.end(),
[](const TrackInfo* track) {
return track && track->ResourceName == "mk:podium_ceremony";
}),
mTracks.end()
);
}
void SetTrack(std::string name) {
if (gTrackRegistry.Find(name)) {
gTrackRegistry.Invoke(name);
} else {
throw std::runtime_error("[World] [SetTrack()] Track name not found in Track list: " + name);
}
}
void NextTrack() {
if (mTracks.empty()) return;
mTrackIndex = (mTrackIndex + 1) % mTracks.size();
gTrackRegistry.Invoke(mTracks[mTrackIndex]->ResourceName);
}
void PreviousTrack() {
if (mTracks.empty()) return;
mTrackIndex = (mTrackIndex + mTracks.size() - 1) % mTracks.size();
gTrackRegistry.Invoke(mTracks[mTrackIndex]->ResourceName);
}
size_t GetTrackIndex() {
return mTrackIndex;
}
const char* GetTrackName() {
if (mTracks.empty()) return "";
if (mTracks[mTrackIndex]) {
return mTracks[mTrackIndex]->Name.c_str();
}
return "";
}
const char* GetTrackDebugName() {
if (mTracks.empty()) return "";
if (mTracks[mTrackIndex]) {
return mTracks[mTrackIndex]->DebugName.c_str();
}
return "";
}
const char* GetTrackLength() {
if (mTracks.empty()) return "";
if (mTracks[mTrackIndex]) {
return mTracks[mTrackIndex]->Length.c_str();
}
return "";
}
/**
* The index setters and getters here are for legacy code support
* Try not to rely too heavily on these functions especially for custom content.
*
* The content at an index may not be guaranteed if other clients have different custom content.
* Even the same content could be loaded at a different index
*
* The location of stock content *should* be consistent across all clients.
*/
void SetTrackByIdx(size_t trackIndex) {
if (trackIndex >= mTracks.size()) {
printf("[TrackBrowser] [SetTrackById] Error: trackIndex %zu out of bounds (max %zu)\n", trackIndex, mTracks.size());
return;
}
if (nullptr == mTracks[mTrackIndex]) {
printf("[TrackBrowser] [SetTrackById] Error: TrackInfo at index %zu is null\n", mTrackIndex);
return;
}
mTrackIndex = trackIndex;
gTrackRegistry.Invoke(mTracks[mTrackIndex]->ResourceName);
}
const char* GetTrackNameByIdx(size_t trackIndex) {
if (trackIndex >= mTracks.size()) {
printf("[TrackBrowser] [GetTrackNameByIdx] Error: trackIndex %zu out of bounds (max %zu)\n", trackIndex, mTracks.size());
return "";
}
if (nullptr == mTracks[trackIndex]) {
printf("[TrackBrowser] [GetTrackNameByIdx] Error: TrackInfo at index %zu is null\n", trackIndex);
return "";
}
return mTracks[trackIndex]->Name.c_str();
}
const char* GetTrackDebugNameByIdx(size_t trackIndex) {
if (trackIndex >= mTracks.size()) {
printf("[TrackBrowser] [GetTrackDebugNameByIdx] Error: trackIndex %zu out of bounds (max %zu)\n", trackIndex, mTracks.size());
return "";
}
if (nullptr == mTracks[trackIndex]) {
printf("[TrackBrowser] [GetTrackDebugNameByIdx] Error: TrackInfo at index %zu is null\n", trackIndex);
return "";
}
return mTracks[trackIndex]->DebugName.c_str();
}
const char* GetTrackLengthByIdx(size_t trackIndex) {
if (trackIndex >= mTracks.size()) {
printf("[TrackBrowser] [GetTrackLengthByIdx] Error: trackIndex %zu out of bounds (max %zu)\n", trackIndex, mTracks.size());
return "";
}
if (nullptr == mTracks[trackIndex]) {
printf("[TrackBrowser] [GetTrackLengthByIdx] Error: TrackInfo at index %zu is null\n", trackIndex);
return "";
}
return mTracks[trackIndex]->Length.c_str();
}
const char* GetMinimapTextureByIdx(size_t trackIndex) {
if (trackIndex >= mTracks.size()) {
printf("[TrackBrowser] [GetTrackMinimapTextureByIdx] Error: trackIndex %zu out of bounds (max %zu)\n", trackIndex, mTracks.size());
return NULL;
}
if (nullptr == mTracks[trackIndex]) {
printf("[TrackBrowser] [GetTrackMinimapTextureByIdx] Error: TrackInfo at index %zu is null\n", trackIndex);
return NULL;
}
return mTracks[trackIndex]->MinimapTexture;
}
};
#endif // __cplusplus
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void TrackBrowser_SetTrack(const char* name);
void TrackBrowser_SetTrackFromCup(void); // <-- Not in TrackBrowser class
void TrackBrowser_NextTrack(void);
void TrackBrowser_PreviousTrack(void);
size_t TrackBrowser_GetTrackIndex(void);
const char* TrackBrowser_GetTrackName(void);
const char* TrackBrowser_GetTrackDebugName(void);
const char* TrackBrowser_GetTrackLength(void);
void TrackBrowser_SetTrackByIdx(size_t trackIndex);
const char* TrackBrowser_GetTrackNameByIdx(size_t trackIndex);
const char* TrackBrowser_GetTrackDebugNameByIdx(size_t trackIndex);
const char* TrackBrowser_GetTrackLengthByIdx(size_t trackIndex);
const char* TrackBrowser_GetMinimapTextureByIdx(size_t trackIndex);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // TRACKBROWSER_H
|