2021-05-05 11:23:15 +02:00
// Based on the Moski plugin which is also based on the Miss plugin :)
2024-02-20 22:19:26 +01:00
const string C_InvalidValueError = "Invalid value. You can set a human readable value like \\$<\\$aaa1:23.456\\$>\nor a value in milliseconds like \\$<\\$aaa83456\\$>" ;
2024-02-18 18:00:52 +01:00
bool G_MenuVisibility = false ;
string G_AuthorTimeText = "0:00:00.000" ;
2021-10-02 00:41:29 +02:00
2024-02-18 18:00:52 +01:00
void Main () {}
void Render () {
auto editor = getEditor ();
2021-05-05 11:23:15 +02:00
if ( editor is null ) {
2024-02-18 18:00:52 +01:00
G_MenuVisibility = false ;
2021-05-05 11:23:15 +02:00
return ;
2024-02-18 18:00:52 +01:00
}
2022-02-24 16:28:44 +01:00
2024-02-18 18:00:52 +01:00
auto map = getMap ();
if ( map is null ) {
G_MenuVisibility = false ;
2021-05-05 11:23:15 +02:00
return ;
}
2022-05-04 15:16:18 +02:00
2024-02-18 18:00:52 +01:00
if ( ! G_MenuVisibility ) {
// Store the last Author Time when hidden
uint CurrentAuthorTime = getAuthorTime ( map );
if ( CurrentAuthorTime < 4294967295 ) {
G_AuthorTimeText = Time :: Format ( CurrentAuthorTime );
}
2022-05-04 15:16:18 +02:00
return ;
}
2024-02-20 22:19:26 +01:00
UI :: SetNextItemWidth ( 200.0 );
2024-02-18 18:00:52 +01:00
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 ();
2021-05-05 11:27:25 +02:00
2024-02-20 22:19:26 +01:00
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 );
2021-05-05 11:23:15 +02:00
if ( UI :: Button ( "Validate" )) {
2024-02-20 22:19:26 +01:00
int AuthorTime = 0 ;
if ( IsMilliseconds ) AuthorTime = Text :: ParseUInt ( G_AuthorTimeText );
else AuthorTime = Time :: ParseRelativeTime ( G_AuthorTimeText );
setAuthorTime ( map , AuthorTime );
2024-02-18 18:00:52 +01:00
setValidationStatus ( editor );
G_MenuVisibility = false ;
2021-05-05 11:23:15 +02:00
}
2024-02-18 18:00:52 +01:00
UI :: EndDisabled ();
2024-02-20 22:19:26 +01:00
UI :: EndGroup ();
// 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 ();
}
2024-02-18 18:00:52 +01:00
2024-02-20 22:19:26 +01:00
// Warning tooltip depending the game
const string warning = GetWarning ();
2024-02-18 18:00:52 +01:00
if ( warning != "" ) {
UI :: SameLine ();
UI :: Text ( "\\$fa2" + Icons :: Info );
if ( UI :: IsItemHovered ()) {
UI :: BeginTooltip ();
UI :: Text ( warning );
UI :: EndTooltip ();
}
2021-05-05 11:27:25 +02:00
}
2024-02-20 22:19:26 +01:00
}
UI :: End ();
2021-05-05 11:23:15 +02:00
}
2024-02-18 18:00:52 +01:00
2021-05-05 11:23:15 +02:00
void RenderMenu () {
2024-02-18 18:00:52 +01:00
auto editor = getEditor ();
if ( editor is null ) return ;
2022-05-04 15:16:18 +02:00
2024-02-18 18:00:52 +01:00
auto map = getMap ();
if ( map is null ) return ;
if ( UI :: MenuItem ( "\\$cf9" + Icons :: Flag + "\\$z Map Validator" , "" , G_MenuVisibility )) {
G_MenuVisibility = ! G_MenuVisibility ;
2021-05-05 11:23:15 +02:00
}
}
2024-02-18 18:00:52 +01:00
2024-02-20 22:19:26 +01:00
bool IsMillisecondsFormat ( string _AuthorTimeText ) {
return Regex :: IsMatch ( _AuthorTimeText , '\\d+' );
}
2024-02-18 18:00:52 +01:00
bool IsValidAuthorTime ( string _AuthorTimeText ) {
if ( ! Regex :: IsMatch ( _AuthorTimeText , '[\\d\\.:]+' )) {
return false ;
}
2024-02-20 22:19:26 +01:00
if ( ! Regex :: IsMatch ( _AuthorTimeText , '^(((((\\d+:)?[0-5])?\\d:)?[0-5])?\\d)\\.\\d{3}$' )) {
2024-02-18 18:00:52 +01:00
return false ;
}
return true ;
}