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