00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <avkon.hrh>
00031 #include <aknnotewrappers.h>
00032
00033 #include "OandXAppUi.h"
00034 #include "oandxcontroller.h"
00035 #include "oandxengine.h"
00036 #include "OandXApplication.h"
00037 #include "OandXAppView.h"
00038 #include "OandXHistView.h"
00039 #include "oandxdefs.h"
00040 #include "OandX.hrh"
00041 #include <OandX.rsg>
00042
00043 #define MaxInfoNoteTextLen 40
00044
00045 COandXAppUi::COandXAppUi()
00050 {
00051
00052 }
00053
00054 void COandXAppUi::ConstructL()
00060 {
00061
00062 BaseConstructL(EAknEnableSkin);
00063 iEngine = COandXEngine::NewL();
00064 iController = COandXController::NewL();
00065
00066 iHistView = COandXHistoryView::NewLC();
00067 AddViewL(iHistView);
00068 CleanupStack::Pop();
00069
00070 iAppView = COandXGameView::NewLC();
00071 AddViewL(iAppView);
00072 CleanupStack::Pop();
00073
00074 SetDefaultViewL(*iAppView);
00075
00076 ReportWhoseTurn();
00077 }
00078
00079
00080 COandXAppUi::~COandXAppUi()
00086 {
00087 delete iController;
00088 delete iEngine;
00089 }
00090
00091 void COandXAppUi::HandleCommandL(TInt aCommand)
00098 {
00099 _LIT8(KDummy, "");
00100 switch(aCommand)
00101 {
00102 case EEikCmdExit:
00103 case EAknSoftkeyExit:
00104 {
00105 SaveL();
00106 Exit();
00107 }
00108 break;
00109 case EOandXNewGame:
00110 {
00111 iController->Reset();
00112 iAppView->Container()->ResetView();
00113 }
00114 break;
00115 case EOandXFirstPlayer:
00116 {
00117 iController->SwitchTurn();
00118 }
00119 break;
00120 case EOandXDisplayStats:
00121 {
00122 if (iHistView->IsActivated())
00123 {
00124 iHistView->ChangeDisplayL(EOandXSetStats);
00125 }
00126 else
00127 {
00128 ActivateViewL(TVwsViewId( KUidOandXApp, KUidOandXHistoryView), TUid::Uid(EHistoryViewDisplayStats), KDummy );
00129 }
00130 break;
00131 }
00132 case EOandXDisplayHistory:
00133 {
00134 if (iHistView->IsActivated())
00135 {
00136 iHistView->ChangeDisplayL(EOandXSetHistory);
00137 }
00138 else
00139 {
00140 ActivateViewL(TVwsViewId(KUidOandXApp, KUidOandXHistoryView), TUid::Uid(EHistoryViewDisplayHistory), KDummy );
00141 }
00142 break;
00143 }
00144 case EOandXDisplayGame:
00145 {
00146 ActivateViewL(TVwsViewId( KUidOandXApp, KUidOandXView)) ;
00147 break;
00148 }
00149 case EOandXResetHistory:
00150 {
00151 Controller().ResetStats();
00152 iHistView->ChangeDisplayL(iHistView->IsDisplayingHistory());
00153 break;
00154 }
00155 default:
00156 break;
00157 }
00158 }
00159
00160 void COandXAppUi::ReportWhoseTurn()
00164 {
00165 iAppView->Container()->ShowTurn();
00166 }
00167
00168 void COandXAppUi::ReportWinnerL(TInt aWinner)
00173 {
00174 TBuf<MaxInfoNoteTextLen> text;
00175 iEikonEnv->ReadResource(text, aWinner==ETileCross ? R_OANDX_X_WINS : R_OANDX_O_WINS);
00176 CAknInformationNote* infoNote = new (ELeave) CAknInformationNote;
00177 infoNote->ExecuteLD(text);
00178 }
00179
00180 TStreamId COandXAppUi::StoreL(CStreamStore& aStore) const
00189 {
00190 RStoreWriteStream stream;
00191 TStreamId id = stream.CreateLC(aStore);
00192 stream << *this;
00193 stream.CommitL();
00194 CleanupStack::PopAndDestroy();
00195 return id;
00196 }
00197
00198 void COandXAppUi::RestoreL(const CStreamStore& aStore, TStreamId aStreamId)
00208 {
00209 RStoreReadStream stream;
00210 stream.OpenLC(aStore,aStreamId);
00211 stream >> *this;
00212 CleanupStack::PopAndDestroy();
00213 }
00214
00215 void COandXAppUi::ExternalizeL(RWriteStream& aStream) const
00222 {
00223 iEngine->ExternalizeL(aStream);
00224 iController->ExternalizeL(aStream);
00225 aStream.WriteInt8L(iAppView->Container()->IdOfFocusControl());
00226 }
00227
00228 void COandXAppUi::InternalizeL(RReadStream& aStream)
00235 {
00236 iEngine->InternalizeL(aStream);
00237 iController->InternalizeL(aStream);
00238 ReportWhoseTurn();
00239 iAppView->Container()->MoveFocusTo(aStream.ReadInt8L());
00240 }
00241
00242
00243
00244
00245 GLDEF_C COandXAppUi* OandXAppUi()
00250 {
00251 return static_cast<COandXAppUi*>(CEikonEnv::Static()->AppUi());
00252 }
00253
00254 GLDEF_C COandXController& Controller()
00259 {
00260 return *OandXAppUi()->iController;
00261 }
00262
00263 GLDEF_C COandXEngine& Engine()
00268 {
00269 return *OandXAppUi()->iEngine;
00270 }