Skip to content

Commit

Permalink
Window_Interpreter fixes:
Browse files Browse the repository at this point in the history
- Base frame for CommonEvent interpreters was always shown with Id '0'
- Encountering a "CallEvent" command while traversing up the stack, always set the flag "is_calling_ev_ce", even if it was a map event
  • Loading branch information
florianessl committed May 23, 2024
1 parent 404e6ba commit f77bd4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/scene_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,13 +1244,14 @@ void Scene_Debug::UpdateInterpreterWindow(int index) {
lcf::rpg::SaveEventExecState state;
std::string first_line = "";
bool valid = false;
int evt_id = 0;

if (index == 1) {
state = Game_Interpreter::GetForegroundInterpreter().GetState();
first_line = Game_Battle::IsBattleRunning() ? "Foreground (Battle)" : "Foreground (Map)";
valid = true;
} else if (index <= state_interpreter.ev.size()) {
int evt_id = state_interpreter.ev[index - 1];
evt_id = state_interpreter.ev[index - 1];
state = state_interpreter.state_ev[index - 1];
first_line = fmt::format("EV{:04d}: {}", evt_id, Game_Map::GetEvent(evt_id)->GetName());
valid = true;
Expand All @@ -1260,6 +1261,7 @@ void Scene_Debug::UpdateInterpreterWindow(int index) {
for (auto& ce : Game_Map::GetCommonEvents()) {
if (ce.common_event_id == ce_id) {
first_line = fmt::format("CE{:04d}: {}", ce_id, ce.GetName());
evt_id = ce_id;
valid = true;
break;
}
Expand All @@ -1268,10 +1270,10 @@ void Scene_Debug::UpdateInterpreterWindow(int index) {

if (valid) {
state_interpreter.selected_state = index;
interpreter_window->SetStackState(index > state_interpreter.ev.size(), first_line, state);
interpreter_window->SetStackState(index > state_interpreter.ev.size(), evt_id, first_line, state);
} else {
state_interpreter.selected_state = -1;
interpreter_window->SetStackState(0, "", {});
interpreter_window->SetStackState(0, 0, "", {});
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/window_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ Window_Interpreter::~Window_Interpreter() {

}

void Window_Interpreter::SetStackState(bool is_ce, std::string interpreter_desc, lcf::rpg::SaveEventExecState state) {
this->interpreter_desc = interpreter_desc;
void Window_Interpreter::SetStackState(bool is_ce, int owner_evt_id, std::string interpreter_desc, lcf::rpg::SaveEventExecState state) {
this->display_item = { is_ce, owner_evt_id, interpreter_desc };
this->state = state;
this->is_ce = is_ce;
}

void Window_Interpreter::Refresh() {
Expand All @@ -73,12 +72,14 @@ void Window_Interpreter::Refresh() {
auto& prev_frame = state.stack[i - 1];
auto& com = prev_frame.commands[prev_frame.current_command - 1];
if (com.code == 12330) { // CallEvent
is_calling_ev_ce = true;
if (com.parameters[0] == 0) {
is_calling_ev_ce = true;
evt_id = com.parameters[1];
} else if (com.parameters[0] == 3 && Player::IsPatchManiac()) {
is_calling_ev_ce = true;
evt_id = Main_Data::game_variables->Get(com.parameters[1]);
} else if (com.parameters[0] == 4 && Player::IsPatchManiac()) {
is_calling_ev_ce = true;
evt_id = Main_Data::game_variables->GetIndirect(com.parameters[1]);
}
}
Expand All @@ -90,7 +91,7 @@ void Window_Interpreter::Refresh() {
max_page_id = page_id;

StackItem item = StackItem();
item.is_ce = is_calling_ev_ce || (i == 0 && this->is_ce);
item.is_ce = is_calling_ev_ce || (i == 0 && this->display_item.is_ce);
item.evt_id = evt_id;
item.page_id = page_id;
item.name = "";
Expand Down Expand Up @@ -147,7 +148,7 @@ void Window_Interpreter::Refresh() {
}

bool Window_Interpreter::IsValid() {
return !interpreter_desc.empty();
return !display_item.desc.empty();
}

void Window_Interpreter::Update() {
Expand All @@ -159,7 +160,7 @@ void Window_Interpreter::DrawDescriptionLines() {
Rect rect = GetItemRect(i++);
contents->ClearRect(rect);

contents->TextDraw(rect.x, rect.y, Font::ColorDefault, interpreter_desc);
contents->TextDraw(rect.x, rect.y, Font::ColorDefault, display_item.desc);

if (state.wait_movement) {
rect = GetItemRect(i++);
Expand Down
12 changes: 9 additions & 3 deletions src/window_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Window_Interpreter : public Window_Selectable {

void Update() override;

void SetStackState(bool is_ce, std::string interpreter_desc, lcf::rpg::SaveEventExecState state);
void SetStackState(bool is_ce, int owner_evt_id, std::string interpreter_desc, lcf::rpg::SaveEventExecState state);
void Refresh();
bool IsValid();

Expand All @@ -39,6 +39,12 @@ class Window_Interpreter : public Window_Selectable {
void DrawDescriptionLines();
void DrawStackLine(int index);
private:
struct InterpDisplayItem {
bool is_ce;
int owner_evt_id;
std::string desc;
};

struct StackItem {
bool is_ce;
int evt_id, page_id;
Expand All @@ -48,12 +54,12 @@ class Window_Interpreter : public Window_Selectable {

const int lines_without_stack_fixed = 3;

bool is_ce = false;
lcf::rpg::SaveEventExecState state;
std::string interpreter_desc;
int lines_without_stack = 0;

int digits_stackitemno = 0, digits_evt_id = 0, digits_page_id = 0, digits_evt_combined_id = 0, digits_cmdcount = 0;

InterpDisplayItem display_item;
std::vector<StackItem> stack_display_items;
};

Expand Down

0 comments on commit f77bd4f

Please sign in to comment.