mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
show an cannot-play-yet alert on guest side too
This commit is contained in:
parent
4314a3f012
commit
00588f50f3
4 changed files with 91 additions and 45 deletions
|
@ -167,6 +167,7 @@ public class BoardDelegate extends DelegateBase
|
|||
String getDict;
|
||||
int nMissing = -1;
|
||||
int nGuestDevs;
|
||||
boolean isServer;
|
||||
boolean inTrade;
|
||||
StartAlertOrder mAlertOrder = StartAlertOrder.values()[0];
|
||||
}
|
||||
|
@ -1985,16 +1986,15 @@ public class BoardDelegate extends DelegateBase
|
|||
// isServer, nDevs, nMissing );
|
||||
m_mySIS.nMissing = nMissing; // will be 0 unless isServer is true
|
||||
m_mySIS.nGuestDevs = nDevs;
|
||||
m_mySIS.isServer = isServer;
|
||||
m_connTypes = connTypes;
|
||||
|
||||
if ( isServer ) {
|
||||
runOnUiThread( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showInviteAlertIf();
|
||||
}
|
||||
} );
|
||||
}
|
||||
runOnUiThread( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showInviteAlertIf();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2463,7 +2463,7 @@ public class BoardDelegate extends DelegateBase
|
|||
if ( null == mINAWrapper ) {
|
||||
mINAWrapper = new InvitesNeededAlert.Wrapper( this );
|
||||
}
|
||||
mINAWrapper.showOrHide( m_mySIS.nMissing, isRematch );
|
||||
mINAWrapper.showOrHide( m_mySIS.isServer, m_mySIS.nMissing, isRematch );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class InvitesNeededAlert {
|
|||
|
||||
Wrapper( Callbacks callbacks ) { mCallbacks = callbacks; }
|
||||
|
||||
void showOrHide( int nPlayersMissing, boolean isRematch )
|
||||
void showOrHide( boolean isServer, int nPlayersMissing, boolean isRematch )
|
||||
{
|
||||
DbgUtils.assertOnUIThread();
|
||||
Log.d( TAG, "showOnceIf(nPlayersMissing=%d); self: %s", nPlayersMissing, mSelf );
|
||||
|
@ -54,12 +54,12 @@ class InvitesNeededAlert {
|
|||
if ( null == mSelf && 0 == nPlayersMissing ) {
|
||||
// cool: need and have nothing, so do nothing
|
||||
} else if ( 0 < nPlayersMissing && null == mSelf ) { // Need but don't have
|
||||
makeNew( nPlayersMissing, isRematch );
|
||||
makeNew( isServer, nPlayersMissing, isRematch );
|
||||
} else if ( 0 == nPlayersMissing && null != mSelf ) { // Have and need to close
|
||||
mSelf.close();
|
||||
} else if ( null != mSelf && nPlayersMissing != mSelf.mState.mNPlayersMissing ) {
|
||||
mSelf.close();
|
||||
makeNew( nPlayersMissing, isRematch );
|
||||
makeNew( isServer, nPlayersMissing, isRematch );
|
||||
} else if ( null != mSelf && nPlayersMissing == mSelf.mState.mNPlayersMissing ) {
|
||||
// nothing to do
|
||||
} else {
|
||||
|
@ -83,10 +83,10 @@ class InvitesNeededAlert {
|
|||
}
|
||||
}
|
||||
|
||||
private void makeNew( int nPlayersMissing, boolean isRematch )
|
||||
private void makeNew( boolean isServer, int nPlayersMissing, boolean isRematch )
|
||||
{
|
||||
Log.d( TAG, "makeNew(nPlayersMissing=%d)", nPlayersMissing );
|
||||
State state = new State( nPlayersMissing, isRematch );
|
||||
State state = new State( isServer, nPlayersMissing, isRematch );
|
||||
mSelf = new InvitesNeededAlert( mCallbacks.getDelegate(), state );
|
||||
mCallbacks.getDelegate().showDialogFragment( DlgID.DLG_INVITE, state );
|
||||
}
|
||||
|
@ -97,11 +97,13 @@ class InvitesNeededAlert {
|
|||
private static class State implements Serializable {
|
||||
private int mNPlayersMissing;
|
||||
private boolean mIsRematch;
|
||||
private boolean mIsServer;
|
||||
|
||||
State( int nPlayers, boolean rematch )
|
||||
State( boolean isServer, int nPlayers, boolean rematch )
|
||||
{
|
||||
mNPlayersMissing = nPlayers;
|
||||
mIsRematch = rematch;
|
||||
mIsServer = isServer;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,13 +131,59 @@ class InvitesNeededAlert {
|
|||
mState = state;
|
||||
}
|
||||
|
||||
private Dialog makeImpl( final Callbacks callbacks, final DBAlert alert,
|
||||
Object[] params )
|
||||
private Dialog makeImpl( final Callbacks callbacks, DBAlert alert, Object[] params )
|
||||
{
|
||||
Dialog result = null;
|
||||
State state = (State)params[0];
|
||||
AlertDialog.Builder ab = mDelegate.makeAlertBuilder();
|
||||
mAlert = alert;
|
||||
|
||||
if ( state.mIsServer ) {
|
||||
makeImplHost( ab, callbacks, alert, state );
|
||||
} else {
|
||||
makeImplGuest( ab, state );
|
||||
}
|
||||
|
||||
alert.setOnCancelListener( new XWDialogFragment.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancelled( XWDialogFragment frag ) {
|
||||
// Log.d( TAG, "onCancelled(frag=%s)", frag );
|
||||
callbacks.onCloseClicked();
|
||||
close();
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
alert.setNoDismissListenerNeg( ab, R.string.button_close_game,
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
callbacks.onCloseClicked();
|
||||
}
|
||||
} );
|
||||
|
||||
Dialog result = ab.create();
|
||||
result.setCanceledOnTouchOutside( false );
|
||||
return result;
|
||||
}
|
||||
|
||||
private void makeImplGuest( AlertDialog.Builder ab, State state )
|
||||
{
|
||||
Context context = mDelegate.getActivity();
|
||||
String message = LocUtils.getString( context, R.string.waiting_host_expl );
|
||||
|
||||
if ( 1 < state.mNPlayersMissing ) {
|
||||
message += "\n\n" +
|
||||
LocUtils.getString( context, R.string.waiting_host_expl_multi );
|
||||
}
|
||||
|
||||
ab.setTitle( R.string.waiting_host_title )
|
||||
.setMessage( message )
|
||||
;
|
||||
}
|
||||
|
||||
private void makeImplHost( AlertDialog.Builder ab, final Callbacks callbacks,
|
||||
DBAlert alert, State state )
|
||||
{
|
||||
Context context = mDelegate.getActivity();
|
||||
String title;
|
||||
|
||||
|
@ -160,8 +208,7 @@ class InvitesNeededAlert {
|
|||
+ LocUtils.getString( context, R.string.invite_msg_extra_rematch );
|
||||
}
|
||||
|
||||
AlertDialog.Builder ab = mDelegate.makeAlertBuilder()
|
||||
.setTitle( title )
|
||||
ab.setTitle( title )
|
||||
.setMessage( message );
|
||||
|
||||
alert.setNoDismissListenerPos( ab, R.string.newgame_invite,
|
||||
|
@ -187,26 +234,5 @@ class InvitesNeededAlert {
|
|||
} );
|
||||
}
|
||||
}
|
||||
|
||||
alert.setNoDismissListenerNeg( ab, R.string.button_close,
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
callbacks.onCloseClicked();
|
||||
}
|
||||
} );
|
||||
|
||||
alert.setOnCancelListener( new XWDialogFragment.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancelled( XWDialogFragment frag ) {
|
||||
// Log.d( TAG, "onCancelled(frag=%s)", frag );
|
||||
callbacks.onCloseClicked();
|
||||
close();
|
||||
}
|
||||
} );
|
||||
|
||||
result = ab.create();
|
||||
result.setCanceledOnTouchOutside( false );
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2260,6 +2260,17 @@
|
|||
<!-- Button for alert with title above -->
|
||||
<string name="waiting_invite_title">Waiting for response</string>
|
||||
<string name="waiting_rematch_title">Rematch in progress</string>
|
||||
|
||||
<!-- Title for when I'm a guest waiting for host to begin game -->
|
||||
<string name="waiting_host_title">Waiting for host</string>
|
||||
<string name="waiting_host_expl">This game is waiting for the host
|
||||
device to begin the game. That usually means that the host is not
|
||||
communicating (it’s temporarily offline?)</string>
|
||||
|
||||
<string name="waiting_host_expl_multi">In this case, because the
|
||||
game is expecting more than just this device to connect, it could
|
||||
also mean that it hasn’t invited everybody yet.</string>
|
||||
|
||||
<!-- Button for alert with title above -->
|
||||
<string name="button_close">Close</string>
|
||||
<string name="button_reinvite">Re-invite</string>
|
||||
|
|
|
@ -97,7 +97,7 @@ typedef struct ServerNonvolatiles {
|
|||
XW_State stateAfterShow;
|
||||
XP_S8 currentTurn; /* invalid when game is over */
|
||||
XP_S8 quitter; /* -1 unless somebody resigned */
|
||||
XP_U8 pendingRegistrations;
|
||||
XP_U8 pendingRegistrations; /* server-case only */
|
||||
XP_Bool showRobotScores;
|
||||
XP_Bool sortNewTiles;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
|
@ -467,8 +467,9 @@ writeStreamIf( XWStreamCtxt* dest, XWStreamCtxt* src )
|
|||
static void
|
||||
informMissing( const ServerCtxt* server, XWEnv xwe )
|
||||
{
|
||||
XP_Bool isServer = amServer( server );
|
||||
const XP_Bool isServer = amServer( server );
|
||||
const CommsCtxt* comms = server->vol.comms;
|
||||
const CurGameInfo* gi = server->vol.gi;
|
||||
CommsAddrRec addr;
|
||||
CommsAddrRec* addrP;
|
||||
if ( !comms ) {
|
||||
|
@ -478,8 +479,16 @@ informMissing( const ServerCtxt* server, XWEnv xwe )
|
|||
comms_getAddr( comms, addrP );
|
||||
}
|
||||
|
||||
XP_U16 nDevs = isServer ? server->nv.nDevices - 1 : 0;
|
||||
XP_U16 nPending = isServer ? server->nv.pendingRegistrations : 0;
|
||||
XP_U16 nDevs = 0;
|
||||
XP_U16 nPending = 0;
|
||||
if ( XWSTATE_BEGIN < server->nv.gameState ) {
|
||||
/* do nothing */
|
||||
} else if ( isServer ) {
|
||||
nPending = server->nv.pendingRegistrations;
|
||||
nDevs = server->nv.nDevices - 1;
|
||||
} else if ( SERVER_ISCLIENT == gi->serverRole ) {
|
||||
nPending = gi->nPlayers - gi_countLocalPlayers( gi, XP_FALSE);
|
||||
}
|
||||
util_informMissing( server->vol.util, xwe, isServer, addrP, nDevs, nPending );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue