use same (new) dialog for solo games

This commit is contained in:
Eric House 2021-01-04 21:26:12 -08:00
parent 4d1e380616
commit 3350ca19b7
4 changed files with 55 additions and 68 deletions

View file

@ -867,16 +867,12 @@ public class GamesListDelegate extends ListDelegateBase
case GAMES_LIST_NEWGAME:
boolean solo = (Boolean)params[0];
if ( solo ) {
dialog = mkNewSoloGameDialog();
} else {
dialog = mkNewNetGameDialog();
if ( XwJNI.hasKnownPlayers() ) {
makeNotAgainBuilder( R.string.not_again_quicknetgame,
R.string.key_na_quicknetgame )
.setTitle( R.string.new_feature_title )
.show();
}
dialog = mkNewNetGameDialog( solo );
if ( !solo && XwJNI.hasKnownPlayers() ) {
makeNotAgainBuilder( R.string.not_again_quicknetgame,
R.string.key_na_quicknetgame )
.setTitle( R.string.new_feature_title )
.show();
}
break;
@ -918,49 +914,16 @@ public class GamesListDelegate extends ListDelegateBase
return dialog;
} // makeDialog
private Dialog mkNewSoloGameDialog()
{
final LinearLayout view = (LinearLayout)
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
final EditWClear edit = (EditWClear)view.findViewById( R.id.edit );
edit.setText( GameUtils.makeDefaultName( m_activity ) );
String msg = getString( R.string.new_game_message );
TextView tmpEdit = (TextView)view.findViewById( R.id.msg );
tmpEdit.setText( msg );
OnClickListener lstnr = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
String name = edit.getText().toString();
curThis().makeThenLaunchOrConfigure( name, true, false );
}
};
AlertDialog.Builder ab = makeAlertBuilder()
.setView( view )
.setTitle( R.string.new_game )
.setIcon( R.drawable.ic_sologame )
.setPositiveButton( R.string.newgame_configure_first, lstnr );
OnClickListener lstnr2 = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
String name = edit.getText().toString();
curThis().makeThenLaunchOrConfigure( name, false, false );
}
};
ab.setNegativeButton( R.string.use_defaults, lstnr2 );
return ab.create();
}
private Dialog mkNewNetGameDialog()
private Dialog mkNewNetGameDialog( final boolean standalone )
{
// String[] names = XwJNI.kplr_getPlayers();
final NewWithKnowns view = (NewWithKnowns)
LocUtils.inflate( m_activity, R.layout.new_game_with_knowns );
view.setGameName( GameUtils.makeDefaultName( m_activity ) );
view.configure( standalone, GameUtils.makeDefaultName( m_activity ) );
AlertDialog.Builder ab = makeAlertBuilder()
.setView( view )
.setTitle( R.string.new_game_networked )
.setIcon( R.drawable.ic_multigame )
.setTitle( standalone ? R.string.new_game : R.string.new_game_networked )
.setIcon( standalone ? R.drawable.ic_sologame: R.drawable.ic_multigame )
.setPositiveButton( android.R.string.cancel, new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
@ -968,20 +931,21 @@ public class GamesListDelegate extends ListDelegateBase
@Override
public void onUseKnown( String knownName, String gameName )
{
Assert.assertTrueNR( !standalone );
CommsAddrRec addr = XwJNI.kplr_getAddr( knownName );
if ( null != addr ) {
launchLikeRematch( addr, gameName );
}
}
@Override
public void onInviteLater( String gameName )
public void onStartGame( String gameName, boolean solo,
boolean configFirst )
{
curThis().makeThenLaunchOrConfigure( gameName, false, false );
}
@Override
public void onConfigureFirst( String gameName )
{
curThis().makeThenLaunchOrConfigure( gameName, true, false );
Assert.assertTrueNR( solo == standalone );
Assert.assertTrueNR( solo == m_mySIS.nextIsSolo );
curThis().makeThenLaunchOrConfigure( gameName,
configFirst,
false );
}
} );
}

View file

