2003-11-20 17:26:35 +01:00
|
|
|
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2006-01-08 02:25:02 +01:00
|
|
|
* Copyright 2002 by Eric House (xwords@eehouse.org). All rights reserved.
|
2003-11-20 17:26:35 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-05-12 09:25:43 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
#include "ceprefs.h"
|
|
|
|
#include "cemain.h"
|
2004-04-14 06:02:19 +02:00
|
|
|
#include "ceclrsel.h"
|
2003-11-20 17:26:35 +01:00
|
|
|
#include "ceutil.h"
|
2006-01-28 20:03:10 +01:00
|
|
|
#include "debhacks.h"
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
/* Stuff the strings for phonies. Why can't I put this in the resource?
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
stuffPhoniesList( HWND hDlg )
|
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
wchar_t* strings[] = {
|
|
|
|
L"Ignore",
|
|
|
|
L"Warn",
|
|
|
|
L"Disallow"
|
|
|
|
};
|
|
|
|
|
|
|
|
for ( i = 0; i < 3; ++i ) {
|
2008-03-15 16:39:58 +01:00
|
|
|
SendDlgItemMessage( hDlg, PHONIES_COMBO, ADDSTRING,
|
2003-11-20 17:26:35 +01:00
|
|
|
0, (long)strings[i] );
|
|
|
|
}
|
|
|
|
} /* stuffPhoniesList */
|
|
|
|
|
|
|
|
static void
|
|
|
|
turnOnOff( HWND hDlg, XP_U16* idList, XP_U16 idCount,
|
|
|
|
XP_Bool turnOn )
|
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
for ( i = 0; i < idCount; ++i ) {
|
|
|
|
ceShowOrHide( hDlg, *idList++, turnOn );
|
|
|
|
}
|
|
|
|
} /* turnOff */
|
|
|
|
|
|
|
|
static void
|
|
|
|
setTimerCtls( HWND hDlg, XP_Bool checked )
|
|
|
|
{
|
|
|
|
ceShowOrHide( hDlg, TIMER_EDIT, checked );
|
|
|
|
|
|
|
|
SendDlgItemMessage( hDlg, TIMER_CHECK, BM_SETCHECK,
|
|
|
|
checked? BST_CHECKED:BST_UNCHECKED, 0 );
|
|
|
|
} /* setTimerCtls */
|
|
|
|
|
|
|
|
static void
|
2004-04-14 06:02:19 +02:00
|
|
|
adjustForChoice( HWND hDlg, CePrefsDlgState* state )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
XP_U16 goesWithGlobal[] = {IDC_CHECKCOLORPLAYED, IDC_LEFTYCHECK,
|
2004-04-14 06:02:19 +02:00
|
|
|
IDC_CHECKSHOWCURSOR, IDC_CHECKROBOTSCORES,
|
|
|
|
IDC_PREFCOLORS };
|
2004-06-18 15:28:31 +02:00
|
|
|
XP_U16 goesWithLocal[] = {IDC_CHECKSMARTROBOT, IDC_CHECKNOHINTS,
|
2003-11-20 17:26:35 +01:00
|
|
|
TIMER_CHECK, TIMER_EDIT, PHONIES_LABEL,
|
2008-03-15 16:39:58 +01:00
|
|
|
PHONIES_COMBO, IDC_PHONIESUPDOWN, IDC_PICKTILES
|
2004-06-18 15:28:31 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
,IDC_CHECKHINTSLIMITS
|
|
|
|
#endif
|
|
|
|
};
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 resID;
|
2004-06-18 15:28:31 +02:00
|
|
|
XP_Bool doGlobalPrefs = state->globals->doGlobalPrefs;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-06-18 15:28:31 +02:00
|
|
|
resID = doGlobalPrefs? IDC_RADIOGLOBAL:IDC_RADIOLOCAL;
|
2003-11-20 17:26:35 +01:00
|
|
|
SendDlgItemMessage( hDlg, resID, BM_SETCHECK, BST_CHECKED, 0L );
|
|
|
|
|
2004-06-18 15:28:31 +02:00
|
|
|
if ( doGlobalPrefs ) {
|
2007-05-26 16:03:07 +02:00
|
|
|
turnOnOff( hDlg, goesWithLocal, VSIZE(goesWithLocal), XP_FALSE );
|
|
|
|
turnOnOff( hDlg, goesWithGlobal, VSIZE(goesWithGlobal), XP_TRUE);
|
2003-11-20 17:26:35 +01:00
|
|
|
} else {
|
2007-05-26 16:03:07 +02:00
|
|
|
turnOnOff( hDlg, goesWithGlobal, VSIZE(goesWithGlobal), XP_FALSE );
|
|
|
|
turnOnOff( hDlg, goesWithLocal, VSIZE(goesWithLocal), XP_TRUE);
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2004-06-18 15:28:31 +02:00
|
|
|
|
|
|
|
if ( !doGlobalPrefs ) {
|
2006-07-02 02:39:31 +02:00
|
|
|
setTimerCtls( hDlg, ceGetChecked( hDlg, TIMER_CHECK ) );
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
2004-06-18 15:28:31 +02:00
|
|
|
ceShowOrHide( hDlg, IDC_CHECKHINTSLIMITS,
|
|
|
|
!ceGetChecked( hDlg, IDC_CHECKNOHINTS) );
|
|
|
|
#endif
|
2006-07-02 02:39:31 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* adjustForChoice */
|
|
|
|
|
|
|
|
/* Copy global state into a local copy that can be changed without
|
|
|
|
* committing should user cancel.
|
|
|
|
*/
|
|
|
|
void
|
2008-02-16 17:02:49 +01:00
|
|
|
loadStateFromCurPrefs( CEAppGlobals* XP_UNUSED_STANDALONE(globals),
|
|
|
|
const CEAppPrefs* appPrefs,
|
2005-07-23 17:31:21 +02:00
|
|
|
const CurGameInfo* gi, CePrefsPrefs* prefsPrefs )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
prefsPrefs->gp.hintsNotAllowed = gi->hintsNotAllowed;
|
|
|
|
prefsPrefs->gp.robotSmartness = gi->robotSmartness;
|
|
|
|
prefsPrefs->gp.timerEnabled = gi->timerEnabled;
|
|
|
|
prefsPrefs->gp.gameSeconds = gi->gameSeconds;
|
|
|
|
prefsPrefs->gp.phoniesAction = gi->phoniesAction;
|
2003-12-09 06:20:10 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
prefsPrefs->gp.allowPickTiles = gi->allowPickTiles;
|
2004-06-18 15:28:31 +02:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
prefsPrefs->gp.allowHintRect = gi->allowHintRect;
|
2003-12-09 06:20:10 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
prefsPrefs->showColors = appPrefs->showColors;
|
|
|
|
|
|
|
|
XP_MEMCPY( &prefsPrefs->cp, &appPrefs->cp, sizeof(prefsPrefs->cp) );
|
2004-04-14 06:02:19 +02:00
|
|
|
XP_MEMCPY( &prefsPrefs->colors, &appPrefs->colors,
|
|
|
|
sizeof(prefsPrefs->colors) );
|
2005-07-23 17:31:21 +02:00
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2005-07-23 17:31:21 +02:00
|
|
|
if ( globals->game.comms != NULL ) {
|
|
|
|
comms_getAddr( globals->game.comms, &prefsPrefs->addrRec );
|
|
|
|
} else {
|
|
|
|
comms_getInitialAddr( &prefsPrefs->addrRec );
|
|
|
|
}
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* loadStateFromCurPrefs */
|
|
|
|
|
|
|
|
void
|
2008-02-16 17:02:49 +01:00
|
|
|
loadCurPrefsFromState( CEAppGlobals* XP_UNUSED_STANDALONE(globals),
|
|
|
|
CEAppPrefs* appPrefs,
|
2005-07-23 17:31:21 +02:00
|
|
|
CurGameInfo* gi, const CePrefsPrefs* prefsPrefs )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
gi->hintsNotAllowed = prefsPrefs->gp.hintsNotAllowed;
|
|
|
|
gi->robotSmartness = prefsPrefs->gp.robotSmartness;
|
|
|
|
gi->timerEnabled = prefsPrefs->gp.timerEnabled;
|
|
|
|
gi->gameSeconds = prefsPrefs->gp.gameSeconds;
|
|
|
|
gi->phoniesAction = prefsPrefs->gp.phoniesAction;
|
2003-12-09 06:20:10 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
gi->allowPickTiles = prefsPrefs->gp.allowPickTiles;
|
2004-06-18 15:28:31 +02:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
gi->allowHintRect = prefsPrefs->gp.allowHintRect;
|
2003-12-09 06:20:10 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
appPrefs->showColors = prefsPrefs->showColors;
|
|
|
|
|
|
|
|
XP_MEMCPY( &appPrefs->cp, &prefsPrefs->cp, sizeof(appPrefs->cp) );
|
2004-04-14 06:02:19 +02:00
|
|
|
XP_MEMCPY( &appPrefs->colors, &prefsPrefs->colors,
|
|
|
|
sizeof(prefsPrefs->colors) );
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
/* I don't think this'll work... */
|
|
|
|
if ( globals->game.comms != NULL ) {
|
|
|
|
comms_setAddr( globals->game.comms, &prefsPrefs->addrRec );
|
|
|
|
} else {
|
|
|
|
XP_LOGF( "no comms to set addr on!!!" );
|
|
|
|
}
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* loadCurPrefsFromState */
|
|
|
|
|
|
|
|
/* Reflect local state into the controls user will see.
|
|
|
|
*/
|
|
|
|
static void
|
2004-04-14 06:02:19 +02:00
|
|
|
loadControlsFromState( HWND hDlg, CePrefsDlgState* pState )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2004-04-14 06:02:19 +02:00
|
|
|
CePrefsPrefs* prefsPrefs = &pState->prefsPrefs;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
ceSetChecked( hDlg, IDC_CHECKCOLORPLAYED, prefsPrefs->showColors );
|
|
|
|
ceSetChecked( hDlg, IDC_CHECKSMARTROBOT,
|
2004-12-12 18:33:52 +01:00
|
|
|
prefsPrefs->gp.robotSmartness > 0 );
|
2003-11-20 17:26:35 +01:00
|
|
|
ceSetChecked( hDlg, IDC_CHECKNOHINTS, prefsPrefs->gp.hintsNotAllowed );
|
|
|
|
|
|
|
|
ceSetChecked( hDlg, IDC_CHECKSHOWCURSOR, prefsPrefs->cp.showBoardArrow );
|
|
|
|
ceSetChecked( hDlg, IDC_CHECKROBOTSCORES, prefsPrefs->cp.showRobotScores );
|
|
|
|
|
2003-12-09 06:20:10 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
ceSetChecked( hDlg, IDC_PICKTILES, prefsPrefs->gp.allowPickTiles );
|
2004-06-18 15:28:31 +02:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
ceSetChecked( hDlg, IDC_CHECKHINTSLIMITS, prefsPrefs->gp.allowHintRect );
|
2003-12-09 06:20:10 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
/* timer */
|
2006-07-02 02:39:31 +02:00
|
|
|
ceSetDlgItemNum( hDlg, TIMER_EDIT, prefsPrefs->gp.gameSeconds / 60 );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-03-15 16:39:58 +01:00
|
|
|
SendDlgItemMessage( hDlg, PHONIES_COMBO, SETCURSEL,
|
2003-11-20 17:26:35 +01:00
|
|
|
prefsPrefs->gp.phoniesAction, 0L );
|
|
|
|
|
|
|
|
if ( !pState->isNewGame ) {
|
2004-05-28 04:46:42 +02:00
|
|
|
XP_U16 unavail[] = { TIMER_CHECK, TIMER_EDIT, IDC_CHECKNOHINTS
|
2003-12-09 06:20:10 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
2004-05-28 04:46:42 +02:00
|
|
|
,IDC_PICKTILES
|
2003-12-09 06:20:10 +01:00
|
|
|
#endif
|
2004-05-28 04:46:42 +02:00
|
|
|
};
|
|
|
|
XP_U16 i;
|
2007-05-26 16:03:07 +02:00
|
|
|
for ( i = 0; i < VSIZE(unavail); ++i ) {
|
2004-05-28 04:46:42 +02:00
|
|
|
ceEnOrDisable( hDlg, unavail[i], XP_FALSE );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
} /* loadControlsFromState */
|
|
|
|
|
|
|
|
/* Save the new choices into state so caller can do what it wants with
|
|
|
|
* the values.
|
|
|
|
*/
|
|
|
|
static void
|
2004-04-14 06:02:19 +02:00
|
|
|
ceControlsToPrefs( HWND hDlg, CePrefsPrefs* prefsPrefs )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
XP_S16 selIndex;
|
|
|
|
|
|
|
|
prefsPrefs->showColors = ceGetChecked( hDlg, IDC_CHECKCOLORPLAYED );
|
|
|
|
prefsPrefs->gp.robotSmartness
|
|
|
|
= ceGetChecked( hDlg, IDC_CHECKSMARTROBOT ) ? 1 : 0;
|
|
|
|
prefsPrefs->gp.hintsNotAllowed = ceGetChecked( hDlg, IDC_CHECKNOHINTS );
|
|
|
|
|
2008-03-15 16:39:58 +01:00
|
|
|
selIndex = (XP_U16)SendDlgItemMessage( hDlg, PHONIES_COMBO, GETCURSEL,
|
2003-11-20 17:26:35 +01:00
|
|
|
0, 0 );
|
|
|
|
if ( selIndex != LB_ERR ) {
|
|
|
|
prefsPrefs->gp.phoniesAction = (XWPhoniesChoice)selIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
prefsPrefs->cp.showBoardArrow = ceGetChecked( hDlg, IDC_CHECKSHOWCURSOR );
|
|
|
|
prefsPrefs->cp.showRobotScores = ceGetChecked( hDlg, IDC_CHECKROBOTSCORES );
|
2004-03-19 05:32:25 +01:00
|
|
|
prefsPrefs->gp.timerEnabled = ceGetChecked( hDlg, TIMER_CHECK );
|
|
|
|
|
|
|
|
if ( prefsPrefs->gp.timerEnabled ) {
|
|
|
|
XP_U16 minutes;
|
|
|
|
|
2006-07-02 02:39:31 +02:00
|
|
|
minutes = ceGetDlgItemNum( hDlg, TIMER_EDIT );
|
2004-03-19 05:32:25 +01:00
|
|
|
|
|
|
|
prefsPrefs->gp.gameSeconds = minutes * 60;
|
|
|
|
}
|
2003-12-09 06:20:10 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
prefsPrefs->gp.allowPickTiles = ceGetChecked( hDlg, IDC_PICKTILES );
|
|
|
|
#endif
|
2004-06-18 15:28:31 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
prefsPrefs->gp.allowHintRect = ceGetChecked( hDlg, IDC_CHECKHINTSLIMITS );
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ceControlsToPrefs */
|
|
|
|
|
|
|
|
LRESULT CALLBACK
|
|
|
|
PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals;
|
|
|
|
XP_U16 id;
|
2004-04-14 06:02:19 +02:00
|
|
|
CePrefsDlgState* pState;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
|
|
|
SetWindowLong( hDlg, GWL_USERDATA, lParam );
|
2004-04-14 06:02:19 +02:00
|
|
|
pState = (CePrefsDlgState*)lParam;
|
2003-11-20 17:26:35 +01:00
|
|
|
globals = pState->globals;
|
|
|
|
|
|
|
|
stuffPhoniesList( hDlg );
|
|
|
|
|
|
|
|
loadControlsFromState( hDlg, pState );
|
|
|
|
adjustForChoice( hDlg, pState );
|
|
|
|
|
2006-05-27 19:18:42 +02:00
|
|
|
ceStackButtonsRight( globals, hDlg );
|
2006-05-25 05:41:32 +02:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
XP_Bool timerOn;
|
2004-04-14 06:02:19 +02:00
|
|
|
pState = (CePrefsDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
|
2004-05-26 06:46:57 +02:00
|
|
|
if ( !!pState ) {
|
|
|
|
globals = pState->globals;
|
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
id = LOWORD(wParam);
|
|
|
|
switch( id ) {
|
|
|
|
|
|
|
|
case IDC_RADIOGLOBAL:
|
|
|
|
case IDC_RADIOLOCAL:
|
|
|
|
pState->globals->doGlobalPrefs = id == IDC_RADIOGLOBAL;
|
|
|
|
adjustForChoice( hDlg, pState );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIMER_CHECK:
|
|
|
|
timerOn = SendDlgItemMessage( hDlg, TIMER_CHECK, BM_GETCHECK,
|
|
|
|
0, 0 );
|
|
|
|
setTimerCtls( hDlg, timerOn );
|
|
|
|
break;
|
|
|
|
case IDC_PREFCOLORS:
|
|
|
|
pState->colorsChanged =
|
|
|
|
ceDoColorsEdit( hDlg, pState->globals,
|
|
|
|
pState->prefsPrefs.colors );
|
|
|
|
break;
|
2004-06-18 15:28:31 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
case IDC_CHECKNOHINTS:
|
|
|
|
timerOn = SendDlgItemMessage( hDlg, IDC_CHECKNOHINTS,
|
|
|
|
BM_GETCHECK, 0, 0 );
|
|
|
|
ceShowOrHide( hDlg, IDC_CHECKHINTSLIMITS, !timerOn );
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-05-26 06:46:57 +02:00
|
|
|
case IDOK:
|
|
|
|
ceControlsToPrefs( hDlg, &pState->prefsPrefs );
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hDlg, id);
|
|
|
|
pState->userCancelled = id == IDCANCEL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
} /* PrefsDlg */
|
|
|
|
|
|
|
|
/* Using state in prefsPrefs, and initing and then storing dialog state in
|
|
|
|
state, put up the dialog and return whether it was cancelled.
|
|
|
|
*/
|
|
|
|
XP_Bool
|
2004-04-14 06:02:19 +02:00
|
|
|
WrapPrefsDialog( HWND hDlg, CEAppGlobals* globals, CePrefsDlgState* state,
|
|
|
|
CePrefsPrefs* prefsPrefs, XP_Bool isNewGame )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
XP_Bool result;
|
|
|
|
XP_MEMSET( state, 0, sizeof(*state) );
|
|
|
|
|
|
|
|
state->globals = globals;
|
|
|
|
state->isNewGame = isNewGame;
|
|
|
|
XP_MEMCPY( &state->prefsPrefs, prefsPrefs, sizeof( state->prefsPrefs ) );
|
|
|
|
|
2006-03-20 05:13:40 +01:00
|
|
|
DialogBoxParam( globals->hInst, (LPCTSTR)IDD_OPTIONSDLG, hDlg,
|
|
|
|
(DLGPROC)PrefsDlg, (long)state );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
result = !state->userCancelled;
|
|
|
|
|
|
|
|
if ( result ) {
|
|
|
|
XP_MEMCPY( prefsPrefs, &state->prefsPrefs, sizeof( *prefsPrefs ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* WrapPrefsDialog */
|