Subversion Repositories Games.Chess Giants

Rev

Rev 140 | Rev 178 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
// dialog_options.cpp
2
 
3
#include "../common.h"
4
 
5
 
6
// dialog template
7
#define THIS_DIALOG DIALOG_OPTIONS
8
 
9
 
10
// global variables used in this module only
11
static void *tab_control;
12
static wchar_t server_string[MAX_PATH];
13
static COLORREF custom_colors[16];
14
static CHOOSECOLOR cc;
15
static unsigned long selectedcolor_clock;
16
static unsigned long selectedcolor_history;
17
 
18
 
19
// prototypes of local functions
20
static void StartThread_ThisDialog (void *thread_parms);
21
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam);
22
static void StartThread_DialogBoxLoad (void *thread_parms);
23
 
24
 
25
void DialogBox_Options (void)
26
{
27
   // helper function to fire up the modeless dialog box
28
 
140 pmbaty 29
   is_dialogbox_displayed = true;
1 pmbaty 30
   _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one
31
 
32
   return; // return as soon as the thread is fired up
33
}
34
 
35
 
36
void DialogBox_Options_Validated (void)
37
{
38
   // callback function called by the main game thread when the dialog box is validated
39
 
40
   // remember this callback is no longer to be called
41
   is_dialogbox_options_validated = false;
42
 
43
   return; // finished
44
}
45
 
46
 
47
static void StartThread_ThisDialog (void *thread_parms)
48
{
49
   // this function runs in a separate thread, for that's the only way (seemingly)
50
   // to implement a non-modal message box using the Common Controls library.
51
 
52
   // display the dialog box
53
   if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
54
      is_dialogbox_options_validated = true;
140 pmbaty 55
   TabControl_Destroy (tab_control); // FIXME: move to this dialog's WM_DESTROY ?
56
   is_dialogbox_displayed = false;
1 pmbaty 57
 
58
 
124 pmbaty 59
   the_board.reevaluate = true; // refresh the GUI buttons if needed
1 pmbaty 60
   return; // _endthread() implied
61
}
62
 
63
 
64
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
65
{
66
   // message handler for the dialog box
67
 
29 pmbaty 68
   static wchar_t temp_string[MAX_PATH];
26 pmbaty 69
   static wchar_t value_string[32];
1 pmbaty 70
 
71
   unsigned short wParam_hiword;
72
   unsigned short wParam_loword;
73
   wchar_t *port_string;
59 pmbaty 74
   int language_index;
119 pmbaty 75
   int engine_index;
1 pmbaty 76
   int is_checked;
77
 
78
   // filter out the commonly used message values
79
   wParam_hiword = HIWORD (wParam);
80
   wParam_loword = LOWORD (wParam);
81
 
82
   // have we just fired up this window ?
83
   if (message == WM_INITDIALOG)
84
   {
85
      // center the window
86
      CenterWindow (hWnd, hMainWnd);
87
 
88
      // set dialog icons (small one for title bar & big one for task manager)
89
      SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
90
      SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
91
 
92
      // set window title and control texts
93
      SetWindowText (hWnd, LOCALIZE (L"Options_Title"));
94
      SetWindowText (GetDlgItem (hWnd, BUTTON_OK), LOCALIZE (L"Button_OK"));
95
      SetWindowText (GetDlgItem (hWnd, BUTTON_CANCEL), LOCALIZE (L"Button_Cancel"));
96
 
97
      // create the tab control and populate it
98
      tab_control = TabControl_New (GetDlgItem (hWnd, TABBOX_OPTIONS), (WNDPROC) DialogProc_ThisDialog);
99
      TabControl_AddPage (tab_control, LOCALIZE (L"Options_OfflineGameParameters"), DIALOG_OPTIONS_ENGINE);
100
      TabControl_AddPage (tab_control, LOCALIZE (L"Options_OnlineGameParameters"), DIALOG_OPTIONS_INTERNET);
101
      TabControl_AddPage (tab_control, LOCALIZE (L"Options_DisplayParameters"), DIALOG_OPTIONS_DISPLAY);
102
      TabControl_AddPage (tab_control, LOCALIZE (L"Options_GameplayParameters"), DIALOG_OPTIONS_GAMEPLAY);
103
 
104
      // setup page 1 (computer play)
33 pmbaty 105
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEPROGRAMNAME), LOCALIZE (L"Options_EngineProgramName"));
119 pmbaty 106
      for (engine_index = 0; engine_index < options.engine.program_count; engine_index++)
150 pmbaty 107
         ComboBox_AddString (TabControl_GetItem (tab_control, COMBOBOX_ENGINE), options.engine.programs[engine_index].friendly_name); // add all engine programs to the combo box
119 pmbaty 108
      ComboBox_SetCurSel (TabControl_GetItem (tab_control, COMBOBOX_ENGINE), options.engine.selected_program); // select the right entry
33 pmbaty 109
 
1 pmbaty 110
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINESEARCHDEPTH), LOCALIZE (L"Options_EnginePredictionLevel"));
111
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_EASY), LOCALIZE (L"Options_Easy"));
112
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_HARD), LOCALIZE (L"Options_Hard"));
26 pmbaty 113
      swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", options.engine.depth);
114
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINESEARCHDEPTHVALUE), value_string);
115
 
1 pmbaty 116
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS), LOCALIZE (L"Options_AllowEngineBlunders"));
117
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_1PCCHANCE), LOCALIZE (L"Options_1PercentChance"));
118
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_100PCCHANCE), LOCALIZE (L"Options_100PercentChance"));
40 pmbaty 119
      if (options.engine.blunder_chances > 0)
26 pmbaty 120
         swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d %%", options.engine.blunder_chances);
121
      else
122
         value_string[0] = 0;
123
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEBLUNDERSVALUE), value_string);
124
 
1 pmbaty 125
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS), LOCALIZE (L"Options_AllowEngineResigns"));
126
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_YIELDING), LOCALIZE (L"Options_Yielding"));
127
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OBSTINATE), LOCALIZE (L"Options_Obstinate"));
26 pmbaty 128
      if (options.engine.obstinacy_level != -1)
129
         swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", 1 + options.engine.obstinacy_level);
130
      else
131
         value_string[0] = 0;
132
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINERESIGNVALUE), value_string);
29 pmbaty 133
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_EXPERTSETTINGS), LOCALIZE (L"Options_ExpertSettingsHelpText"));
134
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_IAMANEXPERT), LOCALIZE (L"Options_IAmAnExpert"));
135
      SetWindowText (TabControl_GetItem (tab_control, BUTTON_EXPERTSETTINGS), LOCALIZE (L"Options_ExpertSettings"));
1 pmbaty 136
 
137
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS), (options.engine.blunder_chances > 0 ? BST_CHECKED : BST_UNCHECKED));
138
      EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), (options.engine.blunder_chances > 0));
139
      EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_1PCCHANCE), (options.engine.blunder_chances > 0));
140
      EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_100PCCHANCE), (options.engine.blunder_chances > 0));
141
      EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), (options.engine.blunder_chances > 0));
142
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS), (options.engine.obstinacy_level >= 0 ? BST_CHECKED : BST_UNCHECKED));
143
      EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), (options.engine.obstinacy_level >= 0));
144
      EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_YIELDING), (options.engine.obstinacy_level >= 0));
145
      EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_OBSTINATE), (options.engine.obstinacy_level >= 0));
29 pmbaty 146
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_IAMANEXPERT), (options.engine.is_expert_mode ? BST_CHECKED : BST_UNCHECKED));
147
      EnableWindow (TabControl_GetItem (tab_control, BUTTON_EXPERTSETTINGS), options.engine.is_expert_mode);
148
      SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_SETRANGE, true, MAKELONG (1, options.engine.max_depth * (options.engine.is_expert_mode ? 3 : 1)));
1 pmbaty 149
      SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_SETPOS, true, options.engine.depth);
150
      SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_SETRANGE, true, MAKELONG (1, 100));
151
      SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_SETPOS, true, (options.engine.blunder_chances > 0 ? options.engine.blunder_chances : 1));
152
      SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_SETRANGE, true, MAKELONG (0, 9));
153
      SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_SETPOS, true, (options.engine.obstinacy_level >= 0 ? options.engine.obstinacy_level : 9));
154
 
155
      // setup page 2 (Internet play)
156
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERADDRESS), LOCALIZE (L"Options_ServerAddress"));
157
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERLOGIN), LOCALIZE (L"Options_ServerLogin"));
158
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERPASSWORD), LOCALIZE (L"Options_ServerPassword"));
159
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSERVERMESSAGES), LOCALIZE (L"Options_ShowServerMessages"));
160
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPUBLICCHAT), LOCALIZE (L"Options_ShowPublicChat"));
161
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERURL), LOCALIZE (L"Options_CreateAccount"));
162
      ConvertStaticToHyperlink (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERURL));
163
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERWARNING), LOCALIZE (L"Options_ServerWarning"));
164
 
165
      swprintf_s (server_string, WCHAR_SIZEOF (server_string), L"%s:%d", options.network.server_address, options.network.server_port);
166
      SetWindowText (TabControl_GetItem (tab_control, EDITBOX_SERVERADDRESS), server_string);
167
      EnableWindow (TabControl_GetItem (tab_control, EDITBOX_SERVERADDRESS), false); // FIXME: as long as we don't support ICC, don't allow users to change server address
168
      SetWindowText (TabControl_GetItem (tab_control, EDITBOX_LOGIN), options.network.login);
169
      SetWindowText (TabControl_GetItem (tab_control, EDITBOX_PASSWORD), options.network.password);
170
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPUBLICCHAT), (options.network.want_publicchat ? BST_CHECKED : BST_UNCHECKED));
171
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSERVERMESSAGES), (options.network.want_servermessages ? BST_CHECKED : BST_UNCHECKED));
172
 
173
      // setup page 3 (display)
59 pmbaty 174
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_LANGUAGE), LOCALIZE (L"Options_Language"));
124 pmbaty 175
      ComboBox_AddString (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), LOCALIZE (L"Options_SystemLanguage"));
59 pmbaty 176
      for (language_index = 0; language_index < language_count; language_index++)
177
         ComboBox_AddString (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), languages[language_index].name); // add it to the combo box
124 pmbaty 178
      if (is_language_auto)
179
         ComboBox_SetCurSel (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), 0); // select the right entry
180
      else
181
         ComboBox_SetCurSel (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), 1 + language_id); // select the right entry
59 pmbaty 182
 
1 pmbaty 183
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_FULLSCREEN), LOCALIZE (L"Options_Fullscreen"));
184
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING), LOCALIZE (L"Options_TextureFiltering"));
185
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), LOCALIZE (L"Options_HiQualityFiltering"));
186
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SPECULARLIGHTING), LOCALIZE (L"Options_SpecularLighting"));
187
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWREFLECTIONS), LOCALIZE (L"Options_ShowReflections"));
188
 
189
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_FULLSCREEN), (options.want_fullscreen ? BST_CHECKED : BST_UNCHECKED));
190
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING), (options.want_filtering ? BST_CHECKED : BST_UNCHECKED));
191
      EnableWindow (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), options.want_filtering);
192
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), (options.want_hiquality ? BST_CHECKED : BST_UNCHECKED));
193
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SPECULARLIGHTING), (options.want_specularlighting ? BST_CHECKED : BST_UNCHECKED));
194
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWREFLECTIONS), (options.want_reflections ? BST_CHECKED : BST_UNCHECKED));
195
 
196
      // setup page 4 (gameplay)
197
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWLASTMOVE), LOCALIZE (L"Options_ShowLastMove"));
198
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPOSSIBLEMOVES), LOCALIZE (L"Options_ShowPossibleMoves"));
199
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTHREATS), LOCALIZE (L"Options_ShowThreats"));
200
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS), LOCALIZE (L"Options_ShowAnimations"));
130 pmbaty 201
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS), LOCALIZE (L"Options_ShowSlidingAnimations"));
1 pmbaty 202
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTAKENPARTS), LOCALIZE (L"Options_ShowTakenParts"));
203
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTURN), LOCALIZE (L"Options_ShowTurn"));
204
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK), LOCALIZE (L"Options_ShowClock"));
205
      SetWindowText (TabControl_GetItem (tab_control, BUTTON_COLORCLOCK), LOCALIZE (L"Button_Color"));
