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