4545#include " baseui.h"
4646#include < lcf/reader_util.h>
4747
48+ Scene_Title::CommandOptionType Scene_Title::force_cursor_index = Scene_Title::CommandOption_None;
49+
4850Scene_Title::Scene_Title () {
4951 type = Scene::Title;
5052}
@@ -108,7 +110,7 @@ void Scene_Title::Continue(SceneType prev_scene) {
108110}
109111
110112void Scene_Title::TransitionIn (SceneType prev_scene) {
111- if (Game_Battle::battle_test.enabled || ! Check2k3ShowTitle () || Player::game_config. new_game . Get ())
113+ if (Game_Battle::battle_test.enabled || CheckStartNewGame ())
112114 return ;
113115
114116 if (prev_scene == Scene::Load || Player::hide_title_flag) {
@@ -133,7 +135,7 @@ void Scene_Title::vUpdate() {
133135 return ;
134136 }
135137
136- if (! Check2k3ShowTitle () || Player::game_config. new_game . Get ()) {
138+ if (CheckStartNewGame ()) {
137139 Player::SetupNewGame ();
138140 if (Player::debug_flag && Player::hide_title_flag) {
139141 Scene::Push (std::make_shared<Scene_Load>());
@@ -170,12 +172,26 @@ void Scene_Title::vUpdate() {
170172void Scene_Title::Refresh () {
171173 // Enable load game if available
172174 continue_enabled = FileFinder::HasSavegame ();
173- if (continue_enabled) {
175+
176+ if (force_cursor_index != CommandOption_None) {
177+ if (auto idx = GetCommandIndex (force_cursor_index); idx != -1 ) {
178+ command_window->SetIndex (idx);
179+ }
180+ force_cursor_index = CommandOption_None;
181+ } else if (continue_enabled) {
174182 command_window->SetIndex (1 );
175183 }
176184 command_window->SetItemEnabled (1 , continue_enabled);
177185}
178186
187+ int Scene_Title::GetCommandIndex (CommandOptionType cmd) const {
188+ auto it = std::find (command_options.begin (), command_options.end (), cmd);
189+ if (it != command_options.end ()) {
190+ return (it - command_options.begin ());
191+ }
192+ return -1 ;
193+ }
194+
179195void Scene_Title::OnTranslationChanged () {
180196 Start ();
181197
@@ -211,35 +227,59 @@ void Scene_Title::RepositionWindow(Window_Command& window, bool center_vertical)
211227void Scene_Title::CreateCommandWindow () {
212228 // Create Options Window
213229 std::vector<std::string> options;
214- options. push_back ( ToString (lcf::Data::terms. new_game ));
215- options. push_back ( ToString (lcf::Data::terms. load_game )) ;
230+
231+ using Cmd = CommandOptionType ;
216232
217233 // Reset index to fix issues on reuse.
218234 indices = CommandIndices ();
219235
236+ command_options.push_back (Cmd::NewGame);
237+ command_options.push_back (Cmd::ContinueGame);
238+
220239 // Set "Import" based on metadata
221240 if (Player::meta->IsImportEnabled ()) {
222- options.push_back (Player::meta->GetExVocabImportSaveTitleText ());
223- indices.import = indices.exit ;
224- indices.exit ++;
241+ command_options.push_back (Cmd::Import);
225242 }
226-
227243 // Set "Settings" based on the configuration
228244 if (Player::player_config.settings_in_title .Get ()) {
229- // FIXME: Translation? Not shown by default though
230- options.push_back (" Settings" );
231- indices.settings = indices.exit ;
232- indices.exit ++;
245+ command_options.push_back (Cmd::Settings);
233246 }
234-
235247 // Set "Translate" based on metadata
236248 if (Player::translation.HasTranslations () && Player::player_config.lang_select_in_title .Get ()) {
237- options.push_back (Player::meta->GetExVocabTranslateTitleText ());
238- indices.translate = indices.exit ;
239- indices.exit ++;
249+ command_options.push_back (Cmd::Translate);
240250 }
241251
242- options.push_back (ToString (lcf::Data::terms.exit_game ));
252+ command_options.push_back (Cmd::Exit);
253+
254+ for (int i = 0 ; i < command_options.size (); ++i) {
255+ switch (command_options[i]) {
256+ case Cmd::NewGame:
257+ indices.new_game = i;
258+ options.push_back (ToString (lcf::Data::terms.new_game ));
259+ break ;
260+ case Cmd::ContinueGame:
261+ indices.continue_game = i;
262+ options.push_back (ToString (lcf::Data::terms.load_game ));
263+ break ;
264+ case Cmd::Import:
265+ indices.import = i;
266+ options.push_back (Player::meta->GetExVocabImportSaveTitleText ());
267+ break ;
268+ case Cmd::Settings:
269+ indices.settings = i;
270+ // FIXME: Translation? Not shown by default though
271+ options.push_back (" Settings" );
272+ break ;
273+ case Cmd::Translate:
274+ indices.translate = i;
275+ options.push_back (Player::meta->GetExVocabTranslateTitleText ());
276+ break ;
277+ case Cmd::Exit:
278+ indices.exit = i;
279+ options.push_back (ToString (lcf::Data::terms.exit_game ));
280+ break ;
281+ }
282+ }
243283
244284 command_window.reset (new Window_Command (options));
245285 RepositionWindow (*command_window, Player::hide_title_flag);
@@ -267,7 +307,7 @@ void Scene_Title::PlayTitleMusic() {
267307
268308bool Scene_Title::CheckEnableTitleGraphicAndMusic () {
269309 return Check2k3ShowTitle () &&
270- !Player::game_config. new_game . Get () &&
310+ !CheckStartNewGame () &&
271311 !Game_Battle::battle_test.enabled &&
272312 !Player::hide_title_flag;
273313}
@@ -280,6 +320,10 @@ bool Scene_Title::CheckValidPlayerLocation() {
280320 return (lcf::Data::treemap.start .party_map_id > 0 );
281321}
282322
323+ bool Scene_Title::CheckStartNewGame () {
324+ return !Check2k3ShowTitle () || Player::game_config.new_game .Get ();
325+ }
326+
283327void Scene_Title::CommandNewGame () {
284328 if (!CheckValidPlayerLocation ()) {
285329 Output::Warning (" The game has no start location set." );
0 commit comments