add alert to name or cancel rematch

This commit is contained in:
Eric House 2023-03-01 19:39:40 -08:00
parent e5d4ecea7d
commit 9533fbd0d9

View file

@ -512,28 +512,29 @@ handleInvite( GameState* gs )
} }
static void static void
handleRematch( GameState* curGS ) onRematchOkd( void* closure, const char* msg )
{ {
LOG_FUNC(); if ( !!msg && msg[0] ) { /* cancel button gives null */
Globals* globals = curGS->globals; GameState* curGS = (GameState*)closure;
GameState* newGS = newGameState( globals ); Globals* globals = curGS->globals;
newGS->util = wasm_util_make( MPPARM(globals->mpool) &newGS->gi, GameState* newGS = newGameState( globals );
globals->dutil, newGS ); newGS->util = wasm_util_make( MPPARM(globals->mpool) &newGS->gi,
globals->dutil, newGS );
if ( game_makeRematch( &curGS->game, NULL_XWE, newGS->util, if ( game_makeRematch( &curGS->game, NULL_XWE, newGS->util,
&globals->cp, (TransportProcs*)NULL, &globals->cp, (TransportProcs*)NULL,
&newGS->game, "newName" ) ) { &newGS->game, msg ) ) {
int gameID = newGS->gi.gameID; int gameID = newGS->gi.gameID;
saveGame( newGS ); saveGame( newGS );
removeGameState( newGS ); /* force reload with drawCtxt etc. */ removeGameState( newGS ); /* force reload with drawCtxt etc. */
loadAndDraw( globals, (NetLaunchInfo*)NULL, gameID, (NewGameParams*)NULL ); loadAndDraw( globals, (NetLaunchInfo*)NULL, gameID, (NewGameParams*)NULL );
} else { } else {
XP_LOGFF( "failed" ); XP_LOGFF( "failed" );
cleanupGame( newGS ); cleanupGame( newGS );
}
} }
LOG_RETURN_VOID();
} }
static void static void
@ -545,6 +546,21 @@ onChatComposed( void* closure, const char* msg )
} }
} }
static void
formatNames( GameState* gs, char buf[] )
{
const CurGameInfo* gi = &gs->gi;
buf[0] = '\0';
for ( int ii = 0; ii < gi->nPlayers; ++ii ) {
const LocalPlayer* lp = &gi->players[ii];
const XP_UCHAR* name = lp->name;
if ( 0 < ii ) {
strcat( buf, " vs. " );
}
strcat( buf, name );
}
}
static void static void
onGameButton( void* closure, const char* button ) onGameButton( void* closure, const char* button )
{ {
@ -584,7 +600,9 @@ onGameButton( void* closure, const char* button )
} else if ( 0 == strcmp(button, BUTTON_INVITE) ) { } else if ( 0 == strcmp(button, BUTTON_INVITE) ) {
handleInvite(gs); handleInvite(gs);
} else if ( 0 == strcmp(button, BUTTON_REMATCH) ) { } else if ( 0 == strcmp(button, BUTTON_REMATCH) ) {
handleRematch(gs); char buf[128];
formatNames( gs, buf );
call_get_string( "Rematch game name?", buf, onRematchOkd, gs );
} }
if ( draw ) { if ( draw ) {