- * 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 ? "Custom" : 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) {
- // Create a _second_ element called 'Custom', which is
- // hidden.
- //
- // Hiding this element (that is, setting it display:none)
- // has the effect of making it not show up when the
- // drop-down list is actually opened, but still show up
- // when the item is selected.
- //
- // So what happens is that there's one element marked
- // 'Custom' that the _user_ selects, but a second one to
- // which we reset the dropdown after the config box
- // returns (if we don't then turn out to select a
- // different preset anyway). The point is that if the user
- // has 'Custom' selected, but then wants to customise
- // their settings a second time, we still get an onchange
- // event when they select the Custom option again, which
- // we wouldn't get if the browser thought it was already
- // the selected one. But here, it's _not_ the selected
- // option already; its invisible evil twin is selected.
- option = document.createElement("option");
- option.value = value;
- option.appendChild(document.createTextNode(name));
- option.style.display = "none";
- gametypeselector.appendChild(option);
- gametypehiddencustom = 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);
+ }