S60UIExamplePlayView.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:8k
源码类别:

Symbian

开发平台:

C/C++

  1. // Copyright (c) 2006 Nokia Corporation.
  2. #include "S60UIExamplePlayView.h"
  3. #include "S60UIExamplePlayContainer.h"
  4. #include "S60UIExampleModel.h"
  5. #include "S60UIExample.hrh"
  6. #include <aknviewappui.h>
  7. #include <S60UIExample.rsg>
  8. #include <eikmenup.h>           // for CEikMenuPane
  9. #include <aknquerydialog.h>
  10. #include <akniconarray.h>    // for (weapon) icon array
  11. #include <stringloader.h>    
  12. #include <aknnotewrappers.h>
  13. // -----------------------------------------------------------------------------
  14. // CS60UIExamplePlayView::CS60UIExamplePlayView()
  15. // C++ default constructor can NOT contain any code, that might leave.
  16. // -----------------------------------------------------------------------------
  17. //
  18. CS60UIExamplePlayView::CS60UIExamplePlayView(CS60UIExampleModel& aModel)
  19.     :iModel(aModel)
  20.     {
  21.     }
  22. // -----------------------------------------------------------------------------
  23. // CS60UIExamplePlayView::NewL()
  24. // Two-phased constructor.
  25. // -----------------------------------------------------------------------------
  26. //
  27. CS60UIExamplePlayView* CS60UIExamplePlayView::NewL(CS60UIExampleModel& aModel)
  28.     {
  29.     CS60UIExamplePlayView* self = CS60UIExamplePlayView::NewLC(aModel);
  30.     CleanupStack::Pop(self);
  31.     return self;
  32.     }
  33. // -----------------------------------------------------------------------------
  34. // CS60UIExamplePlayView::NewLC()
  35. // Two-phased constructor.
  36. // -----------------------------------------------------------------------------
  37. //
  38. CS60UIExamplePlayView* CS60UIExamplePlayView::NewLC(CS60UIExampleModel& aModel)
  39.     {
  40.     CS60UIExamplePlayView* self = new (ELeave) CS60UIExamplePlayView(aModel);
  41.     CleanupStack::PushL(self);
  42.     self->ConstructL();
  43.     return self;
  44.     }
  45. // -----------------------------------------------------------------------------
  46. // CS60UIExamplePlayView::ConstructL()
  47. // Symbian 2nd phase constructor can leave.
  48. // -----------------------------------------------------------------------------
  49. //
  50. void CS60UIExamplePlayView::ConstructL()
  51.     {
  52.     BaseConstructL(R_S60UIEXAMPLE_PLAYVIEW);
  53.     }
  54. // -----------------------------------------------------------------------------
  55. // CS60UIExamplePlayView::~CS60UIExamplePlayView()
  56. // Destructor.
  57. // -----------------------------------------------------------------------------
  58. //
  59. CS60UIExamplePlayView::~CS60UIExamplePlayView()
  60.     {
  61.     // No implementation required
  62.     }
  63. // -----------------------------------------------------------------------------
  64. // CS60UIExamplePlayView::Id()
  65. // Returns View's ID.
  66. // -----------------------------------------------------------------------------
  67. //
  68. TUid CS60UIExamplePlayView::Id() const
  69.     {
  70.     return TUid::Uid(ES60UIExamplePlayViewId);
  71.     }
  72. // -----------------------------------------------------------------------------
  73. // CS60UIExamplePlayView::DoActivateL()
  74. // Activate the View
  75. // -----------------------------------------------------------------------------
  76. //
  77. void CS60UIExamplePlayView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
  78.                                         TUid /*aCustomMessageId*/,
  79.                                         const TDesC8& /*aCustomMessage*/)
  80.     {
  81.     iContainer = CS60UIExamplePlayContainer::NewL(ClientRect(), iModel);
  82.     AppUi()->AddToStackL(*this, iContainer);
  83.     }
  84. // -----------------------------------------------------------------------------
  85. // CS60UIExamplePlayView::DoDeactivate()
  86. // -----------------------------------------------------------------------------
  87. //
  88. void CS60UIExamplePlayView::DoDeactivate()
  89.     {
  90.     if (iContainer)
  91.         {
  92.         AppUi()->RemoveFromStack(iContainer);
  93.         delete iContainer;
  94.         iContainer = NULL;
  95.         }
  96.         
  97.     }
  98. // -----------------------------------------------------------------------------
  99. // CS60UIExamplePlayView::HandleCommandL()
  100. // Takes care of Command handling.
  101. // -----------------------------------------------------------------------------
  102. //
  103. void CS60UIExamplePlayView::HandleCommandL(TInt aCommand)
  104.     {
  105.     switch (aCommand)
  106.         {
  107.         case ES60UIExampleStopGame:
  108.             {
  109.             iModel.GameStop();
  110.             // Query if score to be entered into HighScores
  111.             CAknQueryDialog* dlg = new (ELeave) CAknQueryDialog();
  112.             if (dlg->ExecuteLD(R_S60UIEXAMPLE_ENTER_SCORE_QUERY))
  113.                 {
  114.                 // Yes. Get player to enter name
  115.                 TBuf<20> name;
  116.                 name.Copy(KNullDesC);
  117.                 CAknTextQueryDialog* txtDlg = 
  118.                      new (ELeave) CAknTextQueryDialog(name);
  119.                 txtDlg->SetPredictiveTextInputPermitted(ETrue); 
  120.                 if (txtDlg->ExecuteLD(R_S60UIEXAMPLE_NAME_QUERY))
  121.                     {
  122.                     // Got name. Insert name and score in highscore list
  123.                     iModel.InsertInHighScoresL(name, iModel.Score());
  124.                     } 
  125.                 }
  126.                 
  127.             // Switch back to initial view
  128.             AppUi()->ActivateLocalViewL(TUid::Uid(ES60UIExampleInitialViewId));
  129.             break;
  130.             }
  131.             
  132.         case ES60UIExampleStartGame:
  133.             {
  134.             // Query if scores are to be reset
  135.             CAknQueryDialog* dlg = new (ELeave) CAknQueryDialog();
  136.             if (dlg->ExecuteLD(R_S60UIEXAMPLE_CONFIRMATION_QUERY))
  137.                 {
  138.             iModel.GameStart();
  139.             
  140.             HBufC* noteText = StringLoader::LoadLC(R_S60UIEXAMPLE_RESETTING_TEXT, iCoeEnv);
  141.          CAknConfirmationNote* startNote = new (ELeave)CAknConfirmationNote;
  142.          startNote->ExecuteLD(*noteText);
  143.          CleanupStack::PopAndDestroy(noteText);
  144.         
  145.             // Get reset scores to navi pane
  146.             iContainer->UpdateNaviPaneL();
  147.             
  148.             // Draw game image (without paused text)
  149.             iContainer->DrawNow();
  150.                 }
  151.                 
  152.             break;
  153.             }
  154.             
  155.         case ES60UIExampleContinueGame:
  156.             iModel.GameContinue();
  157.             // Draw game image (without paused text)
  158.             iContainer->DrawNow();
  159.             break;
  160.             
  161.         case ES60UIExamplePauseGame:
  162.             iModel.GamePause();
  163.             // Draw game image (with paused text)
  164.             iContainer->DrawNow();
  165.             break;
  166.             
  167.         case ES60UIExampleWeapon:
  168.             {
  169.             // Choose a weapon
  170.             TInt index = 0;
  171.             CAknListQueryDialog* list = 
  172.                           new(ELeave) CAknListQueryDialog(&index);
  173.                           
  174.             // First construct the dialog
  175.     list->PrepareLC(R_S60UIEXAMPLE_LIST_QUERY);
  176.     
  177.     // load icons
  178.     CAknIconArray* icons = new (ELeave) CAknIconArray(3);
  179.     CleanupStack::PushL(icons);
  180.     icons->ConstructFromResourceL(R_S60UIEXAMPLE_WEAPON_ICONS);
  181.     
  182.     // Pass to the list (& ownership)
  183.     list->SetIconArrayL(icons);
  184.     CleanupStack::Pop(icons);
  185.     
  186.     // launch the dialog   
  187.     if (list->RunLD())
  188.                 {
  189.                 // ok pressed, index is the selected item index.
  190.                 }
  191.                 
  192.             break;
  193.             }
  194.         
  195.         default:
  196.             // pass anything else to the AppUi
  197.             AppUi()->HandleCommandL(aCommand);
  198.         }
  199.     }
  200.     
  201. // -----------------------------------------------------------------------------
  202. // CS60UIExamplePlayView::DynInitMenuPaneL()
  203. // Used to remove unwanted options from the options menu
  204. // -----------------------------------------------------------------------------
  205. //
  206. void CS60UIExamplePlayView::
  207.     DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
  208.     {
  209.     if (aResourceId == R_S60UIEXAMPLE_PLAYMENU)
  210.         {
  211.         if (iModel.IsGamePaused())
  212.             {
  213.             // Yes, paused. Remove "Pause" option
  214.             aMenuPane->SetItemDimmed(ES60UIExamplePauseGame, ETrue);
  215.             }
  216.         else
  217.             {
  218.             // No, not paused. Remove "Continue" option
  219.             aMenuPane->SetItemDimmed(ES60UIExampleContinueGame, ETrue);
  220.             }
  221.         }
  222.     }
  223. // End of File