fix map validator in case of plugins API is not available

This commit is contained in:
Beu 2022-05-04 15:16:18 +02:00
parent 7608c38221
commit b1d4df560d
2 changed files with 56 additions and 35 deletions

View File

@ -6,45 +6,51 @@ int author_time;
void Main() {} void Main() {}
void validate(int author_time) { void validate(int author_time) {
// Get editor var
#if UNITED #if UNITED
CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor); CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor);
#else #else
CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor); CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor);
#endif #endif
#if TMNEXT || MP4 // Get map & pluginmaptype if possible
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap); #if TURBO
CGameEditorPluginMapMapType@ pluginmaptype = cast<CGameEditorPluginMapMapType>(editor.PluginMapType);
#elif TURBO
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge); CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
CGameCtnEditorPluginMapType@ pluginmaptype = cast<CGameCtnEditorPluginMapType>(editor.EditorMapType); CGameCtnEditorPluginMapType@ pluginmaptype = cast<CGameCtnEditorPluginMapType>(editor.EditorMapType);
#elif UNITED #elif UNITED
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge); CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
auto pluginmaptype == null;
#else
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap);
CGameEditorPluginMapMapType@ pluginmaptype = cast<CGameEditorPluginMapMapType>(editor.PluginMapType);
#endif #endif
if (editor is null) { if (editor is null) {
return; return;
} }
#if TMNEXT || MP4 if (pluginmaptype !is null) {
pluginmaptype.ValidationStatus = CGameEditorPluginMapMapType::EValidationStatus::Validated; #if TURBO
#elif TURBO pluginmaptype.ValidationStatus = CGameCtnEditorPluginMapType::EValidationStatus::Validated;
pluginmaptype.ValidationStatus = CGameCtnEditorPluginMapType::EValidationStatus::Validated; #else
pluginmaptype.ValidationStatus = CGameEditorPluginMapMapType::EValidationStatus::Validated;
#endif #endif
}
if (map !is null) { if (map !is null) {
#if UNITED #if UNITED
map.ChallengeParameters.AuthorTime = author_time; map.ChallengeParameters.AuthorTime = author_time;
map.ChallengeParameters.AuthorScore = author_time; map.ChallengeParameters.AuthorScore = author_time;
map.ChallengeParameters.GoldTime = Math::Floor((1000 + author_time + author_time * 0.06)/1000)*1000; map.ChallengeParameters.GoldTime = Math::Floor((1000 + author_time + author_time * 0.06)/1000)*1000;
map.ChallengeParameters.SilverTime = Math::Floor((1000 + author_time + author_time * 0.2)/1000)*1000; map.ChallengeParameters.SilverTime = Math::Floor((1000 + author_time + author_time * 0.2)/1000)*1000;
map.ChallengeParameters.BronzeTime = Math::Floor((1000 + author_time + author_time * 0.5)/1000)*1000; map.ChallengeParameters.BronzeTime = Math::Floor((1000 + author_time + author_time * 0.5)/1000)*1000;
#else #else
map.TMObjective_AuthorTime = author_time; map.TMObjective_AuthorTime = author_time;
#endif #endif
#if MP4 || TURBO || UNITED #if !TMNEXT
map.IdName = ""; // Remove the map UID, the game will generate it again when saving map.IdName = ""; // Remove the map UID, the game will generate it again when saving
#endif #endif
} }
} }
@ -53,20 +59,25 @@ void Render() {
if (!menu_visibility) { if (!menu_visibility) {
return; return;
} }
#if UNITED #if UNITED
CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor); CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor);
#else #else
CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor); CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor);
#endif #endif
#if TMNEXT || MP4 #if TMNEXT || MP4
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap); CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap);
#elif TURBO || UNITED #else
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge); CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
#endif #endif
UI::Begin("\\$cf9" + Icons::Flag + "\\$z Map Validator###MapValidator", menu_visibility, UI::WindowFlags::NoResize | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoCollapse); if (map is null && editor is null) {
if (map !is null && editor !is null) { menu_visibility = false;
return;
}
if (UI::Begin("\\$cf9" + Icons::Flag + "\\$z Map Validator###MapValidator", menu_visibility, UI::WindowFlags::NoResize | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoCollapse)){
author_time = UI::InputInt("Author time in ms", author_time ,1); author_time = UI::InputInt("Author time in ms", author_time ,1);
if (author_time < 0) author_time = 0; if (author_time < 0) author_time = 0;
@ -85,19 +96,32 @@ void Render() {
UI::Text("with " + display_time + " of author time"); UI::Text("with " + display_time + " of author time");
#if TURBO #if TURBO
UI::Text("Note: your map must have a start and a finish\n(or a multilap + 1CP) to be validated with the plugin"); UI::Text("Note: your map must have a start and a finish\n(or a multilap + 1CP) to be validated with the plugin");
#elif UNITED #elif UNITED
UI::Text("Note: for an unknown reason, it happens that the times of\nthe medals are not updated, I invite you to check by yourself"); UI::Text("Note: for an unknown reason, it happens that the times of\nthe medals are not updated, I invite you to check by yourself");
#endif #endif
} else {
UI::Text("Open this plugin in the map editor");
}
UI::End(); UI::End();
}
} }
void RenderMenu() { void RenderMenu() {
#if UNITED
CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor);
#else
CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor);
#endif
#if TMNEXT || MP4
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap);
#else
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
#endif
if (map is null && editor is null) {
return;
}
if(UI::MenuItem("\\$cf9" + Icons::Flag + "\\$z Map Validator", "", menu_visibility)) { if(UI::MenuItem("\\$cf9" + Icons::Flag + "\\$z Map Validator", "", menu_visibility)) {
menu_visibility = !menu_visibility; menu_visibility = !menu_visibility;
} }

View File

@ -4,9 +4,6 @@ author = "Beu"
category = "Map Editor" category = "Map Editor"
siteid = 91 siteid = 91
version = "1.5" version = "1.6"
blocks = [ "Plugin_MapValidator" ] blocks = [ "Plugin_MapValidator" ]
[script]
imports = [ "Icons.as" ]