2003-11-20 17:26:35 +01:00
|
|
|
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2006-04-20 15:47:58 +02:00
|
|
|
* Copyright 2002-2006 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:17:35 +02:00
|
|
|
#include <stdio.h> /* swprintf */
|
2003-11-20 17:26:35 +01:00
|
|
|
#include "ceginfo.h"
|
|
|
|
#include "cemain.h"
|
|
|
|
#include "ceutil.h"
|
|
|
|
#include "cedict.h"
|
2005-07-23 17:31:21 +02:00
|
|
|
#include "cecondlg.h"
|
2003-11-20 17:26:35 +01:00
|
|
|
#include "strutils.h"
|
|
|
|
|
|
|
|
#define NUM_COLS 4
|
2006-04-20 06:39:46 +02:00
|
|
|
#define MENUDICTS_INCR 16
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-04-30 21:54:40 +02:00
|
|
|
static XP_S16
|
|
|
|
findInsertPoint( const wchar_t* wPath, wchar_t** menuDicts,
|
|
|
|
XP_U16 nMenuDicts )
|
|
|
|
{
|
|
|
|
XP_S16 loc = 0; /* simple case: nothing here */
|
|
|
|
|
|
|
|
if ( nMenuDicts > 0 ) {
|
|
|
|
wchar_t thisShortBuf[CE_MAX_PATH_LEN+1];
|
|
|
|
wchar_t* thisShortName = wbname( thisShortBuf, sizeof(thisShortBuf),
|
|
|
|
wPath );
|
|
|
|
|
|
|
|
/* If the short path doesn't already exist, find where it belongs. This
|
|
|
|
is wasteful if we're doing this a lot since the short path isn't
|
|
|
|
cached. */
|
|
|
|
for ( /* loc = 0*/; loc < nMenuDicts; ++loc ) {
|
|
|
|
wchar_t oneShortBuf[CE_MAX_PATH_LEN+1];
|
|
|
|
wchar_t* oneShortName = wbname( oneShortBuf, sizeof(oneShortBuf),
|
|
|
|
menuDicts[loc] );
|
|
|
|
int diff = _wcsicmp( thisShortName, oneShortName );
|
|
|
|
if ( diff > 0 ) {
|
|
|
|
continue;
|
|
|
|
} else if ( diff == 0 ) {
|
|
|
|
loc = -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return loc;
|
|
|
|
} /* findInsertPoint */
|
2006-04-19 06:56:00 +02:00
|
|
|
|
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
addDictToState( const wchar_t* wPath, XP_U16 XP_UNUSED(index), void* ctxt )
|
2006-04-19 06:56:00 +02:00
|
|
|
{
|
|
|
|
GameInfoState* giState = (GameInfoState*)ctxt;
|
2006-04-20 06:39:46 +02:00
|
|
|
/* Let's display only the short form, but save the whole path */
|
|
|
|
wchar_t* wstr;
|
|
|
|
XP_U16 len;
|
2006-04-30 21:54:40 +02:00
|
|
|
XP_S16 loc; /* < 0 means skip it */
|
2006-04-20 06:39:46 +02:00
|
|
|
|
2006-04-30 21:54:40 +02:00
|
|
|
loc = findInsertPoint( wPath, giState->menuDicts,
|
|
|
|
giState->nMenuDicts );
|
|
|
|
|
|
|
|
if ( loc >= 0 ) {
|
|
|
|
/* make a copy of the long name */
|
|
|
|
len = wcslen( wPath ) + 1;
|
|
|
|
wstr = (wchar_t*)XP_MALLOC( giState->globals->mpool,
|
|
|
|
len * sizeof(wstr[0]) );
|
|
|
|
|
|
|
|
XP_MEMCPY( wstr, wPath, len*sizeof(wstr[0]) );
|
|
|
|
if ( !giState->menuDicts ) {
|
|
|
|
XP_ASSERT( giState->nMenuDicts == 0 );
|
|
|
|
XP_ASSERT( giState->capMenuDicts == 0 );
|
|
|
|
giState->capMenuDicts = MENUDICTS_INCR;
|
|
|
|
giState->menuDicts
|
|
|
|
= (wchar_t**)XP_MALLOC( giState->globals->mpool,
|
|
|
|
giState->capMenuDicts
|
|
|
|
* sizeof(giState->menuDicts[0]) );
|
|
|
|
} else if ( giState->nMenuDicts == giState->capMenuDicts ) {
|
|
|
|
giState->capMenuDicts += MENUDICTS_INCR;
|
|
|
|
giState->menuDicts
|
|
|
|
= (wchar_t**)XP_REALLOC( giState->globals->mpool,
|
|
|
|
giState->menuDicts,
|
|
|
|
giState->capMenuDicts
|
|
|
|
* sizeof(giState->menuDicts[0]) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( loc < giState->nMenuDicts ) {
|
|
|
|
XP_MEMMOVE( &giState->menuDicts[loc+1], &giState->menuDicts[loc],
|
|
|
|
(giState->nMenuDicts - loc)
|
|
|
|
* sizeof(giState->menuDicts[0]) );
|
2006-04-19 06:56:00 +02:00
|
|
|
}
|
2006-04-30 21:54:40 +02:00
|
|
|
giState->menuDicts[loc] = wstr;
|
|
|
|
++giState->nMenuDicts;
|
2006-04-19 06:56:00 +02:00
|
|
|
}
|
|
|
|
|
2006-04-25 06:25:08 +02:00
|
|
|
return XP_FALSE;
|
2006-04-30 21:54:40 +02:00
|
|
|
} /* addDictToState */
|
|
|
|
|
|
|
|
static void
|
|
|
|
addDictsToMenu( GameInfoState* giState )
|
|
|
|
{
|
|
|
|
wchar_t* shortname;
|
|
|
|
wchar_t shortPath[CE_MAX_PATH_LEN+1];
|
|
|
|
XP_U16 i, nMenuDicts = giState->nMenuDicts;
|
|
|
|
XP_S16 sel = 0;
|
|
|
|
|
|
|
|
/* insert the short names in the menu */
|
|
|
|
for ( i = 0; i < nMenuDicts; ++i ) {
|
|
|
|
wchar_t* wPath = giState->menuDicts[i];
|
|
|
|
shortname = wbname( shortPath, sizeof(shortPath), wPath );
|
|
|
|
SendDlgItemMessage( giState->hDlg, IDC_DICTCOMBO, CB_ADDSTRING, 0,
|
|
|
|
(long)shortname );
|
|
|
|
|
|
|
|
if ( giState->newDictName[0] != 0 && sel == 0 ) {
|
|
|
|
XP_UCHAR buf[CE_MAX_PATH_LEN+1];
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, wPath, -1, buf, sizeof(buf),
|
|
|
|
NULL, NULL );
|
|
|
|
if ( 0 == XP_STRCMP( buf, giState->newDictName ) ) {
|
|
|
|
sel = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SendDlgItemMessage( giState->hDlg, IDC_DICTCOMBO, CB_SETCURSEL, sel, 0L );
|
|
|
|
} /* addDictsToMenu */
|
2006-04-19 06:56:00 +02:00
|
|
|
|
2006-04-20 06:39:46 +02:00
|
|
|
static void
|
|
|
|
cleanupGameInfoState( GameInfoState* giState )
|
|
|
|
{
|
|
|
|
if ( !!giState->menuDicts ) {
|
|
|
|
XP_U16 nMenuDicts = giState->nMenuDicts;
|
|
|
|
XP_U16 i;
|
|
|
|
for ( i = 0; i < nMenuDicts; ++i ) {
|
|
|
|
XP_FREE( giState->globals->mpool, giState->menuDicts[i] );
|
|
|
|
}
|
|
|
|
XP_FREE( giState->globals->mpool, giState->menuDicts );
|
|
|
|
giState->menuDicts = NULL;
|
|
|
|
}
|
|
|
|
} /* cleanupGameInfoState */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
|
|
|
loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
|
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
CurGameInfo* gi = &globals->gameInfo;
|
2006-06-08 03:35:20 +02:00
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2003-11-20 17:26:35 +01:00
|
|
|
wchar_t* roles[] = { L"Standalone", L"Host", L"Guest" };
|
2007-05-26 16:03:07 +02:00
|
|
|
for ( i = 0; i < VSIZE(roles); ++i ) {
|
2006-06-08 03:35:20 +02:00
|
|
|
SendDlgItemMessage( hDlg, IDC_ROLECOMBO, CB_ADDSTRING, 0,
|
|
|
|
(long)roles[i] );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
2006-06-08 03:35:20 +02:00
|
|
|
wchar_t widebuf[8];
|
2003-11-20 17:26:35 +01:00
|
|
|
/* put a string in the moronic combobox */
|
|
|
|
swprintf( widebuf, L"%d", i + 1 );
|
|
|
|
SendDlgItemMessage( hDlg, IDC_NPLAYERSCOMBO, CB_ADDSTRING, 0,
|
|
|
|
(long)widebuf );
|
|
|
|
}
|
|
|
|
|
2006-06-08 03:35:20 +02:00
|
|
|
newg_load( giState->newGameCtx, gi );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2005-11-27 21:13:42 +01:00
|
|
|
#ifndef STUBBED_DICT
|
2006-04-19 06:56:00 +02:00
|
|
|
if ( !!gi->dictName ) {
|
|
|
|
XP_LOGF( "%s: copying %s to giState->newDictName",
|
2007-12-02 20:13:25 +01:00
|
|
|
__func__, gi->dictName );
|
2006-04-19 06:56:00 +02:00
|
|
|
XP_MEMCPY( giState->newDictName, gi->dictName,
|
2005-06-28 06:42:08 +02:00
|
|
|
(XP_U16)XP_STRLEN(gi->dictName)+1 );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2006-04-19 06:56:00 +02:00
|
|
|
if ( giState->isNewGame ) {
|
2006-04-30 21:54:40 +02:00
|
|
|
(void)ceLocateNDicts( MPPARM(globals->mpool) globals->hInst,
|
|
|
|
CE_MAXDICTS, addDictToState, giState );
|
2006-04-22 16:19:21 +02:00
|
|
|
} else {
|
|
|
|
wchar_t wPath[CE_MAX_PATH_LEN+1];
|
|
|
|
XP_ASSERT( gi->dictName[0] != '\0' );
|
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, gi->dictName, -1,
|
2007-05-26 16:03:07 +02:00
|
|
|
wPath, VSIZE(wPath) );
|
2006-04-30 21:54:40 +02:00
|
|
|
(void)addDictToState( wPath, 0, giState );
|
2006-04-19 06:56:00 +02:00
|
|
|
}
|
2006-04-30 21:54:40 +02:00
|
|
|
addDictsToMenu( giState );
|
2006-04-19 06:56:00 +02:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( !giState->isNewGame ) {
|
2006-06-08 03:35:20 +02:00
|
|
|
ceEnOrDisable( hDlg, IDC_DICTCOMBO, XP_FALSE );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
} /* loadFromGameInfo */
|
|
|
|
|
2008-01-05 17:37:49 +01:00
|
|
|
static XP_Bool
|
2003-11-20 17:26:35 +01:00
|
|
|
stateToGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
|
|
|
|
{
|
|
|
|
CurGameInfo* gi = &globals->gameInfo;
|
|
|
|
XP_Bool timerOn;
|
2008-01-05 17:37:49 +01:00
|
|
|
XP_Bool success = newg_store( giState->newGameCtx, gi, XP_TRUE );
|
|
|
|
|
|
|
|
if ( success ) {
|
|
|
|
|
|
|
|
/* dictionary */ {
|
|
|
|
int sel;
|
|
|
|
sel = SendDlgItemMessage( hDlg, IDC_DICTCOMBO, CB_GETCURSEL,
|
|
|
|
0, 0L );
|
|
|
|
if ( sel >= 0 ) {
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, giState->menuDicts[sel], -1,
|
|
|
|
giState->newDictName,
|
|
|
|
sizeof(giState->newDictName), NULL, NULL );
|
|
|
|
}
|
|
|
|
replaceStringIfDifferent( globals->mpool, &gi->dictName,
|
|
|
|
giState->newDictName );
|
2006-04-19 06:56:00 +02:00
|
|
|
}
|
|
|
|
|
2008-01-05 17:37:49 +01:00
|
|
|
/* timer */
|
|
|
|
timerOn = ceGetChecked( hDlg, TIMER_CHECK );
|
|
|
|
gi->timerEnabled = timerOn;
|
|
|
|
if ( timerOn ) {
|
|
|
|
XP_UCHAR numBuf[10];
|
|
|
|
XP_U16 len = sizeof(numBuf);
|
|
|
|
ceGetDlgItemText( hDlg, TIMER_EDIT, numBuf, &len );
|
|
|
|
if ( len > 0 ) {
|
|
|
|
XP_U16 num = atoi( numBuf );
|
|
|
|
gi->gameSeconds = num * 60;
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
2008-01-05 17:37:49 +01:00
|
|
|
/* preferences */
|
|
|
|
if ( giState->prefsChanged ) {
|
|
|
|
loadCurPrefsFromState( globals, &globals->appPrefs, gi,
|
|
|
|
&giState->prefsPrefs );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
2008-01-05 17:37:49 +01:00
|
|
|
LOG_RETURNF( "%d", (int)success );
|
|
|
|
return success;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* stateToGameInfo */
|
|
|
|
|
|
|
|
static void
|
2006-05-19 15:45:48 +02:00
|
|
|
handlePrefsButton( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2004-04-14 05:57:59 +02:00
|
|
|
CePrefsDlgState state;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
/* need to keep my stuff in a temporary place and to read back out of it
|
|
|
|
if launched a second time before the user's cancelled or not out of
|
|
|
|
the calling dlg.*/
|
|
|
|
|
|
|
|
if ( WrapPrefsDialog( hDlg, globals, &state, &giState->prefsPrefs,
|
|
|
|
giState->isNewGame ) ) {
|
|
|
|
giState->prefsChanged = XP_TRUE;
|
2004-05-26 06:39:29 +02:00
|
|
|
giState->colorsChanged = state.colorsChanged;
|
2003-11-20 17:26:35 +01:00
|
|
|
/* nothing to do until user finally does confirm the parent dialog */
|
|
|
|
}
|
2006-05-19 15:45:48 +02:00
|
|
|
} /* handlePrefsButton */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2005-07-23 17:31:21 +02:00
|
|
|
static void
|
2006-06-08 03:35:20 +02:00
|
|
|
handleConnOptionsButton( HWND hDlg, CEAppGlobals* globals,
|
2007-02-02 09:34:37 +01:00
|
|
|
DeviceRole role, GameInfoState* giState )
|
2005-07-23 17:31:21 +02:00
|
|
|
{
|
|
|
|
CeConnDlgState state;
|
|
|
|
|
2006-06-08 03:35:20 +02:00
|
|
|
if ( WrapConnsDlg( hDlg, globals, &giState->prefsPrefs.addrRec,
|
2006-10-28 16:56:04 +02:00
|
|
|
role, &state ) ) {
|
2006-06-08 03:35:20 +02:00
|
|
|
XP_MEMCPY( &giState->prefsPrefs.addrRec, &state.addrRec,
|
2005-07-23 17:31:21 +02:00
|
|
|
sizeof(giState->prefsPrefs.addrRec) );
|
|
|
|
giState->addrChanged = XP_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-06-08 03:35:20 +02:00
|
|
|
static XP_U16
|
|
|
|
resIDForCol( XP_U16 player, NewGameColumn col )
|
|
|
|
{
|
2006-06-11 22:12:20 +02:00
|
|
|
XP_U16 resID = 0;
|
2006-06-08 03:35:20 +02:00
|
|
|
switch ( col ) {
|
2006-06-08 03:51:34 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_COL_REMOTE:
|
|
|
|
resID = REMOTE_CHECK1;
|
|
|
|
break;
|
2006-06-08 03:51:34 +02:00
|
|
|
#endif
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_COL_ROBOT:
|
|
|
|
resID = ROBOT_CHECK1;
|
|
|
|
break;
|
|
|
|
case NG_COL_NAME:
|
|
|
|
resID = NAME_EDIT1;
|
|
|
|
break;
|
|
|
|
case NG_COL_PASSWD:
|
|
|
|
resID = PASS_EDIT1;
|
|
|
|
break;
|
|
|
|
}
|
2006-06-11 22:12:20 +02:00
|
|
|
XP_ASSERT( resID != 0 );
|
2006-06-08 03:35:20 +02:00
|
|
|
return resID + ( player * NUM_COLS );
|
|
|
|
} /* resIDForCol */
|
|
|
|
|
|
|
|
static XP_U16
|
|
|
|
resIDForAttr( NewGameAttr attr )
|
|
|
|
{
|
2006-06-11 22:12:20 +02:00
|
|
|
XP_U16 resID = 0;
|
2006-06-08 03:35:20 +02:00
|
|
|
switch( attr ) {
|
|
|
|
case NG_ATTR_NPLAYERS:
|
|
|
|
resID = IDC_NPLAYERSCOMBO;
|
|
|
|
break;
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_ATTR_ROLE:
|
|
|
|
resID = IDC_ROLECOMBO;
|
|
|
|
break;
|
2006-06-10 18:15:31 +02:00
|
|
|
case NG_ATTR_REMHEADER:
|
|
|
|
resID = IDC_REMOTE_LABEL;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case NG_ATTR_NPLAYHEADER:
|
|
|
|
resID = IDC_TOTAL_LABEL;
|
|
|
|
break;
|
2006-06-18 21:02:47 +02:00
|
|
|
case NG_ATTR_CANJUGGLE:
|
|
|
|
resID = GIJUGGLE_BUTTON;
|
|
|
|
break;
|
2006-10-28 16:56:04 +02:00
|
|
|
default:
|
|
|
|
break;
|
2006-06-08 03:35:20 +02:00
|
|
|
}
|
2006-06-11 22:12:20 +02:00
|
|
|
XP_ASSERT( resID != 0 );
|
2006-06-08 03:35:20 +02:00
|
|
|
return resID;
|
|
|
|
} /* resIDForAttr */
|
|
|
|
|
2006-06-10 18:15:31 +02:00
|
|
|
static void
|
2006-10-28 16:56:04 +02:00
|
|
|
doForNWEnable( HWND hDlg, XP_U16 resID, XP_TriEnable enable )
|
2006-06-10 18:15:31 +02:00
|
|
|
{
|
2006-10-28 16:56:04 +02:00
|
|
|
XP_Bool makeVisible = enable != TRI_ENAB_HIDDEN;
|
2006-06-10 18:15:31 +02:00
|
|
|
ceShowOrHide( hDlg, resID, makeVisible );
|
|
|
|
if ( makeVisible ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
ceEnOrDisable( hDlg, resID, enable == TRI_ENAB_ENABLED );
|
2006-06-10 18:15:31 +02:00
|
|
|
}
|
|
|
|
} /* doForNWEnable */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
2006-06-08 03:35:20 +02:00
|
|
|
ceEnableColProc( void* closure, XP_U16 player, NewGameColumn col,
|
2006-10-28 16:56:04 +02:00
|
|
|
XP_TriEnable enable )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2006-06-08 03:35:20 +02:00
|
|
|
GameInfoState* giState = (GameInfoState*)closure;
|
2006-06-10 18:15:31 +02:00
|
|
|
XP_U16 resID = resIDForCol( player, col );
|
|
|
|
doForNWEnable( giState->hDlg, resID, enable );
|
2006-06-08 03:35:20 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-06-08 03:35:20 +02:00
|
|
|
static void
|
2006-10-28 16:56:04 +02:00
|
|
|
ceEnableAttrProc( void* closure, NewGameAttr attr, XP_TriEnable enable )
|
2006-06-08 03:35:20 +02:00
|
|
|
{
|
|
|
|
GameInfoState* giState = (GameInfoState*)closure;
|
|
|
|
XP_U16 resID = resIDForAttr( attr );
|
2006-06-10 18:15:31 +02:00
|
|
|
doForNWEnable( giState->hDlg, resID, enable );
|
2006-06-08 03:35:20 +02:00
|
|
|
} /* ceEnableAttrProc */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceGetColProc( void* closure, XP_U16 player, NewGameColumn col,
|
|
|
|
NgCpCallbk cpcb, const void* cpClosure )
|
|
|
|
{
|
|
|
|
NGValue value;
|
|
|
|
GameInfoState* giState = (GameInfoState*)closure;
|
|
|
|
XP_U16 resID = resIDForCol( player, col );
|
|
|
|
XP_UCHAR txt[128];
|
|
|
|
XP_U16 len;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-06-08 03:35:20 +02:00
|
|
|
switch ( col ) {
|
2006-06-08 03:51:34 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_COL_REMOTE:
|
2006-06-08 03:51:34 +02:00
|
|
|
#endif
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_COL_ROBOT:
|
|
|
|
value.ng_bool = ceGetChecked( giState->hDlg, resID );
|
|
|
|
break;
|
|
|
|
case NG_COL_NAME:
|
|
|
|
case NG_COL_PASSWD:
|
|
|
|
len = sizeof(txt);
|
|
|
|
ceGetDlgItemText( giState->hDlg, resID, txt, &len );
|
|
|
|
value.ng_cp = &txt[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
XP_ASSERT(0);
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2006-06-08 03:35:20 +02:00
|
|
|
|
|
|
|
(*cpcb)( value, cpClosure );
|
|
|
|
} /* ceGetColProc */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceSetColProc( void* closure, XP_U16 player, NewGameColumn col,
|
|
|
|
const NGValue value )
|
|
|
|
{
|
|
|
|
GameInfoState* giState = (GameInfoState*)closure;
|
|
|
|
XP_U16 resID = resIDForCol( player, col );
|
|
|
|
const XP_UCHAR* cp;
|
|
|
|
|
|
|
|
switch( col ) {
|
|
|
|
case NG_COL_PASSWD:
|
|
|
|
case NG_COL_NAME:
|
|
|
|
if ( NULL == value.ng_cp ) {
|
|
|
|
cp = "";
|
|
|
|
} else {
|
|
|
|
cp = value.ng_cp;
|
|
|
|
}
|
|
|
|
ceSetDlgItemText( giState->hDlg, resID, cp );
|
|
|
|
break;
|
2006-06-08 03:51:34 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_COL_REMOTE:
|
2006-06-08 03:51:34 +02:00
|
|
|
#endif
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_COL_ROBOT:
|
|
|
|
ceSetChecked( giState->hDlg, resID, value.ng_bool );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceSetAttrProc(void* closure, NewGameAttr attr, const NGValue value )
|
|
|
|
{
|
|
|
|
GameInfoState* giState = (GameInfoState*)closure;
|
|
|
|
XP_U16 resID = resIDForAttr( attr );
|
|
|
|
|
|
|
|
LOG_FUNC();
|
|
|
|
|
|
|
|
switch ( attr ) {
|
|
|
|
case NG_ATTR_NPLAYERS:
|
2006-09-15 09:39:57 +02:00
|
|
|
SendDlgItemMessage( giState->hDlg, resID, CB_SETCURSEL,
|
|
|
|
value.ng_u16 - 1, 0L );
|
|
|
|
break;
|
2006-06-10 18:15:31 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2006-06-08 03:35:20 +02:00
|
|
|
case NG_ATTR_ROLE:
|
2006-09-15 09:39:57 +02:00
|
|
|
SendDlgItemMessage( giState->hDlg, resID, CB_SETCURSEL,
|
|
|
|
value.ng_role, 0L );
|
2006-06-08 03:35:20 +02:00
|
|
|
break;
|
2006-09-15 09:39:57 +02:00
|
|
|
#endif
|
2006-06-10 18:15:31 +02:00
|
|
|
case NG_ATTR_NPLAYHEADER:
|
|
|
|
ceSetDlgItemText( giState->hDlg, resID, value.ng_cp );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-06-08 03:35:20 +02:00
|
|
|
}
|
|
|
|
} /* ceSetAttrProc */
|
|
|
|
|
|
|
|
static XP_U16
|
|
|
|
playerFromID( XP_U16 id, XP_U16 base )
|
|
|
|
{
|
|
|
|
XP_U16 player;
|
|
|
|
player = (id - base) / NUM_COLS;
|
2007-12-02 20:13:25 +01:00
|
|
|
/* XP_LOGF( "%s: looks like row %d", __func__, player ); */
|
2006-06-08 03:35:20 +02:00
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handleColChecked( GameInfoState* giState, XP_U16 id, XP_U16 base )
|
2006-06-08 03:35:20 +02:00
|
|
|
{
|
|
|
|
NGValue value;
|
|
|
|
XP_U16 player = playerFromID( id, base );
|
|
|
|
|
|
|
|
value.ng_bool = ceGetChecked( giState->hDlg, id );
|
|
|
|
|
2006-08-16 15:44:44 +02:00
|
|
|
newg_colChanged( giState->newGameCtx, player );
|
2006-06-08 03:35:20 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-06-16 03:30:20 +02:00
|
|
|
/* It's too much work at this point to get the icon button looking good,
|
|
|
|
* e.g. properly greyed-out when disabled. So I'm sticking with the "J".
|
|
|
|
* Here's the code to start with if I get more ambitious. Remember: the
|
|
|
|
* GIJUGGLE_BUTTON needs to have the BS_OWNERDRAW attribute for this to work.
|
|
|
|
*/
|
|
|
|
#ifdef OWNERDRAW_JUGGLE
|
|
|
|
static void
|
|
|
|
ceDrawIconButton( CEAppGlobals* globals, DRAWITEMSTRUCT* dis )
|
|
|
|
{
|
|
|
|
HBITMAP bmp = LoadBitmap( globals->hInst,
|
|
|
|
MAKEINTRESOURCE(IDB_JUGGLEBUTTON) );
|
|
|
|
if ( !!bmp ) {
|
|
|
|
ceDrawBitmapInRect( dis->hDC, &dis->rcItem, bmp );
|
|
|
|
DeleteObject( bmp );
|
|
|
|
}
|
|
|
|
} /* ceDrawColorButton */
|
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
LRESULT CALLBACK
|
|
|
|
GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals;
|
|
|
|
XP_U16 id;
|
|
|
|
GameInfoState* giState;
|
|
|
|
|
2006-07-02 02:40:16 +02:00
|
|
|
/* #ifdef DEBUG */
|
|
|
|
/* { */
|
|
|
|
/* char buf[64]; */
|
|
|
|
/* messageToBuf( message, buf, sizeof(buf) ); */
|
2007-12-02 20:13:25 +01:00
|
|
|
/* XP_LOGF( "%s: %s", __func__, buf ); */
|
2006-07-02 02:40:16 +02:00
|
|
|
/* } */
|
|
|
|
/* #endif */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
if ( message == WM_INITDIALOG ) {
|
|
|
|
SetWindowLong( hDlg, GWL_USERDATA, lParam );
|
|
|
|
giState = (GameInfoState*)lParam;
|
2006-04-19 06:56:00 +02:00
|
|
|
giState->hDlg = hDlg;
|
2003-11-20 17:26:35 +01:00
|
|
|
globals = giState->globals;
|
|
|
|
|
2006-06-08 03:35:20 +02:00
|
|
|
giState->newGameCtx = newg_make( MPPARM(globals->mpool)
|
|
|
|
giState->isNewGame,
|
2006-06-10 18:15:31 +02:00
|
|
|
&globals->util,
|
2006-06-08 03:35:20 +02:00
|
|
|
ceEnableColProc,
|
|
|
|
ceEnableAttrProc,
|
|
|
|
ceGetColProc,
|
|
|
|
ceSetColProc,
|
|
|
|
ceSetAttrProc,
|
|
|
|
giState );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
loadFromGameInfo( hDlg, globals, giState );
|
2006-06-08 03:35:20 +02:00
|
|
|
loadStateFromCurPrefs( globals, &globals->appPrefs, &globals->gameInfo,
|
2003-11-20 17:26:35 +01:00
|
|
|
&giState->prefsPrefs );
|
|
|
|
|
2005-06-30 03:44:56 +02:00
|
|
|
if ( giState->isNewGame ) {
|
|
|
|
(void)SetWindowText( hDlg, L"New game" );
|
|
|
|
}
|
2006-05-27 19:18:42 +02:00
|
|
|
ceStackButtonsRight( globals, hDlg );
|
2003-11-20 17:26:35 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
giState = (GameInfoState*)GetWindowLong( hDlg, GWL_USERDATA );
|
2004-05-26 06:39:29 +02:00
|
|
|
if ( !!giState ) {
|
|
|
|
globals = giState->globals;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-05-26 06:39:29 +02:00
|
|
|
switch (message) {
|
2006-06-16 03:30:20 +02:00
|
|
|
|
|
|
|
#ifdef OWNERDRAW_JUGGLE
|
|
|
|
case WM_DRAWITEM: /* for BS_OWNERDRAW style */
|
|
|
|
ceDrawIconButton( globals, (DRAWITEMSTRUCT*)lParam );
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
|
2004-05-26 06:39:29 +02:00
|
|
|
case WM_COMMAND:
|
|
|
|
id = LOWORD(wParam);
|
|
|
|
switch( id ) {
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-05-26 06:39:29 +02:00
|
|
|
case ROBOT_CHECK1:
|
|
|
|
case ROBOT_CHECK2:
|
|
|
|
case ROBOT_CHECK3:
|
|
|
|
case ROBOT_CHECK4:
|
2006-08-16 15:44:44 +02:00
|
|
|
handleColChecked( giState, id, ROBOT_CHECK1 );
|
2004-05-26 06:39:29 +02:00
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2004-05-26 06:39:29 +02:00
|
|
|
case REMOTE_CHECK1:
|
|
|
|
case REMOTE_CHECK2:
|
|
|
|
case REMOTE_CHECK3:
|
|
|
|
case REMOTE_CHECK4:
|
2006-08-16 15:44:44 +02:00
|
|
|
handleColChecked( giState, id, REMOTE_CHECK1 );
|
2004-05-26 06:39:29 +02:00
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
#endif
|
|
|
|
|
2004-05-26 06:39:29 +02:00
|
|
|
case IDC_NPLAYERSCOMBO:
|
|
|
|
if ( HIWORD(wParam) == CBN_SELCHANGE ) {
|
2006-06-08 03:35:20 +02:00
|
|
|
if ( giState->isNewGame ) { /* ignore if in info
|
|
|
|
mode */
|
|
|
|
NGValue value;
|
|
|
|
value.ng_u16 = 1 + (XP_U16)
|
|
|
|
SendDlgItemMessage( hDlg,
|
|
|
|
IDC_NPLAYERSCOMBO,
|
|
|
|
CB_GETCURSEL, 0, 0L);
|
|
|
|
newg_attrChanged( giState->newGameCtx,
|
|
|
|
NG_ATTR_NPLAYERS, value );
|
2004-05-26 06:39:29 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2004-05-26 06:39:29 +02:00
|
|
|
break;
|
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2004-05-26 06:39:29 +02:00
|
|
|
case IDC_ROLECOMBO:
|
|
|
|
if ( HIWORD(wParam) == CBN_SELCHANGE ) {
|
2006-06-08 03:35:20 +02:00
|
|
|
if ( giState->isNewGame ) { /* ignore if in info
|
|
|
|
mode */
|
|
|
|
NGValue value;
|
|
|
|
value.ng_role =
|
2007-02-02 09:34:37 +01:00
|
|
|
(DeviceRole)SendDlgItemMessage( hDlg,
|
2006-06-08 03:35:20 +02:00
|
|
|
IDC_ROLECOMBO,
|
|
|
|
CB_GETCURSEL, 0,
|
|
|
|
0L);
|
|
|
|
newg_attrChanged( giState->newGameCtx,
|
|
|
|
NG_ATTR_ROLE, value );
|
2005-10-06 04:34:07 +02:00
|
|
|
/* If we've switched to a state where we'll be
|
|
|
|
connecting */
|
2006-06-08 03:35:20 +02:00
|
|
|
if ( value.ng_role != SERVER_STANDALONE ) {
|
|
|
|
handleConnOptionsButton( hDlg, globals,
|
2006-10-28 16:56:04 +02:00
|
|
|
value.ng_role,
|
2006-06-08 03:35:20 +02:00
|
|
|
giState );
|
2005-10-06 04:34:07 +02:00
|
|
|
}
|
2004-05-26 06:39:29 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2004-05-26 06:39:29 +02:00
|
|
|
break;
|
2005-07-23 17:31:21 +02:00
|
|
|
#endif
|
2006-06-08 03:35:20 +02:00
|
|
|
case GIJUGGLE_BUTTON:
|
|
|
|
XP_ASSERT( giState->isNewGame );
|
2006-07-02 02:40:16 +02:00
|
|
|
/* Juggle vs switch. On Win32, updates are coalesced so
|
|
|
|
you don't see anything on screen if you change a field
|
|
|
|
then change it back. In terms of messages, all we see
|
|
|
|
here is a WM_CTLCOLOREDIT for each field being
|
|
|
|
changed. If I post a custom event here, it comes in
|
|
|
|
*before* the WM_CTLCOLOREDIT events. Short of a
|
|
|
|
timer, which starts a race with the user, I see no way
|
|
|
|
to get notified after the drawing's done. So for now,
|
|
|
|
we switch rather than juggle: call juggle until
|
|
|
|
something actually happens. */
|
|
|
|
while ( !newg_juggle( giState->newGameCtx ) ) {
|
|
|
|
}
|
2006-06-08 03:35:20 +02:00
|
|
|
break;
|
|
|
|
|
2004-05-26 06:39:29 +02:00
|
|
|
case OPTIONS_BUTTON:
|
2006-05-19 15:45:48 +02:00
|
|
|
handlePrefsButton( hDlg, globals, giState );
|
2004-05-26 06:39:29 +02:00
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-05-26 06:39:29 +02:00
|
|
|
case IDOK:
|
2008-01-05 17:37:49 +01:00
|
|
|
if ( !stateToGameInfo( hDlg, globals, giState ) ) {
|
|
|
|
break;
|
|
|
|
}
|
2004-05-26 06:39:29 +02:00
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hDlg, id);
|
|
|
|
giState->userCancelled = id == IDCANCEL;
|
2006-04-20 06:39:46 +02:00
|
|
|
cleanupGameInfoState( giState );
|
2006-06-08 03:35:20 +02:00
|
|
|
newg_destroy( giState->newGameCtx );
|
2004-05-26 06:39:29 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* case WM_CLOSE: */
|
|
|
|
/* EndDialog(hDlg, id); */
|
|
|
|
/* return TRUE; */
|
|
|
|
/* default: */
|
|
|
|
/* return DefWindowProc(hDlg, message, wParam, lParam); */
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
} /* GameInfo */
|