Rev 124 | Rev 131 | 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 | |||
125 | pmbaty | 41 | player_t *player; |
42 | |||
1 | pmbaty | 43 | // display the dialog box |
44 | if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) |
||
45 | is_dialogbox_endgame_validated = true; |
||
46 | |||
125 | pmbaty | 47 | player = Player_GetCurrent (); |
48 | player->view_distance = CLOSEUP_VIEW_DISTANCE; // zoom on the tragedy |
||
49 | //the_board.reevaluate = true; // refresh the GUI buttons if needed // DO NOT REEVALUATE else the endgame dialog box will keep popup repeatedly! |
||
1 | pmbaty | 50 | return; // _endthread() implied |
51 | } |
||
52 | |||
53 | |||
54 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
55 | { |
||
56 | // message handler for the dialog box |
||
57 | |||
58 | unsigned short wParam_hiword; |
||
59 | unsigned short wParam_loword; |
||
60 | |||
61 | // filter out the commonly used message values |
||
62 | wParam_hiword = HIWORD (wParam); |
||
63 | wParam_loword = LOWORD (wParam); |
||
64 | |||
65 | // have we just fired up this window ? |
||
66 | if (message == WM_INITDIALOG) |
||
67 | { |
||
68 | // center the window |
||
69 | CenterWindow (hWnd, hMainWnd); |
||
70 | |||
71 | // set dialog icons (small one for title bar & big one for task manager) |
||
72 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
73 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
74 | |||
75 | // set window title and control texts |
||
76 | SetWindowText (hWnd, LOCALIZE (L"EndGame_Title")); |
||
77 | SetWindowText (GetDlgItem (hWnd, BUTTON_OK), LOCALIZE (L"Button_OK")); |
||
78 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR), LOCALIZE (L"EndGame_StatusBar")); |
||
79 | |||
80 | // set the right message |
||
81 | if (the_board.game_state == STATE_WHITEWIN_CHECKMATE) |
||
82 | { |
||
83 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate")); |
||
84 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins")); |
||
85 | } |
||
86 | else if (the_board.game_state == STATE_BLACKWIN_CHECKMATE) |
||
87 | { |
||
88 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate")); |
||
89 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins")); |
||
90 | } |
||
91 | else if (the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT) |
||
92 | { |
||
93 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign")); |
||
94 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins")); |
||
95 | } |
||
96 | else if (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT) |
||
97 | { |
||
98 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign")); |
||
99 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins")); |
||
100 | } |
||
101 | else if (the_board.game_state == STATE_DRAW_STALEMATE) |
||
102 | { |
||
103 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_StaleMate")); |
||
104 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame")); |
||
105 | } |
||
106 | else if (the_board.game_state == STATE_DRAW_AGREEMENT) |
||
107 | { |
||
108 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Agreement")); |
||
109 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame")); |
||
110 | } |
||
111 | else if (the_board.game_state == STATE_DRAW_OTHER) |
||
112 | { |
||
107 | pmbaty | 113 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_DrawGame")); |
114 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), L""); // TODO: display something better |
||
1 | pmbaty | 115 | } |
116 | else if (the_board.game_state == STATE_ADJOURNED) |
||
117 | { |
||
118 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Adjourned")); |
||
119 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), L""); |
||
120 | } |
||
121 | |||
122 | // convert the status bar message to a hyperlink |
||
123 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR)); |
||
124 | } |
||
125 | |||
126 | // else did we click the close button on the title bar ? |
||
127 | else if (message == WM_CLOSE) |
||
128 | EndDialog (hWnd, 0); // close the dialog box |
||
129 | |||
130 | // else did we take action on one of the controls ? |
||
131 | else if (message == WM_COMMAND) |
||
132 | { |
||
133 | // was it the OK button ? |
||
134 | if (wParam_loword == BUTTON_OK) |
||
135 | EndDialog (hWnd, 1); // close the dialog box and return OK |
||
136 | |||
137 | // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
138 | else if (wParam_loword == IDCANCEL) |
||
139 | EndDialog (hWnd, 0); // close the dialog box |
||
140 | |||
141 | // else was it the status bar hyperlink ? |
||
142 | else if (wParam_loword == STATICTEXT_ENDGAME_STATUSBAR) |
||
143 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
144 | } |
||
145 | |||
146 | // call the default dialog message processing function to keep things going |
||
147 | return (false); |
||
148 | } |