make hint rect per-player; hide when tray not visible; make upward

drag remove it.
This commit is contained in:
ehouse 2004-06-16 04:06:02 +00:00
parent 35ab9b34fe
commit fbc7c3f687
2 changed files with 92 additions and 55 deletions

View file

@ -96,7 +96,8 @@ static XP_Bool board_moveCursor( BoardCtxt* board, XP_Key cursorKey );
#endif #endif
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
static HintAtts figureHintAtts( BoardCtxt* board, XP_U16 col, XP_U16 row ); static HintAtts figureHintAtts( BoardCtxt* board, XP_U16 col, XP_U16 row );
static void invalCurHintRect( BoardCtxt* board, XP_Bool doMirrow ); static void invalCurHintRect( BoardCtxt* board, XP_U16 player,
XP_Bool doMirrow );
#else #else
# define figureHintAtts(b,c,r) HINT_BORDER_NONE # define figureHintAtts(b,c,r) HINT_BORDER_NONE
@ -541,6 +542,15 @@ board_selectPlayer( BoardCtxt* board, XP_U16 newPlayer )
invalTradeWindow( board, oldPlayer, invalTradeWindow( board, oldPlayer,
board->tradeInProgress[newPlayer] ); board->tradeInProgress[newPlayer] );
#ifdef XWFEATURE_SEARCHLIMIT
if ( board->hasHintRect[oldPlayer] ) {
invalCurHintRect( board, oldPlayer, XP_FALSE );
}
if ( board->hasHintRect[newPlayer] ) {
invalCurHintRect( board, newPlayer, XP_FALSE );
}
#endif
invalArrowCell( board, XP_FALSE ); invalArrowCell( board, XP_FALSE );
board->selPlayer = (XP_U8)newPlayer; board->selPlayer = (XP_U8)newPlayer;
invalArrowCell( board, XP_FALSE ); invalArrowCell( board, XP_FALSE );
@ -1320,6 +1330,9 @@ setTrayVisState( BoardCtxt* board, XW_TrayVisState newState )
} }
invalArrowCell( board, XP_FALSE ); invalArrowCell( board, XP_FALSE );
board->scoreBoardInvalid = XP_TRUE; /* b/c what's bold may change */ board->scoreBoardInvalid = XP_TRUE; /* b/c what's bold may change */
#ifdef XWFEATURE_SEARCHLIMIT
invalCurHintRect( board, selPlayer, XP_FALSE );
#endif
util_trayHiddenChange( board->util, board->trayVisState ); util_trayHiddenChange( board->util, board->trayVisState );
} }
@ -1340,7 +1353,7 @@ board_flip( BoardCtxt* board )
invalCellsWithTiles( board, XP_TRUE ); invalCellsWithTiles( board, XP_TRUE );
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
invalCurHintRect( board, XP_TRUE ); invalCurHintRect( board, board->selPlayer, XP_TRUE );
#endif #endif
board->isFlipped = !board->isFlipped; board->isFlipped = !board->isFlipped;
@ -1451,8 +1464,8 @@ board_requestHint( BoardCtxt* board, XP_U16 nTilesToUse, XP_Bool* workRemainsP )
model_getDictionary(model), model_getDictionary(model),
tiles, nTiles, nTilesToUse, tiles, nTiles, nTilesToUse,
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
board->hasHintRect? board->hasHintRect[selPlayer]?
&board->limits : NULL, &board->limits[selPlayer] : NULL,
#endif #endif
NO_SCORE_LIMIT, NO_SCORE_LIMIT,
&canMove, &newMove ); &canMove, &newMove );
@ -1773,33 +1786,38 @@ static HintAtts
figureHintAtts( BoardCtxt* board, XP_U16 col, XP_U16 row ) figureHintAtts( BoardCtxt* board, XP_U16 col, XP_U16 row )
{ {
HintAtts result = HINT_BORDER_NONE; HintAtts result = HINT_BORDER_NONE;
XP_Bool isFlipped = board->isFlipped;
/* while lets us break to exit... */ if ( board->trayVisState == TRAY_REVEALED ) {
while ( board->hasHintRect || board->hintDragInProgress ) { HintLimits limits;
if ( col < board->limits.left ) break; XP_Bool isFlipped = board->isFlipped;
if ( row < board->limits.top ) break;
if ( col > board->limits.right ) break;
if ( row > board->limits.bottom ) break;
if ( col == board->limits.left ) { limits = board->limits[board->selPlayer];
result |= isFlipped? HINT_BORDER_TOP : HINT_BORDER_LEFT;
/* while lets us break to exit... */
while ( board->hasHintRect[board->selPlayer]
|| board->hintDragInProgress ) {
if ( col < limits.left ) break;
if ( row < limits.top ) break;
if ( col > limits.right ) break;
if ( row > limits.bottom ) break;
if ( col == limits.left ) {
result |= isFlipped? HINT_BORDER_TOP : HINT_BORDER_LEFT;
}
if ( col == limits.right ) {
result |= isFlipped? HINT_BORDER_BOTTOM:HINT_BORDER_RIGHT;
}
if ( row == limits.top) {
result |= isFlipped?HINT_BORDER_LEFT:HINT_BORDER_TOP;
}
if ( row == limits.bottom ) {
result |= isFlipped? HINT_BORDER_RIGHT:HINT_BORDER_BOTTOM;
}
if ( result == HINT_BORDER_NONE ) {
result = HINT_BORDER_CENTER;
}
break;
} }
if ( col == board->limits.right ) {
result |= isFlipped? HINT_BORDER_BOTTOM:HINT_BORDER_RIGHT;
}
if ( row == board->limits.top) {
result |= isFlipped?HINT_BORDER_LEFT:HINT_BORDER_TOP;
}
if ( row == board->limits.bottom ) {
result |= isFlipped? HINT_BORDER_RIGHT:HINT_BORDER_BOTTOM;
}
if ( result == HINT_BORDER_NONE ) {
result = HINT_BORDER_CENTER;
} else {
/* XP_LOGF( "border hints set for {%d,%d}", col, row ); */
}
break;
} }
return result; return result;
@ -1865,40 +1883,44 @@ invalHintForNew( BoardCtxt* board, XP_U16 newCol, XP_U16 newRow )
} /* invalHintForNew */ } /* invalHintForNew */
static void static void
invalCurHintRect( BoardCtxt* board, XP_Bool doMirror ) invalCurHintRect( BoardCtxt* board, XP_U16 player, XP_Bool doMirror )
{ {
invalCellRegion( board, board->limits.left, board->limits.top, HintLimits* limits = &board->limits[player];
board->limits.right, board->limits.bottom, doMirror ); invalCellRegion( board, limits->left, limits->top,
limits->right, limits->bottom, doMirror );
} /* invalCurHintRect */ } /* invalCurHintRect */
static void static void
clearCurHintRect( BoardCtxt* board ) clearCurHintRect( BoardCtxt* board )
{ {
invalCurHintRect( board, XP_FALSE ); invalCurHintRect( board, board->selPlayer, XP_FALSE );
board->hasHintRect = XP_FALSE; board->hasHintRect[board->selPlayer] = XP_FALSE;
} /* clearCurHintRect */ } /* clearCurHintRect */
static void static void
setHintRect( BoardCtxt* board ) setHintRect( BoardCtxt* board )
{ {
HintLimits limits;
if ( board->hintDragStartRow < board->hintDragCurRow ) { if ( board->hintDragStartRow < board->hintDragCurRow ) {
board->limits.top = board->hintDragStartRow; limits.top = board->hintDragStartRow;
board->limits.bottom = board->hintDragCurRow; limits.bottom = board->hintDragCurRow;
} else { } else {
board->limits.top = board->hintDragCurRow; limits.top = board->hintDragCurRow;
board->limits.bottom = board->hintDragStartRow; limits.bottom = board->hintDragStartRow;
} }
if ( board->hintDragStartCol < board->hintDragCurCol ) { if ( board->hintDragStartCol < board->hintDragCurCol ) {
board->limits.left = board->hintDragStartCol; limits.left = board->hintDragStartCol;
board->limits.right = board->hintDragCurCol; limits.right = board->hintDragCurCol;
} else { } else {
board->limits.left = board->hintDragCurCol; limits.left = board->hintDragCurCol;
board->limits.right = board->hintDragStartCol; limits.right = board->hintDragStartCol;
} }
XP_LOGF( "hintRect now {{%d,%d},{%d,%d}", XP_LOGF( "hintRect now {{%d,%d},{%d,%d}",
board->limits.left, board->limits.top, limits.left, limits.top,
board->limits.right, board->limits.bottom ); limits.right, limits.bottom );
}
board->limits[board->selPlayer] = limits;
} /* setHintRect */
static XP_Bool static XP_Bool
continueHintRegionDrag( BoardCtxt* board, XP_U16 x, XP_U16 y ) continueHintRegionDrag( BoardCtxt* board, XP_U16 x, XP_U16 y )
@ -1913,7 +1935,7 @@ continueHintRegionDrag( BoardCtxt* board, XP_U16 x, XP_U16 y )
board->hintDragInProgress = XP_TRUE; board->hintDragInProgress = XP_TRUE;
if ( board->hasHintRect ) { if ( board->hasHintRect[board->selPlayer] ) {
clearCurHintRect( board ); clearCurHintRect( board );
} }
/* Now that we've moved, this isn't a timer thing. Clean up any /* Now that we've moved, this isn't a timer thing. Clean up any
@ -1937,18 +1959,33 @@ static XP_Bool
finishHintRegionDrag( BoardCtxt* board, XP_U16 x, XP_U16 y ) finishHintRegionDrag( BoardCtxt* board, XP_U16 x, XP_U16 y )
{ {
XP_Bool needsRedraw = XP_FALSE; XP_Bool needsRedraw = XP_FALSE;
XP_Bool makeActive;
XP_ASSERT( board->hintDragInProgress ); XP_ASSERT( board->hintDragInProgress );
needsRedraw = continueHintRegionDrag( board, x, y ); needsRedraw = continueHintRegionDrag( board, x, y );
XP_ASSERT( !board->hasHintRect ); XP_ASSERT( !board->hasHintRect[board->selPlayer] );
board->hasHintRect = XP_TRUE;
XP_LOGF( "done with hint drag. Rect is {{%d,%d},{%d,%d}}", /* Now check if the whole drag ended above where it started. If yes, it
board->limits.left, board->limits.top, means erase! */
board->limits.right, board->limits.bottom ); if ( board->isFlipped ) {
makeActive = board->hintDragStartCol <= board->hintDragCurCol;
board_resetEngine( board ); } else {
makeActive = board->hintDragStartRow <= board->hintDragCurRow;
}
XP_LOGF( "makeActive = %d", makeActive );
board->hasHintRect[board->selPlayer] = makeActive;
if ( !makeActive ) {
invalCurHintRect( board, board->selPlayer, XP_FALSE );
needsRedraw = XP_TRUE;
} else {
XP_LOGF( "done with hint drag. Rect is {{%d,%d},{%d,%d}}",
board->limits[board->selPlayer].left,
board->limits[board->selPlayer].top,
board->limits[board->selPlayer].right,
board->limits[board->selPlayer].bottom );
board_resetEngine( board );
}
return needsRedraw; return needsRedraw;
} /* finishHintRegionDrag */ } /* finishHintRegionDrag */

View file

@ -164,8 +164,8 @@ struct BoardCtxt {
XP_U16 hintDragCurCol, hintDragCurRow; XP_U16 hintDragCurCol, hintDragCurRow;
XP_Bool hintDragInProgress; XP_Bool hintDragInProgress;
XP_Bool hasHintRect; XP_Bool hasHintRect[MAX_NUM_PLAYERS];
HintLimits limits; HintLimits limits[MAX_NUM_PLAYERS];
#endif #endif
MPSLOT MPSLOT