From 7454f494554a3406c6a382d6feba2f9040eb3121 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 4 May 2011 13:36:27 +0200 Subject: [PATCH] Allow switching off match mode through menu The Machine Match menu item is now checkmarked, and no longer grayed during a match, and clicking it while a match is running will terminate the match after the current game. To not be left with hanging checkmarks, the checkmark is already removed duringthe last match game (which is logically equivalent to ordinary Two Machines mode anyway). --- backend.c | 10 ++++++++++ winboard/winboard.c | 31 ++++++++++++++----------------- xboard.c | 8 ++++---- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/backend.c b/backend.c index f2c0c98..f7b26e5 100644 --- a/backend.c +++ b/backend.c @@ -1365,6 +1365,16 @@ void MatchEvent(int mode) { // [HGM] moved out of InitBackend3, to make it callable when match starts through menu int dummy; + if(matchMode) { // already in match mode: switch it off + appData.matchGames = matchGame; // kludge to let match terminate after next game. + ModeHighlight(); // kludgey way to remove checkmark... + return; + } + if(gameMode != BeginningOfGame) { + DisplayError(_("You can only start a match from the initial position."), 0); + return; + } + appData.matchGames = appData.defaultMatchGames; /* Set up machine vs. machine match */ nextGame = 0; NextTourneyGame(0, &dummy); // sets appData.matchGames if this is tourney, to make sure ReserveGame knows it diff --git a/winboard/winboard.c b/winboard/winboard.c index c8bf0b2..ae9d561 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -4842,10 +4842,6 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_Match: // [HGM] match: flows into next case, after setting Match Mode and nr of Games - if(gameMode != BeginningOfGame) { // allow menu item to remain enabled for better mode highligting - DisplayError(_("You can only start a match from the initial position."), 0); break; - } - appData.matchGames = appData.defaultMatchGames; MatchEvent(2); // distinguish from command-line-triggered case (matchMode=1) break; @@ -7858,7 +7854,7 @@ Enables machineThinkingEnables[] = { { IDM_MachineWhite, MF_BYCOMMAND|MF_GRAYED }, { IDM_MachineBlack, MF_BYCOMMAND|MF_GRAYED }, { IDM_TwoMachines, MF_BYCOMMAND|MF_GRAYED }, - { IDM_Match, MF_BYCOMMAND|MF_GRAYED }, +// { IDM_Match, MF_BYCOMMAND|MF_GRAYED }, { IDM_TypeInMove, MF_BYCOMMAND|MF_GRAYED }, { IDM_RetractMove, MF_BYCOMMAND|MF_GRAYED }, { -1, -1 } @@ -7878,7 +7874,7 @@ Enables userThinkingEnables[] = { { IDM_MachineWhite, MF_BYCOMMAND|MF_ENABLED }, { IDM_MachineBlack, MF_BYCOMMAND|MF_ENABLED }, { IDM_TwoMachines, MF_BYCOMMAND|MF_ENABLED }, - { IDM_Match, MF_BYCOMMAND|MF_ENABLED }, +// { IDM_Match, MF_BYCOMMAND|MF_ENABLED }, { IDM_TypeInMove, MF_BYCOMMAND|MF_ENABLED }, { IDM_RetractMove, MF_BYCOMMAND|MF_ENABLED }, { -1, -1 } @@ -7891,6 +7887,12 @@ Enables userThinkingEnables[] = { * \*---------------------------------------------------------------------------*/ VOID +CheckMark(UINT item, int state) +{ + if(item) CheckMenuItem(GetMenu(hwndMain), item, MF_BYCOMMAND|state); +} + +VOID ModeHighlight() { static UINT prevChecked = 0; @@ -7920,7 +7922,7 @@ ModeHighlight() nowChecked = IDM_MachineWhite; break; case TwoMachinesPlay: - nowChecked = matchMode ? IDM_Match : IDM_TwoMachines; // [HGM] match + nowChecked = IDM_TwoMachines; break; case AnalyzeMode: nowChecked = IDM_AnalysisMode; @@ -7951,12 +7953,9 @@ ModeHighlight() nowChecked = 0; break; } - if (prevChecked != 0) - (void) CheckMenuItem(GetMenu(hwndMain), - prevChecked, MF_BYCOMMAND|MF_UNCHECKED); - if (nowChecked != 0) - (void) CheckMenuItem(GetMenu(hwndMain), - nowChecked, MF_BYCOMMAND|MF_CHECKED); + CheckMark(prevChecked, MF_UNCHECKED); + CheckMark(nowChecked, MF_CHECKED); + CheckMark(IDM_Match, matchMode && matchGame < appData.matchGames ? MF_CHECKED : MF_UNCHECKED); if (nowChecked == IDM_LoadGame || nowChecked == IDM_Training) { (void) EnableMenuItem(GetMenu(hwndMain), IDM_Training, @@ -7971,11 +7970,9 @@ ModeHighlight() /* [DM] icsEngineAnalyze - Do a sceure check too */ if (appData.icsActive) { if (appData.icsEngineAnalyze) { - (void) CheckMenuItem(GetMenu(hwndMain), IDM_AnalysisMode, - MF_BYCOMMAND|MF_CHECKED); + CheckMark(IDM_AnalysisMode, MF_CHECKED); } else { - (void) CheckMenuItem(GetMenu(hwndMain), IDM_AnalysisMode, - MF_BYCOMMAND|MF_UNCHECKED); + CheckMark(IDM_AnalysisMode, MF_UNCHECKED); } } DisplayLogos(); // [HGM] logos: mode change could have altered logos diff --git a/xboard.c b/xboard.c index e9c4347..e5822a4 100644 --- a/xboard.c +++ b/xboard.c @@ -2925,7 +2925,7 @@ Enables machineThinkingEnables[] = { { "menuMode.Machine White", False }, { "menuMode.Machine Black", False }, { "menuMode.Two Machines", False }, - { "menuMode.Machine Match", False }, +// { "menuMode.Machine Match", False }, { "menuEngine.Retract Move", False }, { NULL, False } }; @@ -2944,7 +2944,7 @@ Enables userThinkingEnables[] = { { "menuMode.Machine White", True }, { "menuMode.Machine Black", True }, { "menuMode.Two Machines", True }, - { "menuMode.Machine Match", True }, +// { "menuMode.Machine Match", True }, { "menuEngine.Retract Move", True }, { NULL, False } }; @@ -5308,6 +5308,8 @@ void ModeHighlight() XtSetValues(XtNameToWidget(menuBarWidget, wname), args, 1); } oldmode = gameMode; + XtSetArg(args[0], XtNleftBitmap, matchMode && matchGame < appData.matchGames ? xMarkPixmap : None); + XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Machine Match"), args, 1); /* Maybe all the enables should be handled here, not just this one */ XtSetSensitive(XtNameToWidget(menuBarWidget, "menuMode.Training"), @@ -5833,8 +5835,6 @@ void MatchProc(w, event, prms, nprms) String *prms; Cardinal *nprms; { - if(gameMode != BeginningOfGame) { DisplayError(_("You can only start a match from the initial position."), 0); return; } - appData.matchGames = appData.defaultMatchGames; MatchEvent(2); } -- 1.7.0.4