From 8e43d06e84f6b7e07189ac31adea4b20e2250f1e Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Fri, 2 Dec 2022 08:21:08 +0300 Subject: [PATCH] Improved console output: added version constants and message box texts. --- SpaceCadetPinball/TPinballTable.cpp | 4 ++-- SpaceCadetPinball/loader.cpp | 2 +- SpaceCadetPinball/pb.cpp | 6 ++++++ SpaceCadetPinball/pb.h | 1 + SpaceCadetPinball/winmain.cpp | 20 +++++++++++++------- SpaceCadetPinball/winmain.h | 1 + 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/SpaceCadetPinball/TPinballTable.cpp b/SpaceCadetPinball/TPinballTable.cpp index 5638ccc..8e9cd17 100644 --- a/SpaceCadetPinball/TPinballTable.cpp +++ b/SpaceCadetPinball/TPinballTable.cpp @@ -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; } @@ -242,7 +242,7 @@ TPinballComponent* TPinballTable::find_component(int 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; } diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index e9dd0b3..283e983 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -62,7 +62,7 @@ int loader::error(int errorCode, int captionCode) if (!errorText) errorText = loader_errors[index].Message; - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, errorCaption, errorText, nullptr); + pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, errorCaption, errorText); return -1; } diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index da6c1a7..aea13ba 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -678,3 +678,9 @@ std::string pb::make_path_name(const std::string& 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); +} diff --git a/SpaceCadetPinball/pb.h b/SpaceCadetPinball/pb.h index f9768e6..9f8e185 100644 --- a/SpaceCadetPinball/pb.h +++ b/SpaceCadetPinball/pb.h @@ -78,6 +78,7 @@ public: static LPCSTR get_rc_string(Msg uID); static int get_rc_int(Msg uID, int* dst); static std::string make_path_name(const std::string& fileName); + static void ShowMessageBox(Uint32 flags, LPCSTR title, LPCSTR message); private: static bool demo_mode; diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 74be159..f774033 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -11,6 +11,8 @@ #include "translations.h" #include "font_selection.h" +constexpr const char* winmain::Version; + SDL_Window* winmain::MainWindow = nullptr; SDL_Renderer* winmain::Renderer = nullptr; ImGuiIO* winmain::ImIO = nullptr; @@ -49,12 +51,17 @@ int winmain::WinMain(LPCSTR lpCmdLine) { 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_SetMainReady(); if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | 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; } @@ -71,7 +78,7 @@ int winmain::WinMain(LPCSTR lpCmdLine) MainWindow = 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; } @@ -89,7 +96,7 @@ int winmain::WinMain(LPCSTR lpCmdLine) } 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; } SDL_RendererInfo rendererInfo{}; @@ -181,8 +188,7 @@ int winmain::WinMain(LPCSTR lpCmdLine) message = message + (path[0] ? path : "working directory") + "\n"; } } - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data", - message.c_str(), window); + pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data", message.c_str()); return 1; } @@ -1036,7 +1042,7 @@ void winmain::memalloc_failure() Sound::Close(); const char* caption = pb::get_rc_string(Msg::STRING270); 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); } @@ -1056,7 +1062,7 @@ void winmain::a_dialog() ImGui::Separator(); 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 SDL_VERSION_ATLEAST(2, 0, 14) diff --git a/SpaceCadetPinball/winmain.h b/SpaceCadetPinball/winmain.h index 7ef7fa9..8b45cbf 100644 --- a/SpaceCadetPinball/winmain.h +++ b/SpaceCadetPinball/winmain.h @@ -65,6 +65,7 @@ class winmain using TimePoint = std::chrono::time_point; public: + static constexpr const char* Version = "2.1.0 DEV"; static bool single_step; static SDL_Window* MainWindow; static SDL_Renderer* Renderer;