Bump to version 1.8

- Allow to enter time in milliseconds like before the 1.6 version
- Add tooltip to display time in milliseconds or in race format
- Add tooltip to explain why validate button is disabled
- Improve valid time detection to allow time in seconds without minutes
This commit is contained in:
Beu 2024-02-20 22:19:26 +01:00
parent 55c5952258
commit 2d4257b010
2 changed files with 38 additions and 10 deletions

View File

@ -1,5 +1,7 @@
// Based on the Moski plugin which is also based on the Miss plugin :)
const string C_InvalidValueError = "Invalid value. You can set a human readable value like \\$<\\$aaa1:23.456\\$>\nor a value in milliseconds like \\$<\\$aaa83456\\$>";
bool G_MenuVisibility = false;
string G_AuthorTimeText = "0:00:00.000";
@ -27,21 +29,45 @@ void Render() {
return;
}
UI::SetNextItemWidth(200.0);
if (UI::Begin("\\$cf9" + Icons::Flag + "\\$z Map Validator###MapValidator", G_MenuVisibility, UI::WindowFlags::NoResize | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoCollapse)){
UI::SetNextItemWidth(100.0);
G_AuthorTimeText = UI::InputText("###AuthorTimeText", G_AuthorTimeText);
UI::SameLine();
UI::BeginDisabled(!IsValidAuthorTime(G_AuthorTimeText));
const bool IsMilliseconds = IsMillisecondsFormat(G_AuthorTimeText);
const bool IsButtonDisabled = (!IsMilliseconds && !IsValidAuthorTime(G_AuthorTimeText));
// Creating group to be able to display the tooltip even when the button is disabled
UI::BeginGroup();
UI::BeginDisabled(IsButtonDisabled);
if (UI::Button("Validate")) {
setAuthorTime(map, Time::ParseRelativeTime(G_AuthorTimeText));
int AuthorTime = 0;
if (IsMilliseconds) AuthorTime = Text::ParseUInt(G_AuthorTimeText);
else AuthorTime = Time::ParseRelativeTime(G_AuthorTimeText);
setAuthorTime(map, AuthorTime);
setValidationStatus(editor);
G_MenuVisibility = false;
}
UI::EndDisabled();
UI::EndGroup();
string warning = GetWarning();
// Time tooltip
if (UI::IsItemHovered()) {
UI::BeginTooltip();
if (IsButtonDisabled) {
UI::Text(C_InvalidValueError);
} else if (IsMilliseconds) {
UI::Text(Time::Format(Text::ParseUInt(G_AuthorTimeText)));
} else {
UI::Text("" + Time::ParseRelativeTime(G_AuthorTimeText) + " ms");
}
UI::EndTooltip();
}
// Warning tooltip depending the game
const string warning = GetWarning();
if (warning != "") {
UI::SameLine();
UI::Text("\\$fa2" + Icons::Info);
@ -51,9 +77,8 @@ void Render() {
UI::EndTooltip();
}
}
UI::End();
}
UI::End();
}
void RenderMenu() {
@ -68,14 +93,17 @@ void RenderMenu() {
}
}
bool IsMillisecondsFormat(string _AuthorTimeText) {
return Regex::IsMatch(_AuthorTimeText, '\\d+');
}
bool IsValidAuthorTime(string _AuthorTimeText) {
if (!Regex::IsMatch(_AuthorTimeText, '[\\d\\.:]+')) {
return false;
}
if (!Regex::IsMatch(_AuthorTimeText, '^((\\d+):)?(\\d|[0-5]\\d):(\\d|[0-5]\\d)\\.\\d{3}$')) {
if (!Regex::IsMatch(_AuthorTimeText, '^(((((\\d+:)?[0-5])?\\d:)?[0-5])?\\d)\\.\\d{3}$')) {
return false;
}
return true;
}

View File

@ -3,6 +3,6 @@ name = "Map Validator"
author = "Beu"
category = "Map Editor"
siteid = 91
version = "1.7"
version = "1.8"
blocks = [ "Plugin_MapValidator" ]