mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
let user choose between tile-spellings
This commit is contained in:
parent
87337ba789
commit
0f9bcd9898
4 changed files with 100 additions and 44 deletions
|
@ -308,6 +308,7 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
switch ( dlgID ) {
|
switch ( dlgID ) {
|
||||||
case CHOOSE_TILES:
|
case CHOOSE_TILES:
|
||||||
final byte[][] choices = (byte[][])params[0];
|
final byte[][] choices = (byte[][])params[0];
|
||||||
|
final int indx = (Integer)params[1];
|
||||||
final String[] strs = new String[choices.length];
|
final String[] strs = new String[choices.length];
|
||||||
for ( int ii = 0; ii < choices.length; ++ii ) {
|
for ( int ii = 0; ii < choices.length; ++ii ) {
|
||||||
strs[ii] = XwJNI.dict_tilesToStr( m_dict, choices[ii], DELIM );
|
strs[ii] = XwJNI.dict_tilesToStr( m_dict, choices[ii], DELIM );
|
||||||
|
@ -327,7 +328,8 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
public void onClick( DialogInterface dialog, int which )
|
public void onClick( DialogInterface dialog, int which )
|
||||||
{
|
{
|
||||||
if ( 0 <= chosen[0] ) {
|
if ( 0 <= chosen[0] ) {
|
||||||
Assert.failDbg();
|
int sel = chosen[0];
|
||||||
|
useButtonClicked( indx, choices[sel] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
|
@ -507,7 +509,9 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void useButtonClicked()
|
private void useButtonClicked() { useButtonClicked( -1, null ); }
|
||||||
|
|
||||||
|
private void useButtonClicked( int justFixed, byte[] fixedTiles )
|
||||||
{
|
{
|
||||||
scrapeBrowseState();
|
scrapeBrowseState();
|
||||||
Log.d( TAG, "useButtonClicked(): m_browseState: %s", m_browseState );
|
Log.d( TAG, "useButtonClicked(): m_browseState: %s", m_browseState );
|
||||||
|
@ -521,25 +525,29 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
|
|
||||||
PatDesc[] pats = m_browseState.m_pats;
|
PatDesc[] pats = m_browseState.m_pats;
|
||||||
for ( int ii = 0; ii < pats.length && !pending; ++ii ) {
|
for ( int ii = 0; ii < pats.length && !pending; ++ii ) {
|
||||||
String strPat = pats[ii].strPat;
|
if ( justFixed == ii ) {
|
||||||
if ( null != strPat && 0 < strPat.length() ) {
|
pats[ii].tilePat = fixedTiles;
|
||||||
byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat );
|
|
||||||
if ( null == choices || 0 == choices.length ) {
|
|
||||||
String langName = DictLangCache.getLangName( m_activity, m_lang );
|
|
||||||
String msg = getString( R.string.no_tiles_exist, strPat, langName );
|
|
||||||
makeOkOnlyBuilder( msg )
|
|
||||||
.setActionPair( Action.SHOW_TILES, R.string.show_tiles_button )
|
|
||||||
.show();
|
|
||||||
pending = true;
|
|
||||||
} else if ( 1 == choices.length
|
|
||||||
|| !XwJNI.dict_hasDuplicates( m_dict ) ) {
|
|
||||||
pats[ii].tilePat = choices[0];
|
|
||||||
} else {
|
|
||||||
showDialogFragment( DlgID.CHOOSE_TILES, (Object)choices );
|
|
||||||
pending = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pats[ii].tilePat = null;
|
String strPat = pats[ii].strPat;
|
||||||
|
if ( null != strPat && 0 < strPat.length() ) {
|
||||||
|
byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat );
|
||||||
|
if ( null == choices || 0 == choices.length ) {
|
||||||
|
String langName = DictLangCache.getLangName( m_activity, m_lang );
|
||||||
|
String msg = getString( R.string.no_tiles_exist, strPat, langName );
|
||||||
|
makeOkOnlyBuilder( msg )
|
||||||
|
.setActionPair( Action.SHOW_TILES, R.string.show_tiles_button )
|
||||||
|
.show();
|
||||||
|
pending = true;
|
||||||
|
} else if ( 1 == choices.length
|
||||||
|
|| !XwJNI.dict_hasDuplicates( m_dict ) ) {
|
||||||
|
pats[ii].tilePat = choices[0];
|
||||||
|
} else {
|
||||||
|
showDialogFragment( DlgID.CHOOSE_TILES, (Object)choices, ii );
|
||||||
|
pending = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pats[ii].tilePat = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2664,25 +2664,30 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1init
|
||||||
data->guard = GI_GUARD;
|
data->guard = GI_GUARD;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
jobject jdescs[3];
|
PatDesc patDescs[3];
|
||||||
PatDesc patDescs[3] = {{0}};
|
XP_MEMSET( patDescs, 0, VSIZE(patDescs) * sizeof(patDescs[0]) );
|
||||||
jbyteArray jtiles[3];
|
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
if ( !!jPatsArr ) {
|
if ( !!jPatsArr ) {
|
||||||
len = (*env)->GetArrayLength( env, jPatsArr );
|
len = (*env)->GetArrayLength( env, jPatsArr );
|
||||||
XP_ASSERT( len == 3 );
|
XP_ASSERT( len == 3 );
|
||||||
for ( int ii = 0; ii < len ; ++ii ) {
|
for ( int ii = 0; ii < len ; ++ii ) {
|
||||||
jdescs[ii] = (*env)->GetObjectArrayElement( env, jPatsArr, ii );
|
jobject jdesc = (*env)->GetObjectArrayElement( env, jPatsArr, ii );
|
||||||
if ( !!jdescs[ii] ) {
|
if ( !!jdesc ) {
|
||||||
if ( getObject( env, jdescs[ii], "tilePat", "[B", &jtiles[ii] ) ) {
|
jbyteArray jtiles;
|
||||||
patDescs[ii].nTiles = (*env)->GetArrayLength( env, jtiles[ii] );
|
if ( getObject( env, jdesc, "tilePat", "[B", &jtiles ) ) {
|
||||||
patDescs[ii].tiles = (Tile*)
|
int nTiles = (*env)->GetArrayLength( env, jtiles );
|
||||||
(*env)->GetByteArrayElements( env, jtiles[ii], NULL );
|
if ( 0 < nTiles ) {
|
||||||
patDescs[ii].anyOrderOk = getBool( env, jdescs[ii], "anyOrderOk" );
|
patDescs[ii].nTiles = nTiles;
|
||||||
|
jbyte* tiles = (*env)->GetByteArrayElements( env, jtiles, NULL );
|
||||||
|
XP_MEMCPY( &patDescs[ii].tiles[0], tiles,
|
||||||
|
nTiles * sizeof(patDescs[ii].tiles[0]) );
|
||||||
|
(*env)->ReleaseByteArrayElements( env, jtiles, tiles, 0 );
|
||||||
|
patDescs[ii].anyOrderOk = getBool( env, jdesc, "anyOrderOk" );
|
||||||
|
}
|
||||||
|
deleteLocalRef( env, jtiles );
|
||||||
}
|
}
|
||||||
} else {
|
deleteLocalRef( env, jdesc );
|
||||||
jtiles[ii] = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2691,14 +2696,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1init
|
||||||
data->iter = di_makeIter( data->dict, env, &mm, NULL, 0,
|
data->iter = di_makeIter( data->dict, env, &mm, NULL, 0,
|
||||||
!!jPatsArr ? patDescs : NULL, VSIZE(patDescs) );
|
!!jPatsArr ? patDescs : NULL, VSIZE(patDescs) );
|
||||||
|
|
||||||
for ( int ii = 0; ii < len ; ++ii ) {
|
|
||||||
if ( !!jtiles[ii] ) {
|
|
||||||
(*env)->ReleaseByteArrayElements( env, jtiles[ii],
|
|
||||||
(jbyte*)patDescs[ii].tiles, 0 );
|
|
||||||
deleteLocalRef( env, jtiles[ii] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
makeIndex( data );
|
makeIndex( data );
|
||||||
(void)di_firstWord( data->iter );
|
(void)di_firstWord( data->iter );
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ typedef struct DictIter DictIter;
|
||||||
* ends-with. The first is more powerful but I'm not sure it'll ever be part
|
* ends-with. The first is more powerful but I'm not sure it'll ever be part
|
||||||
* of a shipping UI.*/
|
* of a shipping UI.*/
|
||||||
typedef struct _PatDesc {
|
typedef struct _PatDesc {
|
||||||
const Tile* tiles;
|
Tile tiles[16];
|
||||||
XP_U16 nTiles;
|
XP_U16 nTiles;
|
||||||
XP_Bool anyOrderOk;
|
XP_Bool anyOrderOk;
|
||||||
} PatDesc;
|
} PatDesc;
|
||||||
|
|
|
@ -832,6 +832,9 @@ typedef enum {
|
||||||
,CMD_TESTPAT
|
,CMD_TESTPAT
|
||||||
,CMD_TESTSTR
|
,CMD_TESTSTR
|
||||||
#endif
|
#endif
|
||||||
|
,CMD_TESTSTARTSW
|
||||||
|
,CMD_TESTCONTAINS
|
||||||
|
,CMD_TESTENDS
|
||||||
,CMD_DICTDIR
|
,CMD_DICTDIR
|
||||||
,CMD_PLAYERDICT
|
,CMD_PLAYERDICT
|
||||||
,CMD_SEED
|
,CMD_SEED
|
||||||
|
@ -971,6 +974,10 @@ static CmdInfoRec CmdInfoRecs[] = {
|
||||||
,{ CMD_TESTSTR, true, "test-string",
|
,{ CMD_TESTSTR, true, "test-string",
|
||||||
"string to be tested against test-pat; exit with non-0 if doesn't match" }
|
"string to be tested against test-pat; exit with non-0 if doesn't match" }
|
||||||
#endif
|
#endif
|
||||||
|
,{CMD_TESTSTARTSW, true, "test-startsw", "use as 'start-with' for pattern"}
|
||||||
|
,{CMD_TESTCONTAINS, true, "test-contains", "use as 'contains' for pattern"}
|
||||||
|
,{CMD_TESTENDS, true, "test-endsw", "use as 'ends-with' for pattern"}
|
||||||
|
|
||||||
,{ CMD_DICTDIR, true, "dict-dir", "path to dir in which dicts will be sought" }
|
,{ CMD_DICTDIR, true, "dict-dir", "path to dir in which dicts will be sought" }
|
||||||
,{ CMD_PLAYERDICT, true, "player-dict", "dictionary name for player (in sequence)" }
|
,{ CMD_PLAYERDICT, true, "player-dict", "dictionary name for player (in sequence)" }
|
||||||
,{ CMD_SEED, true, "seed", "random seed" }
|
,{ CMD_SEED, true, "seed", "random seed" }
|
||||||
|
@ -1941,14 +1948,45 @@ tmp_noop_sigintterm( int XP_UNUSED(sig) )
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _FTD {
|
||||||
|
PatDesc* desc;
|
||||||
|
XP_Bool called;
|
||||||
|
} FTD;
|
||||||
|
|
||||||
|
static XP_Bool
|
||||||
|
onFoundTiles2( void* closure, const Tile* tiles, int nTiles )
|
||||||
|
{
|
||||||
|
FTD* data = (FTD*)closure;
|
||||||
|
if ( data->called ) {
|
||||||
|
XP_LOGFF( "ERROR: called more than once; Hungarian case???" );
|
||||||
|
} else if ( nTiles > VSIZE(data->desc->tiles) ) {
|
||||||
|
XP_ASSERT(0);
|
||||||
|
} else {
|
||||||
|
data->called = XP_TRUE;
|
||||||
|
data->desc->nTiles = nTiles;
|
||||||
|
XP_MEMCPY( &data->desc->tiles[0], tiles, nTiles * sizeof(tiles[0]) );
|
||||||
|
}
|
||||||
|
return XP_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef XWFEATURE_WALKDICT
|
#ifdef XWFEATURE_WALKDICT
|
||||||
|
static void
|
||||||
|
getPat( const DictionaryCtxt* dict, const XP_UCHAR* str, PatDesc* desc )
|
||||||
|
{
|
||||||
|
if ( !!str && '\0' != str[0] ) {
|
||||||
|
FTD data = { .desc = desc, };
|
||||||
|
dict_tilesForString( dict, str, 0, onFoundTiles2, &data );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static DictIter*
|
static DictIter*
|
||||||
patsParamsToIter( const LaunchParams* params, const DictionaryCtxt* dict )
|
patsParamsToIter( const LaunchParams* params, const DictionaryCtxt* dict )
|
||||||
{
|
{
|
||||||
const XP_UCHAR** strPats = NULL;
|
const XP_UCHAR** strPats = NULL;
|
||||||
const XP_UCHAR* _strPats[4];
|
const XP_UCHAR* _strPats[4];
|
||||||
XP_U16 nStrPats = 0;
|
XP_U16 nStrPats = 0;
|
||||||
const PatDesc* pats = NULL;
|
PatDesc descs[3] = {0};
|
||||||
XP_U16 nPatDescs = 0;
|
XP_U16 nPatDescs = 0;
|
||||||
|
|
||||||
if ( !!params->iterTestPats ) {
|
if ( !!params->iterTestPats ) {
|
||||||
|
@ -1962,7 +2000,10 @@ patsParamsToIter( const LaunchParams* params, const DictionaryCtxt* dict )
|
||||||
strPats[ii] = iter->data;
|
strPats[ii] = iter->data;
|
||||||
}
|
}
|
||||||
} else if ( !!params->patStartW || !!params->patContains || !!params->patEndsW ) {
|
} else if ( !!params->patStartW || !!params->patContains || !!params->patEndsW ) {
|
||||||
XP_ASSERT(0);
|
getPat( dict, params->patStartW, &descs[0] );
|
||||||
|
getPat( dict, params->patContains, &descs[1] );
|
||||||
|
getPat( dict, params->patEndsW, &descs[2] );
|
||||||
|
nPatDescs = 3;
|
||||||
/* and what about the boolean? */
|
/* and what about the boolean? */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1973,7 +2014,7 @@ patsParamsToIter( const LaunchParams* params, const DictionaryCtxt* dict )
|
||||||
}
|
}
|
||||||
|
|
||||||
DictIter* iter = di_makeIter( dict, NULL_XWE, dimmp, strPats, nStrPats,
|
DictIter* iter = di_makeIter( dict, NULL_XWE, dimmp, strPats, nStrPats,
|
||||||
pats, nPatDescs );
|
descs, nPatDescs );
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2822,6 +2863,16 @@ main( int argc, char** argv )
|
||||||
mainParams.iterTestPatStr = optarg;
|
mainParams.iterTestPatStr = optarg;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case CMD_TESTSTARTSW:
|
||||||
|
mainParams.patStartW = optarg;
|
||||||
|
break;
|
||||||
|
case CMD_TESTCONTAINS:
|
||||||
|
mainParams.patContains = optarg;
|
||||||
|
break;
|
||||||
|
case CMD_TESTENDS:
|
||||||
|
mainParams.patEndsW = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case CMD_DICTDIR:
|
case CMD_DICTDIR:
|
||||||
mainParams.dictDirs = g_slist_append( mainParams.dictDirs, optarg );
|
mainParams.dictDirs = g_slist_append( mainParams.dictDirs, optarg );
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue