Skip to content

Commit

Permalink
Fix name scene showing the incorrect face graphic
Browse files Browse the repository at this point in the history
Wow, another silent integer to Pointer conversion
When will this end...

Fix EasyRPG#3286
  • Loading branch information
Ghabry committed Nov 22, 2024
1 parent a446cdb commit 830d70e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
8 changes: 7 additions & 1 deletion src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,13 @@ bool Game_Interpreter_Map::CommandEnterHeroName(lcf::rpg::EventCommand const& co
auto charset = com.parameters[1];
auto use_default_name = com.parameters[2];

auto scene = std::make_shared<Scene_Name>(actor_id, charset, use_default_name);
Game_Actor* actor = Main_Data::game_actors->GetActor(actor_id);
if (!actor) {
Output::Warning("EnterHeroName: Invalid actor ID {}", actor_id);
return true;
}

auto scene = std::make_shared<Scene_Name>(*actor, charset, use_default_name);
Scene::instance->SetRequestedScene(std::move(scene));

++index;
Expand Down
32 changes: 10 additions & 22 deletions src/scene_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,14 @@
#include "player.h"
#include "output.h"

Scene_Name::Scene_Name(int actor_id, int charset, bool use_default_name)
: actor_id(actor_id), layout_index(charset), use_default_name(use_default_name)
Scene_Name::Scene_Name(Game_Actor& actor, int charset, bool use_default_name)
: actor(actor), layout_index(charset), use_default_name(use_default_name)
{
Scene::type = Scene::Name;

auto *actor = Main_Data::game_actors->GetActor(actor_id);
if (!actor) {
Output::Error("EnterHeroName: Invalid actor ID {}", actor_id);
}
}

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

auto *actor = Main_Data::game_actors->GetActor(actor_id);
assert(actor);

int margin_x = 32;
int margin_y = 8;
int window_face_width = 64;
Expand All @@ -51,11 +42,11 @@ void Scene_Name::Start() {
int window_keyboard_height = 160;

face_window.reset(new Window_Face(Player::menu_offset_x + margin_x, Player::menu_offset_y + margin_y, window_face_width, window_face_height));
face_window->Set(actor_id);
face_window->Set(actor);
face_window->Refresh();

name_window.reset(new Window_Name(Player::menu_offset_x + window_face_width + margin_x, Player::menu_offset_y + margin_y + 32, window_name_width, window_name_height));
name_window->Set(use_default_name ? ToString(actor->GetName()) : "");
name_window->Set(use_default_name ? ToString(actor.GetName()) : "");
name_window->Refresh();

const char* done = Window_Keyboard::DONE;
Expand Down Expand Up @@ -118,15 +109,12 @@ void Scene_Name::vUpdate() {
assert(!s.empty());

if (s == Window_Keyboard::DONE) {
auto* actor = Main_Data::game_actors->GetActor(actor_id);
if (actor != nullptr) {
if (name_window->Get().empty()) {
name_window->Set(ToString(actor->GetName()));
name_window->Refresh();
} else {
actor->SetName(name_window->Get());
Scene::Pop();
}
if (name_window->Get().empty()) {
name_window->Set(ToString(actor.GetName()));
name_window->Refresh();
} else {
actor.SetName(name_window->Get());
Scene::Pop();
}
} else if (s == Window_Keyboard::NEXT_PAGE) {
++layout_index;
Expand Down
5 changes: 3 additions & 2 deletions src/scene_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ class Scene_Name : public Scene {
/**
* Constructor.
*/
Scene_Name(int actor_id, int charset, bool use_default_name);
Scene_Name(Game_Actor& actor, int charset, bool use_default_name);

void Start() override;
void vUpdate() override;

protected:
std::vector<Window_Keyboard::Mode> layouts;
int actor_id = 0;
int layout_index = 0;
bool use_default_name = false;

private:
Game_Actor& actor;

std::unique_ptr<Window_Keyboard> kbd_window;
std::unique_ptr<Window_Name> name_window;
std::unique_ptr<Window_Face> face_window;
Expand Down

0 comments on commit 830d70e

Please sign in to comment.