Skip to content

Commit 80d1f95

Browse files
committed
PPCOMP: Implemented setting of cursor position for subcommands "CallGameMenu" & "CallTitleScreen"
1 parent d2d92eb commit 80d1f95

File tree

6 files changed

+96
-51
lines changed

6 files changed

+96
-51
lines changed

src/game_powerpatch.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "scene_load.h"
2626
#include "scene_save.h"
2727
#include "scene_debug.h"
28+
#include "scene_title.h"
29+
#include "scene_menu.h"
2830
#include "main_data.h"
2931
#include "game_interpreter_map.h"
3032
#include "game_map.h"
@@ -207,14 +209,25 @@ bool Game_PowerPatch::Execute(PPC_CommandType command, Span<std::string const> a
207209
Scene::instance->SetRequestedScene(std::make_shared<Scene_Save>());
208210
break;
209211
case Type::CallGameMenu: {
210-
int cursor = args.size() >= 1 ? atoi(args[0].c_str()) : 0;
211-
//TODO: implement cursor
212-
Game_Map::GetInterpreter().RequestMainMenuScene();
212+
if (args.size() >= 1) {
213+
if (atoi(args[0].c_str())) {
214+
Scene_Menu::force_cursor_index = Scene_Menu::CommandOptionType::Save;
215+
} else {
216+
Scene_Menu::force_cursor_index = Scene_Menu::CommandOptionType::Item;
217+
}
218+
}
219+
Scene::instance->SetRequestedScene(std::make_shared<Scene_Menu>());
213220
break;
214221
}
215222
case Type::CallTitleScreen: {
216-
int cursor = args.size() >= 1 ? atoi(args[0].c_str()) : 0;
217-
//TODO: implement cursor
223+
if (args.size() >= 1) {
224+
if (atoi(args[0].c_str())) {
225+
Scene_Title::force_cursor_index = Scene_Title::CommandOptionType::ContinueGame;
226+
} else {
227+
Scene_Title::force_cursor_index = Scene_Title::CommandOptionType::NewGame;
228+
}
229+
}
230+
Player::force_make_to_title_flag = true;
218231
async_op = AsyncOp::MakeToTitle();
219232
break;
220233
}

src/player.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ namespace Player {
136136
int rng_seed = -1;
137137
Game_ConfigPlayer player_config;
138138
Game_ConfigGame game_config;
139+
bool force_make_to_title_flag = false;
139140
#ifdef EMSCRIPTEN
140141
std::string emscripten_game_name;
141142
#endif

src/player.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ namespace Player {
415415
/** Translation manager, including list of languages and current translation. */
416416
extern Translation translation;
417417

418+
/** If true, the game will be forced to stay at the title scene, even if the "new_game" option is set. */
419+
extern bool force_make_to_title_flag;
420+
418421
/**
419422
* The default speed modifier applied when the speed up button is pressed
420423
* Only used for configuring the speedup, don't read this var directly use

src/scene_menu.cpp

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ constexpr int menu_command_width = 88;
4040
constexpr int gold_window_width = 88;
4141
constexpr int gold_window_height = 32;
4242

43+
Scene_Menu::CommandOptionType Scene_Menu::force_cursor_index = Scene_Menu::CommandOption_None;
44+
4345
Scene_Menu::Scene_Menu(int menu_index) :
4446
menu_index(menu_index) {
4547
type = Scene::Menu;
@@ -78,28 +80,30 @@ void Scene_Menu::CreateCommandWindow() {
7880
// Create Options Window
7981
std::vector<std::string> options;
8082

83+
using Cmd = CommandOptionType;
84+
8185
if (Player::IsRPG2k()) {
82-
command_options.push_back(Item);
83-
command_options.push_back(Skill);
84-
command_options.push_back(Equipment);
85-
command_options.push_back(Save);
86+
command_options.push_back(Cmd::Item);
87+
command_options.push_back(Cmd::Skill);
88+
command_options.push_back(Cmd::Equipment);
89+
command_options.push_back(Cmd::Save);
8690
if (Player::player_config.settings_in_menu.Get()) {
87-
command_options.push_back(Settings);
91+
command_options.push_back(Cmd::Settings);
8892
}
8993
if (Player::debug_flag) {
90-
command_options.push_back(Debug);
94+
command_options.push_back(Cmd::Debug);
9195
}
92-
command_options.push_back(Quit);
96+
command_options.push_back(Cmd::Quit);
9397
} else {
9498
for (std::vector<int16_t>::iterator it = lcf::Data::system.menu_commands.begin();
9599
it != lcf::Data::system.menu_commands.end(); ++it) {
96100
switch (*it) {
97-
case Row:
101+
case static_cast<int>(Cmd::Row):
98102
if (Feature::HasRow()) {
99103
command_options.push_back((CommandOptionType)*it);
100104
}
101105
break;
102-
case Wait:
106+
case static_cast<int>(Cmd::Wait):
103107
if (Feature::HasRpg2k3BattleSystem()) {
104108
command_options.push_back((CommandOptionType)*it);
105109
}
@@ -110,46 +114,46 @@ void Scene_Menu::CreateCommandWindow() {
110114
}
111115
}
112116
if (Player::player_config.settings_in_menu.Get()) {
113-
command_options.push_back(Settings);
117+
command_options.push_back(Cmd::Settings);
114118
}
115119
if (Player::debug_flag) {
116-
command_options.push_back(Debug);
120+
command_options.push_back(Cmd::Debug);
117121
}
118-
command_options.push_back(Quit);
122+
command_options.push_back(Cmd::Quit);
119123
}
120124

121125
// Add all menu items
122126
std::vector<CommandOptionType>::iterator it;
123127
for (it = command_options.begin(); it != command_options.end(); ++it) {
124128
switch(*it) {
125-
case Item:
129+
case Cmd::Item:
126130
options.push_back(ToString(lcf::Data::terms.command_item));
127131
break;
128-
case Skill:
132+
case Cmd::Skill:
129133
options.push_back(ToString(lcf::Data::terms.command_skill));
130134
break;
131-
case Equipment:
135+
case Cmd::Equipment:
132136
options.push_back(ToString(lcf::Data::terms.menu_equipment));
133137
break;
134-
case Save:
138+
case Cmd::Save:
135139
options.push_back(ToString(lcf::Data::terms.menu_save));
136140
break;
137-
case Status:
141+
case Cmd::Status:
138142
options.push_back(ToString(lcf::Data::terms.status));
139143
break;
140-
case Row:
144+
case Cmd::Row:
141145
options.push_back(ToString(lcf::Data::terms.row));
142146
break;
143-
case Order:
147+
case Cmd::Order:
144148
options.push_back(ToString(lcf::Data::terms.order));
145149
break;
146-
case Wait:
150+
case Cmd::Wait:
147151
options.push_back(ToString(Main_Data::game_system->GetAtbMode() == lcf::rpg::SaveSystem::AtbMode_atb_wait ? lcf::Data::terms.wait_on : lcf::Data::terms.wait_off));
148152
break;
149-
case Settings:
153+
case Cmd::Settings:
150154
options.push_back("Settings");
151155
break;
152-
case Debug:
156+
case Cmd::Debug:
153157
options.push_back("Debug");
154158
break;
155159
default:
@@ -161,22 +165,30 @@ void Scene_Menu::CreateCommandWindow() {
161165
command_window.reset(new Window_Command(options, menu_command_width));
162166
command_window->SetX(Player::menu_offset_x);
163167
command_window->SetY(Player::menu_offset_y);
164-
command_window->SetIndex(menu_index);
168+
169+
if (force_cursor_index != CommandOption_None) {
170+
if (auto idx = GetCommandIndex(force_cursor_index); idx != -1) {
171+
command_window->SetIndex(idx);
172+
}
173+
force_cursor_index = CommandOption_None;
174+
} else {
175+
command_window->SetIndex(menu_index);
176+
}
165177

166178
// Disable items
167179
for (it = command_options.begin(); it != command_options.end(); ++it) {
168180
switch(*it) {
169-
case Save:
181+
case Cmd::Save:
170182
// If save is forbidden disable this item
171183
if (!Main_Data::game_system->GetAllowSave()) {
172184
command_window->DisableItem(it - command_options.begin());
173185
}
174-
case Wait:
175-
case Quit:
176-
case Settings:
177-
case Debug:
186+
case Cmd::Wait:
187+
case Cmd::Quit:
188+
case Cmd::Settings:
189+
case Cmd::Debug:
178190
break;
179-
case Order:
191+
case Cmd::Order:
180192
if (Main_Data::game_party->GetActors().size() <= 1) {
181193
command_window->DisableItem(it - command_options.begin());
182194
}
@@ -191,25 +203,26 @@ void Scene_Menu::CreateCommandWindow() {
191203
}
192204

193205
void Scene_Menu::UpdateCommand() {
206+
using Cmd = CommandOptionType;
194207
if (Input::IsTriggered(Input::CANCEL)) {
195208
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cancel));
196209
Scene::Pop();
197210
} else if (Input::IsTriggered(Input::DECISION)) {
198211
menu_index = command_window->GetIndex();
199212

200213
switch (command_options[menu_index]) {
201-
case Item:
214+
case Cmd::Item:
202215
if (Main_Data::game_party->GetActors().empty()) {
203216
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
204217
} else {
205218
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
206219
Scene::Push(std::make_shared<Scene_Item>());
207220
}
208221
break;
209-
case Skill:
210-
case Equipment:
211-
case Status:
212-
case Row:
222+
case Cmd::Skill:
223+
case Cmd::Equipment:
224+
case Cmd::Status:
225+
case Cmd::Row:
213226
if (Main_Data::game_party->GetActors().empty()) {
214227
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
215228
} else {
@@ -219,37 +232,37 @@ void Scene_Menu::UpdateCommand() {
219232
menustatus_window->SetIndex(0);
220233
}
221234
break;
222-
case Save:
235+
case Cmd::Save:
223236
if (!Main_Data::game_system->GetAllowSave()) {
224237
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
225238
} else {
226239
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
227240
Scene::Push(std::make_shared<Scene_Save>());
228241
}
229242
break;
230-
case Order:
243+
case Cmd::Order:
231244
if (Main_Data::game_party->GetActors().size() <= 1) {
232245
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
233246
} else {
234247
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
235248
Scene::Push(std::make_shared<Scene_Order>());
236249
}
237250
break;
238-
case Wait:
251+
case Cmd::Wait:
239252
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
240253
Main_Data::game_system->ToggleAtbMode();
241254
command_window->SetItemText(menu_index,
242255
Main_Data::game_system->GetAtbMode() == lcf::rpg::SaveSystem::AtbMode_atb_wait ? lcf::Data::terms.wait_on : lcf::Data::terms.wait_off);
243256
break;
244-
case Settings:
257+
case Cmd::Settings:
245258
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Game_System::SFX_Decision));
246259
Scene::Push(std::make_shared<Scene_Settings>());
247260
break;
248-
case Debug:
261+
case Cmd::Debug:
249262
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
250263
Scene::Push(std::make_shared<Scene_Debug>());
251264
break;
252-
case Quit:
265+
case Cmd::Quit:
253266
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
254267
Scene::Push(std::make_shared<Scene_End>());
255268
break;
@@ -258,30 +271,31 @@ void Scene_Menu::UpdateCommand() {
258271
}
259272

260273
void Scene_Menu::UpdateActorSelection() {
274+
using Cmd = CommandOptionType;
261275
if (Input::IsTriggered(Input::CANCEL)) {
262276
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cancel));
263277
command_window->SetActive(true);
264278
menustatus_window->SetActive(false);
265279
menustatus_window->SetIndex(-1);
266280
} else if (Input::IsTriggered(Input::DECISION)) {
267281
switch (command_options[command_window->GetIndex()]) {
268-
case Skill:
282+
case Cmd::Skill:
269283
if (!menustatus_window->GetActor()->CanAct()) {
270284
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
271285
return;
272286
}
273287
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
274288
Scene::Push(std::make_shared<Scene_Skill>(Main_Data::game_party->GetActors(), menustatus_window->GetIndex()));
275289
break;
276-
case Equipment:
290+
case Cmd::Equipment:
277291
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
278292
Scene::Push(std::make_shared<Scene_Equip>(Main_Data::game_party->GetActors(), menustatus_window->GetIndex()));
279293
break;
280-
case Status:
294+
case Cmd::Status:
281295
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
282296
Scene::Push(std::make_shared<Scene_Status>(Main_Data::game_party->GetActors(), menustatus_window->GetIndex()));
283297
break;
284-
case Row:
298+
case Cmd::Row:
285299
{
286300
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
287301
// Don't allow entire party in the back row.
@@ -313,3 +327,11 @@ void Scene_Menu::UpdateActorSelection() {
313327
menustatus_window->SetIndex(-1);
314328
}
315329
}
330+
331+
int Scene_Menu::GetCommandIndex(CommandOptionType cmd) const {
332+
auto it = std::find(command_options.begin(), command_options.end(), cmd);
333+
if (it != command_options.end()) {
334+
return (it - command_options.begin());
335+
}
336+
return -1;
337+
}

src/scene_menu.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Scene_Menu : public Scene {
5656
void UpdateActorSelection();
5757

5858
/** Options available in a Rpg2k3 menu. */
59-
enum CommandOptionType {
59+
enum class CommandOptionType {
6060
Item = 1,
6161
Skill,
6262
Equipment,
@@ -71,6 +71,11 @@ class Scene_Menu : public Scene {
7171
Settings = 101,
7272
};
7373

74+
int GetCommandIndex(CommandOptionType cmd) const;
75+
76+
static const CommandOptionType CommandOption_None = static_cast<CommandOptionType>(0);
77+
static CommandOptionType force_cursor_index;
78+
7479
private:
7580
/** Selected index on startup. */
7681
int menu_index;

src/scene_title.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool Scene_Title::CheckValidPlayerLocation() {
321321
}
322322

323323
bool Scene_Title::CheckStartNewGame() {
324-
return !Check2k3ShowTitle() || Player::game_config.new_game.Get();
324+
return (!Check2k3ShowTitle() || Player::game_config.new_game.Get()) && !Player::force_make_to_title_flag;
325325
}
326326

327327
void Scene_Title::CommandNewGame() {
@@ -385,4 +385,5 @@ void Scene_Title::OnTitleSpriteReady(FileRequestResult* result) {
385385

386386
void Scene_Title::OnGameStart() {
387387
restart_title_cache = true;
388+
Player::force_make_to_title_flag = false;
388389
}

0 commit comments

Comments
 (0)