Skip to content

Commit

Permalink
Custom Logos on Startup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jetrotal committed Sep 25, 2023
1 parent a5f6f69 commit 110cfa1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -202,6 +204,8 @@ void Player::Init(std::vector<std::string> args) {

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

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

Expand Down
3 changes: 3 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
50 changes: 43 additions & 7 deletions src/scene_logo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> 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);

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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<Scene_Logo>());
return;
}

Player::current_logo = 0;

if (is_valid) {
if (!Player::startup_language.empty()) {
Player::translation.SelectLanguage(Player::startup_language);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 110cfa1

Please sign in to comment.