2005-01-08 18:13:30 +00:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4;-*- */
|
|
|
|
/*
|
|
|
|
* Copyright 2005 by Eric House (fixin@peak.org). All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <eikedwin.h>
|
|
|
|
#include <eikmfne.h>
|
|
|
|
#include <eikchlst.h>
|
|
|
|
|
|
|
|
#include "symgamdl.h"
|
2005-01-09 18:58:05 +00:00
|
|
|
#include "symutil.h"
|
2005-01-08 18:13:30 +00:00
|
|
|
#include "xwords.hrh"
|
2005-01-13 02:31:15 +00:00
|
|
|
#include "xwords.rsg"
|
2005-01-08 18:13:30 +00:00
|
|
|
|
2005-01-09 18:58:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* TGameInfoBuf
|
|
|
|
***************************************************************************/
|
|
|
|
TGameInfoBuf::TGameInfoBuf( const CurGameInfo* aGi,
|
|
|
|
CDesC16ArrayFlat* aDictList )
|
2005-01-13 02:31:15 +00:00
|
|
|
: iDictList(aDictList),
|
|
|
|
iDictIndex(0)
|
2005-01-09 18:58:05 +00:00
|
|
|
{
|
|
|
|
TInt i;
|
|
|
|
|
|
|
|
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
|
|
|
iIsRobot[i] = aGi->players[i].isRobot;
|
|
|
|
|
|
|
|
TBuf8<32> tmp( aGi->players[i].name );
|
|
|
|
iPlayerNames[i].Copy( tmp );
|
|
|
|
}
|
|
|
|
iNPlayers = aGi->nPlayers;
|
|
|
|
|
|
|
|
if ( aGi->dictName != NULL ) {
|
|
|
|
TBuf8<32> tmp( aGi->dictName );
|
|
|
|
TBuf16<32> dictName;
|
|
|
|
dictName.Copy( tmp );
|
2005-01-13 02:31:15 +00:00
|
|
|
(void)iDictList->Find( dictName, iDictIndex ); /*iDictIndex ref passed*/
|
2005-01-09 18:58:05 +00:00
|
|
|
}
|
|
|
|
} /* TGameInfoBuf::TGameInfoBuf */
|
|
|
|
|
|
|
|
void
|
|
|
|
TGameInfoBuf::CopyToL( MPFORMAL CurGameInfo* aGi )
|
|
|
|
{
|
|
|
|
TInt i;
|
|
|
|
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
|
|
|
aGi->players[i].isRobot = iIsRobot[i];
|
|
|
|
|
|
|
|
symReplaceStrIfDiff( MPPARM(mpool) &aGi->players[i].name,
|
|
|
|
iPlayerNames[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
aGi->nPlayers = iNPlayers;
|
|
|
|
|
|
|
|
TPtrC16 dictName = (*iDictList)[iDictIndex];
|
|
|
|
symReplaceStrIfDiff( MPPARM(mpool) &aGi->dictName, dictName );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* CXWGameInfoDlg
|
|
|
|
***************************************************************************/
|
|
|
|
CXWGameInfoDlg::CXWGameInfoDlg( MPFORMAL TGameInfoBuf* aGib, TBool aNewGame )
|
2005-01-13 02:31:15 +00:00
|
|
|
: iIsNewGame(aNewGame), iGib(aGib)
|
2005-01-08 18:13:30 +00:00
|
|
|
{
|
|
|
|
MPASSIGN( this->mpool, mpool );
|
|
|
|
}
|
|
|
|
|
|
|
|
CXWGameInfoDlg::~CXWGameInfoDlg()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWGameInfoDlg::PreLayoutDynInitL()
|
|
|
|
{
|
2005-01-13 02:31:15 +00:00
|
|
|
XP_U16 i;
|
2005-01-09 18:58:05 +00:00
|
|
|
CEikChoiceList* list;
|
|
|
|
|
2005-01-08 18:13:30 +00:00
|
|
|
/* This likely belongs in its own method */
|
|
|
|
const TInt deps[] = { EConnectionRole
|
|
|
|
};
|
2005-01-09 18:58:05 +00:00
|
|
|
for ( i = 0; i < sizeof(deps)/sizeof(deps[0]); ++i ) {
|
2005-01-08 18:13:30 +00:00
|
|
|
HandleControlStateChangeL( deps[i] );
|
|
|
|
}
|
2005-01-09 18:58:05 +00:00
|
|
|
|
|
|
|
list = static_cast<CEikChoiceList*>(Control(ENPlayersList));
|
|
|
|
list->SetCurrentItem( iGib->iNPlayers - 1 );
|
|
|
|
|
|
|
|
list = static_cast<CEikChoiceList*>(Control(ENPlayersWhichList));
|
|
|
|
list->SetArrayExternalOwnership( EFalse );
|
|
|
|
list->SetArrayL( MakeNumListL( 1, iGib->iNPlayers ) );
|
|
|
|
|
|
|
|
list = static_cast<CEikChoiceList*>(Control(ESelDictChoice));
|
|
|
|
list->SetArrayL( iGib->iDictList );
|
|
|
|
list->SetCurrentItem( iGib->iDictIndex );
|
|
|
|
|
|
|
|
iCurPlayerShown = 0;
|
|
|
|
LoadPlayerInfo( iCurPlayerShown );
|
2005-01-08 18:13:30 +00:00
|
|
|
} /* PreLayoutDynInitL */
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWGameInfoDlg::HandleControlStateChangeL( TInt aControlId )
|
|
|
|
{
|
|
|
|
XP_LOGF( "HandleControlStateChangeL got %d", aControlId );
|
|
|
|
CEikChoiceList* list;
|
2005-01-09 18:58:05 +00:00
|
|
|
CEikChoiceList* whichList;
|
|
|
|
TInt item;
|
|
|
|
TBool show;
|
2005-01-08 18:13:30 +00:00
|
|
|
|
|
|
|
switch ( aControlId ) {
|
|
|
|
case EConnectionRole:
|
|
|
|
/* Hide EConnectionType if it's standalone */
|
|
|
|
list = static_cast<CEikChoiceList*>(Control(EConnectionRole));
|
|
|
|
|
|
|
|
MakeLineVisible( EConnectionType, list->CurrentItem() != 0 );
|
|
|
|
break;
|
2005-01-09 18:58:05 +00:00
|
|
|
|
|
|
|
case ENPlayersList:
|
|
|
|
/* The ENPlayersWhichList must match the number of players available,
|
|
|
|
and we need to display a different player if we're currently
|
|
|
|
showing one who no longer exists. */
|
|
|
|
list = static_cast<CEikChoiceList*>
|
|
|
|
(Control( ENPlayersList ));
|
|
|
|
item = list->CurrentItem();
|
|
|
|
|
|
|
|
whichList = static_cast<CEikChoiceList*>
|
|
|
|
(Control( ENPlayersWhichList ));
|
|
|
|
whichList->SetArrayL( MakeNumListL( 1, item + 1 ) );
|
|
|
|
|
|
|
|
if ( item < iCurPlayerShown ) {
|
|
|
|
/* HandleControlStateChangeL seems not to get called for this
|
|
|
|
change. But the DrawDeferred()s below make it ok */
|
|
|
|
whichList->SetCurrentItem( item );
|
|
|
|
SetPlayerShown( item );
|
|
|
|
} else {
|
|
|
|
whichList->SetCurrentItem( iCurPlayerShown );
|
|
|
|
}
|
|
|
|
whichList->DrawDeferred();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENPlayersWhichList:
|
|
|
|
list = static_cast<CEikChoiceList*>
|
|
|
|
(Control( ENPlayersWhichList ));
|
|
|
|
SetPlayerShown( list->CurrentItem() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EPlayerLocationChoice:
|
2005-01-08 18:13:30 +00:00
|
|
|
list = static_cast<CEikChoiceList*>
|
2005-01-09 18:58:05 +00:00
|
|
|
(Control(EPlayerLocationChoice ));
|
|
|
|
show = list->CurrentItem() == 0;
|
2005-01-08 18:13:30 +00:00
|
|
|
|
2005-01-09 18:58:05 +00:00
|
|
|
MakeLineVisible( EPlayerName, show );
|
|
|
|
MakeLineVisible( EPlayerSpeciesChoice, show );
|
|
|
|
MakeLineVisible( EDecryptPassword, show );
|
2005-01-08 18:13:30 +00:00
|
|
|
break;
|
2005-01-09 18:58:05 +00:00
|
|
|
|
2005-01-08 18:13:30 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TBool
|
|
|
|
CXWGameInfoDlg::OkToExitL( TInt aKeyCode )
|
|
|
|
{
|
2005-01-09 18:58:05 +00:00
|
|
|
CEikChoiceList* list;
|
|
|
|
|
|
|
|
/* Dictionary */
|
|
|
|
list = static_cast<CEikChoiceList*>(Control(ESelDictChoice));
|
|
|
|
iGib->iDictIndex = list->CurrentItem();
|
|
|
|
|
|
|
|
/* Player data (all but displayed already saved) */
|
|
|
|
SavePlayerInfo( iCurPlayerShown );
|
|
|
|
|
|
|
|
/* number of players */
|
|
|
|
list = static_cast<CEikChoiceList*>(Control(ENPlayersList));
|
|
|
|
iGib->iNPlayers = list->CurrentItem() + 1;
|
|
|
|
|
2005-01-08 18:13:30 +00:00
|
|
|
return ETrue;
|
|
|
|
}
|
2005-01-09 18:58:05 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CXWGameInfoDlg::LoadPlayerInfo( TInt aWhich )
|
|
|
|
{
|
|
|
|
/* location */
|
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* name */
|
|
|
|
XP_LOGF( "setting name" );
|
|
|
|
CEikEdwin* nameEditor = static_cast<CEikEdwin*>(Control(EPlayerName));
|
|
|
|
nameEditor->SetTextL( &iGib->iPlayerNames[aWhich] );
|
|
|
|
nameEditor->DrawDeferred();
|
|
|
|
|
|
|
|
XP_LOGF( "done setting name" );
|
|
|
|
|
|
|
|
/* species */
|
|
|
|
CEikChoiceList* list = static_cast<CEikChoiceList*>
|
|
|
|
(Control(EPlayerSpeciesChoice ));
|
|
|
|
TInt oldVal = list->CurrentItem();
|
|
|
|
TInt newVal = iGib->iIsRobot[aWhich]? 1:0;
|
|
|
|
if ( oldVal != newVal ) {
|
|
|
|
list->SetCurrentItem( newVal );
|
|
|
|
list->DrawDeferred();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* password */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWGameInfoDlg::SavePlayerInfo( TInt aWhich )
|
|
|
|
{
|
|
|
|
|
|
|
|
/* name */
|
|
|
|
CEikEdwin* nameEditor = static_cast<CEikEdwin*>(Control(EPlayerName));
|
|
|
|
nameEditor->GetText( iGib->iPlayerNames[aWhich] );
|
|
|
|
|
|
|
|
/* species */
|
|
|
|
CEikChoiceList* list = static_cast<CEikChoiceList*>
|
|
|
|
(Control(EPlayerSpeciesChoice ));
|
|
|
|
iGib->iIsRobot[aWhich] = (list->CurrentItem() == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWGameInfoDlg::SetPlayerShown( TInt aPlayer )
|
|
|
|
{
|
|
|
|
if ( aPlayer != iCurPlayerShown ) {
|
|
|
|
SavePlayerInfo( iCurPlayerShown );
|
|
|
|
LoadPlayerInfo( aPlayer );
|
|
|
|
iCurPlayerShown = aPlayer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CDesC16ArrayFlat*
|
|
|
|
CXWGameInfoDlg::MakeNumListL( TInt aFirst, TInt aLast )
|
|
|
|
{
|
|
|
|
XP_ASSERT( aFirst <= aLast );
|
|
|
|
|
|
|
|
CDesC16ArrayFlat* list = new (ELeave)CDesC16ArrayFlat(aLast - aFirst + 1);
|
|
|
|
TInt i;
|
|
|
|
char str[2] = { 0, 0 };
|
|
|
|
for ( i = aFirst; i <= aLast; ++i ) {
|
|
|
|
str[0] = '0' + i;
|
|
|
|
TBuf8<4> buf8( (unsigned char*)str );
|
|
|
|
TBuf16<4> buf16;
|
|
|
|
buf16.Copy( buf8 );
|
|
|
|
list->AppendL( buf16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
} /* MakeNumListL */
|
2005-01-13 02:31:15 +00:00
|
|
|
|
|
|
|
/* static*/ TBool
|
|
|
|
CXWGameInfoDlg::DoGameInfoDlgL( MPFORMAL TGameInfoBuf* aGib, TBool aNewGame )
|
|
|
|
{
|
|
|
|
CXWGameInfoDlg* me =
|
|
|
|
new(ELeave)CXWGameInfoDlg( MPPARM(mpool) aGib, aNewGame );
|
|
|
|
return me->ExecuteLD( R_XWORDS_NEWGAME_DLG );
|
|
|
|
}
|