Rev 124 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | // dialog_endgame.cpp |
| 2 | |||
| 3 | #include "../common.h" |
||
| 4 | |||
| 5 | |||
| 6 | // dialog template |
||
| 7 | #define THIS_DIALOG DIALOG_GOTOMOVE |
||
| 8 | |||
| 9 | |||
| 10 | // global variables used in this module only |
||
| 11 | static int wanted_move = 0; |
||
| 12 | |||
| 13 | |||
| 14 | // prototypes of local functions |
||
| 15 | static void StartThread_ThisDialog (void *thread_parms); |
||
| 16 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
| 17 | |||
| 18 | |||
| 19 | void DialogBox_GoToMove (void) |
||
| 20 | { |
||
| 21 | // helper function to fire up the modeless dialog box |
||
| 22 | |||
| 23 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
||
| 24 | |||
| 25 | return; // return as soon as the thread is fired up |
||
| 26 | } |
||
| 27 | |||
| 28 | |||
| 29 | void DialogBox_GoToMove_Validated (void) |
||
| 30 | { |
||
| 31 | // callback function called by the main game thread when the dialog box is validated |
||
| 32 | |||
| 33 | // remember this callback is no longer to be called |
||
| 34 | is_dialogbox_gotomove_validated = false; |
||
| 35 | |||
| 36 | // enter view mode and set the viewed move to the one we want (with sanity checks) |
||
| 37 | if (wanted_move < 0) |
||
| 38 | the_board.viewed_move = 0; // clamp min to start state |
||
| 39 | else if ((the_board.move_count > 1) && (wanted_move > the_board.move_count - 1)) |
||
| 40 | the_board.viewed_move = the_board.move_count - 1; // clamp max to last move |
||
| 41 | else |
||
| 42 | the_board.viewed_move = wanted_move; // else any move in between |
||
| 43 | |||
| 44 | the_board.reevaluate = true; // evaluate board again |
||
| 45 | return; // finished, invitation is sent |
||
| 46 | } |
||
| 47 | |||
| 48 | |||
| 49 | static void StartThread_ThisDialog (void *thread_parms) |
||
| 50 | { |
||
| 51 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
| 52 | // to implement a non-modal message box using the Common Controls library. |
||
| 53 | |||
| 54 | // display the dialog box |
||
| 55 | if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) |
||
| 56 | is_dialogbox_gotomove_validated = true; |
||
| 57 | |||
| 58 | return; // _endthread() implied |
||
| 59 | } |
||
| 60 | |||
| 61 | |||
| 62 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
| 63 | { |
||
| 64 | // message handler for the dialog box |
||
| 65 | |||
| 66 | unsigned short wParam_hiword; |
||
| 67 | unsigned short wParam_loword; |
||
| 68 | |||
| 69 | // filter out the commonly used message values |
||
| 70 | wParam_hiword = HIWORD (wParam); |
||
| 71 | wParam_loword = LOWORD (wParam); |
||
| 72 | |||
| 73 | // have we just fired up this window ? |
||
| 74 | if (message == WM_INITDIALOG) |
||
| 75 | { |
||
| 76 | // center the window |
||
| 77 | CenterWindow (hWnd, hMainWnd); |
||
| 78 | |||
| 79 | // set dialog icons (small one for title bar & big one for task manager) |
||
| 80 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 81 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 82 | |||
| 83 | // set window title and control texts |
||
| 84 | SetWindowText (hWnd, LOCALIZE (L"GoToMove_Title")); |
||
| 85 | SetDlgItemText (hWnd, BUTTON_OK, LOCALIZE (L"Button_OK")); |
||
| 86 | SetDlgItemText (hWnd, STATICTEXT_GOTOMOVE, LOCALIZE (L"GoToMove")); |
||
| 87 | SetDlgItemInt (hWnd, EDITBOX_GOTOMOVE, MOVEINDEX_TO_PGNMOVENUMBER (the_board.viewed_move), false); |
||
| 88 | SetDlgItemText (hWnd, RADIOBUTTON_GOTOMOVE_WHITE, LOCALIZE (L"Games_White")); |
||
| 89 | SetDlgItemText (hWnd, RADIOBUTTON_GOTOMOVE_BLACK, LOCALIZE (L"Games_Black")); |
||
| 90 | SetDlgItemText (hWnd, STATICTEXT_GOTOMOVE_STATUSBAR, LOCALIZE (L"GoToMove_StatusBar")); |
||
| 91 | |||
| 92 | // initialize the radio buttons |
||
| 93 | Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_WHITE), (1 - the_board.viewed_move % 2 == COLOR_WHITE ? BST_CHECKED : BST_UNCHECKED)); |
||
| 94 | Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_BLACK), (1 - the_board.viewed_move % 2 == COLOR_BLACK ? BST_CHECKED : BST_UNCHECKED)); |
||
| 95 | |||
| 96 | // convert the status bar message to a hyperlink |
||
| 97 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_GOTOMOVE_STATUSBAR)); |
||
| 98 | } |
||
| 99 | |||
| 100 | // else did we click the close button on the title bar ? |
||
| 101 | else if (message == WM_CLOSE) |
||
| 102 | EndDialog (hWnd, 0); // close the dialog box |
||
| 103 | |||
| 104 | // else did we take action on one of the controls ? |
||
| 105 | else if (message == WM_COMMAND) |
||
| 106 | { |
||
| 107 | // was it the OK button ? |
||
| 108 | if (wParam_loword == BUTTON_OK) |
||
| 109 | { |
||
| 110 | // translate the wanted move number into a move array index |
||
| 111 | wanted_move = PGNMOVENUMBER_TO_MOVEINDEX (GetDlgItemInt (hWnd, EDITBOX_GOTOMOVE, NULL, false), |
||
| 112 | (Button_GetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_BLACK)) == BST_CHECKED ? COLOR_BLACK : COLOR_WHITE)); |
||
| 113 | EndDialog (hWnd, 1); // close the dialog box and return a success value |
||
| 114 | } |
||
| 115 | |||
| 116 | // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
| 117 | else if (wParam_loword == IDCANCEL) |
||
| 118 | EndDialog (hWnd, 0); // close the dialog box |
||
| 119 | |||
| 120 | // else is it a radio button ? |
||
| 121 | else if (wParam_loword == RADIOBUTTON_GOTOMOVE_WHITE) |
||
| 122 | Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_BLACK), BST_UNCHECKED); |
||
| 123 | else if (wParam_loword == RADIOBUTTON_GOTOMOVE_BLACK) |
||
| 124 | Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_WHITE), BST_UNCHECKED); |
||
| 125 | |||
| 126 | // else was it the status bar hyperlink ? |
||
| 127 | else if (wParam_loword == STATICTEXT_ENDGAME_STATUSBAR) |
||
| 128 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
| 129 | } |
||
| 130 | |||
| 131 | // call the default dialog message processing function to keep things going |
||
| 132 | return (false); |
||
| 133 | } |