]> granicus.if.org Git - nethack/commitdiff
centralize the invert decision logic to avoid updates to 7 ports
authornhmall <nhmall@nethack.org>
Tue, 24 Dec 2019 02:44:34 +0000 (21:44 -0500)
committernhmall <nhmall@nethack.org>
Tue, 24 Dec 2019 02:44:34 +0000 (21:44 -0500)
This will make it easier to tinker for best results.

include/extern.h
include/flag.h
src/mapglyph.c
src/options.c
win/Qt/qt_menu.cpp
win/X11/winmenu.c
win/curses/cursdial.c
win/gem/wingem1.c
win/tty/wintty.c
win/win32/mhmenu.c

index 8c5a2cbd282b04abe06f5c3c16d1722cb710c71f..2d7947e6284a6bfce6fa451a773733f961bfb1c3 100644 (file)
@@ -1217,6 +1217,7 @@ E int FDECL(mapglyph, (int, int *, int *, unsigned *, int, int, unsigned));
 E char *FDECL(encglyph, (int));
 E char *FDECL(decode_mixed, (char *, const char *));
 E void FDECL(genl_putmixed, (winid, int, const char *));
+E boolean FDECL(menuitem_invert_test, (int, unsigned, BOOLEAN_P));
 
 /* ### mcastu.c ### */
 
index e1091a562b3ffa74a716e99924ea459e469971d8..446f15e5df2d1a82a298c2f4928c7a05051a8f85 100644 (file)
@@ -243,6 +243,8 @@ struct instance_flags {
      */
     unsigned msg_history; /* hint: # of top lines to save */
     int getpos_coords;    /* show coordinates when getting cursor position */
+    int menuinvertmode;  /* 0 = invert toggles every item;
+                            1 = invert skips 'all items' item */
     int menu_headings;    /* ATR for menu headings */
     int *opt_booldup;     /* for duplication of boolean opts in config file */
     int *opt_compdup;     /* for duplication of compound opts in conf file */
index 74492cc74b4ffd022d4fa0c77c0b36bec2d32d0d..59d01010b85ea346ee8ca05a1dc5acf97c3c22e3 100644 (file)
@@ -438,4 +438,26 @@ const char *str;
     putstr(window, attr, decode_mixed(buf, str));
 }
 
+/*
+ * Window port helper function for menu invert routines to move the decision
+ * logic into one place instead of 7 different window-port routines.
+ */
+boolean
+menuitem_invert_test(mode, itemflags, is_selected)
+int mode;
+unsigned itemflags;     /* The itemflags for the item               */
+boolean is_selected;    /* The current selection status of the item */
+{
+    boolean skipinvert = (itemflags & MENU_ITEMFLAGS_SKIPINVERT) != 0;
+    
+    if ((iflags.menuinvertmode == 1 || iflags.menuinvertmode == 2)
+        && !mode && skipinvert && !is_selected)
+        return FALSE;
+    else if (iflags.menuinvertmode == 2
+        && !mode && skipinvert && is_selected)
+        return TRUE;
+    else
+        return TRUE;
+}
+
 /*mapglyph.c*/
index df5add42d94fe66e07447232cc974ac5eb514617..253ec29fa04fed30d8f3b0df4602778143139131 100644 (file)
@@ -311,6 +311,7 @@ static struct Comp_Opt {
     { "horsename", "the name of your (first) horse (e.g., horsename:Silver)",
       PL_PSIZ, DISP_IN_GAME },
     { "map_mode", "map display mode under Windows", 20, DISP_IN_GAME }, /*WC*/
+    { "menuinvertmode", "behaviour of menu iverts", 5, SET_IN_GAME },
     { "menustyle", "user interface for object selection", MENUTYPELEN,
       SET_IN_GAME },
     { "menu_deselect_all", "deselect all items in a menu", 4, SET_IN_FILE },
@@ -2362,6 +2363,24 @@ boolean tinitial, tfrom_file;
         return retval;
     }
 
+    /* menuinvertmode=0 or 1 or 2 (2 is experimental) */
+    fullname = "menuinvertmode";
+    if (match_optname(opts, fullname, 5, TRUE)) {
+        if (negated) {
+            bad_negation(fullname, FALSE);
+            return FALSE;
+        } else {
+            int mode = atoi(op);
+
+            if (mode < 0 || mode > 2) {
+                config_error_add("Illegal %s parameter '%s'", fullname, op);
+                return FALSE;
+            }
+            iflags.menuinvertmode = mode;
+       }
+       return retval;
+    }
+
     fullname = "msghistory";
     if (match_optname(opts, fullname, 3, TRUE)) {
         if (duplicate)
@@ -5614,7 +5633,9 @@ char *buf;
                                   : (i == MAP_MODE_ASCII_FIT_TO_SCREEN)
                                     ? "fit_to_screen"
                                     : defopt);
-    } else if (!strcmp(optname, "menustyle"))
+    } else if (!strcmp(optname, "menuinvertmode"))
+        Sprintf(buf, "%d", iflags.menuinvertmode);
+    else if (!strcmp(optname, "menustyle"))
         Sprintf(buf, "%s", menutype[(int) flags.menu_style]);
     else if (!strcmp(optname, "menu_deselect_all"))
         Sprintf(buf, "%s", to_be_done);
