mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
get trade working
This commit is contained in:
parent
bf5db08357
commit
02a193902f
4 changed files with 48 additions and 21 deletions
|
@ -79,6 +79,12 @@ EM_JS(void, jscallback_set, (JSCallback proc, void* closure, int inMS), {
|
||||||
setTimeout( timerproc, inMS, closure );
|
setTimeout( timerproc, inMS, closure );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EM_JS(void, setButtonText, (const char* id, const char* text), {
|
||||||
|
let jsid = UTF8ToString(id);
|
||||||
|
let jstext = UTF8ToString(text);
|
||||||
|
document.getElementById(jsid).textContent = jstext;
|
||||||
|
});
|
||||||
|
|
||||||
static void updateScreen( Globals* globals, bool doSave );
|
static void updateScreen( Globals* globals, bool doSave );
|
||||||
|
|
||||||
static XP_S16
|
static XP_S16
|
||||||
|
@ -115,6 +121,14 @@ send_msg( XWEnv xwe, const XP_U8* buf, XP_U16 len,
|
||||||
return nSent;
|
return nSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
updateTradeButton( Globals* globals )
|
||||||
|
{
|
||||||
|
XP_Bool inTrade = board_inTrade( globals->game.board, NULL );
|
||||||
|
const char* text = inTrade ? "Cancel trade" : "Trade";
|
||||||
|
setButtonText( "trade", text );
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initDeviceGlobals( Globals* globals )
|
initDeviceGlobals( Globals* globals )
|
||||||
{
|
{
|
||||||
|
@ -242,6 +256,7 @@ loadSavedGame( Globals* globals )
|
||||||
if ( loaded ) {
|
if ( loaded ) {
|
||||||
updateScreen( globals, false );
|
updateScreen( globals, false );
|
||||||
}
|
}
|
||||||
|
updateTradeButton( globals );
|
||||||
}
|
}
|
||||||
stream_destroy( stream, NULL );
|
stream_destroy( stream, NULL );
|
||||||
return loaded;
|
return loaded;
|
||||||
|
@ -412,6 +427,7 @@ main_query( Globals* globals, const XP_UCHAR* query, QueryProc proc, void* closu
|
||||||
{
|
{
|
||||||
bool ok = call_confirm( query );
|
bool ok = call_confirm( query );
|
||||||
(*proc)( closure, ok );
|
(*proc)( closure, ok );
|
||||||
|
updateTradeButton( globals );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -526,8 +542,10 @@ button( void* closure, const char* msg )
|
||||||
} else if ( 0 == strcmp(msg, "hintup") ) {
|
} else if ( 0 == strcmp(msg, "hintup") ) {
|
||||||
draw = board_requestHint( board, NULL, XP_FALSE, &redo );
|
draw = board_requestHint( board, NULL, XP_FALSE, &redo );
|
||||||
} else if ( 0 == strcmp(msg, "trade") ) {
|
} else if ( 0 == strcmp(msg, "trade") ) {
|
||||||
// draw = board_beginTrade( board, NULL );
|
draw = board_inTrade( board, NULL )
|
||||||
call_alert("not implemented");
|
? board_endTrade( board )
|
||||||
|
: board_beginTrade( board, NULL );
|
||||||
|
updateTradeButton( globals );
|
||||||
} else if ( 0 == strcmp(msg, "commit") ) {
|
} else if ( 0 == strcmp(msg, "commit") ) {
|
||||||
draw = board_commitTurn( board, NULL, XP_FALSE, XP_FALSE, NULL );
|
draw = board_commitTurn( board, NULL, XP_FALSE, XP_FALSE, NULL );
|
||||||
} else if ( 0 == strcmp(msg, "flip") ) {
|
} else if ( 0 == strcmp(msg, "flip") ) {
|
||||||
|
|
|
@ -58,13 +58,13 @@
|
||||||
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
|
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button onclick="callButton('hintdown');">Prev Hint</button>
|
<button id="hintdown", onclick="callButton(this);">Prev Hint</button>
|
||||||
<button onclick="callButton('hintup');">Next Hint</button>
|
<button id="hintup", onclick="callButton(this);">Next Hint</button>
|
||||||
<button onclick="callButton('trade');">Trade</button>
|
<button id="trade", onclick="callButton(this);">Trade</button>
|
||||||
<button onclick="callButton('commit');">Commit</button>
|
<button id="commit", onclick="callButton(this);">Commit</button>
|
||||||
<button onclick="callButton('flip');">Flip</button>
|
<button id="flip", onclick="callButton(this);">Flip</button>
|
||||||
<button onclick="callButton('redo');">Un/Redo</button>
|
<button id="redo", onclick="callButton(this);">Un/Redo</button>
|
||||||
<button onclick="callButton('vals');">Vals</button>
|
<button id="vals", onclick="callButton(this);">Vals</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span>Player 1</span>
|
<span>Player 1</span>
|
||||||
|
@ -74,10 +74,6 @@
|
||||||
<span>Player 2</span>
|
<span>Player 2</span>
|
||||||
<input type="checkbox" id="player1Checked">Is Robot</input>
|
<input type="checkbox" id="player1Checked">Is Robot</input>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<span>Local player name:</span>
|
|
||||||
<input type="textarea" id="playerName">Player 1</input>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<button type="button" onclick="callNewGame();">New Local Game</button>
|
<button type="button" onclick="callNewGame();">New Local Game</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -193,8 +189,8 @@
|
||||||
Module.ccall('newgame', null, ['number', 'boolean', 'boolean'], args);
|
Module.ccall('newgame', null, ['number', 'boolean', 'boolean'], args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function callButton(name) {
|
function callButton(obj) {
|
||||||
Module.ccall('button', null, ['number', 'string'], [state.closure, name]);
|
Module.ccall('button', null, ['number', 'string'], [state.closure, obj.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onHaveDevID(closure, devid) {
|
function onHaveDevID(closure, devid) {
|
||||||
|
|
|
@ -176,7 +176,7 @@ imgInRect( WasmDrawCtx* wdctx, SDL_Surface* img, const XP_Rect* rect )
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawTile( WasmDrawCtx* wdctx, const XP_UCHAR* face, int val,
|
drawTile( WasmDrawCtx* wdctx, const XP_UCHAR* face, int val,
|
||||||
int owner, const XP_Rect* rect )
|
int owner, const XP_Rect* rect, CellFlags flags )
|
||||||
{
|
{
|
||||||
clearRect( wdctx, rect );
|
clearRect( wdctx, rect );
|
||||||
frameRect( wdctx, rect );
|
frameRect( wdctx, rect );
|
||||||
|
@ -196,6 +196,14 @@ drawTile( WasmDrawCtx* wdctx, const XP_UCHAR* face, int val,
|
||||||
XP_SNPRINTF( buf, VSIZE(buf), "%d", val );
|
XP_SNPRINTF( buf, VSIZE(buf), "%d", val );
|
||||||
textInRect( wdctx, buf, &tmp, &sPlayerColors[owner] );
|
textInRect( wdctx, buf, &tmp, &sPlayerColors[owner] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( 0 != (flags & (CELL_PENDING|CELL_RECENT)) ) {
|
||||||
|
XP_Rect tmp = *rect;
|
||||||
|
for ( int ii = 0; ii < 3; ++ii ) {
|
||||||
|
insetRect( &tmp, 1, 1 );
|
||||||
|
frameRect( wdctx, &tmp );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -463,7 +471,7 @@ wasm_draw_drawTile( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect,
|
||||||
XP_U16 val, CellFlags flags )
|
XP_U16 val, CellFlags flags )
|
||||||
{
|
{
|
||||||
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
||||||
drawTile( wdctx, text, val, wdctx->trayOwner, rect );
|
drawTile( wdctx, text, val, wdctx->trayOwner, rect, flags );
|
||||||
return XP_TRUE;
|
return XP_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,7 +487,7 @@ wasm_draw_drawTileMidDrag( DrawCtx* dctx, XWEnv xwe,
|
||||||
CellFlags flags )
|
CellFlags flags )
|
||||||
{
|
{
|
||||||
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
||||||
drawTile( wdctx, text, val, wdctx->trayOwner, rect );
|
drawTile( wdctx, text, val, wdctx->trayOwner, rect, flags );
|
||||||
return XP_TRUE;
|
return XP_TRUE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -489,7 +497,7 @@ wasm_draw_drawTileBack( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect,
|
||||||
CellFlags flags )
|
CellFlags flags )
|
||||||
{
|
{
|
||||||
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
||||||
drawTile( wdctx, "?", -1, wdctx->trayOwner, rect );
|
drawTile( wdctx, "?", -1, wdctx->trayOwner, rect, flags );
|
||||||
return XP_TRUE;
|
return XP_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,12 @@ static void
|
||||||
wasm_util_notifyTrade( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR** tiles,
|
wasm_util_notifyTrade( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR** tiles,
|
||||||
XP_U16 nTiles )
|
XP_U16 nTiles )
|
||||||
{
|
{
|
||||||
LOG_FUNC();
|
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
|
||||||
|
Globals* globals = (Globals*)wuctxt->closure;
|
||||||
|
XP_UCHAR buf[128];
|
||||||
|
XP_SNPRINTF( buf, sizeof(buf),
|
||||||
|
"Are you sure you want to trade the %d selected tiles?", nTiles );
|
||||||
|
main_query( globals, buf, query_proc_notifyMove, uc );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -519,7 +524,7 @@ wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dctxt, void* closure )
|
||||||
|
|
||||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyMove, wasm );
|
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyMove, wasm );
|
||||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyTrade, wasm );
|
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyTrade, wasm );
|
||||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyPickTileBlank, wasm );
|
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyPickTileBlank, wasm );
|
||||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_informNeedPickTiles, wasm );
|
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_informNeedPickTiles, wasm );
|
||||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_informNeedPassword, wasm );
|
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_informNeedPassword, wasm );
|
||||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_trayHiddenChange, wasm );
|
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_trayHiddenChange, wasm );
|
||||||
|
|
Loading…
Reference in a new issue