@ -46,14 +46,14 @@ public class NewWithKnowns extends LinearLayout
public interface ButtonCallbacks {
void onUseKnown( String knownName, String gameName );
void onInviteLater( String gameName );
void onConfigureFirst( String gameName );
void onStartGame( String gameName, boolean solo, boolean configFirst );
}
private ButtonChangeListener mListener;
private String mCurKnown;
private int mCurRadio;
private Spinner mNamesSpinner;
private boolean mStandalone;
public NewWithKnowns( Context cx, AttributeSet as )
{
@ -66,9 +66,11 @@ public class NewWithKnowns extends LinearLayout
mListener = listener;
}
void setGameName( String gameName )
void configure( boolean standalone, String gameName )
{
boolean hasKnowns = XwJNI.hasKnownPlayers();
mStandalone = standalone;
boolean hasKnowns = !standalone && XwJNI.hasKnownPlayers();
int[] toHide;
if ( hasKnowns ) {
String[] knowns = XwJNI.kplr_getPlayers();
mCurKnown = DBUtils.getStringFor( getContext(), KP_NAME_KEY,
@ -89,11 +91,16 @@ public class NewWithKnowns extends LinearLayout
break;
}
}
toHide = new int[]{ R.id.radio_default, R.id.choose_expl_default,
};
} else {
int[] toHide = { R.id.radio_known, R.id.names, R.id.expl_known };
for ( int resID : toHide ) {
findViewById(resID).setVisibility( View.GONE );
}
toHide = new int[]{ R.id.radio_known, R.id.names, R.id.expl_known,
R.id.radio_unknown, R.id.choose_expl_new,
};
}
for ( int resID : toHide ) {
findViewById(resID).setVisibility(View.GONE);
}
EditWClear et = (EditWClear)findViewById( R.id.name_edit );
@ -112,12 +119,14 @@ public class NewWithKnowns extends LinearLayout
procs.onUseKnown( mCurKnown, gameName );
break;
case R.id.radio_unknown:
procs.onInviteLater( gameName );
case R.id.radio_default:
procs.onStartGame( gameName, mStandalone, false );
break;
case R.id.radio_configure:
procs.onConfigureFirst( gameName );
procs.onStartGame( gameName, mStandalone, true );
break;
default:
Assert.failDbg();
break;
}
}
@ -165,11 +174,14 @@ public class NewWithKnowns extends LinearLayout
.getString( context, R.string.newgame_invite_fmt, mCurKnown );
break;
case R.id.radio_unknown:
case R.id.radio_default:
resId = R.string.newgame_open_game;
break;
case R.id.radio_configure:
resId = R.string.newgame_configure_game;
break;
default:
Assert.failDbg();
}
if ( 0 != resId ) {

View file

@ -15,11 +15,23 @@
android:layout_height="wrap_content"
>
<!-- One of these two pairs gets hidden -->
<RadioButton android:id="@+id/radio_default"
android:text="@string/use_defaults"
style="@style/new_game_radio"
/>
<TextView android:id="@+id/choose_expl_default"
android:text="@string/choose_expl_default"
style="@style/new_game_expl"
/>
<!-- pair 2 (networked games case) -->
<RadioButton android:id="@+id/radio_unknown"
android:text="@string/newgame_radio_unknown"
style="@style/new_game_radio"
/>
<TextView android:text="@string/choose_expl_new"
<TextView android:id="@+id/choose_expl_new"
android:text="@string/choose_expl_new"
style="@style/new_game_expl"
/>

View file

@ -2208,9 +2208,6 @@
<string name="new_game">New one-device game</string>
<string name="new_game_networked">New networked game</string>
<string name="rematch_name_fmt">%1$s</string>
<string name="new_game_message">Would you like to create this game
using default settings?\n\nOr would you like to configure it
first?</string>
<string name="new_game_message_nodflt">This game must be
configured before it can be opened.</string>
<string name="use_defaults">Use defaults</string>
@ -2672,6 +2669,8 @@
“%1$s” to “%2$s”. Is “%2$s” already in use?</string>
<!-- Quick-start new game explanations and buttons -->
<string name="choose_expl_default">Start a solo game using the
current defaults</string>
<string name="choose_expl_new">Start a game with somebody new,
sending an invitation via email, SMS, or even a QR code</string>
<string name="choose_expl_known">OR start a game with somebody youve