Subversion Repositories Games.Chess Giants

Rev

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