beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
210 stars 99 forks source link

Feature: LuaMenu widget:StartLoadingGame #1516

Open GoogleFrog opened 4 months ago

GoogleFrog commented 4 months ago

Luamenu currently has widget:ActivateGame and widget:ActivateMenu to help the lobby overlay hide and activate itself when a game is loaded behind it. However, widget:ActivateGame seems to be called when the game finishes loading, rather than when it starts. This leads to the following bug:

The lobby should have hidden itself as soon as the load screen appears, but instead, it acts as if it is hiding "behind" the load screen. My understanding of the load screen was that every lua state was suspended (apart from the lua load screen), so clicking on start was not a concern. Or perhaps the mouse click is buffered and sent to LuaMenu before widget:ActivateGame occurs, but I put echos on the start button that indicate that this is not the case. I don't know if this is a new bug, or if something changed in the years since I last looked at this area.

Interestingly, Spring.GetGameName() returns the name of the game that is loading. However, this doesn't help that much, because players can legitimately start a game by switching to the lobby and pressing start, even when a game is running. In this case, Spring.GetGameName() would not change, so it cannot be relied on to indicate when a game starts loading.

Another option is for LuaMenu itself to remember when it sends a Spring.Restart or Spring.Reload, and activate its own "Game Loading" behaviour. This would work most of the time, but open the door for spaghetti code and fudgy timers, and the stakes are too high. I say this because:

My suggestion is that the engine supply widget:StartLoadingGame. This would trigger when the loading screen appears. Chobby would use it to switch to the ingame UI, making the start button unclickable.