GreepTheSheep / openplanet-speedometer

A vehicle dashboard in Trackmania with RPM and speed counters, and gear indicator with custom themes!
4 stars 3 forks source link

Option to hide old Trackmania speedometers #4

Open notwa opened 1 year ago

notwa commented 1 year ago

Is it possible to hide the built-in speedometer in Trackmania 2 Canyon, allowing me to replace it with yours? The built-in speedometer is not very useful as it lacks a tachometer or any options to tweak (like positioning). It's also just big and ugly. I've done some googling, but I can only find results about server-side configs which don't apply to local play.

I looked into coding this myself, but I can't find a way to access any CGameManialinkFrame/CGameManialinkPage objects from Openplanet. It looks like I should be able to iterate over GetApp().CurrentPlayground.UIConfigs[0].UILayers, but every LocalPage member is null. If I could get a handle on the correct page, I could just run Page.MainFrame.GetFirstChild("Frame_Speed").Visible = false;.

Here's a screencap of the stock speedometer for good measure. image

GreepTheSheep commented 1 year ago

Would be cool. So we need to hide:

notwa commented 1 year ago

Ah, it affects the other TM games as well? Good to know. I recently had an itch to play Canyon after many years, so it's the only one fresh in my memory. I knew about the online one already, but I wanted to focus on the local speedometer to start.

I only just noticed the CGameNetwork::GetManialinkPages method (it's only mentioned in Openplanet's changelogs) so this seems like the way to go assuming the API doesn't change. Some proof of concept code — you probably don't want to run this every frame if you can help it:

void HideSiblings(CGameManialinkControl@ control)
{
    if (control is null) return;
    auto siblings = control.Parent.Controls;
    for (uint j = 0; j < siblings.Length; j++) {
        siblings[j].Visible = false;
    }
}

void Render()
{
    auto network = GetApp().Network;
    if (network is null) return;
    auto pages = network.GetManialinkPages();
    for (uint i = 0; i < pages.Length; i++) {
        auto page = pages[i];
        if (page is null) continue; // quite common when joining servers
        auto frame = pages[i].MainFrame;
        if (network.ClientManiaAppPlayground is null) { // Local
            auto speedometer = frame.GetFirstChild("Frame_Speed");
            if (speedometer !is null) {
                speedometer.Visible = false;
                break;
            }
        } else { // Online
            HideSiblings(frame.GetFirstChild("Frame_SpeedGauge")); // stock
            HideSiblings(frame.GetFirstChild("QuadTachometer")); // custom on some servers
        }
    }
}

This works in Canyon and Stadium… and I don't own the other games (yet).

edit: changed RenderInterface to Render because the former only runs with the F3 UI open

GreepTheSheep commented 1 year ago

Looks great, this works on all modes including Online, but this not works on "local" play (e.g RPG title pack or playing from ManiaExchange/RMC plugin), it uses a different speedometer that the normal one, example on the image below

image

I believe it uses a different Identifier that I don't know what it could be, we need some investigating on it

notwa commented 1 year ago

This should deal with that:

    auto playground = GetApp().PlaygroundScript;
    if (playground !is null) {
        playground.UIManager.UIAll.OverlayHideSpeedAndDist = true;
    }
GreepTheSheep commented 1 year ago

I haven't seen that one, that's great.

Maniaplanet is now okay for hiding the original speedometer.

I'll work on Turbo and try to figure out. I believe this should be the same as Maniaplanet

notwa commented 1 year ago

The other day, I noticed that the speedometer you posted above still appears in Test Mode in the TM2 track editors. This code works…

        playground.UIManager.UIAll.OverlayHideGauges = true;

but this also hides the timer. I'm not yet sure of a workaround for this.