Skip to content

Commit

Permalink
Scene_Shop: use a continuation for transaction handling
Browse files Browse the repository at this point in the history
Handles cases where called shop scene is overwritten by
another scene
  • Loading branch information
mateofio committed Apr 13, 2019
1 parent 5debe86 commit eacdbb4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3348,7 +3348,6 @@ bool Game_Interpreter::DefaultContinuation(RPG::EventCommand const& /* com */) {

// Dummy Continuations

bool Game_Interpreter::ContinuationOpenShop(RPG::EventCommand const& /* com */) { return true; }
bool Game_Interpreter::ContinuationShowInnStart(RPG::EventCommand const& /* com */) { return true; }
bool Game_Interpreter::ContinuationShowInnFinish(RPG::EventCommand const& /* com */) { return true; }
bool Game_Interpreter::ContinuationEnemyEncounter(RPG::EventCommand const& /* com */) { return true; }
Expand Down
1 change: 0 additions & 1 deletion src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ class Game_Interpreter

virtual bool DefaultContinuation(RPG::EventCommand const& com);
virtual bool ContinuationChoices(RPG::EventCommand const& com);
virtual bool ContinuationOpenShop(RPG::EventCommand const& com);
virtual bool ContinuationShowInnStart(RPG::EventCommand const& com);
virtual bool ContinuationShowInnFinish(RPG::EventCommand const& com);
virtual bool ContinuationEnemyEncounter(RPG::EventCommand const& com);
Expand Down
24 changes: 7 additions & 17 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,29 +308,19 @@ bool Game_Interpreter_Map::CommandOpenShop(RPG::EventCommand const& com) { // co
args.goods.push_back(*it);
}

Game_Temp::shop_transaction = false;
const auto indent = com.indent;
args.continuation = [this, indent](bool did_transaction) {
SetSubcommandIndex(indent, did_transaction ? 0 : 1);
};

auto scene = std::make_shared<Scene_Shop>(std::move(args));
Scene::instance->SetRequestedScene(std::move(scene));

SetContinuation(static_cast<ContinuationFunction>(&Game_Interpreter_Map::ContinuationOpenShop));

return false;
}

bool Game_Interpreter_Map::ContinuationOpenShop(RPG::EventCommand const& com) {
auto* frame = GetFrame();
assert(frame);
auto& index = frame->current_command;

continuation = nullptr;

int sub_idx = Game_Temp::shop_transaction ? 0 : 1;

SetSubcommandIndex(com.indent, sub_idx);
// save game compatibility with RPG_RT
ReserveSubcommandIndex(indent);

++index;
return true;
return false;
}

bool Game_Interpreter_Map::CommandTransaction(RPG::EventCommand const& com) { // code 20720
Expand Down
1 change: 0 additions & 1 deletion src/game_interpreter_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class Game_Interpreter_Map : public Game_Interpreter
bool CommandOpenLoadMenu(RPG::EventCommand const& com);
bool CommandToggleAtbMode(RPG::EventCommand const& com);

bool ContinuationOpenShop(RPG::EventCommand const& com) override;
bool ContinuationShowInnStart(RPG::EventCommand const& com) override;
bool ContinuationShowInnContinue(RPG::EventCommand const& com);
bool ContinuationShowInnFinish(RPG::EventCommand const& com) override;
Expand Down
2 changes: 0 additions & 2 deletions src/game_temp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::shop_transaction;
int Game_Temp::inn_price;
std::string Game_Temp::hero_name;
int Game_Temp::hero_name_id;
Expand All @@ -44,7 +43,6 @@ void Game_Temp::Init() {
transition_processing = false;
transition_type = Transition::TransitionNone;
transition_erase = false;
shop_transaction = false;
inn_price = 0;
hero_name = "";
hero_name_id = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/game_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class Game_Temp {
static Transition::TransitionType transition_type;
static bool transition_erase;

static bool shop_transaction;

static int inn_type; // message set A or B
static int inn_price;
static bool inn_stay;
Expand Down
6 changes: 4 additions & 2 deletions src/scene_shop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void Scene_Shop::Start() {
sell_window->SetIndex(0);
sell_window->SetActive(true);

Game_Temp::shop_transaction = false;
timer = 0;

if (args.buys && args.sells) {
Expand Down Expand Up @@ -200,6 +199,9 @@ void Scene_Shop::Update() {
void Scene_Shop::UpdateCommandSelection() {
if (Input::IsTriggered(Input::CANCEL)) {
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cancel));
if (args.continuation) {
args.continuation(did_transaction);
}
Scene::Pop();
} else if (Input::IsTriggered(Input::DECISION)) {
switch (shop_window->GetChoice()) {
Expand Down Expand Up @@ -306,6 +308,6 @@ void Scene_Shop::UpdateNumberInput() {
}
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));

Game_Temp::shop_transaction = true;
did_transaction = true;
}
}
5 changes: 5 additions & 0 deletions src/scene_shop.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "window_shopstatus.h"
#include "window_shopsell.h"
#include "window_shop.h"
#include <functional>

/**
* Scene Shop class.
Expand All @@ -37,11 +38,14 @@
class Scene_Shop : public Scene {

public:
using ShopContinuation = std::function<void(bool)>;

struct Args {
bool buys = true;
bool sells = true;
int shop_type = 0;
std::vector<int> goods;
ShopContinuation continuation;
};

/**
Expand Down Expand Up @@ -86,6 +90,7 @@ class Scene_Shop : public Scene {
int mode;
int timer;
Args args;
bool did_transaction = false;
};

#endif

0 comments on commit eacdbb4

Please sign in to comment.