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