206
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY), LOCALIZE (L"Options_ShowHistory"));
207
      SetWindowText (TabControl_GetItem (tab_control, BUTTON_COLORHISTORY), LOCALIZE (L"Button_Color"));
208
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_USESEPIAFORHISTORY), LOCALIZE (L"Options_UseSepiaForHistory"));
209
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD), LOCALIZE (L"Options_RotateBoard"));
210
      SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_ROTATESPEED), LOCALIZE (L"Options_RotateSpeed"));
211
      SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PLAYSOUNDS), LOCALIZE (L"Options_PlaySounds"));
212
 
213
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWLASTMOVE), (options.want_lastmove ? BST_CHECKED : BST_UNCHECKED));
214
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPOSSIBLEMOVES), (options.want_possiblemoves ? BST_CHECKED : BST_UNCHECKED));
215
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTHREATS), (options.want_threats ? BST_CHECKED : BST_UNCHECKED));
216
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS), (options.want_animations ? BST_CHECKED : BST_UNCHECKED));
130 pmbaty 217
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS), (options.want_slidinganimations ? BST_CHECKED : BST_UNCHECKED));
1 pmbaty 218
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTAKENPARTS), (options.want_takenparts ? BST_CHECKED : BST_UNCHECKED));
219
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTURN), (options.want_turn ? BST_CHECKED : BST_UNCHECKED));
220
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK), (options.want_clock ? BST_CHECKED : BST_UNCHECKED));
221
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY), (options.want_history ? BST_CHECKED : BST_UNCHECKED));
222
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_USESEPIAFORHISTORY), (options.want_sepiafilter ? BST_CHECKED : BST_UNCHECKED));
223
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD), (options.want_autorotateon1vs1 ? BST_CHECKED : BST_UNCHECKED));
224
      Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PLAYSOUNDS), (options.want_sounds ? BST_CHECKED : BST_UNCHECKED));
225
      SendMessage (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), TBM_SETRANGE, true, MAKELONG (5, 80));
226
      SendMessage (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), TBM_SETPOS, true, options.rotate_speed);
227
 
228
      // set the selected color to the current game clock color (convert from RGBA to GDI BGR)
229
      selectedcolor_clock = ((options.clock_color & 0x0000ff00) << 8)
230
                            | ((options.clock_color & 0x00ff0000) >> 8)
231
                            | ((options.clock_color & 0xff000000) >> 24);
232
 
233
      // set the selected color to the current game history color (convert from RGBA to GDI BGR)
234
      selectedcolor_history = ((options.history_color & 0x0000ff00) << 8)
235
                              | ((options.history_color & 0x00ff0000) >> 8)
236
                              | ((options.history_color & 0xff000000) >> 24);
237
 
238
      // set focus on the first settable item
239
      SendMessage (TabControl_GetItem (tab_control, EDITBOX_LOGIN), EM_SETSEL, 0, -1); // select all text
240
      SetFocus (TabControl_GetItem (tab_control, EDITBOX_LOGIN));
241
   }
242
 
243
   // else did we click the close button on the title bar ?
244
   else if (message == WM_CLOSE)
245
      EndDialog (hWnd, 0); // close the dialog box
246
 
247
   // else did we take action on one of the controls ?
248
   else if (message == WM_COMMAND)
