don't allow saving/playing a multi-divice game that doesn't have at

least one way of connecting. Instead, give a choice between discarding
it and editing, and if the latter choice it taken open the alert for
picking ways to connect. Requires a new version of showConfirmThen()
that lets the negative button be other than "Cancel".
This commit is contained in:
Eric House 2015-02-01 22:15:06 -08:00
parent 02da56ce9c
commit 8abe7720c8
8 changed files with 156 additions and 66 deletions

View file

@ -563,6 +563,7 @@ public final class R {
/** Text of button displayed when downloading is an option
*/
public static final int button_download=0x7f0501a9;
public static final int button_edit=0x7f0502dc;
public static final int button_go_settings=0x7f05027d;
/**
*/
@ -733,6 +734,7 @@ public final class R {
on the board.
*/
public static final int clr_crosshairs=0x7f050158;
public static final int config_no_connvia=0x7f0502db;
/**
*/
public static final int confirm_clear=0x7f050222;

View file

@ -2298,7 +2298,13 @@
<string name="enable_bt_first">Please turn Bluetooth on before enabling.</string>
<string name="enable_sms_first">Please check \"Allow games via SMS\" before enabling.</string>
<string name="warn_no_comms">If you have no default connection
<string name="warn_no_comms">Every networked game must have at
least one way of communicating. If you have no default connection
options every new networked game will have to be configured
manually.</string>
<string name="config_no_connvia">This game has no way to connect
and cannot be saved. Would you like to discard it, or edit to give
it a way to connect?</string>
<string name="button_edit">Edit</string>
</resources>

View file

@ -1951,7 +1951,12 @@
emag si nepo.</string>
<string name="enable_bt_first">Esaelp nrut Htooteulb no erofeb gnilbane.</string>
<string name="enable_sms_first">Esaelp kcehc \"Wolla semag aiv SMS\" erofeb gnilbane.</string>
<string name="warn_no_comms">Fi uoy evah on tluafed noitcennoc
<string name="warn_no_comms">Yreve dekrowten emag tsum evah ta
tsael eno yaw fo gnitacinummoc. Fi uoy evah on tluafed noitcennoc
snoitpo yreve wen dekrowten emag lliw evah ot eb derugifnoc
yllaunam.</string>
<string name="config_no_connvia">Siht emag sah on yaw ot tcennoc
dna tonnac eb devas. Dluow uoy ekil ot dracsid ,ti ro tide ot evig
ti a yaw ot ?tcennoc</string>
<string name="button_edit">Tide</string>
</resources>

View file

@ -1951,7 +1951,12 @@
GAME IS OPEN.</string>
<string name="enable_bt_first">PLEASE TURN BLUETOOTH ON BEFORE ENABLING.</string>
<string name="enable_sms_first">PLEASE CHECK \"ALLOW GAMES VIA SMS\" BEFORE ENABLING.</string>
<string name="warn_no_comms">IF YOU HAVE NO DEFAULT CONNECTION
<string name="warn_no_comms">EVERY NETWORKED GAME MUST HAVE AT
LEAST ONE WAY OF COMMUNICATING. IF YOU HAVE NO DEFAULT CONNECTION
OPTIONS EVERY NEW NETWORKED GAME WILL HAVE TO BE CONFIGURED
MANUALLY.</string>
<string name="config_no_connvia">THIS GAME HAS NO WAY TO CONNECT
AND CANNOT BE SAVED. WOULD YOU LIKE TO DISCARD IT, OR EDIT TO GIVE
IT A WAY TO CONNECT?</string>
<string name="button_edit">EDIT</string>
</resources>

View file

@ -384,6 +384,11 @@ public class DelegateBase implements DlgClickNotify,
m_delegate.showConfirmThen( msg, posButton, action, params );
}
protected void showConfirmThen( int msg, int posButton, int negButton, Action action )
{
m_delegate.showConfirmThen( msg, posButton, negButton, action );
}
protected void showConfirmThen( int msg, int posButton, Action action,
Object... params )
{
@ -495,7 +500,28 @@ public class DelegateBase implements DlgClickNotify,
//////////////////////////////////////////////////////////////////////
public void dlgButtonClicked( Action action, int button, Object[] params )
{
Assert.fail();
if ( BuildConfig.DEBUG ) {
String buttonName = null;
switch( button ) {
case AlertDialog.BUTTON_POSITIVE:
buttonName = "positive";
break;
case AlertDialog.BUTTON_NEGATIVE:
buttonName = "negative";
break;
case AlertDialog.BUTTON_NEUTRAL:
buttonName = "neutral";
break;
case DlgDelegate.DISMISS_BUTTON:
buttonName = "dismiss";
break;
default:
Assert.fail();
break;
}
DbgUtils.logf( "DelegateBase.dlgButtonClicked(action=%s button=%s): UNHANDLED",
action.toString(), buttonName );
}
}
public void inviteChoiceMade( Action action, DlgClickNotify.InviteMeans means, Object[] params )

View file

@ -87,6 +87,7 @@ public class DlgDelegate {
// Game configs
LOCKED_CHANGE_ACTION,
EXIT_NO_SAVE,
// New Game
NEW_GAME_ACTION,
@ -316,17 +317,30 @@ public class DlgDelegate {
showConfirmThen( msg, posButton, action, null );
}
public void showConfirmThen( int msg, int posButton, int negButton, Action action )
{
showConfirmThen( getString(msg), posButton, negButton, action, null );
}
public void showConfirmThen( int msg, int posButton, Action action,
Object[] params )
{
showConfirmThen( getString( msg ), posButton, action, params );
showConfirmThen( getString(msg), posButton, R.string.button_cancel,
action, params );
}
public void showConfirmThen( String msg, int posButton, Action action,
Object[] params )
{
showConfirmThen( msg, posButton, R.string.button_cancel, action,
params );
}
public void showConfirmThen( String msg, int posButton, int negButton,
Action action, Object[] params )
{
DlgState state = new DlgState( DlgID.CONFIRM_THEN, msg, posButton,
action, 0, params );
negButton, action, 0, params );
addState( state );
showDialog( DlgID.CONFIRM_THEN );
}
@ -538,7 +552,7 @@ public class DlgDelegate {
builder.setTitle( R.string.query_title );
builder.setMessage( state.m_msg );
builder.setPositiveButton( state.m_posButton, lstnr );
builder.setNegativeButton( R.string.button_cancel, lstnr );
builder.setNegativeButton( state.m_negButton, lstnr );
Dialog dialog = builder.create();
return setCallbackDismissListener( dialog, state, dlgID );

View file

@ -30,6 +30,7 @@ public class DlgState implements Parcelable {
public DlgID m_id;
public String m_msg;
public int m_posButton;
public int m_negButton;
public Action m_action = null;
public ActionPair m_pair = null;
public int m_prefsKey;
@ -60,12 +61,19 @@ public class DlgState implements Parcelable {
}
public DlgState( DlgID dlgID, String msg, int posButton,
Action action, int prefsKey,
Object[] params )
Action action, int prefsKey, Object[] params )
{
this( dlgID, msg, posButton, R.string.button_cancel,
action, prefsKey, params );
}
public DlgState( DlgID dlgID, String msg, int posButton, int negButton,
Action action, int prefsKey, Object[] params )
{
m_id = dlgID;
m_msg = msg;
m_posButton = posButton;
m_negButton = negButton;
m_action = action;
m_prefsKey = prefsKey;
m_params = params;
@ -88,6 +96,7 @@ public class DlgState implements Parcelable {
public void writeToParcel( Parcel out, int flags ) {
out.writeInt( m_id.ordinal() );
out.writeInt( m_posButton );
out.writeInt( m_negButton );
out.writeInt( null == m_action ? -1 : m_action.ordinal() );
out.writeInt( m_prefsKey );
out.writeString( m_msg );
@ -98,11 +107,12 @@ public class DlgState implements Parcelable {
public DlgState createFromParcel(Parcel in) {
DlgID id = DlgID.values()[in.readInt()];
int posButton = in.readInt();
int negButton = in.readInt();
int tmp = in.readInt();
Action action = 0 > tmp ? null : Action.values()[tmp];
int prefsKey = in.readInt();
String msg = in.readString();
return new DlgState( id, msg, posButton, action, prefsKey );
return new DlgState( id, msg, posButton, negButton, action, prefsKey, null );
}
public DlgState[] newArray(int size) {

View file

@ -296,14 +296,16 @@ public class GameConfigDelegate extends DelegateBase
break;
}
}
public void typeSetEmpty() {}
}, null );
final DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
m_conTypes = items.getTypes();
m_car.populate( m_activity, m_conTypes );
setConnLabel();
setupRelayStuffIf();
showHideRelayStuff();
}
};
@ -556,7 +558,7 @@ public class GameConfigDelegate extends DelegateBase
int relayPort = XWPrefs.getDefaultRelayPort( m_activity );
XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort );
}
m_conTypes = m_carOrig.conTypes;
m_conTypes = (CommsConnTypeSet)m_carOrig.conTypes.clone();
XwJNI.game_dispose( gamePtr );
m_car = new CommsAddrRec( m_carOrig );
@ -574,30 +576,7 @@ public class GameConfigDelegate extends DelegateBase
}
setConnLabel();
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
m_joinPublicCheck =
(CheckBox)findViewById(R.id.join_public_room_check);
m_joinPublicCheck.setOnClickListener( this );
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
setChecked( R.id.advertise_new_room_check,
m_car.ip_relay_advertiseRoom );
m_publicRoomsSet =
(LinearLayout)findViewById(R.id.public_rooms_set );
m_privateRoomsSet =
(LinearLayout)findViewById(R.id.private_rooms_set );
setText( R.id.room_edit, m_car.ip_relay_invite );
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
m_refreshRoomsButton =
(ImageButton)findViewById( R.id.refresh_button );
m_refreshRoomsButton.setOnClickListener( this );
adjustConnectStuff();
}
setupRelayStuffIf();
loadPlayersList();
configLangSpinner();
@ -651,20 +630,36 @@ public class GameConfigDelegate extends DelegateBase
@Override
public void dlgButtonClicked( Action action, int button, Object[] params )
{
boolean positive = AlertDialog.BUTTON_POSITIVE == button;
switch( action ) {
case LOCKED_CHANGE_ACTION:
if ( positive ) {
boolean callSuper = false;
if ( AlertDialog.BUTTON_POSITIVE == button ) {
switch( action ) {
case LOCKED_CHANGE_ACTION:
handleLockedChange();
}
break;
case SMS_CONFIG_ACTION:
if ( positive ) {
break;
case SMS_CONFIG_ACTION:
Utils.launchSettings( m_activity );
break;
case EXIT_NO_SAVE:
finish();
break;
default:
callSuper = true;
}
break;
default:
Assert.fail();
} else if ( AlertDialog.BUTTON_NEGATIVE == button ) {
switch ( action ) {
case EXIT_NO_SAVE:
showDialog( DlgID.CHANGE_CONN );
break;
default:
callSuper = true;
break;
}
} else {
callSuper = true;
}
if ( callSuper ) {
super.dlgButtonClicked( action, button, params );
}
}
@ -697,7 +692,12 @@ public class GameConfigDelegate extends DelegateBase
// from here if there's no confirmation needed, or launch
// a new dialog whose OK button does the same thing.
saveChanges();
if ( m_forResult ) {
if ( 0 == m_conTypes.size() ) {
showConfirmThen( R.string.config_no_connvia,
R.string.button_discard,
R.string.button_edit,
Action.EXIT_NO_SAVE );
} else if ( m_forResult ) {
applyChanges( true );
Intent intent = new Intent();
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
@ -1111,26 +1111,20 @@ public class GameConfigDelegate extends DelegateBase
position = m_boardsizeSpinner.getSelectedItemPosition();
m_gi.boardSize = positionToSize( position );
for ( Iterator<CommsConnType> iter = m_conTypes.iterator();
iter.hasNext(); ) {
switch( iter.next() ) {
case COMMS_CONN_RELAY:
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
m_car.ip_relay_advertiseRoom =
getChecked( R.id.advertise_new_room_check );
if ( m_car.ip_relay_seeksPublicRoom ) {
SpinnerAdapter adapter = m_roomChoose.getAdapter();
if ( null != adapter ) {
int pos = m_roomChoose.getSelectedItemPosition();
if ( pos >= 0 && pos < adapter.getCount() ) {
m_car.ip_relay_invite = (String)adapter.getItem(pos);
}
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
m_car.ip_relay_advertiseRoom =
getChecked( R.id.advertise_new_room_check );
if ( m_car.ip_relay_seeksPublicRoom ) {
SpinnerAdapter adapter = m_roomChoose.getAdapter();
if ( null != adapter ) {
int pos = m_roomChoose.getSelectedItemPosition();
if ( pos >= 0 && pos < adapter.getCount() ) {
m_car.ip_relay_invite = (String)adapter.getItem(pos);
}
} else {
m_car.ip_relay_invite = getText( R.id.room_edit ).trim();
}
break;
// nothing to save for BT yet
} else {
m_car.ip_relay_invite = getText( R.id.room_edit ).trim();
}
}
@ -1198,6 +1192,34 @@ public class GameConfigDelegate extends DelegateBase
m_connLabel.setText( getString( R.string.connect_label_fmt, connString ) );
}
private void setupRelayStuffIf()
{
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
if ( null == m_joinPublicCheck ) {
m_joinPublicCheck =
(CheckBox)findViewById(R.id.join_public_room_check);
m_joinPublicCheck.setOnClickListener( this );
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
setChecked( R.id.advertise_new_room_check,
m_car.ip_relay_advertiseRoom );
m_publicRoomsSet =
(LinearLayout)findViewById(R.id.public_rooms_set );
m_privateRoomsSet =
(LinearLayout)findViewById(R.id.private_rooms_set );
setText( R.id.room_edit, m_car.ip_relay_invite );
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
m_refreshRoomsButton =
(ImageButton)findViewById( R.id.refresh_button );
m_refreshRoomsButton.setOnClickListener( this );
adjustConnectStuff();
}
}
}
private void showHideRelayStuff()
{
boolean show = m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY );