Rev 52 | Rev 59 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // main.cpp |
2 | |||
3 | #define DEFINE_GLOBALS |
||
4 | #include "common.h" |
||
5 | |||
6 | |||
7 | // handy macros |
||
8 | #define GUIBUTTON_ENABLE(button) { if ((button).state == 0) (button).state = 1; } |
||
9 | #define GUIBUTTON_DISABLE(button) { if ((button).state > 0) (button).state = 0; } |
||
10 | |||
11 | |||
12 | // prototypes of locally used functions |
||
13 | static void MainLoop_FindCurrentViewer (void); |
||
14 | static void MainLoop_EvaluateGameState (void); |
||
15 | |||
16 | |||
17 | int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpCmdLine, int nCmdShow) |
||
18 | { |
||
19 | // the entry point for any Windows program |
||
20 | |||
21 | WNDCLASSEX wc; |
||
22 | MENUINFO menu_info; |
||
23 | MSG msg; |
||
24 | HBITMAP hSplashBmp; |
||
25 | BITMAP splash_bmp; |
||
26 | HDC hdc; |
||
27 | HMENU hMenu; |
||
28 | HMENU hDropDownMenu; |
||
29 | RECT rect; |
||
30 | PAINTSTRUCT ps; |
||
31 | HBITMAP hbmTmp; |
||
32 | HDC hdcMem; |
||
33 | float previous_time; |
||
34 | int frame_count; |
||
35 | int array_index; |
||
36 | bool is_success; |
||
37 | char *endptr; |
||
38 | wchar_t app_pathname[MAX_PATH]; |
||
11 | pmbaty | 39 | wchar_t font_pathname[MAX_PATH]; |
41 | pmbaty | 40 | wchar_t temp_string[100]; |
1 | pmbaty | 41 | struct _stat fileinfo; |
42 | HACCEL hAccelerators; |
||
43 | ACCEL accelerators[] = |
||
44 | { |
||
45 | {FVIRTKEY | FCONTROL, L'O', MENUID_GAME_LOAD}, |
||
46 | {FVIRTKEY | FCONTROL, L'S', MENUID_GAME_SAVE}, |
||
47 | {FVIRTKEY | FCONTROL, L'Z', MENUID_CHESSBOARD_CANCELLASTMOVE}, |
||
48 | {FVIRTKEY, VK_HOME, MENUID_CHESSBOARD_BEGINNINGOFGAME}, |
||
49 | {FVIRTKEY, VK_LEFT, MENUID_CHESSBOARD_PREVIOUSMOVE}, |
||
50 | {FVIRTKEY, VK_RIGHT, MENUID_CHESSBOARD_NEXTMOVE}, |
||
51 | {FVIRTKEY, VK_END, MENUID_CHESSBOARD_CURRENTSTATEOFGAME}, |
||
52 | {FVIRTKEY | FCONTROL, L'G', MENUID_CHESSBOARD_GOTOMOVE}, |
||
53 | {FVIRTKEY, VK_F1, MENUID_HELP_HELP}, |
||
54 | {FVIRTKEY, VK_F2, MENUID_GAME_NEWGAME}, |
||
55 | {FVIRTKEY, VK_F3, MENUID_GAME_STATISTICS}, |
||
56 | {FVIRTKEY, VK_F4, MENUID_GAME_OPTIONS}, |
||
57 | {FVIRTKEY, VK_F5, MENUID_CHESSBOARD_TOPVIEW}, |
||
58 | {FVIRTKEY, VK_F6, MENUID_CHESSBOARD_DEFAULTVIEW}, |
||
59 | {FVIRTKEY, VK_F7, MENUID_CHESSBOARD_RESETVIEW}, |
||
60 | {FVIRTKEY, VK_UP, MENUID_CHESSBOARD_ZOOMIN}, |
||
61 | {FVIRTKEY, VK_DOWN, MENUID_CHESSBOARD_ZOOMOUT}, |
||
62 | {FVIRTKEY | FCONTROL, VK_DOWN, MENUID_CHESSBOARD_DISPLAYWINDOWSDESKTOP}, |
||
63 | {FVIRTKEY, VK_F8, MENUID_CHESSBOARD_CHANGEAPPEARANCE}, |
||
64 | {FVIRTKEY, VK_F9, MENUID_INTERNET_SHOWONLINEPLAYERS}, |
||
65 | {FVIRTKEY, VK_F10, MENUID_INTERNET_SHOWSOUGHTGAMES}, |
||
66 | }; |
||
67 | |||
68 | // save application instance |
||
69 | hAppInstance = hInstance; |
||
70 | |||
71 | // find module and path names, and *IMPORTANT*, set the current working directory there |
||
72 | GetModuleFileName (NULL, app_pathname, WCHAR_SIZEOF (app_pathname)); |
||
73 | GetDirectoryPath (app_pathname, app_path); |
||
74 | SetCurrentDirectoryW (app_path); |
||
75 | |||
76 | // initialize stuff |
||
14 | pmbaty | 77 | is_registered = false; |
1 | pmbaty | 78 | terminate_everything = false; |
79 | hMainWnd = NULL; |
||
80 | hChatterChannelsWnd = NULL; |
||
81 | hGamesWnd = NULL; |
||
82 | hMOTDWnd = NULL; |
||
83 | hOpponentsWnd = NULL; |
||
84 | hSoughtWnd = NULL; |
||
85 | #ifdef NDEBUG |
||
86 | want_framerate = false; // release mode, don't display framerate |
||
87 | #else |
||
2 | pmbaty | 88 | want_framerate = true; // display framerate in debug mode |
1 | pmbaty | 89 | #endif // NDEBUG |
90 | is_dialogbox_about_validated = false; |
||
91 | is_dialogbox_challenge_validated = false; |
||
92 | is_dialogbox_changeappearance_validated = false; |
||
93 | is_dialogbox_comment_validated = false; |
||
94 | is_dialogbox_endgame_validated = false; |
||
95 | is_dialogbox_gotomove_validated = false; |
||
96 | is_dialogbox_load_validated = false; |
||
97 | is_dialogbox_message_validated = false; |
||
98 | is_dialogbox_newgame_validated = false; |
||
99 | is_dialogbox_options_validated = false; |
||
100 | is_dialogbox_pawnpromotion_validated = false; |
||
101 | is_dialogbox_playercard_validated = false; |
||
102 | is_dialogbox_playerinfoname_validated = false; |
||
103 | is_dialogbox_quit_validated = false; |
||
104 | is_dialogbox_resign_validated = false; |
||
105 | is_dialogbox_save_validated = false; |
||
106 | is_dialogbox_saveposition_validated = false; |
||
107 | is_dialogbox_sendchallenge_validated = false; |
||
108 | is_dialogbox_sendseek_validated = false; |
||
109 | is_dialogbox_takeback_validated = false; |
||
110 | is_window_chat_validated = false; |
||
111 | is_window_chatterchannels_validated = false; |
||
112 | is_window_games_validated = false; |
||
113 | is_window_motd_validated = false; |
||
114 | is_window_opponents_validated = false; |
||
115 | is_window_sought_validated = false; |
||
116 | save_pathname[0] = 0; |
||
117 | srand ((unsigned int) time (NULL)); // initialize PRNG |
||
21 | pmbaty | 118 | animation_endtime = 0.0f; |
119 | command_ignoretime = 0.0f; |
||
120 | sound_playtime = 0.0f; |
||
121 | highlight_endtime = 0.0f; |
||
122 | previous_time = 0.0f; |
||
123 | frame_count = 0; |
||
1 | pmbaty | 124 | |
125 | // read configuration data |
||
126 | Config_Load (); |
||
127 | |||
14 | pmbaty | 128 | // see if the program is registered |
129 | is_registered = IsRegistrationCorrect (options.registration.user_email, options.registration.activation_code); |
||
130 | |||
1 | pmbaty | 131 | // read texts in the right language, if such a translation exists |
132 | is_success = false; |
||
133 | GetLocaleInfo (LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, os_language, WCHAR_SIZEOF (os_language)); |
||
11 | pmbaty | 134 | is_success = LocalizedTexts_Init (L"%s/data/languages/%s.ini", app_path, os_language); |
1 | pmbaty | 135 | |
136 | // fallback to English if language not found |
||
137 | if (!is_success) |
||
30 | pmbaty | 138 | { |
139 | wcscpy_s (os_language, WCHAR_SIZEOF (os_language), L"English"); |
||
140 | is_success = LocalizedTexts_Init (L"%s/data/languages/%s.ini", app_path, os_language); |
||
141 | } |
||
1 | pmbaty | 142 | |
143 | // consistency check: don't go further if texts aren't available |
||
144 | if (!is_success) |
||
56 | pmbaty | 145 | { |
146 | MessageBox (NULL, L"Chess Giants was unable to load its data files.\nThe game cannot start.\n\nPlease reinstall this program to fix the problem.", L"Chess Giants", MB_ICONERROR | MB_OK); |
||
1 | pmbaty | 147 | return (-1); // bomb out on error |
56 | pmbaty | 148 | } |
1 | pmbaty | 149 | |
150 | // create the main menu line |
||
151 | hMenu = CreateMenu (); |
||
152 | hDropDownMenu = CreateMenu (); // create the first drop-down item |
||
153 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_NEWGAME, LOCALIZE (L"Menu_GameNewGame")); |
||
154 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_LOAD, LOCALIZE (L"Menu_GameLoadGame")); |
||
155 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_SETUPPOSITION, LOCALIZE (L"Menu_GameSetupPosition")); |
||
156 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_SAVE, LOCALIZE (L"Menu_GameSaveGame")); // initially grayed |
||
157 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_SAVEAS, LOCALIZE (L"Menu_GameSaveGameAs")); // initially grayed |
||
158 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_SAVEPOSITIONAS, LOCALIZE (L"Menu_GameSavePositionAs")); // initially grayed |
||
159 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_RESIGN, LOCALIZE (L"Menu_GameResign")); |
||
160 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
161 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_STATISTICS, LOCALIZE (L"Menu_GameStatistics")); |
||
162 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_OPTIONS, LOCALIZE (L"Menu_GameOptions")); |
||
163 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
164 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_QUIT, LOCALIZE (L"Menu_GameQuit")); |
||
165 | AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Game")); |
||
166 | DestroyMenu (hDropDownMenu); |
||
167 | hDropDownMenu = CreateMenu (); // create the second drop-down item |
||
168 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_SUGGESTMOVE, LOCALIZE (L"Menu_ChessboardSuggestMove")); // initially grayed |
||
169 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_CANCELLASTMOVE, LOCALIZE (L"Menu_ChessboardCancelLastMove")); // initially grayed |
||
170 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_COMMENTMOVE, LOCALIZE (L"Menu_ChessboardCommentMove")); // initially grayed |
||
171 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_GOTOMOVE, LOCALIZE (L"Menu_ChessboardGoToMove")); // initially grayed |
||
172 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_SWAPSIDES, LOCALIZE (L"Menu_ChessboardSwapSides")); // initially grayed |
||
173 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
174 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_TOPVIEW, LOCALIZE (L"Menu_ChessboardTopView")); |
||
175 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_DEFAULTVIEW, LOCALIZE (L"Menu_ChessboardDefaultView")); |
||
176 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_RESETVIEW, LOCALIZE (L"Menu_ChessboardResetView")); |
||
177 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
178 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_CHANGEAPPEARANCE, LOCALIZE (L"Menu_ChessboardChangeAppearance")); |
||
179 | if (options.want_fullscreen) |
||
180 | { |
||
181 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
182 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_DISPLAYWINDOWSDESKTOP, LOCALIZE (L"Menu_ChessboardDisplayWindowsDesktop")); |
||
183 | } |
||
184 | AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Chessboard")); |
||
185 | DestroyMenu (hDropDownMenu); |
||
186 | hDropDownMenu = CreateMenu (); // create the third drop-down item |
||
187 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_SHOWONLINEPLAYERS, LOCALIZE (L"Menu_InternetShowOnlinePlayers")); // initially grayed |
||
188 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_SHOWSOUGHTGAMES, LOCALIZE (L"Menu_InternetShowSoughtGames")); // initially grayed |
||
189 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_SEEKGAME, LOCALIZE (L"Menu_InternetSeekGame")); // initially grayed |
||
190 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
191 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_CHATTERCHANNELS, LOCALIZE (L"Menu_InternetChatterChannels")); // initially grayed |
||
192 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_ENTERCHATTEXT, LOCALIZE (L"Menu_InternetEnterChatText")); // initially grayed |
||
193 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
194 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_DISPLAYPLAYERCARD, LOCALIZE (L"Menu_InternetDisplayPlayerCard")); // initially grayed |
||
195 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_DISPLAYYOURCARD, LOCALIZE (L"Menu_InternetDisplayYourCard")); // initially grayed |
||
196 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
197 | AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_MOTD, LOCALIZE (L"Menu_InternetDisplayMOTD")); // initially grayed |
||
198 | AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Internet")); |
||
199 | DestroyMenu (hDropDownMenu); |
||
200 | hDropDownMenu = CreateMenu (); // create the fourth drop-down item |
||
201 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_HELP, LOCALIZE (L"Menu_HelpDisplayHelp")); |
||
202 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_GETCHESSGAMES, LOCALIZE (L"Menu_HelpGetChessGames")); |
||
203 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
21 | pmbaty | 204 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYVISUALTHEMES, LOCALIZE (L"Menu_HelpAddModifyThemes")); |
50 | pmbaty | 205 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYENGINES, LOCALIZE (L"Menu_HelpAddModifyEngines")); |
21 | pmbaty | 206 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYTRANSLATIONS, LOCALIZE (L"Menu_HelpAddModifyTranslations")); |
207 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
||
1 | pmbaty | 208 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ABOUT, LOCALIZE (L"Menu_HelpAbout")); |
209 | AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Help")); |
||
210 | DestroyMenu (hDropDownMenu); |
||
211 | |||
212 | // create the accelerators |
||
213 | hAccelerators = CreateAcceleratorTable (accelerators, sizeof (accelerators) / sizeof (ACCEL)); |
||
214 | |||
215 | // register the window class, create the window and show it |
||
216 | memset (&wc, 0, sizeof (wc)); |
||
217 | wc.cbSize = sizeof (wc); |
||
218 | wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; // double-clicks support |
||
219 | wc.lpfnWndProc = WindowProc_Main; |
||
220 | wc.hInstance = hAppInstance; |
||
221 | wc.hIcon = LoadIcon (hAppInstance, (wchar_t *) ICON_MAIN); |
||
222 | wc.hCursor = LoadCursor (NULL, IDC_ARROW); |
||
223 | wc.lpszClassName = PROGRAM_NAME L" WndClass"; |
||
224 | RegisterClassEx (&wc); |
||
41 | pmbaty | 225 | swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), PROGRAM_NAME L"%s", (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); // build window title |
1 | pmbaty | 226 | if (options.want_fullscreen) |
41 | pmbaty | 227 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_POPUPWINDOW, // temp_string holds window title |
1 | pmbaty | 228 | 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), |
229 | NULL, hMenu, hAppInstance, NULL); |
||
230 | else |
||
231 | { |
||
3 | pmbaty | 232 | // in windowed mode, ensure window width and height aren't greater than screen size nor lower than a safe minimum |
1 | pmbaty | 233 | if (options.window_width > GetSystemMetrics (SM_CXMAXTRACK)) |
3 | pmbaty | 234 | options.window_width = GetSystemMetrics (SM_CXMAXTRACK); // check this first in case screen size is reported incorrect |
1 | pmbaty | 235 | if (options.window_height > GetSystemMetrics (SM_CYMAXTRACK)) |
236 | options.window_height = GetSystemMetrics (SM_CYMAXTRACK); |
||
3 | pmbaty | 237 | if (options.window_width < 640) |
238 | options.window_width = 640; // check this secondly in case screen size is reported incorrect |
||
239 | if (options.window_height < 480) |
||
240 | options.window_height = 480; |
||
1 | pmbaty | 241 | |
41 | pmbaty | 242 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_OVERLAPPEDWINDOW, // temp_string holds window title |
1 | pmbaty | 243 | GetSystemMetrics (SM_CXSCREEN) / 2 - options.window_width / 2, |
244 | GetSystemMetrics (SM_CYSCREEN) / 2 - options.window_height / 2, |
||
245 | options.window_width, |
||
246 | options.window_height, |
||
247 | NULL, hMenu, hAppInstance, NULL); |
||
248 | } |
||
249 | ShowWindow (hMainWnd, nCmdShow); |
||
250 | |||
251 | // display the splash screen |
||
252 | memset ((void *) &splash_bmp, 0, sizeof (splash_bmp)); |
||
11 | pmbaty | 253 | hSplashBmp = W32LoadImage (L"%s/data/splash.bmp", app_path); // load the splash bitmap |
1 | pmbaty | 254 | GetObject (hSplashBmp, sizeof (splash_bmp), (void *) &splash_bmp); // get a structure containing its size (among others) |
255 | hdcMem = CreateCompatibleDC (NULL); // create a device context compatible with the screen |
||
256 | hbmTmp = SelectBitmap (hdcMem, hSplashBmp); // select our bitmap to use in it |
||
257 | hdc = BeginPaint (hMainWnd, &ps); // begin painting on the main window |
||
258 | GetClientRect (hMainWnd, &rect); |
||
259 | StretchBlt (hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, splash_bmp.bmWidth, splash_bmp.bmHeight, SRCCOPY); // bit blit the bitmap into it |
||
260 | EndPaint (hMainWnd, &ps); // end painting on the main window |
||
261 | SelectObject (hdcMem, hbmTmp); // restore the previous selection |
||
262 | DeleteDC (hdcMem); // and delete the handles to the device context |
||
263 | DeleteObject (hSplashBmp); // and to the bitmap that we used |
||
264 | |||
265 | // make the menu modeless |
||
266 | memset (&menu_info, 0, sizeof (menu_info)); // prepare menu info structure |
||
267 | menu_info.cbSize = sizeof (MENUINFO); |
||
268 | menu_info.fMask = MIM_STYLE; |
||
269 | GetMenuInfo (GetMenu (hMainWnd), &menu_info); // get current style |
||
270 | menu_info.dwStyle |= MNS_MODELESS; // add the "modeless" flag |
||
271 | SetMenuInfo (GetMenu (hMainWnd), &menu_info); // and send it back |
||
272 | |||
273 | // load status icons, bitmaps and texts |
||
11 | pmbaty | 274 | handlestatus[HANDLESTATUS_AVAILABLE].icon = W32LoadIcon (L"%s/data/icons/available.ico", app_path); |
275 | handlestatus[HANDLESTATUS_AVAILABLE].bitmap = W32LoadImage (L"%s/data/status/available.bmp", app_path); |
||
1 | pmbaty | 276 | handlestatus[HANDLESTATUS_AVAILABLE].text = LOCALIZE (L"Opponents_StatusAvailable"); |
11 | pmbaty | 277 | handlestatus[HANDLESTATUS_INGAME].icon = W32LoadIcon (L"%s/data/icons/ingame.ico", app_path); |
278 | handlestatus[HANDLESTATUS_INGAME].bitmap = W32LoadImage (L"%s/data/status/ingame.bmp", app_path); |
||
1 | pmbaty | 279 | handlestatus[HANDLESTATUS_INGAME].text = LOCALIZE (L"Opponents_StatusInGame"); |
11 | pmbaty | 280 | handlestatus[HANDLESTATUS_INSIMULATION].icon = W32LoadIcon (L"%s/data/icons/insimulation.ico", app_path); |
281 | handlestatus[HANDLESTATUS_INSIMULATION].bitmap = W32LoadImage (L"%s/data/status/insimulation.bmp", app_path); |
||
1 | pmbaty | 282 | handlestatus[HANDLESTATUS_INSIMULATION].text = LOCALIZE (L"Opponents_StatusInSimulation"); |
11 | pmbaty | 283 | handlestatus[HANDLESTATUS_INTOURNAMENT].icon = W32LoadIcon (L"%s/data/icons/intournament.ico", app_path); |
284 | handlestatus[HANDLESTATUS_INTOURNAMENT].bitmap = W32LoadImage (L"%s/data/status/intournament.bmp", app_path); |
||
1 | pmbaty | 285 | handlestatus[HANDLESTATUS_INTOURNAMENT].text = LOCALIZE (L"Opponents_StatusInTournament"); |
11 | pmbaty | 286 | handlestatus[HANDLESTATUS_EXAMININGAGAME].icon = W32LoadIcon (L"%s/data/icons/examiningagame.ico", app_path); |
287 | handlestatus[HANDLESTATUS_EXAMININGAGAME].bitmap = W32LoadImage (L"%s/data/status/examiningagame.bmp", app_path); |
||
1 | pmbaty | 288 | handlestatus[HANDLESTATUS_EXAMININGAGAME].text = LOCALIZE (L"Opponents_StatusExaminingAGame"); |
11 | pmbaty | 289 | handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].icon = W32LoadIcon (L"%s/data/icons/notopenforamatch.ico", app_path); |
290 | handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].bitmap = W32LoadImage (L"%s/data/status/notopenforamatch.bmp", app_path); |
||
1 | pmbaty | 291 | handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].text = LOCALIZE (L"Opponents_StatusNotOpenForAMatch"); |
11 | pmbaty | 292 | handlestatus[HANDLESTATUS_INACTIVEORBUSY].icon = W32LoadIcon (L"%s/data/icons/inactiveorbusy.ico", app_path); |
293 | handlestatus[HANDLESTATUS_INACTIVEORBUSY].bitmap = W32LoadImage (L"%s/data/status/inactiveorbusy.bmp", app_path); |
||
1 | pmbaty | 294 | handlestatus[HANDLESTATUS_INACTIVEORBUSY].text = LOCALIZE (L"Opponents_StatusInactiveOrBusy"); |
11 | pmbaty | 295 | handlestatus[HANDLESTATUS_OFFLINE].icon = W32LoadIcon (L"%s/data/icons/offline.ico", app_path); |
296 | handlestatus[HANDLESTATUS_OFFLINE].bitmap = W32LoadImage (L"%s/data/status/offline.bmp", app_path); |
||
1 | pmbaty | 297 | handlestatus[HANDLESTATUS_OFFLINE].text = LOCALIZE (L"Opponents_StatusOffline"); |
298 | |||
11 | pmbaty | 299 | // load the system fonts |
1 | pmbaty | 300 | hFontChat = CreateFont (17, 0, 0, 0, FW_DONTCARE, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, |
301 | CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Comic Sans MS"); |
||
302 | |||
21 | pmbaty | 303 | // before any rendering is done, it's a good idea to know what time it is |
304 | current_time = ProcessTime (); |
||
305 | |||
1 | pmbaty | 306 | // initialize renderer |
307 | if (!Render_Init ()) |
||
308 | return (-1); // bomb out on error |
||
309 | |||
310 | // load sprites |
||
11 | pmbaty | 311 | larrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-left.*", app_path); |
312 | rarrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-right.*", app_path); |
||
313 | chatbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/chat.*", app_path); |
||
314 | gamesbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/games.*", app_path); |
||
315 | peoplebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/people.*", app_path); |
||
316 | sepia_spriteindex = Render_LoadSprite (L"%s/data/sprites/sepia.*", app_path); |
||
1 | pmbaty | 317 | for (array_index = 0; array_index < 12; array_index++) |
11 | pmbaty | 318 | spinner_spriteindex[array_index] = Render_LoadSprite (L"%s/data/sprites/spinner-%d.png", app_path, array_index * 30); // spinning wheel |
1 | pmbaty | 319 | |
11 | pmbaty | 320 | // add our custom fonts to the list of available fonts for the duration of the process |
321 | swprintf_s (font_pathname, WCHAR_SIZEOF (font_pathname), L"%s/data/fonts/papyrus.ttf", app_path); |
||
322 | AddFontResourceEx (font_pathname, FR_PRIVATE, 0); |
||
323 | // load rendered fonts |
||
18 | pmbaty | 324 | arrow_fontindex = Render_LoadFont (L"Papyrus", 24, false, false); |
325 | chat_fontindex = Render_LoadFont (L"Papyrus", 32, false, false); |
||
326 | players_fontindex = Render_LoadFont (L"Papyrus", 40, false, true); |
||
327 | centermsg_fontindex = Render_LoadFont (L"Papyrus", 54, false, true); |
||
1 | pmbaty | 328 | |
329 | // load themes, initialize a new human vs. human game and setup the scene |
||
330 | if (!Themes_Init ()) |
||
331 | return (-1); // bomb out on error |
||
332 | Board_Init (&the_board, PLAYER_HUMAN, PLAYER_HUMAN, FENSTARTUP_STANDARDCHESS); |
||
333 | Scene_Init (&the_scene, &the_board); |
||
334 | |||
335 | // has a filename been specifed on the command-line AND that file exists ? |
||
336 | if ((lpCmdLine != NULL) && (lpCmdLine[0] != 0)) |
||
337 | { |
||
338 | while (*lpCmdLine == '"') |
||
339 | lpCmdLine++; // skip leading quotes |
||
340 | if ((endptr = strchr (lpCmdLine, '"')) != NULL) |
||
341 | *endptr = 0; // break the string at the first ending quote |
||
41 | pmbaty | 342 | |
50 | pmbaty | 343 | // is it a file that exists ? |
344 | if (_stat (lpCmdLine, &fileinfo) == 0) |
||
345 | { |
||
346 | ConvertToWideChar (load_pathname, WCHAR_SIZEOF (load_pathname), lpCmdLine); // save pathname string |
||
347 | is_dialogbox_load_validated = true; // and act as if the user just validated a load dialog box |
||
348 | } |
||
41 | pmbaty | 349 | #ifndef NDEBUG |
50 | pmbaty | 350 | // else is it a registration info ? if so, parse it |
351 | else if ((strncmp (lpCmdLine, "/r=", 3) == 0) && ((endptr = strchr (&lpCmdLine[3], ',')) != NULL)) |
||
41 | pmbaty | 352 | { |
353 | *endptr = 0; // break the string at the separator between user email and activation code |
||
354 | ConvertToWideChar (temp_string, WCHAR_SIZEOF (temp_string), &lpCmdLine[3]); // read user email |
||
355 | is_registered = IsRegistrationCorrect (temp_string, atoi (endptr + 1)); // and see whether we're registered or not |
||
356 | DialogBox_NewGame (); // still open the "new game" dialog box |
||
357 | } |
||
358 | #endif // !NDEBUG |
||
1 | pmbaty | 359 | else |
360 | DialogBox_NewGame (); // if specified filename doesn't exist, fallback to the "new game" dialog box |
||
361 | } |
||
362 | else |
||
363 | DialogBox_NewGame (); // when no filename is specified, display the new game dialog box |
||
364 | |||
365 | // enter the main loop |
||
366 | while (!terminate_everything) |
||
367 | { |
||
368 | // see what time it is |
||
369 | current_time = ProcessTime (); |
||
370 | |||
371 | // are we in demo mode and is it time to quit ? |
||
14 | pmbaty | 372 | if (!is_registered && (current_time > DEMO_TIMEOUT)) |
18 | pmbaty | 373 | DestroyWindow (hMainWnd); // if so, send a quit message in order to break the loop |
1 | pmbaty | 374 | |
375 | // grab the current window size |
||
376 | GetWindowRect (hMainWnd, &rect); |
||
377 | options.window_width = rect.right - rect.left; |
||
378 | options.window_height = rect.bottom - rect.top; |
||
379 | |||
380 | // are we in the middle of an animation or just after it ? |
||
381 | if (current_time < animation_endtime + 0.5f) |
||
382 | the_scene.update = true; // always update during animations |
||
383 | else |
||
384 | the_scene.update |= Board_Think (&the_board); // make the board (i.e, both players) think |
||
385 | |||
386 | MainLoop_FindCurrentViewer (); // determine current viewer |
||
387 | |||
388 | // see if we have a message waiting for any window in the current thread and dispatch it |
||
389 | while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) |
||
390 | { |
||
391 | // check for accelerator keystrokes from the main window |
||
392 | if ((msg.hwnd != hMainWnd) || !TranslateAccelerator (hMainWnd, hAccelerators, &msg)) |
||
393 | { |
||
394 | TranslateMessage (&msg); // translate and dispatch all other messages |
||
395 | DispatchMessage (&msg); |
||
396 | } |
||
397 | } |
||
398 | |||
399 | // handle dialog box and window return codes |
||
400 | if (is_dialogbox_about_validated) DialogBox_About_Validated (); |
||
401 | if (is_dialogbox_challenge_validated) DialogBox_Challenge_Validated (); |
||
402 | if (is_dialogbox_changeappearance_validated) DialogBox_ChangeAppearance_Validated (); |
||
403 | if (is_dialogbox_comment_validated) DialogBox_Comment_Validated (); |
||
404 | if (is_dialogbox_endgame_validated) DialogBox_EndGame_Validated (); |
||
405 | if (is_dialogbox_gotomove_validated) DialogBox_GoToMove_Validated (); |
||
406 | if (is_dialogbox_load_validated) DialogBox_Load_Validated (); |
||
407 | if (is_dialogbox_message_validated) DialogBox_Message_Validated (); |
||
408 | if (is_dialogbox_newgame_validated) DialogBox_NewGame_Validated (); |
||
409 | if (is_dialogbox_options_validated) DialogBox_Options_Validated (); |
||
410 | if (is_dialogbox_pawnpromotion_validated) DialogBox_PawnPromotion_Validated (); |
||
411 | if (is_dialogbox_playercard_validated) DialogBox_PlayerCard_Validated (); |
||
412 | if (is_dialogbox_playerinfoname_validated) DialogBox_PlayerInfoName_Validated (); |
||
413 | if (is_dialogbox_quit_validated) DialogBox_Quit_Validated (); |
||
414 | if (is_dialogbox_resign_validated) DialogBox_Resign_Validated (); |
||
415 | if (is_dialogbox_save_validated) DialogBox_Save_Validated (); |
||
416 | if (is_dialogbox_saveposition_validated) DialogBox_SavePosition_Validated (); |
||
417 | if (is_dialogbox_sendchallenge_validated) DialogBox_SendChallenge_Validated (); |
||
418 | if (is_dialogbox_sendseek_validated) DialogBox_SendSeek_Validated (); |
||
419 | if (is_dialogbox_takeback_validated) DialogBox_Takeback_Validated (); |
||
420 | if (is_window_chat_validated) Window_Chat_Validated (); |
||
421 | if (is_window_chatterchannels_validated) Window_ChatterChannels_Validated (); |
||
422 | if (is_window_games_validated) Window_Games_Validated (); |
||
423 | if (is_window_motd_validated) Window_MOTD_Validated (); |
||
424 | if (is_window_opponents_validated) Window_Opponents_Validated (); |
||
425 | if (is_window_sought_validated) Window_Sought_Validated (); |
||
426 | |||
427 | MainLoop_EvaluateGameState (); // evaluate game state |
||
428 | |||
429 | // is the table rotating ? |
||
430 | if (Player_RotateTable (&the_board.players[current_viewer], current_time - previous_time)) |
||
431 | the_scene.update = true; // if so, update the scene |
||
432 | |||
433 | // are we highlighting something ? |
||
434 | if (highlight_endtime > current_time) |
||
435 | the_scene.update = true; // if so, update the scene |
||
436 | |||
437 | // else if we WERE just highlighting something, clear the hovered positions |
||
438 | else if (highlight_endtime + 0.1f > current_time) |
||
439 | { |
||
440 | the_board.hovered_position[0] = -1; |
||
441 | the_board.hovered_position[1] = -1; |
||
442 | the_scene.update = true; // and update the scene |
||
443 | } |
||
444 | |||
445 | // if we want the game clock, update scene every second |
||
446 | if (options.want_clock && ((int) current_time != (int) previous_time)) |
||
447 | the_scene.update = true; |
||
448 | |||
449 | // if there's something in the central text buffer, update scene too |
||
450 | if (the_scene.gui.central_text.is_displayed) |
||
451 | the_scene.update = true; |
||
452 | |||
453 | // if we have a spinning wheel, update scene too |
||
454 | if (the_scene.gui.want_spinwheel) |
||
455 | the_scene.update = true; |
||
456 | |||
457 | // do we NOT need to update the scene ? |
||
458 | if (!the_scene.update) |
||
459 | { |
||
460 | // cycle through all themes and see if one of them needs to be loaded |
||
461 | for (array_index = 0; array_index < theme_count; array_index++) |
||
462 | if (!themes[array_index].is_loaded) |
||
463 | { |
||
464 | Theme_Load (&themes[array_index], false); // load a bit more of this theme |
||
465 | break; // and stop looping (see you next pass) |
||
466 | } |
||
467 | } |
||
468 | |||
469 | // do we need to update the scene ? |
||
470 | if (the_scene.update || want_framerate) |
||
471 | { |
||
472 | Scene_Update (&the_scene, &the_board); // evaluate which parts need to be placed |
||
473 | Render_RenderFrame (&the_scene); // render a game frame |
||
474 | |||
475 | the_scene.update = false; // scene no longer needs to be updated now |
||
476 | } |
||
477 | |||
478 | Audio_Think (); // ensure audio is playing |
||
479 | |||
480 | previous_time = current_time; // save previous time |
||
481 | if (frame_count == 100) |
||
482 | { |
||
483 | frame_count = 0; // reset frame count every 100 frames |
||
484 | Sleep (1); // once every 100 frames, wait a millisecond |
||
485 | } |
||
486 | else |
||
487 | Sleep (0); // else just allow context switching |
||
488 | frame_count++; // increase the frame count |
||
489 | } |
||
490 | |||
491 | ///////////////////////////////////////////////////////////////////////// |
||
492 | // at this point, we exited the main loop and we are returning to Windows |
||
493 | |||
494 | // release scene, game, themes and shutdown Direct3D |
||
495 | Scene_Shutdown (&the_scene); |
||
496 | Board_Shutdown (&the_board); |
||
497 | Themes_Shutdown (); |
||
498 | Render_Shutdown (); |
||
499 | |||
500 | // delete the font resources |
||
501 | DeleteObject (hFontChat); |
||
502 | |||
503 | // delete the bitmap and icon ressources |
||
504 | for (array_index = 1; array_index < sizeof (handlestatus) / sizeof (handlestatus[0]); array_index++) |
||
505 | { |
||
506 | DeleteObject (handlestatus[array_index].bitmap); |
||
507 | DestroyIcon (handlestatus[array_index].icon); |
||
508 | } |
||
509 | |||
510 | // unregister window class |
||
511 | UnregisterClass (wc.lpszClassName, hAppInstance); |
||
512 | |||
513 | // destroy the accelerators table |
||
514 | if (hAccelerators) |
||
515 | DestroyAcceleratorTable (hAccelerators); |
||
516 | hAccelerators = NULL; |
||
517 | |||
518 | // destroy the game menu |
||
519 | if (IsMenu (hMenu)) |
||
520 | DestroyMenu (hMenu); |
||
521 | hMenu = NULL; |
||
522 | |||
14 | pmbaty | 523 | // are we not registered yet ? |
524 | if (!is_registered) |
||
525 | DialogBox_Registration (); |
||
526 | |||
1 | pmbaty | 527 | // save configuration data |
528 | Config_Save (); |
||
529 | |||
530 | // unload localized texts |
||
531 | LocalizedTexts_Shutdown (); |
||
532 | |||
533 | return (0); // and return to Windows. |
||
534 | } |
||
535 | |||
536 | |||
537 | static void MainLoop_FindCurrentViewer (void) |
||
538 | { |
||
539 | // helper function that tells who is the current viewer |
||
540 | |||
541 | if ((the_board.players[COLOR_WHITE].type == PLAYER_HUMAN) && (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN)) |
||
542 | current_viewer = Board_ColorToMove (&the_board); // if both players are human, track them both |
||
543 | else if (the_board.players[COLOR_WHITE].type == PLAYER_HUMAN) |
||
544 | current_viewer = COLOR_WHITE; // else if only the white is human, track the white |
||
545 | else if (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN) |
||
546 | current_viewer = COLOR_BLACK; // else if it's the black, track the black |
||
547 | else |
||
548 | current_viewer = COLOR_WHITE; // else no human in game, track just the white |
||
549 | |||
550 | return; // finished, current viewer is known |
||
551 | } |
||
552 | |||
553 | |||
554 | static void MainLoop_EvaluateGameState (void) |
||
555 | { |
||
556 | // function to evaluate the game state in the main loop when a part has just moved |
||
557 | |||
41 | pmbaty | 558 | static wchar_t window_title[256]; |
559 | |||
1 | pmbaty | 560 | player_t *current_player; |
561 | player_t *opposite_player; |
||
562 | player_t *network_player; |
||
563 | boardmove_t *last_move; |
||
564 | int enabled_value; |
||
565 | int move_index; |
||
566 | |||
567 | if (!the_board.reevaluate) |
||
568 | return; // if the board doesn't need to be reevaluated, don't do anything |
||
569 | |||
570 | // get current and opposite players |
||
571 | current_player = Player_GetCurrent (); |
||
572 | opposite_player = Player_GetOpposite (); |
||
573 | |||
574 | // see if we're online |
||
575 | network_player = Player_FindByType (PLAYER_INTERNET); |
||
576 | |||
577 | // has the game started ? |
||
578 | if (the_board.move_count > 1) |
||
579 | { |
||
580 | // game has started, enable the "save" and "save as" menu options |
||
581 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_ENABLED); |
||
582 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_ENABLED); |
||
583 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED); |
||
584 | |||
585 | // enable the "go to move" menu option |
||
586 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_ENABLED); |
||
587 | |||
588 | // are we watching the last move ? |
||
589 | if (the_board.viewed_move == the_board.move_count - 1) |
||
590 | { |
||
591 | // get a quick acccess to the last move |
||
592 | last_move = &the_board.moves[the_board.move_count - 1]; |
||
593 | |||
50 | pmbaty | 594 | // if the current player is a human AND its opponent is a computer, allow him to ask us for a hint |
595 | if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER)) |
||
1 | pmbaty | 596 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_ENABLED); |
597 | else |
||
598 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_GRAYED); |
||
599 | |||
600 | // (if the current player is a human |
||
601 | // AND (its opponent is another human AND there's at least one move played) |
||
602 | // OR (its opponent is a computer AND there are at least two moves played) |
||
603 | // OR (its opponent is a remote player AND we're in game AND there are at least two moves played)) |
||
604 | // OR the current player is a remote player AND we're in game AND there are at least two moves played), allow him to cancel move |
||
605 | if (((current_player->type == PLAYER_HUMAN) |
||
606 | && ((opposite_player->type == PLAYER_HUMAN) |
||
607 | || ((opposite_player->type == PLAYER_COMPUTER) && (the_board.move_count > 2)) |
||
608 | || ((opposite_player->type == PLAYER_INTERNET) && (opposite_player->is_in_game) && (the_board.move_count > 2)))) |
||
609 | || ((current_player->type == PLAYER_INTERNET) && (current_player->is_in_game) && (the_board.move_count > 2))) |
||
610 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_ENABLED); |
||
611 | else |
||
612 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_GRAYED); |
||
613 | |||
614 | // is the current player in check ? (to play the right sound) |
||
615 | // read as: was the last move an opponent's move AND did it put us to check ? |
||
616 | if (last_move->is_check) |
||
617 | { |
||
618 | // is it a checkmate ? (checkmate == check + stalemate) |
||
619 | if (last_move->is_stalemate) |
||
620 | { |
||
621 | // display the game over dialog box |
||
622 | the_board.game_state = (Board_ColorToMove (&the_board) == COLOR_WHITE ? STATE_BLACKWIN_CHECKMATE : STATE_WHITEWIN_CHECKMATE); |
||
623 | DialogBox_EndGame (); |
||
624 | } |
||
625 | } |
||
626 | else |
||
627 | { |
||
628 | // is it a stalemate ? |
||
629 | if (last_move->is_stalemate) |
||
630 | { |
||
631 | // display the game over dialog box |
||
632 | the_board.game_state = STATE_DRAW_STALEMATE; |
||
633 | DialogBox_EndGame (); |
||
634 | } |
||
635 | } |
||
636 | |||
637 | // have there 50 moves been played each side (i.e, 100 plies) AND is the current player human ? |
||
638 | if ((the_board.move_count > 100) && (current_player->type == PLAYER_HUMAN)) |
||
639 | { |
||
640 | // go backwards and see when is the latest move that took an opponent's piece OR the latest pawn move |
||
641 | for (move_index = the_board.move_count - 1; move_index >= 0; move_index--) |
||
642 | if (the_board.moves[move_index].has_captured || (the_board.moves[move_index].part == PART_PAWN)) |
||
643 | break; // stop as soon as we find one |
||
644 | |||
645 | // can the fifty moves draw rule be claimed AND does the current player claims it ? |
||
646 | if (move_index + 1 + 100 < the_board.move_count) |
||
647 | { |
||
648 | // yes. Propose it to the side that's on move |
||
649 | // TODO: non-modal MessageBox (copy dialog_newgame.cpp and use return values) |
||
650 | } |
||
651 | } |
||
652 | |||
653 | if (the_scene.gui.larrow.state == 0) |
||
654 | the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet |
||
655 | if (the_scene.gui.rarrow.state != 0) |
||
656 | the_scene.gui.rarrow.state = 0; // disable "forward" arrow if it's already displayed |
||
657 | |||
658 | if (the_board.game_state == STATE_PLAYING) |
||
659 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
660 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Current")); |
||
661 | else if ((the_board.game_state == STATE_BLACKWIN_CHECKMATE) || (the_board.game_state == STATE_WHITEWIN_CHECKMATE)) |
||
662 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
663 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_CheckMate")); |
||
664 | else if ((the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT) || (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT)) |
||
665 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
666 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_Resign")); |
||
667 | else if (the_board.game_state == STATE_DRAW_STALEMATE) |
||
668 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
669 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_StaleMate")); |
||
670 | else if (the_board.game_state == STATE_DRAW_AGREEMENT) |
||
671 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
672 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_Agreement")); |
||
673 | else if (the_board.game_state == STATE_DRAW_OTHER) |
||
674 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
675 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_DrawOther")); |
||
676 | |||
677 | // enable the "comment on this move" menu option |
||
678 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_ENABLED); |
||
679 | } |
||
680 | |||
681 | // else are we watching another move, but not the beginning of the game ? |
||
682 | else if (the_board.viewed_move > 0) |
||
683 | { |
||
684 | if (the_scene.gui.larrow.state == 0) |
||
685 | the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet |
||
686 | if (the_scene.gui.rarrow.state == 0) |
||
687 | the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet |
||
688 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
689 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, |
||
18 | pmbaty | 690 | L"%s %d\n%s", LOCALIZE (L"Move"), (the_board.viewed_move + 1) / 2, (the_board.viewed_move % 2 ? LOCALIZE (L"Games_White"): LOCALIZE (L"Games_Black"))); |
1 | pmbaty | 691 | |
692 | // enable the "save position as" and "comment on this move" menu options |
||
693 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED); |
||
694 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_ENABLED); |
||
695 | } |
||
696 | |||
697 | // else we must be watching the beginning of the game (no move yet) |
||
698 | else |
||
699 | { |
||
700 | if (the_scene.gui.larrow.state != 0) |
||
701 | the_scene.gui.larrow.state = 0; // disable "back" arrow if it's already displayed |
||
702 | if (the_scene.gui.rarrow.state == 0) |
||
703 | the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet |
||
704 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
705 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Beginning")); |
||
706 | |||
707 | // disable the "save position as" and "comment on this move" menu options |
||
708 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED); |
||
709 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_GRAYED); |
||
710 | } |
||
711 | } |
||
712 | else |
||
713 | { |
||
714 | // game has not started, disable the "save", "save as" and "save position as" menu options |
||
715 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_GRAYED); |
||
716 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_GRAYED); |
||
717 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED); |
||
718 | |||
52 | pmbaty | 719 | // if the current player is a human AND its opponent is a computer, allow him to ask us for a hint |
720 | if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER)) |
||
721 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_ENABLED); |
||
722 | else |
||
723 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_GRAYED); |
||
724 | |||
725 | // disable the "cancel last move", "comment move" and "go to move" menu options |
||
1 | pmbaty | 726 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_GRAYED); |
727 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_GRAYED); |
||
728 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_GRAYED); |
||
729 | |||
730 | // and disable the two arrows and the arrow text |
||
731 | the_scene.gui.larrow.state = 0; |
||
732 | the_scene.gui.rarrow.state = 0; |
||
733 | the_scene.gui.arrow_text.is_displayed = false; |
||
734 | } |
||
735 | |||
736 | // no matter whether the game started or not, if the current player is a human AND its opponent is a computer, allow him to swap sides |
||
737 | if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER)) |
||
738 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_ENABLED); |
||
739 | else |
||
740 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_GRAYED); |
||
741 | |||
742 | // update window title |
||
743 | if ((the_board.players[COLOR_WHITE].name[0] != 0) && (the_board.players[COLOR_BLACK].name[0] != 0)) |
||
744 | { |
||
14 | pmbaty | 745 | swprintf_s (window_title, WCHAR_SIZEOF (window_title), L"%s %s %s - " PROGRAM_NAME L"%s", the_board.players[COLOR_WHITE].name, LOCALIZE (L"Versus"), the_board.players[COLOR_BLACK].name, (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); |
1 | pmbaty | 746 | SetWindowText (hMainWnd, window_title); // update window title |
747 | } |
||
748 | else if (the_board.players[COLOR_WHITE].name[0] != 0) |
||
749 | { |
||
14 | pmbaty | 750 | swprintf_s (window_title, WCHAR_SIZEOF (window_title), L"%s - " PROGRAM_NAME L"%s", the_board.players[COLOR_WHITE].name, (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); |
1 | pmbaty | 751 | SetWindowText (hMainWnd, window_title); // update window title |
752 | } |
||
753 | |||
754 | // are we in internet mode AND are we logged in ? |
||
755 | if ((network_player != NULL) && network_player->is_logged_in) |
||
756 | { |
||
757 | // are we currently playing a game ? |
||
758 | if (network_player->is_in_game) |
||
759 | { |
||
760 | GUIBUTTON_ENABLE (the_scene.gui.chatbutton); // enable chat button if it's not enabled yet |
||
761 | GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled |
||
762 | GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled |
||
763 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_ENABLED); // allow resigning |
||
764 | } |
||
765 | else |
||
766 | { |
||
767 | GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled |
||
768 | GUIBUTTON_ENABLE (the_scene.gui.gamesbutton); // enable games button if it's not enabled yet |
||
769 | GUIBUTTON_ENABLE (the_scene.gui.peoplebutton); // enable people button if it's not enabled yet |
||
770 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_GRAYED); // disable ability to resign |
||
771 | } |
||
772 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_ENABLED); // enable stats |
||
773 | |||
774 | enabled_value = MF_ENABLED; // remember to enable the internet-related menu items |
||
775 | } |
||
776 | // else it's a local or vs. computer game |
||
777 | else |
||
778 | { |
||
779 | GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled |
||
780 | GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled |
||
781 | GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled |
||
782 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_ENABLED); // allow resigning |
||
783 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_GRAYED); // disable stats |
||
784 | |||
785 | enabled_value = MF_GRAYED; // remember to disable the internet-related menu items |
||
786 | } |
||
787 | |||
788 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SETUPPOSITION, !enabled_value); // note the inversion |
||
789 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWONLINEPLAYERS, enabled_value); |
||
790 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWSOUGHTGAMES, enabled_value); |
||
791 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SEEKGAME, enabled_value); |
||
792 | if (!options.network.want_publicchat) |
||
793 | { |
||
794 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, MF_GRAYED); // always grayed if we don't want public chat |
||
795 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, MF_GRAYED); |
||
796 | } |
||
797 | else |
||
798 | { |
||
799 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, enabled_value); // else enabled only in internet mode |
||
800 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, enabled_value); |
||
801 | } |
||
802 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYPLAYERCARD, enabled_value); |
||
803 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYYOURCARD, enabled_value); |
||
804 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_MOTD, enabled_value); |
||
805 | |||
806 | the_board.reevaluate = false; // board evaluation has been done |
||
807 | return; // finished, new board state is known |
||
808 | } |