Skip to content

Commit

Permalink
Scene_Name: use Args instead of game_temp
Browse files Browse the repository at this point in the history
  • Loading branch information
mateofio committed Apr 13, 2019
1 parent eacdbb4 commit 02be291
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
27 changes: 13 additions & 14 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,23 +540,22 @@ bool Game_Interpreter_Map::CommandEnterHeroName(RPG::EventCommand const& com) {
return false;
}

Game_Temp::hero_name_id = com.parameters[0];
Game_Temp::hero_name_charset = com.parameters[1];
const int actor_id = com.parameters[0];

if (com.parameters[2] != 0) {
Game_Actor *actor = Game_Actors::GetActor(Game_Temp::hero_name_id);

if (!actor) {
Output::Warning("EnterHeroName: Invalid actor ID %d", Game_Temp::hero_name_id);
Game_Temp::hero_name.clear();
} else {
Game_Temp::hero_name = actor->GetName();
}
} else {
Game_Temp::hero_name.clear();
Game_Actor* actor = Game_Actors::GetActor(actor_id);
if (!actor) {
Output::Warning("ChangeHeroName: Invalid actor ID %d", actor_id);
return true;
}

Scene::instance->SetRequestedScene(std::make_shared<Scene_Name>());
Scene_Name::Args args;

args.actor_id = actor_id;
args.charset = com.parameters[1];
args.show_default_name = com.parameters[2];


Scene::instance->SetRequestedScene(std::make_shared<Scene_Name>(std::move(args)));
++index;
return false;
}
Expand Down
6 changes: 0 additions & 6 deletions src/game_temp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ bool Game_Temp::transition_processing;
Transition::TransitionType Game_Temp::transition_type;
bool Game_Temp::transition_erase;
int Game_Temp::inn_price;
std::string Game_Temp::hero_name;
int Game_Temp::hero_name_id;
int Game_Temp::hero_name_charset;
bool Game_Temp::battle_running;
int Game_Temp::battle_troop_id;
std::string Game_Temp::battle_background;
Expand All @@ -44,9 +41,6 @@ void Game_Temp::Init() {
transition_type = Transition::TransitionNone;
transition_erase = false;
inn_price = 0;
hero_name = "";
hero_name_id = 0;
hero_name_charset = 0;
battle_running = false;
battle_troop_id = 0;
battle_background = {};
Expand Down
4 changes: 0 additions & 4 deletions src/game_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class Game_Temp {
static int inn_price;
static bool inn_stay;

static std::string hero_name;
static int hero_name_id;
static int hero_name_charset;

static bool battle_running;
static int battle_troop_id;
static std::string battle_background;
Expand Down
19 changes: 12 additions & 7 deletions src/scene_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@
#include "game_temp.h"
#include "input.h"
#include "player.h"
#include "reader_util.h"

Scene_Name::Scene_Name() {
Scene_Name::Scene_Name(Args args)
: args(std::move(args))
{
Scene::type = Scene::Name;
}

void Scene_Name::Start() {
// Create the windows

name_window.reset(new Window_Name(96, 40, 192, 32));
name_window->Set(Game_Temp::hero_name);
if (args.show_default_name) {
auto* actor = ReaderUtil::GetElement(Data::actors, args.actor_id);
assert(actor);
name_window->Set(actor->name);
}
name_window->Refresh();

face_window.reset(new Window_Face(32, 8, 64, 64));
face_window->Set(Game_Temp::hero_name_id);
face_window->Set(args.actor_id);
face_window->Refresh();

layout_index = Game_Temp::hero_name_charset;
layout_index = args.charset;

const char* done = Window_Keyboard::DONE;
// Japanese pages
Expand Down Expand Up @@ -101,8 +107,7 @@ void Scene_Name::Update() {
assert(!s.empty());

if (s == Window_Keyboard::DONE) {
Game_Temp::hero_name = name_window->Get();
Game_Actor* actor = Game_Actors::GetActor(Game_Temp::hero_name_id);
Game_Actor* actor = Game_Actors::GetActor(args.actor_id);
if (actor != NULL) {
if (name_window->Get().empty()) {
name_window->Set(actor->GetName());
Expand Down
8 changes: 7 additions & 1 deletion src/scene_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@
class Scene_Name : public Scene {

public:
struct Args {
int actor_id = 0;
int charset = 0;
bool show_default_name = false;
};
/**
* Constructor.
*/
Scene_Name();
explicit Scene_Name(Args args);

void Start() override;
void Update() override;
Expand All @@ -45,6 +50,7 @@ class Scene_Name : public Scene {
std::unique_ptr<Window_Keyboard> kbd_window;
std::unique_ptr<Window_Name> name_window;
std::unique_ptr<Window_Face> face_window;
Args args;
};

#endif

0 comments on commit 02be291

Please sign in to comment.