Rev 56 | Rev 60 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 56 | Rev 59 | ||
---|---|---|---|
Line 22... | Line 22... | ||
22 | MENUINFO menu_info; |
22 | MENUINFO menu_info; |
23 | MSG msg; |
23 | MSG msg; |
24 | HBITMAP hSplashBmp; |
24 | HBITMAP hSplashBmp; |
25 | BITMAP splash_bmp; |
25 | BITMAP splash_bmp; |
26 | HDC hdc; |
26 | HDC hdc; |
27 | HMENU hMenu; |
- | |
28 | HMENU hDropDownMenu; |
- | |
29 | RECT rect; |
27 | RECT rect; |
30 | PAINTSTRUCT ps; |
28 | PAINTSTRUCT ps; |
31 | HBITMAP hbmTmp; |
29 | HBITMAP hbmTmp; |
32 | HDC hdcMem; |
30 | HDC hdcMem; |
33 | float previous_time; |
31 | float previous_time; |
34 | int frame_count; |
32 | int frame_count; |
35 | int array_index; |
33 | int array_index; |
36 | bool is_success; |
- | |
37 | char *endptr; |
34 | char *endptr; |
38 | wchar_t app_pathname[MAX_PATH]; |
35 | wchar_t app_pathname[MAX_PATH]; |
39 | wchar_t font_pathname[MAX_PATH]; |
36 | wchar_t font_pathname[MAX_PATH]; |
40 | wchar_t temp_string[100]; |
37 | wchar_t temp_string[100]; |
41 | struct _stat fileinfo; |
38 | 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 | 39 | ||
68 | // save application instance |
40 | // save application instance |
69 | hAppInstance = hInstance; |
41 | hAppInstance = hInstance; |
70 | 42 | ||
71 | // find module and path names, and *IMPORTANT*, set the current working directory there |
43 | // find module and path names, and *IMPORTANT*, set the current working directory there |
Line 119... | Line 91... | ||
119 | command_ignoretime = 0.0f; |
91 | command_ignoretime = 0.0f; |
120 | sound_playtime = 0.0f; |
92 | sound_playtime = 0.0f; |
121 | highlight_endtime = 0.0f; |
93 | highlight_endtime = 0.0f; |
122 | previous_time = 0.0f; |
94 | previous_time = 0.0f; |
123 | frame_count = 0; |
95 | frame_count = 0; |
124 | 96 | ||
- | 97 | // load the texts and ensure we have at least one display language |
|
- | 98 | LocalizedTexts_Init (); |
|
- | 99 | if (language_count < 1) |
|
- | 100 | { |
|
- | 101 | 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); |
|
- | 102 | return (-1); // bomb out on error |
|
- | 103 | } |
|
- | 104 | ||
125 | // read configuration data |
105 | // read configuration data |
126 | Config_Load (); |
106 | Config_Load (); |
127 | 107 | ||
128 | // see if the program is registered |
108 | // see if the program is registered |
129 | is_registered = IsRegistrationCorrect (options.registration.user_email, options.registration.activation_code); |
109 | is_registered = IsRegistrationCorrect (options.registration.user_email, options.registration.activation_code); |
130 | - | ||
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)); |
- | |
134 | is_success = LocalizedTexts_Init (L"%s/data/languages/%s.ini", app_path, os_language); |
- | |
135 | - | ||
136 | // fallback to English if language not found |
- | |
137 | if (!is_success) |
- | |
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 | } |
- | |
142 | - | ||
143 | // consistency check: don't go further if texts aren't available |
- | |
144 | if (!is_success) |
- | |
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); |
- | |
147 | return (-1); // bomb out on error |
- | |
148 | } |
- | |
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); |
- | |
204 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYVISUALTHEMES, LOCALIZE (L"Menu_HelpAddModifyThemes")); |
- | |
205 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYENGINES, LOCALIZE (L"Menu_HelpAddModifyEngines")); |
- | |
206 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYTRANSLATIONS, LOCALIZE (L"Menu_HelpAddModifyTranslations")); |
- | |
207 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
- | |
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 | 110 | ||
215 | // register the window class, create the window and show it |
111 | // register the window class, create the window and show it |
216 | memset (&wc, 0, sizeof (wc)); |
112 | memset (&wc, 0, sizeof (wc)); |
217 | wc.cbSize = sizeof (wc); |
113 | wc.cbSize = sizeof (wc); |
218 | wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; // double-clicks support |
114 | wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; // double-clicks support |
Line 223... | Line 119... | ||
223 | wc.lpszClassName = PROGRAM_NAME L" WndClass"; |
119 | wc.lpszClassName = PROGRAM_NAME L" WndClass"; |
224 | RegisterClassEx (&wc); |
120 | RegisterClassEx (&wc); |
225 | swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), PROGRAM_NAME L"%s", (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); // build window title |
121 | swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), PROGRAM_NAME L"%s", (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); // build window title |
226 | if (options.want_fullscreen) |
122 | if (options.want_fullscreen) |
227 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_POPUPWINDOW, // temp_string holds window title |
123 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_POPUPWINDOW, // temp_string holds window title |
228 | 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), |
124 | 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), NULL, NULL, hAppInstance, NULL); |
229 | NULL, hMenu, hAppInstance, NULL); |
- | |
230 | else |
125 | else |
231 | { |
126 | { |
232 | // in windowed mode, ensure window width and height aren't greater than screen size nor lower than a safe minimum |
127 | // in windowed mode, ensure window width and height aren't greater than screen size nor lower than a safe minimum |
233 | if (options.window_width > GetSystemMetrics (SM_CXMAXTRACK)) |
128 | if (options.window_width > GetSystemMetrics (SM_CXMAXTRACK)) |
234 | options.window_width = GetSystemMetrics (SM_CXMAXTRACK); // check this first in case screen size is reported incorrect |
129 | options.window_width = GetSystemMetrics (SM_CXMAXTRACK); // check this first in case screen size is reported incorrect |
Line 240... | Line 135... | ||
240 | options.window_height = 480; |
135 | options.window_height = 480; |
241 | 136 | ||
242 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_OVERLAPPEDWINDOW, // temp_string holds window title |
137 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_OVERLAPPEDWINDOW, // temp_string holds window title |
243 | GetSystemMetrics (SM_CXSCREEN) / 2 - options.window_width / 2, |
138 | GetSystemMetrics (SM_CXSCREEN) / 2 - options.window_width / 2, |
244 | GetSystemMetrics (SM_CYSCREEN) / 2 - options.window_height / 2, |
139 | GetSystemMetrics (SM_CYSCREEN) / 2 - options.window_height / 2, |
245 | options.window_width, |
- | |
246 | options.window_height, |
- | |
247 | NULL, |
140 | options.window_width, options.window_height, NULL, NULL, hAppInstance, NULL); |
248 | } |
141 | } |
249 | ShowWindow (hMainWnd, nCmdShow); |
142 | ShowWindow (hMainWnd, nCmdShow); |
- | 143 | ||
- | 144 | // create the main menu line, and its accelerators |
|
- | 145 | hMainMenu = NULL; |
|
- | 146 | hMainAccelerators = NULL; |
|
- | 147 | CreateOrUpdateApplicationMenu (); |
|
250 | 148 | ||
251 | // display the splash screen |
149 | // display the splash screen |
252 | memset ((void *) &splash_bmp, 0, sizeof (splash_bmp)); |
150 | memset ((void *) &splash_bmp, 0, sizeof (splash_bmp)); |
253 | hSplashBmp = W32LoadImage (L"%s/data/splash.bmp", app_path); // load the splash bitmap |
151 | hSplashBmp = W32LoadImage (L"%s/data/splash.bmp", app_path); // load the splash bitmap |
254 | GetObject (hSplashBmp, sizeof (splash_bmp), (void *) &splash_bmp); // get a structure containing its size (among others) |
152 | GetObject (hSplashBmp, sizeof (splash_bmp), (void *) &splash_bmp); // get a structure containing its size (among others) |
Line 387... | Line 285... | ||
387 | 285 | ||
388 | // see if we have a message waiting for any window in the current thread and dispatch it |
286 | // 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)) |
287 | while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) |
390 | { |
288 | { |
391 | // check for accelerator keystrokes from the main window |
289 | // check for accelerator keystrokes from the main window |
392 | if ((msg.hwnd != hMainWnd) || !TranslateAccelerator (hMainWnd, |
290 | if ((msg.hwnd != hMainWnd) || !TranslateAccelerator (hMainWnd, hMainAccelerators, &msg)) |
393 | { |
291 | { |
394 | TranslateMessage (&msg); // translate and dispatch all other messages |
292 | TranslateMessage (&msg); // translate and dispatch all other messages |
395 | DispatchMessage (&msg); |
293 | DispatchMessage (&msg); |
396 | } |
294 | } |
397 | } |
295 | } |
Line 509... | Line 407... | ||
509 | 407 | ||
510 | // unregister window class |
408 | // unregister window class |
511 | UnregisterClass (wc.lpszClassName, hAppInstance); |
409 | UnregisterClass (wc.lpszClassName, hAppInstance); |
512 | 410 | ||
513 | // destroy the accelerators table |
411 | // destroy the accelerators table |
514 | if ( |
412 | if (hMainAccelerators) |
515 | DestroyAcceleratorTable ( |
413 | DestroyAcceleratorTable (hMainAccelerators); |
516 |
|
414 | hMainAccelerators = NULL; |
517 | 415 | ||
518 | // destroy the |
416 | // destroy the application menu object |
519 | if (IsMenu ( |
417 | if (IsMenu (hMainMenu)) |
520 | DestroyMenu ( |
418 | DestroyMenu (hMainMenu); |
521 |
|
419 | hMainMenu = NULL; |
522 | 420 | ||
523 | // are we not registered yet ? |
421 | // are we not registered yet ? |
524 | if (!is_registered) |
422 | if (!is_registered) |
525 | DialogBox_Registration (); |
423 | DialogBox_Registration (); |
526 | 424 |