track focus on Rem: region of scoreboard in addition to players' score

areas, pass into draw whether to show it highlighted, and fire a util
method when it's clicked on.  Intent is that platforms show the
remaining tiles dialog.
This commit is contained in:
ehouse 2008-10-24 08:56:20 +00:00
parent f1a975c106
commit 3b28583d0d
6 changed files with 71 additions and 42 deletions

View file

@ -772,14 +772,14 @@ timerFiredForPen( BoardCtxt* board )
board->penTimerFired = XP_TRUE;
}
} else if ( board->penDownObject == OBJ_SCORE ) {
XP_S16 player;
LocalPlayer* lp;
player = figureScorePlayerTapped( board, board->penDownX,
board->penDownY );
XP_S16 scoreIndex = figureScoreRectTapped( board, board->penDownX,
board->penDownY );
/* I've seen this assert fire on simulator. No log is kept so I can't
tell why, but might want to test and do nothing in this case. */
/* XP_ASSERT( player >= 0 ); */
if ( player >= 0 ) {
if ( scoreIndex > CURSOR_LOC_REM ) {
XP_U16 player = scoreIndex - 1;
const XP_UCHAR* format;
XP_UCHAR scoreExpl[48];
XP_U16 explLen;
@ -1874,7 +1874,7 @@ handleLikeDown( BoardCtxt* board, BoardObjectType onWhich, XP_U16 x, XP_U16 y )
break;
case OBJ_SCORE:
if ( figureScorePlayerTapped( board, x, y ) >= 0 ) {
if ( figureScoreRectTapped( board, x, y ) > CURSOR_LOC_REM ) {
util_setTimer( board->util, TIMER_PENDOWN, 0,
p_board_timerFired, board );
}
@ -2172,7 +2172,14 @@ getFocussedCellCenter( BoardCtxt* board, XP_U16* xp, XP_U16* yp )
static void
getFocussedScoreCenter( BoardCtxt* board, XP_U16* xp, XP_U16* yp )
{
getRectCenter( &board->pti[board->scoreCursorLoc].scoreRects, xp, yp );
XP_Rect* rectPtr;
XP_S16 scoreCursorLoc = board->scoreCursorLoc;
if ( CURSOR_LOC_REM == scoreCursorLoc ) {
rectPtr = &board->remRect;
} else {
rectPtr = &board->pti[scoreCursorLoc-1].scoreRects;
}
getRectCenter( rectPtr, xp, yp );
}
static XP_Bool

View file

@ -169,6 +169,7 @@ struct BoardCtxt {
#ifdef KEYBOARD_NAV
XP_Bool focusHasDived;
XP_Rect remRect; /* on scoreboard */
#endif
/* scoreboard state */
@ -207,6 +208,8 @@ struct BoardCtxt {
MPSLOT
};
#define CURSOR_LOC_REM 0
#define valHintMiniWindowActive( board ) \
((XP_Bool)((board)->miniWindowStuff[MINIWINDOW_VALHINT].text != NULL))
#define MY_TURN(b) ((b)->selPlayer == server_getCurrentTurn( (b)->server ))

View file

@ -131,7 +131,7 @@ typedef struct DrawCtxVTable {
XP_U16* width, XP_U16* height );
void DRAW_VTABLE_NAME(drawRemText) (DrawCtx* dctx, const XP_Rect* rInner,
const XP_Rect* rOuter,
XP_S16 nTilesLeft);
XP_S16 nTilesLeft, XP_Bool focussed );
void DRAW_VTABLE_NAME(scoreBegin) ( DrawCtx* dctx, const XP_Rect* rect,
XP_U16 numPlayers, DrawFocusState dfs );
@ -256,8 +256,8 @@ struct DrawCtx {
CALL_DRAW_NAME3( scoreBegin,(dc), (r), (t), (f))
#define draw_measureRemText( dc, r, n, wp, hp ) \
CALL_DRAW_NAME4(measureRemText, (dc), (r), (n), (wp), (hp) )
#define draw_drawRemText( dc, ri, ro, n ) \
CALL_DRAW_NAME3(drawRemText, (dc), (ri), (ro), (n) )
#define draw_drawRemText( dc, ri, ro, n, f ) \
CALL_DRAW_NAME4(drawRemText, (dc), (ri), (ro), (n), (f) )
#define draw_measureScoreText(dc,r,dsi,wp,hp) \
CALL_DRAW_NAME4(measureScoreText,(dc),(r),(dsi),(wp),(hp))
#define draw_score_drawPlayer(dc, ri, ro, dsi) \

View file

@ -68,11 +68,15 @@ drawScoreBoard( BoardCtxt* board )
XP_Rect cursorRect;
XP_Rect* cursorRectP = NULL;
XP_Bool focusAll = XP_FALSE;
XP_Bool remFocussed = XP_FALSE;
XP_S16 cursorIndex = -1;
if ( board->focussed == OBJ_SCORE ) {
focusAll = !board->focusHasDived;
if ( !focusAll ) {
cursorIndex = board->scoreCursorLoc;
remFocussed = CURSOR_LOC_REM == cursorIndex;
--cursorIndex;
}
}
#endif
@ -155,12 +159,17 @@ drawScoreBoard( BoardCtxt* board )
*adjustDim = remDim;
draw_drawRemText( board->draw, &scoreRect, &scoreRect,
nTilesInPool );
nTilesInPool, focusAll || remFocussed );
board->remRect = scoreRect;
*adjustPt += remDim;
#ifdef KEYBOARD_NAV
/* Hack: don't let the cursor disappear if Rem: goes away */
} else if ( board->scoreCursorLoc == CURSOR_LOC_REM ) {
board->scoreCursorLoc = selPlayer + 1;
#endif
}
board->remDim = remDim; /* save now so register can be reused */
board->remDim = remDim;
for ( dp = datum, i = 0; i < nPlayers; ++dp, ++i ) {
XP_Rect innerRect;
@ -231,49 +240,53 @@ board_setScoreboardLoc( BoardCtxt* board, XP_U16 scoreLeft, XP_U16 scoreTop,
} /* board_setScoreboardLoc */
XP_S16
figureScorePlayerTapped( BoardCtxt* board, XP_U16 x, XP_U16 y )
figureScoreRectTapped( const BoardCtxt* board, XP_U16 xx, XP_U16 yy )
{
XP_S16 result = -1;
XP_S16 left;
XP_U16 nPlayers = board->gi->nPlayers;
if ( board->scoreSplitHor ) {
left = x - board->scoreBdBounds.left;
left = xx - board->scoreBdBounds.left;
} else {
left = y - board->scoreBdBounds.top;
left = yy - board->scoreBdBounds.top;
}
left -= board->remDim;
if ( left >= 0 ) {
for ( result = 0; result < nPlayers; ++result ) {
PerTurnInfo* pti = board->pti + result;
if ( left < pti->scoreDims ) {
break;
if ( left < 0 ) {
result = CURSOR_LOC_REM;
} else {
for ( result = 0; result < nPlayers; ) {
left -= board->pti[result].scoreDims;
++result; /* increment before test to skip REM */
if ( left < 0 ) {
break; /* found it! */
}
left -= pti->scoreDims;
}
if ( result > nPlayers ) {
result = -1;
}
}
if ( result >= nPlayers ) {
result = -1;
}
return result;
} /* figureScorePlayerTapped */
} /* figureScoreRectTapped */
/* If the pen also went down on the scoreboard, make the selected player the
* one closest to the mouse up loc.
*/
#if defined POINTER_SUPPORT || defined KEYBOARD_NAV
XP_Bool
handlePenUpScore( BoardCtxt* board, XP_U16 x, XP_U16 y )
handlePenUpScore( BoardCtxt* board, XP_U16 xx, XP_U16 yy )
{
XP_Bool result = XP_FALSE;
XP_Bool result = XP_TRUE;
XP_S16 playerNum = figureScorePlayerTapped( board, x, y );
XP_S16 rectNum = figureScoreRectTapped( board, xx, yy );
if ( playerNum >= 0 ) {
board_selectPlayer( board, playerNum );
result = XP_TRUE;
if ( rectNum == CURSOR_LOC_REM ) {
util_remSelected( board->util );
} else if ( --rectNum >= 0 ) {
board_selectPlayer( board, rectNum );
} else {
result = XP_FALSE;
}
return result;
} /* handlePenUpScore */
@ -315,34 +328,34 @@ moveScoreCursor( BoardCtxt* board, XP_Key key, XP_Bool preflightOnly,
XP_Bool* pUp )
{
XP_Bool result = XP_TRUE;
XP_U16 nPlayers = board->gi->nPlayers;
XP_S16 scoreCursorLoc = board->scoreCursorLoc;
XP_U16 top = board->gi->nPlayers;
/* Don't let cursor be 0 if rem square's not shown */
XP_U16 bottom = (board->remDim > 0) ? 0 : 1;
XP_Bool up = XP_FALSE;
/* Depending on scoreboard layout, keys move cursor or leave. */
key = flipKey( key, board->scoreSplitHor );
switch ( key ) {
case XP_CURSOR_KEY_RIGHT:
case XP_CURSOR_KEY_LEFT:
up = XP_TRUE;
break;
case XP_CURSOR_KEY_DOWN:
++scoreCursorLoc;
break;
case XP_CURSOR_KEY_RIGHT:
up = XP_TRUE;
break;
case XP_CURSOR_KEY_UP:
--scoreCursorLoc;
break;
case XP_CURSOR_KEY_LEFT:
up = XP_TRUE;
break;
default:
result = XP_FALSE;
}
if ( !up && ((scoreCursorLoc < 0) || (scoreCursorLoc >= nPlayers)) ) {
if ( !up && ((scoreCursorLoc < bottom) || (scoreCursorLoc > top)) ) {
up = XP_TRUE;
} else if ( !preflightOnly ) {
board->scoreCursorLoc = scoreCursorLoc;
board->scoreBoardInvalid = XP_TRUE;
board->scoreBoardInvalid = result;
}
*pUp = up;

View file

@ -23,7 +23,7 @@
#include "boardp.h"
void drawScoreBoard( BoardCtxt* board );
XP_S16 figureScorePlayerTapped( BoardCtxt* board, XP_U16 x, XP_U16 y );
XP_S16 figureScoreRectTapped( const BoardCtxt* board, XP_U16 x, XP_U16 y );
void drawTimer( BoardCtxt* board );
#if defined POINTER_SUPPORT || defined KEYBOARD_NAV

View file

@ -152,6 +152,9 @@ typedef struct UtilVtable {
XP_Bool (*m_util_warnIllegalWord)( XW_UtilCtxt* uc, BadWordInfo* bwi,
XP_U16 turn, XP_Bool turnLost );
void (*m_util_remSelected)(XW_UtilCtxt* uc);
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
void (*m_util_addrChange)( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
const CommsAddrRec* newAddr );
@ -242,6 +245,9 @@ struct XW_UtilCtxt {
#define util_warnIllegalWord( uc, w, p, b ) \
(uc)->vtable->m_util_warnIllegalWord((uc),(w),(p),(b))
#define util_remSelected( uc ) \
(uc)->vtable->m_util_remSelected((uc))
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
#define util_addrChange( uc, addro, addrn ) \
(uc)->vtable->m_util_addrChange((uc), (addro), (addrn))