Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Popup on missing game files #1617

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extras/videoDrivers/SDL2/VideoSDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@
boost::nowide::cerr << msg << std::endl;
}

void VideoSDL2::ShowErrorMessage(const std::string& title, const std::string& message)

Check warning on line 226 in extras/videoDrivers/SDL2/VideoSDL2.cpp

View check run for this annotation

Codecov / codecov/patch

extras/videoDrivers/SDL2/VideoSDL2.cpp#L226

Added line #L226 was not covered by tests
{
// window==nullptr is okay too ("no parent")
Flow86 marked this conversation as resolved.
Show resolved Hide resolved
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title.c_str(), message.c_str(), window);

Check warning on line 229 in extras/videoDrivers/SDL2/VideoSDL2.cpp

View check run for this annotation

Codecov / codecov/patch

extras/videoDrivers/SDL2/VideoSDL2.cpp#L229

Added line #L229 was not covered by tests
}

void VideoSDL2::HandlePaste()
{
if(!SDL_HasClipboardText())
Expand Down
2 changes: 2 additions & 0 deletions extras/videoDrivers/SDL2/VideoSDL2.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class VideoSDL2 final : public VideoDriver

bool MessageLoop() override;

void ShowErrorMessage(const std::string& title, const std::string& message) override;

/// Get a timestamp
unsigned long GetTickCount() const override;

Expand Down
6 changes: 6 additions & 0 deletions extras/videoDrivers/WinAPI/WinAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstring>
#include <iostream>
#include <limits>
#include <winuser.h>

/**
* Zeiger auf die aktuelle Instanz.
Expand Down Expand Up @@ -443,6 +444,11 @@ bool VideoWinAPI::MessageLoop()
return true;
}

void VideoWinAPI::ShowErrorMessage(const std::string& title, const std::string& message)
{
MessageBoxA(nullptr, message.c_str(), title.c_str(), MB_OK | MB_ICONEXCLAMATION);
}

/**
* Funktion zum Auslesen des TickCounts.
*
Expand Down
3 changes: 3 additions & 0 deletions extras/videoDrivers/WinAPI/WinAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class VideoWinAPI final : public VideoDriver
/// Die Nachrichtenschleife.
bool MessageLoop() override;

/// Popup Window
void ShowErrorMessage(const std::string& title, const std::string& message) override;

/// Funktion zum Auslesen des TickCounts.
unsigned long GetTickCount() const override;

Expand Down
3 changes: 3 additions & 0 deletions libs/driver/include/driver/VideoInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class BOOST_SYMBOL_VISIBLE IVideoDriver
virtual bool IsInitialized() const = 0;
/// Shall we support OpenGL? (Disabled for tests)
virtual bool IsOpenGL() const = 0;

// Display the problem to the gamer
virtual void ShowErrorMessage(const std::string& title, const std::string& message) = 0;
};

class VideoDriverLoaderInterface;
Expand Down
13 changes: 10 additions & 3 deletions libs/s25main/desktops/dskSplash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
#include "WindowManager.h"
#include "controls/ctrlTimer.h"
#include "dskMainMenu.h"
#include "helpers/format.hpp"
#include "ingameWindows/iwMusicPlayer.h"
#include "mygettext/mygettext.h"
#include "ogl/glArchivItem_Bitmap.h"
#include "gameData/ApplicationLoader.h"
#include "s25util/Log.h"
#include "s25util/error.h"
#include <drivers/VideoDriverWrapper.h>

using namespace std::chrono_literals;

Expand Down Expand Up @@ -76,9 +78,14 @@

} else
{
s25util::error(_("Some files failed to load.\n"
"Please ensure that the Settlers 2 Gold-Edition is installed \n"
"in the same directory as Return to the Roots."));
const auto fmt = boost::format(_("Some essential game files failed to load.\n"

Check warning on line 81 in libs/s25main/desktops/dskSplash.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/desktops/dskSplash.cpp#L81

Added line #L81 was not covered by tests
"Please ensure that the Settlers 2 Gold-Edition is installed in\n"
"%1%"))
% RTTRCONFIG.ExpandPath("<RTTR_GAME>").string();

Check warning on line 84 in libs/s25main/desktops/dskSplash.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/desktops/dskSplash.cpp#L84

Added line #L84 was not covered by tests

s25util::error(fmt.str());
VIDEODRIVER.ShowErrorMessage(_("Missing game files"), fmt.str());

Check warning on line 87 in libs/s25main/desktops/dskSplash.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/desktops/dskSplash.cpp#L86-L87

Added lines #L86 - L87 were not covered by tests

GLOBALVARS.notdone = false;
}
}
6 changes: 6 additions & 0 deletions libs/s25main/drivers/VideoDriverWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@
return true;
}

void VideoDriverWrapper::ShowErrorMessage(const std::string& title, const std::string& message)

Check warning on line 183 in libs/s25main/drivers/VideoDriverWrapper.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/drivers/VideoDriverWrapper.cpp#L183

Added line #L183 was not covered by tests
{
if(videodriver)
videodriver->ShowErrorMessage(title, message);

Check warning on line 186 in libs/s25main/drivers/VideoDriverWrapper.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/drivers/VideoDriverWrapper.cpp#L185-L186

Added lines #L185 - L186 were not covered by tests
}

void VideoDriverWrapper::setTargetFramerate(int target)
{
frameLimiter_->setTargetFramerate(target);
Expand Down
2 changes: 2 additions & 0 deletions libs/s25main/drivers/VideoDriverWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class VideoDriverWrapper : public Singleton<VideoDriverWrapper, SingletonPolicie
// Nachrichtenschleife
bool Run();

void ShowErrorMessage(const std::string& title, const std::string& message);

unsigned GetTickCount();
/// Set framerate target (FPS)
/// negative for unlimited, 0 for hardware VSync
Expand Down
6 changes: 6 additions & 0 deletions tests/mockupDrivers/MockupVideoDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "MockupVideoDriver.h"
#include <boost/nowide/iostream.hpp>
#include <iostream>

MockupVideoDriver::MockupVideoDriver(VideoDriverLoaderInterface* CallBack) : VideoDriver(CallBack), tickCount_(1)
{
Expand Down Expand Up @@ -81,3 +82,8 @@ void* MockupVideoDriver::GetMapPointer() const
{
return nullptr;
}

void MockupVideoDriver::ShowErrorMessage(const std::string& title, const std::string& message)
{
std::cerr << title << ": " << message << std::endl;
}
1 change: 1 addition & 0 deletions tests/mockupDrivers/MockupVideoDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MockupVideoDriver : public VideoDriver
KeyEvent GetModKeyState() const override;
void* GetMapPointer() const override;
bool IsOpenGL() const override { return false; }
void ShowErrorMessage(const std::string& title, const std::string& message) override;
using VideoDriver::FindClosestVideoMode;

KeyEvent modKeyState_;
Expand Down