Files
Leviathan/Client/Game/engine/Ui/KTextParser.h
T
2026-06-01 12:46:52 +02:00

283 lines
6.9 KiB
C++

// KTextParser.h: interface for the KTextParser class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_KTEXTPARSER_H__8015B58E_E66F_4CBF_9B38_FBAB7C1A61E4__INCLUDED_)
#define AFX_KTEXTPARSER_H__8015B58E_E66F_4CBF_9B38_FBAB7C1A61E4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/*
KTextParser
Usage commands:
Font - <FONT:fontname> ex : <FONT:gulim> - font 변경
Size - <SIZE:size> ex : <SIZE:10> - font size 조절
Color - <#RRGGBB[AA]> ex: <#ff00ff> , <#ff00ff88>
Replacement
- <$[ (L) ID | Alias string]> ex: <$L100> <$100> <$PLAYER_NAME> <$PLAYER_LEVEL>
Paragraph Control
- <BR> Break line
- <P> Break Page
Bold - <B> is bold on and </B> is bold off.
Inverse - <INV> is inverse text. </INV> is inverse off.
Strike - <STRIKE> : strike line on </STRIKE> : strike line off
Shadow - <SHD> is shadow text </SHD> is shadow off
Outline - <OUT> is outline text </OUT> is outline off
Glow - <GLOW> is glow text </GLOW> is glow off
Underline - <U> : underline on </U> : underline off
줄맞춤은 한 Phrase당 한번밖에 설정 못함
Align - <VCENTER>, <TOP>, <BOTTOM>,<HCENTER>, <LEFT>, <RIGHT>
Emoticon Display
- <%%ID > ex : <%%10> , <%%10>
Pnx Emoticon Display
- <%ID > ex : <%10>
*/
#include "K3DTypes.h"
#include "KTextRender.h"
#ifdef _COUNTRY_ME_
#include "Localization/MiddleEast.h"
#endif
class KTextParser
{
public:
KTextParser();
~KTextParser();
enum ICON_TYPE
{
KICON_TEXT = 0,
KICON_EMOTICON,
KICON_NX3,
};
// maxWidth는 Pixel 좌표
// 2010.06.08 - prodongi
int AddString(LPCSTR lpszString, DWORD dwMaxWidth = 256, bool bTagEnable = true, bool bUseSplit = false, bool scroll = false);
//int AddString(LPCSTR lpszString, DWORD dwMaxWidth = 256, bool bTagEnable = true, bool bUseSplit = false);
#ifdef _COUNTRY_ME_
int GetParagraphCount() { return (int)m_vtTextParagraph.size(); }
KTextParagraph* GetTextParagraph(int nIndex)
{
return m_vtTextParagraph.at(nIndex);
}
const KTextParagraph* GetTextParagraph(int nIndex) const
{
return m_vtTextParagraph.at(nIndex);
}
struct StringTableHandler
{
virtual const char* getString( int nId ) = 0;
};
static void SetStringTable( StringTableHandler *pHandler ) { s_pStringTableHandler = pHandler; }
static const char* GetString( int nId ) { if( s_pStringTableHandler ) return s_pStringTableHandler->getString( nId ); return NULL; }
static void AddEmoticonFilter( const std::string& strText, const std::string& strAni );
static StringTableHandler* s_pStringTableHandler;
std::vector <KTextParagraph*> m_vtTextParagraph;
typedef std::map <std::string, std::string> mapEmoticon;
typedef mapEmoticon::iterator imapEmoticon;
static mapEmoticon s_mapEmoticonFilter;
#else
struct TEXT_PRIMITIVE
{
TEXT_PRIMITIVE()
{
Init();
}
void Init()
{
bIsLineBreak = false;
bIsWordWrap = false;
nPageBreak = nBreak = 0;
sFontName = KTextRender::KDEFAULT_FONT_NAME;
nFontSize = KTextRender::KDEFAULT_FONT_SIZE;
Color = KColor(0xFFFFFFFF);
ColorFX = KColor(0xFF000000);
dwFontFlag = 0;
dwIconType = KICON_TEXT;
dwIconID = 0;
dwCount = 0;
dwOffset = 0;
nOffsetY = 0; ///< 그려질 오브젝트 y 오프셋
nBlankWidth = 0;
bContinue = false;
sText.erase();
}
bool bIsLineBreak; ///< 라인을 끊어서 찍어야 함 -_-
bool bIsWordWrap;
/// 몇번 나왔나 숫자를 나타냄
int nBreak; // <BP>
int nPageBreak; // <P>
/// <Font: fontname, size>
int nFontSize;
std::string sFontName;
/// <#ffffffff>
KColor Color;
KColor ColorFX;
/// <B>, <INV>, <SHADOW>, <U>, <S>
DWORD dwFontFlag;
/// <%[ (S) | M | L ] ID >, <%%[ (S) | M | L ] ID >
DWORD dwIconType;
DWORD dwIconID;
DWORD dwCount;
//
DWORD dwOffset;
short nOffsetY; ///< 그려질 오브젝트 y 오프셋
unsigned short nBlankWidth;
bool bContinue;
std::string sText;
};
int GetPrimitiveCount() { return (int)m_vtTextPrimitive.size(); }
TEXT_PRIMITIVE & GetPrimitive(int nIndex)
{
return m_vtTextPrimitive.at(nIndex);
}
const TEXT_PRIMITIVE & GetPrimitive(int nIndex) const
{
return m_vtTextPrimitive.at(nIndex);
}
std::vector<TEXT_PRIMITIVE> m_vtTextPrimitive;
/// Using for changing phrase tag when tag is disabled.
TEXT_PRIMITIVE & GetCurrentTP() { return m_CurrentTP; }
TEXT_PRIMITIVE m_CurrentTP;
#endif
DWORD GetAlign() { return m_dwHAlign | m_dwVAlign; }
void SetAlign(DWORD dwHAlign, DWORD dwVAlign) { m_dwHAlign = dwHAlign; m_dwVAlign = dwVAlign; }
void Clear()
{
#ifdef _COUNTRY_ME_
for ( std::vector < KTextParagraph* >::iterator it = m_vtTextParagraph.begin(); it != m_vtTextParagraph.end(); ++it )
delete *it;
m_vtTextParagraph.clear();
#else
m_vtTextPrimitive.clear();
#endif
m_dwCurrentLineWidth = 0;
}
void SetEditMode( bool bFlag ) { m_bEditMode = bFlag; }
static void SetUseWordWrap( bool bFlag )
{
s_bUseWordWrap = bFlag;
}
static bool GetUseWordWrap()
{
return s_bUseWordWrap;
}
private:
struct TEXT_TOKEN
{
enum TOKEN_TYPE
{
NONE = 0,
INVALID, ///< 1
EOS, ///< 2
TEXT, ///< 3
TEXTCMD, ///< 4
FONT, ///< 5
SIZE, ///< 6
COLOR, ///< 7
BOLD, ///< 8
UNBOLD, ///< 9
UNDER_LINE, ///< 10
UNDER_LINEOFF, ///< 11
STRIKE_LINE, ///< 12
STRIKE_LINEOFF,///< 13
SHADOW, ///< 14
SHADOWOFF, ///< 15
INVERSE, ///< 16
INVERSE_OFF, ///< 17
BREAK, ///< 18
PAGEBREAK, ///< 19
EMOTICON, ///< 20
NX3, ///< 21
HALIGN, ///< 22
VALIGN, ///< 23
OUTLINE, ///< 24
OUTLINEOFF, ///< 25
GLOW, ///< 26
GLOWOFF, ///< 27
COLOR_FX, ///< 28
GLOW2X, ///< 29
GLOW2XOFF, ///< 30
OFFSET, ///< 31
CARET, ///< 32
CARET_OFF, ///< 33
OFFSETY, ///< 34 // 그려질 오브젝트 y 오프셋 추가 적용
UNKNOWN
};
DWORD dwType;
std::string sText;
std::string sTokenText;
union
{
DWORD dwAlign;
DWORD dwIconID;
DWORD dwColor;
DWORD dwFontSize;
DWORD dwOffset;
short nOffsetY; ///< 그려질 오브젝트 y 오프셋
};
};
// 2010.06.08 - prodongi
void _AddString(LPCSTR lpszString, int nDepth, DWORD dwMaxWidth, bool bTagEnable, bool bUseSplit, bool scroll);
//void _AddString(LPCSTR lpszString, int nDepth, DWORD dwMaxWidth, bool bTagEnable, bool bUseSplit);
void _GetNextToken( TEXT_TOKEN *pToken, LPCSTR lpszToken, int & nCount);
void _InterpretCommand( LPCSTR lpszToken, TEXT_TOKEN * pToken);
DWORD m_dwCurrentLineWidth; ///< 현재까지 지나온 Line의 길이 저장
/// Parsing 해서 나온 Align Value 저장
DWORD m_dwHAlign;
DWORD m_dwVAlign;
bool m_bEditMode;
static bool s_bUseWordWrap;
};
#endif // !defined(AFX_KTEXTPARSER_H__8015B58E_E66F_4CBF_9B38_FBAB7C1A61E4__INCLUDED_)