249
   {
250
      // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
251
      if (wParam_loword == IDCANCEL)
252
         EndDialog (hWnd, 0); // close the dialog box
253
 
254
      // else was it the OK button ?
255
      else if (wParam_loword == BUTTON_OK)
256
      {
257
         // grab the new parameters and close the dialog box
258
 
259
         // set the server address, login and password
260
         GetWindowText (TabControl_GetItem (tab_control, EDITBOX_SERVERADDRESS), server_string, WCHAR_SIZEOF (server_string));
261
         options.network.server_address[0] = 0; // default values
262
         options.network.server_port = 0;
263
         port_string = wcschr (server_string, L':'); // find the address:port separator
264
         if (port_string != NULL)
265
         {
266
            port_string[0] = 0; // split the string
267
            options.network.server_port = _wtoi (&port_string[1]); // and read the port
268
         }
269
         wcscpy_s (options.network.server_address, WCHAR_SIZEOF (options.network.server_address), server_string); // now read the address
270
         GetWindowText (TabControl_GetItem (tab_control, EDITBOX_LOGIN), options.network.login, WCHAR_SIZEOF (options.network.login));
271
         GetWindowText (TabControl_GetItem (tab_control, EDITBOX_PASSWORD), options.network.password, WCHAR_SIZEOF (options.network.password));
272
 
59 pmbaty 273
         // display
124 pmbaty 274
         language_index = ComboBox_GetCurSel (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE));
275
         is_language_auto = (language_index == 0); // first, see if the system language is selected
276
         if (!is_language_auto)
277
            language_id = language_index - 1; // because slot #0 of the list is taken by "System Language"
59 pmbaty 278
         CreateOrUpdateApplicationMenu (); // on language change, update the application menu
1 pmbaty 279
         options.want_fullscreen = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_FULLSCREEN)) != 0);
280
         options.want_filtering = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING)) != 0);
281
         options.want_specularlighting = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SPECULARLIGHTING)) != 0);
282
         options.want_reflections = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWREFLECTIONS)) != 0);
59 pmbaty 283
 
284
         // gameplay
285
         options.network.want_servermessages = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSERVERMESSAGES)) != 0);
286
         options.network.want_publicchat = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPUBLICCHAT)) != 0);
1 pmbaty 287
         options.want_lastmove = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWLASTMOVE)) != 0);
288
         options.want_possiblemoves = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPOSSIBLEMOVES)) != 0);
289
         options.want_threats = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTHREATS)) != 0);
290
         options.want_animations = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS)) != 0);
130 pmbaty 291
         options.want_slidinganimations = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS)) != 0);
1 pmbaty 292
         options.want_takenparts = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTAKENPARTS)) != 0);
293
         options.want_turn = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTURN)) != 0);
294
         options.want_clock = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK)) != 0);
295
         options.clock_color = 0 | ((selectedcolor_clock & 0x000000ff) << 24)
296
                                 | ((selectedcolor_clock & 0x0000ff00) << 8)
297
                                 | ((selectedcolor_clock & 0x00ff0000) >> 8); // convert from GDI BGR to RGBA
298
         options.want_history = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY)) != 0);
299
         options.history_color = 0 | ((selectedcolor_history & 0x000000ff) << 24)
300
                                   | ((selectedcolor_history & 0x0000ff00) << 8)
301
                                   | ((selectedcolor_history & 0x00ff0000) >> 8); // convert from GDI BGR to RGBA
302
         options.want_sepiafilter = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_USESEPIAFORHISTORY)) != 0);
303
         options.want_autorotateon1vs1 = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD)) != 0);
304
         options.want_sounds = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PLAYSOUNDS)) != 0);
40 pmbaty 305
         options.rotate_speed = SendMessage (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), TBM_GETPOS, 0, 0);
1 pmbaty 306
 
40 pmbaty 307
         // engine options
308
         ComboBox_GetLBText (TabControl_GetItem (tab_control, COMBOBOX_ENGINE), ComboBox_GetCurSel (TabControl_GetItem (tab_control, COMBOBOX_ENGINE)), temp_string);
119 pmbaty 309
         for (engine_index = 0; engine_index < options.engine.program_count; engine_index++)
150 pmbaty 310
            if ((_wcsicmp (temp_string, options.engine.programs[engine_index].friendly_name) == 0) && (engine_index != options.engine.selected_program))
119 pmbaty 311
            {
312
               options.engine.selected_program = engine_index;
313
               MessageBox (hWnd, LOCALIZE (L"Options_ChessEngineChangeWillAffectNextGame"), LOCALIZE (L"ImportantMessage"), MB_ICONINFORMATION | MB_OK);
314
            }
