Subversion Repositories Games.Chess Giants

Rev

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