- // Copyright (c) 2006 Nokia Corporation.
- #include "S60UIExamplePlayView.h"
- #include "S60UIExamplePlayContainer.h"
- #include "S60UIExampleModel.h"
- #include "S60UIExample.hrh"
- #include <aknviewappui.h>
- #include <S60UIExample.rsg>
- #include <eikmenup.h> // for CEikMenuPane
- #include <aknquerydialog.h>
- #include <akniconarray.h> // for (weapon) icon array
- #include <stringloader.h>
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::CS60UIExamplePlayView()
- // C++ default constructor can NOT contain any code, that might leave.
- // -----------------------------------------------------------------------------
- //
- CS60UIExamplePlayView::CS60UIExamplePlayView(CS60UIExampleModel& aModel)
- :iModel(aModel)
- {
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::NewL()
- // Two-phased constructor.
- // -----------------------------------------------------------------------------
- //
- CS60UIExamplePlayView* CS60UIExamplePlayView::NewL(CS60UIExampleModel& aModel)
- {
- CS60UIExamplePlayView* self = CS60UIExamplePlayView::NewLC(aModel);
- CleanupStack::Pop(self);
- return self;
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::NewLC()
- // Two-phased constructor.
- // -----------------------------------------------------------------------------
- //
- CS60UIExamplePlayView* CS60UIExamplePlayView::NewLC(CS60UIExampleModel& aModel)
- {
- CS60UIExamplePlayView* self = new (ELeave) CS60UIExamplePlayView(aModel);
- CleanupStack::PushL(self);
- self->ConstructL();
- return self;
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::ConstructL()
- // Symbian 2nd phase constructor can leave.
- // -----------------------------------------------------------------------------
- //
- void CS60UIExamplePlayView::ConstructL()
- {
- BaseConstructL(R_S60UIEXAMPLE_PLAYVIEW);
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::~CS60UIExamplePlayView()
- // Destructor.
- // -----------------------------------------------------------------------------
- //
- CS60UIExamplePlayView::~CS60UIExamplePlayView()
- {
- // No implementation required
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::Id()
- // Returns View's ID.
- // -----------------------------------------------------------------------------
- //
- TUid CS60UIExamplePlayView::Id() const
- {
- return TUid::Uid(ES60UIExamplePlayViewId);
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::DoActivateL()
- // Activate the View
- // -----------------------------------------------------------------------------
- //
- void CS60UIExamplePlayView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
- TUid /*aCustomMessageId*/,
- const TDesC8& /*aCustomMessage*/)
- {
- iContainer = CS60UIExamplePlayContainer::NewL(ClientRect(), iModel);
- AppUi()->AddToStackL(*this, iContainer);
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::DoDeactivate()
- // -----------------------------------------------------------------------------
- //
- void CS60UIExamplePlayView::DoDeactivate()
- {
- if (iContainer)
- {
- AppUi()->RemoveFromStack(iContainer);
- delete iContainer;
- iContainer = NULL;
- }
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::HandleCommandL()
- // Takes care of Command handling.
- // -----------------------------------------------------------------------------
- //
- void CS60UIExamplePlayView::HandleCommandL(TInt aCommand)
- {
- switch (aCommand)
- {
- case ES60UIExampleStopGame:
- {
- iModel.GameStop();
- // Query if score to be entered into HighScores
- CAknQueryDialog* dlg = new (ELeave) CAknQueryDialog();
- if (dlg->ExecuteLD(R_S60UIEXAMPLE_ENTER_SCORE_QUERY))
- {
- // Yes. Get player to enter name
- TBuf<20> name;
- name.Copy(KNullDesC);
- CAknTextQueryDialog* txtDlg =
- new (ELeave) CAknTextQueryDialog(name);
- txtDlg->SetPredictiveTextInputPermitted(ETrue);
- if (txtDlg->ExecuteLD(R_S60UIEXAMPLE_NAME_QUERY))
- {
- // Got name. Insert name and score in highscore list
- iModel.InsertInHighScoresL(name, iModel.Score());
- }
- }
- // Switch back to initial view
- AppUi()->ActivateLocalViewL(TUid::Uid(ES60UIExampleInitialViewId));
- break;
- }
- case ES60UIExampleStartGame:
- {
- iModel.GameStart();
- // Get reset scores to navi pane
- iContainer->UpdateNaviPaneL();
- // Draw game image (without paused text)
- iContainer->DrawNow();
- break;
- }
- case ES60UIExampleContinueGame:
- iModel.GameContinue();
- // Draw game image (without paused text)
- iContainer->DrawNow();
- break;
- case ES60UIExamplePauseGame:
- iModel.GamePause();
- // Draw game image (with paused text)
- iContainer->DrawNow();
- break;
- default:
- // pass anything else to the AppUi
- AppUi()->HandleCommandL(aCommand);
- }
- }
- // -----------------------------------------------------------------------------
- // CS60UIExamplePlayView::DynInitMenuPaneL()
- // Used to remove unwanted options from the options menu
- // -----------------------------------------------------------------------------
- //
- void CS60UIExamplePlayView::
- DynInitMenuPaneL(TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/)
- {
- }
- // End of File