www.pudn.com > GameEngine_src.rar > CMessageManager.cpp


// CMessageManager.cpp: implementation of the CMessageManager class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "CMessageManager.h" 
 
extern PEASYDRAW	g_pEasyDraw; 
 
const int NUM_MSG = 8; 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
CMessageManager::CMessageManager() 
{ 
	m_NormalMsgSurface = NULL;	 
	m_NormalMsgLastTick = 0; 
} 
 
CMessageManager::~CMessageManager() 
{ 
 
} 
 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
bool CMessageManager::Init() 
{ 
	int h = CEasyDraw::g_CharHeight * NUM_MSG; 
	int w = CEasyDraw::g_CharWidth * 16; 
 
	m_NormalMsgSurface = g_pEasyDraw->CreateSurfaceEx( NULL, w, h, true, true, 0 ); 
	if ( m_NormalMsgSurface == 0 ) 
		return false; 
 
	m_NormalMsgHeight = h; 
 
	return true; 
} 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
void CMessageManager::Free() 
{ 
} 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
void CMessageManager::UpdateAndDraw() 
{ 
	if ( m_NormalMsgArray.GetLength() > 0 ) 
	{ 
		unsigned int ThisTick = timeGetTime(); 
		if ( ThisTick - m_NormalMsgLastTick > 5000 ) 
		{ 
			m_NormalMsgLastTick = ThisTick; 
			m_NormalMsgHeight -= CEasyDraw::g_CharHeight; 
			if ( m_NormalMsgHeight < 0 ) 
			{ 
				m_NormalMsgHeight = 0; 
				m_NormalMsgArray.Delete( 0 ); 
 
				if ( m_NormalMsgArray.IsEmpty() ) 
				{ 
					m_NormalMsgHeight = m_NormalMsgSurface->GetHeight(); 
					return; 
				} 
			} 
			 
			m_NormalMsgSurface->ClearSurface( 0, 0 ); 
			m_NormalMsgSurface->BeginDrawText( 0, m_NormalMsgHeight ); 
			for ( int i = 0; i < m_NormalMsgArray.GetLength(); ++i ) 
			{ 
				m_NormalMsgSurface->DrawText( m_NormalMsgArray[i].c_str(), 0xff00, 0 ); 
			} 
			m_NormalMsgSurface->EndDrawText(); 
		} 
 
		int h = g_pEasyDraw->GetDeviceHeight() - m_NormalMsgSurface->GetHeight() - 128; 
		m_NormalMsgSurface->DrawSurface( 0, h, 0 ); 
	} 
} 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
void CMessageManager::AddMessage( const char *msg ) 
{ 
	string str = msg; 
	m_NormalMsgArray.Add( str ); 
	m_NormalMsgLastTick = 0; 
	//m_NormalMsgHeight -= CEasyDraw::g_CharHeight; 
	//if ( m_NormalMsgHeight < 0 ) 
	//{ 
		//m_NormalMsgHeight = 0; 
		//m_NormalMsgArray.Delete( 0 ); 
	//} 
}