⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appstatehelpscreen.cpp

📁 RGA: Biowaste Game Example This C++ application demonstrates how to create a 2D mobile game for S60
💻 CPP
字号:

#include "AppStateHelpScreen.h"
#include "ExampleApplication.h"



const TInt KNumHelpPages = 3;



CAppStateHelpScreen::CAppStateHelpScreen(CExampleApplication& aApp)
	: CAppState(aApp),
	  iNextState(EAppUpdateStateContinue)
	{

	}


CAppStateHelpScreen::~CAppStateHelpScreen()
	{
	}


TInt CAppStateHelpScreen::Init()
	{
	return KErrNone;
	}


EAppUpdateState CAppStateHelpScreen::Update(const TReal64& /*aFrametime*/)
	{
	return iNextState;
	}


void CAppStateHelpScreen::Draw(IGraphicsContext& aContext)
	{
	TSize bbsize = App().BackBufferSize();
	TRect screen = TRect(0, 0, bbsize.iWidth, bbsize.iHeight);

	// blend background image
	App().BlendRect(TRect(	0,
			0,
			bbsize.iWidth,
			bbsize.iHeight));
	
	CGraphicsContext* context = App().SystemGc( App().BackBuffer() );
	
	TInt i;
	const CFont* font = App().NormalFont();
	const TInt yinc = font->HeightInPixels();
	const TInt margin = 5;
	context->UseFont(font);
	TInt y = 10 + yinc;
	TRect rc(margin, y, bbsize.iWidth - margin, y + (bbsize.iHeight >> 1));
	
	TInt spritestarty = 80;

	switch (iCurrentPage)
		{
		case 0:	// basic info & radar
			context->SetPenColor(KRgbGreen);
	
			// draw title
			context->DrawText(	KTextHelpTitle,
								screen,
								20,
								CGraphicsContext::ECenter);
		
			// draw instructions
			context->SetPenColor(KRgbWhite);
			y += yinc + DrawTextInBox(	KTextHelpInfo,
										font,
										*context,
										rc);
			
			// radar info
			context->DrawText(	KTextHelpRadar,
								screen,
								y,
								CGraphicsContext::ECenter);
			y += yinc;
			
			context->SetPenColor(KRgbGreen);
			context->DrawText(	KTextHelpRadarGreen,
								screen,
								y,
								CGraphicsContext::ECenter);
			y += yinc;
			
			context->SetPenColor(KRgbYellow);
			context->DrawText(	KTextHelpRadarYellow,
								screen,
								y,
								CGraphicsContext::ECenter);
			y += yinc;
			
			context->SetPenColor(KRgbRed);
			context->DrawText(	KTextHelpRadarRed,
								screen,
								y,
								CGraphicsContext::ECenter);
			y += yinc;

			
			break;
			
		case 1:	// ghosts
			context->SetPenColor(KRgbGreen);
			
			// draw title
			context->DrawText(	KTextHelpGhostsTitle,
								screen,
								20,
								CGraphicsContext::ECenter);
			
			context->SetPenColor(KRgbWhite);
			spritestarty = yinc + DrawTextInBox(	KTextHelpGhostsInfo,
													font,
													*context,
													rc);
			
			// draw ghost descriptions
			rc.iTl.iX = 80;
			rc.iTl.iY = spritestarty;
			rc.iBr.iX = bbsize.iWidth - margin;
			rc.iBr.iY = rc.iTl.iY + 70;
			
			for (i=0; i<3; i++)
				{
				if (i == 0)
					{
					DrawTextInBox(	KTextHelpGhostRed,
									font,
									*context,
									rc);
					}
				else if (i == 1)
					{
					DrawTextInBox(	KTextHelpGhostGreen,
									font,
									*context,
									rc);
					}
				else if (i == 2)
					{
					DrawTextInBox(	KTextHelpGhostBlue,
									font,
									*context,
									rc);
					}
				rc.iTl.iY += 60;
				rc.iBr.iY += 60;
				}
			break;
			
		case 2:	// bonuses
			context->SetPenColor(KRgbGreen);
			
			// draw title
			context->DrawText(	KTextHelpBonusTitle,
								screen,
								20,
								CGraphicsContext::ECenter);
			
			// draw info
			context->SetPenColor(KRgbWhite);
			spritestarty = yinc + DrawTextInBox(	KTextHelpBonusInfo,
													font,
													*context,
													rc);
			
			// draw bonus descriptions
			rc.iTl.iX = 80;
			rc.iTl.iY = spritestarty;
			rc.iBr.iX = bbsize.iWidth - margin;
			rc.iBr.iY = rc.iTl.iY + 70;
			
			for (i=0; i<3; i++)
				{
				if (i == 0)
					{
					DrawTextInBox(	KTextHelpBonusMoney,
									font,
									*context,
									rc);
					}
				else if (i == 1)
					{
					DrawTextInBox(	KTextHelpBonusPower,
									font,
									*context,
									rc);
					}
				else if (i == 2)
					{
					DrawTextInBox(	KTextHelpBonusWater,
									font,
									*context,
									rc);
					}
				rc.iTl.iY += 60;
				rc.iBr.iY += 60;
				}
			break;
		}
					
	
	// draw current page
	TBuf<32> msg;
	msg.Format(_L("%d/%d"), iCurrentPage + 1, KNumHelpPages);
	TPoint pos;
	pos.iX = bbsize.iWidth - font->TextWidthInPixels(msg) - margin;
	pos.iY = bbsize.iHeight - yinc;
	context->SetPenColor(KRgbWhite);
	context->DrawText(msg, pos);
	
	context->DiscardFont();
	App().ApplySystemGc();
	

	
	// after texts drawing
	switch (iCurrentPage)
		{
		case 1:
			// draw ghosts
			for (i=0; i<3; i++)
				{
				IBitmap* ghost = App().Bitmap(KBitmapGhostRed + i);
				if (ghost->Lock() == OK)
					{
					aContext.BitBlit(	CPoint(margin, spritestarty + (i * 60)),
										*ghost);
					ghost->Unlock();
					}
				}
		break;
		case 2:
			// draw bonuses
			for (i=0; i<3; i++)
				{
				IBitmap* bonus = App().Bitmap(KBitmapBonusMoney + i);
				if (bonus->Lock() == OK)
					{
					aContext.BitBlit(	CPoint(margin, spritestarty + (i * 60)),
										*bonus);
					bonus->Unlock();
					}
				}
			break;
		}
	
	
	}


