00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <avkon.hrh>
00018 #include <aknnotewrappers.h>
00019
00020 #include "OandXAppUi.h"
00021 #include "oandxcontroller.h"
00022 #include "oandxengine.h"
00023 #include "OandXAppView.h"
00024 #include "oandxdefs.h"
00025 #include "OandX.hrh"
00026 #include <OandX.rsg>
00027
00028 #define MaxInfoNoteTextLen 40
00029
00030 COandXAppUi::COandXAppUi()
00035
00036 {
00037
00038 }
00039
00040 void COandXAppUi::ConstructL()
00046 {
00047
00048 BaseConstructL(EAknEnableSkin);
00049 iEngine = COandXEngine::NewL();
00050 iController = COandXController::NewL();
00051 iAppView = COandXAppView::NewL(ClientRect());
00052 AddToStackL(iAppView);
00053 iStacked = ETrue;
00054
00055 ReportWhoseTurn();
00056 }
00057
00058
00059 COandXAppUi::~COandXAppUi()
00065 {
00066 if (iStacked)
00067 {
00068 RemoveFromStack(iAppView);
00069 }
00070 delete iAppView;
00071 delete iController;
00072 delete iEngine;
00073 }
00074
00075
00076 void COandXAppUi::HandleCommandL(TInt aCommand)
00083 {
00084 switch(aCommand)
00085 {
00086 case EEikCmdExit:
00087 case EAknSoftkeyExit:
00088 {
00089 SaveL();
00090 Exit();
00091 }
00092 break;
00093 case EOandXNewGame:
00094 {
00095 iController->Reset();
00096 iAppView->ResetView();
00097 }
00098 break;
00099 case EOandXSwitchTurn:
00100 {
00101 iController->SwitchTurn();
00102 }
00103 break;
00104
00105 default:
00106 break;
00107 }
00108 }
00109
00110 void COandXAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
00111 {
00112 if (aResourceId == R_OANDX_MENU)
00113 {
00114 if (iController->IsNewGame())
00115 {
00116 CEikMenuPaneItem::SData item;
00117 iCoeEnv->ReadResource(item.iText, iController->IsCrossTurn()?R_OANDX_O_MOVES_FIRST:R_OANDX_X_MOVES_FIRST );
00118 item.iCommandId = EOandXSwitchTurn;
00119 item.iFlags = 0;
00120 item.iCascadeId = 0;
00121 aMenuPane->AddMenuItemL(item);
00122
00123 aMenuPane->DeleteMenuItem(EOandXNewGame);
00124 }
00125 }
00126 }
00127
00128 void COandXAppUi::ReportWhoseTurn()
00132 {
00133 iAppView->ShowTurn();
00134 }
00135
00136 void COandXAppUi::ReportWinnerL(TInt aWinner)
00141 {
00142 TBuf<MaxInfoNoteTextLen> text;
00143 iEikonEnv->ReadResource(text, aWinner==ETileCross ? R_OANDX_X_WINS : R_OANDX_O_WINS);
00144 CAknInformationNote* infoNote = new (ELeave) CAknInformationNote;
00145 infoNote->ExecuteLD(text);
00146 }
00147
00148 TStreamId COandXAppUi::StoreL(CStreamStore& aStore) const
00157 {
00158 RStoreWriteStream stream;
00159 TStreamId id = stream.CreateLC(aStore);
00160 stream << *this;
00161 stream.CommitL();
00162 CleanupStack::PopAndDestroy();
00163 return id;
00164 }
00165
00166 void COandXAppUi::RestoreL(const CStreamStore& aStore, TStreamId aStreamId)
00176 {
00177 RStoreReadStream stream;
00178 stream.OpenLC(aStore,aStreamId);
00179 stream >> *this;
00180 CleanupStack::PopAndDestroy();
00181 }
00182
00183 void COandXAppUi::ExternalizeL(RWriteStream& aStream) const
00190 {
00191 iEngine->ExternalizeL(aStream);
00192 iController->ExternalizeL(aStream);
00193 aStream.WriteInt8L(iAppView->IdOfFocusControl());
00194 }
00195
00196 void COandXAppUi::InternalizeL(RReadStream& aStream)
00203 {
00204 iEngine->InternalizeL(aStream);
00205 iController->InternalizeL(aStream);
00206 ReportWhoseTurn();
00207 iAppView->MoveFocusTo(aStream.ReadInt8L());
00208 }
00209
00210
00211
00212
00213 GLDEF_C COandXAppUi* OandXAppUi()
00218 {
00219 return static_cast<COandXAppUi*>(CEikonEnv::Static()->AppUi());
00220 }
00221
00222 GLDEF_C COandXController& Controller()
00227 {
00228 return *OandXAppUi()->iController;
00229 }
00230
00231 GLDEF_C COandXEngine& Engine()
00236 {
00237 return *OandXAppUi()->iEngine;
00238 }