mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #8173 from Robyt3/Client-Demo-Loading-Message
Render loading popup also while loading demo files
This commit is contained in:
commit
a9b254b0e2
|
@ -61,11 +61,17 @@ public:
|
|||
{
|
||||
LOADING_STATE_DETAIL_INITIAL,
|
||||
LOADING_STATE_DETAIL_LOADING_MAP,
|
||||
LOADING_STATE_DETAIL_LOADING_DEMO,
|
||||
LOADING_STATE_DETAIL_SENDING_READY,
|
||||
LOADING_STATE_DETAIL_GETTING_READY,
|
||||
};
|
||||
|
||||
typedef std::function<void()> TMapLoadingCallbackFunc;
|
||||
enum ELoadingCallbackDetail
|
||||
{
|
||||
LOADING_CALLBACK_DETAIL_MAP,
|
||||
LOADING_CALLBACK_DETAIL_DEMO,
|
||||
};
|
||||
typedef std::function<void(ELoadingCallbackDetail Detail)> TLoadingCallback;
|
||||
|
||||
protected:
|
||||
// quick access to state of the client
|
||||
|
@ -88,7 +94,7 @@ protected:
|
|||
float m_RenderFrameTime = 0.0001f;
|
||||
float m_FrameTimeAvg = 0.0001f;
|
||||
|
||||
TMapLoadingCallbackFunc m_MapLoadingCBFunc = nullptr;
|
||||
TLoadingCallback m_LoadingCallback = nullptr;
|
||||
|
||||
char m_aNews[3000] = "";
|
||||
int m_Points = -1;
|
||||
|
@ -128,7 +134,7 @@ public:
|
|||
inline int64_t StateStartTime() const { return m_StateStartTime; }
|
||||
void SetLoadingStateDetail(ELoadingStateDetail LoadingStateDetail) { m_LoadingStateDetail = LoadingStateDetail; }
|
||||
|
||||
void SetMapLoadingCBFunc(TMapLoadingCallbackFunc &&Func) { m_MapLoadingCBFunc = std::move(Func); }
|
||||
void SetLoadingCallback(TLoadingCallback &&Func) { m_LoadingCallback = std::move(Func); }
|
||||
|
||||
// tick time access
|
||||
inline int PrevGameTick(int Conn) const { return m_aPrevGameTick[Conn]; }
|
||||
|
|
|
@ -910,9 +910,8 @@ const char *CClient::LoadMap(const char *pName, const char *pFilename, SHA256_DI
|
|||
|
||||
SetState(IClient::STATE_LOADING);
|
||||
SetLoadingStateDetail(IClient::LOADING_STATE_DETAIL_LOADING_MAP);
|
||||
|
||||
if((bool)m_MapLoadingCBFunc)
|
||||
m_MapLoadingCBFunc();
|
||||
if((bool)m_LoadingCallback)
|
||||
m_LoadingCallback(IClient::LOADING_CALLBACK_DETAIL_MAP);
|
||||
|
||||
if(!m_pMap->Load(pFilename))
|
||||
{
|
||||
|
@ -995,8 +994,6 @@ const char *CClient::LoadMapSearch(const char *pMapName, SHA256_DIGEST *pWantedS
|
|||
}
|
||||
str_format(aBuf, sizeof(aBuf), "loading map, map=%s wanted %scrc=%08x", pMapName, aWanted, WantedCrc);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
|
||||
SetState(IClient::STATE_LOADING);
|
||||
SetLoadingStateDetail(IClient::LOADING_STATE_DETAIL_LOADING_MAP);
|
||||
|
||||
// try the normal maps folder
|
||||
str_format(aBuf, sizeof(aBuf), "maps/%s.map", pMapName);
|
||||
|
@ -3553,10 +3550,18 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
|||
Disconnect();
|
||||
m_aNetClient[CONN_MAIN].ResetErrorString();
|
||||
|
||||
SetState(IClient::STATE_LOADING);
|
||||
SetLoadingStateDetail(IClient::LOADING_STATE_DETAIL_LOADING_DEMO);
|
||||
if((bool)m_LoadingCallback)
|
||||
m_LoadingCallback(IClient::LOADING_CALLBACK_DETAIL_DEMO);
|
||||
|
||||
// try to start playback
|
||||
m_DemoPlayer.SetListener(this);
|
||||
if(m_DemoPlayer.Load(Storage(), m_pConsole, pFilename, StorageType))
|
||||
{
|
||||
DisconnectWithReason(m_DemoPlayer.ErrorMessage());
|
||||
return m_DemoPlayer.ErrorMessage();
|
||||
}
|
||||
|
||||
// load map
|
||||
const CMapInfo *pMapInfo = m_DemoPlayer.GetMapInfo();
|
||||
|
|
|
@ -1891,6 +1891,9 @@ void CMenus::RenderPopupLoading(CUIRect Screen)
|
|||
case IClient::LOADING_STATE_DETAIL_LOADING_MAP:
|
||||
str_copy(aLabel1, Localize("Loading map file from storage"));
|
||||
break;
|
||||
case IClient::LOADING_STATE_DETAIL_LOADING_DEMO:
|
||||
str_copy(aLabel1, Localize("Loading demo file from storage"));
|
||||
break;
|
||||
case IClient::LOADING_STATE_DETAIL_SENDING_READY:
|
||||
str_copy(aLabel1, Localize("Requesting to join the game"));
|
||||
break;
|
||||
|
|
|
@ -210,8 +210,31 @@ void CGameClient::OnConsoleInit()
|
|||
|
||||
void CGameClient::OnInit()
|
||||
{
|
||||
Client()->SetMapLoadingCBFunc([this]() {
|
||||
m_Menus.RenderLoading(DemoPlayer()->IsPlaying() ? Localize("Preparing demo playback") : Localize("Connected"), Localize("Loading map file from storage"), 0, false);
|
||||
Client()->SetLoadingCallback([this](IClient::ELoadingCallbackDetail Detail) {
|
||||
const char *pTitle;
|
||||
if(Detail == IClient::LOADING_CALLBACK_DETAIL_DEMO || DemoPlayer()->IsPlaying())
|
||||
{
|
||||
pTitle = Localize("Preparing demo playback");
|
||||
}
|
||||
else
|
||||
{
|
||||
pTitle = Localize("Connected");
|
||||
}
|
||||
|
||||
const char *pMessage;
|
||||
switch(Detail)
|
||||
{
|
||||
case IClient::LOADING_CALLBACK_DETAIL_MAP:
|
||||
pMessage = Localize("Loading map file from storage");
|
||||
break;
|
||||
case IClient::LOADING_CALLBACK_DETAIL_DEMO:
|
||||
pMessage = Localize("Loading demo file from storage");
|
||||
break;
|
||||
default:
|
||||
dbg_assert(false, "Invalid callback loading detail");
|
||||
dbg_break();
|
||||
}
|
||||
m_Menus.RenderLoading(pTitle, pMessage, 0, false);
|
||||
});
|
||||
|
||||
m_pGraphics = Kernel()->RequestInterface<IGraphics>();
|
||||
|
|
Loading…
Reference in a new issue