Rev 21 | Rev 41 | 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]; |
14 | pmbaty | 40 | wchar_t window_title[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); |
||
14 | pmbaty | 221 | swprintf_s (window_title, WCHAR_SIZEOF (window_title), PROGRAM_NAME L"%s", (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); |
1 | pmbaty | 222 | if (options.want_fullscreen) |
14 | pmbaty | 223 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, window_title, WS_POPUPWINDOW, |
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 | |
14 | pmbaty | 238 | hMainWnd = CreateWindowEx (0, wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, |
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 |
||
338 | if (_stat (lpCmdLine, &fileinfo) == 0) |
||
339 | { |
||
340 | ConvertToWideChar (load_pathname, WCHAR_SIZEOF (load_pathname), lpCmdLine); // save pathname string |
||
341 | is_dialogbox_load_validated = true; // and act as if the user just validated a load dialog box |
||
342 | } |
||
343 | else |
||
344 | DialogBox_NewGame (); // if specified filename doesn't exist, fallback to the "new game" dialog box |
||
345 | } |
||
346 | else |
||
347 | DialogBox_NewGame (); // when no filename is specified, display the new game dialog box |
||
348 | |||
349 | // enter the main loop |
||
350 | while (!terminate_everything) |
||
351 | { |
||
352 | // see what time it is |
||
353 | current_time = ProcessTime (); |
||
354 | |||
355 | // are we in demo mode and is it time to quit ? |
||
14 | pmbaty | 356 | if (!is_registered && (current_time > DEMO_TIMEOUT)) |
18 | pmbaty | 357 | DestroyWindow (hMainWnd); // if so, send a quit message in order to break the loop |
1 | pmbaty | 358 | |
359 | // grab the current window size |
||
360 | GetWindowRect (hMainWnd, &rect); |
||
361 | options.window_width = rect.right - rect.left; |
||
362 | options.window_height = rect.bottom - rect.top; |
||
363 | |||
364 | // are we in the middle of an animation or just after it ? |
||
365 | if (current_time < animation_endtime + 0.5f) |
||
366 | the_scene.update = true; // always update during animations |
||
367 | else |
||
368 | the_scene.update |= Board_Think (&the_board); // make the board (i.e, both players) think |
||
369 | |||
370 | MainLoop_FindCurrentViewer (); // determine current viewer |
||
371 | |||
372 | // see if we have a message waiting for any window in the current thread and dispatch it |
||
373 | while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) |
||
374 | { |
||
375 | // check for accelerator keystrokes from the main window |
||
376 | if ((msg.hwnd != hMainWnd) || !TranslateAccelerator (hMainWnd, hAccelerators, &msg)) |
||
377 | { |
||
378 | TranslateMessage (&msg); // translate and dispatch all other messages |
||
379 | DispatchMessage (&msg); |
||
380 | } |
||
381 | } |
||
382 | |||
383 | // handle dialog box and window return codes |
||
384 | if (is_dialogbox_about_validated) DialogBox_About_Validated (); |
||
385 | if (is_dialogbox_challenge_validated) DialogBox_Challenge_Validated (); |
||
386 | if (is_dialogbox_changeappearance_validated) DialogBox_ChangeAppearance_Validated (); |
||
387 | if (is_dialogbox_comment_validated) DialogBox_Comment_Validated (); |
||
388 | if (is_dialogbox_endgame_validated) DialogBox_EndGame_Validated (); |
||
389 | if (is_dialogbox_gotomove_validated) DialogBox_GoToMove_Validated (); |
||
390 | if (is_dialogbox_load_validated) DialogBox_Load_Validated (); |
||
391 | if (is_dialogbox_message_validated) DialogBox_Message_Validated (); |
||
392 | if (is_dialogbox_newgame_validated) DialogBox_NewGame_Validated (); |
||
393 | if (is_dialogbox_options_validated) DialogBox_Options_Validated (); |
||
394 | if (is_dialogbox_pawnpromotion_validated) DialogBox_PawnPromotion_Validated (); |
||
395 | if (is_dialogbox_playercard_validated) DialogBox_PlayerCard_Validated (); |
||
396 | if (is_dialogbox_playerinfoname_validated) DialogBox_PlayerInfoName_Validated (); |
||
397 | if (is_dialogbox_quit_validated) DialogBox_Quit_Validated (); |
||
398 | if (is_dialogbox_resign_validated) DialogBox_Resign_Validated (); |
||
399 | if (is_dialogbox_save_validated) DialogBox_Save_Validated (); |
||
400 | if (is_dialogbox_saveposition_validated) DialogBox_SavePosition_Validated (); |
||
401 | if (is_dialogbox_sendchallenge_validated) DialogBox_SendChallenge_Validated (); |
||
402 | if (is_dialogbox_sendseek_validated) DialogBox_SendSeek_Validated (); |
||
403 | if (is_dialogbox_takeback_validated) DialogBox_Takeback_Validated (); |
||
404 | if (is_window_chat_validated) Window_Chat_Validated (); |
||
405 | if (is_window_chatterchannels_validated) Window_ChatterChannels_Validated (); |
||
406 | if (is_window_games_validated) Window_Games_Validated (); |
||
407 | if (is_window_motd_validated) Window_MOTD_Validated (); |
||
408 | if (is_window_opponents_validated) Window_Opponents_Validated (); |
||
409 | if (is_window_sought_validated) Window_Sought_Validated (); |
||
410 | |||
411 | MainLoop_EvaluateGameState (); // evaluate game state |
||
412 | |||
413 | // is the table rotating ? |
||
414 | if (Player_RotateTable (&the_board.players[current_viewer], current_time - previous_time)) |
||
415 | the_scene.update = true; // if so, update the scene |
||
416 | |||
417 | // are we highlighting something ? |
||
418 | if (highlight_endtime > current_time) |
||
419 | the_scene.update = true; // if so, update the scene |
||
420 | |||
421 | // else if we WERE just highlighting something, clear the hovered positions |
||
422 | else if (highlight_endtime + 0.1f > current_time) |
||
423 | { |
||
424 | the_board.hovered_position[0] = -1; |
||
425 | the_board.hovered_position[1] = -1; |
||
426 | the_scene.update = true; // and update the scene |
||
427 | } |
||
428 | |||
429 | // if we want the game clock, update scene every second |
||
430 | if (options.want_clock && ((int) current_time != (int) previous_time)) |
||
431 | the_scene.update = true; |
||
432 | |||
433 | // if there's something in the central text buffer, update scene too |
||
434 | if (the_scene.gui.central_text.is_displayed) |
||
435 | the_scene.update = true; |
||
436 | |||
437 | // if we have a spinning wheel, update scene too |
||
438 | if (the_scene.gui.want_spinwheel) |
||
439 | the_scene.update = true; |
||
440 | |||
441 | // do we NOT need to update the scene ? |
||
442 | if (!the_scene.update) |
||
443 | { |
||
444 | // cycle through all themes and see if one of them needs to be loaded |
||
445 | for (array_index = 0; array_index < theme_count; array_index++) |
||
446 | if (!themes[array_index].is_loaded) |
||
447 | { |
||
448 | Theme_Load (&themes[array_index], false); // load a bit more of this theme |
||
449 | break; // and stop looping (see you next pass) |
||
450 | } |
||
451 | } |
||
452 | |||
453 | // do we need to update the scene ? |
||
454 | if (the_scene.update || want_framerate) |
||
455 | { |
||
456 | Scene_Update (&the_scene, &the_board); // evaluate which parts need to be placed |
||
457 | Render_RenderFrame (&the_scene); // render a game frame |
||
458 | |||
459 | the_scene.update = false; // scene no longer needs to be updated now |
||
460 | } |
||
461 | |||
462 | Audio_Think (); // ensure audio is playing |
||
463 | |||
464 | previous_time = current_time; // save previous time |
||
465 | if (frame_count == 100) |
||
466 | { |
||
467 | frame_count = 0; // reset frame count every 100 frames |
||
468 | Sleep (1); // once every 100 frames, wait a millisecond |
||
469 | } |
||
470 | else |
||
471 | Sleep (0); // else just allow context switching |
||
472 | frame_count++; // increase the frame count |
||
473 | } |
||
474 | |||
475 | ///////////////////////////////////////////////////////////////////////// |
||
476 | // at this point, we exited the main loop and we are returning to Windows |
||
477 | |||
478 | // release scene, game, themes and shutdown Direct3D |
||
479 | Scene_Shutdown (&the_scene); |
||
480 | Board_Shutdown (&the_board); |
||
481 | Themes_Shutdown (); |
||
482 | Render_Shutdown (); |
||
483 | |||
484 | // delete the font resources |
||
485 | DeleteObject (hFontChat); |
||
486 | |||
487 | // delete the bitmap and icon ressources |
||
488 | for (array_index = 1; array_index < sizeof (handlestatus) / sizeof (handlestatus[0]); array_index++) |
||
489 | { |
||
490 | DeleteObject (handlestatus[array_index].bitmap); |
||
491 | DestroyIcon (handlestatus[array_index].icon); |
||
492 | } |
||
493 | |||
494 | // unregister window class |
||
495 | UnregisterClass (wc.lpszClassName, hAppInstance); |
||
496 | |||
497 | // destroy the accelerators table |
||
498 | if (hAccelerators) |
||
499 | DestroyAcceleratorTable (hAccelerators); |
||
500 | hAccelerators = NULL; |
||
501 | |||
502 | // destroy the game menu |
||
503 | if (IsMenu (hMenu)) |
||
504 | DestroyMenu (hMenu); |
||
505 | hMenu = NULL; |
||
506 | |||
14 | pmbaty | 507 | // are we not registered yet ? |
508 | if (!is_registered) |
||
509 | DialogBox_Registration (); |
||
510 | |||
1 | pmbaty | 511 | // save configuration data |
512 | Config_Save (); |
||
513 | |||
514 | // unload localized texts |
||
515 | LocalizedTexts_Shutdown (); |
||
516 | |||
517 | return (0); // and return to Windows. |
||
518 | } |
||
519 | |||
520 | |||
521 | static void MainLoop_FindCurrentViewer (void) |
||
522 | { |
||
523 | // helper function that tells who is the current viewer |
||
524 | |||
525 | if ((the_board.players[COLOR_WHITE].type == PLAYER_HUMAN) && (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN)) |
||
526 | current_viewer = Board_ColorToMove (&the_board); // if both players are human, track them both |
||
527 | else if (the_board.players[COLOR_WHITE].type == PLAYER_HUMAN) |
||
528 | current_viewer = COLOR_WHITE; // else if only the white is human, track the white |
||
529 | else if (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN) |
||
530 | current_viewer = COLOR_BLACK; // else if it's the black, track the black |
||
531 | else |
||
532 | current_viewer = COLOR_WHITE; // else no human in game, track just the white |
||
533 | |||
534 | return; // finished, current viewer is known |
||
535 | } |
||
536 | |||
537 | |||
538 | static void MainLoop_EvaluateGameState (void) |
||
539 | { |
||
540 | // function to evaluate the game state in the main loop when a part has just moved |
||
541 | |||
542 | wchar_t window_title[256]; |
||
543 | player_t *current_player; |
||
544 | player_t *opposite_player; |
||
545 | player_t *network_player; |
||
546 | boardmove_t *last_move; |
||
547 | int enabled_value; |
||
548 | int move_index; |
||
549 | |||
550 | if (!the_board.reevaluate) |
||
551 | return; // if the board doesn't need to be reevaluated, don't do anything |
||
552 | |||
553 | // get current and opposite players |
||
554 | current_player = Player_GetCurrent (); |
||
555 | opposite_player = Player_GetOpposite (); |
||
556 | |||
557 | // see if we're online |
||
558 | network_player = Player_FindByType (PLAYER_INTERNET); |
||
559 | |||
560 | // has the game started ? |
||
561 | if (the_board.move_count > 1) |
||
562 | { |
||
563 | // game has started, enable the "save" and "save as" menu options |
||
564 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_ENABLED); |
||
565 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_ENABLED); |
||
566 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED); |
||
567 | |||
568 | // enable the "go to move" menu option |
||
569 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_ENABLED); |
||
570 | |||
571 | // are we watching the last move ? |
||
572 | if (the_board.viewed_move == the_board.move_count - 1) |
||
573 | { |
||
574 | // get a quick acccess to the last move |
||
575 | last_move = &the_board.moves[the_board.move_count - 1]; |
||
576 | |||
577 | // if the current player is a human AND its opponent is a computer, allow him to ask us for a hint |
||
578 | if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER)) |
||
579 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_ENABLED); |
||
580 | else |
||
581 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_GRAYED); |
||
582 | |||
583 | // (if the current player is a human |
||
584 | // AND (its opponent is another human AND there's at least one move played) |
||
585 | // OR (its opponent is a computer AND there are at least two moves played) |
||
586 | // OR (its opponent is a remote player AND we're in game AND there are at least two moves played)) |
||
587 | // 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 |
||
588 | if (((current_player->type == PLAYER_HUMAN) |
||
589 | && ((opposite_player->type == PLAYER_HUMAN) |
||
590 | || ((opposite_player->type == PLAYER_COMPUTER) && (the_board.move_count > 2)) |
||
591 | || ((opposite_player->type == PLAYER_INTERNET) && (opposite_player->is_in_game) && (the_board.move_count > 2)))) |
||
592 | || ((current_player->type == PLAYER_INTERNET) && (current_player->is_in_game) && (the_board.move_count > 2))) |
||
593 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_ENABLED); |
||
594 | else |
||
595 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_GRAYED); |
||
596 | |||
597 | // is the current player in check ? (to play the right sound) |
||
598 | // read as: was the last move an opponent's move AND did it put us to check ? |
||
599 | if (last_move->is_check) |
||
600 | { |
||
601 | // is it a checkmate ? (checkmate == check + stalemate) |
||
602 | if (last_move->is_stalemate) |
||
603 | { |
||
604 | // display the game over dialog box |
||
605 | the_board.game_state = (Board_ColorToMove (&the_board) == COLOR_WHITE ? STATE_BLACKWIN_CHECKMATE : STATE_WHITEWIN_CHECKMATE); |
||
606 | DialogBox_EndGame (); |
||
607 | } |
||
608 | } |
||
609 | else |
||
610 | { |
||
611 | // is it a stalemate ? |
||
612 | if (last_move->is_stalemate) |
||
613 | { |
||
614 | // display the game over dialog box |
||
615 | the_board.game_state = STATE_DRAW_STALEMATE; |
||
616 | DialogBox_EndGame (); |
||
617 | } |
||
618 | } |
||
619 | |||
620 | // have there 50 moves been played each side (i.e, 100 plies) AND is the current player human ? |
||
621 | if ((the_board.move_count > 100) && (current_player->type == PLAYER_HUMAN)) |
||
622 | { |
||
623 | // go backwards and see when is the latest move that took an opponent's piece OR the latest pawn move |
||
624 | for (move_index = the_board.move_count - 1; move_index >= 0; move_index--) |
||
625 | if (the_board.moves[move_index].has_captured || (the_board.moves[move_index].part == PART_PAWN)) |
||
626 | break; // stop as soon as we find one |
||
627 | |||
628 | // can the fifty moves draw rule be claimed AND does the current player claims it ? |
||
629 | if (move_index + 1 + 100 < the_board.move_count) |
||
630 | { |
||
631 | // yes. Propose it to the side that's on move |
||
632 | // TODO: non-modal MessageBox (copy dialog_newgame.cpp and use return values) |
||
633 | } |
||
634 | } |
||
635 | |||
636 | if (the_scene.gui.larrow.state == 0) |
||
637 | the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet |
||
638 | if (the_scene.gui.rarrow.state != 0) |
||
639 | the_scene.gui.rarrow.state = 0; // disable "forward" arrow if it's already displayed |
||
640 | |||
641 | if (the_board.game_state == STATE_PLAYING) |
||
642 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
643 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Current")); |
||
644 | else if ((the_board.game_state == STATE_BLACKWIN_CHECKMATE) || (the_board.game_state == STATE_WHITEWIN_CHECKMATE)) |
||
645 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
646 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_CheckMate")); |
||
647 | else if ((the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT) || (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT)) |
||
648 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
649 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_Resign")); |
||
650 | else if (the_board.game_state == STATE_DRAW_STALEMATE) |
||
651 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
652 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_StaleMate")); |
||
653 | else if (the_board.game_state == STATE_DRAW_AGREEMENT) |
||
654 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
655 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_Agreement")); |
||
656 | else if (the_board.game_state == STATE_DRAW_OTHER) |
||
657 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
658 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_DrawOther")); |
||
659 | |||
660 | // enable the "comment on this move" menu option |
||
661 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_ENABLED); |
||
662 | } |
||
663 | |||
664 | // else are we watching another move, but not the beginning of the game ? |
||
665 | else if (the_board.viewed_move > 0) |
||
666 | { |
||
667 | if (the_scene.gui.larrow.state == 0) |
||
668 | the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet |
||
669 | if (the_scene.gui.rarrow.state == 0) |
||
670 | the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet |
||
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, |
||
18 | pmbaty | 673 | 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 | 674 | |
675 | // enable the "save position as" and "comment on this move" menu options |
||
676 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED); |
||
677 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_ENABLED); |
||
678 | } |
||
679 | |||
680 | // else we must be watching the beginning of the game (no move yet) |
||
681 | else |
||
682 | { |
||
683 | if (the_scene.gui.larrow.state != 0) |
||
684 | the_scene.gui.larrow.state = 0; // disable "back" arrow if it's already displayed |
||
685 | if (the_scene.gui.rarrow.state == 0) |
||
686 | the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet |
||
687 | Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, |
||
688 | RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Beginning")); |
||
689 | |||
690 | // disable the "save position as" and "comment on this move" menu options |
||
691 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED); |
||
692 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_GRAYED); |
||
693 | } |
||
694 | } |
||
695 | else |
||
696 | { |
||
697 | // game has not started, disable the "save", "save as" and "save position as" menu options |
||
698 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_GRAYED); |
||
699 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_GRAYED); |
||
700 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED); |
||
701 | |||
702 | // also disable the "suggest move", "cancel last move", "comment move" and "go to move" menu options |
||
703 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_GRAYED); |
||
704 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_GRAYED); |
||
705 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_GRAYED); |
||
706 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_GRAYED); |
||
707 | |||
708 | // and disable the two arrows and the arrow text |
||
709 | the_scene.gui.larrow.state = 0; |
||
710 | the_scene.gui.rarrow.state = 0; |
||
711 | the_scene.gui.arrow_text.is_displayed = false; |
||
712 | } |
||
713 | |||
714 | // 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 |
||
715 | if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER)) |
||
716 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_ENABLED); |
||
717 | else |
||
718 | EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_GRAYED); |
||
719 | |||
720 | // update window title |
||
721 | if ((the_board.players[COLOR_WHITE].name[0] != 0) && (the_board.players[COLOR_BLACK].name[0] != 0)) |
||
722 | { |
||
14 | pmbaty | 723 | 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 | 724 | SetWindowText (hMainWnd, window_title); // update window title |
725 | } |
||
726 | else if (the_board.players[COLOR_WHITE].name[0] != 0) |
||
727 | { |
||
14 | pmbaty | 728 | 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 | 729 | SetWindowText (hMainWnd, window_title); // update window title |
730 | } |
||
731 | |||
732 | // are we in internet mode AND are we logged in ? |
||
733 | if ((network_player != NULL) && network_player->is_logged_in) |
||
734 | { |
||
735 | // are we currently playing a game ? |
||
736 | if (network_player->is_in_game) |
||
737 | { |
||
738 | GUIBUTTON_ENABLE (the_scene.gui.chatbutton); // enable chat button if it's not enabled yet |
||
739 | GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled |
||
740 | GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled |
||
741 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_ENABLED); // allow resigning |
||
742 | } |
||
743 | else |
||
744 | { |
||
745 | GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled |
||
746 | GUIBUTTON_ENABLE (the_scene.gui.gamesbutton); // enable games button if it's not enabled yet |
||
747 | GUIBUTTON_ENABLE (the_scene.gui.peoplebutton); // enable people button if it's not enabled yet |
||
748 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_GRAYED); // disable ability to resign |
||
749 | } |
||
750 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_ENABLED); // enable stats |
||
751 | |||
752 | enabled_value = MF_ENABLED; // remember to enable the internet-related menu items |
||
753 | } |
||
754 | // else it's a local or vs. computer game |
||
755 | else |
||
756 | { |
||
757 | GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled |
||
758 | GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled |
||
759 | GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled |
||
760 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_ENABLED); // allow resigning |
||
761 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_GRAYED); // disable stats |
||
762 | |||
763 | enabled_value = MF_GRAYED; // remember to disable the internet-related menu items |
||
764 | } |
||
765 | |||
766 | EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SETUPPOSITION, !enabled_value); // note the inversion |
||
767 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWONLINEPLAYERS, enabled_value); |
||
768 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWSOUGHTGAMES, enabled_value); |
||
769 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SEEKGAME, enabled_value); |
||
770 | if (!options.network.want_publicchat) |
||
771 | { |
||
772 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, MF_GRAYED); // always grayed if we don't want public chat |
||
773 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, MF_GRAYED); |
||
774 | } |
||
775 | else |
||
776 | { |
||
777 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, enabled_value); // else enabled only in internet mode |
||
778 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, enabled_value); |
||
779 | } |
||
780 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYPLAYERCARD, enabled_value); |
||
781 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYYOURCARD, enabled_value); |
||
782 | EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_MOTD, enabled_value); |
||
783 | |||
784 | the_board.reevaluate = false; // board evaluation has been done |
||
785 | return; // finished, new board state is known |
||
786 | } |