Skip to content

Instantly share code, notes, and snippets.

@davidbmaier
Created June 23, 2023 16:04
Show Gist options
  • Save davidbmaier/f4bf9ac2169aa18136a32332c7f1cf0a to your computer and use it in GitHub Desktop.
Save davidbmaier/f4bf9ac2169aa18136a32332c7f1cf0a to your computer and use it in GitHub Desktop.
Time spent - TM2020 editor plugin by Beu
#RequireContext CMapEditorPlugin
#Const ScriptName "TimeSpent.Script.txt"
#Const Version "2022-10-26"
// Made by Beu#1337
Text CreateManialink()
{
return """
<frame pos="-160 61">
<quad pos="-11 1" size="40 6" image="file://Media/Manialinks/Nadeo/TMNext/Menus/PageMatchmakingMain/hud_lobby_button_superroyal_bg.dds" colorize="006538" opacity="0.75"/>
<quad pos="0 -0" size="4 4" style="UICommon64_1" substyle="Chrono_light" />
<label id="label-timespent" pos="26 -0.75" size="23 2.75" halign="right" textsize="1" textcolor="ffff" textfont="GameFontSemiBold"/>
</frame>
<script><!--
#Include "TextLib" as TL
#Include "MathLib" as ML
Text TimeToText(Integer _Time) {
declare Text Result;
declare Integer Days = _Time / 86400;
declare Integer Hours = _Time % 86400 / 3600;
declare Integer Minutes = _Time % 86400 % 3600 / 60;
declare Integer Seconds = _Time % 60;
if (_Time >= 86400) {
Result ^= Days ^ "d ";
if (Hours < 10) Result ^= "0";
}
if (_Time >= 3600) {
Result ^= Hours ^ "h ";
if (Minutes < 10) Result ^= "0";
}
if (_Time >= 60) {
Result ^= Minutes ^ "m ";
if (Seconds < 10) Result ^= "0";
}
Result ^= Seconds ^ "s";
return Result;
}
main () {
declare CMlLabel Label_TimeSpent <=> (Page.GetFirstChild("label-timespent") as CMlLabel);
declare Integer TimeSpent_TimeInSecs for Page;
declare Integer Last_TimeInSecs;
while(True) {
yield;
if (Last_TimeInSecs != TimeSpent_TimeInSecs) {
Last_TimeInSecs = TimeSpent_TimeInSecs;
Label_TimeSpent.Value = TimeToText(TimeSpent_TimeInSecs);
}
}
}
--></script>
""";
}
main() {
LayersDefaultManialinkVersion = 3;
ManialinkText = CreateManialink();
declare metadata Integer Plugin_TimeSpent_TimeInSecs for Map;
declare Integer TimeSpent_TimeInSecs for ManialinkPage = Plugin_TimeSpent_TimeInSecs;
declare Integer Last_CheckUpdate = Now + 1000;
while (True) {
yield;
if (Last_CheckUpdate < Now) {
Last_CheckUpdate = Now + 1000;
Plugin_TimeSpent_TimeInSecs += 1;
TimeSpent_TimeInSecs = Plugin_TimeSpent_TimeInSecs;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment