Subversion Repositories Games.Chess Giants

Rev

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