From 59e3a9e715601e65d6a208b2bf8fc0b9c7c0fee8 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 23 Feb 2014 23:51:20 +0100 Subject: [PATCH] Allow adding played move to book A button is added in the Edit Book dialog to prime XBoard for adding the next move entered through the user interface to the book window, without actually playing it. --- backend.c | 11 +++++++++++ backend.h | 2 ++ book.c | 1 + dialogs.c | 16 +++++++++++++++- winboard/wedittags.c | 16 +++++++++++++--- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/backend.c b/backend.c index 4f820f2..f305409 100644 --- a/backend.c +++ b/backend.c @@ -6816,6 +6816,7 @@ int lastLoadGameUseList = FALSE; char lastLoadGameTitle[MSG_SIZ], lastLoadPositionTitle[MSG_SIZ]; ChessMove lastLoadGameStart = EndOfFile; int doubleClick; +Boolean addToBookFlag; void UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) @@ -6995,6 +6996,16 @@ UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) return; } + if(addToBookFlag) { // adding moves to book + char buf[MSG_SIZ], move[MSG_SIZ]; + CoordsToAlgebraic(boards[currentMove], PosFlags(currentMove), fromY, fromX, toY, toX, promoChar, move); + snprintf(buf, MSG_SIZ, " 0.0%% 1 %s\n", move); + AddBookMove(buf); + addToBookFlag = FALSE; + ClearHighlights(); + return; + } + FinishMove(moveType, fromX, fromY, toX, toY, promoChar); } diff --git a/backend.h b/backend.h index d62f510..29773a8 100644 --- a/backend.h +++ b/backend.h @@ -73,6 +73,7 @@ extern Board boards[]; extern char marker[BOARD_RANKS][BOARD_FILES]; extern char lastMsg[MSG_SIZ]; extern Boolean bookUp; +extern Boolean addToBookFlag; extern int tinyLayout, smallLayout; extern Boolean mcMode; extern int dragging; @@ -204,6 +205,7 @@ int PromoScroll P((int x, int y)); void EditBookEvent P((void)); Boolean DisplayBook P((int moveNr)); void SaveToBook P((char *text)); +void AddBookMove P((char *text)); void PlayBookMove P((char *text, int index)); void HoverEvent P((int hiX, int hiY, int x, int y)); int PackGame P((Board board)); diff --git a/book.c b/book.c index bb9d170..89ac610 100644 --- a/book.c +++ b/book.c @@ -792,6 +792,7 @@ DisplayBook (int moveNr) p = MovesToText(count, entries); EditTagsPopUp(p, NULL); free(p); + addToBookFlag = FALSE; return TRUE; } diff --git a/dialogs.c b/dialogs.c index 5a904e5..fdf6d11 100644 --- a/dialogs.c +++ b/dialogs.c @@ -1182,10 +1182,17 @@ NewTagsCallback (int n) return 1; } +static void +NewMove () +{ + addToBookFlag = !addToBookFlag; +} + static Option tagsOptions[] = { { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL }, { 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", (char **) &TagsClick, TextBox, "" }, -{ 0, 0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") }, +{ 0, 0, 100, NULL, (void*) &NewMove, NULL, NULL, Button, N_("add next move") }, +{ 0,SAME_ROW,100,NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") }, { 0,SAME_ROW, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" } }; @@ -1210,6 +1217,7 @@ NewTagsPopup (char *text, char *msg) { char *title = bookUp ? _("Edit book") : _("Tags"); + tagsOptions[2].type = bookUp ? Button : Skip; if(DialogExists(TagsDlg)) { // if already exists, alter title and content SetWidgetText(&tagsOptions[1], text, TagsDlg); SetDialogTitle(TagsDlg, title); @@ -1246,6 +1254,12 @@ EditTagsProc () if (bookUp || !PopDown(TagsDlg)) EditTagsEvent(); } +void +AddBookMove (char *text) +{ + AppendText(&tagsOptions[1], text); +} + //---------------------------------------------- ICS Input Box ---------------------------------- char *icsText; diff --git a/winboard/wedittags.c b/winboard/wedittags.c index 6a8b1c6..79f4edc 100644 --- a/winboard/wedittags.c +++ b/winboard/wedittags.c @@ -26,6 +26,7 @@ #include "config.h" #include /* required for all Windows applications */ +#include #include #include #include @@ -43,6 +44,7 @@ /* Module globals */ static char *editTagsText, **resPtr; +static HWND memo; BOOL editTagsUp = FALSE; BOOL canEditTags = FALSE; @@ -66,14 +68,15 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: /* message: initialize dialog box */ /* Initialize the dialog items */ Translate(hDlg, DLG_EditTags); - hwndText = GetDlgItem(hDlg, OPT_TagsText); + hwndText = memo = GetDlgItem(hDlg, OPT_TagsText); SendMessage(hwndText, WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, MAKELPARAM(FALSE, 0)); SetDlgItemText(hDlg, OPT_TagsText, editTagsText); EnableWindow(GetDlgItem(hDlg, OPT_TagsCancel), canEditTags); - EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags); + EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags || bookUp); SendMessage(hwndText, EM_SETREADONLY, !canEditTags, 0); if (bookUp) { + SetDlgItemText(hDlg, OPT_EditTags, _("&Play Move")); SetWindowText(hDlg, _("Edit Book")); SetFocus(hwndText); } else @@ -150,6 +153,7 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; case OPT_EditTags: + if(bookUp) addToBookFlag = !addToBookFlag; else EditTagsEvent(); return TRUE; @@ -204,11 +208,17 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; } +VOID AddBookMove(char *text) +{ + SendMessage( memo, EM_SETSEL, 999999, 999999 ); // [HGM] multivar: choose insertion point + SendMessage( memo, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text ); +} + VOID TagsPopDown(void) { if (editTagsDialog) ShowWindow(editTagsDialog, SW_HIDE); CheckMenuItem(GetMenu(hwndMain), IDM_Tags, MF_UNCHECKED); - editTagsUp = bookUp = FALSE; + editTagsUp = bookUp = addToBookFlag = FALSE; } -- 1.7.0.4