Fixed prefs save/load

This commit is contained in:
simon.kagstrom 2009-01-10 09:32:58 +00:00
parent dc6d9aab2b
commit 56dc7b62ab
3 changed files with 41 additions and 20 deletions

View File

@ -1,4 +1,5 @@
version 2: version 2:
* Fixed some corner-cases in the prefs setting to avoid loosing key bindings etc
* Improve keyboard bindings to handle press and release correctly and also * Improve keyboard bindings to handle press and release correctly and also
both controllers at the same time (key is released when the last controller releases both controllers at the same time (key is released when the last controller releases
it) it)

View File

@ -166,6 +166,8 @@ public:
int fake_key_index; int fake_key_index;
int fake_key_keytime; int fake_key_keytime;
bool prefs_changed;
void select_disc(Prefs *np); void select_disc(Prefs *np);
void bind_key(Prefs *np); void bind_key(Prefs *np);
void display_options(Prefs *np); void display_options(Prefs *np);

View File

@ -77,6 +77,8 @@ void C64::c64_ctor1(void)
this->fake_key_keytime = 5; this->fake_key_keytime = 5;
this->fake_key_type = 0; this->fake_key_type = 0;
this->prefs_changed = false;
MENU_SIZE_X = FULL_DISPLAY_X - FULL_DISPLAY_X / 4; MENU_SIZE_X = FULL_DISPLAY_X - FULL_DISPLAY_X / 4;
MENU_SIZE_Y = FULL_DISPLAY_Y - FULL_DISPLAY_Y / 4; MENU_SIZE_Y = FULL_DISPLAY_Y - FULL_DISPLAY_Y / 4;
@ -198,6 +200,7 @@ void C64::select_disc(Prefs *np)
NewPrefs(np); NewPrefs(np);
ThePrefs = *np; ThePrefs = *np;
} }
this->prefs_changed = true;
} }
menu_fini(&select_disc_menu); menu_fini(&select_disc_menu);
@ -253,10 +256,14 @@ void C64::bind_key(Prefs *np)
32, 32, MENU_SIZE_X, MENU_SIZE_Y); 32, 32, MENU_SIZE_X, MENU_SIZE_Y);
int key = menu_select(real_screen, &key_menu, NULL); int key = menu_select(real_screen, &key_menu, NULL);
/* Assume prefs are changed */
this->prefs_changed = true;
if (key > 0) if (key > 0)
np->JoystickKeyBinding[opt] = kcs[key]; np->JoystickKeyBinding[opt] = kcs[key];
else if (key == 0) else if (key == 0)
np->JoystickKeyBinding[opt] = -1; np->JoystickKeyBinding[opt] = -1;
else
this->prefs_changed = false;
menu_fini(&key_menu); menu_fini(&key_menu);
} }
menu_fini(&bind_key_menu); menu_fini(&bind_key_menu);
@ -270,16 +277,19 @@ void C64::display_options(Prefs *np)
32, 32, MENU_SIZE_X, MENU_SIZE_Y); 32, 32, MENU_SIZE_X, MENU_SIZE_Y);
int opt = menu_select(real_screen, &display_menu, NULL); int opt = menu_select(real_screen, &display_menu, NULL);
if (opt >= 0) if (opt >= 0)
{
np->DisplayOption = opt; np->DisplayOption = opt;
this->prefs_changed = true;
}
menu_fini(&display_menu); menu_fini(&display_menu);
} }
void C64::save_load_state(Prefs *np) void C64::save_load_state(Prefs *np)
{ {
menu_t save_load_menu; menu_t save_load_menu;
menu_t select_saves_menu; menu_t select_saves_menu;
menu_init(&save_load_menu, this->menu_font, save_load_state_messages, menu_init(&save_load_menu, this->menu_font, save_load_state_messages,
32, 32, MENU_SIZE_X, MENU_SIZE_Y); 32, 32, MENU_SIZE_X, MENU_SIZE_Y);
int opt = menu_select(real_screen, &save_load_menu, NULL); int opt = menu_select(real_screen, &save_load_menu, NULL);
switch(opt) switch(opt)
@ -320,17 +330,17 @@ void C64::save_load_state(Prefs *np)
else /* Load the snapshot */ else /* Load the snapshot */
this->LoadSnapshot(buf); this->LoadSnapshot(buf);
} }
menu_fini(&select_saves_menu); menu_fini(&select_saves_menu);
/* Cleanup everything */ /* Cleanup everything */
for ( int i = 0; file_list[i]; i++ ) for ( int i = 0; file_list[i]; i++ )
free((void*)file_list[i]); free((void*)file_list[i]);
free(file_list); free(file_list);
} break; } break;
default: default:
break; break;
} }
menu_fini(&save_load_menu); menu_fini(&save_load_menu);
} }
/* /*
@ -440,17 +450,19 @@ void C64::VBlank(bool draw_frame)
if (this->have_a_break) { if (this->have_a_break) {
int submenus[1]; int submenus[1];
int opt; int opt;
int old_swap = ThePrefs.JoystickSwap == true ? 1 : 0;
Prefs *np = Frodo::reload_prefs(); Prefs np = ThePrefs;
this->prefs_changed = false;
TheSID->PauseSound(); TheSID->PauseSound();
submenus[0] = np->JoystickSwap == true ? 1 : 0; submenus[0] = old_swap;
opt = menu_select(real_screen, &this->main_menu, submenus); opt = menu_select(real_screen, &this->main_menu, submenus);
switch(opt) switch(opt)
{ {
case 0: /* Insert disc/tape */ case 0: /* Insert disc/tape */
this->select_disc(np); this->select_disc(&np);
break; break;
case 1: /* Load disc/tape */ case 1: /* Load disc/tape */
this->fake_key_sequence = true; this->fake_key_sequence = true;
@ -459,15 +471,15 @@ void C64::VBlank(bool draw_frame)
Reset(); Reset();
break; break;
case 3: /* Bind keys to joystick */ case 3: /* Bind keys to joystick */
this->bind_key(np); this->bind_key(&np);
break; break;
case 4: /* Display options */ case 4: /* Display options */
this->display_options(np); this->display_options(&np);
break; break;
case 5: /* Swap joysticks */ case 5: /* Swap joysticks */
break; break;
case 7: /* Save / load game */ case 7: /* Save / load game */
this->save_load_state(np); this->save_load_state(&np);
break; break;
case 9: /* Quit */ case 9: /* Quit */
quit_thyself = true; quit_thyself = true;
@ -477,17 +489,23 @@ void C64::VBlank(bool draw_frame)
break; break;
} }
if (submenus[0] == 0) if (submenus[0] == 0)
np->JoystickSwap = false; np.JoystickSwap = false;
else else
np->JoystickSwap = true; np.JoystickSwap = true;
if (submenus[0] != old_swap)
this->prefs_changed = true;
this->NewPrefs(np); if (this->prefs_changed)
ThePrefs = *np; {
ThePrefs.Save(PREFS_PATH); this->NewPrefs(&np);
ThePrefs = np;
}
TheDisplay->FakeKeyPress(-1, false, TheCIA1->KeyMatrix, TheDisplay->FakeKeyPress(-1, false, TheCIA1->KeyMatrix,
TheCIA1->RevMatrix); TheCIA1->RevMatrix);
this->have_a_break = false; this->have_a_break = false;
if (this->quit_thyself)
ThePrefs.Save(PREFS_PATH);
} }
/* From Acorn port */ /* From Acorn port */
static uint64_t lastFrame; static uint64_t lastFrame;