40 pmbaty 315
 
1 pmbaty 316
         options.engine.depth = SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_GETPOS, 0, 0);
40 pmbaty 317
         if (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS)))
318
            options.engine.blunder_chances = SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_GETPOS, 0, 0);
319
         else
320
            options.engine.blunder_chances = 0;
321
         if (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS)))
322
            options.engine.obstinacy_level = SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_GETPOS, 0, 0);
323
         else
324
            options.engine.obstinacy_level = -1;
1 pmbaty 325
 
326
         EndDialog (hWnd, 0); // close the dialog box
327
      }
328
 
329
      // else was it the cancel button ?
330
      else if (wParam_loword == BUTTON_CANCEL)
331
         EndDialog (hWnd, 0); // close the dialog box
332
 
29 pmbaty 333
      // else was it the expert settings button ?
334
      else if (wParam_loword == BUTTON_EXPERTSETTINGS)
335
      {
59 pmbaty 336
         ComboBox_GetLBText (TabControl_GetItem (tab_control, COMBOBOX_ENGINE), ComboBox_GetCurSel (TabControl_GetItem (tab_control, COMBOBOX_ENGINE)), value_string);
337
         swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), L"%s\\engines\\%s\\init.txt", app_path, value_string);
29 pmbaty 338
         ShellExecute (NULL, L"open", temp_string, NULL, NULL, SW_SHOWNORMAL); // open the engine initialization text file
339
      }
340
 
1 pmbaty 341
      // else is it the rotate board check box ? if so, enable or disable the speed slider
342
      else if (wParam_loword == CHECKBOX_OPTIONS_ROTATEBOARD)
343
      {
344
         EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_ROTATESPEED), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD)));
345
         EnableWindow (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD)));
346
      }
347
 
29 pmbaty 348
      // else is it the I am an expert check box ? if so, enable or disable the expert settings button and adjust the engine level slider
349
      else if (wParam_loword == CHECKBOX_OPTIONS_IAMANEXPERT)
350
      {
351
         options.engine.is_expert_mode = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_IAMANEXPERT)) == BST_CHECKED);
352
         EnableWindow (TabControl_GetItem (tab_control, BUTTON_EXPERTSETTINGS), options.engine.is_expert_mode);
353
         SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_SETRANGE, true, MAKELONG (1, options.engine.max_depth * (options.engine.is_expert_mode ? 3 : 1)));
354
      }
355
 
1 pmbaty 356
      // else is it the allow engine blunders check box ? if so, enable or disable the blunder chance slider
357
      else if (wParam_loword == CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS)
358
      {
359
         is_checked = Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS));
360
         EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), is_checked);
361
         EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_1PCCHANCE), is_checked);
362
         EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_100PCCHANCE), is_checked);
26 pmbaty 363
         if (is_checked)
40 pmbaty 364
            swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d %%", SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_GETPOS, 0, 0));
26 pmbaty 365
         else
366
            value_string[0] = 0;
367
         SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEBLUNDERSVALUE), value_string);
1 pmbaty 368
      }
369
 
370
      // else is it the allow engine resigns check box ? if so, enable or disable the blunder chance slider
371
      else if (wParam_loword == CHECKBOX_OPTIONS_ALLOWENGINERESIGNS)
372
      {
373
         is_checked = Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS));
374
         EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), is_checked);
375
         EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_YIELDING), is_checked);
376
         EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_OBSTINATE), is_checked);
26 pmbaty 377
         if (is_checked)
40 pmbaty 378
            swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", 1 + SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_GETPOS, 0, 0));
26 pmbaty 379
         else
380
            value_string[0] = 0;
381
         SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINERESIGNVALUE), value_string);
1 pmbaty 382
      }
383
 
384
      // else is it the enable filtering check box ? if so, enable or disable the high quality checkbox
385
      else if (wParam_loword == CHECKBOX_OPTIONS_TEXTUREFILTERING)
386
         EnableWindow (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING)));
387
 
