Skip to content

Commit

Permalink
Handle error on loading game resources
Browse files Browse the repository at this point in the history
Fixes #1244
  • Loading branch information
Flamefire authored and Flow86 committed Jul 4, 2020
1 parent 969c93a commit 1a1bc12
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
45 changes: 31 additions & 14 deletions libs/s25main/desktops/dskCredits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "controls/ctrlButton.h"
#include "drivers/VideoDriverWrapper.h"
#include "dskMainMenu.h"
#include "ingameWindows/iwMsgbox.h"
#include "lua/GameDataLoader.h"
#include "ogl/FontStyle.h"
#include "ogl/MusicItem.h"
Expand All @@ -43,7 +44,7 @@ const unsigned PAGE_TIME = 12900;
/// Duration for fading between pages
const unsigned FADING_TIME = 2000;

dskCredits::dskCredits() : Desktop(LOADER.GetImageN("setup013", 0))
dskCredits::dskCredits() : Desktop(LOADER.GetImageN("setup013", 0)), itCurEntry(entries.end())
{
// Zurück
AddTextButton(0, DrawPoint(300, 550), Extent(200, 22), TC_RED1, _("Back"), NormalFont);
Expand All @@ -53,6 +54,25 @@ dskCredits::dskCredits() : Desktop(LOADER.GetImageN("setup013", 0))
// "Credits"
AddText(2, DrawPoint(400, 33), _("Credits"), COLOR_YELLOW, FontStyle::CENTER, LargeFont);

itCurEntry = entries.end();

WorldDescription worldDesc;
GameDataLoader gdLoader(worldDesc);
if(!gdLoader.Load())
{
WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"), _("Failed to load game data"), this, MSB_OK, MSB_EXCLAMATIONRED, 0));
return;
}

std::vector<Nation> nations(NUM_NATIVE_NATS);
for(int i = 0; i < NUM_NATIVE_NATS; i++)
nations[i] = Nation(i);

if(!LOADER.LoadFilesAtGame(worldDesc.get(DescIdx<LandscapeDesc>(0)).mapGfxPath, false, nations))
{
WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"), _("Failed to load game resources"), this, MSB_OK, MSB_EXCLAMATIONRED, 0));
return;
}
CreditsEntry entry = CreditsEntry("Florian Doersch (FloSoft):", GetCreditsImgOrDefault("flosoft"));
entry.lines.push_back(_("Project management"));
entry.lines.push_back(_("Server management"));
Expand Down Expand Up @@ -151,17 +171,6 @@ dskCredits::dskCredits() : Desktop(LOADER.GetImageN("setup013", 0))
entry.lines.push_back(_("Thank you!"));
entries.push_back(entry);

WorldDescription worldDesc;
GameDataLoader gdLoader(worldDesc);
if(!gdLoader.Load())
throw std::runtime_error("Failed to load game data");

std::vector<Nation> nations(NUM_NATIVE_NATS);
for(int i = 0; i < NUM_NATIVE_NATS; i++)
nations[i] = Nation(i);

LOADER.LoadFilesAtGame(worldDesc.get(DescIdx<LandscapeDesc>(0)).mapGfxPath, false, nations);

this->itCurEntry = entries.begin();

if(LOADER.sng_lst.size() > 8)
Expand All @@ -173,8 +182,11 @@ dskCredits::~dskCredits() = default;
void dskCredits::Draw_()
{
Desktop::Draw_();
DrawBobs();
DrawCredit();
if(itCurEntry != entries.end())
{
DrawBobs();
DrawCredit();
}
}

void dskCredits::DrawCredit()
Expand Down Expand Up @@ -332,6 +344,11 @@ void dskCredits::Msg_ButtonClick(const unsigned /*ctrl_id*/)
Close();
}

void dskCredits::Msg_MsgBoxResult(unsigned, MsgboxResult)
{
Close();
}

void dskCredits::SetActive(bool active)
{
Desktop::SetActive(active);
Expand Down
1 change: 1 addition & 0 deletions libs/s25main/desktops/dskCredits.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class dskCredits : public Desktop
bool Msg_KeyDown(const KeyEvent& ke) override;
void Draw_() override;
void Msg_ButtonClick(unsigned ctrl_id) override;
void Msg_MsgBoxResult(unsigned msgbox_id, MsgboxResult) override;
void SetActive(bool active) override;
static bool Close();

Expand Down
20 changes: 14 additions & 6 deletions libs/s25main/desktops/dskGameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ void dskGameLoader::Msg_Timer(const unsigned /*ctrl_id*/)
case 3: // Objekte laden
{
loader_.initTextures();
loader_.loadTextures();
if(!loader_.loadTextures())
{
ShowErrorMsg(_("Failed to load game resources"));
return; // Don't restart timer!
}

text->SetText(_("Game crate was picked and spread out..."));
break;
Expand All @@ -114,7 +118,7 @@ void dskGameLoader::Msg_Timer(const unsigned /*ctrl_id*/)
gameInterface = std::make_unique<dskGameInterface>(loader_.getGame(), GAMECLIENT.GetNWFInfo(), GAMECLIENT.GetPlayerId());
} catch(std::runtime_error& e)
{
LC_Status_Error(std::string(_("Failed to init GUI: ")) + e.what());
ShowErrorMsg(std::string(_("Failed to init GUI: ")) + e.what());
return;
}
// TODO: richtige Messages senden, um das zu laden /*GetMap()->GenerateOpenGL();*/
Expand All @@ -135,13 +139,18 @@ void dskGameLoader::Msg_Timer(const unsigned /*ctrl_id*/)
timer->Start(interval);
}

void dskGameLoader::ShowErrorMsg(const std::string& error)
{
WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"), error, this, MSB_OK, MSB_EXCLAMATIONRED, 0));
GetCtrl<ctrlTimer>(1)->Stop();
}

/**
* (Lobby-)Status: Benutzerdefinierter Fehler (kann auch Conn-Loss o.ä sein)
*/
void dskGameLoader::LC_Status_Error(const std::string& error)
{
WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"), error, this, MSB_OK, MSB_EXCLAMATIONRED, 0));
GetCtrl<ctrlTimer>(1)->Stop();
ShowErrorMsg(error);
}

void dskGameLoader::CI_GameStarted(const std::shared_ptr<Game>&)
Expand All @@ -152,6 +161,5 @@ void dskGameLoader::CI_GameStarted(const std::shared_ptr<Game>&)

void dskGameLoader::CI_Error(const ClientError ce)
{
WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"), ClientErrorToStr(ce), this, MSB_OK, MSB_EXCLAMATIONRED, 0));
GetCtrl<ctrlTimer>(1)->Stop();
ShowErrorMsg(ClientErrorToStr(ce));
}
1 change: 1 addition & 0 deletions libs/s25main/desktops/dskGameLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class dskGameLoader : public Desktop, public ClientInterface, public LobbyInterf
private:
void Msg_MsgBoxResult(unsigned msgbox_id, MsgboxResult mbr) override;
void Msg_Timer(unsigned ctrl_id) override;
void ShowErrorMsg(const std::string& error);

unsigned position;
GameLoader loader_;
Expand Down

0 comments on commit 1a1bc12

Please sign in to comment.