mopoidcontainerview.cpp

来自「mopoid game symbian os application devel」· C++ 代码 · 共 376 行

CPP
376
字号
/*
 ========================================================================
 Name        : MopoidContainerView.cpp
 Author      : 
 Copyright   : 
 Description : Manages the container of this view.
 License     : 

 ========================================================================
 */
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <akncontext.h>
#include <akntitle.h>
#include <stringloader.h>
#include <barsread.h>
#include <eikbtgpc.h>
#include <aknnotewrappers.h>
#include <Mopoid.rsg>
// ]]] end generated region [Generated System Includes]

// [[[ begin generated region: do not modify [Generated User Includes]

#include "Mopoid.hrh"
#include "MopoidContainerView.h"
#include "MopoidContainer.hrh"
#include "MopoidContainer.h"
// ]]] end generated region [Generated User Includes]

// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]

/**
 * First phase of Symbian two-phase construction. Should not contain any
 * code that could leave.
 */
CMopoidContainerView::CMopoidContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iMopoidContainer = NULL;
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * The view's destructor removes the container from the control
 * stack and destroys it.
 */
CMopoidContainerView::~CMopoidContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iMopoidContainer;
	iMopoidContainer = NULL;
	// ]]] end generated region [Generated Contents]
	
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance then calls the second-phase constructor
 * without leaving the instance on the cleanup stack.
 * @return new instance of CMopoidContainerView
 */
CMopoidContainerView* CMopoidContainerView::NewL()
	{
	CMopoidContainerView* self = CMopoidContainerView::NewLC();
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance, pushes it on the cleanup stack,
 * then calls the second-phase constructor.
 * @return new instance of CMopoidContainerView
 */
CMopoidContainerView* CMopoidContainerView::NewLC()
	{
	CMopoidContainerView* self = new ( ELeave ) CMopoidContainerView();
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
	}


/**
 * Second-phase constructor for view.  
 * Initialize contents from resource.
 */ 
void CMopoidContainerView::ConstructL()
	{
	// [[[ begin generated region: do not modify [Generated Code]
	BaseConstructL( R_MOPOID_CONTAINER_MOPOID_CONTAINER_VIEW );
				
	// ]]] end generated region [Generated Code]
	
	// add your own initialization code here
	
	}

/**
 * @return The UID for this view
 */
TUid CMopoidContainerView::Id() const
	{
	return TUid::Uid( EMopoidContainerViewId );
	}

/**
 * Handle a command for this view (override)
 * @param aCommand command id to be handled
 */
void CMopoidContainerView::HandleCommandL( TInt aCommand )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	TBool commandHandled = EFalse;
	switch ( aCommand )
		{	// code to dispatch to the AknView's menu and CBA commands is generated here
		case EMopoidContainerViewStart_new_gameMenuItemCommand:
			commandHandled = HandleStart_new_gameMenuItemSelectedL( aCommand );
			break;
		case EMopoidContainerViewSound_OnMenuItemCommand:
			commandHandled = HandleSound_OnMenuItemSelectedL( aCommand );
			break;
		case EMopoidContainerViewSound_OffMenuItemCommand:
			commandHandled = HandleSound_OffMenuItemSelectedL( aCommand );
			break;
		case EMopoidContainerViewAboutMenuItemCommand:
			commandHandled = HandleAboutMenuItemSelectedL( aCommand );
			break;
		default:
			break;
		}
	
		
	if ( !commandHandled ) 
		{
	
		if ( aCommand == EAknSoftkeyExit )
			{
			AppUi()->HandleCommandL( EEikCmdExit );
			}
	
		}
	// ]]] end generated region [Generated Code]
	
	}

/**
 *	Handles user actions during activation of the view, 
 *	such as initializing the content.
 */
void CMopoidContainerView::DoActivateL( 
		const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/,
		const TDesC8& /*aCustomMessage*/ )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	SetupStatusPaneL();
	
				
	if ( iMopoidContainer == NULL )
		{
		iMopoidContainer = CreateContainerL();
		iMopoidContainer->SetMopParent( this );
		AppUi()->AddToStackL( *this, iMopoidContainer );
		} 
	// ]]] end generated region [Generated Contents]
	
	}

/**
 */
void CMopoidContainerView::DoDeactivate()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CleanupStatusPane();
	
	if ( iMopoidContainer != NULL )
		{
		AppUi()->RemoveFromViewStack( *this, iMopoidContainer );
		delete iMopoidContainer;
		iMopoidContainer = NULL;
		}
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * Handle status pane size change for this view (override)
 */
void CMopoidContainerView::HandleStatusPaneSizeChange()
	{
	CAknView::HandleStatusPaneSizeChange();
	
	// this may fail, but we're not able to propagate exceptions here
	TVwsViewId view;	AppUi()->GetActiveViewId( view );	if ( view.iViewUid == Id() )		{		TInt result;		TRAP( result, SetupStatusPaneL() );		}	
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	
	}

// [[[ begin generated function: do not modify
void CMopoidContainerView::SetupStatusPaneL()
	{
	// reset the context pane
	TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
	CEikStatusPaneBase::TPaneCapabilities subPaneContext = 
		StatusPane()->PaneCapabilities( contextPaneUid );
	if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
		{
		CAknContextPane* context = static_cast< CAknContextPane* > ( 
			StatusPane()->ControlL( contextPaneUid ) );
		context->SetPictureToDefaultL();
		}
	
	// setup the title pane
	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
	CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
		StatusPane()->PaneCapabilities( titlePaneUid );
	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
		{
		CAknTitlePane* title = static_cast< CAknTitlePane* >( 
			StatusPane()->ControlL( titlePaneUid ) );
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_MOPOID_CONTAINER_TITLE_RESOURCE );
		title->SetFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
				
	}

// ]]] end generated function

// [[[ begin generated function: do not modify
void CMopoidContainerView::CleanupStatusPane()
	{
	}

// ]]] end generated function

/**
 *	Creates the top-level container for the view.  You may modify this method's
 *	contents and the CMopoidContainer::NewL() signature as needed to initialize the
 *	container, but the signature for this method is fixed.
 *	@return new initialized instance of CMopoidContainer
 */
CMopoidContainer* CMopoidContainerView::CreateContainerL()
	{
	return CMopoidContainer::NewL( ClientRect(), NULL, this );
	}

/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CMopoidContainerView::HandleAboutMenuItemSelectedL( TInt /*aCommand*/ )
	{
	RunNoteAboutL();
	return ETrue;
	}
				
// [[[ begin generated function: do not modify
/**
 * Show the popup note for noteAbout
 * @param aOverrideText optional override text
 */
void CMopoidContainerView::RunNoteAboutL( const TDesC* aOverrideText )
	{
	CAknInformationNote* note = new ( ELeave ) CAknInformationNote();
	if ( aOverrideText == NULL )
		{
		HBufC* noteText = StringLoader::LoadLC(R_MOPOID_CONTAINER_NOTE_ABOUT);
		note->ExecuteLD( *noteText );
		CleanupStack::PopAndDestroy( noteText );
		}
	else
		{
		note->ExecuteLD( *aOverrideText );
		}
	}
// ]]] end generated function
	/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CMopoidContainerView::HandleStart_new_gameMenuItemSelectedL( TInt aCommand )
	{
	// Menu command: Start a new game
	if (iMopoidContainer->iGameEngine)
		iMopoidContainer->iGameEngine->StartNewGameL();
	return ETrue;
	}
				
//------------------------------------------------------------------------------
// Handle any change of focus
void CMopoidContainerView::HandleForegroundEventL(TBool aForeground)
	{
	if (aForeground) // gained focus
		{
		// Don't resume the game - wait for user to resume it
		if (iMopoidContainer && iMopoidContainer->iGameEngine)
			{
			iMopoidContainer->iGameEngine->iHaveFocus = ETrue;
			}
		}
	else // lost focus
		{
		// Pause game
		if (iMopoidContainer && iMopoidContainer->iGameEngine)
			{
			iMopoidContainer->iGameEngine->PauseGame();
			iMopoidContainer->iGameEngine->iHaveFocus = EFalse;
			}
		}

	// call base class event handler
	CAknView::HandleForegroundEventL(aForeground);
	}

/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CMopoidContainerView::HandleSound_OnMenuItemSelectedL( TInt aCommand )
	{
	if (iMopoidContainer && iMopoidContainer->iGameEngine)
		{
		iMopoidContainer->iGameEngine->SetSoundLevelL(ETrue);
		}
	return ETrue;
	}
				
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CMopoidContainerView::HandleSound_OffMenuItemSelectedL( TInt aCommand )
	{
	if (iMopoidContainer && iMopoidContainer->iGameEngine)
			{
			iMopoidContainer->iGameEngine->SetSoundLevelL(EFalse);
			}
	return ETrue;
	}
		
// ------------------------------------------------------------------------------
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
//
void CMopoidContainerView::DynInitMenuPaneL(TInt aResourceId,
		CEikMenuPane* aMenuPane)
	{
	if (R_MOPOID_CONTAINER_MENU_PANE1_MENU_PANE == aResourceId && iMopoidContainer && iMopoidContainer->iGameEngine)
		{
		aMenuPane->SetItemDimmed(EMopoidContainerViewSound_OnMenuItemCommand, iMopoidContainer->iGameEngine->IsSoundOn());
		aMenuPane->SetItemDimmed(EMopoidContainerViewSound_OffMenuItemCommand, !iMopoidContainer->iGameEngine->IsSoundOn());
		}
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?