📄 npcwnd.cpp
字号:
/******************************************************************************************************************
葛碘疙:
累己磊:
累己老:
[老磊][荐沥磊] : 荐沥 郴侩
*******************************************************************************************************************/
#include "StdAfx.h"
#define MAX_NPCSTR_HEIGHT 129
#define MAX_SHOW_LINE 6
#define POS_DRAWSTART_Y 40
#define LINE_GAP 5
#define BUILD_GUILD "@@BUILDGUILDNOW" // 巩颇 汲赋
#define GUILD_WAR "@@GUILDWAR" // 巩里 脚没
#define WITHDRAWAL_CASTLE "@@WITHDRAWAL" // 捣阑 茫绰促.
#define RECEIPT_CASTLE "@@RECEIPTS" // 捣阑 嘎变促.
#define SCRIPT_GENTEXT 1
#define SCRIPT_BUTTON 2
#define SCRIPT_RETURN 3
#define SCRIPT_TAG 4
COLORREF ScriptTxtColor[] = { RGB(0, 0, 0), // 0 : Black
RGB(255, 0, 0), // 1 : Red
RGB(0, 128, 0), // 2 : Green
RGB(128, 128, 0), // 3 : Olive
RGB(128, 128, 128), // 4 : Gray
RGB(128, 0, 0), // 5 : Marron
RGB(0, 128, 128), // 6 : Teal
RGB(0, 0, 128), // 7 : Navy
RGB(192, 192, 192), // 8 : Silver
RGB(128, 0, 128), // 9 : Purple
RGB(0, 255, 0), // 10 : Lime
RGB(0, 0, 255), // 11 : Blue
RGB(255, 255, 255), // 12 : White
RGB(255, 0, 255), // 13 : Fuchsia
RGB(0, 255, 255), // 14 : Aqua
RGB(255, 255, 0), // 15 : Yellow
RGB(1, 1, 1), // 16 : Default
};
class CScriptLine
{
public:
BYTE m_btScriptType;
char *m_pszScriptText;
char *m_pszScriptCommand;
RECT m_Rect;
bool m_fIsSelected;
bool m_fIsFocused;
public:
CScriptLine()
{
m_pszScriptText = NULL;
m_pszScriptCommand = NULL;
m_fIsFocused = FALSE;
m_fIsSelected = FALSE;
}
~CScriptLine()
{
// if (m_pszScriptText) delete [] m_pszScriptText;
// if (m_pszScriptCommand) delete [] m_pszScriptCommand;
}
};
CPDLList<CScriptLine> ScriptList;
char szQuestNPCName[64];
char *CheckText(char *pszScript)
{
if (pszScript)
{
char *pszText = pszScript;
while (*pszText)
{
if (*pszText == '\\' || *pszText == '<' || *pszText == '{')
return pszText;
pszText++;
}
}
return NULL;
}
char *AddScriptLine(char *pszLine, int nLineLen, int nType)
{
CScriptLine* pScriptLine = new CScriptLine;
if (pScriptLine)
{
pScriptLine->m_btScriptType = nType;
switch (nType)
{
case SCRIPT_GENTEXT:
{
pScriptLine->m_pszScriptText = new char[nLineLen];
memcpy(pScriptLine->m_pszScriptText, pszLine, nLineLen);
pScriptLine->m_pszScriptText[nLineLen] = '\0';
ScriptList.AddNode(pScriptLine);
return NULL;
}
case SCRIPT_RETURN:
{
ScriptList.AddNode(pScriptLine);
return NULL;
}
case SCRIPT_BUTTON:
{
char *pszEndCmd;
char *pszDevide;
if (pszEndCmd = (char *)strchr(pszLine, '>'))
{
*pszEndCmd = '\0';
if (pszDevide = (char *)strchr(pszLine, '/'))
{
*pszDevide = '\0';
pScriptLine->m_pszScriptCommand = new char[pszEndCmd - pszDevide];
pScriptLine->m_pszScriptText = new char[pszDevide - pszLine];
strcpy(pScriptLine->m_pszScriptCommand, ++pszDevide);
strcpy(pScriptLine->m_pszScriptText, ++pszLine);
ScriptList.AddNode(pScriptLine);
}
return ++pszEndCmd;
}
return NULL;
}
case SCRIPT_TAG:
{
char *pszEndCmd;
char *pszDevide;
if (pszEndCmd = (char *)strchr(pszLine, '}'))
{
*pszEndCmd = '\0';
if (pszDevide = (char *)strchr(pszLine, '/'))
{
*pszDevide = '\0';
pScriptLine->m_pszScriptCommand = new char[pszEndCmd - pszDevide];
pScriptLine->m_pszScriptText = new char[pszDevide - pszLine];
strcpy(pScriptLine->m_pszScriptCommand, ++pszDevide);
strcpy(pScriptLine->m_pszScriptText, ++pszLine);
ScriptList.AddNode(pScriptLine);
}
return ++pszEndCmd;
}
return NULL;
}
}
}
delete pScriptLine;
return NULL;
}
void DevideScript(char *pszScript)
{
char *pszText = pszScript;
char *pszPaser;
int nLineLen = 0;
while (*pszText)
{
if (pszPaser = CheckText(pszText))
{
nLineLen = pszPaser - pszText;
switch (*pszPaser)
{
case '\\':
{
if (nLineLen >= 1)
AddScriptLine(pszText, nLineLen, SCRIPT_GENTEXT);
AddScriptLine(NULL, 0, SCRIPT_RETURN);
pszText = ++pszPaser;
break;
}
case '<':
{
if (nLineLen >= 1)
AddScriptLine(pszText, nLineLen, SCRIPT_GENTEXT);
pszText = AddScriptLine(pszPaser, nLineLen, SCRIPT_BUTTON);
break;
}
case '{':
{
if (nLineLen >= 1)
AddScriptLine(pszText, nLineLen, SCRIPT_GENTEXT);
pszText = AddScriptLine(pszPaser, nLineLen, SCRIPT_TAG);
break;
}
}
}
}
}
CNPCWnd::CNPCWnd()
{
m_nStartLine = 0;
m_nMaxLine = MAX_SHOW_LINE;
}
CNPCWnd::~CNPCWnd()
{
ResetDialog();
}
VOID CNPCWnd::CreateNPCChatWnd(INT nID, CWHWilImageData* pxWndImage, INT nFrameImgIdx, INT nStartX, INT nStartY, INT nWidth, INT nHeight, BOOL bCanMove)
{
CreateGameWnd(nID, pxWndImage, nFrameImgIdx, bCanMove, nStartX, nStartY, nWidth, nHeight);
m_xMsgBox.Load(&(g_xGameProc.m_xInterface.m_xInterImgEx));
}
VOID CNPCWnd::ShowNPCChatWnd()
{
SIZE tSize;
RECT tRect;
CScriptLine* pScriptLine;
int nLineCnt = 0;
int nLine = 0;
int POS_DRAWSTART_X = 60;
int MAX_NPCSTR_WIDTH = 430;
tRect = GetGameWndRect(); // Get Window Rect
ShowGameWnd();
ScriptList.MoveCurrentToTop();
COLORREF TextColor = ScriptTxtColor[12];
for (int i = 0; i < ScriptList.GetCounter(); i++)
{
pScriptLine = ScriptList.GetCurrentData();
switch (pScriptLine->m_btScriptType)
{
case SCRIPT_GENTEXT:
{
char szTempText[1024];
tSize = g_xMainWnd.GetStrLength(NULL, NULL, pScriptLine->m_pszScriptText);
if (nLine + tSize.cx > MAX_NPCSTR_WIDTH)
{
int nLen = strlen(pScriptLine->m_pszScriptText);
int nCount = 0;
for (int i = 0; i < nLen; i++)
{
if (pScriptLine->m_pszScriptText[i] < 0)
{
szTempText[nCount++] = pScriptLine->m_pszScriptText[i++];
szTempText[nCount] = pScriptLine->m_pszScriptText[i];
szTempText[nCount + 1] = '\0';
}
else
{
szTempText[nCount] = pScriptLine->m_pszScriptText[i];
szTempText[nCount + 1] = '\0';
}
tSize = g_xMainWnd.GetStrLength(NULL, NULL, szTempText);
if (nLine + tSize.cx >= MAX_NPCSTR_WIDTH)
{
if (nLineCnt >= m_nStartLine && nLineCnt <= m_nStartLine + MAX_SHOW_LINE)
g_xMainWnd.PutsHan(NULL, tRect.left + POS_DRAWSTART_X + nLine, tRect.top + ((nLineCnt - m_nStartLine) * (tSize.cy + LINE_GAP)) + POS_DRAWSTART_Y,
TextColor, RGB(0, 0, 0), szTempText);
nLineCnt++;
nLine = 0;
nCount = 0;
}
else
nCount++;
}
if (nCount)
{
if (nLineCnt >= m_nStartLine && nLineCnt <= m_nStartLine + MAX_SHOW_LINE)
g_xMainWnd.PutsHan(NULL, tRect.left + POS_DRAWSTART_X + nLine, tRect.top + ((nLineCnt - m_nStartLine) * (tSize.cy + LINE_GAP)) + POS_DRAWSTART_Y,
TextColor, RGB(0, 0, 0), szTempText);
nLine += tSize.cx;
}
}
else
{
if (nLineCnt >= m_nStartLine && nLineCnt <= m_nStartLine + MAX_SHOW_LINE)
g_xMainWnd.PutsHan(NULL, tRect.left + POS_DRAWSTART_X + nLine, tRect.top + ((nLineCnt - m_nStartLine) * (tSize.cy + LINE_GAP)) + POS_DRAWSTART_Y,
TextColor, RGB(0, 0, 0), pScriptLine->m_pszScriptText);
nLine += tSize.cx;
}
break;
}
case SCRIPT_RETURN:
nLineCnt++;
nLine = 0;
break;
case SCRIPT_BUTTON:
{
char szTempText[1024];
HFONT hFont = NULL;
COLORREF color = RGB(255, 255, 0);
if (pScriptLine->m_fIsFocused)
hFont = g_xMainWnd.CreateGameFont("奔覆", 9, 0, FW_NORMAL, FALSE, TRUE);
if (pScriptLine->m_fIsSelected)
color = RGB(255, 0, 0);
tSize = g_xMainWnd.GetStrLength(NULL, NULL, pScriptLine->m_pszScriptText);
if (nLine + tSize.cx > MAX_NPCSTR_WIDTH)
{
int nLen = strlen(pScriptLine->m_pszScriptText);
int nCount = 0;
int nRow = 0;
pScriptLine->m_Rect.left = tRect.left + POS_DRAWSTART_X + nLine;
pScriptLine->m_Rect.top = tRect.top + (nLineCnt * (tSize.cy + LINE_GAP)) + POS_DRAWSTART_Y;
pScriptLine->m_Rect.right = pScriptLine->m_Rect.left + MAX_NPCSTR_WIDTH;
for (int i = 0; i < nLen; i++)
{
if (pScriptLine->m_pszScriptText[i] < 0)
{
szTempText[nCount++] = pScriptLine->m_pszScriptText[i++];
szTempText[nCount] = pScriptLine->m_pszScriptText[i];
szTempText[nCount + 1] = '\0';
}
else
{
szTempText[nCount] = pScriptLine->m_pszScriptText[i];
szTempText[nCount + 1] = '\0';
}
tSize = g_xMainWnd.GetStrLength(NULL, NULL, szTempText);
if (nLine + tSize.cx >= MAX_NPCSTR_WIDTH)
{
if (nLineCnt >= m_nStartLine && nLineCnt <= m_nStartLine + MAX_SHOW_LINE)
g_xMainWnd.PutsHan(NULL, tRect.left + POS_DRAWSTART_X + nLine, tRect.top + ((nLineCnt - m_nStartLine) * (tSize.cy + LINE_GAP)) + POS_DRAWSTART_Y,
color, RGB(0, 0, 0), szTempText, hFont);
nLineCnt++;
nRow++;
nLine = 0;
nCount = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -