Rev 178 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | // dialog_pawnpromotion.cpp |
| 2 | |||
| 3 | #include "../common.h" |
||
| 4 | |||
| 5 | |||
| 6 | // dialog template |
||
| 7 | #define THIS_DIALOG DIALOG_PAWNPROMOTION |
||
| 8 | |||
| 9 | |||
| 10 | // global variables used in this module only |
||
| 11 | static int promotion_type = PART_NONE; |
||
| 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_PawnPromotion (void) |
||
| 20 | { |
||
| 21 | // helper function to fire up the modeless dialog box |
||
| 22 | |||
| 140 | pmbaty | 23 | is_dialogbox_displayed = true; |
| 1 | pmbaty | 24 | _beginthread (StartThread_ThisDialog, 0, NULL); // so fire up a new one |
| 25 | |||
| 26 | return; // return as soon as the thread is fired up |
||
| 27 | } |
||
| 28 | |||
| 29 | |||
| 30 | void DialogBox_PawnPromotion_Validated (void) |
||
| 31 | { |
||
| 32 | // callback function called by the main game thread when the dialog box is validated |
||
| 33 | |||
| 34 | boardmove_t *currentmove; |
||
| 171 | pmbaty | 35 | player_t *opposite_player; |
| 1 | pmbaty | 36 | |
| 37 | // remember this callback is no longer to be called |
||
| 38 | is_dialogbox_pawnpromotion_validated = false; |
||
| 39 | |||
| 40 | currentmove = &the_board.moves[the_board.move_count - 1]; // quick access to previous move |
||
| 41 | |||
| 42 | // save promotion type and promote the part to the desired type |
||
| 43 | currentmove->promotion_type = promotion_type; |
||
| 44 | Move_SetSlot (currentmove, currentmove->target[0], currentmove->target[1], currentmove->color, currentmove->promotion_type); |
||
| 45 | |||
| 46 | // evaluate new check and stalemate status |
||
| 47 | currentmove->is_check = Move_IsCheck (currentmove, 1 - currentmove->color); // save whether opponent is in check or not |
||
| 48 | currentmove->is_stalemate = Move_IsStaleMate (currentmove, 1 - currentmove->color); // save whether opponent is stalemate |
||
| 49 | |||
| 50 | // re-describe our move in Standard Abbreviated Notation and describe the resulting table in Forsyth-Edwards Notation |
||
| 193 | pmbaty | 51 | Move_DescribeInSAN (currentmove, &the_board.moves[the_board.move_count - 2], currentmove->pgntext, WCHAR_SIZEOF (currentmove->pgntext), false); // don't use the localized part abbreviations); |
| 1 | pmbaty | 52 | Move_DescribeInFEN (currentmove); |
| 53 | |||
| 54 | // forget the hovered and selected positions |
||
| 55 | Board_SetSelectedAndHovered (&the_board, -1, -1, -1, -1); |
||
| 56 | |||
| 178 | pmbaty | 57 | // pawn promotions are a special case. When the dialog is displayed, the move has ALREADY been done. So we must |
| 58 | // not warn the OPPOSITE player of the current move, but the CURRENT player of the current move. |
||
| 59 | opposite_player = Player_GetCurrent (); |
||
| 171 | pmbaty | 60 | opposite_player->should_wakeup = true; // tell the opposite player to wake up |
| 61 | |||
| 1 | pmbaty | 62 | the_board.reevaluate = true; // evaluate the new board |
| 63 | the_scene.update = true; // and redraw the scene |
||
| 64 | |||
| 65 | return; // finished, pawn has been promoted to the desired part type |
||
| 66 | } |
||
| 67 | |||
| 68 | |||
| 69 | static void StartThread_ThisDialog (void *thread_parms) |
||
| 70 | { |
||
| 71 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
| 72 | // to implement a non-modal message box using the Common Controls library. |
||
| 73 | |||
| 74 | // display the dialog box |
||
| 75 | promotion_type = DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog); |
||
| 76 | if (promotion_type > 0) |
||
| 77 | is_dialogbox_pawnpromotion_validated = true; |
||
| 140 | pmbaty | 78 | is_dialogbox_displayed = false; |
| 1 | pmbaty | 79 | |
| 124 | pmbaty | 80 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
| 1 | pmbaty | 81 | return; // _endthread() implied |
| 82 | } |
||
| 83 | |||
| 84 | |||
| 85 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
| 86 | { |
||
| 87 | // message handler for the dialog box |
||
| 88 | |||
| 89 | unsigned short wParam_hiword; |
||
| 90 | unsigned short wParam_loword; |
||
| 91 | |||
| 92 | // filter out the commonly used message values |
||
| 93 | wParam_hiword = HIWORD (wParam); |
||
| 94 | wParam_loword = LOWORD (wParam); |
||
| 95 | |||
| 96 | // have we just fired up this window ? |
||
| 97 | if (message == WM_INITDIALOG) |
||
| 98 | { |
||
| 99 | // center the window |
||
| 100 | CenterWindow (hWnd, hMainWnd); |
||
| 101 | |||
| 102 | // set dialog icons (small one for title bar & big one for task manager) |
||
| 103 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 104 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 105 | |||
| 106 | // set window title and control texts |
||
| 107 | SetWindowText (hWnd, LOCALIZE (L"PawnPromotion_Title")); |
||
| 108 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_QUESTION), LOCALIZE (L"PawnPromotion_Question")); |
||
| 109 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR), LOCALIZE (L"PawnPromotion_StatusBar")); |
||
| 110 | |||
| 111 | // convert the bitmaps to clickable things |
||
| 112 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_ROOK)); |
||
| 113 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_KNIGHT)); |
||
| 114 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_BISHOP)); |
||
| 115 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_QUEEN)); |
||
| 116 | |||
| 117 | // convert the status bar message to a hyperlink |
||
| 118 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR)); |
||
| 119 | } |
||
| 120 | |||
| 121 | // else did we take action on one of the controls ? |
||
| 122 | else if (message == WM_COMMAND) |
||
| 123 | { |
||
| 124 | // was it the "rook" button ? |
||
| 125 | if (wParam_loword == BUTTON_ROOK) |
||
| 126 | EndDialog (hWnd, PART_ROOK); // close the dialog box and return a "promote to rook" value |
||
| 127 | |||
| 128 | // else was it the "knight" button ? |
||
| 129 | else if (wParam_loword == BUTTON_KNIGHT) |
||
| 130 | EndDialog (hWnd, PART_KNIGHT); // close the dialog box and return a "promote to knight" value |
||
| 131 | |||
| 132 | // else was it the "bishop" button ? |
||
| 133 | else if (wParam_loword == BUTTON_BISHOP) |
||
| 134 | EndDialog (hWnd, PART_BISHOP); // close the dialog box and return a "promote to bishop" value |
||
| 135 | |||
| 136 | // else was it the "queen" button ? |
||
| 137 | else if (wParam_loword == BUTTON_QUEEN) |
||
| 138 | EndDialog (hWnd, PART_QUEEN); // close the dialog box and return a "promote to queen" value |
||
| 139 | |||
| 140 | // else was it the status bar hyperlink ? |
||
| 141 | else if (wParam_loword == STATICTEXT_PAWNPROMOTION_STATUSBAR) |
||
| 142 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
| 143 | } |
||
| 144 | |||
| 145 | // call the default dialog message processing function to keep things going |
||
| 146 | return (false); |
||
| 147 | } |