Greyout unavailable variants in New Variant dialog
authorH.G. Muller <h.g.muller@hccnet.nl>
Mon, 24 Jan 2011 14:01:25 +0000 (15:01 +0100)
committerArun Persaud <arun@nubati.net>
Sat, 29 Jan 2011 02:15:59 +0000 (18:15 -0800)
The WB radio-button code is refactored to be driven from a list (which
must be kept in phase with the variant definitions in common.h!). It now
also checks if the first engine supports the variant, and greys out the
item if it isn't. XB now also makes this check. Slight re-ordering of
10x8 variants there, to have the more common on top.
If no radio button is selected, keep old variant even on OK.

winboard/resource.h
winboard/winboard.rc
winboard/woptions.c
xoptions.c

index 33b3875..d3cf585 100644 (file)
 #define OPT_VariantTwilight             1528\r
 #define OPT_VariantMakruk               1529\r
 #define OPT_VariantSChess               1530\r
+#define OPT_VariantSpartan              1531\r
 #define IDC_Files                       1550\r
 #define IDC_Ranks                       1551\r
 #define IDC_Holdings                    1552\r
index 3eaa824..78eb5b2 100644 (file)
@@ -677,7 +677,7 @@ BEGIN
                     70,10\r
     CONTROL         "&bughouse",OPT_VariantBughouse,"Button",BS_AUTORADIOBUTTON,80,24,70,\r
                     10\r
-    CONTROL         "Sp&artan",OPT_VariantTwilight,"Button",BS_AUTORADIOBUTTON,80,34,70,\r
+    CONTROL         "Sp&artan",OPT_VariantSpartan,"Button",BS_AUTORADIOBUTTON,80,34,70,\r
                     10\r
     CONTROL         "&shogi",OPT_VariantShogi,"Button",BS_AUTORADIOBUTTON,80,\r
                     44,70,10\r
index 93dde9e..3aeab42 100644 (file)
@@ -756,40 +756,71 @@ BoardOptionsPopup(HWND hwnd)
   FreeProcInstance(lpProc);\r
 }\r
 \r
+int radioButton[] = {\r
+    OPT_VariantNormal,\r
+    -1, // Loadable\r
+    OPT_VariantWildcastle,\r
+    OPT_VariantNocastle,\r
+    OPT_VariantFRC,\r
+    OPT_VariantBughouse,\r
+    OPT_VariantCrazyhouse,\r
+    OPT_VariantLosers,\r
+    OPT_VariantSuicide,\r
+    OPT_VariantGiveaway,\r
+    OPT_VariantTwoKings,\r
+    -1, //Kriegspiel\r
+    OPT_VariantAtomic,\r
+    OPT_Variant3Check,\r
+    OPT_VariantShatranj,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    OPT_VariantShogi,\r
+    OPT_VariantXiangqi,\r
+    OPT_VariantCourier,\r
+    OPT_VariantGothic,\r
+    OPT_VariantCapablanca,\r
+    OPT_VariantKnightmate,\r
+    OPT_VariantFairy,        \r
+    OPT_VariantCylinder,\r
+    OPT_VariantFalcon,\r
+    OPT_VariantCRC,\r
+    OPT_VariantBerolina,\r
+    OPT_VariantJanus,\r
+    OPT_VariantSuper,\r
+    OPT_VariantGreat,\r
+    -1, // Twilight,\r
+    OPT_VariantMakruk,\r
+    OPT_VariantSChess,\r
+    OPT_VariantSpartan, // Spartan\r
+    -2 // sentinel\r
+};\r
+\r
 VariantClass\r
 VariantWhichRadio(HWND hDlg)\r
 {\r
-  return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantCRC) ? VariantCapaRandom :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantSuper) ? VariantSuper :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantBerolina) ? VariantBerolina :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle :\r
-         (IsDlgButtonChecked(hDlg, OPT_Variant3Check) ? Variant3Check :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantGreat) ? VariantGreat :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantGiveaway) ? VariantGiveaway :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantTwilight) ? VariantSpartan :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantMakruk) ? VariantMakruk :\r
-         (IsDlgButtonChecked(hDlg, OPT_VariantSChess) ? VariantSChess :\r
-          VariantNormal ))))))))))))))))))))))))))))));\r
+  int i=0, j;\r
+  while((j = radioButton[i++]) != -2) {\r
+       if(j == -1) continue; // no menu button\r
+       if(IsDlgButtonChecked(hDlg, j)) return (VariantClass) i-1;\r
+  }\r
+  return gameInfo.variant; // If no button checked, keep old\r
+}\r
+\r
+void\r
+VariantShowRadio(HWND hDlg)\r
+{\r
+  int i=0, j;\r
+  CheckDlgButton(hDlg, radioButton[gameInfo.variant], TRUE);\r
+  while((j = radioButton[i++]) != -2) {\r
+       if(j == -1) continue; // no menu button\r
+       EnableWindow(GetDlgItem(hDlg, j), appData.noChessProgram || strstr(first.variants, VariantName(i-1)));\r
+  }\r
 }\r
 \r
 LRESULT CALLBACK\r
@@ -803,100 +834,9 @@ NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
     Translate(hDlg, DLG_NewVariant);\r
+\r
     /* Initialize the dialog items */\r
-    switch (gameInfo.variant) {\r
-    case VariantNormal:\r
-      CheckDlgButton(hDlg, OPT_VariantNormal, TRUE);\r
-      break;\r
-    case VariantCrazyhouse:\r
-      CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE);\r
-      break;\r
-    case VariantBughouse:\r
-      CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE);\r
-      break;\r
-    case VariantShogi:\r
-      CheckDlgButton(hDlg, OPT_VariantShogi, TRUE);\r
-      break;\r
-    case VariantXiangqi:\r
-      CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE);\r
-      break;\r
-    case VariantCapablanca:\r
-      CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE);\r
-      break;\r
-    case VariantGothic:\r
-      CheckDlgButton(hDlg, OPT_VariantGothic, TRUE);\r
-      break;\r
-    case VariantCourier:\r
-      CheckDlgButton(hDlg, OPT_VariantCourier, TRUE);\r
-      break;\r
-    case VariantKnightmate:\r
-      CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE);\r
-      break;\r
-    case VariantTwoKings:\r
-      CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE);\r
-      break;\r
-    case VariantFairy:\r
-      CheckDlgButton(hDlg, OPT_VariantFairy, TRUE);\r
-      break;\r
-    case VariantAtomic:\r
-      CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE);\r
-      break;\r
-    case VariantSuicide:\r
-      CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE);\r
-      break;\r
-    case VariantLosers:\r
-      CheckDlgButton(hDlg, OPT_VariantLosers, TRUE);\r
-      break;\r
-    case VariantShatranj:\r
-      CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE);\r
-      break;\r
-    case VariantFischeRandom:\r
-      CheckDlgButton(hDlg, OPT_VariantFRC, TRUE);\r
-      break;\r
-    case VariantCapaRandom:\r
-      CheckDlgButton(hDlg, OPT_VariantCRC, TRUE);\r
-      break;\r
-    case VariantFalcon:\r
-      CheckDlgButton(hDlg, OPT_VariantFalcon, TRUE);\r
-      break;\r
-    case VariantCylinder:\r
-      CheckDlgButton(hDlg, OPT_VariantCylinder, TRUE);\r
-      break;\r
-    case Variant3Check:\r
-      CheckDlgButton(hDlg, OPT_Variant3Check, TRUE);\r
-      break;\r
-    case VariantSuper:\r
-      CheckDlgButton(hDlg, OPT_VariantSuper, TRUE);\r
-      break;\r
-    case VariantBerolina:\r
-      CheckDlgButton(hDlg, OPT_VariantBerolina, TRUE);\r
-      break;\r
-    case VariantJanus:\r
-      CheckDlgButton(hDlg, OPT_VariantJanus, TRUE);\r
-      break;\r
-    case VariantWildCastle:\r
-      CheckDlgButton(hDlg, OPT_VariantWildcastle, TRUE);\r
-      break;\r
-    case VariantNoCastle:\r
-      CheckDlgButton(hDlg, OPT_VariantNocastle, TRUE);\r
-      break;\r
-    case VariantGreat:\r
-      CheckDlgButton(hDlg, OPT_VariantGreat, TRUE);\r
-      break;\r
-    case VariantGiveaway:\r
-      CheckDlgButton(hDlg, OPT_VariantGiveaway, TRUE);\r
-      break;\r
-    case VariantSpartan:\r
-      CheckDlgButton(hDlg, OPT_VariantTwilight, TRUE);\r
-      break;\r
-    case VariantMakruk:\r
-      CheckDlgButton(hDlg, OPT_VariantMakruk, TRUE);\r
-      break;\r
-    case VariantSChess:\r
-      CheckDlgButton(hDlg, OPT_VariantSChess, TRUE);\r
-      break;\r
-    default: ;\r
-    }\r
+    VariantShowRadio(hDlg);\r
 \r
     SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );\r
     SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );\r
index 759ea19..c8b49b2 100644 (file)
@@ -973,12 +973,12 @@ struct NewVarButton buttonDesc[] = {
     {N_("shogi (9x9)"),       "#BFFFFF", 0, VariantShogi},
     {N_("xiangqi (9x10)"),    "#BFFFFF", 0, VariantXiangqi},
     {N_("courier (12x8)"),    "#BFFFBF", 0, VariantCourier},
-    {N_("janus (10x8)"),      "#BFBFFF", 0, VariantJanus},
     {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
-    {N_("CRC (10x8)"),        "#BFBFFF", 0, VariantCapaRandom},
 #ifdef GOTHIC
     {N_("Gothic (10x8)"),     "#BFBFFF", 0, VariantGothic},
 #endif
+    {N_("janus (10x8)"),      "#BFBFFF", 0, VariantJanus},
+    {N_("CRC (10x8)"),        "#BFBFFF", 0, VariantCapaRandom},
 #ifdef FALCON
     {N_("Falcon (10x8)"),     "#BFBFFF", 0, VariantFalcon},
 #endif
@@ -1088,6 +1088,7 @@ void NewVariantPopUp()
        XtSetArg(args[j], XtNradioData, i+1); j++;
        XtSetArg(args[j], XtNbackground, buttonColor); j++;
        XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
+       XtSetArg(args[j], XtNsensitive, appData.noChessProgram || strstr(first.variants, VariantName(buttonDesc[i].variant))); j++;
        buttonDesc[i].handle = last =
            XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
     }