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

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. // -----------------------------------------------------------------------------
  13. // CS60UIExamplePlayView::CS60UIExamplePlayView()
  14. // C++ default constructor can NOT contain any code, that might leave.
  15. // -----------------------------------------------------------------------------
  16. //
  17. CS60UIExamplePlayView::CS60UIExamplePlayView(CS60UIExampleModel& aModel)
  18.     :iModel(aModel)
  19.     {
  20.     }
  21. // -----------------------------------------------------------------------------
  22. // CS60UIExamplePlayView::NewL()
  23. // Two-phased constructor.
  24. // -----------------------------------------------------------------------------
  25. //
  26. CS60UIExamplePlayView* CS60UIExamplePlayView::NewL(CS60UIExampleModel& aModel)
  27.     {
  28.     CS60UIExamplePlayView* self = CS60UIExamplePlayView::NewLC(aModel);
  29.     CleanupStack::Pop(self);
  30.     return self;
  31.     }
  32. // -----------------------------------------------------------------------------
  33. // CS60UIExamplePlayView::NewLC()
  34. // Two-phased constructor.
  35. // -----------------------------------------------------------------------------
  36. //
  37. CS60UIExamplePlayView* CS60UIExamplePlayView::NewLC(CS60UIExampleModel& aModel)
  38.     {
  39.     CS60UIExamplePlayView* self = new (ELeave) CS60UIExamplePlayView(aModel);
  40.     CleanupStack::PushL(self);
  41.     self->ConstructL();
  42.     return self;
  43.     }
  44. // -----------------------------------------------------------------------------
  45. // CS60UIExamplePlayView::ConstructL()
  46. // Symbian 2nd phase constructor can leave.
  47. // -----------------------------------------------------------------------------
  48. //
  49. void CS60UIExamplePlayView::ConstructL()
  50.     {
  51.     BaseConstructL(R_S60UIEXAMPLE_PLAYVIEW);
  52.     }
  53. // -----------------------------------------------------------------------------
  54. // CS60UIExamplePlayView::~CS60UIExamplePlayView()
  55. // Destructor.
  56. // -----------------------------------------------------------------------------
  57. //
  58. CS60UIExamplePlayView::~CS60UIExamplePlayView()
  59.     {
  60.     // No implementation required
  61.     }
  62. // -----------------------------------------------------------------------------
  63. // CS60UIExamplePlayView::Id()
  64. // Returns View's ID.
  65. // -----------------------------------------------------------------------------
  66. //
  67. TUid CS60UIExamplePlayView::Id() const
  68.     {
  69.     return TUid::Uid(ES60UIExamplePlayViewId);
  70.     }
  71. // -----------------------------------------------------------------------------
  72. // CS60UIExamplePlayView::DoActivateL()
  73. // Activate the View
  74. // -----------------------------------------------------------------------------
  75. //
  76. void CS60UIExamplePlayView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
  77.                                         TUid /*aCustomMessageId*/,
  78.                                         const TDesC8& /*aCustomMessage*/)
  79.     {
  80.     iContainer = CS60UIExamplePlayContainer::NewL(ClientRect(), iModel);
  81.     AppUi()->AddToStackL(*this, iContainer);
  82.     }
  83. // -----------------------------------------------------------------------------
  84. // CS60UIExamplePlayView::DoDeactivate()
  85. // -----------------------------------------------------------------------------
  86. //
  87. void CS60UIExamplePlayView::DoDeactivate()
  88.     {
  89.     if (iContainer)
  90.         {
  91.         AppUi()->RemoveFromStack(iContainer);
  92.         delete iContainer;
  93.         iContainer = NULL;
  94.         }
  95.         
  96.     }
  97. // -----------------------------------------------------------------------------
  98. // CS60UIExamplePlayView::HandleCommandL()
  99. // Takes care of Command handling.
  100. // -----------------------------------------------------------------------------
  101. //
  102. void CS60UIExamplePlayView::HandleCommandL(TInt aCommand)
  103.     {
  104.     switch (aCommand)
  105.         {
  106.         case ES60UIExampleStopGame:
  107.             {
  108.             iModel.GameStop();
  109.             // Query if score to be entered into HighScores
  110.             CAknQueryDialog* dlg = new (ELeave) CAknQueryDialog();
  111.             if (dlg->ExecuteLD(R_S60UIEXAMPLE_ENTER_SCORE_QUERY))
  112.                 {
  113.                 // Yes. Get player to enter name
  114.                 TBuf<20> name;
  115.                 name.Copy(KNullDesC);
  116.                 CAknTextQueryDialog* txtDlg = 
  117.                      new (ELeave) CAknTextQueryDialog(name);
  118.                 txtDlg->SetPredictiveTextInputPermitted(ETrue); 
  119.                 if (txtDlg->ExecuteLD(R_S60UIEXAMPLE_NAME_QUERY))
  120.                     {
  121.                     // Got name. Insert name and score in highscore list
  122.                     iModel.InsertInHighScoresL(name, iModel.Score());
  123.                     } 
  124.                 }
  125.                 
  126.             // Switch back to initial view
  127.             AppUi()->ActivateLocalViewL(TUid::Uid(ES60UIExampleInitialViewId));
  128.             break;
  129.             }
  130.             
  131.         case ES60UIExampleStartGame:
  132.             {
  133.             iModel.GameStart();
  134.             // Get reset scores to navi pane
  135.             iContainer->UpdateNaviPaneL();
  136.             // Draw game image (without paused text)
  137.             iContainer->DrawNow();
  138.             break;
  139.             }
  140.             
  141.         case ES60UIExampleContinueGame:
  142.             iModel.GameContinue();
  143.             // Draw game image (without paused text)
  144.             iContainer->DrawNow();
  145.             break;
  146.             
  147.         case ES60UIExamplePauseGame:
  148.             iModel.GamePause();
  149.             // Draw game image (with paused text)
  150.             iContainer->DrawNow();
  151.             break;
  152.             
  153.         default:
  154.             // pass anything else to the AppUi
  155.             AppUi()->HandleCommandL(aCommand);
  156.         }
  157.     }
  158.     
  159. // -----------------------------------------------------------------------------
  160. // CS60UIExamplePlayView::DynInitMenuPaneL()
  161. // Used to remove unwanted options from the options menu
  162. // -----------------------------------------------------------------------------
  163. //
  164. void CS60UIExamplePlayView::
  165.     DynInitMenuPaneL(TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/)
  166.     {
  167.     }
  168. // End of File