mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
Add new attributes to cover strings for number of players and remote
column head; make enabled an enum to differentiate between hidden and disabled.
This commit is contained in:
parent
1967a137ef
commit
44abbc4493
2 changed files with 96 additions and 31 deletions
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "nwgamest.h"
|
#include "nwgamest.h"
|
||||||
#include "strutils.h"
|
#include "strutils.h"
|
||||||
|
#include "LocalizedStrIncludes.h"
|
||||||
|
|
||||||
#ifdef CPLUS
|
#ifdef CPLUS
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -32,11 +33,12 @@ struct NewGameCtx {
|
||||||
NewGameSetColProc setColProc;
|
NewGameSetColProc setColProc;
|
||||||
NewGameGetColProc getColProc;
|
NewGameGetColProc getColProc;
|
||||||
NewGameSetAttrProc setAttrProc;
|
NewGameSetAttrProc setAttrProc;
|
||||||
|
XW_UtilCtxt* util;
|
||||||
void* closure;
|
void* closure;
|
||||||
|
|
||||||
/* Palm needs to store cleartext passwords separately in order to
|
/* Palm needs to store cleartext passwords separately in order to
|
||||||
store '***' in the visible field */
|
store '***' in the visible field */
|
||||||
XP_Bool enabled[NG_NUM_COLS][MAX_NUM_PLAYERS];
|
NewGameEnable enabled[NG_NUM_COLS][MAX_NUM_PLAYERS];
|
||||||
XP_U16 nPlayers;
|
XP_U16 nPlayers;
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
Connectedness role;
|
Connectedness role;
|
||||||
|
@ -47,12 +49,15 @@ struct NewGameCtx {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void enableOne( NewGameCtx* ngc, XP_U16 player, NewGameColumn col,
|
static void enableOne( NewGameCtx* ngc, XP_U16 player, NewGameColumn col,
|
||||||
XP_Bool enable, XP_Bool force );
|
NewGameEnable enable, XP_Bool force );
|
||||||
static void adjustAllRows( NewGameCtx* ngc, XP_Bool force );
|
static void adjustAllRows( NewGameCtx* ngc, XP_Bool force );
|
||||||
static void adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force );
|
static void adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force );
|
||||||
|
static void setRoleStrings( NewGameCtx* ngc );
|
||||||
|
|
||||||
|
|
||||||
NewGameCtx*
|
NewGameCtx*
|
||||||
newg_make( MPFORMAL XP_Bool isNewGame,
|
newg_make( MPFORMAL XP_Bool isNewGame,
|
||||||
|
XW_UtilCtxt* util,
|
||||||
NewGameEnableColProc enableColProc,
|
NewGameEnableColProc enableColProc,
|
||||||
NewGameEnableAttrProc enableAttrProc,
|
NewGameEnableAttrProc enableAttrProc,
|
||||||
NewGameGetColProc getColProc, NewGameSetColProc setColProc,
|
NewGameGetColProc getColProc, NewGameSetColProc setColProc,
|
||||||
|
@ -66,9 +71,9 @@ newg_make( MPFORMAL XP_Bool isNewGame,
|
||||||
result->setColProc = setColProc;
|
result->setColProc = setColProc;
|
||||||
result->getColProc = getColProc;
|
result->getColProc = getColProc;
|
||||||
result->setAttrProc = setAttrProc;
|
result->setAttrProc = setAttrProc;
|
||||||
/* result->getAttrProc = getAttrProc; */
|
|
||||||
result->closure = closure;
|
result->closure = closure;
|
||||||
result->isNewGame = isNewGame;
|
result->isNewGame = isNewGame;
|
||||||
|
result->util = util;
|
||||||
MPASSIGN(result->mpool, mpool);
|
MPASSIGN(result->mpool, mpool);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -77,14 +82,7 @@ newg_make( MPFORMAL XP_Bool isNewGame,
|
||||||
void
|
void
|
||||||
newg_destroy( NewGameCtx* ngc )
|
newg_destroy( NewGameCtx* ngc )
|
||||||
{
|
{
|
||||||
#ifdef PLATFORM_PALM
|
XP_FREE( ngc->mpool, ngc );
|
||||||
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
|
||||||
XP_UCHAR* passwd = ngc->passwds[i];
|
|
||||||
if ( !!passwd ) {
|
|
||||||
XP_FREE( ngc->mpool, passwd );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} /* newg_destroy */
|
} /* newg_destroy */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -97,14 +95,17 @@ newg_load( NewGameCtx* ngc, const CurGameInfo* gi )
|
||||||
ngc->nPlayers = gi->nPlayers;
|
ngc->nPlayers = gi->nPlayers;
|
||||||
value.ng_u16 = ngc->nPlayers;
|
value.ng_u16 = ngc->nPlayers;
|
||||||
(*ngc->setAttrProc)( closure, NG_ATTR_NPLAYERS, value );
|
(*ngc->setAttrProc)( closure, NG_ATTR_NPLAYERS, value );
|
||||||
(*ngc->enableAttrProc)( closure, NG_ATTR_NPLAYERS, ngc->isNewGame );
|
(*ngc->enableAttrProc)( closure, NG_ATTR_NPLAYERS, ngc->isNewGame?
|
||||||
|
NGEnableEnabled : NGEnableDisabled );
|
||||||
|
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
ngc->role = gi->serverRole;
|
ngc->role = gi->serverRole;
|
||||||
value.ng_role = ngc->role;
|
value.ng_role = ngc->role;
|
||||||
(*ngc->setAttrProc)( closure, NG_ATTR_ROLE, value );
|
(*ngc->setAttrProc)( closure, NG_ATTR_ROLE, value );
|
||||||
(*ngc->enableAttrProc)( closure, NG_ATTR_ROLE, ngc->isNewGame );
|
(*ngc->enableAttrProc)( closure, NG_ATTR_ROLE, ngc->isNewGame?
|
||||||
|
NGEnableEnabled : NGEnableDisabled );
|
||||||
#endif
|
#endif
|
||||||
|
setRoleStrings( ngc );
|
||||||
|
|
||||||
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ cpToGI( NGValue value, const void* cbClosure )
|
||||||
switch ( cpcl->col ) {
|
switch ( cpcl->col ) {
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
case NG_COL_REMOTE:
|
case NG_COL_REMOTE:
|
||||||
pl->isLocal = value.ng_bool;
|
pl->isLocal = !value.ng_bool;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case NG_COL_NAME:
|
case NG_COL_NAME:
|
||||||
|
@ -208,6 +209,7 @@ newg_attrChanged( NewGameCtx* ngc, NewGameAttr attr, NGValue value )
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
} else if ( NG_ATTR_ROLE == attr ) {
|
} else if ( NG_ATTR_ROLE == attr ) {
|
||||||
ngc->role = value.ng_role;
|
ngc->role = value.ng_role;
|
||||||
|
setRoleStrings( ngc );
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
|
@ -333,9 +335,9 @@ newg_juggle( NewGameCtx* ngc )
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enableOne( NewGameCtx* ngc, XP_U16 player, NewGameColumn col,
|
enableOne( NewGameCtx* ngc, XP_U16 player, NewGameColumn col,
|
||||||
XP_Bool enable, XP_Bool force )
|
NewGameEnable enable, XP_Bool force )
|
||||||
{
|
{
|
||||||
XP_Bool* esp = &ngc->enabled[col][player];
|
NewGameEnable* esp = &ngc->enabled[col][player];
|
||||||
if ( force || (*esp != enable) ) {
|
if ( force || (*esp != enable) ) {
|
||||||
(*ngc->enableColProc)( ngc->closure, player, col, enable );
|
(*ngc->enableColProc)( ngc->closure, player, col, enable );
|
||||||
}
|
}
|
||||||
|
@ -354,22 +356,28 @@ adjustAllRows( NewGameCtx* ngc, XP_Bool force )
|
||||||
static void
|
static void
|
||||||
adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force )
|
adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force )
|
||||||
{
|
{
|
||||||
XP_Bool enable[NG_NUM_COLS];
|
NewGameEnable enable[NG_NUM_COLS];
|
||||||
NewGameColumn col;
|
NewGameColumn col;
|
||||||
XP_MEMSET( enable, 0, sizeof(enable) );
|
|
||||||
XP_Bool isLocal = XP_TRUE;
|
XP_Bool isLocal = XP_TRUE;
|
||||||
DeepValue dValue;
|
DeepValue dValue;
|
||||||
|
|
||||||
|
for ( col = 0; col < NG_NUM_COLS; ++col ) {
|
||||||
|
enable[col] = NGEnableHidden;
|
||||||
|
}
|
||||||
|
|
||||||
/* If there aren't this many players, all are disabled */
|
/* If there aren't this many players, all are disabled */
|
||||||
if ( player >= ngc->nPlayers ) {
|
if ( player >= ngc->nPlayers ) {
|
||||||
/* do nothing: all are false */
|
/* do nothing: all are hidden above */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
/* If standalone or client, remote is disabled */
|
/* If standalone or client, remote is hidden. If server but not
|
||||||
|
new game, it's disabled */
|
||||||
if ( ngc->role == SERVER_ISSERVER ) {
|
if ( ngc->role == SERVER_ISSERVER ) {
|
||||||
enable[NG_COL_REMOTE] = XP_TRUE;
|
if ( ngc->isNewGame ) {
|
||||||
|
enable[NG_COL_REMOTE] = NGEnableEnabled;
|
||||||
|
} else {
|
||||||
|
enable[NG_COL_REMOTE] = NGEnableDisabled;
|
||||||
|
}
|
||||||
dValue.col = NG_COL_REMOTE;
|
dValue.col = NG_COL_REMOTE;
|
||||||
(*ngc->getColProc)( ngc->closure, player, NG_COL_REMOTE,
|
(*ngc->getColProc)( ngc->closure, player, NG_COL_REMOTE,
|
||||||
deepCopy, &dValue );
|
deepCopy, &dValue );
|
||||||
|
@ -377,15 +385,32 @@ adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If local is enabled and not set, all else is disabled */
|
/* If remote is enabled and set, then if it's a new game all else is
|
||||||
|
hidden. But if it's not a new game, they're disabled. Password is
|
||||||
|
always hidden if robot is set. */
|
||||||
if ( isLocal ) {
|
if ( isLocal ) {
|
||||||
enable[NG_COL_NAME] = XP_TRUE;
|
NewGameEnable passwdEn;
|
||||||
enable[NG_COL_ROBOT] = XP_TRUE;
|
/* No changing name or robotness since they're sent to remote
|
||||||
|
host. */
|
||||||
|
enable[NG_COL_NAME] = NGEnableEnabled;
|
||||||
|
enable[NG_COL_ROBOT] = NGEnableEnabled;
|
||||||
|
|
||||||
dValue.col = NG_COL_ROBOT;
|
dValue.col = NG_COL_ROBOT;
|
||||||
(*ngc->getColProc)( ngc->closure, player, NG_COL_ROBOT, deepCopy,
|
(*ngc->getColProc)( ngc->closure, player, NG_COL_ROBOT, deepCopy,
|
||||||
&dValue );
|
&dValue );
|
||||||
if ( !dValue.value.ng_bool ) {
|
if ( !dValue.value.ng_bool ) {
|
||||||
enable[NG_COL_PASSWD] = XP_TRUE;
|
/* It is's a robot, leave it hidden */
|
||||||
|
enable[NG_COL_PASSWD] = passwdEn = ngc->isNewGame?
|
||||||
|
NGEnableEnabled : NGEnableDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if ( ngc->isNewGame ) {
|
||||||
|
/* leave 'em hidden */
|
||||||
|
} else {
|
||||||
|
enable[NG_COL_NAME] = NGEnableDisabled;
|
||||||
|
enable[NG_COL_ROBOT] = NGEnableDisabled;
|
||||||
|
/* leave passwd hidden */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,6 +420,34 @@ adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force )
|
||||||
}
|
}
|
||||||
} /* adjustOneRow */
|
} /* adjustOneRow */
|
||||||
|
|
||||||
|
static void
|
||||||
|
setRoleStrings( NewGameCtx* ngc )
|
||||||
|
{
|
||||||
|
XP_U16 strID;
|
||||||
|
NGValue value;
|
||||||
|
void* closure = ngc->closure;
|
||||||
|
/* Tell client to set/change players label text, and also to add remote
|
||||||
|
checkbox column header if required. */
|
||||||
|
|
||||||
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
|
(*ngc->enableAttrProc)( closure, NG_ATTR_REMHEADER,
|
||||||
|
ngc->role == SERVER_ISSERVER?
|
||||||
|
NGEnableEnabled : NGEnableHidden );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ( 0 ) {
|
||||||
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
|
} else if ( ngc->role == SERVER_ISCLIENT ) {
|
||||||
|
strID = STR_LOCALPLAYERS;
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
strID = STR_TOTALPLAYERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
value.ng_cp = util_getUserString( ngc->util, strID );
|
||||||
|
(*ngc->setAttrProc)( closure, NG_ATTR_NPLAYHEADER, value );
|
||||||
|
} /* setRoleStrings */
|
||||||
|
|
||||||
#ifdef CPLUS
|
#ifdef CPLUS
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,6 +35,7 @@ EXTERN_C_START
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
|
#include "util.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
typedef struct NewGameCtx NewGameCtx;
|
typedef struct NewGameCtx NewGameCtx;
|
||||||
|
@ -51,10 +52,20 @@ typedef enum {
|
||||||
} NewGameColumn;
|
} NewGameColumn;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
|
NG_ATTR_ROLE,
|
||||||
|
NG_ATTR_REMHEADER,
|
||||||
|
#endif
|
||||||
NG_ATTR_NPLAYERS
|
NG_ATTR_NPLAYERS
|
||||||
,NG_ATTR_ROLE
|
,NG_ATTR_NPLAYHEADER
|
||||||
|
,NG_ATTR_CANJUGGLE
|
||||||
} NewGameAttr;
|
} NewGameAttr;
|
||||||
|
|
||||||
|
typedef enum { NGEnableHidden,
|
||||||
|
NGEnableDisabled,
|
||||||
|
NGEnableEnabled
|
||||||
|
} NewGameEnable;
|
||||||
|
|
||||||
typedef union NGValue {
|
typedef union NGValue {
|
||||||
const XP_UCHAR* ng_cp;
|
const XP_UCHAR* ng_cp;
|
||||||
XP_U16 ng_u16;
|
XP_U16 ng_u16;
|
||||||
|
@ -64,9 +75,9 @@ typedef union NGValue {
|
||||||
|
|
||||||
/* Enable or disable (show or hide) controls */
|
/* Enable or disable (show or hide) controls */
|
||||||
typedef void (*NewGameEnableColProc)( void* closure, XP_U16 player,
|
typedef void (*NewGameEnableColProc)( void* closure, XP_U16 player,
|
||||||
NewGameColumn col, XP_Bool enable );
|
NewGameColumn col, NewGameEnable enable );
|
||||||
typedef void (*NewGameEnableAttrProc)( void* closure, NewGameAttr attr,
|
typedef void (*NewGameEnableAttrProc)( void* closure, NewGameAttr attr,
|
||||||
XP_Bool enable );
|
NewGameEnable enable );
|
||||||
/* Get the contents of a control. Type of param "value" is either
|
/* Get the contents of a control. Type of param "value" is either
|
||||||
boolean or char* */
|
boolean or char* */
|
||||||
typedef void (*NgCpCallbk)( NGValue value, const void* cpClosure );
|
typedef void (*NgCpCallbk)( NGValue value, const void* cpClosure );
|
||||||
|
@ -83,6 +94,7 @@ typedef void (*NewGameSetAttrProc)(void* closure, NewGameAttr attr,
|
||||||
|
|
||||||
|
|
||||||
NewGameCtx* newg_make( MPFORMAL XP_Bool isNewGame,
|
NewGameCtx* newg_make( MPFORMAL XP_Bool isNewGame,
|
||||||
|
XW_UtilCtxt* util,
|
||||||
NewGameEnableColProc enableColProc,
|
NewGameEnableColProc enableColProc,
|
||||||
NewGameEnableAttrProc enableAttrProc,
|
NewGameEnableAttrProc enableAttrProc,
|
||||||
NewGameGetColProc getColProc,
|
NewGameGetColProc getColProc,
|
||||||
|
|
Loading…
Reference in a new issue