void CAppStateHelpScreen::KeyDown(TUint32 aKeyCode)
	{
	switch (aKeyCode)
		{
		case INPUT_KEY_DIGITAL_LEFT:
			if (--iCurrentPage < 0)
				{
				iCurrentPage = KNumHelpPages - 1;
				}
			App().RePlayAudio(KAudioFileMenuMove);
			break;
			
		case INPUT_KEY_DIGITAL_RIGHT:
			if (++iCurrentPage >= KNumHelpPages)
				{
				iCurrentPage = 0;
				}
			App().RePlayAudio(KAudioFileMenuMove);
			break;

		default:
			iNextState = EAppUpdateStateInitMenu;
		}
	}


TInt CAppStateHelpScreen::DrawTextInBox(	const TDesC& aText,
											const CFont* aFont,
											CGraphicsContext& aGc,
											const TRect& aRect,
											CGraphicsContext::TTextAlign aHrz /*=CGraphicsContext::ELeft*/)
	{
	// draw multiline text
	
	// compute number of lines that fit the rectangle
	TInt i;
	const TInt fontheight = aFont->HeightInPixels();
	const TInt numlines = aRect.Height() / fontheight;
	
	if (numlines == 0 || aText.Length() < 2)
		{
		// rectangle is too small
		return 0;
		}
	
	RArray<TPtrC> lines;

	// go thru the text and find lines
	TInt startindex = 0;
	TInt lastsafebreak = 0;
	for (i=1; i<aText.Length(); i++)
		{
		// check potential line breaker
		if (	aText[i] == ' ' ||
				i == aText.Length() - 1)
			{
			// get the text from startindex to this
			TPtrC tmp(aText.Mid(startindex, i - startindex + 1));
			
			if (aFont->TextWidthInPixels(tmp) > aRect.Width())
				{
				// text is longer than rectangle width, or this is a last character
				TPtrC tmp2(aText.Mid(startindex, lastsafebreak - startindex + 1));
				lines.Append(tmp2);

				startindex = lastsafebreak + 1;
				i = startindex + 1;
				}
			else if (i == aText.Length() - 1)
				{
				lines.Append(tmp);
				}
			else
				{
				// text is still shorter than rect width
				lastsafebreak = i;
				}
			}
		}
	
	// draw the lines
	TInt y = fontheight;
	for (i=0; i<lines.Count(); i++)
		{
		aGc.DrawText(lines[i], aRect, y, aHrz);
		y += fontheight;
		}
	
	lines.Reset();
	return y;
	}

⌨️ 快捷键说明

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