Skip to content

Commit

Permalink
Scene_Debug: Minor refactoring + UX improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
florianessl committed May 12, 2024
1 parent 5816219 commit 64475dc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
58 changes: 41 additions & 17 deletions src/scene_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Scene_Debug::Start() {
interpreter_window->SetActive(false);

UpdateRangeListWindow();
var_window->Refresh();
RefreshDetailWindow();

strings_cached = false;
interpreter_states_cached = false;
Expand Down Expand Up @@ -184,6 +184,18 @@ int Scene_Debug::GetSelectedIndexFromRange() const {
return range_page * 100 + range_index * 10 + 1;
}

void Scene_Debug::RestoreRangeSelectionFromSelectedValue(int value) {
switch (mode) {
case eInterpreter:
range_index = value % 10;
range_page = value / 10;
break;
default:
range_index = (value % 100) / 10;
range_page = value / 100;
break;
}
}

void Scene_Debug::SetupUiRangeList() {
auto& idx = prev[mode];
Expand All @@ -206,7 +218,7 @@ void Scene_Debug::PushUiRangeList() {
range_window->SetActive(true);

UpdateRangeListWindow();
var_window->Refresh();
RefreshDetailWindow();
}

void Scene_Debug::PushUiVarList() {
Expand Down Expand Up @@ -245,7 +257,7 @@ void Scene_Debug::PushUiNumberInput(int init_value, int digits, bool show_operat
numberinput_window->SetMaxDigits(digits);
numberinput_window->Refresh();

var_window->Refresh();
UpdateDetailWindow();
UpdateRangeListWindow();
}

Expand Down Expand Up @@ -273,6 +285,11 @@ void Scene_Debug::PushUiStringView() {
void Scene_Debug::PushUiInterpreterView() {
const bool was_range_list = (GetFrame().uimode == eUiRangeList);

if (!interpreter_window->IsValid()) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
return;
}

Push(eUiInterpreterView);

auto& idx = prev[mode];
Expand Down Expand Up @@ -308,7 +325,6 @@ void Scene_Debug::Pop() {
stringview_window->SetActive(false);
stringview_window->SetVisible(false);
interpreter_window->SetActive(false);
interpreter_window->SetVisible(false);

if (stack_index == 0) {
Scene::Pop();
Expand All @@ -317,7 +333,8 @@ void Scene_Debug::Pop() {

--stack_index;

auto nui = GetFrame().uimode;
auto& frame = GetFrame();
auto nui = frame.uimode;
switch (nui) {
case eUiMain:
var_window->SetMode(Window_VarList::eNone);
Expand All @@ -328,13 +345,12 @@ void Scene_Debug::Pop() {
break;
case eUiRangeList:
range_window->SetActive(true);
range_index = (GetFrame().value % 100) / 10;
range_page = GetFrame().value / 100;
RestoreRangeSelectionFromSelectedValue(frame.value);
range_window->SetIndex(range_index);
break;
case eUiVarList:
var_window->SetActive(true);
var_window->SetIndex((GetFrame().value - 1) % 10);
var_window->SetIndex((frame.value - 1) % 10);
break;
case eUiNumberInput:
numberinput_window->SetNumber(GetFrame().value);
Expand All @@ -347,7 +363,7 @@ void Scene_Debug::Pop() {
break;
case eUiInterpreterView:
interpreter_window->SetActive(true);
interpreter_window->SetIndex((GetFrame().value - 1) % 10);
numberinput_window->SetNumber(frame.value);
var_window->SetVisible(false);
interpreter_window->SetVisible(true);
break;
Expand All @@ -358,15 +374,15 @@ void Scene_Debug::Pop() {
}

UpdateRangeListWindow();
var_window->Refresh();
interpreter_window->Refresh();
RefreshDetailWindow();
}

void Scene_Debug::vUpdate() {
range_window->Update();
if (range_index != range_window->GetIndex()){
range_index = range_window->GetIndex();
UpdateDetailWindow();
RefreshDetailWindow();
}
var_window->Update();

Expand All @@ -387,7 +403,7 @@ void Scene_Debug::vUpdate() {
UpdateFrameValueFromUi();
if (mode == eMain) {
auto next_mode = static_cast<Mode>(range_window->GetIndex() + range_page * 10 + 1);
if (next_mode > eMain && next_mode < eLastMainMenuOption) {
if (next_mode > eMain && next_mode <= GetNumMainMenuItems()) {
if (!range_window->IsItemEnabled(range_window->GetIndex())) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
} else {
Expand Down Expand Up @@ -587,6 +603,7 @@ void Scene_Debug::vUpdate() {
}
if (range_page != range_page_prev) {
UpdateDetailWindow();
RefreshDetailWindow();
UpdateRangeListWindow();
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
}
Expand All @@ -599,8 +616,9 @@ void Scene_Debug::vUpdate() {
}
if (range_page != range_page_prev) {
UpdateDetailWindow();
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
RefreshDetailWindow();
UpdateRangeListWindow();
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
}
}

Expand Down Expand Up @@ -778,9 +796,15 @@ void Scene_Debug::UpdateRangeListWindow() {
void Scene_Debug::UpdateDetailWindow() {
if (mode != eInterpreter) {
var_window->UpdateList(GetSelectedIndexFromRange());
var_window->Refresh();
} else {
UpdateInterpreterWindow(GetSelectedIndexFromRange());
}
}

void Scene_Debug::RefreshDetailWindow() {
if (mode != eInterpreter) {
var_window->Refresh();
} else {
interpreter_window->Refresh();
}
}
Expand Down Expand Up @@ -885,7 +909,7 @@ void Scene_Debug::DoSwitch() {
Main_Data::game_switches->Flip(sw_id);
Game_Map::SetNeedRefresh(true);

var_window->Refresh();
RefreshDetailWindow();
}
}

Expand Down Expand Up @@ -1142,7 +1166,7 @@ void Scene_Debug::UpdateInterpreterWindow(int index) {

if (valid) {
interpreter_window->SetStackState(index > interpreters_ev.size(), first_line, state);
} else if (interpreter_window->GetContents()) {
interpreter_window->GetContents()->Clear();
} else {
interpreter_window->SetStackState(0, "", {});
}
}
5 changes: 4 additions & 1 deletion src/scene_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ class Scene_Debug : public Scene {
/** Get the last page for the current mode */
int GetLastPage();

/* Get the first item number for the selected range */
/** Get the first item number for the selected range */
int GetSelectedIndexFromRange() const;

void RestoreRangeSelectionFromSelectedValue(int value);

int GetNumMainMenuItems() const;

void DoSwitch();
Expand Down Expand Up @@ -166,6 +168,7 @@ class Scene_Debug : public Scene {
Window_VarList::Mode GetWindowMode() const;
void UpdateFrameValueFromUi();
void UpdateDetailWindow();
void RefreshDetailWindow();

bool IsValidMapId(int map_id) const;

Expand Down
8 changes: 8 additions & 0 deletions src/window_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ void Window_Interpreter::Refresh() {

CreateContents();
contents->Clear();

if (!IsValid())
return;

DrawDescriptionLines();

for (int i = 0; i < stack_display_items.size(); ++i) {
DrawStackLine(i);
}
}

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

void Window_Interpreter::Update() {
Window_Selectable::Update();
}
Expand Down
1 change: 1 addition & 0 deletions src/window_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Window_Interpreter : public Window_Selectable {

void SetStackState(bool is_ce, std::string interpreter_desc, lcf::rpg::SaveEventExecState state);
void Refresh();
bool IsValid();
protected:
void DrawDescriptionLines();
void DrawStackLine(int index);
Expand Down

0 comments on commit 64475dc

Please sign in to comment.