ValveSoftware / source-sdk-2013

The 2013 edition of the Source SDK
https://developer.valvesoftware.com/wiki/SDK2013_GettingStarted
Other
3.84k stars 2.02k forks source link

[Question] How do you properly make an implementation based on IGameUI::OnLevelLoadingFinished? #411

Open colistro123 opened 7 years ago

colistro123 commented 7 years ago

Long story short, I replaced the game ui and loading screens with HTML but once the levels are done loading I want to hide the loading screen. OnLevelLoadingFinished gets invoked once the loading screens are done but not sure on how to make a proper implementation for it.

I haven't been able to find anything to make a class that inherits from IGameUI to be able to receive the OnLevelLoadingFinished call and do something from there depending on the bError / failureReason result. As a last resort I decided to do some hideous thing like getting the IGameUI vtable, replacing the OnLevelLoadingFinished member for one of mine and calling back the original function but that's not how you should do things.

Thanks in advance.

BerntA commented 7 years ago

Can't you just use SetLoadingBackgroundDialog?

Example:

static CDllDemandLoader g_GameUIDLL("GameUI");
CreateInterfaceFn gameUIFactory = g_GameUIDLL.GetFactory();
if (gameUIFactory)
{
    GameUI = (IGameUI *)gameUIFactory(GAMEUI_INTERFACE_VERSION, NULL);
    if (GameUI)
        GameUI->SetLoadingBackgroundDialog(MyPanel->GetVPanel());
}
colistro123 commented 7 years ago

@BerntA Thanks, yeah I'm doing this to set the html panels as the backgrounds, problem is that I have another panel that needs triggering once the game is either:

A: Done loading a level. B: Fails to load a level.

As I said before there's OnLevelLoadingFinished in the IGameUI class but I couldn't find anything to make a class that inherits from that one so I know when OnLevelLoadingFinished is called.

I temporarily solved it by getting the loading state bool from GameUI (which is set to true once a level is loading and then set to false when the loading finishes or fails) and checking it in an UpdateFrame function but that's a really 'hacky' workaround I shouldn't be doing.