mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
update to use new blank-picking API
This commit is contained in:
parent
8789ed9bc5
commit
767d7fa2f4
3 changed files with 54 additions and 63 deletions
|
@ -39,50 +39,41 @@ extern "C" {
|
|||
|
||||
class LettersList : public CList {
|
||||
private:
|
||||
DictionaryCtxt* fDict;
|
||||
Tile blank;
|
||||
XP_UCHAR4* fTexts;
|
||||
|
||||
public:
|
||||
LettersList( DictionaryCtxt* dict, U16 numRows );
|
||||
LettersList( XP_UCHAR4* texts, U16 numRows );
|
||||
|
||||
U16 GetRowHeight( S32 row ) { return LETTER_HEIGHT; }
|
||||
void DrawRow( RECT *rect, S32 row );
|
||||
};
|
||||
|
||||
LettersList::LettersList( DictionaryCtxt* dict, U16 numRows )
|
||||
LettersList::LettersList( XP_UCHAR4* texts, U16 numRows )
|
||||
: CList( 1001, LETTERS_ROW_WIDTH,
|
||||
LETTERS_ROW_HEIGHT * LETTERS_NUM_VISROWS,
|
||||
numRows, LISTOPTION_ALWAYS_HIGHLIGHT )
|
||||
{
|
||||
fDict = dict;
|
||||
this->blank = dict_getBlankTile( dict );
|
||||
fTexts = texts;
|
||||
|
||||
this->SetCurrentRow(0); // Select the first item so there's a default
|
||||
}
|
||||
|
||||
void LettersList::DrawRow( RECT *rect, S32 row )
|
||||
{
|
||||
unsigned char buf[4];
|
||||
Tile tile = row;
|
||||
// We don't draw the blank, and if it's other than the highest value tile
|
||||
// we need to skip it, drawing instead the next tile above.
|
||||
if ( row >= this->blank ) {
|
||||
++tile;
|
||||
}
|
||||
dict_tilesToString( fDict, &tile, 1, buf );
|
||||
CWindow* window = this->GetWindow();
|
||||
window->DrawText( (char*)buf, rect->x, rect->y );
|
||||
window->DrawText( (char*)fTexts[row], rect->x, rect->y );
|
||||
} /* LettersList::DrawRow */
|
||||
|
||||
CAskLetterWindow::CAskLetterWindow( DictionaryCtxt* dict,
|
||||
XP_UCHAR* resultP )
|
||||
CAskLetterWindow::CAskLetterWindow( PickInfo* pi, XP_U16 playerNum,
|
||||
XP_UCHAR4* texts, XP_U16 nTiles,
|
||||
XP_S16* resultP )
|
||||
: CWindow( ASKLETTER_WINDOW_ID, 55, 15, 80, 220, "Blank", TRUE )
|
||||
{
|
||||
fDict = dict;
|
||||
this->resultP = resultP;
|
||||
this->blank = dict_getBlankTile( dict );
|
||||
fTexts = texts;
|
||||
fNTiles = nTiles;
|
||||
fResultP = resultP;
|
||||
|
||||
this->list = new LettersList( dict, dict_numTileFaces( dict ) - 1 );
|
||||
this->list = new LettersList( texts, nTiles );
|
||||
this->AddChild( this->list, 5, 5 );
|
||||
|
||||
CButton* okbutton = new CButton( 1000, 0, 0, "Ok" );
|
||||
|
@ -93,41 +84,33 @@ S32
|
|||
CAskLetterWindow::MsgHandler( MSG_TYPE type, CViewable *object, S32 data )
|
||||
{
|
||||
S32 result = 0;
|
||||
Tile tile;
|
||||
|
||||
switch (type) {
|
||||
case MSG_BUTTON_SELECT: // there's only one button....
|
||||
tile = this->list->GetCurrentRow();
|
||||
if ( tile >= this->blank ) {
|
||||
++tile;
|
||||
}
|
||||
dict_tilesToString( fDict, &tile, 1, this->resultP );
|
||||
*fResultP = this->list->GetCurrentRow();
|
||||
|
||||
this->Close();
|
||||
result = 1;
|
||||
break;
|
||||
this->Close();
|
||||
result = 1;
|
||||
break;
|
||||
|
||||
case MSG_KEY: // allow keys to select the matching letter in the list
|
||||
if ( isalpha( data ) ) {
|
||||
XP_UCHAR ch = toupper(data);
|
||||
Tile tile = dict_tileForString( fDict, &ch );
|
||||
if ( tile != EMPTY_TILE ) {
|
||||
S32 row = tile;
|
||||
XP_ASSERT( tile != this->blank );
|
||||
if ( tile > this->blank ) {
|
||||
--row;
|
||||
}
|
||||
this->list->SetCurrentRow( row );
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
if ( isalpha( data ) ) {
|
||||
XP_UCHAR ch = toupper(data);
|
||||
for ( U16 i = 0; i < fNTiles; ++i ) {
|
||||
if ( ch == fTexts[i][0] ) {
|
||||
this->list->SetCurrentRow( i );
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( result == 0 ) {
|
||||
result = CWindow::MsgHandler( type, object, data );
|
||||
result = CWindow::MsgHandler( type, object, data );
|
||||
}
|
||||
return result;
|
||||
} // CAskLetterWindow::MsgHandler
|
||||
|
|
|
@ -19,15 +19,17 @@
|
|||
|
||||
extern "C" {
|
||||
#include "dictnry.h"
|
||||
#include "util.h"
|
||||
}
|
||||
|
||||
class CAskLetterWindow : public CWindow {
|
||||
private:
|
||||
Tile blank;
|
||||
DictionaryCtxt* fDict;
|
||||
XP_UCHAR* resultP;
|
||||
XP_UCHAR4* fTexts;
|
||||
XP_S16* fResultP;
|
||||
XP_U16 fNTiles;
|
||||
CList* list; /* my own subclass, of course */
|
||||
public:
|
||||
CAskLetterWindow( DictionaryCtxt* dict, XP_UCHAR* resultP );
|
||||
CAskLetterWindow( PickInfo* pi, XP_U16 playerNum,
|
||||
XP_UCHAR4* texts, XP_U16 nTiles, XP_S16* result );
|
||||
S32 MsgHandler( MSG_TYPE type, CViewable *object, S32 data );
|
||||
};
|
||||
|
|
|
@ -90,25 +90,27 @@ static VTableMgr* frank_util_getVTManager( XW_UtilCtxt* uc );
|
|||
static DictionaryCtxt* frank_util_makeEmptyDict( XW_UtilCtxt* uc );
|
||||
static void frank_util_userError( XW_UtilCtxt* uc, UtilErrID id );
|
||||
static XP_U16 frank_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id,
|
||||
XWStreamCtxt* stream );
|
||||
static void frank_util_askBlankFace( XW_UtilCtxt* uc, DictionaryCtxt* dict,
|
||||
XP_UCHAR* buf );
|
||||
XWStreamCtxt* stream );
|
||||
static XP_S16 frank_util_userPickTile( XW_UtilCtxt* uc, PickInfo* pi,
|
||||
XP_U16 playerNum,
|
||||
XP_UCHAR4* texts, XP_U16 nTiles );
|
||||
static XP_Bool frank_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
|
||||
XP_UCHAR* buf, XP_U16* len );
|
||||
XP_UCHAR* buf, XP_U16* len );
|
||||
static void frank_util_trayHiddenChange( XW_UtilCtxt* uc,
|
||||
XW_TrayVisState newState );
|
||||
XW_TrayVisState newState );
|
||||
static void frank_util_notifyGameOver( XW_UtilCtxt* uc );
|
||||
static XP_Bool frank_util_hiliteCell( XW_UtilCtxt* uc, XP_U16 col, XP_U16 row );
|
||||
static XP_Bool frank_util_hiliteCell( XW_UtilCtxt* uc,
|
||||
XP_U16 col, XP_U16 row );
|
||||
static XP_Bool frank_util_engineProgressCallback( XW_UtilCtxt* uc );
|
||||
static void frank_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why );
|
||||
static void frank_util_requestTime( XW_UtilCtxt* uc );
|
||||
static XP_U32 frank_util_getCurSeconds( XW_UtilCtxt* uc );
|
||||
static XWBonusType frank_util_getSquareBonus( XW_UtilCtxt* uc,
|
||||
ModelCtxt* model,
|
||||
XP_U16 col, XP_U16 row );
|
||||
ModelCtxt* model,
|
||||
XP_U16 col, XP_U16 row );
|
||||
static XP_UCHAR* frank_util_getUserString( XW_UtilCtxt* uc, XP_U16 stringCode );
|
||||
static XP_Bool frank_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
|
||||
XP_U16 turn, XP_Bool turnLost );
|
||||
XP_U16 turn, XP_Bool turnLost );
|
||||
static void frank_util_engineStarting( XW_UtilCtxt* uc );
|
||||
static void frank_util_engineStopping( XW_UtilCtxt* uc );
|
||||
|
||||
|
@ -406,7 +408,7 @@ CXWordsWindow::initUtil()
|
|||
/* vtable->m_util_yOffsetChange = NULL <--no scrolling */
|
||||
vtable->m_util_userError = frank_util_userError;
|
||||
vtable->m_util_userQuery = frank_util_userQuery;
|
||||
vtable->m_util_askBlankFace = frank_util_askBlankFace;
|
||||
vtable->m_util_userPickTile = frank_util_userPickTile;
|
||||
vtable->m_util_askPassword = frank_util_askPassword;
|
||||
vtable->m_util_trayHiddenChange = frank_util_trayHiddenChange;
|
||||
vtable->m_util_notifyGameOver = frank_util_notifyGameOver;
|
||||
|
@ -1398,12 +1400,16 @@ frank_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
|
|||
return askResult;
|
||||
} /* frank_util_userQuery */
|
||||
|
||||
static void
|
||||
frank_util_askBlankFace( XW_UtilCtxt* uc, DictionaryCtxt* dict,
|
||||
unsigned char* buf )
|
||||
static XP_S16
|
||||
frank_util_userPickTile( XW_UtilCtxt* uc, PickInfo* pi,
|
||||
XP_U16 playerNum,
|
||||
XP_UCHAR4* texts, XP_U16 nTiles )
|
||||
{
|
||||
CXWordsWindow* self = (CXWordsWindow*)uc->closure;
|
||||
self->wrappedEventLoop( new CAskLetterWindow( dict, buf ) );
|
||||
XP_S16 result;
|
||||
self->wrappedEventLoop( new CAskLetterWindow( pi, playerNum,
|
||||
texts, nTiles, &result ) );
|
||||
return result;
|
||||
/* doesn't need to inval because CAskLetterWindow saves bits behind */
|
||||
} /* frank_util_askBlankFace */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue