Improved console output: added version constants and message box texts.

This commit is contained in:
Muzychenko Andrey 2022-12-02 08:21:08 +03:00
parent 31530bef18
commit 8e43d06e84
6 changed files with 24 additions and 10 deletions

View File

@ -228,7 +228,7 @@ TPinballComponent* TPinballTable::find_component(LPCSTR componentName)
} }
} }
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find:", componentName, nullptr); pb::ShowMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find:", componentName);
return nullptr; return nullptr;
} }
@ -242,7 +242,7 @@ TPinballComponent* TPinballTable::find_component(int groupIndex)
} }
snprintf(Buffer, sizeof Buffer, "%d", groupIndex); snprintf(Buffer, sizeof Buffer, "%d", groupIndex);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find (lh):", Buffer, nullptr); pb::ShowMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find (lh):", Buffer);
return nullptr; return nullptr;
} }

View File

@ -62,7 +62,7 @@ int loader::error(int errorCode, int captionCode)
if (!errorText) if (!errorText)
errorText = loader_errors[index].Message; errorText = loader_errors[index].Message;
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, errorCaption, errorText, nullptr); pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, errorCaption, errorText);
return -1; return -1;
} }

View File

@ -678,3 +678,9 @@ std::string pb::make_path_name(const std::string& fileName)
{ {
return BasePath + fileName; return BasePath + fileName;
} }
void pb::ShowMessageBox(Uint32 flags, LPCSTR title, LPCSTR message)
{
fprintf(flags == SDL_MESSAGEBOX_ERROR ? stderr : stdout, "BL error: %s\n%s\n", title, message);
SDL_ShowSimpleMessageBox(flags, title, message, winmain::MainWindow);
}

View File

@ -78,6 +78,7 @@ public:
static LPCSTR get_rc_string(Msg uID); static LPCSTR get_rc_string(Msg uID);
static int get_rc_int(Msg uID, int* dst); static int get_rc_int(Msg uID, int* dst);
static std::string make_path_name(const std::string& fileName); static std::string make_path_name(const std::string& fileName);
static void ShowMessageBox(Uint32 flags, LPCSTR title, LPCSTR message);
private: private:
static bool demo_mode; static bool demo_mode;

View File

@ -11,6 +11,8 @@
#include "translations.h" #include "translations.h"
#include "font_selection.h" #include "font_selection.h"
constexpr const char* winmain::Version;
SDL_Window* winmain::MainWindow = nullptr; SDL_Window* winmain::MainWindow = nullptr;
SDL_Renderer* winmain::Renderer = nullptr; SDL_Renderer* winmain::Renderer = nullptr;
ImGuiIO* winmain::ImIO = nullptr; ImGuiIO* winmain::ImIO = nullptr;
@ -49,12 +51,17 @@ int winmain::WinMain(LPCSTR lpCmdLine)
{ {
std::set_new_handler(memalloc_failure); std::set_new_handler(memalloc_failure);
printf("Game version: %s\n", Version);
printf("Compiled with: SDL %d.%d.%d;", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
printf(" SDL_mixer %d.%d.%d;", SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL);
printf(" ImGui %s\n", IMGUI_VERSION);
// SDL init // SDL init
SDL_SetMainReady(); SDL_SetMainReady();
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO |
SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0)
{ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not initialize SDL2", SDL_GetError(), nullptr); pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, "Could not initialize SDL2", SDL_GetError());
return 1; return 1;
} }
@ -71,7 +78,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
MainWindow = window; MainWindow = window;
if (!window) if (!window)
{ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not create window", SDL_GetError(), nullptr); pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, "Could not create window", SDL_GetError());
return 1; return 1;
} }
@ -89,7 +96,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
} }
if (!renderer) if (!renderer)
{ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not create renderer", SDL_GetError(), window); pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, "Could not create renderer", SDL_GetError());
return 1; return 1;
} }
SDL_RendererInfo rendererInfo{}; SDL_RendererInfo rendererInfo{};
@ -181,8 +188,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
message = message + (path[0] ? path : "working directory") + "\n"; message = message + (path[0] ? path : "working directory") + "\n";
} }
} }
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data", pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data", message.c_str());
message.c_str(), window);
return 1; return 1;
} }
@ -1036,7 +1042,7 @@ void winmain::memalloc_failure()
Sound::Close(); Sound::Close();
const char* caption = pb::get_rc_string(Msg::STRING270); const char* caption = pb::get_rc_string(Msg::STRING270);
const char* text = pb::get_rc_string(Msg::STRING279); const char* text = pb::get_rc_string(Msg::STRING279);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, caption, text, MainWindow); pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, caption, text);
std::exit(1); std::exit(1);
} }
@ -1056,7 +1062,7 @@ void winmain::a_dialog()
ImGui::Separator(); ImGui::Separator();
ImGui::TextUnformatted("Decompiled -> Ported to SDL"); ImGui::TextUnformatted("Decompiled -> Ported to SDL");
ImGui::TextUnformatted("Version 2.0.1"); ImGui::Text("Version %s", Version);
if (ImGui::SmallButton("Project home: https://github.com/k4zmu2a/SpaceCadetPinball")) if (ImGui::SmallButton("Project home: https://github.com/k4zmu2a/SpaceCadetPinball"))
{ {
#if SDL_VERSION_ATLEAST(2, 0, 14) #if SDL_VERSION_ATLEAST(2, 0, 14)

View File

@ -65,6 +65,7 @@ class winmain
using TimePoint = std::chrono::time_point<Clock>; using TimePoint = std::chrono::time_point<Clock>;
public: public:
static constexpr const char* Version = "2.1.0 DEV";
static bool single_step; static bool single_step;
static SDL_Window* MainWindow; static SDL_Window* MainWindow;
static SDL_Renderer* Renderer; static SDL_Renderer* Renderer;