- * Add a preset to the drop-down types menu. The provided text is
- * the name of the preset. (The corresponding game_params stays on
- * the C side and never comes out this far; we just pass a numeric
- * index back to the C code when a selection is made.)
- *
- * The special 'Custom' preset is requested by passing NULL to
- * this function, rather than the string "Custom", since in that
- * case we need to do something special - see below.
- */
- js_add_preset: function(ptr) {
- var name = (ptr == 0 ? "Customise..." : Pointer_stringify(ptr));
- var value = gametypeoptions.length;
-
- var option = document.createElement("option");
- option.value = value;
- option.appendChild(document.createTextNode(name));
- gametypeselector.appendChild(option);
- gametypeoptions.push(option);
-
- if (ptr == 0) {
- // The option we've just created is the one for inventing
- // a new custom setup.
- gametypenewcustom = option;
- option.value = -1;
-
- // Now create another element called 'Custom', which will
- // be auto-selected by us to indicate the custom settings
- // you've previously selected. However, we don't add it to
- // the game type selector; it will only appear when the
- // user actually has custom settings selected.
- option = document.createElement("option");
- option.value = -2;
- option.appendChild(document.createTextNode("Custom"));
- gametypethiscustom = option;
+ * Add a preset to the drop-down types menu, or to a submenu of
+ * it. 'menuid' specifies an index into our array of submenus
+ * where the item might be placed; 'value' specifies the number
+ * that js_get_selected_preset() will return when this item is
+ * clicked.
+ */
+ js_add_preset: function(menuid, ptr, value) {
+ var name = Pointer_stringify(ptr);
+ var item = document.createElement("li");
+ item.setAttribute("data-index", value);
+ var tick = document.createElement("span");
+ tick.appendChild(document.createTextNode("\u2713"));
+ tick.style.color = "transparent";
+ tick.style.paddingRight = "0.5em";
+ item.appendChild(tick);
+ item.appendChild(document.createTextNode(name));
+ gametypesubmenus[menuid].appendChild(item);
+ gametypeitems.push(item);
+
+ item.onclick = function(event) {
+ if (dlg_dimmer === null) {
+ gametypeselectedindex = value;
+ command(2);
+ }