130 pmbaty 388
      // else is it the show animations check box ? if so, enable or disable the show sliding animations checkbox too
389
      else if (wParam_loword == CHECKBOX_OPTIONS_SHOWANIMATIONS)
390
         EnableWindow (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS)));
391
 
1 pmbaty 392
      // else is it the show game clock check box ? if so, enable or disable the game clock color button
393
      else if (wParam_loword == CHECKBOX_OPTIONS_SHOWCLOCK)
394
         EnableWindow (TabControl_GetItem (tab_control, BUTTON_COLORCLOCK), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK)));
395
 
396
      // else is it the game clock color button ?
397
      else if (wParam_loword == BUTTON_COLORCLOCK)
398
      {
399
         // prepare a color pick dialog box
400
         memset (&cc, 0, sizeof (cc));
401
         cc.lStructSize = sizeof (cc);
402
         cc.hwndOwner = hWnd;
403
         cc.lpCustColors = (unsigned long *) custom_colors;
404
         cc.rgbResult = selectedcolor_clock;
405
         cc.Flags = CC_FULLOPEN | CC_RGBINIT;
406
 
407
         // fire it up
408
         if (ChooseColor (&cc))
409
            selectedcolor_clock = cc.rgbResult; // save away returned color
410
      }
411
 
412
      // else is it the show game history check box ? if so, enable or disable the game history color button
413
      else if (wParam_loword == CHECKBOX_OPTIONS_SHOWHISTORY)
414
         EnableWindow (TabControl_GetItem (tab_control, BUTTON_COLORHISTORY), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY)));
415
 
416
      // else is it the game history color button ?
417
      else if (wParam_loword == BUTTON_COLORHISTORY)
418
      {
419
         // prepare a color pick dialog box
420
         memset (&cc, 0, sizeof (cc));
421
         cc.lStructSize = sizeof (cc);
422
         cc.hwndOwner = hWnd;
423
         cc.lpCustColors = (unsigned long *) custom_colors;
424
         cc.rgbResult = selectedcolor_history;
425
         cc.Flags = CC_FULLOPEN | CC_RGBINIT;
426
 
427
         // fire it up
428
         if (ChooseColor (&cc))
429
            selectedcolor_history = cc.rgbResult; // save away returned color
430
      }
431
 
432
      // else is it the create/manage account hyperlink ?
433
      else if (wParam_loword == STATICTEXT_OPTIONS_SERVERURL)
434
      {
59 pmbaty 435
         swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), ACCOUNTCREATION_URL, languages[language_id].name); // build account creation url
29 pmbaty 436
         ShellExecute (NULL, L"open", temp_string, NULL, NULL, SW_MAXIMIZE); // open the accounts page in the default browser, maximized
1 pmbaty 437
      }
438
   }
439
 
26 pmbaty 440
   // else is it a notification for a slider moving ?
441
   else if (message == WM_HSCROLL)
442
   {
443
      // is it the engine prediction level slider ? if so, update the slider value text
444
      if ((HWND) lParam == TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL))
445
      {
446
         swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_GETPOS, 0, 0));
447
         SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINESEARCHDEPTHVALUE), value_string);
448
      }
449
 
450
      // else is it the engine blunders slider ? if so, update the slider value text
451
      else if ((HWND) lParam == TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE))
452
      {
453
         swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d %%", SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_GETPOS, 0, 0));
454
         SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEBLUNDERSVALUE), value_string);
455
      }
456
 
457
      // else is it the engine obstinacy slider ? if so, update the slider value text
458
      else if ((HWND) lParam == TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY))
459
      {
460
         swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", 1 + SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_GETPOS, 0, 0));
461
         SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINERESIGNVALUE), value_string);
462
      }
463
   }
464
 
1 pmbaty 465
   // else is it a notification for the tab control ?
466
   else if ((message == WM_NOTIFY) && (((NMHDR *) lParam)->hwndFrom == GetDlgItem (hWnd, TABBOX_OPTIONS)))
467
      TabControl_Notify ((NMHDR *) lParam);
468
 
469
   // call the default dialog message processing function to keep things going
470
   return (false);
471
}