-
Notifications
You must be signed in to change notification settings - Fork 2
/
CreateUI.as
302 lines (242 loc) · 6.92 KB
/
CreateUI.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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
class CreateUI
{
bool m_visible = false;
string m_stadiumType = "Base";
array<string> m_stadiumTypes = {
"Base",
"NoStadium"
};
string m_stadiumBase = "48x48";
array<string> m_stadiumBases = {
"48x48"
};
array<string> m_moods = {
"Screen155Sunrise",
"Screen155Day",
"Screen155Sunset",
"Screen155Night"
};
string m_currentEnviro;
string m_currentCar;
string m_currentMood = m_moods[1];
string m_currentMod;
array<string> m_environments;
array<string> m_archetypes;
array<string> m_mods;
int m_decoSizeX;
int m_decoSizeY;
int m_decoSizeZ;
int m_decoGroundY;
int m_decoSizeStep = 16;
CGameManiaTitle@ m_title;
void Render()
{
if (!m_visible) {
return;
}
auto app = GetApp();
UI::Begin("Create a new map", m_visible, UI::WindowFlags::NoResize | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoCollapse);
if (m_environments.Length <= 0 || m_archetypes.Length <= 0) {
// Not in a pack
UI::Text("Enter a title pack before trying to create a new map.");
} else if (app.RootMap !is null) {
// A map is loaded
UI::Text("Return to the main menu to create a new map.");
} else {
// Ready to create a new map
UI::Text("Environment");
// Environment
if (UI::BeginCombo("Environment", m_currentEnviro)) {
for (uint i = 0; i < m_environments.Length; i++) {
string environment = m_environments[i];
if (UI::Selectable(environment, environment == m_currentEnviro)) {
SetEnvironment(environment);
}
}
UI::EndCombo();
}
// Archetype
if (UI::BeginCombo("Gameplay", m_currentCar)) {
for (uint i = 0; i < m_archetypes.Length; i++) {
string archetype = m_archetypes[i];
if (UI::Selectable(archetype, archetype == m_currentCar)) {
m_currentCar = archetype;
}
}
UI::EndCombo();
}
// Mod
if (m_mods.Length > 0) {
if (UI::BeginCombo("Mod", m_currentMod)) {
if (UI::Selectable("(none)", m_currentMod == "")) {
m_currentMod = "";
}
for (uint i = 0; i < m_mods.Length; i++) {
string mod = m_mods[i];
if (UI::Selectable(mod, mod == m_currentMod)) {
m_currentMod = mod;
}
}
UI::EndCombo();
}
}
UI::Text("Decoration properties");
// Stadium decoration type
if (m_currentEnviro == "Stadium") {
if (UI::BeginCombo("Base", m_stadiumBase)) {
for (uint i = 0; i < m_stadiumBases.Length; i++) {
string stadiumBase = m_stadiumBases[i];
if (UI::Selectable(stadiumBase, stadiumBase == m_stadiumBase)) {
m_stadiumBase = stadiumBase;
UpdateSizeSettings();
}
}
UI::EndCombo();
}
}
// Mood
if (UI::BeginCombo("Mood", m_currentMood)) {
for (uint i = 0; i < m_moods.Length; i++) {
string mood = m_moods[i];
if (UI::Selectable(mood, mood == m_currentMood)) {
m_currentMood = mood;
}
}
UI::EndCombo();
}
// Dimensions
if (m_decoSizeX <= 0) { m_decoSizeX = m_decoSizeStep; }
if (m_decoSizeY <= 0) { m_decoSizeY = m_decoSizeStep; }
if (m_decoSizeZ <= 0) { m_decoSizeZ = m_decoSizeStep; }
m_decoSizeX = UI::InputInt("Size X", m_decoSizeX, m_decoSizeStep);
m_decoSizeY = UI::InputInt("Size Y (height)", m_decoSizeY, m_decoSizeStep);
m_decoSizeZ = UI::InputInt("Size Z", m_decoSizeZ, m_decoSizeStep);
// Limitation of the engine
if (m_decoSizeX > 255) { m_decoSizeX = 255; }
if (m_decoSizeY > 255) { m_decoSizeY = 255; }
if (m_decoSizeZ > 255) { m_decoSizeZ = 255; }
// Ground height
//if (m_decoGroundY < 0) m_decoGroundY = 0;
//m_decoGroundY = UI::InputInt("Ground Y", m_decoGroundY, 1);
// Create
if (UI::Button("Create")) {
m_visible = false;
EditNewMap();
}
UI::SameLine();
}
if (UI::Button("Close")) {
m_visible = false;
}
UI::End();
}
void SetEnvironment(const string &in enviro)
{
m_currentEnviro = enviro;
if (m_currentEnviro == "Stadium") { m_currentCar = "CarSport"; }
UpdateSizeSettings();
SetMods();
}
void UpdateSizeSettings()
{
m_decoSizeY = 40;
if (m_currentEnviro == "Stadium") {
m_decoSizeX = 48;
m_decoGroundY = 8;
}
m_decoSizeZ = m_decoSizeX;
}
void EditNewMap()
{
CTrackMania@ app = cast<CTrackMania>(GetApp());
if (app.ManiaTitleControlScriptAPI is null) {
return;
}
@g_decorSize = null;
CGameCtnDecoration@ deco = null;
auto fidDeco = Fids::GetGame("GameData/Stadium/GameCtnDecoration/" + m_stadiumType + m_stadiumBase + m_currentMood + ".Decoration.Gbx");
if (fidDeco !is null) {
@deco = cast<CGameCtnDecoration>(Fids::Preload(fidDeco));
if (deco is null) {
error("Unable to load decor for base '" + m_stadiumType + "' with '" + m_stadiumBase + "' and mood '" + m_currentMood + "'!");
return;
}
} else {
error("Unable to find decor for base '" + m_stadiumType + "' with '" + m_stadiumBase + "' and mood '" + m_currentMood + "'!");
return;
}
@g_decorSize = deco.DecoSize;
g_originalSize.x = g_decorSize.SizeX;
g_originalSize.y = g_decorSize.SizeY;
g_originalSize.z = g_decorSize.SizeZ;
print("Setting decor size");
g_decorSize.SizeX = m_decoSizeX;
g_decorSize.SizeY = m_decoSizeY;
g_decorSize.SizeZ = m_decoSizeZ;
//g_decorSize.BaseHeightOffset = m_decoGroundY;
string modPath = "";
if (m_currentMod != "") {
modPath = "Skins/" + m_currentEnviro + "/Mod/" + m_currentMod;
}
print("Starting editor");
app.ManiaTitleControlScriptAPI.EditNewMap2(
m_currentEnviro,
m_stadiumBase + m_currentMood,
modPath,
m_currentCar,
"", false, "", ""
);
}
void Update()
{
if (!m_visible) {
@m_title = null;
return;
}
auto app = cast<CGameManiaPlanet>(GetApp());
if (m_title !is app.LoadedManiaTitle) {
@m_title = app.LoadedManiaTitle;
UpdateInfo();
}
}
void SetMods()
{
string skinsPath = "Skins/" + m_currentEnviro + "/Mod";
m_mods.RemoveRange(0, m_mods.Length);
AddMods(Fids::GetUserFolder(skinsPath));
auto folderTitles = Fids::GetFakeFolder("Titles");
if (folderTitles !is null) {
for (uint j = 0; j < folderTitles.Trees.Length; j++) {
AddMods(Fids::GetFidsFolder(folderTitles.Trees[j], skinsPath));
}
}
m_currentMod = "";
}
void AddMods(CSystemFidsFolder@ folder)
{
if (folder is null) {
return;
}
for (uint i = 0; i < folder.Leaves.Length; i++) {
auto fidMod = folder.Leaves[i];
m_mods.InsertLast(fidMod.FileName);
}
}
void UpdateInfo()
{
m_environments.RemoveRange(0, m_environments.Length);
m_archetypes.RemoveRange(0, m_archetypes.Length);
for (uint i = 0; i < m_title.CollectionFids.Length; i++) {
auto fid = cast<CSystemFidFile>(m_title.CollectionFids[i]);
if (fid.ShortFileName == "Stadium" || fid.ShortFileName == "StadiumCE") {
m_environments.InsertLast("Stadium");
m_archetypes.InsertLast("CarSport");
m_archetypes.InsertLast("CarSnow");
m_archetypes.InsertLast("CarRally");
m_archetypes.InsertLast("CarDesert");
m_archetypes.InsertLast("CharacterPilot");
}
SetEnvironment(m_environments[0]);
}
}
}