Rev 125 | Go to most recent revision | Details | Compare with Previous | 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_ENDGAME |
||
| 8 | |||
| 9 | |||
| 10 | // prototypes of local functions |
||
| 11 | static void StartThread_ThisDialog (void *thread_parms); |
||
| 12 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
| 13 | |||
| 14 | |||
| 15 | void DialogBox_EndGame (void) |
||
| 16 | { |
||
| 17 | // helper function to fire up the modeless dialog box |
||
| 18 | |||
| 19 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
||
| 20 | |||
| 21 | return; // return as soon as the thread is fired up |
||
| 22 | } |
||
| 23 | |||
| 24 | |||
| 25 | void DialogBox_EndGame_Validated (void) |
||
| 26 | { |
||
| 27 | // callback function called by the main game thread when the dialog box is validated |
||
| 28 | |||
| 29 | // remember this callback is no longer to be called |
||
| 30 | is_dialogbox_endgame_validated = false; |
||
| 31 | |||
| 32 | return; // finished |
||
| 33 | } |
||
| 34 | |||
| 35 | |||
| 36 | static void StartThread_ThisDialog (void *thread_parms) |
||
| 37 | { |
||
| 38 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
| 39 | // to implement a non-modal message box using the Common Controls library. |
||
| 40 | |||
| 131 | pmbaty | 41 | // player_t *player; |
| 42 | // int column; |
||
| 43 | // int line; |
||
| 125 | pmbaty | 44 | |
| 1 | pmbaty | 45 | // display the dialog box |
| 46 | if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) |
||
| 47 | is_dialogbox_endgame_validated = true; |
||
| 48 | |||
| 131 | pmbaty | 49 | /* player = Player_GetCurrent (); |
| 125 | pmbaty | 50 | player->view_distance = CLOSEUP_VIEW_DISTANCE; // zoom on the tragedy |
| 131 | pmbaty | 51 | |
| 52 | for (line = 0; line < 8; line++) |
||
| 53 | for (column = 0; column < 8; column++) |
||
| 54 | if ((the_board.moves[the_board.viewed_move].slots[line][column].part == PART_KING) |
||
| 55 | && (the_board.moves[the_board.viewed_move].slots[line][column].color == player->color)) |
||
| 56 | { |
||
| 57 | lookatpoint_x = 17.5f - (7 - column) * 5.0f; // focus on the victim king |
||
| 58 | lookatpoint_y = 17.5f - line * 5.0f; // focus on the victim king |
||
| 59 | break; |
||
| 60 | }*/ // This is a bad idea. People need to view the table normally to understand their fate. |
||
| 61 | |||
| 125 | pmbaty | 62 | //the_board.reevaluate = true; // refresh the GUI buttons if needed // DO NOT REEVALUATE else the endgame dialog box will keep popup repeatedly! |
| 1 | pmbaty | 63 | return; // _endthread() implied |
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
| 68 | { |
||
| 69 | // message handler for the dialog box |
||
| 70 | |||
| 71 | unsigned short wParam_hiword; |
||
| 72 | unsigned short wParam_loword; |
||
| 73 | |||
| 74 | // filter out the commonly used message values |
||
| 75 | wParam_hiword = HIWORD (wParam); |
||
| 76 | wParam_loword = LOWORD (wParam); |
||
| 77 | |||
| 78 | // have we just fired up this window ? |
||
| 79 | if (message == WM_INITDIALOG) |
||
| 80 | { |
||
| 81 | // center the window |
||
| 82 | CenterWindow (hWnd, hMainWnd); |
||
| 83 | |||
| 84 | // set dialog icons (small one for title bar & big one for task manager) |
||
| 85 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 86 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 87 | |||
| 88 | // set window title and control texts |
||
| 89 | SetWindowText (hWnd, LOCALIZE (L"EndGame_Title")); |
||
| 90 | SetWindowText (GetDlgItem (hWnd, BUTTON_OK), LOCALIZE (L"Button_OK")); |
||
| 91 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR), LOCALIZE (L"EndGame_StatusBar")); |
||
| 92 | |||
| 93 | // set the right message |
||
| 94 | if (the_board.game_state == STATE_WHITEWIN_CHECKMATE) |
||
| 95 | { |
||
| 96 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate")); |
||
| 97 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins")); |
||
| 98 | } |
||
| 99 | else if (the_board.game_state == STATE_BLACKWIN_CHECKMATE) |
||
| 100 | { |
||
| 101 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate")); |
||
| 102 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins")); |
||
| 103 | } |
||
| 104 | else if (the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT) |
||
| 105 | { |
||
| 106 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign")); |
||
| 107 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins")); |
||
| 108 | } |
||
| 109 | else if (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT) |
||
| 110 | { |
||
| 111 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign")); |
||
| 112 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins")); |
||
| 113 | } |
||
| 114 | else if (the_board.game_state == STATE_DRAW_STALEMATE) |
||
| 115 | { |
||
| 116 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_StaleMate")); |
||
| 117 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame")); |
||
| 118 | } |
||
| 119 | else if (the_board.game_state == STATE_DRAW_AGREEMENT) |
||
| 120 | { |
||
| 121 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Agreement")); |
||
| 122 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame")); |
||
| 123 | } |
||
| 124 | else if (the_board.game_state == STATE_DRAW_OTHER) |
||
| 125 | { |
||
| 107 | pmbaty | 126 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_DrawGame")); |
| 127 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), L""); // TODO: display something better |
||
| 1 | pmbaty | 128 | } |
| 129 | else if (the_board.game_state == STATE_ADJOURNED) |
||
| 130 | { |
||
| 131 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Adjourned")); |
||
| 132 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), L""); |
||
| 133 | } |
||
| 134 | |||
| 135 | // convert the status bar message to a hyperlink |
||
| 136 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR)); |
||
| 137 | } |
||
| 138 | |||
| 139 | // else did we click the close button on the title bar ? |
||
| 140 | else if (message == WM_CLOSE) |
||
| 141 | EndDialog (hWnd, 0); // close the dialog box |
||
| 142 | |||
| 143 | // else did we take action on one of the controls ? |
||
| 144 | else if (message == WM_COMMAND) |
||
| 145 | { |
||
| 146 | // was it the OK button ? |
||
| 147 | if (wParam_loword == BUTTON_OK) |
||
| 148 | EndDialog (hWnd, 1); // close the dialog box and return OK |
||
| 149 | |||
| 150 | // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
| 151 | else if (wParam_loword == IDCANCEL) |
||
| 152 | EndDialog (hWnd, 0); // close the dialog box |
||
| 153 | |||
| 154 | // else was it the status bar hyperlink ? |
||
| 155 | else if (wParam_loword == STATICTEXT_ENDGAME_STATUSBAR) |
||
| 156 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
| 157 | } |
||
| 158 | |||
| 159 | // call the default dialog message processing function to keep things going |
||
| 160 | return (false); |
||
| 161 | } |