use same dialog for all new networked games

This commit is contained in:
Eric House 2021-01-04 11:46:34 -08:00
parent 185abd2d04
commit 65ba8cef66
4 changed files with 56 additions and 55 deletions

View file

@ -867,15 +867,16 @@ public class GamesListDelegate extends ListDelegateBase
case GAMES_LIST_NEWGAME: case GAMES_LIST_NEWGAME:
boolean solo = (Boolean)params[0]; boolean solo = (Boolean)params[0];
boolean forceConfig = 2 <= params.length && (Boolean)params[1]; if ( solo ) {
if ( !solo && !forceConfig && XwJNI.hasKnownPlayers() ) { dialog = mkNewSoloGameDialog();
dialog = mkNewWithKnowns(); } else {
dialog = mkNewNetGameDialog();
if ( XwJNI.hasKnownPlayers() ) {
makeNotAgainBuilder( R.string.not_again_quicknetgame, makeNotAgainBuilder( R.string.not_again_quicknetgame,
R.string.key_na_quicknetgame ) R.string.key_na_quicknetgame )
.setTitle( R.string.new_feature_title ) .setTitle( R.string.new_feature_title )
.show(); .show();
} else { }
dialog = mkNewGameDialog( solo );
} }
break; break;
@ -917,23 +918,14 @@ public class GamesListDelegate extends ListDelegateBase
return dialog; return dialog;
} // makeDialog } // makeDialog
private Dialog mkNewGameDialog( boolean solo ) private Dialog mkNewSoloGameDialog()
{ {
final LinearLayout view = (LinearLayout) final LinearLayout view = (LinearLayout)
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit ); LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
final EditWClear edit = (EditWClear)view.findViewById( R.id.edit ); final EditWClear edit = (EditWClear)view.findViewById( R.id.edit );
edit.setText( GameUtils.makeDefaultName( m_activity ) ); edit.setText( GameUtils.makeDefaultName( m_activity ) );
boolean canDoDefaults = solo || String msg = getString( R.string.new_game_message );
0 < XWPrefs.getAddrTypes( m_activity ).size();
int iconResID = solo ? R.drawable.ic_sologame : R.drawable.ic_multigame;
int titleID = solo ? R.string.new_game : R.string.new_game_networked;
String msg = getString( canDoDefaults ? R.string.new_game_message
: R.string.new_game_message_nodflt );
if ( !solo ) {
msg += "\n\n" + getString( R.string.new_game_message_net );
}
TextView tmpEdit = (TextView)view.findViewById( R.id.msg ); TextView tmpEdit = (TextView)view.findViewById( R.id.msg );
tmpEdit.setText( msg ); tmpEdit.setText( msg );
@ -946,10 +938,9 @@ public class GamesListDelegate extends ListDelegateBase
AlertDialog.Builder ab = makeAlertBuilder() AlertDialog.Builder ab = makeAlertBuilder()
.setView( view ) .setView( view )
.setTitle( titleID ) .setTitle( R.string.new_game )
.setIcon( iconResID ) .setIcon( R.drawable.ic_sologame )
.setPositiveButton( R.string.newgame_configure_first, lstnr ); .setPositiveButton( R.string.newgame_configure_first, lstnr );
if ( canDoDefaults ) {
OnClickListener lstnr2 = new OnClickListener() { OnClickListener lstnr2 = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
String name = edit.getText().toString(); String name = edit.getText().toString();
@ -957,16 +948,15 @@ public class GamesListDelegate extends ListDelegateBase
} }
}; };
ab.setNegativeButton( R.string.use_defaults, lstnr2 ); ab.setNegativeButton( R.string.use_defaults, lstnr2 );
}
return ab.create(); return ab.create();
} }
private Dialog mkNewWithKnowns() private Dialog mkNewNetGameDialog()
{ {
String[] names = XwJNI.kplr_getPlayers(); // String[] names = XwJNI.kplr_getPlayers();
final NewWithKnowns view = (NewWithKnowns) final NewWithKnowns view = (NewWithKnowns)
LocUtils.inflate( m_activity, R.layout.new_game_with_knowns ); LocUtils.inflate( m_activity, R.layout.new_game_with_knowns );
view.setNames( names, GameUtils.makeDefaultName( m_activity ) ); view.setGameName( GameUtils.makeDefaultName( m_activity ) );
AlertDialog.Builder ab = makeAlertBuilder() AlertDialog.Builder ab = makeAlertBuilder()
.setView( view ) .setView( view )
.setTitle( R.string.new_game_networked ) .setTitle( R.string.new_game_networked )

View file

@ -31,6 +31,7 @@ import android.widget.RadioGroup;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
public class NewWithKnowns extends LinearLayout public class NewWithKnowns extends LinearLayout
@ -65,8 +66,11 @@ public class NewWithKnowns extends LinearLayout
mListener = listener; mListener = listener;
} }
void setNames( String[] knowns, String gameName ) void setGameName( String gameName )
{ {
boolean hasKnowns = XwJNI.hasKnownPlayers();
if ( hasKnowns ) {
String[] knowns = XwJNI.kplr_getPlayers();
mCurKnown = DBUtils.getStringFor( getContext(), KP_NAME_KEY, mCurKnown = DBUtils.getStringFor( getContext(), KP_NAME_KEY,
knowns[0] ); knowns[0] );
ArrayAdapter<String> adapter = new ArrayAdapter<String> adapter = new
@ -85,6 +89,12 @@ public class NewWithKnowns extends LinearLayout
break; break;
} }
} }
} else {
int[] toHide = { R.id.radio_known, R.id.names, R.id.expl_known };
for ( int resID : toHide ) {
findViewById(resID).setVisibility( View.GONE );
}
}
EditWClear et = (EditWClear)findViewById( R.id.name_edit ); EditWClear et = (EditWClear)findViewById( R.id.name_edit );
et.setText( gameName ); et.setText( gameName );
@ -141,8 +151,10 @@ public class NewWithKnowns extends LinearLayout
private void onRadioChanged() private void onRadioChanged()
{ {
if ( null != mNamesSpinner ) {
mNamesSpinner.setVisibility( mCurRadio == R.id.radio_known mNamesSpinner.setVisibility( mCurRadio == R.id.radio_known
? View.VISIBLE : View.GONE ); ? View.VISIBLE : View.GONE );
}
Context context = getContext(); Context context = getContext();
int resId = 0; int resId = 0;

View file

@ -34,7 +34,8 @@
android:paddingLeft="32dp" android:paddingLeft="32dp"
android:visibility="gone" android:visibility="gone"
/> />
<TextView android:text="@string/choose_expl_known" <TextView android:id="@+id/expl_known"
android:text="@string/choose_expl_known"
style="@style/new_game_expl" style="@style/new_game_expl"
/> />

View file

@ -2213,8 +2213,6 @@
first?</string> first?</string>
<string name="new_game_message_nodflt">This game must be <string name="new_game_message_nodflt">This game must be
configured before it can be opened.</string> configured before it can be opened.</string>
<string name="new_game_message_net">(You will have a chance to
invite other players after it is created.)</string>
<string name="use_defaults">Use defaults</string> <string name="use_defaults">Use defaults</string>
<string name="nplayers_prompt">Number on this device</string> <string name="nplayers_prompt">Number on this device</string>
<plurals name="nplayers_fmt"> <plurals name="nplayers_fmt">