mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-06 20:45:54 +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 {
|
class LettersList : public CList {
|
||||||
private:
|
private:
|
||||||
DictionaryCtxt* fDict;
|
XP_UCHAR4* fTexts;
|
||||||
Tile blank;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LettersList( DictionaryCtxt* dict, U16 numRows );
|
LettersList( XP_UCHAR4* texts, U16 numRows );
|
||||||
|
|
||||||
U16 GetRowHeight( S32 row ) { return LETTER_HEIGHT; }
|
U16 GetRowHeight( S32 row ) { return LETTER_HEIGHT; }
|
||||||
void DrawRow( RECT *rect, S32 row );
|
void DrawRow( RECT *rect, S32 row );
|
||||||
};
|
};
|
||||||
|
|
||||||
LettersList::LettersList( DictionaryCtxt* dict, U16 numRows )
|
LettersList::LettersList( XP_UCHAR4* texts, U16 numRows )
|
||||||
: CList( 1001, LETTERS_ROW_WIDTH,
|
: CList( 1001, LETTERS_ROW_WIDTH,
|
||||||
LETTERS_ROW_HEIGHT * LETTERS_NUM_VISROWS,
|
LETTERS_ROW_HEIGHT * LETTERS_NUM_VISROWS,
|
||||||
numRows, LISTOPTION_ALWAYS_HIGHLIGHT )
|
numRows, LISTOPTION_ALWAYS_HIGHLIGHT )
|
||||||
{
|
{
|
||||||
fDict = dict;
|
fTexts = texts;
|
||||||
this->blank = dict_getBlankTile( dict );
|
|
||||||
|
|
||||||
this->SetCurrentRow(0); // Select the first item so there's a default
|
this->SetCurrentRow(0); // Select the first item so there's a default
|
||||||
}
|
}
|
||||||
|
|
||||||
void LettersList::DrawRow( RECT *rect, S32 row )
|
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();
|
CWindow* window = this->GetWindow();
|
||||||
window->DrawText( (char*)buf, rect->x, rect->y );
|
window->DrawText( (char*)fTexts[row], rect->x, rect->y );
|
||||||
} /* LettersList::DrawRow */
|
} /* LettersList::DrawRow */
|
||||||
|
|
||||||
CAskLetterWindow::CAskLetterWindow( DictionaryCtxt* dict,
|
CAskLetterWindow::CAskLetterWindow( PickInfo* pi, XP_U16 playerNum,
|
||||||
XP_UCHAR* resultP )
|
XP_UCHAR4* texts, XP_U16 nTiles,
|
||||||
|
XP_S16* resultP )
|
||||||
: CWindow( ASKLETTER_WINDOW_ID, 55, 15, 80, 220, "Blank", TRUE )
|
: CWindow( ASKLETTER_WINDOW_ID, 55, 15, 80, 220, "Blank", TRUE )
|
||||||
{
|
{
|
||||||
fDict = dict;
|
fTexts = texts;
|
||||||
this->resultP = resultP;
|
fNTiles = nTiles;
|
||||||
this->blank = dict_getBlankTile( dict );
|
fResultP = resultP;
|
||||||
|
|
||||||
this->list = new LettersList( dict, dict_numTileFaces( dict ) - 1 );
|
this->list = new LettersList( texts, nTiles );
|
||||||
this->AddChild( this->list, 5, 5 );
|
this->AddChild( this->list, 5, 5 );
|
||||||
|
|
||||||
CButton* okbutton = new CButton( 1000, 0, 0, "Ok" );
|
CButton* okbutton = new CButton( 1000, 0, 0, "Ok" );
|
||||||
|
@ -93,15 +84,10 @@ S32
|
||||||
CAskLetterWindow::MsgHandler( MSG_TYPE type, CViewable *object, S32 data )
|
CAskLetterWindow::MsgHandler( MSG_TYPE type, CViewable *object, S32 data )
|
||||||
{
|
{
|
||||||
S32 result = 0;
|
S32 result = 0;
|
||||||
Tile tile;
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MSG_BUTTON_SELECT: // there's only one button....
|
case MSG_BUTTON_SELECT: // there's only one button....
|
||||||
tile = this->list->GetCurrentRow();
|
*fResultP = this->list->GetCurrentRow();
|
||||||
if ( tile >= this->blank ) {
|
|
||||||
++tile;
|
|
||||||
}
|
|
||||||
dict_tilesToString( fDict, &tile, 1, this->resultP );
|
|
||||||
|
|
||||||
this->Close();
|
this->Close();
|
||||||
result = 1;
|
result = 1;
|
||||||
|
@ -110,15 +96,12 @@ CAskLetterWindow::MsgHandler( MSG_TYPE type, CViewable *object, S32 data )
|
||||||
case MSG_KEY: // allow keys to select the matching letter in the list
|
case MSG_KEY: // allow keys to select the matching letter in the list
|
||||||
if ( isalpha( data ) ) {
|
if ( isalpha( data ) ) {
|
||||||
XP_UCHAR ch = toupper(data);
|
XP_UCHAR ch = toupper(data);
|
||||||
Tile tile = dict_tileForString( fDict, &ch );
|
for ( U16 i = 0; i < fNTiles; ++i ) {
|
||||||
if ( tile != EMPTY_TILE ) {
|
if ( ch == fTexts[i][0] ) {
|
||||||
S32 row = tile;
|
this->list->SetCurrentRow( i );
|
||||||
XP_ASSERT( tile != this->blank );
|
|
||||||
if ( tile > this->blank ) {
|
|
||||||
--row;
|
|
||||||
}
|
|
||||||
this->list->SetCurrentRow( row );
|
|
||||||
result = 1;
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,17 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "dictnry.h"
|
#include "dictnry.h"
|
||||||
|
#include "util.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
class CAskLetterWindow : public CWindow {
|
class CAskLetterWindow : public CWindow {
|
||||||
private:
|
private:
|
||||||
Tile blank;
|
XP_UCHAR4* fTexts;
|
||||||
DictionaryCtxt* fDict;
|
XP_S16* fResultP;
|
||||||
XP_UCHAR* resultP;
|
XP_U16 fNTiles;
|
||||||
CList* list; /* my own subclass, of course */
|
CList* list; /* my own subclass, of course */
|
||||||
public:
|
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 );
|
S32 MsgHandler( MSG_TYPE type, CViewable *object, S32 data );
|
||||||
};
|
};
|
||||||
|
|
|
@ -91,14 +91,16 @@ static DictionaryCtxt* frank_util_makeEmptyDict( XW_UtilCtxt* uc );
|
||||||
static void frank_util_userError( XW_UtilCtxt* uc, UtilErrID id );
|
static void frank_util_userError( XW_UtilCtxt* uc, UtilErrID id );
|
||||||
static XP_U16 frank_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id,
|
static XP_U16 frank_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id,
|
||||||
XWStreamCtxt* stream );
|
XWStreamCtxt* stream );
|
||||||
static void frank_util_askBlankFace( XW_UtilCtxt* uc, DictionaryCtxt* dict,
|
static XP_S16 frank_util_userPickTile( XW_UtilCtxt* uc, PickInfo* pi,
|
||||||
XP_UCHAR* buf );
|
XP_U16 playerNum,
|
||||||
|
XP_UCHAR4* texts, XP_U16 nTiles );
|
||||||
static XP_Bool frank_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
|
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,
|
static void frank_util_trayHiddenChange( XW_UtilCtxt* uc,
|
||||||
XW_TrayVisState newState );
|
XW_TrayVisState newState );
|
||||||
static void frank_util_notifyGameOver( XW_UtilCtxt* uc );
|
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 XP_Bool frank_util_engineProgressCallback( XW_UtilCtxt* uc );
|
||||||
static void frank_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why );
|
static void frank_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why );
|
||||||
static void frank_util_requestTime( XW_UtilCtxt* uc );
|
static void frank_util_requestTime( XW_UtilCtxt* uc );
|
||||||
|
@ -406,7 +408,7 @@ CXWordsWindow::initUtil()
|
||||||
/* vtable->m_util_yOffsetChange = NULL <--no scrolling */
|
/* vtable->m_util_yOffsetChange = NULL <--no scrolling */
|
||||||
vtable->m_util_userError = frank_util_userError;
|
vtable->m_util_userError = frank_util_userError;
|
||||||
vtable->m_util_userQuery = frank_util_userQuery;
|
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_askPassword = frank_util_askPassword;
|
||||||
vtable->m_util_trayHiddenChange = frank_util_trayHiddenChange;
|
vtable->m_util_trayHiddenChange = frank_util_trayHiddenChange;
|
||||||
vtable->m_util_notifyGameOver = frank_util_notifyGameOver;
|
vtable->m_util_notifyGameOver = frank_util_notifyGameOver;
|
||||||
|
@ -1398,12 +1400,16 @@ frank_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
|
||||||
return askResult;
|
return askResult;
|
||||||
} /* frank_util_userQuery */
|
} /* frank_util_userQuery */
|
||||||
|
|
||||||
static void
|
static XP_S16
|
||||||
frank_util_askBlankFace( XW_UtilCtxt* uc, DictionaryCtxt* dict,
|
frank_util_userPickTile( XW_UtilCtxt* uc, PickInfo* pi,
|
||||||
unsigned char* buf )
|
XP_U16 playerNum,
|
||||||
|
XP_UCHAR4* texts, XP_U16 nTiles )
|
||||||
{
|
{
|
||||||
CXWordsWindow* self = (CXWordsWindow*)uc->closure;
|
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 */
|
/* doesn't need to inval because CAskLetterWindow saves bits behind */
|
||||||
} /* frank_util_askBlankFace */
|
} /* frank_util_askBlankFace */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue