From 7783021fd760ab951b8dac6f5990f4dbacd6f6ae Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 23 Sep 2015 07:53:49 -0700 Subject: [PATCH] give player a chance to name rematch game, and provide default that includes opponent's name --- xwords4/android/XWords4/archive/R.java | 63 +++++++-------- .../android/XWords4/res/values/strings.xml | 1 + .../XWords4/res_src/values-ba_CK/strings.xml | 5 +- .../XWords4/res_src/values-ca_PS/strings.xml | 5 +- .../eehouse/android/xw4/BoardDelegate.java | 3 +- .../src/org/eehouse/android/xw4/DlgID.java | 1 + .../android/xw4/GamesListDelegate.java | 79 +++++++++++++++---- .../eehouse/android/xw4/jni/CurGameInfo.java | 15 ++-- 8 files changed, 113 insertions(+), 59 deletions(-) diff --git a/xwords4/android/XWords4/archive/R.java b/xwords4/android/XWords4/archive/R.java index d7fe92add..d6e1d1018 100644 --- a/xwords4/android/XWords4/archive/R.java +++ b/xwords4/android/XWords4/archive/R.java @@ -683,8 +683,6 @@ string name="str_robot_moved">O robô fez esta jogada:\u0020Do not notify me no matter - how long it\'s been my turn XLATE-ME For debugging */ @@ -1178,7 +1176,7 @@ XLATE-ME /** XLATE-ME Discard changes */ - public static final int button_discard_changes=0x7f0502d7; + public static final int button_discard_changes=0x7f0502d8; /** Done @@ -1214,7 +1212,7 @@ XLATE-ME /** XLATE-ME Edit */ - public static final int button_edit=0x7f0502d6; + public static final int button_edit=0x7f0502d7; public static final int button_enable=0x7f05031a; /** XLATE-ME Enable Bluetooth @@ -1517,7 +1515,7 @@ XLATE-ME public static final int button_trade_commit=0x7f0500dd; /** Button for alert with title above */ - public static final int button_wait=0x7f0502d1; + public static final int button_wait=0x7f0502d2; /** ############################################################ # Dialogs @@ -1718,7 +1716,7 @@ XLATE-ME and cannot be saved. Would you like to discard your changes, or edit to give it a way to connect? */ - public static final int config_no_connvia=0x7f0502d5; + public static final int config_no_connvia=0x7f0502d6; public static final int confirm_clear_chat=0x7f050325; public static final int confirm_clear_relay=0x7f05020f; /** Additional text appended to text confirm_delete_dictf in the @@ -1932,7 +1930,7 @@ XLATE-ME /** XLATE-ME Change Communicate via */ - public static final int connection_via_label=0x7f0502cd; + public static final int connection_via_label=0x7f0502ce; /** (Last failure was %1$s) @@ -2295,12 +2293,14 @@ XLATE-ME */ public static final int dicts_list_prompt_fmt=0x7f0500da; public static final int disable_nag_solo_title=0x7f0502de; - public static final int disable_nag_summary_net=0x7f0502dc; - public static final int disable_nag_summary_solo=0x7f0502dd; + /** Do not notify me no matter + how long it\'s been my turn + */ + public static final int disable_nag_summary=0x7f0502dd; /** Disable turn reminders */ - public static final int disable_nag_title=0x7f0502db; - public static final int disable_nags_title=0x7f0502da; + public static final int disable_nag_title=0x7f0502dc; + public static final int disable_nags_title=0x7f0502db; /** text of item at bottom of dicts choice spinner. It launches the browser pointed at the site where additional wordlists can be found. @@ -2424,11 +2424,11 @@ XLATE-ME /** XLATE-ME Rooms others can see and join */ - public static final int enable_pubroom_summary=0x7f0502cc; + public static final int enable_pubroom_summary=0x7f0502cd; /** XLATE-ME Enable public rooms */ - public static final int enable_pubroom_title=0x7f0502cb; + public static final int enable_pubroom_title=0x7f0502cc; public static final int enable_relay_toself_summary=0x7f050321; public static final int enable_relay_toself_title=0x7f050320; /** @@ -2460,7 +2460,7 @@ XLATE-ME device \"%1$s\" has already accepted an invitation to this game. */ - public static final int err_dup_invite_fmt=0x7f0502c6; + public static final int err_dup_invite_fmt=0x7f0502c7; /** XLATE-ME Update checks URL */ @@ -3136,11 +3136,11 @@ XLATE-ME /** XLATE-ME Invite more than one player per remote device */ - public static final int invite_multi_summary=0x7f0502ca; + public static final int invite_multi_summary=0x7f0502cb; /** XLATE-ME Invite multiple */ - public static final int invite_multi_title=0x7f0502c9; + public static final int invite_multi_title=0x7f0502ca; /** Most users create games with only two players, which is the default, but Crosswords supports up to four. When I'm using the above string to encourage the opener of a game missing @@ -3180,7 +3180,7 @@ XLATE-ME expect it to take a while. They will still be able to connect.) */ - public static final int invite_stays=0x7f0502d2; + public static final int invite_stays=0x7f0502d3; /** Send invitation using SMS (texting) or via email? Send invitation using NFC (Android @@ -3968,11 +3968,11 @@ XLATE-ME /** XLATE-ME For experienced players */ - public static final int network_advanced_summary=0x7f0502c8; + public static final int network_advanced_summary=0x7f0502c9; /** XLATE-ME Advanced */ - public static final int network_advanced_title=0x7f0502c7; + public static final int network_advanced_title=0x7f0502c8; /** Network game settings */ public static final int network_behavior=0x7f050158; @@ -4029,17 +4029,17 @@ XLATE-ME using default settings?\n\nOr would you like to configure it first? */ - public static final int new_game_message=0x7f0502c1; + public static final int new_game_message=0x7f0502c2; /** XLATE-ME (You will have a chance to invite other players when it is open.) */ - public static final int new_game_message_net=0x7f0502c3; + public static final int new_game_message_net=0x7f0502c4; /** XLATE-ME This game must be configured before it can be opened. */ - public static final int new_game_message_nodflt=0x7f0502c2; + public static final int new_game_message_nodflt=0x7f0502c3; /** XLATE-ME New networked game */ @@ -4244,7 +4244,7 @@ XLATE-ME of this device against the one you want to invite—any time the game is open. */ - public static final int nfc_just_tap=0x7f0502d3; + public static final int nfc_just_tap=0x7f0502d4; /** XLATE-ME GSM XLATE-ME @@ -4677,7 +4677,7 @@ XLATE-ME and want them back, enable them now. You can turn them off again in Settings. */ - public static final int not_again_enablepublic=0x7f0502d9; + public static final int not_again_enablepublic=0x7f0502da; /** Shown when you tap the flip button on the toolbar of the main Board screen Shown when you tap the flip button on the toolbar of the main @@ -4702,7 +4702,7 @@ XLATE-ME section of App settings). */ - public static final int not_again_hidenewgamebuttons=0x7f0502cf; + public static final int not_again_hidenewgamebuttons=0x7f0502d0; /** Shown when you tap the next hint button on the toolbar of the main Board screen Shown when you tap the next hint button on the toolbar of the @@ -4929,7 +4929,7 @@ XLATE-ME /** XLATE-ME Number on this device */ - public static final int nplayers_prompt=0x7f0502c5; + public static final int nplayers_prompt=0x7f0502c6; /** text of label identifying the field where human players can enter an option password. The label and field disappear when the robot player checkbox is checked because it makes no @@ -5723,7 +5723,8 @@ XLATE-ME keep this game open while waiting. You will be notified when the game is ready to play. */ - public static final int rematch_msg=0x7f0502d8; + public static final int rematch_msg=0x7f0502d9; + public static final int rematch_name_fmt=0x7f0502c1; /** Processing wordlist information… */ public static final int remote_digesting=0x7f0502a5; @@ -5877,7 +5878,7 @@ XLATE-ME /** XLATE-ME Hide buttons */ - public static final int set_pref=0x7f0502ce; + public static final int set_pref=0x7f0502cf; /** text of separator marking out other-setting area of the dialog text of separator marking out other-setting area of the dialog Other settings @@ -6841,7 +6842,7 @@ string name="str_robot_moved">Robot uskutočnil tento ťah:Use defaults */ - public static final int use_defaults=0x7f0502c4; + public static final int use_defaults=0x7f0502c5; /** text of checkbox controlling whether there's a game timer text of checkbox controlling whether there's a game timer Enable game timer @@ -6861,7 +6862,7 @@ string name="str_robot_moved">Robot uskutočnil tento ťah:Waiting for players */ - public static final int waiting_title=0x7f0502d0; + public static final int waiting_title=0x7f0502d1; /** XLATE-ME Bluetooth is currently off on this device. No moves will be sent via Bluetooth.\n\nYou can enable @@ -6875,7 +6876,7 @@ string name="str_robot_moved">Robot uskutočnil tento ťah: */ - public static final int warn_no_comms=0x7f0502d4; + public static final int warn_no_comms=0x7f0502d5; /** The number %1$s for %2$s is not diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index a9e8c59bb..8295bdb55 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2395,6 +2395,7 @@ New one-device game New networked game + Rematch with %1$s Would you like to create this game using default settings?\n\nOr would you like to configure it diff --git a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml index 6b6dafe71..6f1a42a6e 100644 --- a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml @@ -2057,6 +2057,7 @@ Etacinummoc aiv Wen ecived-eno emag Wen dekrowten emag + Hctamer htiw %1$s Dluow uoy ekil ot etaerc siht emag gnisu tluafed ?sgnittes\n\nRo dluow uoy ekil ot erugifnoc ti ?tsrif @@ -2115,10 +2116,10 @@ dna tnaw meht ,kcab elbane meht won. Uoy nac nrut meht ffo niaga ni Sgnittes. Nrut srednimer - Elbasid ,srednimer krowten semag + Elbasid krowten emag srednimer Od ton yfiton em on rettam woh gnol ti\'s neeb ym nrut - Elbasid ,srednimer olos semag + Elbasid olos emag srednimer Ruoy ecived si tes pu rof %1$s. Dluow uoy ekil ot daolnwod a tsildrow os uoy nac yalp Sdrowssorc ni %1$s? diff --git a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml index dff93ad5c..455292dc4 100644 --- a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml @@ -2057,6 +2057,7 @@ COMMUNICATE VIA NEW ONE-DEVICE GAME NEW NETWORKED GAME + REMATCH WITH %1$s WOULD YOU LIKE TO CREATE THIS GAME USING DEFAULT SETTINGS?\n\nOR WOULD YOU LIKE TO CONFIGURE IT FIRST? @@ -2115,10 +2116,10 @@ AND WANT THEM BACK, ENABLE THEM NOW. YOU CAN TURN THEM OFF AGAIN IN SETTINGS. TURN REMINDERS - DISABLE REMINDERS, NETWORK GAMES + DISABLE NETWORK GAME REMINDERS DO NOT NOTIFY ME NO MATTER HOW LONG IT\'S BEEN MY TURN - DISABLE REMINDERS, SOLO GAMES + DISABLE SOLO GAME REMINDERS YOUR DEVICE IS SET UP FOR %1$s. WOULD YOU LIKE TO DOWNLOAD A WORDLIST SO YOU CAN PLAY CROSSWORDS IN %1$s? diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java index 29dd49a8d..690650ff0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -2584,10 +2584,11 @@ public class BoardDelegate extends DelegateBase } if ( doIt ) { + String[] opponents = m_gi.getRemoteNames(); Intent intent = GamesListDelegate .makeRematchIntent( m_activity, m_rowid, m_gi.dictName, m_gi.dictLang, m_connTypes, btAddr, - phone, relayID ); + phone, relayID, opponents[0] ); if ( null != intent ) { startActivity( intent ); finish(); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java index 6de9d61a7..53f0e559d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java @@ -70,4 +70,5 @@ public enum DlgID { , DLG_GETDICT , GAMES_LIST_NEWGAME , CHANGE_CONN + , GAMES_LIST_NAME_REMATCH } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 1c712d23b..db172b59b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -89,6 +89,7 @@ public class GamesListDelegate extends ListDelegateBase private static final String REMATCH_ROWID_EXTRA = "rm_rowid"; private static final String REMATCH_DICT_EXTRA = "rm_dict"; private static final String REMATCH_LANG_EXTRA = "rm_lang"; + private static final String REMATCH_OPPONENT_EXTRA = "rm_opp"; private static final String REMATCH_ADDRS_EXTRA = "rm_addrs"; private static final String REMATCH_BTADDR_EXTRA = "rm_btaddr"; private static final String REMATCH_PHONE_EXTRA = "rm_phone"; @@ -588,6 +589,8 @@ public class GamesListDelegate extends ListDelegateBase private boolean m_nextIsSolo; private Button[] m_newGameButtons; private boolean m_haveShownGetDict; + private Intent m_rematchIntent; + private String m_rematchOpponent; public GamesListDelegate( ListDelegator delegator, Bundle sis ) { @@ -842,6 +845,23 @@ public class GamesListDelegate extends ListDelegateBase .create(); break; + case GAMES_LIST_NAME_REMATCH: + view = (LinearLayout) + LocUtils.inflate( m_activity, R.layout.msg_label_and_edit ); + dialog = makeAlertBuilder() + .setView( view ) + .setTitle( R.string.button_rematch ) + .setIcon( R.drawable.multigame__gen ) + .setPositiveButton( android.R.string.ok, new OnClickListener() { + public void onClick( DialogInterface dlg, int item ) { + EditText edit = (EditText)((Dialog)dlg) + .findViewById( R.id.edit ); + startRematchWithName( edit ); + } + } ) + .create(); + break; + default: dialog = super.onCreateDialog( id ); break; @@ -878,6 +898,16 @@ public class GamesListDelegate extends ListDelegateBase edit.setText( msg ); edit = (TextView)dialog.findViewById( R.id.edit ); edit.setText( GameUtils.makeDefaultName( m_activity, m_nextIsSolo ) ); + edit.setVisibility( View.VISIBLE ); + break; + + case GAMES_LIST_NAME_REMATCH: + edit = (TextView)dialog.findViewById( R.id.edit ); + String name = getString( R.string.rematch_name_fmt, + m_rematchOpponent ); + edit.setText( name ); + ((TextView)dialog.findViewById( R.id.msg )) + .setVisibility( View.GONE ); break; } } @@ -1857,30 +1887,44 @@ public class GamesListDelegate extends ListDelegateBase String btAddr = intent.getStringExtra( REMATCH_BTADDR_EXTRA ); String phone = intent.getStringExtra( REMATCH_PHONE_EXTRA ); String relayID = intent.getStringExtra( REMATCH_RELAYID_EXTRA ); - long newid; if ( null == btAddr && null == phone && null == relayID ) { // this will juggle if the preference is set - newid = GameUtils.dupeGame( m_activity, rowid ); + long newid = GameUtils.dupeGame( m_activity, rowid ); + launchGame( newid ); } else { - String dict = intent.getStringExtra( REMATCH_DICT_EXTRA ); - int lang = intent.getIntExtra( REMATCH_LANG_EXTRA, -1 ); - int bits = intent.getIntExtra( REMATCH_ADDRS_EXTRA, -1 ); - CommsConnTypeSet addrs = new CommsConnTypeSet( bits ); - - long groupID = DBUtils.getGroupForGame( m_activity, rowid ); - String gameName = "rematch"; // FIX ME :-) - newid = GameUtils.makeNewMultiGame( m_activity, groupID, - dict, lang, - addrs, gameName ); - - DBUtils.addRematchInfo( m_activity, newid, btAddr, phone, - relayID ); + m_rematchIntent = intent; + m_rematchOpponent = + intent.getStringExtra( REMATCH_OPPONENT_EXTRA ); + showDialog( DlgID.GAMES_LIST_NAME_REMATCH ); } - launchGame( newid ); } } } + private void startRematchWithName( EditText edit ) + { + String gameName = edit.getText().toString(); + if ( null != gameName && 0 < gameName.length() ) { + Intent intent = m_rematchIntent; + long rowid = intent.getLongExtra( REMATCH_ROWID_EXTRA, -1 ); + String btAddr = intent.getStringExtra( REMATCH_BTADDR_EXTRA ); + String phone = intent.getStringExtra( REMATCH_PHONE_EXTRA ); + String relayID = intent.getStringExtra( REMATCH_RELAYID_EXTRA ); + String dict = intent.getStringExtra( REMATCH_DICT_EXTRA ); + int lang = intent.getIntExtra( REMATCH_LANG_EXTRA, -1 ); + int bits = intent.getIntExtra( REMATCH_ADDRS_EXTRA, -1 ); + CommsConnTypeSet addrs = new CommsConnTypeSet( bits ); + + long groupID = DBUtils.getGroupForGame( m_activity, rowid ); + long newid = GameUtils.makeNewMultiGame( m_activity, groupID, + dict, lang, + addrs, gameName ); + + DBUtils.addRematchInfo( m_activity, newid, btAddr, phone, + relayID ); + } + } + private void tryAlert( Intent intent ) { String msg = intent.getStringExtra( ALERT_MSG ); @@ -2264,7 +2308,7 @@ public class GamesListDelegate extends ListDelegateBase String dict, int lang, CommsConnTypeSet addrTypes, String btAddr, String phone, - String relayID ) + String relayID, String opponent ) { Intent intent = null; if ( XWApp.REMATCH_SUPPORTED ) { @@ -2272,6 +2316,7 @@ public class GamesListDelegate extends ListDelegateBase intent.putExtra( REMATCH_ROWID_EXTRA, rowid ); intent.putExtra( REMATCH_DICT_EXTRA, dict ); intent.putExtra( REMATCH_LANG_EXTRA, lang ); + intent.putExtra( REMATCH_OPPONENT_EXTRA, opponent ); if ( null != addrTypes ) { intent.putExtra( REMATCH_ADDRS_EXTRA, addrTypes.toInt() ); // here if ( null != btAddr ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java index 0f664d124..41492a7cc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java @@ -20,10 +20,11 @@ package org.eehouse.android.xw4.jni; -import java.util.Random; import android.content.Context; -import java.util.HashSet; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; +import java.util.Random; import junit.framework.Assert; import org.eehouse.android.xw4.DbgUtils; @@ -366,13 +367,15 @@ public class CurGameInfo { } } - public void setFirstLocalName( String name ) { + public String[] getRemoteNames() + { + ArrayList al = new ArrayList(); for ( int ii = 0; ii < nPlayers; ++ii ) { - if ( players[ii].isLocal ) { - players[ii].name = name; - break; + if ( ! players[ii].isLocal ) { + al.add( players[ii].name ); } } + return al.toArray( new String[al.size()] ); } private boolean moveUp( int which )