diff options
| author | Simon Tatham <anakin@pobox.com> | 2017-04-24 16:00:24 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2017-04-26 21:51:23 +0100 |
| commit | a7dc17c4258837b0ee3927f1db5e1c02acee5cc3 (patch) | |
| tree | 731c1ac2fe23e9f42d857ad48eaefd1b0c14e44e /emcc.c | |
| parent | bc2c1f69fddac3a51d086fb379f0ec8954f4b894 (diff) | |
| download | puzzles-a7dc17c4258837b0ee3927f1db5e1c02acee5cc3.zip puzzles-a7dc17c4258837b0ee3927f1db5e1c02acee5cc3.tar.gz puzzles-a7dc17c4258837b0ee3927f1db5e1c02acee5cc3.tar.bz2 puzzles-a7dc17c4258837b0ee3927f1db5e1c02acee5cc3.tar.xz | |
Rework the preset menu system to permit submenus.
To do this, I've completely replaced the API between mid-end and front
end, so any downstream front end maintainers will have to do some
rewriting of their own (sorry). I've done the necessary work in all
five of the front ends I keep in-tree here - Windows, GTK, OS X,
Javascript/Emscripten, and Java/NestedVM - and I've done it in various
different styles (as each front end found most convenient), so that
should provide a variety of sample code to show downstreams how, if
they should need it.
I've left in the old puzzle back-end API function to return a flat
list of presets, so for the moment, all the puzzle backends are
unchanged apart from an extra null pointer appearing in their
top-level game structure. In a future commit I'll actually use the new
feature in a puzzle; perhaps in the further future it might make sense
to migrate all the puzzles to the new API and stop providing back ends
with two alternative ways of doing things, but this seemed like enough
upheaval for one day.
Diffstat (limited to 'emcc.c')
| -rw-r--r-- | emcc.c | 41 |
1 files changed, 25 insertions, 16 deletions
@@ -61,7 +61,8 @@ extern void js_debug(const char *); extern void js_error_box(const char *message); extern void js_remove_type_dropdown(void); extern void js_remove_solve_button(void); -extern void js_add_preset(const char *name); +extern void js_add_preset(int menuid, const char *name, int value); +extern int js_add_preset_submenu(int menuid, const char *name); extern int js_get_selected_preset(void); extern void js_select_preset(int n); extern void js_get_date_64(unsigned *p); @@ -552,6 +553,21 @@ static game_params **presets; static int npresets; int have_presets_dropdown; +void populate_js_preset_menu(int menuid, struct preset_menu *menu) +{ + int i; + for (i = 0; i < menu->n_entries; i++) { + struct preset_menu_entry *entry = &menu->entries[i]; + if (entry->params) { + presets[entry->id] = entry->params; + js_add_preset(menuid, entry->title, entry->id); + } else { + int js_submenu = js_add_preset_submenu(menuid, entry->title); + populate_js_preset_menu(js_submenu, entry->submenu); + } + } +} + void select_appropriate_preset(void) { if (have_presets_dropdown) { @@ -787,23 +803,16 @@ int main(int argc, char **argv) * Set up the game-type dropdown with presets and/or the Custom * option. */ - npresets = midend_num_presets(me); - if (npresets == 0) { - /* - * This puzzle doesn't have selectable game types at all. - * Completely remove the drop-down list from the page. - */ - js_remove_type_dropdown(); - have_presets_dropdown = FALSE; - } else { + { + struct preset_menu *menu = midend_get_presets(me, &npresets); presets = snewn(npresets, game_params *); - for (i = 0; i < npresets; i++) { - char *name; - midend_fetch_preset(me, i, &name, &presets[i]); - js_add_preset(name); - } + for (i = 0; i < npresets; i++) + presets[i] = NULL; + + populate_js_preset_menu(0, menu); + if (thegame.can_configure) - js_add_preset(NULL); /* the 'Custom' entry in the dropdown */ + js_add_preset(0, "Custom", -1); have_presets_dropdown = TRUE; |