// dialog_options.cpp
#include "../common.h"
// dialog template
#define THIS_DIALOG DIALOG_OPTIONS
// global variables used in this module only
static void *tab_control;
static wchar_t server_string[MAX_PATH];
static COLORREF custom_colors[16];
static CHOOSECOLOR cc;
static unsigned long selectedcolor_clock;
static unsigned long selectedcolor_history;
// prototypes of local functions
static void StartThread_ThisDialog (void *thread_parms);
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam);
static void StartThread_DialogBoxLoad (void *thread_parms);
void DialogBox_Options (void)
{
// helper function to fire up the modeless dialog box
is_dialogbox_displayed = true;
_beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one
return; // return as soon as the thread is fired up
}
void DialogBox_Options_Validated (void)
{
// callback function called by the main game thread when the dialog box is validated
// remember this callback is no longer to be called
is_dialogbox_options_validated = false;
return; // finished
}
static void StartThread_ThisDialog (void *thread_parms)
{
// this function runs in a separate thread, for that's the only way (seemingly)
// to implement a non-modal message box using the Common Controls library.
// display the dialog box
if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
is_dialogbox_options_validated = true;
TabControl_Destroy (tab_control); // FIXME: move to this dialog's WM_DESTROY ?
is_dialogbox_displayed = false;
the_board.reevaluate = true; // refresh the GUI buttons if needed
return; // _endthread() implied
}
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{
// message handler for the dialog box
static wchar_t temp_string[MAX_PATH];
static wchar_t value_string[32];
unsigned short wParam_hiword;
unsigned short wParam_loword;
wchar_t *port_string;
int language_index;
int engine_index;
int is_checked;
int level;
HWND hCtlWnd;
// filter out the commonly used message values
wParam_hiword = HIWORD (wParam);
wParam_loword = LOWORD (wParam);
// have we just fired up this window ?
if (message == WM_INITDIALOG)
{
// center the window
CenterWindow (hWnd, hMainWnd);
// set dialog icons (small one for title bar & big one for task manager)
SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
// set window title and control texts
SetWindowText (hWnd, LOCALIZE (L"Options_Title"));
SetWindowText (GetDlgItem (hWnd, BUTTON_OK), LOCALIZE (L"Button_OK"));
SetWindowText (GetDlgItem (hWnd, BUTTON_CANCEL), LOCALIZE (L"Button_Cancel"));
// create the tab control and populate it
tab_control = TabControl_New (GetDlgItem (hWnd, TABBOX_OPTIONS), (WNDPROC) DialogProc_ThisDialog);
TabControl_AddPage (tab_control, LOCALIZE (L"Options_OfflineGameParameters"), DIALOG_OPTIONS_ENGINE);
TabControl_AddPage (tab_control, LOCALIZE (L"Options_OnlineGameParameters"), DIALOG_OPTIONS_INTERNET);
TabControl_AddPage (tab_control, LOCALIZE (L"Options_DisplayParameters"), DIALOG_OPTIONS_DISPLAY);
TabControl_AddPage (tab_control, LOCALIZE (L"Options_GameplayParameters"), DIALOG_OPTIONS_GAMEPLAY);
// setup page 1 (computer play)
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEPROGRAMNAME), LOCALIZE (L"Options_EngineProgramName"));
for (engine_index = 0; engine_index < options.engine.program_count; engine_index++)
if (kernel32_version >= options.engine.programs[engine_index].kernel32_minver)
ComboBox_AddString (TabControl_GetItem (tab_control, COMBOBOX_ENGINE), options.engine.programs[engine_index].friendly_name); // add all SUPPORTED engine programs to the combo box
ComboBox_SetCurSel (TabControl_GetItem (tab_control, COMBOBOX_ENGINE), options.engine.selected_program); // select the right entry
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINESEARCHDEPTH), LOCALIZE (L"Options_EnginePredictionLevel"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_EASY), LOCALIZE (L"Options_Easy"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_HARD), LOCALIZE (L"Options_Hard"));
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", options.engine.depth);
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINESEARCHDEPTHVALUE), value_string);
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS), LOCALIZE (L"Options_AllowEngineBlunders"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_1PCCHANCE), LOCALIZE (L"Options_1PercentChance"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_100PCCHANCE), LOCALIZE (L"Options_100PercentChance"));
if (options.engine.blunder_chances > 0)
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d %%", options.engine.blunder_chances);
else
value_string[0] = 0;
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEBLUNDERSVALUE), value_string);
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS), LOCALIZE (L"Options_AllowEngineResigns"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_YIELDING), LOCALIZE (L"Options_Yielding"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OBSTINATE), LOCALIZE (L"Options_Obstinate"));
if (options.engine.obstinacy_level != -1)
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", 1 + options.engine.obstinacy_level);
else
value_string[0] = 0;
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINERESIGNVALUE), value_string);
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_EXPERTSETTINGS), LOCALIZE (L"Options_ExpertSettingsHelpText"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_IAMANEXPERT), LOCALIZE (L"Options_IAmAnExpert"));
SetWindowText (TabControl_GetItem (tab_control, BUTTON_EXPERTSETTINGS), LOCALIZE (L"Options_ExpertSettings"));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS), (options.engine.blunder_chances > 0 ? BST_CHECKED : BST_UNCHECKED));
EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), (options.engine.blunder_chances > 0));
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_1PCCHANCE), (options.engine.blunder_chances > 0));
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_100PCCHANCE), (options.engine.blunder_chances > 0));
EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), (options.engine.blunder_chances > 0));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS), (options.engine.obstinacy_level >= 0 ? BST_CHECKED : BST_UNCHECKED));
EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), (options.engine.obstinacy_level >= 0));
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_YIELDING), (options.engine.obstinacy_level >= 0));
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_OBSTINATE), (options.engine.obstinacy_level >= 0));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_IAMANEXPERT), (options.engine.is_expert_mode ? BST_CHECKED : BST_UNCHECKED));
EnableWindow (TabControl_GetItem (tab_control, BUTTON_EXPERTSETTINGS), options.engine.is_expert_mode);
SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_SETRANGE, true, MAKELONG (1, options.engine.max_depth * (options.engine.is_expert_mode ? 3 : 1)));
SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_SETPOS, true, options.engine.depth);
SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_SETRANGE, true, MAKELONG (1, 100));
SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_SETPOS, true, (options.engine.blunder_chances > 0 ? options.engine.blunder_chances : 1));
SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_SETRANGE, true, MAKELONG (0, 9));
SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_SETPOS, true, (options.engine.obstinacy_level >= 0 ? options.engine.obstinacy_level : 9));
// setup page 2 (Internet play)
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERADDRESS), LOCALIZE (L"Options_ServerAddress"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERLOGIN), LOCALIZE (L"Options_ServerLogin"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERPASSWORD), LOCALIZE (L"Options_ServerPassword"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSERVERMESSAGES), LOCALIZE (L"Options_ShowServerMessages"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPUBLICCHAT), LOCALIZE (L"Options_ShowPublicChat"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERURL), LOCALIZE (L"Options_CreateAccount"));
ConvertStaticToHyperlink (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERURL));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_SERVERWARNING), LOCALIZE (L"Options_ServerWarning"));
swprintf_s (server_string, WCHAR_SIZEOF (server_string), L"%s:%d", options.network.server_address, options.network.server_port);
SetWindowText (TabControl_GetItem (tab_control, EDITBOX_SERVERADDRESS), server_string);
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
SetWindowText (TabControl_GetItem (tab_control, EDITBOX_LOGIN), options.network.login);
SetWindowText (TabControl_GetItem (tab_control, EDITBOX_PASSWORD), options.network.password);
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPUBLICCHAT), (options.network.want_publicchat ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSERVERMESSAGES), (options.network.want_servermessages ? BST_CHECKED : BST_UNCHECKED));
// setup page 3 (display)
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_LANGUAGE), LOCALIZE (L"Options_Language"));
ComboBox_AddString (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), LOCALIZE (L"Options_SystemLanguage"));
for (language_index = 0; language_index < language_count; language_index++)
ComboBox_AddString (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), languages[language_index].name); // add it to the combo box
if (is_language_auto)
ComboBox_SetCurSel (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), 0); // select the right entry
else
ComboBox_SetCurSel (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE), 1 + language_id); // select the right entry
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_FULLSCREEN), LOCALIZE (L"Options_Fullscreen"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING), LOCALIZE (L"Options_TextureFiltering"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), LOCALIZE (L"Options_HiQualityFiltering"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SPECULARLIGHTING), LOCALIZE (L"Options_SpecularLighting"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWREFLECTIONS), LOCALIZE (L"Options_ShowReflections"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_USESEPIAFORHISTORY), LOCALIZE (L"Options_UseSepiaForHistory"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_STARTWITHTOPVIEW), LOCALIZE (L"Options_StartWithTopView"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_PARTLETTERS), LOCALIZE (L"Options_PartLetters"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_PARTNAME_ROOK), LOCALIZE (L"Part_Rook"));
hCtlWnd = TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_ROOK); SetWindowText (hCtlWnd, options.part_letters.rook); SendMessage (hCtlWnd, EM_LIMITTEXT, 1, 0);
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_PARTNAME_KNIGHT), LOCALIZE (L"Part_Knight"));
hCtlWnd = TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_KNIGHT); SetWindowText (hCtlWnd, options.part_letters.knight); SendMessage (hCtlWnd, EM_LIMITTEXT, 1, 0);
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_PARTNAME_BISHOP), LOCALIZE (L"Part_Bishop"));
hCtlWnd = TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_BISHOP); SetWindowText (hCtlWnd, options.part_letters.bishop); SendMessage (hCtlWnd, EM_LIMITTEXT, 1, 0);
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_PARTNAME_QUEEN), LOCALIZE (L"Part_Queen"));
hCtlWnd = TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_QUEEN); SetWindowText (hCtlWnd, options.part_letters.queen); SendMessage (hCtlWnd, EM_LIMITTEXT, 1, 0);
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_PARTNAME_KING), LOCALIZE (L"Part_King"));
hCtlWnd = TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_KING); SetWindowText (hCtlWnd, options.part_letters.king); SendMessage (hCtlWnd, EM_LIMITTEXT, 1, 0);
SetWindowText (TabControl_GetItem (tab_control, BUTTON_STANDARD), LOCALIZE (L"Standard"));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_FULLSCREEN), (options.want_fullscreen ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING), (options.want_filtering ? BST_CHECKED : BST_UNCHECKED));
EnableWindow (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), options.want_filtering);
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), (options.want_hiquality ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SPECULARLIGHTING), (options.want_specularlighting ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWREFLECTIONS), (options.want_reflections ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_USESEPIAFORHISTORY), (options.want_sepiafilter ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_STARTWITHTOPVIEW), (options.want_startwithtopview ? BST_CHECKED : BST_UNCHECKED));
// setup page 4 (gameplay)
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWLASTMOVE), LOCALIZE (L"Options_ShowLastMove"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPOSSIBLEMOVES), LOCALIZE (L"Options_ShowPossibleMoves"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTHREATS), LOCALIZE (L"Options_ShowThreats"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS), LOCALIZE (L"Options_ShowAnimations"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS), LOCALIZE (L"Options_ShowSlidingAnimations"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTAKENPARTS), LOCALIZE (L"Options_ShowTakenParts"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTURN), LOCALIZE (L"Options_ShowTurn"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK), LOCALIZE (L"Options_ShowClock"));
SetWindowText (TabControl_GetItem (tab_control, BUTTON_COLORCLOCK), LOCALIZE (L"Button_Color"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY), LOCALIZE (L"Options_ShowHistory"));
SetWindowText (TabControl_GetItem (tab_control, BUTTON_COLORHISTORY), LOCALIZE (L"Button_Color"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PREFERBLACKSIDE), LOCALIZE (L"Options_PreferBlackSide"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD), LOCALIZE (L"Options_RotateBoard"));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_ROTATESPEED), LOCALIZE (L"Options_RotateSpeed"));
SetWindowText (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PLAYSOUNDS), LOCALIZE (L"Options_PlaySounds"));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWLASTMOVE), (options.want_lastmove ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPOSSIBLEMOVES), (options.want_possiblemoves ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTHREATS), (options.want_threats ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS), (options.want_animations ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS), (options.want_slidinganimations ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTAKENPARTS), (options.want_takenparts ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTURN), (options.want_turn ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK), (options.want_clock ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY), (options.want_history ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PREFERBLACKSIDE), (options.want_playblackside ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD), (options.want_autorotateon1vs1 ? BST_CHECKED : BST_UNCHECKED));
Button_SetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PLAYSOUNDS), (options.want_sounds ? BST_CHECKED : BST_UNCHECKED));
SendMessage (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), TBM_SETRANGE, true, MAKELONG (5, 80));
SendMessage (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), TBM_SETPOS, true, options.rotate_speed);
// set the selected color to the current game clock color (convert from RGBA to GDI BGR)
selectedcolor_clock = ((options.clock_color & 0x0000ff00) << 8)
| ((options.clock_color & 0x00ff0000) >> 8)
| ((options.clock_color & 0xff000000) >> 24);
// set the selected color to the current game history color (convert from RGBA to GDI BGR)
selectedcolor_history = ((options.history_color & 0x0000ff00) << 8)
| ((options.history_color & 0x00ff0000) >> 8)
| ((options.history_color & 0xff000000) >> 24);
// set focus on the first settable item
hCtlWnd = TabControl_GetItem (tab_control, EDITBOX_LOGIN);
SendMessage (hCtlWnd, EM_SETSEL, 0, -1); // select all text
SetFocus (hCtlWnd);
}
// else did we click the close button on the title bar ?
else if (message == WM_CLOSE)
EndDialog (hWnd, 0); // close the dialog box
// else did we take action on one of the controls ?
else if (message == WM_COMMAND)
{
// did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
if (wParam_loword == IDCANCEL)
EndDialog (hWnd, 0); // close the dialog box
// else was it the OK button ?
else if (wParam_loword == BUTTON_OK)
{
// grab the new parameters and close the dialog box
// set the server address, login and password
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_SERVERADDRESS), server_string, WCHAR_SIZEOF (server_string));
options.network.server_address[0] = 0; // default values
options.network.server_port = 0;
port_string = wcschr (server_string, L':'); // find the address:port separator
if (port_string != NULL)
{
port_string[0] = 0; // split the string
options.network.server_port = _wtoi (&port_string[1]); // and read the port
}
wcscpy_s (options.network.server_address, WCHAR_SIZEOF (options.network.server_address), server_string); // now read the address
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_LOGIN), options.network.login, WCHAR_SIZEOF (options.network.login));
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_PASSWORD), options.network.password, WCHAR_SIZEOF (options.network.password));
// display
language_index = ComboBox_GetCurSel (TabControl_GetItem (tab_control, COMBOBOX_LANGUAGE));
is_language_auto = (language_index == 0); // first, see if the system language is selected
if (!is_language_auto)
language_id = language_index - 1; // because slot #0 of the list is taken by "System Language"
CreateOrUpdateApplicationMenu (); // on language change, update the application menu
options.want_fullscreen = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_FULLSCREEN)) != 0);
options.want_filtering = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING)) != 0);
options.want_specularlighting = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SPECULARLIGHTING)) != 0);
options.want_reflections = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWREFLECTIONS)) != 0);
options.want_sepiafilter = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_USESEPIAFORHISTORY)) != 0);
options.want_startwithtopview = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_STARTWITHTOPVIEW)) != 0);
// make sure part letters are unique, only save them if they are
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_ROOK), &temp_string[0], WCHAR_SIZEOF (temp_string) - 0);
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_KNIGHT), &temp_string[2], WCHAR_SIZEOF (temp_string) - 2);
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_BISHOP), &temp_string[4], WCHAR_SIZEOF (temp_string) - 4);
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_QUEEN), &temp_string[6], WCHAR_SIZEOF (temp_string) - 6);
GetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_KING), &temp_string[8], WCHAR_SIZEOF (temp_string) - 8);
temp_string[1] = temp_string[3] = temp_string[5] = temp_string[7] = temp_string[9] = 0; // terminate the strings ourselves
if ( (temp_string[2] != temp_string[0]) && (temp_string[4] != temp_string[0]) && (temp_string[4] != temp_string[2]) && (temp_string[6] != temp_string[0]) && (temp_string[6] != temp_string[2])
&& (temp_string[6] != temp_string[4]) && (temp_string[8] != temp_string[0]) && (temp_string[8] != temp_string[2]) && (temp_string[8] != temp_string[4]) && (temp_string[8] != temp_string[6]))
{
wcscpy_s (options.part_letters.rook, WCHAR_SIZEOF (options.part_letters.rook), &temp_string[0]);
wcscpy_s (options.part_letters.knight, WCHAR_SIZEOF (options.part_letters.knight), &temp_string[2]);
wcscpy_s (options.part_letters.bishop, WCHAR_SIZEOF (options.part_letters.bishop), &temp_string[4]);
wcscpy_s (options.part_letters.queen, WCHAR_SIZEOF (options.part_letters.queen), &temp_string[6]);
wcscpy_s (options.part_letters.king, WCHAR_SIZEOF (options.part_letters.king), &temp_string[8]);
}
// gameplay
options.network.want_servermessages = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSERVERMESSAGES)) != 0);
options.network.want_publicchat = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPUBLICCHAT)) != 0);
options.want_lastmove = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWLASTMOVE)) != 0);
options.want_possiblemoves = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWPOSSIBLEMOVES)) != 0);
options.want_threats = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTHREATS)) != 0);
options.want_animations = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS)) != 0);
options.want_slidinganimations = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS)) != 0);
options.want_takenparts = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTAKENPARTS)) != 0);
options.want_turn = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWTURN)) != 0);
options.want_clock = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK)) != 0);
options.clock_color = 0 | ((selectedcolor_clock & 0x000000ff) << 24)
| ((selectedcolor_clock & 0x0000ff00) << 8)
| ((selectedcolor_clock & 0x00ff0000) >> 8); // convert from GDI BGR to RGBA
options.want_history = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY)) != 0);
options.history_color = 0 | ((selectedcolor_history & 0x000000ff) << 24)
| ((selectedcolor_history & 0x0000ff00) << 8)
| ((selectedcolor_history & 0x00ff0000) >> 8); // convert from GDI BGR to RGBA
options.want_playblackside = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PREFERBLACKSIDE)) != 0);
options.want_autorotateon1vs1 = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD)) != 0);
options.want_sounds = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_PLAYSOUNDS)) != 0);
options.rotate_speed = SendMessage (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), TBM_GETPOS, 0, 0);
// engine options
ComboBox_GetLBText (TabControl_GetItem (tab_control, COMBOBOX_ENGINE), ComboBox_GetCurSel (TabControl_GetItem (tab_control, COMBOBOX_ENGINE)), temp_string);
for (engine_index = 0; engine_index < options.engine.program_count; engine_index++)
if ((_wcsicmp (temp_string, options.engine.programs[engine_index].friendly_name) == 0) && (engine_index != options.engine.selected_program))
{
options.engine.selected_program = engine_index;
if ((the_board.game_state == STATE_SETUPPOSITION) || ((the_board.game_state == STATE_PLAYING) && (the_board.move_count > 1)))
MessageBox (hWnd, LOCALIZE (L"Options_ChessEngineChangeWillAffectNextGame"), LOCALIZE (L"ImportantMessage"), MB_ICONINFORMATION | MB_OK);
}
options.engine.depth = SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_GETPOS, 0, 0);
if (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS)))
options.engine.blunder_chances = SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_GETPOS, 0, 0);
else
options.engine.blunder_chances = 0;
if (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS)))
options.engine.obstinacy_level = SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_GETPOS, 0, 0);
else
options.engine.obstinacy_level = -1;
EndDialog (hWnd, 0); // close the dialog box
}
// else was it the cancel button ?
else if (wParam_loword == BUTTON_CANCEL)
EndDialog (hWnd, 0); // close the dialog box
// else was it the expert settings button ?
else if (wParam_loword == BUTTON_EXPERTSETTINGS)
{
swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), L"%s\\engines\\%s\\init.txt", app_path, options.engine.programs[ComboBox_GetCurSel (TabControl_GetItem (tab_control, COMBOBOX_ENGINE))].folder);
ShellExecute (NULL, L"open", temp_string, NULL, NULL, SW_SHOWNORMAL); // open the engine initialization text file
}
// else are we focusing to a part abbreviation edit box ?
else if ((HIWORD (wParam) == EN_SETFOCUS) && ( (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_ROOK) || (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_KNIGHT) || (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_BISHOP)
|| (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_QUEEN) || (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_KING)))
PostMessage ((HWND) lParam, EM_SETSEL, 0, -1); // select the whole text
// else are we editing a part abbreviation edit box ?
else if ((HIWORD (wParam) == EN_CHANGE) && ( (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_ROOK) || (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_KNIGHT) || (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_BISHOP)
|| (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_QUEEN) || (wParam_loword == EDITBOX_OPTIONS_PARTLETTER_KING)))
{
static bool do_not_hook = false;
if (!do_not_hook)
{
size_t len;
GetWindowText ((HWND) lParam, temp_string, WCHAR_SIZEOF (temp_string));
len = wcslen (temp_string);
temp_string[0] = (len > 0 ? towupper (temp_string[0]) : 0);
temp_string[1] = 0;
do_not_hook = true; // FIXME: dirty
SetWindowText ((HWND) lParam, temp_string); // update text
PostMessage ((HWND) lParam, EM_SETSEL, 0, -1); // select the whole text
do_not_hook = false; // FIXME: dirty
}
}
// else was it the "standard part abbreviations" button ?
else if (wParam_loword == BUTTON_STANDARD)
{
// reset part abbreviation letters to the international defaults
wcscpy_s (options.part_letters.rook, WCHAR_SIZEOF (options.part_letters.rook), L"R"); SetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_ROOK), options.part_letters.rook);
wcscpy_s (options.part_letters.knight, WCHAR_SIZEOF (options.part_letters.rook), L"N"); SetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_KNIGHT), options.part_letters.knight);
wcscpy_s (options.part_letters.bishop, WCHAR_SIZEOF (options.part_letters.rook), L"B"); SetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_BISHOP), options.part_letters.bishop);
wcscpy_s (options.part_letters.queen, WCHAR_SIZEOF (options.part_letters.rook), L"Q"); SetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_QUEEN), options.part_letters.queen);
wcscpy_s (options.part_letters.king, WCHAR_SIZEOF (options.part_letters.rook), L"K"); SetWindowText (TabControl_GetItem (tab_control, EDITBOX_OPTIONS_PARTLETTER_KING), options.part_letters.king);
}
// else is it the rotate board check box ? if so, enable or disable the speed slider
else if (wParam_loword == CHECKBOX_OPTIONS_ROTATEBOARD)
{
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_OPTIONS_ROTATESPEED), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD)));
EnableWindow (TabControl_GetItem (tab_control, SLIDER_OPTIONS_ROTATESPEED), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ROTATEBOARD)));
}
// 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
else if (wParam_loword == CHECKBOX_OPTIONS_IAMANEXPERT)
{
options.engine.is_expert_mode = (Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_IAMANEXPERT)) == BST_CHECKED);
EnableWindow (TabControl_GetItem (tab_control, BUTTON_EXPERTSETTINGS), options.engine.is_expert_mode);
SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_SETRANGE, true, MAKELONG (1, options.engine.max_depth * (options.engine.is_expert_mode ? 3 : 1)));
}
// else is it the allow engine blunders check box ? if so, enable or disable the blunder chance slider
else if (wParam_loword == CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS)
{
is_checked = Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINEBLUNDERS));
EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), is_checked);
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_1PCCHANCE), is_checked);
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_100PCCHANCE), is_checked);
if (is_checked)
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d %%", SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_GETPOS, 0, 0));
else
value_string[0] = 0;
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEBLUNDERSVALUE), value_string);
}
// else is it the allow engine resigns check box ? if so, enable or disable the blunder chance slider
else if (wParam_loword == CHECKBOX_OPTIONS_ALLOWENGINERESIGNS)
{
is_checked = Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_ALLOWENGINERESIGNS));
EnableWindow (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), is_checked);
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_YIELDING), is_checked);
EnableWindow (TabControl_GetItem (tab_control, STATICTEXT_OBSTINATE), is_checked);
if (is_checked)
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", 1 + SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_GETPOS, 0, 0));
else
value_string[0] = 0;
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINERESIGNVALUE), value_string);
}
// else is it the enable filtering check box ? if so, enable or disable the high quality checkbox
else if (wParam_loword == CHECKBOX_OPTIONS_TEXTUREFILTERING)
EnableWindow (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_HIGHQUALITYFILTERING), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_TEXTUREFILTERING)));
// else is it the show animations check box ? if so, enable or disable the show sliding animations checkbox too
else if (wParam_loword == CHECKBOX_OPTIONS_SHOWANIMATIONS)
EnableWindow (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWSLIDINGANIMATIONS), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWANIMATIONS)));
// else is it the show game clock check box ? if so, enable or disable the game clock color button
else if (wParam_loword == CHECKBOX_OPTIONS_SHOWCLOCK)
EnableWindow (TabControl_GetItem (tab_control, BUTTON_COLORCLOCK), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWCLOCK)));
// else is it the game clock color button ?
else if (wParam_loword == BUTTON_COLORCLOCK)
{
// prepare a color pick dialog box
memset (&cc, 0, sizeof (cc));
cc.lStructSize = sizeof (cc);
cc.hwndOwner = hWnd;
cc.lpCustColors = (unsigned long *) custom_colors;
cc.rgbResult = selectedcolor_clock;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
// fire it up
if (ChooseColor (&cc))
selectedcolor_clock = cc.rgbResult; // save away returned color
}
// else is it the show game history check box ? if so, enable or disable the game history color button
else if (wParam_loword == CHECKBOX_OPTIONS_SHOWHISTORY)
EnableWindow (TabControl_GetItem (tab_control, BUTTON_COLORHISTORY), Button_GetCheck (TabControl_GetItem (tab_control, CHECKBOX_OPTIONS_SHOWHISTORY)));
// else is it the game history color button ?
else if (wParam_loword == BUTTON_COLORHISTORY)
{
// prepare a color pick dialog box
memset (&cc, 0, sizeof (cc));
cc.lStructSize = sizeof (cc);
cc.hwndOwner = hWnd;
cc.lpCustColors = (unsigned long *) custom_colors;
cc.rgbResult = selectedcolor_history;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
// fire it up
if (ChooseColor (&cc))
selectedcolor_history = cc.rgbResult; // save away returned color
}
// else is it the create/manage account hyperlink ?
else if (wParam_loword == STATICTEXT_OPTIONS_SERVERURL)
{
swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), ACCOUNTCREATION_URL, languages[language_id].name); // build account creation url
ShellExecute (NULL, L"open", temp_string, NULL, NULL, SW_MAXIMIZE); // open the accounts page in the default browser, maximized
}
}
// else is it a notification for a slider moving ?
else if (message == WM_HSCROLL)
{
// is it the engine prediction level slider ? if so, update the slider value text
if ((HWND) lParam == TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL))
{
level = SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_DIFFICULTYLEVEL), TBM_GETPOS, 0, 0); // retrieve the difficulty level
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", level);
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINESEARCHDEPTHVALUE), value_string);
if ((level > 20) && (wParam_loword == SB_THUMBPOSITION))
MessageBox (hWnd, LOCALIZE (L"Options_ExcessiveDifficulty"), LOCALIZE (L"ImportantMessage"), MB_ICONWARNING | MB_OK); // if the user is a dumb fuck, let him know that he is (FIXME: this displays twice)
}
// else is it the engine blunders slider ? if so, update the slider value text
else if ((HWND) lParam == TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE))
{
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d %%", SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_BLUNDERCHANCE), TBM_GETPOS, 0, 0));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINEBLUNDERSVALUE), value_string);
}
// else is it the engine obstinacy slider ? if so, update the slider value text
else if ((HWND) lParam == TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY))
{
swprintf_s (value_string, WCHAR_SIZEOF (value_string), L"%d", 1 + SendMessage (TabControl_GetItem (tab_control, SLIDER_ENGINE_OBSTINACY), TBM_GETPOS, 0, 0));
SetWindowText (TabControl_GetItem (tab_control, STATICTEXT_ENGINERESIGNVALUE), value_string);
}
}
// else is it a notification for the tab control ?
else if ((message == WM_NOTIFY) && (((NMHDR *) lParam)->hwndFrom == GetDlgItem (hWnd, TABBOX_OPTIONS)))
TabControl_Notify ((NMHDR *) lParam);
// call the default dialog message processing function to keep things going
return (false);
}