From 2ad3ca1ba84d14592ebcee541d4c27eb505d0784 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 14 Apr 2012 21:33:49 +0200 Subject: [PATCH] Implement automatic partner observe Starting a game, or starting to observe one, now automatically issues a 'pobserve' command if dual-board is switched on, so that the partner game will pop up in the secondary board (assuming it is bughouse). The secondary board now displays the players in the title. (This (lightly) breaks WinBoard again.) When the primary game ends, the secondary board closes automatically. Initial sizing of the board is repaired, and now uses the actual current board size, rather than the initial size of the main board. --- backend.c | 20 +++++++++++++++++++- dialogs.c | 9 ++++++--- xboard.c | 7 +++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/backend.c b/backend.c index bc25c5f..1cd59ce 100644 --- a/backend.c +++ b/backend.c @@ -4242,10 +4242,12 @@ ParseBoard12 (char *string) break; } - if((gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack) + if((gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack || + gameMode == IcsObserving && appData.dualBoard) // also allow use of second board for observing two games && newGameMode == IcsObserving && gamenum != ics_gamenum && appData.bgObserve) { // [HGM] bughouse: don't act on alien boards while we play. Just parse the board and save it */ int fac = strchr(elapsed_time, '.') ? 1 : 1000; + static int lastBgGame = -1; char *toSqr; for (k = 0; k < ranks; k++) { for (j = 0; j < files; j++) @@ -4271,6 +4273,12 @@ ParseBoard12 (char *string) DisplayWhiteClock(white_time*fac, to_play == 'W'); DisplayBlackClock(black_time*fac, to_play != 'W'); activePartner = to_play; + if(gamenum != lastBgGame) { + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%s %s %s", white, _("vs."), black); + DisplayTitle(buf); + } + lastBgGame = gamenum; activePartnerTime = to_play == 'W' ? white_time*fac : black_time*fac; partnerUp = 0; flipView = !flipView; } // [HGM] dual snprintf(partnerStatus, MSG_SIZ,"W: %d:%02d B: %d:%02d (%d-%d) %c", white_time*fac/60000, (white_time*fac%60000)/1000, @@ -4280,6 +4288,16 @@ ParseBoard12 (char *string) return; } + if(appData.dualBoard && appData.bgObserve) { + if((newGameMode == IcsPlayingWhite || newGameMode == IcsPlayingBlack) && moveNum == 1) + SendToICS(ics_prefix), SendToICS("pobserve\n"); + else if(newGameMode == IcsObserving && (gameMode == BeginningOfGame || gameMode == IcsIdle)) { + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%spobserve %s\n", ics_prefix, white); + SendToICS(buf); + } + } + /* Modify behavior for initial board display on move listing of wild games. */ diff --git a/dialogs.c b/dialogs.c index 93e817a..07eba9b 100644 --- a/dialogs.c +++ b/dialogs.c @@ -1764,6 +1764,8 @@ DisplayTitle (char *text) if (text == NULL) text = ""; + if(partnerUp) { SetDialogTitle(DummyDlg, text); return; } + if (*text != NULLCHAR) { safeStrCpy(icon, text, sizeof(icon)/sizeof(icon[0]) ); safeStrCpy(title, text, sizeof(title)/sizeof(title[0]) ); @@ -1981,12 +1983,13 @@ Option dualOptions[] = { // auxiliary board window void SlavePopUp () { + int size = BOARD_WIDTH*(squareSize + lineGap) + lineGap; // copy params from main board dualOptions[0].choice = mainOptions[W_WHITE].choice; dualOptions[1].choice = mainOptions[W_BLACK].choice; - dualOptions[3].value = mainOptions[W_BOARD].value; - dualOptions[3].max = dualOptions[2].max = mainOptions[W_BOARD].max; // board size - dualOptions[0].max = dualOptions[1].max = mainOptions[W_WHITE].max; // clock width + dualOptions[3].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap; + dualOptions[3].max = dualOptions[2].max = size; // board width + dualOptions[0].max = dualOptions[1].max = size/2 - 3; // clock width GenericPopUp(dualOptions, "XBoard", DummyDlg, BoardWindow, NONMODAL, 1); } diff --git a/xboard.c b/xboard.c index 0726ade..d3b827f 100644 --- a/xboard.c +++ b/xboard.c @@ -936,14 +936,17 @@ InitDrawingSizes (BoardSize boardSize, int flags) int i; static Dimension oldWidth, oldHeight; static VariantClass oldVariant; - static int oldMono = -1; + static int oldMono = -1, oldTwoBoards = 0; if(!formWidget) return; + if(oldTwoBoards && !twoBoards) PopDown(DummyDlg); + oldTwoBoards = twoBoards; + if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap); boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap); - +fprintf(debugFP, "BOARD %d x %d\n",boardWidth, boardHeight); if(boardWidth != oldWidth || boardHeight != oldHeight) { // do resizing stuff only if size actually changed oldWidth = boardWidth; oldHeight = boardHeight; -- 1.7.0.4