From 110cfa1941f8bd3d3ebad23f2708faca38f0e931 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:06:06 -0300 Subject: [PATCH 1/7] Custom Logos on Startup You must add images named LOGO0, LOGO1, LOGO2, LOGOn to the Font folder. it will stop showing logos whenever it fails to find a file. Update scene_logo.cpp --- src/player.cpp | 4 ++++ src/player.h | 3 +++ src/scene_logo.cpp | 50 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 4c3d16948a..1fb1fbacb0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -106,6 +106,8 @@ namespace Player { int message_box_offset_x = (screen_width - MENU_WIDTH) / 2; bool has_custom_resolution = false; + int current_logo; + bool exit_flag; bool reset_flag; bool debug_flag; @@ -202,6 +204,8 @@ void Player::Init(std::vector args) { void Player::Run() { Instrumentation::Init("EasyRPG-Player"); + + current_logo = 0; Scene::Push(std::make_shared()); Graphics::UpdateSceneCallback(); diff --git a/src/player.h b/src/player.h index 457aa14e3b..16675a18ea 100644 --- a/src/player.h +++ b/src/player.h @@ -307,6 +307,9 @@ namespace Player { /** Set the desired rendering frames per second */ void SetTargetFps(int fps); + /** Current Logo - for startup */ + extern int current_logo; + /** Exit flag, if true will exit application on next Player::Update. */ extern bool exit_flag; diff --git a/src/scene_logo.cpp b/src/scene_logo.cpp index 668951fc54..1d5f4956d8 100644 --- a/src/scene_logo.cpp +++ b/src/scene_logo.cpp @@ -40,16 +40,39 @@ Scene_Logo::Scene_Logo() : type = Scene::Logo; } +Filesystem_Stream::InputStream logo_stream; +Filesystem_Stream::InputStream next_logo; + void Scene_Logo::Start() { if (!Player::debug_flag && !Game_Battle::battle_test.enabled) { std::time_t t = std::time(nullptr); std::tm* tm = std::localtime(&t); - if (Rand::ChanceOf(1, 32) || (tm->tm_mday == 1 && tm->tm_mon == 3)) { - logo_img = Bitmap::Create(easyrpg_logo2, sizeof(easyrpg_logo2), false); - } else { - logo_img = Bitmap::Create(easyrpg_logo, sizeof(easyrpg_logo), false); + if (FileFinder::Game()) logo_stream = FileFinder::OpenImage("Font", "LOGO" + std::to_string(Player::current_logo)); + //TODO: Maybe get LOGO1,LOGO2,LOGO3 from rpg_rt too? + + if (!logo_stream && Player::current_logo == 0) { + + if (Rand::ChanceOf(1, 32) || (tm->tm_mday == 1 && tm->tm_mon == 3)) { + logo_img = Bitmap::Create(easyrpg_logo2, sizeof(easyrpg_logo2), false); + } + else { + logo_img = Bitmap::Create(easyrpg_logo, sizeof(easyrpg_logo), false); + } + } + else { + // Read the data from logo_stream and store it in a variable + std::vector logoData = Utils::ReadStream(logo_stream); + + // Access the data as needed + const uint8_t* cached_logo = logoData.data(); + size_t logoSize = logoData.size(); + + // Create a bitmap using the logo data + logo_img = Bitmap::Create(cached_logo, logoSize, false); + } + DrawText(false); @@ -91,7 +114,7 @@ void Scene_Logo::vUpdate() { #endif if (FileFinder::IsValidProject(fs)) { - Player::CreateGameObjects(); + if (Player::current_logo == 0) Player::CreateGameObjects(); // changed to stop loading the same assets multiple times. is_valid = true; } } @@ -105,10 +128,21 @@ void Scene_Logo::vUpdate() { if (Player::debug_flag || Game_Battle::battle_test.enabled || - frame_counter == 60 || + frame_counter == 90 || //had to be longer to cover when Player::CreateGameObjects() doesn't happen Input::IsTriggered(Input::DECISION) || Input::IsTriggered(Input::CANCEL)) { + Player::current_logo++; + next_logo = FileFinder::OpenImage("Font", "LOGO" + std::to_string(Player::current_logo)); + + if (next_logo) { + Scene::Pop(); + Scene::Push(std::make_shared()); + return; + } + + Player::current_logo = 0; + if (is_valid) { if (!Player::startup_language.empty()) { Player::translation.SelectLanguage(Player::startup_language); @@ -137,7 +171,9 @@ void Scene_Logo::DrawBackground(Bitmap& dst) { } void Scene_Logo::DrawText(bool verbose) { - Rect text_rect = {17, 215, 320 - 32, 16}; + if (Player::current_logo != 0) return; + + Rect text_rect = {17, 215, 320 - 32, 0}; //last argument (rect height) is now 0 to remove a black rectangle that appears as text background color. Color text_color = {185, 199, 173, 255}; Color shadow_color = {69, 69, 69, 255}; logo_img->ClearRect(text_rect); From f4bea092c7d41e7f1a769ec71051d305908d4ed7 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:15:36 -0300 Subject: [PATCH 2/7] Custom Logos - Major Refactor - Add custom functions preloadLogos() and DetectGame() to keep it easy to read and maintain. - DetectGame() only happens after loading the Default EasyRPG logo. This happens to avoid a blank screen while loading game assets, as suggested by @Ghabry - Disable the shift key behavior when not at LOGO0. - Fix webplayer issue by adding the prefix ` Scene_Logo::` to the new functions. ------------------------ I guess this solves the issues? Lemme know if you guys need anything else. --- src/player.cpp | 3 + src/player.h | 3 + src/scene_logo.cpp | 160 ++++++++++++++++++++++++++------------------- src/scene_logo.h | 2 + 4 files changed, 101 insertions(+), 67 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 1fb1fbacb0..2e25c852ea 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -106,6 +106,7 @@ namespace Player { int message_box_offset_x = (screen_width - MENU_WIDTH) / 2; bool has_custom_resolution = false; + std::vector logos_container; int current_logo; bool exit_flag; @@ -206,6 +207,8 @@ void Player::Run() { Instrumentation::Init("EasyRPG-Player"); current_logo = 0; + logos_container.clear(); + Scene::Push(std::make_shared()); Graphics::UpdateSceneCallback(); diff --git a/src/player.h b/src/player.h index 16675a18ea..0e6ffbda8f 100644 --- a/src/player.h +++ b/src/player.h @@ -307,6 +307,9 @@ namespace Player { /** Set the desired rendering frames per second */ void SetTargetFps(int fps); + /** Logos Container - A collection of logo files */ + extern std::vector logos_container; + /** Current Logo - for startup */ extern int current_logo; diff --git a/src/scene_logo.cpp b/src/scene_logo.cpp index 1d5f4956d8..59b4227026 100644 --- a/src/scene_logo.cpp +++ b/src/scene_logo.cpp @@ -40,40 +40,26 @@ Scene_Logo::Scene_Logo() : type = Scene::Logo; } -Filesystem_Stream::InputStream logo_stream; -Filesystem_Stream::InputStream next_logo; +static bool detected_game = false; void Scene_Logo::Start() { - if (!Player::debug_flag && !Game_Battle::battle_test.enabled) { - std::time_t t = std::time(nullptr); - std::tm* tm = std::localtime(&t); - - if (FileFinder::Game()) logo_stream = FileFinder::OpenImage("Font", "LOGO" + std::to_string(Player::current_logo)); - //TODO: Maybe get LOGO1,LOGO2,LOGO3 from rpg_rt too? + - if (!logo_stream && Player::current_logo == 0) { - - if (Rand::ChanceOf(1, 32) || (tm->tm_mday == 1 && tm->tm_mon == 3)) { - logo_img = Bitmap::Create(easyrpg_logo2, sizeof(easyrpg_logo2), false); - } - else { - logo_img = Bitmap::Create(easyrpg_logo, sizeof(easyrpg_logo), false); - } + if (!Player::debug_flag && !Game_Battle::battle_test.enabled) { + // Preload logos if the container is empty + if (Player::logos_container.empty()) { + Player::logos_container = Scene_Logo::preloadLogos(); + } + // Access the logo based on Player::current_logo + if (Player::current_logo < Player::logos_container.size()) { + logo_img = Player::logos_container[Player::current_logo]; } else { - // Read the data from logo_stream and store it in a variable - std::vector logoData = Utils::ReadStream(logo_stream); - - // Access the data as needed - const uint8_t* cached_logo = logoData.data(); - size_t logoSize = logoData.size(); - - // Create a bitmap using the logo data - logo_img = Bitmap::Create(cached_logo, logoSize, false); + // Handle the case when Player::current_logo exceeds the number of logos + // You may want to add error handling here. } - DrawText(false); logo = std::make_unique(); @@ -84,64 +70,29 @@ void Scene_Logo::Start() { } void Scene_Logo::vUpdate() { - static bool is_valid = false; - - if (frame_counter == 0) { - auto fs = FileFinder::Game(); - - if (!fs) { - fs = FileFinder::Root().Create(Main_Data::GetDefaultProjectPath()); - if (!fs) { - Output::Error("{} is not a valid path", Main_Data::GetDefaultProjectPath()); - } - FileFinder::SetGameFilesystem(fs); - } - -#ifdef EMSCRIPTEN - static bool once = true; - if (once) { - FileRequestAsync* index = AsyncHandler::RequestFile("index.json"); - index->SetImportantFile(true); - request_id = index->Bind(&Scene_Logo::OnIndexReady, this); - once = false; - index->Start(); - return; - } - - if (!async_ready) { - return; - } -#endif - - if (FileFinder::IsValidProject(fs)) { - if (Player::current_logo == 0) Player::CreateGameObjects(); // changed to stop loading the same assets multiple times. - is_valid = true; - } - } - + static bool is_valid = detected_game; ++frame_counter; - if (Input::IsPressed(Input::SHIFT)) { + if (Input::IsPressed(Input::SHIFT) && Player::current_logo == 0) { DrawText(true); --frame_counter; } if (Player::debug_flag || Game_Battle::battle_test.enabled || - frame_counter == 90 || //had to be longer to cover when Player::CreateGameObjects() doesn't happen + frame_counter == (Player::current_logo == 0 ? 60 : 90) || //had to be longer to cover when Player::CreateGameObjects() doesn't happen Input::IsTriggered(Input::DECISION) || Input::IsTriggered(Input::CANCEL)) { Player::current_logo++; - next_logo = FileFinder::OpenImage("Font", "LOGO" + std::to_string(Player::current_logo)); - - if (next_logo) { + if (Player::current_logo < Player::logos_container.size()) { Scene::Pop(); Scene::Push(std::make_shared()); return; } Player::current_logo = 0; + Player::logos_container.clear(); if (is_valid) { if (!Player::startup_language.empty()) { @@ -166,6 +117,80 @@ void Scene_Logo::vUpdate() { } } +void Scene_Logo::DetectGame() { + + if (detected_game) { + return; + } + + auto fs = FileFinder::Game(); + if (!fs) { + fs = FileFinder::Root().Create(Main_Data::GetDefaultProjectPath()); + if (!fs) { + Output::Error("{} is not a valid path", Main_Data::GetDefaultProjectPath()); + } + FileFinder::SetGameFilesystem(fs); + } + +#ifdef EMSCRIPTEN + static bool once = true; + if (once) { + FileRequestAsync* index = AsyncHandler::RequestFile("index.json"); + index->SetImportantFile(true); + request_id = index->Bind(&Scene_Logo::OnIndexReady, this); + once = false; + index->Start(); + return; + } + if (!async_ready) { + return; + } +#endif + + if (FileFinder::IsValidProject(fs)) { + Player::CreateGameObjects(); + detected_game = true; + } +} + +std::vector Scene_Logo::preloadLogos() { + std::vector logos; + std::time_t t = std::time(nullptr); + std::tm* tm = std::localtime(&t); + + for (int logoIndex = 0; ; logoIndex++) { + Filesystem_Stream::InputStream logoStream; + if (logoIndex != 0) logoStream = FileFinder::OpenImage("Font", "LOGO" + std::to_string(logoIndex)); + //TODO: Maybe get LOGO1,LOGO2,LOGO3 from rpg_rt too? + + if (!logoStream) { + if (logoIndex == 0) { + if (Rand::ChanceOf(1, 32) || (tm->tm_mday == 1 && tm->tm_mon == 3)) { + logos.push_back(Bitmap::Create(easyrpg_logo2, sizeof(easyrpg_logo2), false)); + } + else { + logos.push_back(Bitmap::Create(easyrpg_logo, sizeof(easyrpg_logo), false)); + } + Scene_Logo::DetectGame(); + } + else break; // Stop when no more logos can be found + } + else { + // Read the data from logoStream and store it in a variable + std::vector logoData = Utils::ReadStream(logoStream); + + // Access the data as needed + const uint8_t* cachedLogo = logoData.data(); + size_t logoSize = logoData.size(); + + // Create a bitmap using the logo data and store it + logos.push_back(Bitmap::Create(cachedLogo, logoSize, false)); + } + } + + return logos; +} + void Scene_Logo::DrawBackground(Bitmap& dst) { dst.Clear(); } @@ -173,7 +198,7 @@ void Scene_Logo::DrawBackground(Bitmap& dst) { void Scene_Logo::DrawText(bool verbose) { if (Player::current_logo != 0) return; - Rect text_rect = {17, 215, 320 - 32, 0}; //last argument (rect height) is now 0 to remove a black rectangle that appears as text background color. + Rect text_rect = { 17, 215, 320 - 32, 16 * verbose }; //last argument (rect height) is now 0 to remove a black rectangle that appears as text background color. Color text_color = {185, 199, 173, 255}; Color shadow_color = {69, 69, 69, 255}; logo_img->ClearRect(text_rect); @@ -186,6 +211,7 @@ void Scene_Logo::DrawText(bool verbose) { text_rect.x--; text_rect.y--; } + } void Scene_Logo::OnIndexReady(FileRequestResult*) { diff --git a/src/scene_logo.h b/src/scene_logo.h index 8b01fdde58..98ef6320b0 100644 --- a/src/scene_logo.h +++ b/src/scene_logo.h @@ -40,6 +40,8 @@ class Scene_Logo : public Scene { void Start() override; void vUpdate() override; + void DetectGame(); + std::vector preloadLogos(); void DrawBackground(Bitmap& dst) override; void DrawText(bool verbose); From 462ae53b447a6f31beb7f185301ef737a24a03ef Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:33:40 -0300 Subject: [PATCH 3/7] Custom Logos - Load logos from the "Logo" Folder Better for reading and organization. --- src/scene_logo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scene_logo.cpp b/src/scene_logo.cpp index 59b4227026..3c1ffdfc78 100644 --- a/src/scene_logo.cpp +++ b/src/scene_logo.cpp @@ -160,7 +160,7 @@ std::vector Scene_Logo::preloadLogos() { for (int logoIndex = 0; ; logoIndex++) { Filesystem_Stream::InputStream logoStream; - if (logoIndex != 0) logoStream = FileFinder::OpenImage("Font", "LOGO" + std::to_string(logoIndex)); + if (logoIndex != 0) logoStream = FileFinder::OpenImage("Logo", "LOGO" + std::to_string(logoIndex)); //TODO: Maybe get LOGO1,LOGO2,LOGO3 from rpg_rt too? if (!logoStream) { From 17b8e0fdd5c62b85aa183aa9f436beef9fd6c698 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:45:57 -0300 Subject: [PATCH 4/7] Ensure that a first logo is shown I guess this last change ensures that the logo can be shown. --- src/scene_logo.cpp | 14 +++++++++----- src/scene_logo.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/scene_logo.cpp b/src/scene_logo.cpp index 3c1ffdfc78..6f2e781dad 100644 --- a/src/scene_logo.cpp +++ b/src/scene_logo.cpp @@ -61,11 +61,7 @@ void Scene_Logo::Start() { } DrawText(false); - - logo = std::make_unique(); - logo->SetBitmap(logo_img); - logo->SetX((Player::screen_width - logo->GetWidth()) / 2); - logo->SetY((Player::screen_height - logo->GetHeight()) / 2); + DrawLogo(logo_img); } } @@ -171,6 +167,7 @@ std::vector Scene_Logo::preloadLogos() { else { logos.push_back(Bitmap::Create(easyrpg_logo, sizeof(easyrpg_logo), false)); } + DrawLogo(logos[logoIndex]); Scene_Logo::DetectGame(); } else break; // Stop when no more logos can be found @@ -191,6 +188,13 @@ std::vector Scene_Logo::preloadLogos() { return logos; } +void Scene_Logo::DrawLogo(BitmapRef logo_img) { + logo = std::make_unique(); + logo->SetBitmap(logo_img); + logo->SetX((Player::screen_width - logo->GetWidth()) / 2); + logo->SetY((Player::screen_height - logo->GetHeight()) / 2); +} + void Scene_Logo::DrawBackground(Bitmap& dst) { dst.Clear(); } diff --git a/src/scene_logo.h b/src/scene_logo.h index 98ef6320b0..181b308b3c 100644 --- a/src/scene_logo.h +++ b/src/scene_logo.h @@ -42,6 +42,7 @@ class Scene_Logo : public Scene { void vUpdate() override; void DetectGame(); std::vector preloadLogos(); + void DrawLogo(BitmapRef logo_img); void DrawBackground(Bitmap& dst) override; void DrawText(bool verbose); From 4bb4dae35e518e35e7b90176210c63f21753bb2b Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sat, 21 Oct 2023 16:29:37 +0200 Subject: [PATCH 5/7] Rework the logo code to always only load the current logo (faster) Add support for emscripten --- src/player.cpp | 6 --- src/player.h | 6 --- src/scene_logo.cpp | 129 +++++++++++++++++++-------------------------- src/scene_logo.h | 10 ++-- 4 files changed, 60 insertions(+), 91 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 2e25c852ea..700c859367 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -106,9 +106,6 @@ namespace Player { int message_box_offset_x = (screen_width - MENU_WIDTH) / 2; bool has_custom_resolution = false; - std::vector logos_container; - int current_logo; - bool exit_flag; bool reset_flag; bool debug_flag; @@ -206,9 +203,6 @@ void Player::Init(std::vector args) { void Player::Run() { Instrumentation::Init("EasyRPG-Player"); - current_logo = 0; - logos_container.clear(); - Scene::Push(std::make_shared()); Graphics::UpdateSceneCallback(); diff --git a/src/player.h b/src/player.h index 0e6ffbda8f..457aa14e3b 100644 --- a/src/player.h +++ b/src/player.h @@ -307,12 +307,6 @@ namespace Player { /** Set the desired rendering frames per second */ void SetTargetFps(int fps); - /** Logos Container - A collection of logo files */ - extern std::vector logos_container; - - /** Current Logo - for startup */ - extern int current_logo; - /** Exit flag, if true will exit application on next Player::Update. */ extern bool exit_flag; diff --git a/src/scene_logo.cpp b/src/scene_logo.cpp index 6f2e781dad..56ab9ff39d 100644 --- a/src/scene_logo.cpp +++ b/src/scene_logo.cpp @@ -35,62 +35,54 @@ #include "version.h" #include -Scene_Logo::Scene_Logo() : - frame_counter(0) { +Scene_Logo::Scene_Logo(unsigned current_logo_index) : + frame_counter(0), current_logo_index(current_logo_index) { type = Scene::Logo; -} -static bool detected_game = false; + if (current_logo_index > 0) { + detected_game = true; + } +} void Scene_Logo::Start() { - - if (!Player::debug_flag && !Game_Battle::battle_test.enabled) { - // Preload logos if the container is empty - if (Player::logos_container.empty()) { - Player::logos_container = Scene_Logo::preloadLogos(); - } - - // Access the logo based on Player::current_logo - if (Player::current_logo < Player::logos_container.size()) { - logo_img = Player::logos_container[Player::current_logo]; - } - else { - // Handle the case when Player::current_logo exceeds the number of logos - // You may want to add error handling here. - } - - DrawText(false); + logo_img = LoadLogo(); + DrawTextOnLogo(false); DrawLogo(logo_img); } } void Scene_Logo::vUpdate() { - static bool is_valid = detected_game; + if (current_logo_index == 0 && frame_counter == 0) { + if (!DetectGame()) { + // async delay for emscripten + return; + } + } + ++frame_counter; - if (Input::IsPressed(Input::SHIFT) && Player::current_logo == 0) { - DrawText(true); + if (Input::IsPressed(Input::SHIFT)) { + DrawTextOnLogo(true); --frame_counter; } + // other logos do not invoke the slow CreateGameObjects: display them longer + bool frame_limit_reached = (frame_counter == (current_logo_index == 0 ? 60 : 90)); + if (Player::debug_flag || Game_Battle::battle_test.enabled || - frame_counter == (Player::current_logo == 0 ? 60 : 90) || //had to be longer to cover when Player::CreateGameObjects() doesn't happen + frame_limit_reached || Input::IsTriggered(Input::DECISION) || Input::IsTriggered(Input::CANCEL)) { - Player::current_logo++; - if (Player::current_logo < Player::logos_container.size()) { - Scene::Pop(); - Scene::Push(std::make_shared()); - return; - } - - Player::current_logo = 0; - Player::logos_container.clear(); + if (detected_game) { + // Check for another logo + if (!FileFinder::FindImage("Logo", "LOGO" + std::to_string(current_logo_index + 1)).empty()) { + Scene::Push(std::make_shared(current_logo_index + 1), true); + return; + } - if (is_valid) { if (!Player::startup_language.empty()) { Player::translation.SelectLanguage(Player::startup_language); } @@ -113,12 +105,7 @@ void Scene_Logo::vUpdate() { } } -void Scene_Logo::DetectGame() { - - if (detected_game) { - return; - } - +bool Scene_Logo::DetectGame() { auto fs = FileFinder::Game(); if (!fs) { fs = FileFinder::Root().Create(Main_Data::GetDefaultProjectPath()); @@ -136,10 +123,10 @@ void Scene_Logo::DetectGame() { request_id = index->Bind(&Scene_Logo::OnIndexReady, this); once = false; index->Start(); - return; + return false; } if (!async_ready) { - return; + return false; } #endif @@ -147,45 +134,31 @@ void Scene_Logo::DetectGame() { Player::CreateGameObjects(); detected_game = true; } + + return true; } -std::vector Scene_Logo::preloadLogos() { - std::vector logos; +BitmapRef Scene_Logo::LoadLogo() { + BitmapRef current_logo; std::time_t t = std::time(nullptr); std::tm* tm = std::localtime(&t); - for (int logoIndex = 0; ; logoIndex++) { - Filesystem_Stream::InputStream logoStream; - if (logoIndex != 0) logoStream = FileFinder::OpenImage("Logo", "LOGO" + std::to_string(logoIndex)); - //TODO: Maybe get LOGO1,LOGO2,LOGO3 from rpg_rt too? - - if (!logoStream) { - if (logoIndex == 0) { - if (Rand::ChanceOf(1, 32) || (tm->tm_mday == 1 && tm->tm_mon == 3)) { - logos.push_back(Bitmap::Create(easyrpg_logo2, sizeof(easyrpg_logo2), false)); - } - else { - logos.push_back(Bitmap::Create(easyrpg_logo, sizeof(easyrpg_logo), false)); - } - DrawLogo(logos[logoIndex]); - Scene_Logo::DetectGame(); - } - else break; // Stop when no more logos can be found + if (current_logo_index == 0) { + // Load the built-in logo + if (Rand::ChanceOf(1, 32) || (tm->tm_mday == 1 && tm->tm_mon == 3)) { + current_logo = Bitmap::Create(easyrpg_logo2, sizeof(easyrpg_logo2), false); } else { - // Read the data from logoStream and store it in a variable - std::vector logoData = Utils::ReadStream(logoStream); - - // Access the data as needed - const uint8_t* cachedLogo = logoData.data(); - size_t logoSize = logoData.size(); - - // Create a bitmap using the logo data and store it - logos.push_back(Bitmap::Create(cachedLogo, logoSize, false)); + current_logo = Bitmap::Create(easyrpg_logo, sizeof(easyrpg_logo), false); } + } else { + // Load external logos + // FIXME: Also get the LOGO1,LOGO2,LOGO3 from RPG_RT + auto logo_stream = FileFinder::OpenImage("Logo", "LOGO" + std::to_string(current_logo_index)); + current_logo = Bitmap::Create(std::move(logo_stream), false); } - return logos; + return current_logo; } void Scene_Logo::DrawLogo(BitmapRef logo_img) { @@ -199,8 +172,11 @@ void Scene_Logo::DrawBackground(Bitmap& dst) { dst.Clear(); } -void Scene_Logo::DrawText(bool verbose) { - if (Player::current_logo != 0) return; +void Scene_Logo::DrawTextOnLogo(bool verbose) { + if (current_logo_index > 0) { + // only render version info on EasyRPG startup logo + return; + } Rect text_rect = { 17, 215, 320 - 32, 16 * verbose }; //last argument (rect height) is now 0 to remove a black rectangle that appears as text background color. Color text_color = {185, 199, 173, 255}; @@ -237,7 +213,10 @@ void Scene_Logo::OnIndexReady(FileRequestResult*) { "Font/Font", // Custom Gothic Font "Font/Font2", // Custom Mincho Font "easyrpg.soundfont", // Custom SF2 soundfont - "autorun.script" // Key Patch Startup script + "autorun.script", // Key Patch Startup script, + "Logo/Logo1", // up to 3 custom startup logos + "Logo/Logo2", + "Logo/Logo3" ); for (auto file: startup_files) { diff --git a/src/scene_logo.h b/src/scene_logo.h index 181b308b3c..a0bc09349d 100644 --- a/src/scene_logo.h +++ b/src/scene_logo.h @@ -36,20 +36,22 @@ class Scene_Logo : public Scene { /** * Constructor. */ - Scene_Logo(); + Scene_Logo(unsigned current_logo_index = 0); void Start() override; void vUpdate() override; - void DetectGame(); - std::vector preloadLogos(); + bool DetectGame(); + BitmapRef LoadLogo(); void DrawLogo(BitmapRef logo_img); void DrawBackground(Bitmap& dst) override; - void DrawText(bool verbose); + void DrawTextOnLogo(bool verbose); private: std::unique_ptr logo; BitmapRef logo_img; int frame_counter; + unsigned current_logo_index; + bool detected_game = false; void OnIndexReady(FileRequestResult* result); FileRequestBinding request_id; From 0c3b3eacf31bc33c1b597e6bb97256d5abbaa9b8 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sat, 21 Oct 2023 16:30:11 +0200 Subject: [PATCH 6/7] Game Browser: Invoke the logo scene when startup logos are found --- src/scene_gamebrowser.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/scene_gamebrowser.cpp b/src/scene_gamebrowser.cpp index c8bb105c8f..3517710c85 100644 --- a/src/scene_gamebrowser.cpp +++ b/src/scene_gamebrowser.cpp @@ -26,6 +26,7 @@ #include "game_system.h" #include "input.h" #include "player.h" +#include "scene_logo.h" #include "scene_title.h" #include "bitmap.h" #include "audio.h" @@ -213,11 +214,17 @@ void Scene_GameBrowser::BootGame() { FileFinder::SetGameFilesystem(fs); Player::CreateGameObjects(); + game_loading = false; + load_window->SetVisible(false); + + if (!FileFinder::FindImage("Logo", "LOGO1").empty()) { + // Delegate to Scene_Logo when a startup graphic was found + Scene::Push(std::make_shared(1), true); + return; + } + if (!Player::startup_language.empty()) { Player::translation.SelectLanguage(Player::startup_language); } Scene::Push(std::make_shared()); - - game_loading = false; - load_window->SetVisible(false); } From 42ab89ee216d06c309b4a4fb7aca9c31dd4dc761 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sat, 21 Oct 2023 21:03:42 +0200 Subject: [PATCH 7/7] Logo: Allow opening the settings after one logo is shown The engine objects are created by then so this is safe --- src/scene_gamebrowser.cpp | 2 +- src/scene_logo.cpp | 23 ++++++++++++++++------- src/scene_logo.h | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/scene_gamebrowser.cpp b/src/scene_gamebrowser.cpp index 3517710c85..f2fe40963d 100644 --- a/src/scene_gamebrowser.cpp +++ b/src/scene_gamebrowser.cpp @@ -219,7 +219,7 @@ void Scene_GameBrowser::BootGame() { if (!FileFinder::FindImage("Logo", "LOGO1").empty()) { // Delegate to Scene_Logo when a startup graphic was found - Scene::Push(std::make_shared(1), true); + Scene::Push(std::make_shared(1)); return; } diff --git a/src/scene_logo.cpp b/src/scene_logo.cpp index 56ab9ff39d..5ac87d6d82 100644 --- a/src/scene_logo.cpp +++ b/src/scene_logo.cpp @@ -26,6 +26,7 @@ #include "player.h" #include "scene_title.h" #include "scene_gamebrowser.h" +#include "scene_settings.h" #include "output.h" #include "generated/logo.h" #include "generated/logo2.h" @@ -42,10 +43,12 @@ Scene_Logo::Scene_Logo(unsigned current_logo_index) : if (current_logo_index > 0) { detected_game = true; } + + skip_logos = Player::debug_flag || Game_Battle::battle_test.enabled; } void Scene_Logo::Start() { - if (!Player::debug_flag && !Game_Battle::battle_test.enabled) { + if (!skip_logos) { logo_img = LoadLogo(); DrawTextOnLogo(false); DrawLogo(logo_img); @@ -67,20 +70,26 @@ void Scene_Logo::vUpdate() { --frame_counter; } + // Allow calling the settings when the first logo was shown (startup completed) + if (current_logo_index > 0 && Input::IsTriggered(Input::SETTINGS_MENU)) { + Scene::Push(std::make_shared()); + } + // other logos do not invoke the slow CreateGameObjects: display them longer bool frame_limit_reached = (frame_counter == (current_logo_index == 0 ? 60 : 90)); - if (Player::debug_flag || - Game_Battle::battle_test.enabled || + if (skip_logos || frame_limit_reached || Input::IsTriggered(Input::DECISION) || Input::IsTriggered(Input::CANCEL)) { if (detected_game) { - // Check for another logo - if (!FileFinder::FindImage("Logo", "LOGO" + std::to_string(current_logo_index + 1)).empty()) { - Scene::Push(std::make_shared(current_logo_index + 1), true); - return; + if (!skip_logos) { + // Check for another logo + if (!FileFinder::FindImage("Logo", "LOGO" + std::to_string(current_logo_index + 1)).empty()) { + Scene::Push(std::make_shared(current_logo_index + 1), true); + return; + } } if (!Player::startup_language.empty()) { diff --git a/src/scene_logo.h b/src/scene_logo.h index a0bc09349d..21c37f8a36 100644 --- a/src/scene_logo.h +++ b/src/scene_logo.h @@ -51,6 +51,7 @@ class Scene_Logo : public Scene { BitmapRef logo_img; int frame_counter; unsigned current_logo_index; + bool skip_logos = false; bool detected_game = false; void OnIndexReady(FileRequestResult* result);