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

Custom Logos at Startup #3096

Merged
merged 7 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void Player::Init(std::vector<std::string> args) {

void Player::Run() {
Instrumentation::Init("EasyRPG-Player");

Scene::Push(std::make_shared<Scene_Logo>());
Graphics::UpdateSceneCallback();

Expand Down
13 changes: 10 additions & 3 deletions src/scene_gamebrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<Scene_Logo>(1), true);
return;
}

if (!Player::startup_language.empty()) {
Player::translation.SelectLanguage(Player::startup_language);
}
Scene::Push(std::make_shared<Scene_Title>());

game_loading = false;
load_window->SetVisible(false);
}
153 changes: 99 additions & 54 deletions src/scene_logo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,81 +35,54 @@
#include "version.h"
#include <ctime>

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;

if (current_logo_index > 0) {
detected_game = true;
}
}

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);
}

DrawText(false);

logo = std::make_unique<Sprite>();
logo->SetBitmap(logo_img);
logo->SetX((Player::screen_width - logo->GetWidth()) / 2);
logo->SetY((Player::screen_height - logo->GetHeight()) / 2);
logo_img = LoadLogo();
DrawTextOnLogo(false);
DrawLogo(logo_img);
}
}

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) {
if (current_logo_index == 0 && frame_counter == 0) {
if (!DetectGame()) {
// async delay for emscripten
return;
}
#endif

if (FileFinder::IsValidProject(fs)) {
Player::CreateGameObjects();
is_valid = true;
}
}

++frame_counter;

if (Input::IsPressed(Input::SHIFT)) {
DrawText(true);
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 == 60 ||
frame_limit_reached ||
Input::IsTriggered(Input::DECISION) ||
Input::IsTriggered(Input::CANCEL)) {

if (is_valid) {
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<Scene_Logo>(current_logo_index + 1), true);
return;
}

if (!Player::startup_language.empty()) {
Player::translation.SelectLanguage(Player::startup_language);
}
Expand All @@ -132,12 +105,80 @@ void Scene_Logo::vUpdate() {
}
}

bool Scene_Logo::DetectGame() {
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 false;
}
if (!async_ready) {
return false;
}
#endif

if (FileFinder::IsValidProject(fs)) {
Player::CreateGameObjects();
detected_game = true;
}

return true;
}

BitmapRef Scene_Logo::LoadLogo() {
BitmapRef current_logo;
std::time_t t = std::time(nullptr);
std::tm* tm = std::localtime(&t);

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 {
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 current_logo;
}

void Scene_Logo::DrawLogo(BitmapRef logo_img) {
logo = std::make_unique<Sprite>();
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();
}

void Scene_Logo::DrawText(bool verbose) {
Rect text_rect = {17, 215, 320 - 32, 16};
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};
Color shadow_color = {69, 69, 69, 255};
logo_img->ClearRect(text_rect);
Expand All @@ -150,6 +191,7 @@ void Scene_Logo::DrawText(bool verbose) {
text_rect.x--;
text_rect.y--;
}

}

void Scene_Logo::OnIndexReady(FileRequestResult*) {
Expand All @@ -171,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) {
Expand Down
9 changes: 7 additions & 2 deletions src/scene_logo.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ class Scene_Logo : public Scene {
/**
* Constructor.
*/
Scene_Logo();
Scene_Logo(unsigned current_logo_index = 0);

void Start() override;
void vUpdate() override;
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<Sprite> logo;
BitmapRef logo_img;
int frame_counter;
unsigned current_logo_index;
bool detected_game = false;

void OnIndexReady(FileRequestResult* result);
FileRequestBinding request_id;
Expand Down
Loading