mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
use new scheme to simplify blank picking
This commit is contained in:
parent
ae05e62a5a
commit
280390990f
2 changed files with 9 additions and 26 deletions
|
@ -998,28 +998,19 @@ typedef struct _BlankPickState {
|
|||
int col, row;
|
||||
int nTiles;
|
||||
int playerNum;
|
||||
char** faces;
|
||||
} BlankPickState;
|
||||
|
||||
static void
|
||||
onBlankPicked( void* closure, const char* face )
|
||||
onBlankPicked( void* closure, const char* str )
|
||||
{
|
||||
XP_LOGFF( "face: %s", face );
|
||||
XP_LOGFF( "index: %s", str );
|
||||
BlankPickState* bps = (BlankPickState*)closure;
|
||||
GameState* gs = bps->gs;
|
||||
Globals* globals = gs->globals;
|
||||
|
||||
int indx = -1;
|
||||
for ( int ii = 0; ii < bps->nTiles; ++ii ) {
|
||||
char* oneFace = bps->faces[ii];
|
||||
if ( indx < 0 && 0 == strcmp( face, oneFace ) ) {
|
||||
indx = ii;
|
||||
}
|
||||
XP_FREE( globals->mpool, oneFace );
|
||||
}
|
||||
XP_FREE( globals->mpool, bps->faces );
|
||||
|
||||
if ( board_setBlankValue( gs->game.board, bps->playerNum,
|
||||
int indx = atoi(str);
|
||||
if ( 0 <= indx && indx < bps->nTiles
|
||||
&& board_setBlankValue( gs->game.board, bps->playerNum,
|
||||
bps->col, bps->row, indx ) ) {
|
||||
updateScreen( gs, true );
|
||||
}
|
||||
|
@ -1037,12 +1028,7 @@ main_pickBlank( GameState* gs, int playerNum, int col, int row,
|
|||
bps->col = col;
|
||||
bps->playerNum = playerNum;
|
||||
bps->nTiles = nTiles;
|
||||
bps->faces = XP_CALLOC( gs->globals->mpool, nTiles * sizeof(bps->faces[0]) );
|
||||
for ( int ii = 0; ii < nTiles; ++ii ) {
|
||||
replaceStringIfDifferent( gs->globals->mpool, &bps->faces[ii], tileFaces[ii] );
|
||||
}
|
||||
|
||||
call_pickBlank( "Pick for your blank", tileFaces, nTiles,
|
||||
call_pickBlank( "Pick a tile for your blank", tileFaces, nTiles,
|
||||
onBlankPicked, bps );
|
||||
}
|
||||
|
||||
|
|
|
@ -179,13 +179,10 @@ function nbBlankPick(title, buttons, proc, closure) {
|
|||
|
||||
const butProc = function(indx) {
|
||||
dlg.parentNode.removeChild(dlg);
|
||||
ccallString(proc, closure, buttons[indx]);
|
||||
ccallString(proc, closure, indx.toString());
|
||||
}
|
||||
|
||||
let ROWLEN = 6;
|
||||
for (ii = 0; ii < buttons.length; ii += ROWLEN) {
|
||||
dlg.appendChild( newButtonDiv( buttons.slice(ii, ii + ROWLEN), butProc ) );
|
||||
}
|
||||
dlg.appendChild( newButtonDiv( buttons, butProc ) );
|
||||
addDepthNote(dlg);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue