drive letters/values from a three-value enum

There are three choices now. The button pops up a menu on android and
moves through the choices on linux.
This commit is contained in:
Eric House 2021-02-11 14:11:02 -08:00
parent 64f1d83b5d
commit be0a6f83f3
24 changed files with 196 additions and 115 deletions

View file

@ -38,6 +38,7 @@ import java.util.Set;
import org.eehouse.android.xw4.jni.BoardDims; import org.eehouse.android.xw4.jni.BoardDims;
import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.CommonPrefs;
import org.eehouse.android.xw4.jni.CommonPrefs.TileValueType;
import org.eehouse.android.xw4.jni.DrawCtx; import org.eehouse.android.xw4.jni.DrawCtx;
import org.eehouse.android.xw4.jni.DrawScoreInfo; import org.eehouse.android.xw4.jni.DrawScoreInfo;
import org.eehouse.android.xw4.jni.JNIThread; import org.eehouse.android.xw4.jni.JNIThread;
@ -372,8 +373,8 @@ public class BoardCanvas extends Canvas implements DrawCtx {
} }
@Override @Override
public boolean drawCell( Rect rect, String text, int tile, String value, public boolean drawCell( Rect rect, String text, int tile, int tileValue,
int owner, int bonus, int hintAtts, int flags ) int owner, int bonus, int flags, TileValueType tvType )
{ {
boolean canDraw = figureFontDims(); boolean canDraw = figureFontDims();
if ( canDraw ) { if ( canDraw ) {
@ -431,6 +432,19 @@ public class BoardCanvas extends Canvas implements DrawCtx {
drawCentered( bonusStr, brect, m_fontDims ); drawCentered( bonusStr, brect, m_fontDims );
} }
} else { } else {
String value = String.format( "%d", tileValue );
switch ( tvType ) {
case TVT_BOTH:
break;
case TVT_FACES:
value = null;
break;
case TVT_VALUES:
text = value;
value = null;
break;
}
m_fillPaint.setColor( adjustColor(foreColor) ); m_fillPaint.setColor( adjustColor(foreColor) );
if ( null == value ) { if ( null == value ) {
drawCentered( text, rect, m_fontDims ); drawCentered( text, rect, m_fontDims );
@ -441,8 +455,8 @@ public class BoardCanvas extends Canvas implements DrawCtx {
drawCentered( text, smaller, m_fontDims ); drawCentered( text, smaller, m_fontDims );
smaller = new Rect(rect); smaller = new Rect(rect);
smaller.left += (3 * smaller.width()) / 4; smaller.left += (2 * smaller.width()) / 3;
smaller.top += (3 * smaller.height()) / 4; smaller.top += (2 * smaller.height()) / 3;
drawCentered( value, smaller, m_fontDims ); drawCentered( value, smaller, m_fontDims );
} }
} }

View file

@ -41,6 +41,7 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.TextView; import android.widget.TextView;
import java.io.Serializable; import java.io.Serializable;
@ -761,8 +762,6 @@ public class BoardDelegate extends DelegateBase
Utils.setItemVisible( menu, R.id.board_menu_flip, Utils.setItemVisible( menu, R.id.board_menu_flip,
m_gsi.visTileCount >= 1 ); m_gsi.visTileCount >= 1 );
Utils.setItemVisible( menu, R.id.board_menu_toggle,
m_gsi.visTileCount >= 1 );
Utils.setItemVisible( menu, R.id.board_menu_juggle, Utils.setItemVisible( menu, R.id.board_menu_juggle,
m_gsi.canShuffle ); m_gsi.canShuffle );
Utils.setItemVisible( menu, R.id.board_menu_undo_current, Utils.setItemVisible( menu, R.id.board_menu_undo_current,
@ -885,9 +884,6 @@ public class BoardDelegate extends DelegateBase
case R.id.board_menu_chat: case R.id.board_menu_chat:
startChatActivity(); startChatActivity();
break; break;
case R.id.board_menu_toggle:
cmd = JNICmd.CMD_VALUES;
break;
case R.id.board_menu_trade: case R.id.board_menu_trade:
String msg = getString( R.string.not_again_trading ); String msg = getString( R.string.not_again_trading );
@ -1031,7 +1027,7 @@ public class BoardDelegate extends DelegateBase
cmd = JNICmd.CMD_UNDO_CUR; cmd = JNICmd.CMD_UNDO_CUR;
break; break;
case VALUES_ACTION: case VALUES_ACTION:
cmd = JNICmd.CMD_VALUES; doValuesPopup( m_toolbar.getButtonFor( Buttons.BUTTON_VALUES ) );
break; break;
case CHAT_ACTION: case CHAT_ACTION:
startChatActivity(); startChatActivity();
@ -2496,6 +2492,41 @@ public class BoardDelegate extends DelegateBase
names, locs ); names, locs );
} }
private void doValuesPopup( View button )
{
PopupMenu popup = new PopupMenu( m_activity, button );
popup.inflate( R.menu.tile_values );
popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick( MenuItem item ) {
CommonPrefs.TileValueType tvType = null;
int id = item.getItemId();
switch ( id ) {
case R.id.values_faces:
tvType = CommonPrefs.TileValueType.TVT_FACES;
break;
case R.id.values_values:
tvType = CommonPrefs.TileValueType.TVT_VALUES;
break;
case R.id.values_both:
tvType = CommonPrefs.TileValueType.TVT_BOTH;
break;
default:
Assert.failDbg();
}
if ( null != tvType ) {
XWPrefs.setPrefsInt( m_activity,
R.string.key_tile_valuetype,
tvType.ordinal() );
handleViaThread( JNICmd.CMD_PREFS_CHANGE );
}
return true;
}
} );
popup.show();
}
private void getConfirmPause( boolean isPause ) private void getConfirmPause( boolean isPause )
{ {
showDialogFragment( DlgID.ASK_DUP_PAUSE, isPause ); showDialogFragment( DlgID.ASK_DUP_PAUSE, isPause );

View file

@ -35,6 +35,12 @@ import org.eehouse.android.xw4.loc.LocUtils;
public class CommonPrefs extends XWPrefs { public class CommonPrefs extends XWPrefs {
private static final String TAG = CommonPrefs.class.getSimpleName(); private static final String TAG = CommonPrefs.class.getSimpleName();
public enum TileValueType {
TVT_BOTH,
TVT_FACES,
TVT_VALUES,
};
public static final int COLOR_TILE_BACK = 0; public static final int COLOR_TILE_BACK = 0;
public static final int COLOR_NOTILE = 1; public static final int COLOR_NOTILE = 1;
public static final int COLOR_FOCUS = 2; public static final int COLOR_FOCUS = 2;
@ -53,6 +59,7 @@ public class CommonPrefs extends XWPrefs {
public boolean sortNewTiles; public boolean sortNewTiles;
public boolean allowPeek; public boolean allowPeek;
public boolean hideCrosshairs; public boolean hideCrosshairs;
public TileValueType tvType;
public int[] playerColors; public int[] playerColors;
public int[] bonusColors; public int[] bonusColors;
@ -85,6 +92,9 @@ public class CommonPrefs extends XWPrefs {
allowPeek = getBoolean( context, sp, R.string.key_peek_other, false ); allowPeek = getBoolean( context, sp, R.string.key_peek_other, false );
hideCrosshairs = getBoolean( context, sp, R.string.key_hide_crosshairs, false ); hideCrosshairs = getBoolean( context, sp, R.string.key_hide_crosshairs, false );
int ord = getInt(context, sp, R.string.key_tile_valuetype, 0);
tvType = TileValueType.values()[ord];
int ids[] = { R.string.key_player0, int ids[] = { R.string.key_player0,
R.string.key_player1, R.string.key_player1,
R.string.key_player2, R.string.key_player2,
@ -125,6 +135,13 @@ public class CommonPrefs extends XWPrefs {
return sp.getBoolean( key, dflt ); return sp.getBoolean( key, dflt );
} }
private int getInt( Context context, SharedPreferences sp,
int id, int dflt )
{
String key = LocUtils.getString( context, id );
return sp.getInt( key, dflt );
}
private int prefToColor( Context context, SharedPreferences sp, int id ) private int prefToColor( Context context, SharedPreferences sp, int id )
{ {
String key = LocUtils.getString( context, id ); String key = LocUtils.getString( context, id );

View file

@ -22,6 +22,8 @@ package org.eehouse.android.xw4.jni;
import android.graphics.Rect; import android.graphics.Rect;
import org.eehouse.android.xw4.jni.CommonPrefs.TileValueType;
public interface DrawCtx { public interface DrawCtx {
// These must be kept in sync with the enum CellFlags in draw.h // These must be kept in sync with the enum CellFlags in draw.h
static final int CELL_NONE = 0x00; static final int CELL_NONE = 0x00;
@ -59,8 +61,8 @@ public interface DrawCtx {
void drawTimer( Rect rect, int player, int secondsLeft, boolean inDuplicateMode ); void drawTimer( Rect rect, int player, int secondsLeft, boolean inDuplicateMode );
boolean drawCell( Rect rect, String text, int tile, String value, boolean drawCell( Rect rect, String text, int tile, int value,
int owner, int bonus, int hintAtts, int flags ); int owner, int bonus, int flags, TileValueType tvType );
void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts, void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts,
int flags ); int flags );
boolean trayBegin ( Rect rect, int owner, int score ); boolean trayBegin ( Rect rect, int owner, int score );

View file

@ -84,7 +84,6 @@ public class JNIThread extends Thread implements AutoCloseable {
CMD_ZOOM, CMD_ZOOM,
CMD_PREV_HINT, CMD_PREV_HINT,
CMD_NEXT_HINT, CMD_NEXT_HINT,
CMD_VALUES,
CMD_COUNTS_VALUES, CMD_COUNTS_VALUES,
CMD_REMAINING, CMD_REMAINING,
CMD_RESEND, CMD_RESEND,
@ -641,10 +640,6 @@ public class JNIThread extends Thread implements AutoCloseable {
barr ); barr );
break; break;
case CMD_VALUES:
draw = XwJNI.board_toggle_showValues( m_jniGamePtr );
break;
case CMD_COUNTS_VALUES: case CMD_COUNTS_VALUES:
sendForDialog( ((Integer)args[0]).intValue(), sendForDialog( ((Integer)args[0]).intValue(),
XwJNI.server_formatDictCounts( m_jniGamePtr, 3 ) XwJNI.server_formatDictCounts( m_jniGamePtr, 3 )

View file

@ -414,7 +414,6 @@ public class XwJNI {
public static native int board_getTrayVisState( GamePtr gamePtr ); public static native int board_getTrayVisState( GamePtr gamePtr );
public static native boolean board_hideTray( GamePtr gamePtr ); public static native boolean board_hideTray( GamePtr gamePtr );
public static native boolean board_showTray( GamePtr gamePtr ); public static native boolean board_showTray( GamePtr gamePtr );
public static native boolean board_toggle_showValues( GamePtr gamePtr );
public static native boolean board_commitTurn( GamePtr gamePtr, public static native boolean board_commitTurn( GamePtr gamePtr,
boolean phoniesConfirmed, boolean phoniesConfirmed,
boolean turnConfirmed, boolean turnConfirmed,

View file

@ -66,9 +66,6 @@
<item android:id="@+id/board_menu_chat" <item android:id="@+id/board_menu_chat"
android:title="@string/menu_chat" android:title="@string/menu_chat"
/> />
<item android:id="@+id/board_menu_toggle"
android:title="@string/menu_toggle_values"
/>
<item android:title="@string/board_submenu_game"> <item android:title="@string/board_submenu_game">
<menu> <menu>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/values_both"
android:title="@string/values_menu_both"
/>
<item android:id="@+id/values_faces"
android:title="@string/values_menu_faces"
/>
<item android:id="@+id/values_values"
android:title="@string/values_menu_values"
/>
</menu>

View file

@ -15,6 +15,7 @@
<string name="key_sort_tiles">key_sort_tiles</string> <string name="key_sort_tiles">key_sort_tiles</string>
<string name="key_peek_other">key_peek_other</string> <string name="key_peek_other">key_peek_other</string>
<string name="key_hide_crosshairs">key_hide_crosshairs</string> <string name="key_hide_crosshairs">key_hide_crosshairs</string>
<string name="key_tile_valuetype">key_tile_valuetype</string>
<string name="key_hide_values">key_hide_values</string> <string name="key_hide_values">key_hide_values</string>
<string name="key_hide_title">key_hide_title</string> <string name="key_hide_title">key_hide_title</string>
<string name="key_hide_newgames">key_hide_newgames</string> <string name="key_hide_newgames">key_hide_newgames</string>

View file

@ -1813,8 +1813,6 @@
<!-- --> <!-- -->
<string name="menu_chat">Chat</string> <string name="menu_chat">Chat</string>
<string name="chat_sender_fmt">%1$s:</string> <string name="chat_sender_fmt">%1$s:</string>
<!-- -->
<string name="menu_toggle_values">Toggle values</string>
<!-- board menu for small devices only --> <!-- board menu for small devices only -->
<string name="board_menu_dict">Browse wordlist</string> <string name="board_menu_dict">Browse wordlist</string>
<!-- --> <!-- -->
@ -2673,4 +2671,10 @@
Tap this and you'll get taken to the "Game configure" Tap this and you'll get taken to the "Game configure"
screen --> screen -->
<string name="newgame_configure_first">Configure first</string> <string name="newgame_configure_first">Configure first</string>
<!-- For the (new) popup menu for how tile displayed on board -->
<string name="values_menu_faces">Letters only</string>
<string name="values_menu_values">Values only</string>
<string name="values_menu_both">Letters and Values</string>
</resources> </resources>

View file

@ -43,12 +43,15 @@ typedef struct _AndDraw {
jobject jdraw; /* global ref; free it! */ jobject jdraw; /* global ref; free it! */
XP_LangCode curLang; XP_LangCode curLang;
jobject jCache[JCACHE_COUNT]; jobject jCache[JCACHE_COUNT];
jobject jTvType;
XP_UCHAR miniTextBuf[128]; XP_UCHAR miniTextBuf[128];
MPSLOT MPSLOT
} AndDraw; } AndDraw;
#define CHECKOUT_MARKER ((jobject)-1) #define CHECKOUT_MARKER ((jobject)-1)
static void deleteGlobalRef( JNIEnv* env, jobject jobj );
static jobject static jobject
makeJRect( AndDraw* draw, JNIEnv* env, int indx, const XP_Rect* rect ) makeJRect( AndDraw* draw, JNIEnv* env, int indx, const XP_Rect* rect )
{ {
@ -399,24 +402,32 @@ static XP_Bool and_draw_beginDraw( DrawCtx* XP_UNUSED(dctx),
static void and_draw_endDraw( DrawCtx* XP_UNUSED(dctx), XWEnv XP_UNUSED(xwe) ) {} static void and_draw_endDraw( DrawCtx* XP_UNUSED(dctx), XWEnv XP_UNUSED(xwe) ) {}
static XP_Bool static XP_Bool
and_draw_boardBegin( DrawCtx* XP_UNUSED(dctx), XWEnv XP_UNUSED(xwe), and_draw_boardBegin( DrawCtx* dctx, XWEnv xwe, const XP_Rect* XP_UNUSED(rect),
const XP_Rect* XP_UNUSED(rect),
XP_U16 XP_UNUSED(cellWidth), XP_U16 XP_UNUSED(cellHeight), XP_U16 XP_UNUSED(cellWidth), XP_U16 XP_UNUSED(cellHeight),
DrawFocusState XP_UNUSED(dfs) ) DrawFocusState XP_UNUSED(dfs), TileValueType tvType )
{ {
JNIEnv* env = xwe;
AndDraw* draw = (AndDraw*)dctx;
jobject jTvType = intToJEnum( env, tvType, PKG_PATH("jni/CommonPrefs$TileValueType") );
draw->jTvType = (*env)->NewGlobalRef( env, jTvType );
deleteLocalRef( env, jTvType );
return XP_TRUE; return XP_TRUE;
} }
static XP_Bool static XP_Bool
and_draw_drawCell( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect, and_draw_drawCell( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect,
const XP_UCHAR* text, const XP_Bitmaps* bitmaps, const XP_UCHAR* text, const XP_Bitmaps* bitmaps,
Tile tile, const XP_UCHAR* value, Tile tile, XP_U16 value,
XP_S16 owner, XWBonusType bonus, HintAtts hintAtts, XP_S16 owner, XWBonusType bonus, HintAtts hintAtts,
CellFlags flags ) CellFlags flags )
{ {
jboolean result; jboolean result;
DRAW_CBK_HEADER("drawCell", DRAW_CBK_HEADER("drawCell",
"(Landroid/graphics/Rect;Ljava/lang/String;ILjava/lang/String;IIII)Z" ); "(Landroid/graphics/Rect;Ljava/lang/String;IIIII"
"L" PKG_PATH("jni/CommonPrefs$TileValueType") ";)Z" );
jobject jrect = makeJRect( draw, xwe, JCACHE_RECT0, rect ); jobject jrect = makeJRect( draw, xwe, JCACHE_RECT0, rect );
jstring jtext = NULL; jstring jtext = NULL;
if ( !!text ) { if ( !!text ) {
@ -425,14 +436,12 @@ and_draw_drawCell( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect,
} }
jtext = (*env)->NewStringUTF( env, text ); jtext = (*env)->NewStringUTF( env, text );
} }
jstring jval = !!value ? (*env)->NewStringUTF( env, value ) : NULL;
result = (*env)->CallBooleanMethod( env, draw->jdraw, mid, result = (*env)->CallBooleanMethod( env, draw->jdraw, mid, jrect,
jrect, jtext, tile, jval, jtext, tile, value, owner, bonus,
owner, bonus, hintAtts, flags, draw->jTvType );
flags );
returnJRect( draw, JCACHE_RECT0, jrect ); returnJRect( draw, JCACHE_RECT0, jrect );
deleteLocalRefs( env, jtext, jval, DELETE_NO_REF ); deleteLocalRef( env, jtext );
DRAW_CBK_HEADER_END(); DRAW_CBK_HEADER_END();
return result; return result;
@ -576,6 +585,10 @@ and_draw_objFinished( DrawCtx* dctx, XWEnv xwe, BoardObjectType typ,
(*env)->CallVoidMethod( env, draw->jdraw, mid, (*env)->CallVoidMethod( env, draw->jdraw, mid,
(jint)typ, jrect ); (jint)typ, jrect );
returnJRect( draw, JCACHE_RECT0, jrect ); returnJRect( draw, JCACHE_RECT0, jrect );
if ( OBJ_BOARD == typ ) {
deleteGlobalRef( env, draw->jTvType );
}
DRAW_CBK_HEADER_END(); DRAW_CBK_HEADER_END();
#endif #endif
} }
@ -734,20 +747,23 @@ makeDraw( MPFORMAL JNIEnv* env,
return (DrawCtx*)draw; return (DrawCtx*)draw;
} }
static void
deleteGlobalRef( JNIEnv* env, jobject jobj )
{
if ( !!jobj ) {
(*env)->DeleteGlobalRef( env, jobj );
}
}
void void
destroyDraw( DrawCtx** dctx, JNIEnv* env ) destroyDraw( DrawCtx** dctx, JNIEnv* env )
{ {
if ( !!*dctx ) { if ( !!*dctx ) {
AndDraw* draw = (AndDraw*)*dctx; AndDraw* draw = (AndDraw*)*dctx;
if ( NULL != draw->jdraw ) { deleteGlobalRef( env, draw->jdraw );
(*env)->DeleteGlobalRef( env, draw->jdraw );
}
for ( int ii = 0; ii < JCACHE_COUNT; ++ii ) { for ( int ii = 0; ii < JCACHE_COUNT; ++ii ) {
jobject jobj = draw->jCache[ii]; deleteGlobalRef( env, draw->jCache[ii] );
if ( !!jobj ) {
(*env)->DeleteGlobalRef( env, jobj );
}
} }
XP_FREE( draw->mpool, draw->vtable ); XP_FREE( draw->mpool, draw->vtable );

View file

@ -598,6 +598,8 @@ loadCommonPrefs( JNIEnv* env, CommonPrefs* cp, jobject j_cp )
#ifdef XWFEATURE_CROSSHAIRS #ifdef XWFEATURE_CROSSHAIRS
cp->hideCrosshairs = getBool( env, j_cp, "hideCrosshairs" ); cp->hideCrosshairs = getBool( env, j_cp, "hideCrosshairs" );
#endif #endif
cp->tvType = jenumFieldToInt( env, j_cp, "tvType",
PKG_PATH("jni/CommonPrefs$TileValueType"));
} }
static XWStreamCtxt* static XWStreamCtxt*
@ -1834,17 +1836,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setBlankValue
return result; return result;
} }
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1toggle_1showValues
( JNIEnv* env, jclass C, GamePtrType gamePtr )
{
jboolean result;
XWJNI_START();
result = board_toggle_showValues( state->game.board );
XWJNI_END();
return result;
}
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1commitTurn Java_org_eehouse_android_xw4_jni_XwJNI_board_1commitTurn
( JNIEnv* env, jclass C, GamePtrType gamePtr, jboolean phoniesConfirmed, ( JNIEnv* env, jclass C, GamePtrType gamePtr, jboolean phoniesConfirmed,

View file

@ -231,7 +231,9 @@ board_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, ModelCtxt* model
board->isFlipped = (XP_Bool)stream_getBits( stream, 1 ); board->isFlipped = (XP_Bool)stream_getBits( stream, 1 );
board->gameOver = (XP_Bool)stream_getBits( stream, 1 ); board->gameOver = (XP_Bool)stream_getBits( stream, 1 );
board->showColors = (XP_Bool)stream_getBits( stream, 1 ); board->showColors = (XP_Bool)stream_getBits( stream, 1 );
board->showCellValues = (XP_Bool)stream_getBits( stream, 1 ); // board->showCellValues = (XP_Bool)
// FIX_NEXT_VERSION_CHANGE: remove this conditionally
(void)stream_getBits( stream, 1 ); /* REMOVE ME */
if ( version >= STREAM_VERS_KEYNAV ) { if ( version >= STREAM_VERS_KEYNAV ) {
board->focussed = (BoardObjectType)stream_getBits( stream, 2 ); board->focussed = (BoardObjectType)stream_getBits( stream, 2 );
@ -330,7 +332,8 @@ board_writeToStream( const BoardCtxt* board, XWStreamCtxt* stream )
stream_putBits( stream, 1, board->isFlipped ); stream_putBits( stream, 1, board->isFlipped );
stream_putBits( stream, 1, board->gameOver ); stream_putBits( stream, 1, board->gameOver );
stream_putBits( stream, 1, board->showColors ); stream_putBits( stream, 1, board->showColors );
stream_putBits( stream, 1, board->showCellValues ); // FIX_NEXT_VERSION_CHANGE: remove this
stream_putBits( stream, 1, 0 ); // board->showCellValues );
stream_putBits( stream, 2, board->focussed ); stream_putBits( stream, 2, board->focussed );
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
stream_putBits( stream, 1, board->focusHasDived ); stream_putBits( stream, 1, board->focusHasDived );
@ -684,13 +687,10 @@ board_getScale( BoardCtxt* board, XP_U16* hScale, XP_U16* vScale )
XP_Bool XP_Bool
board_prefsChanged( BoardCtxt* board, const CommonPrefs* cp ) board_prefsChanged( BoardCtxt* board, const CommonPrefs* cp )
{ {
XP_Bool showArrowChanged; XP_Bool showArrowChanged = cp->showBoardArrow == board->disableArrow;
XP_Bool hideValChanged; XP_Bool hideValChanged = cp->hideTileValues != board->hideValsInTray;
XP_Bool showColorsChanged; XP_Bool showColorsChanged = board->showColors != cp->showColors;
XP_Bool showValsChanged = board->tvType != cp->tvType;
showArrowChanged = cp->showBoardArrow == board->disableArrow;
hideValChanged = cp->hideTileValues != board->hideValsInTray;
showColorsChanged = board->showColors != cp->showColors;
board->disableArrow = !cp->showBoardArrow; board->disableArrow = !cp->showBoardArrow;
board->hideValsInTray = cp->hideTileValues; board->hideValsInTray = cp->hideTileValues;
@ -700,6 +700,7 @@ board_prefsChanged( BoardCtxt* board, const CommonPrefs* cp )
#ifdef XWFEATURE_CROSSHAIRS #ifdef XWFEATURE_CROSSHAIRS
board->hideCrosshairs = cp->hideCrosshairs; board->hideCrosshairs = cp->hideCrosshairs;
#endif #endif
board->tvType = cp->tvType;
if ( showArrowChanged ) { if ( showArrowChanged ) {
showArrowChanged = setArrowVisible( board, XP_FALSE ); showArrowChanged = setArrowVisible( board, XP_FALSE );
@ -707,7 +708,7 @@ board_prefsChanged( BoardCtxt* board, const CommonPrefs* cp )
if ( hideValChanged ) { if ( hideValChanged ) {
board_invalTrayTiles( board, ALLTILES ); board_invalTrayTiles( board, ALLTILES );
} }
if ( showColorsChanged ) { if ( showColorsChanged || showValsChanged ) {
board->scoreBoardInvalid = XP_TRUE; board->scoreBoardInvalid = XP_TRUE;
showColorsChanged = invalCellsWithTiles( board ); showColorsChanged = invalCellsWithTiles( board );
} }
@ -2059,23 +2060,6 @@ board_inTrade( const BoardCtxt* board, XP_Bool* anySelected )
return pti->tradeInProgress; return pti->tradeInProgress;
} }
XP_Bool
board_toggle_showValues( BoardCtxt* board )
{
XP_Bool changed;
board->showCellValues = !board->showCellValues;
/* We show the tile values when showCellValues is set even if
hideValsInTray is set. So inval the tray if there will be a change.
And set changed to true in case there are no tiles on the baord yet.
*/
changed = board->hideValsInTray && (board->trayVisState == TRAY_REVEALED);
if ( changed ) {
board_invalTrayTiles( board, ALLTILES );
}
return invalCellsWithTiles( board ) || changed;
} /* board_toggle_showValues */
XP_Bool XP_Bool
board_replaceNTiles( BoardCtxt* board, XWEnv xwe, XP_U16 nTiles ) board_replaceNTiles( BoardCtxt* board, XWEnv xwe, XP_U16 nTiles )
{ {

View file

@ -148,7 +148,6 @@ XP_Bool board_draw( BoardCtxt* board, XWEnv xwe );
XP_Bool board_get_flipped( const BoardCtxt* board ); XP_Bool board_get_flipped( const BoardCtxt* board );
XP_Bool board_flip( BoardCtxt* board ); XP_Bool board_flip( BoardCtxt* board );
XP_Bool board_inTrade( const BoardCtxt* board, XP_Bool* anySelected ); XP_Bool board_inTrade( const BoardCtxt* board, XP_Bool* anySelected );
XP_Bool board_toggle_showValues( BoardCtxt* board );
XP_Bool board_replaceTiles( BoardCtxt* board, XWEnv xwe ); XP_Bool board_replaceTiles( BoardCtxt* board, XWEnv xwe );
XP_Bool board_redoReplacedTiles( BoardCtxt* board, XWEnv xwe ); XP_Bool board_redoReplacedTiles( BoardCtxt* board, XWEnv xwe );

View file

@ -269,7 +269,7 @@ drawBoard( BoardCtxt* board, XWEnv xwe )
&& draw_boardBegin( board->draw, xwe, &board->boardBounds, && draw_boardBegin( board->draw, xwe, &board->boardBounds,
board->sd[SCROLL_H].scale, board->sd[SCROLL_H].scale,
board->sd[SCROLL_V].scale, board->sd[SCROLL_V].scale,
dfsFor( board, OBJ_BOARD ) ) ) { dfsFor( board, OBJ_BOARD ), board->tvType ) ) {
XP_Bool allDrawn = XP_TRUE; XP_Bool allDrawn = XP_TRUE;
XP_S16 ii; XP_S16 ii;
@ -404,8 +404,7 @@ drawCell( BoardCtxt* board, XWEnv xwe, const XP_U16 col,
HintAtts hintAtts; HintAtts hintAtts;
CellFlags flags = CELL_NONE; CellFlags flags = CELL_NONE;
XP_Bool isOrigin; XP_Bool isOrigin;
XP_UCHAR valBuf[4]; XP_U16 value = 0;
XP_UCHAR* value = NULL;
isEmpty = !model_getTile( model, modelCol, modelRow, showPending, isEmpty = !model_getTile( model, modelCol, modelRow, showPending,
selPlayer, &tile, &isBlank, selPlayer, &tile, &isBlank,
@ -426,17 +425,13 @@ drawCell( BoardCtxt* board, XWEnv xwe, const XP_U16 col,
break; break;
} else { } else {
Tile valTile = isBlank? dict_getBlankTile( dict ) : tile; Tile valTile = isBlank? dict_getBlankTile( dict ) : tile;
XP_U16 val = dict_getTileValue( dict, valTile ); value = dict_getTileValue( dict, valTile );
if ( board->showColors ) { if ( board->showColors ) {
owner = (XP_S16)model_getCellOwner( model, modelCol, owner = (XP_S16)model_getCellOwner( model, modelCol,
modelRow ); modelRow );
} }
if ( board->showCellValues ) {
XP_SNPRINTF( valBuf, VSIZE(valBuf), "%d", val );
value = valBuf;
}
if ( dict_faceIsBitmap( dict, tile ) ) { if ( dict_faceIsBitmap( dict, tile ) ) {
dict_getFaceBitmaps( dict, tile, &bitmaps ); dict_getFaceBitmaps( dict, tile, &bitmaps );
bptr = &bitmaps; bptr = &bitmaps;
@ -550,7 +545,7 @@ drawDragTileIf( BoardCtxt* board, XWEnv xwe )
if ( isBlank ) { if ( isBlank ) {
flags |= CELL_ISBLANK; flags |= CELL_ISBLANK;
} }
if ( board->hideValsInTray && !board->showCellValues ) { if ( board->hideValsInTray ) {
flags |= CELL_VALHIDDEN; flags |= CELL_VALHIDDEN;
} }
draw_drawTileMidDrag( board->draw, xwe, &rect, face, draw_drawTileMidDrag( board->draw, xwe, &rect, face,

View file

@ -177,6 +177,7 @@ struct BoardCtxt {
#ifdef XWFEATURE_CROSSHAIRS #ifdef XWFEATURE_CROSSHAIRS
XP_Bool hideCrosshairs; XP_Bool hideCrosshairs;
#endif #endif
TileValueType tvType;
XP_Bool eraseTray; XP_Bool eraseTray;
XP_Bool boardObscuresTray; XP_Bool boardObscuresTray;
@ -228,7 +229,7 @@ struct BoardCtxt {
XW_TrayVisState trayVisState; XW_TrayVisState trayVisState;
XP_Bool penTimerFired; XP_Bool penTimerFired;
XP_Bool showCellValues; XP_Bool unused_showCellValues;
XP_Bool showColors; XP_Bool showColors;
MPSLOT MPSLOT

View file

@ -216,6 +216,14 @@ typedef enum {
BONUS_LAST BONUS_LAST
} XWBonusType; } XWBonusType;
typedef enum _TileValueType {
TVT_BOTH,
TVT_FACES,
TVT_VALUES,
TVT_N_ENTRIES,
} TileValueType;
/* For now, let's define keys here. Old method based on __FILE__ was /* For now, let's define keys here. Old method based on __FILE__ was
* stupid. Can be more clever later -- as long as these don't change again * stupid. Can be more clever later -- as long as these don't change again
*/ */
@ -262,6 +270,7 @@ typedef struct CommonPrefs {
#ifdef XWFEATURE_ROBOTPHONIES #ifdef XWFEATURE_ROBOTPHONIES
XP_U16 makePhonyPct; XP_U16 makePhonyPct;
#endif #endif
TileValueType tvType;
} CommonPrefs; } CommonPrefs;
typedef struct _PlayerDicts { typedef struct _PlayerDicts {

View file

@ -123,7 +123,7 @@ typedef struct DrawCtxVTable {
XP_Bool DRAW_VTABLE_NAME(boardBegin) ( DrawCtx* dctx, XWEnv xwe, XP_Bool DRAW_VTABLE_NAME(boardBegin) ( DrawCtx* dctx, XWEnv xwe,
const XP_Rect* rect, const XP_Rect* rect,
XP_U16 hScale, XP_U16 vScale, XP_U16 hScale, XP_U16 vScale,
DrawFocusState dfs ); DrawFocusState dfs, TileValueType tvType );
void DRAW_VTABLE_NAME(objFinished)( DrawCtx* dctx, XWEnv xwe, BoardObjectType typ, void DRAW_VTABLE_NAME(objFinished)( DrawCtx* dctx, XWEnv xwe, BoardObjectType typ,
const XP_Rect* rect, const XP_Rect* rect,
DrawFocusState dfs ); DrawFocusState dfs );
@ -179,7 +179,7 @@ typedef struct DrawCtxVTable {
XP_Bool DRAW_VTABLE_NAME(drawCell) ( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect, XP_Bool DRAW_VTABLE_NAME(drawCell) ( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect,
/* at least one of these two will be null */ /* at least one of these two will be null */
const XP_UCHAR* text, const XP_Bitmaps* bitmaps, const XP_UCHAR* text, const XP_Bitmaps* bitmaps,
Tile tile, const XP_UCHAR* value, /* null if hidden */ Tile tile, XP_U16 value,
XP_S16 owner, /* -1 means don't use */ XP_S16 owner, /* -1 means don't use */
XWBonusType bonus, HintAtts hintAtts, XWBonusType bonus, HintAtts hintAtts,
CellFlags flags ); CellFlags flags );
@ -279,8 +279,8 @@ struct DrawCtx {
#define draw_dictChanged( dc, e, n, d ) CALL_DRAW_NAME2(dictChanged, (dc),(e),(n),(d)) #define draw_dictChanged( dc, e, n, d ) CALL_DRAW_NAME2(dictChanged, (dc),(e),(n),(d))
#define draw_beginDraw( dc,e ) CALL_DRAW_NAME0(beginDraw, (dc), (e)) #define draw_beginDraw( dc,e ) CALL_DRAW_NAME0(beginDraw, (dc), (e))
#define draw_endDraw( dc,e ) CALL_DRAW_NAME0(endDraw, (dc), (e)) #define draw_endDraw( dc,e ) CALL_DRAW_NAME0(endDraw, (dc), (e))
#define draw_boardBegin( dc,e,r,h,v,f ) CALL_DRAW_NAME4(boardBegin, (dc), (e), \ #define draw_boardBegin( dc,e,r,h,v,f,tvt ) CALL_DRAW_NAME5(boardBegin, (dc), (e), \
(r),(h),(v),(f)) (r),(h),(v),(f), (tvt))
#define draw_objFinished( dc, e, t, r, d ) \ #define draw_objFinished( dc, e, t, r, d ) \
CALL_DRAW_NAME3(objFinished, (dc),(e), (t), (r), (d)) CALL_DRAW_NAME3(objFinished, (dc),(e), (t), (r), (d))
#define draw_trayBegin( dc, e, r, o, s, f ) \ #define draw_trayBegin( dc, e, r, o, s, f ) \

View file

@ -172,7 +172,7 @@ drawTray( BoardCtxt* board, XWEnv xwe )
XP_U16 numInTray = countTilesToShow( board ); XP_U16 numInTray = countTilesToShow( board );
XP_Bool isBlank; XP_Bool isBlank;
XP_Bool isADrag = dragDropInProgress( board ); XP_Bool isADrag = dragDropInProgress( board );
CellFlags baseFlags = board->hideValsInTray && !board->showCellValues CellFlags baseFlags = board->hideValsInTray
? CELL_VALHIDDEN : CELL_NONE; ? CELL_VALHIDDEN : CELL_NONE;
dragDropGetTrayChanges( board, &ddRmvdIndx, &ddAddedIndx ); dragDropGetTrayChanges( board, &ddRmvdIndx, &ddAddedIndx );

View file

@ -1180,13 +1180,9 @@ handleFlip( void* closure, int XP_UNUSED(key) )
} /* handleFlip */ } /* handleFlip */
static bool static bool
handleToggleValues( void* closure, int XP_UNUSED(key) ) handleToggleValues( void* XP_UNUSED(closure), int XP_UNUSED(key) )
{ {
CursesBoardGlobals* bGlobals = (CursesBoardGlobals*)closure; XP_ASSERT( 0 );
CommonGlobals* cGlobals = &bGlobals->cGlobals;
if ( board_toggle_showValues( cGlobals->game.board ) ) {
board_draw( cGlobals->game.board, NULL_XWE );
}
return XP_TRUE; return XP_TRUE;
} /* handleToggleValues */ } /* handleToggleValues */

View file

@ -95,7 +95,8 @@ static XP_Bool
curses_draw_boardBegin( DrawCtx* XP_UNUSED(p_dctx), XWEnv XP_UNUSED(xwe), curses_draw_boardBegin( DrawCtx* XP_UNUSED(p_dctx), XWEnv XP_UNUSED(xwe),
const XP_Rect* XP_UNUSED(rect), const XP_Rect* XP_UNUSED(rect),
XP_U16 XP_UNUSED(width), XP_U16 XP_UNUSED(height), XP_U16 XP_UNUSED(width), XP_U16 XP_UNUSED(height),
DrawFocusState XP_UNUSED(dfs) ) DrawFocusState XP_UNUSED(dfs),
TileValueType XP_UNUSED(tvType) )
{ {
return XP_TRUE; return XP_TRUE;
} /* curses_draw_boardBegin */ } /* curses_draw_boardBegin */
@ -392,7 +393,7 @@ static XP_Bool
curses_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect, curses_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect,
const XP_UCHAR* letter, const XP_UCHAR* letter,
const XP_Bitmaps* XP_UNUSED(bitmaps), const XP_Bitmaps* XP_UNUSED(bitmaps),
Tile XP_UNUSED(tile), const XP_UCHAR* XP_UNUSED(value), Tile XP_UNUSED(tile), const XP_U16 XP_UNUSED(value),
XP_S16 XP_UNUSED(owner), XWBonusType bonus, XP_S16 XP_UNUSED(owner), XWBonusType bonus,
HintAtts XP_UNUSED(hintAtts), CellFlags flags ) HintAtts XP_UNUSED(hintAtts), CellFlags flags )
{ {

View file

@ -1221,9 +1221,10 @@ static gboolean
handle_value_button( GtkWidget* XP_UNUSED(widget), gpointer closure ) handle_value_button( GtkWidget* XP_UNUSED(widget), gpointer closure )
{ {
GtkGameGlobals* globals = (GtkGameGlobals*)closure; GtkGameGlobals* globals = (GtkGameGlobals*)closure;
if ( board_toggle_showValues( globals->cGlobals.game.board ) ) { CommonGlobals* cGlobals = &globals->cGlobals;
board_draw( globals->cGlobals.game.board, NULL_XWE ); cGlobals->cp.tvType = (cGlobals->cp.tvType + 1) % TVT_N_ENTRIES;
} board_prefsChanged( cGlobals->game.board, &cGlobals->cp );
board_draw( cGlobals->game.board, NULL_XWE );
return TRUE; return TRUE;
} /* handle_value_button */ } /* handle_value_button */

View file

@ -77,7 +77,7 @@ typedef struct GtkDrawCtx {
XP_U16 trayOwner; XP_U16 trayOwner;
XP_U16 cellWidth; XP_U16 cellWidth;
XP_U16 cellHeight; XP_U16 cellHeight;
TileValueType tvType;
XP_Bool scoreIsVertical; XP_Bool scoreIsVertical;
} GtkDrawCtx; } GtkDrawCtx;

View file

@ -490,12 +490,13 @@ gtk_draw_endDraw( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe) )
static XP_Bool static XP_Bool
gtk_draw_boardBegin( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect, gtk_draw_boardBegin( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect,
XP_U16 width, XP_U16 height, XP_U16 width, XP_U16 height,
DrawFocusState XP_UNUSED(dfs) ) DrawFocusState XP_UNUSED(dfs), TileValueType tvType )
{ {
GdkRectangle gdkrect; GdkRectangle gdkrect;
GtkDrawCtx* dctx = (GtkDrawCtx*)(void*)p_dctx; GtkDrawCtx* dctx = (GtkDrawCtx*)(void*)p_dctx;
dctx->cellWidth = width; dctx->cellWidth = width;
dctx->cellHeight = height; dctx->cellHeight = height;
dctx->tvType = tvType;
gtkSetForeground( dctx, &dctx->black ); gtkSetForeground( dctx, &dctx->black );
@ -610,7 +611,7 @@ static XP_Bool
gtk_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect, gtk_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect,
const XP_UCHAR* letter, const XP_UCHAR* letter,
const XP_Bitmaps* bitmaps, Tile XP_UNUSED(tile), const XP_Bitmaps* bitmaps, Tile XP_UNUSED(tile),
const XP_UCHAR* value, XP_S16 owner, XWBonusType bonus, const XP_U16 tileValue, XP_S16 owner, XWBonusType bonus,
HintAtts hintAtts, CellFlags flags ) HintAtts hintAtts, CellFlags flags )
{ {
GtkDrawCtx* dctx = (GtkDrawCtx*)(void*)p_dctx; GtkDrawCtx* dctx = (GtkDrawCtx*)(void*)p_dctx;
@ -623,6 +624,10 @@ gtk_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect,
((flags & CELL_ISCURSOR) != 0) ? &dctx->cursor : NULL; ((flags & CELL_ISCURSOR) != 0) ? &dctx->cursor : NULL;
GdkRGBA* foreground = &dctx->white; GdkRGBA* foreground = &dctx->white;
XP_UCHAR valBuf[4];
XP_SNPRINTF( valBuf, sizeof(valBuf), "%d", tileValue );
const XP_UCHAR* value = valBuf;
gtkEraseRect( dctx, rect ); gtkEraseRect( dctx, rect );
gtkInsetRect( &rectInset, 1 ); gtkInsetRect( &rectInset, 1 );
@ -669,6 +674,7 @@ gtk_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect,
XP_GTK_JUST_CENTER, &dctx->black, NULL ); XP_GTK_JUST_CENTER, &dctx->black, NULL );
} }
} else if ( !!bitmaps && !!bitmaps->bmps[0] ) { } else if ( !!bitmaps && !!bitmaps->bmps[0] ) {
XP_ASSERT(0); /* we don't handle this now */
XP_Rect tmpRect = *rect; XP_Rect tmpRect = *rect;
if ( !!value ) { if ( !!value ) {
tmpRect.width = tmpRect.width * 3 / 4; tmpRect.width = tmpRect.width * 3 / 4;
@ -676,6 +682,14 @@ gtk_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect,
} }
drawBitmapFromLBS( dctx, bitmaps->bmps[0], &tmpRect ); drawBitmapFromLBS( dctx, bitmaps->bmps[0], &tmpRect );
} else if ( !!letter ) { } else if ( !!letter ) {
TileValueType useTyp = dctx->tvType;
if ( TVT_VALUES == useTyp ) {
letter = value;
useTyp = TVT_FACES;
}
if ( TVT_FACES == useTyp ) {
value = NULL;
}
XP_Bool isBlank = (flags & CELL_ISBLANK) != 0; XP_Bool isBlank = (flags & CELL_ISBLANK) != 0;
if ( cursor ) { if ( cursor ) {
gtkSetForeground( dctx, cursor ); gtkSetForeground( dctx, cursor );
@ -722,12 +736,13 @@ gtk_draw_drawCell( DrawCtx* p_dctx, XWEnv XP_UNUSED(xwe), const XP_Rect* rect,
} }
if ( !!value ) { if ( !!value ) {
const int fraction = 3;
XP_Rect tmpRect = *rect; XP_Rect tmpRect = *rect;
tmpRect.left += tmpRect.width * 3 / 4; tmpRect.left += tmpRect.width * (fraction-1) / fraction;
tmpRect.width /= 4; tmpRect.width /= fraction;
tmpRect.top += tmpRect.height * 3 / 4; tmpRect.top += tmpRect.height * (fraction-1) / fraction;
tmpRect.height /= 4; tmpRect.height /= fraction;
draw_string_at( dctx, NULL, value, dctx->cellHeight/4, &tmpRect, draw_string_at( dctx, NULL, value, dctx->cellHeight/fraction, &tmpRect,
XP_GTK_JUST_CENTER, foreground, cursor ); XP_GTK_JUST_CENTER, foreground, cursor );
} }