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

📄 gamemsg.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// GameMsg.cpp: implementation of the GameMsg class.
//
//////////////////////////////////////////////////////////////////////

#include "basefunc.H"
#include "nd_bitmap.H"
#include "GameMsg.h"
#include "Player.h"
#include "Hero.h"
#include "GameDataSet.h"
#include "3droledata.h"
//--------------------------------------------------------------------
// define string constants
//--------------------------------------------------------------------
const int  FONT_EDGE_COLOR				= 0x000000;

const OBJID STRING_PREFIX_GLOBAL		= 100005;//"【千里传音】";
const OBJID STRING_PREFIX_SYSTEM		= 100006;//"【系统】";
const OBJID STRING_PREFIX_ACTION		= 100007;//"【动作】";
const OBJID STRING_PREFIX_WHISPER		= 100008;//"【私聊】";
const OBJID STRING_PREFIX_TEAM			= 100009;//"【队伍】";
const OBJID STRING_PREFIX_CLAN			= 100010;//"【帮派】";
const OBJID STRING_PREFIX_FAMILY		= 100011;//"【家庭】";
const OBJID STRING_PREFIX_TALK			= 100012;//"【交谈】";
const OBJID STRING_PREFIX_YELP			= 100013;//"【叫喊】";
const OBJID STRING_PREFIX_FRIEND		= 100014;//"【朋友】";
const OBJID STRING_PREFIX_GM			= 100015;//"【GM】";
const OBJID STRING_PREFIX_GHOST			= 100016;//"【幽灵】";
const OBJID STRING_PREFIX_LEAVEWORD		= 100119;//"【留言】";
const OBJID STRING_PREFIX_SERVE			= 100157;//"【服务】";

const OBJID STRING_TO					= 100017;//"对";
const OBJID STRING_SAY					= 100018;//"说:";

const OBJID STR_SYSTEM					= 100020;
const OBJID STR_ALLUSERS				= 100026;

const char STRING_SYSTEM[]				= "SYSTEM";
const char STRING_ALL_USERS[]			= "ALLUSERS";

const int	LAST_SHOWLINE_INDEX			= 17;
const int	FONT_NAME					= 10049;
const int  MSGFONT_WIDTH				= 7;
const int  MSGFONT_HEIGHT				= 14;
const int  WARNING_CHAR1				= 100300;		//"密";
const int  WARNING_CHAR2				= 100301;		//"码";
const int  WARNING_CHAR3				= 100302;		//"MIMA";
const int  WARNING_CHAR4				= 100303;		//"PASSWORD";
//--------------------------------------------------------------------

// global...
CGameMsg	g_objGameMsg;
#ifdef _ANALYSIS_ON
DWORD g_dwTxtMsgTimeCost	= 0;
#endif

//--------------------------------------------------------------------
// CGameMsgUnit Construction/Destruction
//--------------------------------------------------------------------
CGameMsgUnit::CGameMsgUnit(void)
{
	this->m_nPrevPosX	= 0;
	this->m_nPrevPosY	= 0;
	this->m_dwTime		= 2500;
	this->m_nStartX		= 0;
	this->m_nDragStep	= 0;
	this->m_nQuakeFlag	= 1;
	this->m_bSuper		= false;

	memset(m_szSender, 0L, sizeof(m_szSender));
	memset(m_szReceiver, 0L, sizeof(m_szReceiver));
	memset(m_szEmotion, 0L, sizeof(m_szEmotion));
	memset(m_szMsg, 0L, sizeof(m_szMsg));

//	CMyBitmap::GetFontSize(m_sizeFont);
	m_sizeFont.iWidth = MSGFONT_WIDTH;
	m_sizeFont.iHeight = MSGFONT_HEIGHT;
	CMyBitmap::GetScreenSize(m_sizeScreen.iWidth, m_sizeScreen.iHeight);
}
//--------------------------------------------------------------------
CGameMsgUnit::~CGameMsgUnit(void)
{
	return;
}
//--------------------------------------------------------------------
void CGameMsgUnit::GetDateTimeStr(DWORD dwDateTime, char* pszStr)
{
	// DWORD: 2002-10-10,10:20  200210101020
	char szTemp[64];
	int nYear, nMonth, nDay, nHour, nMinute;
	nYear	= dwDateTime/100000000;
	nMonth	= (dwDateTime/1000000)%100;
	nDay	= (dwDateTime/10000)%100;
	nHour	= (dwDateTime/100)%100;
	nMinute	= dwDateTime%100;
	sprintf(szTemp,"【%d:%d】", nHour, nMinute);
	strcpy(pszStr, szTemp);
}
//--------------------------------------------------------------------
char* CGameMsgUnit::Show(int nStartX, int nStartY, BOOL bCapture, int nScreenWidth)
{
	if(m_nDragStep == 0)
	{
		m_nStartX = nScreenWidth;
		m_nDragStep = 1;
	}

	if(this->m_unTxtStyle & 0x0001) // 拖动效果
	{
		if(nStartX < m_nStartX)
			m_nStartX = m_nStartX - 6;
		else
			m_nStartX = nStartX;
	}
	else
	{
		m_nStartX = nStartX;
	}


	if(this->m_unTxtStyle & 0x0002 && (::TimeGet() - this->m_dwBeginTime) <=  3000) // 闪烁效果
	{
		this->m_dwWordsColorFlash += 0x00000500;
		if(this->m_dwWordsColorFlash > 0xFF00FF00)
			this->m_dwWordsColorFlash = _COLOR_SYSTEM_SPEAKER;
		this->m_dwSystemColor			= this->m_dwWordsColorFlash;
		this->m_dwSystemMessageColor	= this->m_dwWordsColorFlash;
		this->m_dwSenderColor			= this->m_dwWordsColorFlash;
		this->m_dwEmotionColor			= this->m_dwWordsColorFlash;
		this->m_dwNormalColor			= this->m_dwWordsColorFlash;
		this->m_dwReceiverColor			= this->m_dwWordsColorFlash;
		this->m_dwWordsColor			= this->m_dwWordsColorFlash;
	}	
	else
	{
		this->m_dwSystemColor			= _COLOR_SYSTEM_SPEAKER;
		this->m_dwSystemMessageColor	= _COLOR_SYSTEM_MESSAGE;
		this->m_dwSenderColor			= _COLOR_PLAYER_SPEAKER;
		this->m_dwEmotionColor			= _COLOR_EMOTION;
		this->m_dwNormalColor			= _COLOR_NORMAL;
		this->m_dwReceiverColor			= _COLOR_RECEIVER;
	}


	if(this->m_unTxtStyle & 0x0008) // 地震效果
	{
		if(this->m_nQuakeFlag<0)
		{
			if(this->m_nQuakeFlag++>0)
				this->m_nStartX += 2;
		}
		else
		{
			this->m_nQuakeFlag = (-10);
			this->m_nStartX -= 2;
		}
	}
	DWORD dwColorTitle = this->m_dwSystemColor;
	if(strstr(this->m_szMsg, g_objHero.GetName()))
	{
		dwColorTitle = _COLOR_SELF;
	}
	else if(strstr(this->m_szSender, g_objHero.GetName()))
	{
		dwColorTitle = _COLOR_SELF;
	}
	else if(strstr(this->m_szReceiver, g_objHero.GetName()))
	{
		dwColorTitle = _COLOR_SELF;
	}
	// 显示前缀
	CMyPos pos;
	pos.x = m_nStartX;
	pos.y = nStartY;
	switch(this->m_unTxtAttribute)
	{
	case _TXTATR_SYSTEM:
		{
			if(this->m_unTxtStyle & 0x0002 && (::TimeGet() - this->m_dwBeginTime) <=  3000) // 闪烁效果
			{
				pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_SYSTEM), nScreenWidth);
			}
			else
			{
				dwColorTitle = 0XFFFE00FB;
				pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_SYSTEM), nScreenWidth);
				this->m_dwWordsColor = 0XFFFFFF00;				
			}
			break;
		}
	case _TXTATR_ACTION:
		{
			dwColorTitle = 0xFFB9FFC0;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_ACTION), nScreenWidth);
			break;
		}
	case _TXTATR_PRIVATE:
		{
			dwColorTitle = 0xFFFE00FB;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_WHISPER), nScreenWidth);
			break;
		}
	case _TXTATR_TEAM:
		{
			dwColorTitle = 0xFFFE00FB;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_TEAM), nScreenWidth);
			break;
		}
	case _TXTATR_SYNDICATE:
		{
			dwColorTitle = 0xFFFE00FB;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_CLAN), nScreenWidth);
			break;
		}
	case _TXTATR_FAMILY:
		pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_FAMILY), nScreenWidth);
		break;
	case _TXTATR_NORMAL:
	case _TXTATR_TALK:
		if (0 != strcmp(m_szSender, STRING_SYSTEM))
		{
			dwColorTitle = 0xFFFE00FB;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_TALK), nScreenWidth);
		}
		else
		{
			dwColorTitle = 0xFF00FF00;
			this->m_dwWordsColor = 0xFFFFFF00;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_SYSTEM), nScreenWidth);
		}
		break;
	case _TXTATR_YELP:
		pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_YELP), nScreenWidth);
		break;
	case _TXTATR_FRIEND:
		{
			dwColorTitle = 0xFFFE00FB;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_FRIEND), nScreenWidth);
			break;
		}
	case _TXTATR_GLOBAL:
		pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_GLOBAL), nScreenWidth);
		break;
	case _TXTATR_GM:
		pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_GM), nScreenWidth);
		break;
	case _TXTATR_GHOST:
		{
			dwColorTitle = 0xFFFE00FB;
			pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_GHOST), nScreenWidth);
			break;
		}
	case _TXTATR_LEAVEWORD:
		pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_LEAVEWORD), nScreenWidth);
		break;
	case _TXTATR_SERVE:
		pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_SERVE), nScreenWidth);
		break;
	default:
		this->m_unTxtAttribute = _TXTATR_SYSTEM;
		pos = ShowColorStr(pos.x, pos.y, dwColorTitle, g_objGameDataSet.GetStr(STRING_PREFIX_SYSTEM), nScreenWidth);
		break;
	}
	// 显示表情
	if (strlen(this->m_szEmotion)>0)
	{
		char szTemp[_MAX_WORDSSIZE * 2];
		int nIndex=0;
		nIndex = atoi(this->m_szEmotion);
		if(m_unTxtAttribute != _TXTATR_ACTION && m_unTxtAttribute!= _TXTATR_SYSTEM)
			sprintf(szTemp,	g_obj3DRoleData.GetTextActionText(nIndex),
			this->m_szSender,
			this->m_szReceiver);
		pos = ShowColorStr(pos.x, pos.y, m_dwEmotionColor, szTemp, nScreenWidth);
	}
	else		// 显示信息		
	{
		const OBJID idStrSystem=100020;
		if (_TXTATR_ACTION != m_unTxtAttribute &&
				_TXTATR_SYSTEM != m_unTxtAttribute &&
					0 != strcmp(m_szSender, g_objGameDataSet.GetStr(idStrSystem)) &&
						0 != strcmp(m_szSender, STRING_SYSTEM))
		{
			pos = ShowColorStr(pos.x, pos.y, 0xFFB9FFC0, m_szSender, nScreenWidth);
//			pos = ShowColorStr(pos.x, pos.y, m_dwEmotionColor, m_szEmotion, nScreenWidth);
			pos = ShowColorStr(pos.x, pos.y, 0xFFFFFFFF, g_objGameDataSet.GetStr(STRING_TO), nScreenWidth);
			pos = ShowColorStr(pos.x, pos.y, 0xFFB9FFC0, m_szReceiver, nScreenWidth);
			pos = ShowColorStr(pos.x, pos.y, 0xFFFFFFFF, g_objGameDataSet.GetStr(STRING_SAY), nScreenWidth);
		}
	}
	pos = ShowColorStr(pos.x, pos.y, this->m_dwWordsColor, this->m_szMsg, nScreenWidth);

	CMyPos posMouse;
	::MouseCheck(posMouse.x, posMouse.y);
	OBJID idStrAllUser = 100026;
	if(this->m_unTxtAttribute != _TXTATR_SYSTEM && 0 != strcmp(m_szSender, STRING_SYSTEM) && bCapture)
	{
		if ( 0 == strcmp(g_objHero.GetName(), this->m_szSender) && 0 == strcmp(this->m_szReceiver, g_objGameDataSet.GetStr(idStrAllUser)))
			return NULL;
		CMySize sizeFont;
//		CMyBitmap::GetFontSize(sizeFont);
		sizeFont.iWidth = MSGFONT_WIDTH;
		sizeFont.iHeight = MSGFONT_HEIGHT;

		CMyPos posRectBegin, posRectEnd;
		posRectBegin.x = m_nStartX;
		posRectBegin.y = nStartY;
		posRectEnd.x = m_nStartX + nScreenWidth - 2;
		posRectEnd.y = pos.y+sizeFont.iHeight+1;
		if(posMouse.x > posRectBegin.x && posMouse.y > posRectBegin.y && posMouse.x < posRectEnd.x && posMouse.y < posRectEnd.y)
		{
			static DWORD dwFrame = 0;
			dwFrame ++;
			DWORD dwCurrentFrame = dwFrame%31;
			DWORD dwR, dwG, dwB;
			if(dwCurrentFrame <= 15)
			{
				dwR = 0x11*dwCurrentFrame;
				dwG = 0x11*dwCurrentFrame;
				dwB = 0xff - 0x11*dwCurrentFrame;
			}
			else
			{
				dwR = 0xff - 0x11*(31-dwCurrentFrame);
				dwG = 0xff - 0x11*(31-dwCurrentFrame);
				dwB = 0x11*(31-dwCurrentFrame);
			}
			DWORD dwColor = 0xff000000 + (dwR << 16) + (dwG << 8) + dwB;

			CMyBitmap::ShowRect(posRectBegin.x, posRectBegin.y, posRectEnd.x, posRectEnd.y, dwColor);
			if ( 0 != strcmp(g_objHero.GetName(), this->m_szSender) )
				return this->m_szSender;
			else
				return this->m_szReceiver ;
		}
	}	
	/*
	char szTemp[64];
	GetDateTimeStr(m_dwTime, szTemp);
	pos = ShowColorStr(pos.x, pos.y, this->m_dwWordsColor, szTemp); 
	*/

	return NULL;

}
//--------------------------------------------------------------------
int CGameMsgUnit::GetLines( int nScreenWidth )
{
	return Scan(nScreenWidth);
}
//--------------------------------------------------------------------
CMyPos CGameMsgUnit::ShowColorStr(int nPosX, int nPosY
								, DWORD dwColor, const char* pszString, int nScreenWidth)
{
	CMyPos posReturn;
	posReturn.x = nPosX;
	posReturn.y = nPosY;
	
	if (!pszString || strlen(pszString) < 1)
		return posReturn;
	
	const char* buf = pszString;
	while(true)
	{
		int nLineLen = (nScreenWidth - m_sizeFont.iWidth * 2 - posReturn.x) / m_sizeFont.iWidth;
		if (nLineLen <= 0)
		{
			posReturn.x = m_nStartX;
			posReturn.y += m_sizeFont.iHeight + 2;
			continue;
		}
		
		int nStrLen = strlen(buf);
		if (nLineLen >= nStrLen)
		{	// 最后一行
			CMyBitmap::ShowEmotionString(posReturn.x+1, posReturn.y+1, FONT_EDGE_COLOR, buf,m_dwBeginTime,false,(char*)g_objGameDataSet.GetStr(FONT_NAME),MSGFONT_HEIGHT);
			CMyBitmap::ShowEmotionString(posReturn.x, posReturn.y, dwColor, buf ,m_dwBeginTime,true,(char*)g_objGameDataSet.GetStr(FONT_NAME),MSGFONT_HEIGHT);
			
			posReturn.x += m_sizeFont.iWidth * nStrLen;
			break;
		}
		
		if (CMyBitmap::IsDBCSLeadByte(buf, nLineLen - 1))
			nLineLen --;
			
		//----------Begin the english version's process(jump line)----------//
		if ( strcmp( g_objGameDataSet.GetVersionInfo(), "English" ) == 0 )
		{
			// Search the last word
			for ( int i = nLineLen - 1; i >= 0; i-- )
			{
				if ( buf[i] == ' ' )
				{
					nLineLen -= nLineLen - i - 1;
					break;
				}
			}
		}
		//----------End the english version's process(jump line)----------//
		char szFace[3] = "";
		strncpy(szFace, buf + nLineLen-1, 3);		//emotion ani jump line
		if (szFace[0] == '#' 
			&& (szFace[1] >= '0' && szFace[1] <= '9') 
			&&(szFace[1] >= '0' && szFace[1] <= '9')) 
		{
			nLineLen = nLineLen - 1;
		}
		strncpy(szFace, buf + nLineLen-2, 3);		//emotion ani jump line
		if (szFace[0] == '#' 
			&& (szFace[1] >= '0' && szFace[1] <= '9') 
			&&(szFace[1] >= '0' && szFace[1] <= '9')) 
		{
			nLineLen = nLineLen - 2;
		}
		// end emotion ani jump line
		char szMsg[2048] = "";
		strncpy(szMsg, buf, nLineLen);
		
		CMyBitmap::ShowEmotionString(posReturn.x+1, posReturn.y+1, FONT_EDGE_COLOR, szMsg,m_dwBeginTime,false,(char*)g_objGameDataSet.GetStr(FONT_NAME),MSGFONT_HEIGHT);
		CMyBitmap::ShowEmotionString(posReturn.x, posReturn.y, dwColor, szMsg ,m_dwBeginTime,true,(char*)g_objGameDataSet.GetStr(FONT_NAME),MSGFONT_HEIGHT);
		
		buf += nLineLen;
		posReturn.x = m_nStartX;
		posReturn.y += m_sizeFont.iHeight + 2;
	}
	
	return posReturn;


}
//--------------------------------------------------------------------
BOOL CGameMsgUnit::GetText(char* pszText, BOOL bTimes)
{
	if(strlen(pszText) <= 0 || pszText == NULL)
		return false;
	char szTemp[_MAX_WORDSSIZE * 2]="";
	// 组合信息的前缀
	if (strlen(this->m_szEmotion)>0)
	{
		int nIndex = 0;
		nIndex = atoi(this->m_szEmotion);
		if(m_unTxtAttribute != _TXTATR_ACTION && m_unTxtAttribute!= _TXTATR_SYSTEM)
			sprintf(szTemp,	g_obj3DRoleData.GetTextActionText(nIndex),
			this->m_szSender, 
			this->m_szReceiver);
	}
	else
	{
		switch(m_unTxtAttribute)
		{

⌨️ 快捷键说明

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