mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-26 09:58:20 +01:00
Make GameInfo struct private
This commit is contained in:
parent
2daea90580
commit
1929505c10
3 changed files with 101 additions and 73 deletions
|
@ -32,6 +32,36 @@
|
||||||
#define NUM_COLS 4
|
#define NUM_COLS 4
|
||||||
#define MENUDICTS_INCR 16
|
#define MENUDICTS_INCR 16
|
||||||
|
|
||||||
|
typedef struct _GameInfoState {
|
||||||
|
CeDlgHdr dlgHdr;
|
||||||
|
NewGameCtx* newGameCtx;
|
||||||
|
XP_UCHAR* newDictName;
|
||||||
|
XP_U16 dictNameLen;
|
||||||
|
|
||||||
|
XP_U16 capMenuDicts;
|
||||||
|
XP_U16 nMenuDicts;
|
||||||
|
wchar_t** menuDicts;
|
||||||
|
XP_U16 nPlayersId;
|
||||||
|
XP_U16 dictListId;
|
||||||
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
|
XP_U16 roleComboId;
|
||||||
|
DeviceRole lastRole; /* to prevent multiple dialog raises */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
XP_Bool isNewGame; /* newGame or GameInfo */
|
||||||
|
XP_Bool userCancelled; /* OUT param */
|
||||||
|
|
||||||
|
GInfoResults results;
|
||||||
|
CePrefsPrefs* prefsPrefs;
|
||||||
|
|
||||||
|
/* Support for repositioning lower items based on num players */
|
||||||
|
XP_U16* moveIds;
|
||||||
|
XP_U16 nMoveIds;
|
||||||
|
XP_U16 prevNPlayers;
|
||||||
|
XP_U16 playersSpacing;
|
||||||
|
|
||||||
|
} GameInfoState;
|
||||||
|
|
||||||
static XP_S16
|
static XP_S16
|
||||||
findInsertPoint( const wchar_t* wPath, wchar_t** menuDicts,
|
findInsertPoint( const wchar_t* wPath, wchar_t** menuDicts,
|
||||||
XP_U16 nMenuDicts )
|
XP_U16 nMenuDicts )
|
||||||
|
@ -188,8 +218,8 @@ loadFromGameInfo( GameInfoState* state )
|
||||||
|
|
||||||
#ifndef STUBBED_DICT
|
#ifndef STUBBED_DICT
|
||||||
if ( !!gi->dictName ) {
|
if ( !!gi->dictName ) {
|
||||||
XP_MEMCPY( state->newDictName, gi->dictName,
|
XP_SNPRINTF( state->newDictName, state->dictNameLen, "%s",
|
||||||
(XP_U16)XP_STRLEN(gi->dictName)+1 );
|
gi->dictName );
|
||||||
}
|
}
|
||||||
if ( state->isNewGame ) {
|
if ( state->isNewGame ) {
|
||||||
(void)ceLocateNDicts( globals, CE_MAXDICTS, addDictToState, state );
|
(void)ceLocateNDicts( globals, CE_MAXDICTS, addDictToState, state );
|
||||||
|
@ -225,8 +255,8 @@ stateToGameInfo( GameInfoState* state )
|
||||||
GETCURSEL(globals), 0, 0L );
|
GETCURSEL(globals), 0, 0L );
|
||||||
if ( sel >= 0 ) {
|
if ( sel >= 0 ) {
|
||||||
WideCharToMultiByte( CP_ACP, 0, state->menuDicts[sel], -1,
|
WideCharToMultiByte( CP_ACP, 0, state->menuDicts[sel], -1,
|
||||||
state->newDictName,
|
state->newDictName, state->dictNameLen,
|
||||||
sizeof(state->newDictName), NULL, NULL );
|
NULL, NULL );
|
||||||
}
|
}
|
||||||
replaceStringIfDifferent( globals->mpool, &gi->dictName,
|
replaceStringIfDifferent( globals->mpool, &gi->dictName,
|
||||||
state->newDictName );
|
state->newDictName );
|
||||||
|
@ -246,9 +276,9 @@ stateToGameInfo( GameInfoState* state )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* preferences */
|
/* preferences */
|
||||||
if ( state->prefsChanged ) {
|
if ( state->results.prefsChanged ) {
|
||||||
loadCurPrefsFromState( globals, &globals->appPrefs, gi,
|
loadCurPrefsFromState( globals, &globals->appPrefs, gi,
|
||||||
&state->prefsPrefs );
|
state->prefsPrefs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,11 +341,11 @@ static void
|
||||||
handlePrefsButton( HWND hDlg, CEAppGlobals* globals, GameInfoState* state )
|
handlePrefsButton( HWND hDlg, CEAppGlobals* globals, GameInfoState* state )
|
||||||
{
|
{
|
||||||
XP_Bool colorsChanged, langChanged;
|
XP_Bool colorsChanged, langChanged;
|
||||||
if ( WrapPrefsDialog( hDlg, globals, &state->prefsPrefs,
|
if ( WrapPrefsDialog( hDlg, globals, state->prefsPrefs,
|
||||||
state->isNewGame, &colorsChanged, &langChanged ) ) {
|
state->isNewGame, &colorsChanged, &langChanged ) ) {
|
||||||
state->prefsChanged = XP_TRUE;
|
state->results.prefsChanged = XP_TRUE;
|
||||||
state->colorsChanged = colorsChanged;
|
state->results.colorsChanged = colorsChanged;
|
||||||
state->langChanged = langChanged;
|
state->results.langChanged = langChanged;
|
||||||
/* nothing to do until user finally does confirm the parent dialog */
|
/* nothing to do until user finally does confirm the parent dialog */
|
||||||
}
|
}
|
||||||
} /* handlePrefsButton */
|
} /* handlePrefsButton */
|
||||||
|
@ -327,11 +357,11 @@ callConnsDlg( GameInfoState* state )
|
||||||
XP_Bool connsComplete = XP_FALSE;
|
XP_Bool connsComplete = XP_FALSE;
|
||||||
/* maybe flag when this isn't changed? No. Check on "Ok" as tagged elsewhere. */
|
/* maybe flag when this isn't changed? No. Check on "Ok" as tagged elsewhere. */
|
||||||
if ( WrapConnsDlg( state->dlgHdr.hDlg, state->dlgHdr.globals,
|
if ( WrapConnsDlg( state->dlgHdr.hDlg, state->dlgHdr.globals,
|
||||||
&state->prefsPrefs.addrRec,
|
&state->prefsPrefs->addrRec,
|
||||||
&state->prefsPrefs.addrRec, state->lastRole,
|
&state->prefsPrefs->addrRec, state->lastRole,
|
||||||
state->isNewGame,
|
state->isNewGame,
|
||||||
&connsComplete ) ) {
|
&connsComplete ) ) {
|
||||||
state->addrChanged = XP_TRUE;
|
state->results.addrChanged = XP_TRUE;
|
||||||
}
|
}
|
||||||
return connsComplete;
|
return connsComplete;
|
||||||
}
|
}
|
||||||
|
@ -591,8 +621,8 @@ checkUpdateCombo( GameInfoState* state, XP_U16 id )
|
||||||
}
|
}
|
||||||
} /* checkUpdateCombo */
|
} /* checkUpdateCombo */
|
||||||
|
|
||||||
LRESULT CALLBACK
|
static LRESULT CALLBACK
|
||||||
GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
GameInfo( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
||||||
{
|
{
|
||||||
CEAppGlobals* globals;
|
CEAppGlobals* globals;
|
||||||
XP_U16 id;
|
XP_U16 id;
|
||||||
|
@ -632,7 +662,7 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
|
|
||||||
loadFromGameInfo( state );
|
loadFromGameInfo( state );
|
||||||
loadStateFromCurPrefs( globals, &globals->appPrefs, &globals->gameInfo,
|
loadStateFromCurPrefs( globals, &globals->appPrefs, &globals->gameInfo,
|
||||||
&state->prefsPrefs );
|
state->prefsPrefs );
|
||||||
|
|
||||||
if ( state->isNewGame ) {
|
if ( state->isNewGame ) {
|
||||||
(void)SetWindowText( hDlg, ceGetResStringL( globals,
|
(void)SetWindowText( hDlg, ceGetResStringL( globals,
|
||||||
|
@ -731,7 +761,8 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
SendDlgItemMessage( hDlg, state->roleComboId,
|
SendDlgItemMessage( hDlg, state->roleComboId,
|
||||||
GETCURSEL(globals), 0, 0L );
|
GETCURSEL(globals), 0, 0L );
|
||||||
if ( role != SERVER_STANDALONE
|
if ( role != SERVER_STANDALONE
|
||||||
&& !comms_checkComplete( &state->prefsPrefs.addrRec )
|
&& !comms_checkComplete(
|
||||||
|
&state->prefsPrefs->addrRec )
|
||||||
&& !callConnsDlg( state ) ) {
|
&& !callConnsDlg( state ) ) {
|
||||||
break;
|
break;
|
||||||
} else if ( !stateToGameInfo( state ) ) {
|
} else if ( !stateToGameInfo( state ) ) {
|
||||||
|
@ -757,3 +788,29 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} /* GameInfo */
|
} /* GameInfo */
|
||||||
|
|
||||||
|
|
||||||
|
XP_Bool
|
||||||
|
WrapGameInfoDialog( CEAppGlobals* globals, XP_Bool isNewGame,
|
||||||
|
CePrefsPrefs* prefsPrefs,
|
||||||
|
XP_UCHAR* dictName, XP_U16 dictNameLen,
|
||||||
|
GInfoResults* results )
|
||||||
|
{
|
||||||
|
GameInfoState state;
|
||||||
|
XP_MEMSET( &state, 0, sizeof(state) );
|
||||||
|
state.dlgHdr.globals = globals;
|
||||||
|
state.isNewGame = isNewGame;
|
||||||
|
state.prefsPrefs = prefsPrefs;
|
||||||
|
state.newDictName = dictName;
|
||||||
|
state.dictNameLen = dictNameLen;
|
||||||
|
|
||||||
|
assertOnTop( globals->hWnd );
|
||||||
|
DialogBoxParam( globals->locInst, (LPCTSTR)IDD_GAMEINFO, globals->hWnd,
|
||||||
|
(DLGPROC)GameInfo, (long)&state );
|
||||||
|
|
||||||
|
if ( !state.userCancelled ) {
|
||||||
|
XP_MEMCPY( results, &state.results, sizeof(*results) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return !state.userCancelled;
|
||||||
|
}
|
||||||
|
|
|
@ -27,39 +27,17 @@
|
||||||
#include "ceutil.h"
|
#include "ceutil.h"
|
||||||
#include "nwgamest.h"
|
#include "nwgamest.h"
|
||||||
|
|
||||||
typedef struct GameInfoState {
|
|
||||||
CeDlgHdr dlgHdr;
|
|
||||||
NewGameCtx* newGameCtx;
|
|
||||||
XP_UCHAR newDictName[CE_MAX_PATH_LEN+1];
|
|
||||||
|
|
||||||
XP_U16 capMenuDicts;
|
|
||||||
XP_U16 nMenuDicts;
|
|
||||||
wchar_t** menuDicts;
|
|
||||||
XP_U16 nPlayersId;
|
|
||||||
XP_U16 dictListId;
|
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
||||||
XP_U16 roleComboId;
|
|
||||||
DeviceRole lastRole; /* to prevent multiple dialog raises */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
XP_Bool isNewGame; /* newGame or GameInfo */
|
|
||||||
XP_Bool userCancelled; /* OUT param */
|
|
||||||
|
|
||||||
|
typedef struct _GInfoResults {
|
||||||
XP_Bool prefsChanged;
|
XP_Bool prefsChanged;
|
||||||
XP_Bool colorsChanged;
|
XP_Bool colorsChanged;
|
||||||
XP_Bool langChanged;
|
XP_Bool langChanged;
|
||||||
XP_Bool addrChanged;
|
XP_Bool addrChanged;
|
||||||
CePrefsPrefs prefsPrefs;
|
} GInfoResults;
|
||||||
|
|
||||||
/* Support for repositioning lower items based on num players */
|
XP_Bool WrapGameInfoDialog( CEAppGlobals* globals, XP_Bool isNewGame,
|
||||||
XP_U16* moveIds;
|
CePrefsPrefs* prefsPrefs,
|
||||||
XP_U16 nMoveIds;
|
XP_UCHAR* dictName, XP_U16 dictNameLen,
|
||||||
XP_U16 prevNPlayers;
|
GInfoResults* results );
|
||||||
XP_U16 playersSpacing;
|
|
||||||
|
|
||||||
} GameInfoState;
|
|
||||||
|
|
||||||
|
|
||||||
LRESULT CALLBACK GameInfo(HWND, UINT, WPARAM, LPARAM);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1748,21 +1748,16 @@ ceWarnLangChange( CEAppGlobals* globals )
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
ceDoNewGame( CEAppGlobals* globals )
|
ceDoNewGame( CEAppGlobals* globals )
|
||||||
{
|
{
|
||||||
GameInfoState giState;
|
|
||||||
CommsAddrRec* addr = NULL;
|
CommsAddrRec* addr = NULL;
|
||||||
XP_Bool changed = XP_FALSE;
|
XP_Bool changed = XP_FALSE;
|
||||||
|
CePrefsPrefs prefsPrefs;
|
||||||
|
XP_UCHAR newDictName[CE_MAX_PATH_LEN+1];
|
||||||
|
GInfoResults results;
|
||||||
|
|
||||||
XP_MEMSET( &giState, 0, sizeof(giState) );
|
if ( WrapGameInfoDialog( globals, XP_TRUE, &prefsPrefs, newDictName,
|
||||||
giState.dlgHdr.globals = globals;
|
VSIZE(newDictName), &results )
|
||||||
giState.isNewGame = XP_TRUE;
|
|
||||||
|
|
||||||
assertOnTop( globals->hWnd );
|
|
||||||
DialogBoxParam( globals->locInst, (LPCTSTR)IDD_GAMEINFO, globals->hWnd,
|
|
||||||
(DLGPROC)GameInfo, (long)&giState );
|
|
||||||
|
|
||||||
if ( !giState.userCancelled
|
|
||||||
#ifndef STUBBED_DICT
|
#ifndef STUBBED_DICT
|
||||||
&& ( giState.newDictName[0] != '\0' )
|
&& ( newDictName[0] != '\0' )
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -1771,21 +1766,21 @@ ceDoNewGame( CEAppGlobals* globals )
|
||||||
globals->curGameName = NULL;
|
globals->curGameName = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( giState.prefsChanged ) {
|
if ( results.prefsChanged ) {
|
||||||
loadCurPrefsFromState( globals, &globals->appPrefs,
|
loadCurPrefsFromState( globals, &globals->appPrefs,
|
||||||
&globals->gameInfo, &giState.prefsPrefs );
|
&globals->gameInfo, &prefsPrefs );
|
||||||
if ( giState.colorsChanged ) {
|
if ( results.colorsChanged ) {
|
||||||
updateForColors( globals );
|
updateForColors( globals );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( giState.langChanged ) {
|
if ( results.langChanged ) {
|
||||||
ceWarnLangChange( globals );
|
ceWarnLangChange( globals );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
||||||
if ( giState.addrChanged ) {
|
if ( results.addrChanged ) {
|
||||||
addr = &giState.prefsPrefs.addrRec;
|
addr = &prefsPrefs.addrRec;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2448,19 +2443,17 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_GAME_GAMEINFO: {
|
case ID_GAME_GAMEINFO: {
|
||||||
GameInfoState state;
|
GInfoResults results;
|
||||||
|
CePrefsPrefs prefsPrefs;
|
||||||
XP_MEMSET( &state, 0, sizeof(state) );
|
XP_UCHAR dictName[CE_MAX_PATH_LEN+1];
|
||||||
state.dlgHdr.globals = globals;
|
|
||||||
|
if ( WrapGameInfoDialog( globals, XP_FALSE, &prefsPrefs,
|
||||||
DialogBoxParam( globals->locInst, (LPCTSTR)IDD_GAMEINFO, hWnd,
|
dictName, VSIZE(dictName),
|
||||||
(DLGPROC)GameInfo, (long)&state );
|
&results ) ) {
|
||||||
|
if ( results.prefsChanged ) {
|
||||||
if ( !state.userCancelled ) {
|
|
||||||
if ( state.prefsChanged ) {
|
|
||||||
updateForColors( globals );
|
updateForColors( globals );
|
||||||
}
|
}
|
||||||
if ( state.langChanged ) {
|
if ( results.langChanged ) {
|
||||||
ceWarnLangChange( globals );
|
ceWarnLangChange( globals );
|
||||||
}
|
}
|
||||||
draw = server_do( globals->game.server );
|
draw = server_do( globals->game.server );
|
||||||
|
|
Loading…
Reference in a new issue