Subversion Repositories Games.Chess Giants

Rev

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