Rev 124 | Rev 171 | Go to most recent revision | 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; |
||
35 | |||
36 | // remember this callback is no longer to be called |
||
37 | is_dialogbox_pawnpromotion_validated = false; |
||
38 | |||
39 | currentmove = &the_board.moves[the_board.move_count - 1]; // quick access to previous move |
||
40 | |||
41 | // save promotion type and promote the part to the desired type |
||
42 | currentmove->promotion_type = promotion_type; |
||
43 | Move_SetSlot (currentmove, currentmove->target[0], currentmove->target[1], currentmove->color, currentmove->promotion_type); |
||
44 | |||
45 | // evaluate new check and stalemate status |
||
46 | currentmove->is_check = Move_IsCheck (currentmove, 1 - currentmove->color); // save whether opponent is in check or not |
||
47 | currentmove->is_stalemate = Move_IsStaleMate (currentmove, 1 - currentmove->color); // save whether opponent is stalemate |
||
48 | |||
49 | // re-describe our move in Standard Abbreviated Notation and describe the resulting table in Forsyth-Edwards Notation |
||
50 | Move_DescribeInSAN (currentmove); |
||
51 | Move_DescribeInFEN (currentmove); |
||
52 | |||
53 | // forget the hovered and selected positions |
||
54 | Board_SetSelectedAndHovered (&the_board, -1, -1, -1, -1); |
||
55 | |||
56 | the_board.has_playerchanged = true; // pawn promotion is complete, we can switch players now |
||
57 | the_board.reevaluate = true; // evaluate the new board |
||
58 | the_scene.update = true; // and redraw the scene |
||
59 | |||
60 | return; // finished, pawn has been promoted to the desired part type |
||
61 | } |
||
62 | |||
63 | |||
64 | static void StartThread_ThisDialog (void *thread_parms) |
||
65 | { |
||
66 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
67 | // to implement a non-modal message box using the Common Controls library. |
||
68 | |||
69 | // display the dialog box |
||
70 | promotion_type = DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog); |
||
71 | if (promotion_type > 0) |
||
72 | is_dialogbox_pawnpromotion_validated = true; |
||
140 | pmbaty | 73 | is_dialogbox_displayed = false; |
1 | pmbaty | 74 | |
124 | pmbaty | 75 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
1 | pmbaty | 76 | return; // _endthread() implied |
77 | } |
||
78 | |||
79 | |||
80 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
81 | { |
||
82 | // message handler for the dialog box |
||
83 | |||
84 | unsigned short wParam_hiword; |
||
85 | unsigned short wParam_loword; |
||
86 | |||
87 | // filter out the commonly used message values |
||
88 | wParam_hiword = HIWORD (wParam); |
||
89 | wParam_loword = LOWORD (wParam); |
||
90 | |||
91 | // have we just fired up this window ? |
||
92 | if (message == WM_INITDIALOG) |
||
93 | { |
||
94 | // center the window |
||
95 | CenterWindow (hWnd, hMainWnd); |
||
96 | |||
97 | // set dialog icons (small one for title bar & big one for task manager) |
||
98 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
99 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
100 | |||
101 | // set window title and control texts |
||
102 | SetWindowText (hWnd, LOCALIZE (L"PawnPromotion_Title")); |
||
103 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_QUESTION), LOCALIZE (L"PawnPromotion_Question")); |
||
104 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR), LOCALIZE (L"PawnPromotion_StatusBar")); |
||
105 | |||
106 | // convert the bitmaps to clickable things |
||
107 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_ROOK)); |
||
108 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_KNIGHT)); |
||
109 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_BISHOP)); |
||
110 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_QUEEN)); |
||
111 | |||
112 | // convert the status bar message to a hyperlink |
||
113 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR)); |
||
114 | } |
||
115 | |||
116 | // else did we take action on one of the controls ? |
||
117 | else if (message == WM_COMMAND) |
||
118 | { |
||
119 | // was it the "rook" button ? |
||
120 | if (wParam_loword == BUTTON_ROOK) |
||
121 | EndDialog (hWnd, PART_ROOK); // close the dialog box and return a "promote to rook" value |
||
122 | |||
123 | // else was it the "knight" button ? |
||
124 | else if (wParam_loword == BUTTON_KNIGHT) |
||
125 | EndDialog (hWnd, PART_KNIGHT); // close the dialog box and return a "promote to knight" value |
||
126 | |||
127 | // else was it the "bishop" button ? |
||
128 | else if (wParam_loword == BUTTON_BISHOP) |
||
129 | EndDialog (hWnd, PART_BISHOP); // close the dialog box and return a "promote to bishop" value |
||
130 | |||
131 | // else was it the "queen" button ? |
||
132 | else if (wParam_loword == BUTTON_QUEEN) |
||
133 | EndDialog (hWnd, PART_QUEEN); // close the dialog box and return a "promote to queen" value |
||
134 | |||
135 | // else was it the status bar hyperlink ? |
||
136 | else if (wParam_loword == STATICTEXT_PAWNPROMOTION_STATUSBAR) |
||
137 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
138 | } |
||
139 | |||
140 | // call the default dialog message processing function to keep things going |
||
141 | return (false); |
||
142 | } |