honor selected group when creating net and sms games too

This commit is contained in:
Eric House 2013-10-22 07:40:46 -07:00
parent 9997c43298
commit 9ed1c21cf8
3 changed files with 68 additions and 44 deletions

View file

@ -46,6 +46,8 @@ public class GameUtils {
public static final String INTENT_KEY_ROWID = "rowid"; public static final String INTENT_KEY_ROWID = "rowid";
public static final String INTENT_FORRESULT_ROWID = "forresult"; public static final String INTENT_FORRESULT_ROWID = "forresult";
private static final long GROUPID_UNSPEC = -1;
public static class NoSuchGameException extends RuntimeException { public static class NoSuchGameException extends RuntimeException {
public NoSuchGameException() { public NoSuchGameException() {
super(); // superfluous super(); // superfluous
@ -320,12 +322,15 @@ public class GameUtils {
public static long saveNew( Context context, CurGameInfo gi ) public static long saveNew( Context context, CurGameInfo gi )
{ {
long groupID = XWPrefs.getDefaultNewGameGroup( context ); return saveNew( context, gi, GROUPID_UNSPEC );
return saveNew( context, gi, groupID );
} }
public static long saveNew( Context context, CurGameInfo gi, long groupID ) public static long saveNew( Context context, CurGameInfo gi, long groupID )
{ {
if ( GROUPID_UNSPEC == groupID ) {
groupID = XWPrefs.getDefaultNewGameGroup( context );
}
long rowid = DBUtils.ROWID_NOTFOUND; long rowid = DBUtils.ROWID_NOTFOUND;
byte[] bytes = XwJNI.gi_to_stream( gi ); byte[] bytes = XwJNI.gi_to_stream( gi );
if ( null != bytes ) { if ( null != bytes ) {
@ -336,7 +341,8 @@ public class GameUtils {
return rowid; return rowid;
} }
private static long makeNewMultiGame( Context context, CommsAddrRec addr, private static long makeNewMultiGame( Context context, long groupID,
CommsAddrRec addr,
int[] lang, String[] dict, int[] lang, String[] dict,
int nPlayersT, int nPlayersH, int nPlayersT, int nPlayersH,
String inviteID, int gameID, String inviteID, int gameID,
@ -359,7 +365,7 @@ public class GameUtils {
// Will need to add a setNPlayers() method to gi to make this // Will need to add a setNPlayers() method to gi to make this
// work // work
Assert.assertTrue( gi.nPlayers == nPlayersT ); Assert.assertTrue( gi.nPlayers == nPlayersT );
rowid = saveNew( context, gi ); rowid = saveNew( context, gi, groupID );
if ( DBUtils.ROWID_NOTFOUND != rowid ) { if ( DBUtils.ROWID_NOTFOUND != rowid ) {
GameLock lock = new GameLock( rowid, true ).lock(); GameLock lock = new GameLock( rowid, true ).lock();
@ -370,8 +376,8 @@ public class GameUtils {
return rowid; return rowid;
} }
public static long makeNewNetGame( Context context, String room, public static long makeNewNetGame( Context context, long groupID,
String inviteID, int[] lang, String room, String inviteID, int[] lang,
String[] dict, int nPlayersT, String[] dict, int nPlayersT,
int nPlayersH ) int nPlayersH )
{ {
@ -381,29 +387,38 @@ public class GameUtils {
CommsAddrRec addr = new CommsAddrRec( relayName, relayPort ); CommsAddrRec addr = new CommsAddrRec( relayName, relayPort );
addr.ip_relay_invite = room; addr.ip_relay_invite = room;
return makeNewMultiGame( context, addr, lang, dict, nPlayersT, return makeNewMultiGame( context, groupID, addr, lang, dict,
nPlayersH, inviteID, 0, false ); nPlayersT, nPlayersH, inviteID, 0, false );
} }
public static long makeNewNetGame( Context context, String room, public static long makeNewNetGame( Context context, long groupID,
String inviteID, int lang, String dict, String room, String inviteID, int lang,
int nPlayers ) String dict, int nPlayers )
{ {
int[] langarr = { lang }; int[] langarr = { lang };
String[] dictArr = { dict }; String[] dictArr = { dict };
return makeNewNetGame( context, room, inviteID, langarr, dictArr, return makeNewNetGame( context, groupID, room, inviteID, langarr,
nPlayers, 1 ); dictArr, nPlayers, 1 );
} }
public static long makeNewNetGame( Context context, NetLaunchInfo info ) public static long makeNewNetGame( Context context, NetLaunchInfo info )
{ {
return makeNewNetGame( context, info.room, info.inviteID, info.lang, return makeNewNetGame( context, GROUPID_UNSPEC, info.room,
info.dict, info.nPlayersT ); info.inviteID, info.lang, info.dict,
info.nPlayersT );
} }
public static long makeNewBTGame( Context context, int gameID, public static long makeNewBTGame( Context context, int gameID,
CommsAddrRec addr, int lang, CommsAddrRec addr, int lang,
int nPlayersT, int nPlayersH ) int nPlayersT, int nPlayersH )
{
return makeNewBTGame( context, GROUPID_UNSPEC, gameID, addr, lang,
nPlayersT, nPlayersH );
}
public static long makeNewBTGame( Context context, long groupID,
int gameID, CommsAddrRec addr, int lang,
int nPlayersT, int nPlayersH )
{ {
long rowid = -1; long rowid = -1;
int[] langa = { lang }; int[] langa = { lang };
@ -411,13 +426,22 @@ public class GameUtils {
if ( isHost ) { if ( isHost ) {
addr = new CommsAddrRec( null, null ); addr = new CommsAddrRec( null, null );
} }
return makeNewMultiGame( context, addr, langa, null, nPlayersT, return makeNewMultiGame( context, groupID, addr, langa, null,
nPlayersH, null, gameID, isHost ); nPlayersT, nPlayersH, null, gameID, isHost );
} }
public static long makeNewSMSGame( Context context, int gameID, public static long makeNewSMSGame( Context context, int gameID,
CommsAddrRec addr, int lang, CommsAddrRec addr,
String dict, int nPlayersT, int lang, String dict, int nPlayersT,
int nPlayersH )
{
return makeNewSMSGame( context, GROUPID_UNSPEC, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
}
public static long makeNewSMSGame( Context context, long groupID,
int gameID, CommsAddrRec addr,
int lang, String dict, int nPlayersT,
int nPlayersH ) int nPlayersH )
{ {
long rowid = -1; long rowid = -1;
@ -427,8 +451,8 @@ public class GameUtils {
if ( isHost ) { if ( isHost ) {
addr = new CommsAddrRec(CommsAddrRec.CommsConnType.COMMS_CONN_SMS); addr = new CommsAddrRec(CommsAddrRec.CommsConnType.COMMS_CONN_SMS);
} }
return makeNewMultiGame( context, addr, langa, dicta, nPlayersT, return makeNewMultiGame( context, groupID, addr, langa, dicta,
nPlayersH, null, gameID, isHost ); nPlayersT, nPlayersH, null, gameID, isHost );
} }
public static void launchInviteActivity( Context context, public static void launchInviteActivity( Context context,

View file

@ -91,6 +91,7 @@ public class GamesList extends XWExpandableListActivity
DELETE_GROUPS, DELETE_GROUPS,
OPEN_GAME OPEN_GAME
}; };
private static final int[] DEBUGITEMS = { private static final int[] DEBUGITEMS = {
R.id.gamel_menu_loaddb, R.id.gamel_menu_loaddb,
R.id.gamel_menu_storedb, R.id.gamel_menu_storedb,
@ -987,9 +988,6 @@ public class GamesList extends XWExpandableListActivity
private void startNewGameActivity( long groupID ) private void startNewGameActivity( long groupID )
{ {
if ( 0 > groupID ) {
groupID = XWPrefs.getDefaultNewGameGroup( this );
}
NewGameActivity.startActivity( this, groupID ); NewGameActivity.startActivity( this, groupID );
} }

View file

@ -236,8 +236,8 @@ public class NewGameActivity extends XWActivity {
m_gameID, m_gameName, m_gameID, m_gameName,
m_lang, m_dict, 2, 1 ); m_lang, m_dict, 2, 1 );
long rowid = GameUtils. long rowid = GameUtils.
makeNewSMSGame( thiz, m_gameID, null, makeNewSMSGame( thiz, m_groupID, m_gameID,
m_lang, m_dict, 2, 1 ); null, m_lang, m_dict, 2, 1 );
DBUtils.setName( thiz, rowid, m_gameName ); DBUtils.setName( thiz, rowid, m_gameName );
GameUtils.launchGame( thiz, rowid, true ); GameUtils.launchGame( thiz, rowid, true );
finish(); finish();
@ -289,8 +289,8 @@ public class NewGameActivity extends XWActivity {
public void run() { public void run() {
long rowid = long rowid =
GameUtils.makeNewBTGame( NewGameActivity.this, GameUtils.makeNewBTGame( NewGameActivity.this,
gameID, null, m_lang, m_groupID, gameID, null,
2, 1 ); m_lang, 2, 1 );
DBUtils.setName( NewGameActivity.this, DBUtils.setName( NewGameActivity.this,
rowid, m_gameName ); rowid, m_gameName );
GameUtils.launchGame( NewGameActivity.this, GameUtils.launchGame( NewGameActivity.this,
@ -328,8 +328,8 @@ public class NewGameActivity extends XWActivity {
if ( networked ) { if ( networked ) {
room = GameUtils.makeRandomID(); room = GameUtils.makeRandomID();
inviteID = GameUtils.makeRandomID(); inviteID = GameUtils.makeRandomID();
rowid = GameUtils.makeNewNetGame( this, room, inviteID, lang, rowid = GameUtils.makeNewNetGame( this, m_groupID, room, inviteID,
dict, nPlayers, 1 ); lang, dict, nPlayers, 1 );
} else { } else {
rowid = GameUtils.saveNew( this, new CurGameInfo( this ), m_groupID ); rowid = GameUtils.saveNew( this, new CurGameInfo( this ), m_groupID );
} }
@ -350,18 +350,20 @@ public class NewGameActivity extends XWActivity {
private void makeNewBTGame( boolean useDefaults ) private void makeNewBTGame( boolean useDefaults )
{ {
int gameID = GameUtils.newGameID(); if ( XWApp.BTSUPPORTED ) {
if ( !useDefaults ) { int gameID = GameUtils.newGameID();
m_newRowID = GameUtils.makeNewBTGame( NewGameActivity.this, if ( !useDefaults ) {
gameID, null, m_lang, m_newRowID = GameUtils.makeNewBTGame( NewGameActivity.this,
2, 1 ); // initial defaults m_groupID, gameID, null,
Intent intent = new Intent( this, GameConfig.class ); m_lang, 2, 1 );
intent.setAction( Intent.ACTION_EDIT ); Intent intent = new Intent( this, GameConfig.class );
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_newRowID ); intent.setAction( Intent.ACTION_EDIT );
intent.putExtra( GameUtils.INTENT_FORRESULT_ROWID, true ); intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_newRowID );
startActivityForResult( intent, CONFIG_FOR_BT ); intent.putExtra( GameUtils.INTENT_FORRESULT_ROWID, true );
} else { startActivityForResult( intent, CONFIG_FOR_BT );
BTInviteActivity.launchForResult( this, 1, INVITE_FOR_BT ); } else {
BTInviteActivity.launchForResult( this, 1, INVITE_FOR_BT );
}
} }
} }
@ -370,8 +372,8 @@ public class NewGameActivity extends XWActivity {
int gameID = GameUtils.newGameID(); int gameID = GameUtils.newGameID();
if ( !useDefaults ) { if ( !useDefaults ) {
m_newRowID = GameUtils.makeNewSMSGame( NewGameActivity.this, m_newRowID = GameUtils.makeNewSMSGame( NewGameActivity.this,
gameID, null, m_lang, m_groupID, gameID, null,
m_dict, 2, 1 ); m_lang, m_dict, 2, 1 );
String name = Utils.format( this, R.string.dft_sms_namef, String name = Utils.format( this, R.string.dft_sms_namef,
gameID & 0xFFFF ); gameID & 0xFFFF );
DBUtils.setName( this, m_newRowID, name ); DBUtils.setName( this, m_newRowID, name );