Subversion Repositories Games.Chess Giants

Rev

Rev 1 | Rev 124 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
// dialog_resign.cpp
2
 
3
#include "../common.h"
4
 
5
 
6
// dialog template
7
#define THIS_DIALOG DIALOG_RESIGN
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_Resign (void)
16
{
17
   // helper function to fire up the modeless dialog box
18
 
19 pmbaty 19
   _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new thread to display the dialog box
1 pmbaty 20
 
21
   return; // return as soon as the thread is fired up
22
}
23
 
24
 
25
void DialogBox_Resign_Validated (void)
26
{
27
   // callback function called by the main game thread when the dialog box is validated
28
 
29
   player_t *network_player;
30
 
31
   // remember this callback is no longer to be called
32
   is_dialogbox_resign_validated = false;
33
 
34
   // see if we're playing against a remote opponent
35
   network_player = Player_FindByType (PLAYER_INTERNET); // quick access to network player
36
 
37
   // is it an online game ?
38
   if (network_player != NULL)
39
      Player_SendBuffer_Add (network_player, 1000, L"resign\n"); // if so, send a resign command
40
 
41
   // else we're playing locally (either vs. another human or vs. computer)
42
   else
43
   {
44
      Scene_Shutdown (&the_scene); // release scene
45
      Board_Shutdown (&the_board); // release chess game
46
      Board_Init (&the_board, PLAYER_HUMAN, PLAYER_HUMAN, FENSTARTUP_STANDARDCHESS); // prepare a new human vs human game (by default)
47
      Scene_Init (&the_scene, &the_board); // initialize scene
48
      SetWindowText (hMainWnd, PROGRAM_NAME); // update window title
49
 
50
      DialogBox_NewGame (); // show the new game dialog box
51
   }
52
 
53
   the_board.reevaluate = true; // evaluate the new board
54
   the_scene.update = true; // update scene
55
 
56
   return; // finished, we have resigned from game
57
}
58
 
59
 
60
static void StartThread_ThisDialog (void *thread_parms)
61
{
62
   // this function runs in a separate thread, for that's the only way (seemingly)
63
   // to implement a non-modal message box using the Common Controls library.
64
 
65
   // display the dialog box
66
   if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
67
      is_dialogbox_resign_validated = true;
68
 
69
   return; // _endthread() implied
70
}
71
 
72
 
73
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
74
{
75
   // message handler for the dialog box
76
 
77
   unsigned short wParam_hiword;
78
   unsigned short wParam_loword;
79
 
80
   // filter out the commonly used message values
81
   wParam_hiword = HIWORD (wParam);
82
   wParam_loword = LOWORD (wParam);
83
 
84
   // have we just fired up this window ?
85
   if (message == WM_INITDIALOG)
86
   {
87
      // center the window
88
      CenterWindow (hWnd, hMainWnd);
89
 
90
      // set dialog icons (small one for title bar & big one for task manager)
91
      SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
92
      SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
93
 
94
      // set window title and control texts
95
      SetWindowText (hWnd, LOCALIZE (L"Quit_Title"));
96
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_RESIGN_QUESTION), LOCALIZE (L"Resign_Question"));
97
      SetWindowText (GetDlgItem (hWnd, BUTTON_GIVEUP), LOCALIZE (L"Resign_GiveUp"));
98
      SetWindowText (GetDlgItem (hWnd, BUTTON_BACKTOGAME), LOCALIZE (L"Resign_BackToGame"));
99
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_RESIGN_STATUSBAR), LOCALIZE (L"Resign_StatusBar"));
100
 
19 pmbaty 101
      // play the "question" system sound
102
      PlaySound ((LPCWSTR) SND_ALIAS_SYSTEMASTERISK, NULL, SND_ALIAS_ID | SND_ASYNC);
103
 
1 pmbaty 104
      // convert the status bar message to a hyperlink
105
      ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_RESIGN_STATUSBAR));
106
   }
107
 
108
   // else did we click the close button on the title bar ?
109
   else if (message == WM_CLOSE)
110
      EndDialog (hWnd, 0); // close the dialog box
111
 
112
   // else did we take action on one of the controls ?
113
   else if (message == WM_COMMAND)
114
   {
115
      // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
116
      if (wParam_loword == IDCANCEL)
117
         EndDialog (hWnd, 0); // close the dialog box
118
 
119
      // else was it the quit button ?
120
      else if (wParam_loword == BUTTON_GIVEUP)
121
         EndDialog (hWnd, 1); // close the dialog box and return a success code
122
 
123
      // else was it the back to game button ?
124
      else if (wParam_loword == BUTTON_BACKTOGAME)
125
         EndDialog (hWnd, 0); // close the dialog box
126
 
127
      // else was it the status bar hyperlink ?
128
      else if (wParam_loword == STATICTEXT_RESIGN_STATUSBAR)
129
         ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
130
   }
131
 
132
   // call the default dialog message processing function to keep things going
133
   return (false);
134
}