index 8be6abaaf9471acc5d90916d7c3b23efe96ca101..b959ad5d0bf49c1d9016cd759a638db86578c865 100644 (file)
@@ -534,7 +534,8 @@ void NetHackQtMenuWindow::Invert()
         return;
 
     for (int i=0; i<itemcount; i++) {
-        if ((itemlist[i].itemflags & MENU_ITEMFLAGS_SKIPINVERT) != 0)
+        if (!menuitem_invert_test(0, itemlist[i].itemflags,
+                                  itemlist[i].selected))
             continue;
 
        QTableWidgetItem *count = table->item(i, 0);
index 36f60829ccae9ca4894f51fec28b5466e89d98cb..9d0e8a4a720c2a3ea8391f836531214fe275449f 100644 (file)
@@ -543,7 +543,7 @@ struct xwindow *wp;
     reset_menu_count(wp->menu_information);
     for (count = 0, curr = wp->menu_information->curr_menu.base; curr;
          curr = curr->next, count++) {
-        if ((curr->itemflags & MENU_ITEMFLAGS_SKIPINVERT) != 0)
+        if (!menuitem_invert_test(0, curr->itemflags, curr->selected))
             continue;
         if (curr->identifier.a_void != 0)
             invert_line(wp, curr, count, -1L);
index a33ef530b1a2768cd804ad0c14f35091e0dbeae0..e18ccdc572b9cb2ac5f32226d35dceebfa352851 100644 (file)
@@ -1553,7 +1553,8 @@ menu_operation(WINDOW * win, nhmenu *menu, menu_op
 
         if (menu_item_ptr->identifier.a_void != NULL) {
             if (operation != INVERT
-                || (menu_item_ptr->itemflags & MENU_ITEMFLAGS_SKIPINVERT) == 0)
+                || menuitem_invert_test(0, menu_item_ptr->itemflags,
+                                        menu_item_ptr->selected))
                 menu_select_deselect(win, menu_item_ptr, operation, current_page);
         }
 
index e25e60ae3082b03ad269e50062dac1f83fcf168b..ecf979a1d19592ee65fad9b31098d5fe17d0c129 100644 (file)
@@ -1784,8 +1784,9 @@ char acc;
     for (curr = invent_list; start-- && curr; curr = curr->Gmi_next)
         ;
     for (; page-- && curr; curr = curr->Gmi_next) {
-        if ((curr->Gmi_itemflags & MENU_ITEMFLAGS_SKIPINVERT) != 0)
+        if (!menuitem_invert_test(0, curr->Gmi_itemflags, curr->Gmi_selected)
             continue;
+
         if (curr->Gmi_identifier && (acc == 0 || curr->Gmi_groupacc == acc)) {
             if (curr->Gmi_selected) {
                 curr->Gmi_selected = FALSE;
index aaba49f41d039a9e8a644b05d7a269c3706cfe87..0fbe47648aa13d45c42eeeca241ad0379083370b 100644 (file)
@@ -1774,7 +1774,7 @@ char acc; /* group accelerator, 0 => all */
     int n;
 
     for (n = 0, curr = page_start; curr != page_end; n++, curr = curr->next) {
-        if ((curr->itemflags & MENU_ITEMFLAGS_SKIPINVERT) != 0)
+        if (!menuitem_invert_test(0, curr->itemflags, curr->selected))
             continue;
 
         if (curr->identifier.a_void && (acc == 0 || curr->gselector == acc)) {
@@ -1812,12 +1812,12 @@ char acc; /* group accelerator, 0 => all */
 
         if (!on_curr_page && curr->identifier.a_void
             && (acc == 0 || curr->gselector == acc)) {
-            if ((curr->itemflags & MENU_ITEMFLAGS_SKIPINVERT) == 0) {
+            if (menuitem_invert_test(0, curr->itemflags, curr->selected)) {
                 if (curr->selected) {
                     curr->selected = FALSE;
                     curr->count = -1;
                 } else
-                    curr->selected = TRUE;
+                curr->selected = TRUE;
             }
         }
     }
index ab76d41ad5d92fe2d4ffbc5bc8678b1452ebf3b5..0150e559ced3372c4febee2af2f71562a516f164 100644 (file)
@@ -1306,7 +1306,8 @@ onListChar(HWND hWnd, HWND hwndList, WORD ch)
         if (data->how == PICK_ANY) {
             reset_menu_count(hwndList, data);
             for (i = 0; i < data->menu.size; i++) {
-                if (!(data->menu.items[i].itemflags & MENU_ITEMFLAGS_SKIPINVERT))
+                if (menuitem_invert_test(0, data->menu.items[i].itemflags,
+                                         NHMENU_IS_SELECTED(data->menu.items[i])))
                     SelectMenuItem(hwndList, data, i,
                                NHMENU_IS_SELECTED(data->menu.items[i]) ? 0
                                                                        : -1);
@@ -1354,7 +1355,8 @@ onListChar(HWND hWnd, HWND hwndList, WORD ch)
             from = max(0, topIndex);
             to = min(data->menu.size, from + pageSize);
             for (i = from; i < to; i++) {
-                if (!(data->menu.items[i].itemflags & MENU_ITEMFLAGS_SKIPINVERT))
+                if (menuitem_invert_test(0, data->menu.items[i].itemflags,
+                                         NHMENU_IS_SELECTED(data->menu.items[i])))                    
                     SelectMenuItem(hwndList, data, i,
                                NHMENU_IS_SELECTED(data->menu.items[i]) ? 0
                                                                        : -1);