📄 s60uiexampleplayview.cpp
字号:
// 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>
#include <aknnotewrappers.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:
{
// Query if scores are to be reset
CAknQueryDialog* dlg = new (ELeave) CAknQueryDialog();
if (dlg->ExecuteLD(R_S60UIEXAMPLE_CONFIRMATION_QUERY))
{
iModel.GameStart();
HBufC* noteText = StringLoader::LoadLC(R_S60UIEXAMPLE_RESETTING_TEXT, iCoeEnv);
CAknConfirmationNote* startNote = new (ELeave)CAknConfirmationNote;
startNote->ExecuteLD(*noteText);
CleanupStack::PopAndDestroy(noteText);
// 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;
case ES60UIExampleWeapon:
{
// Choose a weapon
TInt index = 0;
CAknListQueryDialog* list =
new(ELeave) CAknListQueryDialog(&index);
// First construct the dialog
list->PrepareLC(R_S60UIEXAMPLE_LIST_QUERY);
// load icons
CAknIconArray* icons = new (ELeave) CAknIconArray(3);
CleanupStack::PushL(icons);
icons->ConstructFromResourceL(R_S60UIEXAMPLE_WEAPON_ICONS);
// Pass to the list (& ownership)
list->SetIconArrayL(icons);
CleanupStack::Pop(icons);
// launch the dialog
if (list->RunLD())
{
// ok pressed, index is the selected item index.
}
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)
{
if (aResourceId == R_S60UIEXAMPLE_PLAYMENU)
{
if (iModel.IsGamePaused())
{
// Yes, paused. Remove "Pause" option
aMenuPane->SetItemDimmed(ES60UIExamplePauseGame, ETrue);
}
else
{
// No, not paused. Remove "Continue" option
aMenuPane->SetItemDimmed(ES60UIExampleContinueGame, ETrue);
}
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -