From 89471db285e1c8df95411b6c762a95a164a5c9f8 Mon Sep 17 00:00:00 2001 From: Beu Date: Sat, 19 Aug 2023 17:55:07 +0200 Subject: [PATCH] add CountdownMover --- CountdownMover/info.toml | 6 ++++ CountdownMover/main.as | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 CountdownMover/info.toml create mode 100644 CountdownMover/main.as diff --git a/CountdownMover/info.toml b/CountdownMover/info.toml new file mode 100644 index 0000000..08ba429 --- /dev/null +++ b/CountdownMover/info.toml @@ -0,0 +1,6 @@ +[meta] +name = "Countdown Mover" +author = "Beu" +category = "Overlay" +version = "1.0" +siteid = 431 \ No newline at end of file diff --git a/CountdownMover/main.as b/CountdownMover/main.as new file mode 100644 index 0000000..142d002 --- /dev/null +++ b/CountdownMover/main.as @@ -0,0 +1,62 @@ +[Setting name="Countdown Position"] +vec2 Setting_CountdownOffset = vec2(155. , 4.); + +const string C_Class_UIModules = 'component-modelibs-uimodules-module'; +const string C_Id_Countdown = 'Race_Countdown'; + +string G_Last_ServerLogin = ""; +uint G_Last_UILayers_Length = 0; +CGameManialinkControl@ G_Control; +bool Update; + +// Search and return the CMlFrame of the Race_Countdown UIModule +CGameManialinkControl@ GetControl(CGameManiaAppPlayground@ _ManiaApp) { + for (uint Index = 0; Index < _ManiaApp.UILayers.Length; ++Index) { + CGameUILayer@ Layer = _ManiaApp.UILayers[Index]; + CGameManialinkPage@ Page = Layer.LocalPage; + + // Check if we have the main UI module + Page.GetClassChildren(C_Class_UIModules, Page.MainFrame, true); + + if (Page.GetClassChildren_Result.Length > 0) { + if (Page.GetClassChildren_Result[0].ControlId == C_Id_Countdown) { + return Page.GetClassChildren_Result[0]; + } + } + } + return null; +} + +void OnSettingsChanged() { + Update = true; +} + +void Main() { + while(true) { + CTrackMania@ App = cast(GetApp()); + CTrackManiaNetwork@ Network = cast(App.Network); + CTrackManiaNetworkServerInfo@ ServerInfo = cast(Network.ServerInfo); + CGameManiaAppPlayground@ ManiaApp = Network.ClientManiaAppPlayground; + + if (Network !is null && ServerInfo !is null && ManiaApp !is null) { + if (G_Last_ServerLogin != ServerInfo.ServerLogin || G_Last_UILayers_Length != ManiaApp.UILayers.Length) { + G_Last_ServerLogin = ServerInfo.ServerLogin; + G_Last_UILayers_Length = ManiaApp.UILayers.Length; + @G_Control = GetControl(ManiaApp); + Update = true; + } + + if (G_Control !is null && Update) { + Update = false; + G_Control.RelativePosition_V3 = Setting_CountdownOffset; + } + } else { + G_Last_ServerLogin = ""; + G_Last_UILayers_Length = 0; + @G_Control = null; + Update = true; + } + + sleep(1000); + } +}