mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
Make sure the right element of the game-type dropdown starts off
selected. Previously we were leaving the first element on the list selected, which is _usually_ right, but not right for Slant. In the process of doing this, I've also reorganised to fix a crash which shows up with non-configurable games (admittedly currently only Nullgame :-) when we still try to call js_select_preset in spite of not having any preset options to select. [originally from svn r9794]
This commit is contained in:
52
emcc.c
52
emcc.c
@ -504,6 +504,15 @@ const struct drawing_api js_drawing = {
|
|||||||
*/
|
*/
|
||||||
static game_params **presets;
|
static game_params **presets;
|
||||||
static int custom_preset;
|
static int custom_preset;
|
||||||
|
int have_presets_dropdown;
|
||||||
|
|
||||||
|
void select_appropriate_preset(void)
|
||||||
|
{
|
||||||
|
if (have_presets_dropdown) {
|
||||||
|
int preset = midend_which_preset(me);
|
||||||
|
js_select_preset(preset < 0 ? custom_preset : preset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static config_item *cfg = NULL;
|
static config_item *cfg = NULL;
|
||||||
static int cfg_which;
|
static int cfg_which;
|
||||||
@ -578,9 +587,7 @@ static void cfg_end(int use_results)
|
|||||||
* New settings are fine; start a new game and close the
|
* New settings are fine; start a new game and close the
|
||||||
* dialog.
|
* dialog.
|
||||||
*/
|
*/
|
||||||
int preset = midend_which_preset(me);
|
select_appropriate_preset();
|
||||||
js_select_preset(preset < 0 ? custom_preset : preset);
|
|
||||||
|
|
||||||
midend_new_game(me);
|
midend_new_game(me);
|
||||||
resize();
|
resize();
|
||||||
midend_redraw(me);
|
midend_redraw(me);
|
||||||
@ -602,8 +609,7 @@ static void cfg_end(int use_results)
|
|||||||
* js_add_preset in emcclib.js - so you won't even be able to
|
* js_add_preset in emcclib.js - so you won't even be able to
|
||||||
* select Custom without a faffy workaround.)
|
* select Custom without a faffy workaround.)
|
||||||
*/
|
*/
|
||||||
int preset = midend_which_preset(me);
|
select_appropriate_preset();
|
||||||
js_select_preset(preset < 0 ? custom_preset : preset);
|
|
||||||
|
|
||||||
free_cfg(cfg);
|
free_cfg(cfg);
|
||||||
js_dialog_cleanup();
|
js_dialog_cleanup();
|
||||||
@ -738,16 +744,34 @@ int main(int argc, char **argv)
|
|||||||
* it's selected.
|
* it's selected.
|
||||||
*/
|
*/
|
||||||
custom_preset = midend_num_presets(me);
|
custom_preset = midend_num_presets(me);
|
||||||
presets = snewn(custom_preset, game_params *);
|
if (custom_preset == 0) {
|
||||||
for (i = 0; i < custom_preset; i++) {
|
/*
|
||||||
char *name;
|
* This puzzle doesn't have selectable game types at all.
|
||||||
midend_fetch_preset(me, i, &name, &presets[i]);
|
* Completely remove the drop-down list from the page.
|
||||||
js_add_preset(name);
|
*/
|
||||||
}
|
|
||||||
if (thegame.can_configure)
|
|
||||||
js_add_preset(NULL); /* the 'Custom' entry in the dropdown */
|
|
||||||
else if (custom_preset == 0)
|
|
||||||
js_remove_type_dropdown();
|
js_remove_type_dropdown();
|
||||||
|
have_presets_dropdown = FALSE;
|
||||||
|
} else {
|
||||||
|
int preset;
|
||||||
|
|
||||||
|
presets = snewn(custom_preset, game_params *);
|
||||||
|
for (i = 0; i < custom_preset; i++) {
|
||||||
|
char *name;
|
||||||
|
midend_fetch_preset(me, i, &name, &presets[i]);
|
||||||
|
js_add_preset(name);
|
||||||
|
}
|
||||||
|
if (thegame.can_configure)
|
||||||
|
js_add_preset(NULL); /* the 'Custom' entry in the dropdown */
|
||||||
|
|
||||||
|
have_presets_dropdown = TRUE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now ensure the appropriate element of the presets menu
|
||||||
|
* starts off selected, in case it isn't the first one in the
|
||||||
|
* list (e.g. Slant).
|
||||||
|
*/
|
||||||
|
select_appropriate_preset();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove the Solve button if the game doesn't support it.
|
* Remove the Solve button if the game doesn't support it.
|
||||||
|
Reference in New Issue
Block a user