From 2a8f66ad9f1fdd3039b369ca4f99dbaa20b79b3a Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Mon, 18 Mar 2019 20:07:23 -0400 Subject: [PATCH 01/10] Fix skill / item scene transition out Fixes bugs: * Switch skill should fast transition out to map * Escape item should slow transition out to map --- src/scene_item.cpp | 15 +++++++++++++++ src/scene_item.h | 1 + src/scene_skill.cpp | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/scene_item.cpp b/src/scene_item.cpp index 736763df7a..ff7ca39954 100644 --- a/src/scene_item.cpp +++ b/src/scene_item.cpp @@ -29,6 +29,7 @@ #include "scene_map.h" #include "scene_teleport.h" #include "output.h" +#include "transition.h" Scene_Item::Scene_Item(int item_index) : item_index(item_index) { @@ -106,3 +107,17 @@ void Scene_Item::Update() { } } } + +void Scene_Item::TransitionOut() { + const auto* item = item_window->GetItem(); + const RPG::Skill* skill = nullptr; + if (item && item->type == RPG::Item::Type_special && item->skill_id > 0) { + skill = ReaderUtil::GetElement(Data::skills, item->skill_id); + } + + if (Scene::instance && Scene::instance->type == Map && skill && skill->type == RPG::Skill::Type_escape) { + Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 32, true); + } else { + Scene::TransitionOut(); + } +} diff --git a/src/scene_item.h b/src/scene_item.h index 55f2090460..1e6f574e4d 100644 --- a/src/scene_item.h +++ b/src/scene_item.h @@ -39,6 +39,7 @@ class Scene_Item : public Scene { void Start() override; void Continue() override; void Update() override; + void TransitionOut() override; private: /** Displays description about the selected item. */ diff --git a/src/scene_skill.cpp b/src/scene_skill.cpp index 3b33bb61b4..902b44d7e8 100644 --- a/src/scene_skill.cpp +++ b/src/scene_skill.cpp @@ -86,7 +86,8 @@ void Scene_Skill::Update() { } void Scene_Skill::TransitionOut() { - if (Scene::instance->type == Map) { + const auto* skill = skill_window->GetSkill(); + if (Scene::instance && Scene::instance->type == Map && skill && skill->type == RPG::Skill::Type_escape) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 32, true); } else { Scene::TransitionOut(); From 5cfc131f5dc5612f3ad4ba655b43860fe96b34a8 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Mon, 18 Mar 2019 18:51:00 -0400 Subject: [PATCH 02/10] Pass the prev/next scene to TransitionIn/Out --- src/scene.cpp | 16 ++++++++++++---- src/scene.h | 9 +++++++-- src/scene_battle.cpp | 8 ++++---- src/scene_battle.h | 4 ++-- src/scene_gameover.cpp | 4 ++-- src/scene_gameover.h | 4 ++-- src/scene_item.cpp | 6 +++--- src/scene_item.h | 2 +- src/scene_map.cpp | 10 +++++----- src/scene_map.h | 4 ++-- src/scene_skill.cpp | 6 +++--- src/scene_skill.h | 2 +- src/scene_teleport.cpp | 6 +++--- src/scene_teleport.h | 2 +- src/scene_title.cpp | 4 ++-- src/scene_title.h | 2 +- 16 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/scene.cpp b/src/scene.cpp index 8a53220da7..691aa2ae96 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -68,6 +68,7 @@ enum PushPopOperation { }; int Scene::push_pop_operation = 0; +Scene::SceneType prev_scene = Scene::Null; Scene::Scene() { type = Scene::Null; @@ -109,7 +110,7 @@ void Scene::MainFunction() { push_pop_operation = 0; - TransitionIn(); + TransitionIn(prev_scene); Resume(); init = true; @@ -127,7 +128,7 @@ void Scene::MainFunction() { Graphics::Update(); Suspend(); - TransitionOut(); + TransitionOut(instance ? instance->type : Null); // TransitionOut stored a screenshot of the last scene Graphics::UpdateSceneCallback(); @@ -148,11 +149,11 @@ void Scene::Resume() { void Scene::Suspend() { } -void Scene::TransitionIn() { +void Scene::TransitionIn(SceneType) { Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 6); } -void Scene::TransitionOut() { +void Scene::TransitionOut(SceneType) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 6, true); } @@ -186,7 +187,12 @@ bool Scene::IsAsyncPending() { void Scene::Update() { } +void Scene::UpdatePrevScene() { + prev_scene = instance ? instance->type : Null; +} + void Scene::Push(std::shared_ptr const& new_scene, bool pop_stack_top) { + UpdatePrevScene(); if (pop_stack_top) { old_instances.push_back(instances.back()); instances.pop_back(); @@ -201,6 +207,7 @@ void Scene::Push(std::shared_ptr const& new_scene, bool pop_stack_top) { } void Scene::Pop() { + UpdatePrevScene(); old_instances.push_back(instances.back()); instances.pop_back(); @@ -216,6 +223,7 @@ void Scene::Pop() { } void Scene::PopUntil(SceneType type) { + UpdatePrevScene(); int count = 0; for (int i = (int)instances.size() - 1 ; i >= 0; --i) { diff --git a/src/scene.h b/src/scene.h index 3a9d81beae..98ba2df8a1 100644 --- a/src/scene.h +++ b/src/scene.h @@ -107,14 +107,18 @@ class Scene { /** * Does the transition upon starting or resuming * the scene + * + * @param prev_scene the scene we transitioned from */ - virtual void TransitionIn(); + virtual void TransitionIn(SceneType prev_scene); /** * Does the transition upon ending or suspending * the scene + * + * @param next_scene the scene we will transition to */ - virtual void TransitionOut(); + virtual void TransitionOut(SceneType next_scene); /** * Called when a transition or async load is finished. @@ -231,6 +235,7 @@ class Scene { Graphics::State state; static void DebugValidate(const char* caller); + static void UpdatePrevScene(); Scene::SceneType request_scene = Null; }; diff --git a/src/scene_battle.cpp b/src/scene_battle.cpp index 3235024750..5ada299d7c 100644 --- a/src/scene_battle.cpp +++ b/src/scene_battle.cpp @@ -96,18 +96,18 @@ void Scene_Battle::Start() { SetState(State_Start); } -void Scene_Battle::TransitionIn() { +void Scene_Battle::TransitionIn(SceneType prev_scene) { if (Game_Temp::transition_menu) { Game_Temp::transition_menu = false; - Scene::TransitionIn(); + Scene::TransitionIn(prev_scene); } else { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_BeginBattleShow), this, 32); } } -void Scene_Battle::TransitionOut() { +void Scene_Battle::TransitionOut(SceneType next_scene) { if (Player::exit_flag || Game_Battle::battle_test.enabled || Game_Temp::transition_menu || Scene::instance->type == Scene::Title) { - Scene::TransitionOut(); + Scene::TransitionOut(next_scene); } else { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_EndBattleErase), this, 32, true); diff --git a/src/scene_battle.h b/src/scene_battle.h index b5696a7ee9..fdfa67f2ad 100644 --- a/src/scene_battle.h +++ b/src/scene_battle.h @@ -63,8 +63,8 @@ class Scene_Battle : public Scene { void Start() override; void Update() override; - void TransitionIn() override; - void TransitionOut() override; + void TransitionIn(SceneType prev_scene) override; + void TransitionOut(SceneType next_scene) override; void DrawBackground() override; enum State { diff --git a/src/scene_gameover.cpp b/src/scene_gameover.cpp index be1fa00f50..7a45c4ba8b 100644 --- a/src/scene_gameover.cpp +++ b/src/scene_gameover.cpp @@ -51,10 +51,10 @@ void Scene_Gameover::OnBackgroundReady(FileRequestResult* result) { background->SetBitmap(Cache::Gameover(result->file)); } -void Scene_Gameover::TransitionIn() { +void Scene_Gameover::TransitionIn(SceneType prev_scene) { Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 80); } -void Scene_Gameover::TransitionOut() { +void Scene_Gameover::TransitionOut(SceneType next_scene) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 80, true); } diff --git a/src/scene_gameover.h b/src/scene_gameover.h index 173b1af83a..edb5382bbb 100644 --- a/src/scene_gameover.h +++ b/src/scene_gameover.h @@ -39,8 +39,8 @@ class Scene_Gameover : public Scene { void Start() override; void Update() override; - void TransitionIn() override; - void TransitionOut() override; + void TransitionIn(SceneType prev_scene) override; + void TransitionOut(SceneType next_scene) override; private: /** Background graphic. */ std::unique_ptr background; diff --git a/src/scene_item.cpp b/src/scene_item.cpp index ff7ca39954..b6e6b93d4b 100644 --- a/src/scene_item.cpp +++ b/src/scene_item.cpp @@ -108,16 +108,16 @@ void Scene_Item::Update() { } } -void Scene_Item::TransitionOut() { +void Scene_Item::TransitionOut(Scene::SceneType next_scene) { const auto* item = item_window->GetItem(); const RPG::Skill* skill = nullptr; if (item && item->type == RPG::Item::Type_special && item->skill_id > 0) { skill = ReaderUtil::GetElement(Data::skills, item->skill_id); } - if (Scene::instance && Scene::instance->type == Map && skill && skill->type == RPG::Skill::Type_escape) { + if (next_scene == Map && skill && skill->type == RPG::Skill::Type_escape) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 32, true); } else { - Scene::TransitionOut(); + Scene::TransitionOut(next_scene); } } diff --git a/src/scene_item.h b/src/scene_item.h index 1e6f574e4d..4df10955e7 100644 --- a/src/scene_item.h +++ b/src/scene_item.h @@ -39,7 +39,7 @@ class Scene_Item : public Scene { void Start() override; void Continue() override; void Update() override; - void TransitionOut() override; + void TransitionOut(Scene::SceneType next_scene) override; private: /** Displays description about the selected item. */ diff --git a/src/scene_map.cpp b/src/scene_map.cpp index 80e47e19b7..65e5f30969 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -104,7 +104,7 @@ void Scene_Map::Resume() { called_battle = false; } -void Scene_Map::TransitionIn() { +void Scene_Map::TransitionIn(SceneType prev_scene) { // Teleport already setup a transition. if (Graphics::IsTransitionPending()) { return; @@ -114,22 +114,22 @@ void Scene_Map::TransitionIn() { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_EndBattleShow), this, 32); } else if (Game_Temp::transition_menu) { Game_Temp::transition_menu = false; - Scene::TransitionIn(); + Scene::TransitionIn(prev_scene); } else { Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 32); } } -void Scene_Map::TransitionOut() { +void Scene_Map::TransitionOut(SceneType next_scene) { if (called_battle) { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_BeginBattleErase), this, 32, true); Graphics::GetTransition().AppendBefore(Color(255, 255, 255, 255), 12, 2); } - else if (Scene::instance && Scene::instance->type == Scene::Gameover) { + else if (next_scene == Scene::Gameover) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 32, true); } else { - Scene::TransitionOut(); + Scene::TransitionOut(next_scene); } } diff --git a/src/scene_map.h b/src/scene_map.h index 616ab05c98..c07a31934f 100644 --- a/src/scene_map.h +++ b/src/scene_map.h @@ -40,8 +40,8 @@ class Scene_Map: public Scene { void Continue() override; void Update() override; void Resume() override; - void TransitionIn() override; - void TransitionOut() override; + void TransitionIn(SceneType prev_scene) override; + void TransitionOut(SceneType next_scene) override; void DrawBackground() override; void CallBattle(); diff --git a/src/scene_skill.cpp b/src/scene_skill.cpp index 902b44d7e8..7f2fc32749 100644 --- a/src/scene_skill.cpp +++ b/src/scene_skill.cpp @@ -85,11 +85,11 @@ void Scene_Skill::Update() { } } -void Scene_Skill::TransitionOut() { +void Scene_Skill::TransitionOut(SceneType next_scene) { const auto* skill = skill_window->GetSkill(); - if (Scene::instance && Scene::instance->type == Map && skill && skill->type == RPG::Skill::Type_escape) { + if (next_scene == Map && skill && skill->type == RPG::Skill::Type_escape) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 32, true); } else { - Scene::TransitionOut(); + Scene::TransitionOut(next_scene); } } diff --git a/src/scene_skill.h b/src/scene_skill.h index 1b21225f0c..9c26689856 100644 --- a/src/scene_skill.h +++ b/src/scene_skill.h @@ -37,7 +37,7 @@ class Scene_Skill : public Scene { void Start() override; void Update() override; - void TransitionOut() override; + void TransitionOut(SceneType next_scene) override; private: /** Actor in the party whose skills are displayed. */ diff --git a/src/scene_teleport.cpp b/src/scene_teleport.cpp index ce81280708..09ced3b838 100644 --- a/src/scene_teleport.cpp +++ b/src/scene_teleport.cpp @@ -64,10 +64,10 @@ void Scene_Teleport::Update() { } } -void Scene_Teleport::TransitionOut() { - if (Scene::instance->type == Map) { +void Scene_Teleport::TransitionOut(SceneType next_scene) { + if (next_scene == Map) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 32, true); } else { - Scene::TransitionOut(); + Scene::TransitionOut(next_scene); } } diff --git a/src/scene_teleport.h b/src/scene_teleport.h index 174a88e31e..a6ac492ad0 100644 --- a/src/scene_teleport.h +++ b/src/scene_teleport.h @@ -37,7 +37,7 @@ class Scene_Teleport : public Scene { void Start() override; void Update() override; - void TransitionOut() override; + void TransitionOut(SceneType next_scene) override; private: std::unique_ptr teleport_window; diff --git a/src/scene_title.cpp b/src/scene_title.cpp index bf43f1dda3..659b51cf37 100644 --- a/src/scene_title.cpp +++ b/src/scene_title.cpp @@ -65,12 +65,12 @@ void Scene_Title::Continue() { } } -void Scene_Title::TransitionIn() { +void Scene_Title::TransitionIn(SceneType prev_scene) { if (Game_Battle::battle_test.enabled || !Data::system.show_title || Player::new_game_flag) return; if (command_window->GetVisible()) { - Scene::TransitionIn(); + Scene::TransitionIn(prev_scene); } else if (!Player::hide_title_flag) { Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 32); diff --git a/src/scene_title.h b/src/scene_title.h index e638169055..840ff38eac 100644 --- a/src/scene_title.h +++ b/src/scene_title.h @@ -36,7 +36,7 @@ class Scene_Title : public Scene { void Start() override; void Continue() override; - void TransitionIn() override; + void TransitionIn(SceneType prev_scene) override; void Resume() override; void Update() override; From b573e086d2b1a75d4f22e729cb31472ca7bd0e7b Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Mon, 18 Mar 2019 19:02:43 -0400 Subject: [PATCH 03/10] Pass prev_scene to Scene::Continue() --- src/scene.cpp | 4 ++-- src/scene.h | 4 +++- src/scene_gamebrowser.cpp | 2 +- src/scene_gamebrowser.h | 2 +- src/scene_item.cpp | 2 +- src/scene_item.h | 2 +- src/scene_map.cpp | 2 +- src/scene_map.h | 2 +- src/scene_menu.cpp | 2 +- src/scene_menu.h | 2 +- src/scene_title.cpp | 2 +- src/scene_title.h | 2 +- 12 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/scene.cpp b/src/scene.cpp index 691aa2ae96..cc8f6c6671 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -102,7 +102,7 @@ void Scene::MainFunction() { Start(); initialized = true; } else { - Continue(); + Continue(prev_scene); } break; default:; @@ -140,7 +140,7 @@ void Scene::MainFunction() { void Scene::Start() { } -void Scene::Continue() { +void Scene::Continue(SceneType prev_scene) { } void Scene::Resume() { diff --git a/src/scene.h b/src/scene.h index 98ba2df8a1..6d8a02531f 100644 --- a/src/scene.h +++ b/src/scene.h @@ -85,8 +85,10 @@ class Scene { * Continue processing. * This function is executed when returning from a * nested scene (instead of Start). + * + * @param prev_scene The previous scene */ - virtual void Continue(); + virtual void Continue(SceneType prev_scene); /** * Resume processing. diff --git a/src/scene_gamebrowser.cpp b/src/scene_gamebrowser.cpp index a581bb7939..f40549cc68 100644 --- a/src/scene_gamebrowser.cpp +++ b/src/scene_gamebrowser.cpp @@ -45,7 +45,7 @@ void Scene_GameBrowser::Start() { Player::FrameReset(); } -void Scene_GameBrowser::Continue() { +void Scene_GameBrowser::Continue(SceneType prev_scene) { #ifdef _WIN32 SetCurrentDirectory(L".."); #endif diff --git a/src/scene_gamebrowser.h b/src/scene_gamebrowser.h index 9c1b1b22d5..19937a1c1b 100644 --- a/src/scene_gamebrowser.h +++ b/src/scene_gamebrowser.h @@ -36,7 +36,7 @@ class Scene_GameBrowser : public Scene { Scene_GameBrowser(); void Start() override; - void Continue() override; + void Continue(SceneType prev_scene) override; void Update() override; /** diff --git a/src/scene_item.cpp b/src/scene_item.cpp index b6e6b93d4b..75bd6bd7e3 100644 --- a/src/scene_item.cpp +++ b/src/scene_item.cpp @@ -45,7 +45,7 @@ void Scene_Item::Start() { item_window->SetIndex(item_index); } -void Scene_Item::Continue() { +void Scene_Item::Continue(SceneType prev_scene) { item_window->Refresh(); } diff --git a/src/scene_item.h b/src/scene_item.h index 4df10955e7..d86fb4dd7f 100644 --- a/src/scene_item.h +++ b/src/scene_item.h @@ -37,7 +37,7 @@ class Scene_Item : public Scene { Scene_Item(int item_index = 0); void Start() override; - void Continue() override; + void Continue(SceneType prev_scene) override; void Update() override; void TransitionOut(Scene::SceneType next_scene) override; diff --git a/src/scene_map.cpp b/src/scene_map.cpp index 65e5f30969..ea7c4a4461 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -80,7 +80,7 @@ void Scene_Map::Start() { async_continuation = [&]() { UpdateSceneCalling(); }; } -void Scene_Map::Continue() { +void Scene_Map::Continue(SceneType prev_scene) { teleport_from_other_scene = true; if (called_battle) { // Came from battle diff --git a/src/scene_map.h b/src/scene_map.h index c07a31934f..dbf0621b5d 100644 --- a/src/scene_map.h +++ b/src/scene_map.h @@ -37,7 +37,7 @@ class Scene_Map: public Scene { ~Scene_Map(); void Start() override; - void Continue() override; + void Continue(SceneType prev_scene) override; void Update() override; void Resume() override; void TransitionIn(SceneType prev_scene) override; diff --git a/src/scene_menu.cpp b/src/scene_menu.cpp index c84e7c090f..f248ecb42c 100644 --- a/src/scene_menu.cpp +++ b/src/scene_menu.cpp @@ -52,7 +52,7 @@ void Scene_Menu::Start() { menustatus_window->SetActive(false); } -void Scene_Menu::Continue() { +void Scene_Menu::Continue(SceneType prev_scene) { menustatus_window->Refresh(); } diff --git a/src/scene_menu.h b/src/scene_menu.h index 4bfb1c60ac..8c151add25 100644 --- a/src/scene_menu.h +++ b/src/scene_menu.h @@ -37,7 +37,7 @@ class Scene_Menu : public Scene { Scene_Menu(int menu_index = 0); void Start() override; - void Continue() override; + void Continue(SceneType prev_scene) override; void Update() override; /** diff --git a/src/scene_title.cpp b/src/scene_title.cpp index 659b51cf37..3acf764cb2 100644 --- a/src/scene_title.cpp +++ b/src/scene_title.cpp @@ -52,7 +52,7 @@ void Scene_Title::Start() { CreateCommandWindow(); } -void Scene_Title::Continue() { +void Scene_Title::Continue(SceneType prev_scene) { if (restart_title_cache) { // Clear the cache when the game returns to the title screen // e.g. by pressing F12, except the Title Load menu diff --git a/src/scene_title.h b/src/scene_title.h index 840ff38eac..4be53a144f 100644 --- a/src/scene_title.h +++ b/src/scene_title.h @@ -35,7 +35,7 @@ class Scene_Title : public Scene { Scene_Title(); void Start() override; - void Continue() override; + void Continue(SceneType prev_scene) override; void TransitionIn(SceneType prev_scene) override; void Resume() override; void Update() override; From 1112a8d6f73961a9250277ca3c380789c95f5d5a Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Mon, 18 Mar 2019 19:07:52 -0400 Subject: [PATCH 04/10] Scene::Resume pass prev_scene --- src/scene.cpp | 4 ++-- src/scene.h | 4 +++- src/scene_map.cpp | 2 +- src/scene_map.h | 2 +- src/scene_title.cpp | 2 +- src/scene_title.h | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/scene.cpp b/src/scene.cpp index cc8f6c6671..a611eac35e 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -111,7 +111,7 @@ void Scene::MainFunction() { push_pop_operation = 0; TransitionIn(prev_scene); - Resume(); + Resume(prev_scene); init = true; return; @@ -143,7 +143,7 @@ void Scene::Start() { void Scene::Continue(SceneType prev_scene) { } -void Scene::Resume() { +void Scene::Resume(SceneType prev_scene) { } void Scene::Suspend() { diff --git a/src/scene.h b/src/scene.h index 6d8a02531f..dba235c149 100644 --- a/src/scene.h +++ b/src/scene.h @@ -95,8 +95,10 @@ class Scene { * This function is executed after the fade in, * either when starting the scene or when returning * from a nested scene + * + * @param prev_scene The previous scene */ - virtual void Resume(); + virtual void Resume(SceneType prev_scene); /** * Suspend processing. diff --git a/src/scene_map.cpp b/src/scene_map.cpp index ea7c4a4461..e66ad7e14b 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -99,7 +99,7 @@ void Scene_Map::Continue(SceneType prev_scene) { spriteset->Update(); } -void Scene_Map::Resume() { +void Scene_Map::Resume(SceneType prev_scene) { teleport_from_other_scene = false; called_battle = false; } diff --git a/src/scene_map.h b/src/scene_map.h index dbf0621b5d..5a92e67444 100644 --- a/src/scene_map.h +++ b/src/scene_map.h @@ -39,7 +39,7 @@ class Scene_Map: public Scene { void Start() override; void Continue(SceneType prev_scene) override; void Update() override; - void Resume() override; + void Resume(SceneType prev_scene) override; void TransitionIn(SceneType prev_scene) override; void TransitionOut(SceneType next_scene) override; void DrawBackground() override; diff --git a/src/scene_title.cpp b/src/scene_title.cpp index 3acf764cb2..0f068d86bb 100644 --- a/src/scene_title.cpp +++ b/src/scene_title.cpp @@ -79,7 +79,7 @@ void Scene_Title::TransitionIn(SceneType prev_scene) { } } -void Scene_Title::Resume() { +void Scene_Title::Resume(SceneType prev_scene) { if (!Data::system.show_title || Player::new_game_flag) return; diff --git a/src/scene_title.h b/src/scene_title.h index 4be53a144f..8b94e4f0a1 100644 --- a/src/scene_title.h +++ b/src/scene_title.h @@ -37,7 +37,7 @@ class Scene_Title : public Scene { void Start() override; void Continue(SceneType prev_scene) override; void TransitionIn(SceneType prev_scene) override; - void Resume() override; + void Resume(SceneType prev_scene) override; void Update() override; /** From 2a0aa840daa2a968aa593e9e1b0f29e359073517 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Mon, 18 Mar 2019 19:13:05 -0400 Subject: [PATCH 05/10] Remove SceneMap::called_battle --- src/scene_map.cpp | 20 ++++++++------------ src/scene_map.h | 2 -- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/scene_map.cpp b/src/scene_map.cpp index e66ad7e14b..d5187fc4fb 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -82,7 +82,7 @@ void Scene_Map::Start() { void Scene_Map::Continue(SceneType prev_scene) { teleport_from_other_scene = true; - if (called_battle) { + if (prev_scene == Scene::Battle) { // Came from battle Game_System::BgmPlay(Main_Data::game_data.system.before_battle_music); } @@ -99,18 +99,15 @@ void Scene_Map::Continue(SceneType prev_scene) { spriteset->Update(); } -void Scene_Map::Resume(SceneType prev_scene) { +void Scene_Map::TransitionIn(SceneType prev_scene) { teleport_from_other_scene = false; - called_battle = false; -} -void Scene_Map::TransitionIn(SceneType prev_scene) { // Teleport already setup a transition. if (Graphics::IsTransitionPending()) { return; } - if (called_battle) { + if (prev_scene == Scene::Battle) { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_EndBattleShow), this, 32); } else if (Game_Temp::transition_menu) { Game_Temp::transition_menu = false; @@ -121,16 +118,16 @@ void Scene_Map::TransitionIn(SceneType prev_scene) { } void Scene_Map::TransitionOut(SceneType next_scene) { - if (called_battle) { + if (next_scene == Scene::Battle) { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_BeginBattleErase), this, 32, true); Graphics::GetTransition().AppendBefore(Color(255, 255, 255, 255), 12, 2); + return; } - else if (next_scene == Scene::Gameover) { + if (next_scene == Scene::Gameover) { Graphics::GetTransition().Init(Transition::TransitionFadeOut, this, 32, true); + return; } - else { - Scene::TransitionOut(next_scene); - } + Scene::TransitionOut(next_scene); } void Scene_Map::DrawBackground() { @@ -312,7 +309,6 @@ void Scene_Map::FinishPendingTeleport() { // Scene calling stuff. void Scene_Map::CallBattle() { - called_battle = true; Main_Data::game_data.system.before_battle_music = Game_System::GetCurrentBGM(); Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_BeginBattle)); Game_System::BgmPlay(Game_System::GetSystemBGM(Game_System::BGM_Battle)); diff --git a/src/scene_map.h b/src/scene_map.h index 5a92e67444..26646fc9e0 100644 --- a/src/scene_map.h +++ b/src/scene_map.h @@ -39,7 +39,6 @@ class Scene_Map: public Scene { void Start() override; void Continue(SceneType prev_scene) override; void Update() override; - void Resume(SceneType prev_scene) override; void TransitionIn(SceneType prev_scene) override; void TransitionOut(SceneType next_scene) override; void DrawBackground() override; @@ -71,7 +70,6 @@ class Scene_Map: public Scene { bool from_save; // Teleport from new game or Teleport / Escape skill from menu. bool teleport_from_other_scene = false; - bool called_battle = false; }; #endif From 4ffd28cb8d36ea0f7eba0b27b4b05e8b9cac9bf3 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Mon, 18 Mar 2019 19:30:11 -0400 Subject: [PATCH 06/10] Scene_Battle: Don't use Game_Temp::transition_menu --- src/scene_battle.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/scene_battle.cpp b/src/scene_battle.cpp index 5ada299d7c..a0d5a3841f 100644 --- a/src/scene_battle.cpp +++ b/src/scene_battle.cpp @@ -97,21 +97,21 @@ void Scene_Battle::Start() { } void Scene_Battle::TransitionIn(SceneType prev_scene) { - if (Game_Temp::transition_menu) { - Game_Temp::transition_menu = false; + if (prev_scene == Scene::Debug) { Scene::TransitionIn(prev_scene); - } else { - Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_BeginBattleShow), this, 32); + return; } + Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_BeginBattleShow), this, 32); } void Scene_Battle::TransitionOut(SceneType next_scene) { - if (Player::exit_flag || Game_Battle::battle_test.enabled || Game_Temp::transition_menu || Scene::instance->type == Scene::Title) { + if (Player::exit_flag + || Game_Battle::battle_test.enabled + || next_scene == Scene::Debug || next_scene == Scene::Title) { Scene::TransitionOut(next_scene); + return; } - else { - Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_EndBattleErase), this, 32, true); - } + Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_EndBattleErase), this, 32, true); } void Scene_Battle::DrawBackground() { @@ -622,7 +622,6 @@ void Scene_Battle::ActionSelectedCallback(Game_Battler* for_battler) { void Scene_Battle::CallDebug() { if (Player::debug_flag) { - Game_Temp::transition_menu = true; Scene::Push(std::make_shared()); } } From 3f51bd30a67c2892711ad32b5a45630be3dbe1e3 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Mon, 18 Mar 2019 19:52:21 -0400 Subject: [PATCH 07/10] Remove Game_Temp::transition_menu * Use prev/next scenes to determine transitions * Put FinishTeleport logic in Scene_Map::Continue() for teleport / escape spells * Handle teleport / escape transition logic in TransitionIn() --- src/game_temp.cpp | 2 -- src/game_temp.h | 1 - src/scene_debug.cpp | 1 - src/scene_map.cpp | 47 +++++++++++++++++++++++++++------------------ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/game_temp.cpp b/src/game_temp.cpp index 281bf8eb53..491354758c 100644 --- a/src/game_temp.cpp +++ b/src/game_temp.cpp @@ -24,7 +24,6 @@ bool Game_Temp::to_title; bool Game_Temp::transition_processing; Transition::TransitionType Game_Temp::transition_type; bool Game_Temp::transition_erase; -bool Game_Temp::transition_menu; bool Game_Temp::shop_buys; bool Game_Temp::shop_sells; int Game_Temp::shop_type; @@ -51,7 +50,6 @@ void Game_Temp::Init() { transition_processing = false; transition_type = Transition::TransitionNone; transition_erase = false; - transition_menu = false; shop_buys = true; shop_sells = true; shop_type = 0; diff --git a/src/game_temp.h b/src/game_temp.h index 15af4f45b0..fa908519c5 100644 --- a/src/game_temp.h +++ b/src/game_temp.h @@ -39,7 +39,6 @@ class Game_Temp { static bool transition_processing; static Transition::TransitionType transition_type; static bool transition_erase; - static bool transition_menu; static bool shop_buys; static bool shop_sells; diff --git a/src/scene_debug.cpp b/src/scene_debug.cpp index 1dab8ba159..3a977eda11 100644 --- a/src/scene_debug.cpp +++ b/src/scene_debug.cpp @@ -247,7 +247,6 @@ void Scene_Debug::Update() { Game_Temp::battle_first_strike = 0; Game_Temp::battle_result = Game_Temp::BattleVictory; Game_Battle::SetBattleMode(0); - Game_Temp::transition_menu = false; static_cast(Scene::instance.get())->CallBattle(); } } diff --git a/src/scene_map.cpp b/src/scene_map.cpp index d5187fc4fb..8e37d86132 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -47,7 +47,6 @@ Scene_Map::Scene_Map(bool from_save) : } Scene_Map::~Scene_Map() { - Game_Temp::transition_menu = false; } void Scene_Map::Start() { @@ -85,11 +84,11 @@ void Scene_Map::Continue(SceneType prev_scene) { if (prev_scene == Scene::Battle) { // Came from battle Game_System::BgmPlay(Main_Data::game_data.system.before_battle_music); - } - else { - Game_Map::PlayBgm(); + return; } + Game_Map::PlayBgm(); + // Player cast Escape / Teleport from menu if (Main_Data::game_player->IsPendingTeleport()) { FinishPendingTeleport(); @@ -99,6 +98,24 @@ void Scene_Map::Continue(SceneType prev_scene) { spriteset->Update(); } +static bool IsMenuScene(Scene::SceneType scene) { + switch (scene) { + case Scene::Shop: + case Scene::Name: + case Scene::Menu: + case Scene::Save: + case Scene::Load: + case Scene::Debug: + case Scene::Skill: + case Scene::Item: + case Scene::Teleport: + return true; + default: + break; + } + return false; +} + void Scene_Map::TransitionIn(SceneType prev_scene) { teleport_from_other_scene = false; @@ -109,12 +126,15 @@ void Scene_Map::TransitionIn(SceneType prev_scene) { if (prev_scene == Scene::Battle) { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_EndBattleShow), this, 32); - } else if (Game_Temp::transition_menu) { - Game_Temp::transition_menu = false; + return; + } + + if (IsMenuScene(prev_scene)) { Scene::TransitionIn(prev_scene); - } else { - Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 32); + return; } + + Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 32); } void Scene_Map::TransitionOut(SceneType next_scene) { @@ -317,20 +337,14 @@ void Scene_Map::CallBattle() { } void Scene_Map::CallShop() { - Game_Temp::transition_menu = true; - Scene::Push(std::make_shared()); } void Scene_Map::CallName() { - Game_Temp::transition_menu = true; - Scene::Push(std::make_shared()); } void Scene_Map::CallMenu() { - Game_Temp::transition_menu = true; - // TODO: Main_Data::game_player->Straighten(); Scene::Push(std::make_shared()); @@ -345,20 +359,15 @@ void Scene_Map::CallMenu() { } void Scene_Map::CallSave() { - Game_Temp::transition_menu = true; - Scene::Push(std::make_shared()); } void Scene_Map::CallLoad() { - Game_Temp::transition_menu = true; - Scene::Push(std::make_shared()); } void Scene_Map::CallDebug() { if (Player::debug_flag) { - Game_Temp::transition_menu = true; Scene::Push(std::make_shared()); } } From c32cd50813853d83a212f35a725ef192604ea71b Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Thu, 21 Mar 2019 19:28:16 -0400 Subject: [PATCH 08/10] Debug menu - don't interrupt other scenes. Imagine a very long cutscene which calls the menu at some point allowing you to save and prepare your characters for a boss battle. Now suppose you hit F9 at exactly that moment. The menu gets canceled in favor of the debug menu and now you start the battle immediately after. We should not allow the debug scene if any event called another scene. We should not allow it to be abused to cancel battles. It also makes sense for ESC menu to take precedence. --- src/scene_map.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/scene_map.cpp b/src/scene_map.cpp index 8e37d86132..0b92cc3f34 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -217,13 +217,16 @@ void Scene_Map::UpdateSceneCalling() { if (Game_Message::visible) return; - if (Player::debug_flag) { + auto call = GetRequestedScene(); + SetRequestedScene(Null); + + if (call == Null && Player::debug_flag) { // ESC-Menu calling can be force called when TestPlay mode is on and cancel is pressed 5 times while holding SHIFT if (Input::IsPressed(Input::SHIFT)) { if (Input::IsTriggered(Input::CANCEL)) { debug_menuoverwrite_counter++; if (debug_menuoverwrite_counter >= 5) { - SetRequestedScene(Menu); + call = Menu; debug_menuoverwrite_counter = 0; } } @@ -231,17 +234,16 @@ void Scene_Map::UpdateSceneCalling() { debug_menuoverwrite_counter = 0; } - if (Input::IsTriggered(Input::DEBUG_MENU)) { - SetRequestedScene(Debug); - } - else if (Input::IsTriggered(Input::DEBUG_SAVE)) { - SetRequestedScene(Save); + if (call == Null) { + if (Input::IsTriggered(Input::DEBUG_MENU)) { + call = Debug; + } + else if (Input::IsTriggered(Input::DEBUG_SAVE)) { + call = Save; + } } } - auto call = GetRequestedScene(); - - SetRequestedScene(Null); switch (call) { case Scene::Menu: CallMenu(); From cfe8d27fc473551cbdcab9135e33c7b324088e8b Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Thu, 21 Mar 2019 20:11:41 -0400 Subject: [PATCH 09/10] Title screen fixes * Simplify logic using prev_scene * Animate the command window if we continue from non-loading * Remove Scene_Title::Resume() --- src/scene_title.cpp | 23 ++++++++--------------- src/scene_title.h | 1 - 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/scene_title.cpp b/src/scene_title.cpp index 0f068d86bb..7d3d5e6a33 100644 --- a/src/scene_title.cpp +++ b/src/scene_title.cpp @@ -63,30 +63,23 @@ void Scene_Title::Continue(SceneType prev_scene) { Start(); } + + if (prev_scene != Scene::Load && !Player::hide_title_flag) { + command_window->SetOpenAnimation(8); + } } void Scene_Title::TransitionIn(SceneType prev_scene) { if (Game_Battle::battle_test.enabled || !Data::system.show_title || Player::new_game_flag) return; - if (command_window->GetVisible()) { + if (prev_scene == Scene::Load || Player::hide_title_flag) { Scene::TransitionIn(prev_scene); - } - else if (!Player::hide_title_flag) { - Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 32); - } else { - Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 6); - } -} - -void Scene_Title::Resume(SceneType prev_scene) { - if (!Data::system.show_title || Player::new_game_flag) return; - - if (command_window) { - command_window->SetVisible(true); } + Graphics::GetTransition().Init(Transition::TransitionFadeIn, this, 32); } + void Scene_Title::Update() { if (Game_Battle::battle_test.enabled) { PrepareBattleTest(); @@ -166,7 +159,7 @@ void Scene_Title::CreateCommandWindow() { command_window->SetBackOpacity(128); } - command_window->SetVisible(false); + command_window->SetVisible(true); } void Scene_Title::PlayTitleMusic() { diff --git a/src/scene_title.h b/src/scene_title.h index 8b94e4f0a1..f5cd8c5e5c 100644 --- a/src/scene_title.h +++ b/src/scene_title.h @@ -37,7 +37,6 @@ class Scene_Title : public Scene { void Start() override; void Continue(SceneType prev_scene) override; void TransitionIn(SceneType prev_scene) override; - void Resume(SceneType prev_scene) override; void Update() override; /** From 2d9672036fdf888dcdb1ff728c028d6dc2d4e048 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Thu, 21 Mar 2019 21:16:30 -0400 Subject: [PATCH 10/10] Fix event transitions behavior with scene change If an event erases the screen: * After a battle - stays erased * After debug - stays erased (Fixes RPG_RT bug where the entire debug menu would be black * After anything else - screen is shown --- src/scene_map.cpp | 13 ++++++++++++- src/scene_map.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/scene_map.cpp b/src/scene_map.cpp index 0b92cc3f34..c5af79b002 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -124,6 +124,11 @@ void Scene_Map::TransitionIn(SceneType prev_scene) { return; } + // If an event erased the screen, don't transition in. + if (screen_erased_by_event) { + return; + } + if (prev_scene == Scene::Battle) { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_EndBattleShow), this, 32); return; @@ -138,6 +143,11 @@ void Scene_Map::TransitionIn(SceneType prev_scene) { } void Scene_Map::TransitionOut(SceneType next_scene) { + if (next_scene != Scene::Battle + && next_scene != Scene::Debug) { + screen_erased_by_event = false; + } + if (next_scene == Scene::Battle) { Graphics::GetTransition().Init((Transition::TransitionType)Game_System::GetTransition(Game_System::Transition_BeginBattleErase), this, 32, true); Graphics::GetTransition().AppendBefore(Color(255, 255, 255, 255), 12, 2); @@ -192,6 +202,7 @@ void Scene_Map::UpdateStage2() { // This will be fixed later. Graphics::GetTransition().Init(Game_Temp::transition_type, this, 32, Game_Temp::transition_erase); + screen_erased_by_event = Game_Temp::transition_erase; // Unless its an instant transition, we must wait for it to finish before we can proceed. if (IsAsyncPending()) { async_continuation = [this]() { UpdateStage3(); }; @@ -313,7 +324,7 @@ void Scene_Map::FinishPendingTeleport() { } // Event forced the screen to erased, so we're done here. - if (Game_Temp::transition_erase) { + if (screen_erased_by_event) { UpdateSceneCalling(); return; } diff --git a/src/scene_map.h b/src/scene_map.h index 26646fc9e0..80f72ad2f4 100644 --- a/src/scene_map.h +++ b/src/scene_map.h @@ -70,6 +70,7 @@ class Scene_Map: public Scene { bool from_save; // Teleport from new game or Teleport / Escape skill from menu. bool teleport_from_other_scene = false; + bool screen_erased_by_event = false; }; #endif