Código:
#include "stdafx.h"
#include "NewUIChatLogWindow.h"
#include "NewUIManager.h"
#include "NewUISystem.h"
#include "DSPlaySound.h"
#include "UIControls.h"
#include "ZzzInterface.h"
#include "MessageColor.h"
using namespace SEASON3B;
SEASON3B::CNewUIChatLogWindow::CNewUIChatLogWindow()
{
Init();
}
SEASON3B::CNewUIChatLogWindow::~CNewUIChatLogWindow()
{
Release();
}
void SEASON3B::CNewUIChatLogWindow::Init()
{
m_pNewUIMng = NULL;
m_WndPos.x = m_WndPos.y = 0;
m_NewWndPos.x = m_NewWndPos.y = 0;
m_ScrollBtnPos.x = m_ScrollBtnPos.y = 0;
m_WndSize.cx = WND_WIDTH; m_WndSize.cy = 0;
m_nShowingLines = 3;
m_iCurrentRenderEndLine = -1;
m_fBackAlpha = 0.6f;
m_EventState = EVENT_NONE;
m_ShowSystemMessage = 0;
m_ShowWhisperMessage = 0;
m_ShowGuildMessage = 0;
m_ShowPartyMessage = 0;
m_bShowFrame = false;
m_CurrentRenderMsgType = TYPE_ALL_MESSAGE;
m_bShowChatLog = true;
m_bPointedMessage = false;
m_iPointedMessageIndex = 0;
this->m_nShowingSystemLines = 2;
this->m_iCurrentRenderEndSystemLine = -1;
}
void SEASON3B::CNewUIChatLogWindow::LoadImages()
{
LoadBitmap("Interface\\newui_scrollbar_up.tga", IMAGE_SCROLL_TOP, GL_LINEAR);
LoadBitmap("Interface\\newui_scrollbar_m.tga", IMAGE_SCROLL_MIDDLE, GL_LINEAR);
LoadBitmap("Interface\\newui_scrollbar_down.tga", IMAGE_SCROLL_BOTTOM, GL_LINEAR);
LoadBitmap("Interface\\newui_scroll_on.tga", IMAGE_SCROLLBAR_ON, GL_LINEAR);
LoadBitmap("Interface\\newui_scroll_off.tga", IMAGE_SCROLLBAR_OFF, GL_LINEAR);
LoadBitmap("Interface\\newui_scrollbar_stretch.jpg", IMAGE_DRAG_BTN, GL_LINEAR);
}
void SEASON3B::CNewUIChatLogWindow::UnloadImages()
{
DeleteBitmap(IMAGE_SCROLL_TOP);
DeleteBitmap(IMAGE_SCROLL_MIDDLE);
DeleteBitmap(IMAGE_SCROLL_BOTTOM);
DeleteBitmap(IMAGE_SCROLLBAR_ON);
DeleteBitmap(IMAGE_SCROLLBAR_OFF);
DeleteBitmap(IMAGE_DRAG_BTN);
}
bool SEASON3B::CNewUIChatLogWindow::RenderBackground()
{
if (m_bShowFrame)
{
m_WndPos.x = GetWindowsCX(m_WndSize.cx) + 5;
m_WndPos.y = (int)setPosDown(410);
g_pChatInputBox->m_posy = 330;
float fRenderPosX = m_WndPos.x - 5.f, fRenderPosY = m_WndPos.y - m_WndSize.cy;
EnableAlphaTest();
glColor4f(0.0f, 0.0f, 0.0f, (GetBackAlpha() > 0.8f) ? 0.8f : GetBackAlpha());
RenderColor(fRenderPosX, fRenderPosY, (float)m_WndSize.cx, (float)m_WndSize.cy);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
DisableAlphaBlend();
}
else
{
m_WndPos.x = 0;
m_WndPos.y = (int)setPosDown(105);
g_pChatInputBox->m_posy = 180;
}
return true;
}
bool SEASON3B::CNewUIChatLogWindow::RenderSystemMessages()
{
if (m_ShowSystemMessage == 1)
{
return false;
}
float fRenderPosX = m_NewWndPos.x;
float fRenderPosY = 40;
type_vector_msgs* pvecMsgs = GetMsgs(TYPE_SYSTEM_MESSAGE);
if (pvecMsgs == NULL || pvecMsgs->size() == 0)
{
return true;
}
int iStartIndex = pvecMsgs->size() - m_nShowingSystemLines;
if (iStartIndex < 0) iStartIndex = 0;
int totalHeight = m_nShowingSystemLines * 16;
EnableAlphaTest();
glColor4f(0.0f, 0.0f, 0.0f, 0.3f);
RenderColor(fRenderPosX, fRenderPosY - 2, 230.0f, totalHeight);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
DisableAlphaBlend();
EnableAlphaTest();
for (int i = 0; i < m_nShowingSystemLines && iStartIndex + i < pvecMsgs->size(); i++)
{
CMessageText* pMsgText = (*pvecMsgs)[iStartIndex + i];
bool bRenderMessage = true;
g_pRenderText->SetFont(g_hFont);
if (pMsgText->GetType() == TYPE_SYSTEM_MESSAGE)
{
if (pMsgText->GetColor() >= 25 && pMsgText->GetColor() <= 100)
{
if (gMessageColor.CheckIsColor(pMsgText->GetColor(), 0))
{
gMessageColor.SetMessageColor(pMsgText->GetColor());
}
}
if(pMsgText->GetColor() == 0)
{
g_pRenderText->SetBgColor(0, 0, 0, 150);
g_pRenderText->SetTextColor(100, 150, 255, 255);
}
}
if (bRenderMessage && !pMsgText->GetText().empty())
{
POINT ptRenderPos = { (long)fRenderPosX + (long)WND_LEFT_RIGHT_EDGE, (long)fRenderPosY + (i * 16) };
if (!pMsgText->GetID().empty())
{
std::string strIDUTF8 = "";
g_pMultiLanguage->ConvertANSIToUTF8OrViceVersa(strIDUTF8, (pMsgText->GetID()).c_str());
type_string strLine = strIDUTF8 + " : " + pMsgText->GetText();
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, strLine.c_str());
}
else
{
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, pMsgText->GetText().c_str());
}
}
}
DisableAlphaBlend();
return true;
}
bool SEASON3B::CNewUIChatLogWindow::RenderMessages()
{
float fRenderPosX = m_WndPos.x;
float fRenderPosY = 40 + (m_nShowingSystemLines * 16) + 5;
type_vector_msgs* pvecMsgs = GetMsgs(GetCurrentMsgType());
if (pvecMsgs == NULL || pvecMsgs->size() == 0)
{
return true;
}
int iStartIndex = pvecMsgs->size() - m_nShowingLines;
if (iStartIndex < 0) iStartIndex = 0;
int totalHeight = m_nShowingLines * 16;
EnableAlphaTest();
glColor4f(0.0f, 0.0f, 0.0f, 0.3f);
RenderColor(fRenderPosX, fRenderPosY - 2, 230.0f, totalHeight);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
DisableAlphaBlend();
EnableAlphaTest();
for (int i = 0; i < m_nShowingLines && iStartIndex + i < pvecMsgs->size(); i++)
{
CMessageText* pMsgText = (*pvecMsgs)[iStartIndex + i];
bool bRenderMessage = true;
g_pRenderText->SetFont(g_hFont);
if (pMsgText->GetType() == TYPE_WHISPER_MESSAGE)
{
if (pMsgText->GetColor() >= 25 && pMsgText->GetColor() <= 100)
{
if (gMessageColor.CheckIsColor(pMsgText->GetColor(), 1))
{
gMessageColor.SetMessageColor(pMsgText->GetColor());
}
}
if (pMsgText->GetColor() == 0)
{
g_pRenderText->SetBgColor(255, 200, 50, 150);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
}
else if (pMsgText->GetType() == TYPE_ERROR_MESSAGE)
{
g_pRenderText->SetBgColor(0, 0, 0, 150);
g_pRenderText->SetTextColor(255, 30, 0, 255);
}
else if (pMsgText->GetType() == TYPE_CHAT_MESSAGE)
{
g_pRenderText->SetBgColor(0, 0, 0, 150);
g_pRenderText->SetTextColor(205, 220, 239, 255);
}
else if (pMsgText->GetType() == TYPE_PARTY_MESSAGE)
{
g_pRenderText->SetBgColor(0, 200, 255, 150);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_GUILD_MESSAGE)
{
g_pRenderText->SetBgColor(0, 255, 150, 200);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_UNION_MESSAGE)
{
g_pRenderText->SetBgColor(200, 200, 0, 200);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_GENS_MESSAGE)
{
g_pRenderText->SetBgColor(150, 200, 100, 200);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_GM_MESSAGE)
{
g_pRenderText->SetBgColor(30, 30, 30, 200);
g_pRenderText->SetTextColor(250, 200, 50, 255);
g_pRenderText->SetFont(g_hFontBold);
}
else
{
bRenderMessage = false;
}
if (bRenderMessage && !pMsgText->GetText().empty())
{
POINT ptRenderPos = { (long)fRenderPosX + (long)WND_LEFT_RIGHT_EDGE, (long)fRenderPosY + (i * 16) };
if (!pMsgText->GetID().empty())
{
std::string strIDUTF8 = "";
g_pMultiLanguage->ConvertANSIToUTF8OrViceVersa(strIDUTF8, (pMsgText->GetID()).c_str());
type_string strLine = strIDUTF8 + " : " + pMsgText->GetText();
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, strLine.c_str());
}
else
{
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, pMsgText->GetText().c_str());
}
}
}
DisableAlphaBlend();
return true;
}
bool SEASON3B::CNewUIChatLogWindow::RenderFrame()
{
if (m_bShowFrame)
{
float fRenderPosX = m_WndPos.x - 7.f, fRenderPosY = m_WndPos.y - m_WndSize.cy;
EnableAlphaTest();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
float x = m_WndPos.x + m_WndSize.cx - 18.f;
float y = fRenderPosY + 2.f;
GWidescreen.RenderImageF(CNewUIChatInputBox::IMAGE_INPUTBOX_BACK, x, y, 12.f, 12.f, 760.f, 2.f, 22.f, 22.f);
float porcento = 1.f;
float Move = 1.f;
y += 12.f;
int m_maxLine = 0;
int NumberLine = GetNumberOfShowingLines();
int EndRenderLine = GetCurrentRenderEndLine();
if (m_maxLine > NumberLine)
{
porcento = (float)((float)NumberLine / (float)m_maxLine);
Move = (float)(((float)EndRenderLine + 1.f) / (float)m_maxLine);
}
else
{
Move = 1.f;
porcento = 1.f;
}
float Max_y = y + (((float)m_WndSize.cy - 28.f) * Move);
float h = (float)(((float)m_WndSize.cy - 28.f) * porcento);
GWidescreen.RenderImageF(CNewUIChatInputBox::IMAGE_INPUTBOX_BACK, x, Max_y - h, 12.f, h, 2.f, 116.f, 22.f, 375.f);
y = m_WndPos.y - 14.f;
GWidescreen.RenderImageF(CNewUIChatInputBox::IMAGE_INPUTBOX_BACK, x, y, 12.f, 12.f, 786.f, 2.f, 22.f, 22.f);
DisableAlphaBlend();
}
return true;
}
bool SEASON3B::CNewUIChatLogWindow::Create(CNewUIManager* pNewUIMng, int x, int y, int nShowingLines /* = 6 */)
{
Release();
if (NULL == pNewUIMng)
return false;
m_pNewUIMng = pNewUIMng;
m_pNewUIMng->AddUIObj(SEASON3B::INTERFACE_CHATLOGWINDOW, this);
m_WndPos.x = x; m_WndPos.y = y;
m_NewWndPos.x = x; m_NewWndPos.y = y;
SetNumberOfShowingLines(nShowingLines);
LoadImages();
return true;
}
void SEASON3B::CNewUIChatLogWindow::Release()
{
UnloadImages();
ResetFilter();
ClearAll();
if (m_pNewUIMng)
{
m_pNewUIMng->RemoveUIObj(this);
m_pNewUIMng = NULL;
}
Init();
}
void SEASON3B::CNewUIChatLogWindow::SetPosition(int x, int y)
{
m_WndPos.x = x;
m_WndPos.y = y;
m_NewWndPos.x = x;
m_NewWndPos.y = y;
}
void SEASON3B::CNewUIChatLogWindow::AddText(const type_string& strID, const type_string& strText, MESSAGE_TYPE MsgType, DWORD MsgColor, MESSAGE_TYPE ErrMsgType/*= TYPE_ALL_MESSAGE*/)
{
if (strID.empty() && strText.empty())
{
return;
}
if (GetNumberOfLines(MsgType) >= MAX_NUMBER_OF_LINES)
{
RemoveFrontLine(MsgType);
}
if (GetNumberOfLines(TYPE_ALL_MESSAGE) >= MAX_NUMBER_OF_LINES)
{
RemoveFrontLine(TYPE_ALL_MESSAGE);
}
if (m_vecFilters.empty() == true)
{
ProcessAddText(strID, strText, MsgType, MsgColor, ErrMsgType);
}
else
{
if (MsgType != TYPE_CHAT_MESSAGE)
{
ProcessAddText(strID, strText, MsgType, MsgColor, ErrMsgType);
}
else if (CheckFilterText(strID) || CheckFilterText(strText))
{
ProcessAddText(strID, strText, MsgType, MsgColor, ErrMsgType);
if (g_pOption->IsWhisperSound())
{
PlayBuffer(SOUND_WHISPER);
}
}
}
}
void SEASON3B::CNewUIChatLogWindow::ProcessAddText(const type_string& strID, const type_string& strText, MESSAGE_TYPE MsgType, DWORD MsgColor, MESSAGE_TYPE ErrMsgType)
{
type_vector_msgs* pvecMsgs = GetMsgs(MsgType);
if (pvecMsgs == NULL)
{
assert(!"Empty Message");
return;
}
int nScrollLines = 0;
int nScrollSystemLines = 0;
if (strText.size() >= 20)
{
type_string strText1, strText2;
SeparateText(strID, strText, strText1, strText2);
if (!strText1.empty())
{
CMessageText* pMsgText = new CMessageText;
if (!pMsgText->Create(strID, strText1, MsgType, MsgColor))
delete pMsgText;
else
{
pvecMsgs->push_back(pMsgText);
}
if (MsgType != TYPE_SYSTEM_MESSAGE)
{
CMessageText* pAllMsgText = new CMessageText;
if (!pAllMsgText->Create(strID, strText1, MsgType, MsgColor))
delete pAllMsgText;
else
{
m_vecAllMsgs.push_back(pAllMsgText);
}
}
if ((MsgType == TYPE_ERROR_MESSAGE) && (ErrMsgType != TYPE_ERROR_MESSAGE && ErrMsgType != TYPE_ALL_MESSAGE))
{
type_vector_msgs* pErrvecMsgs = GetMsgs(ErrMsgType);
if (pErrvecMsgs == NULL)
{
assert(!"Error Chat");
return;
}
CMessageText* pErrMsgText = new CMessageText;
if (!pErrMsgText->Create(strID, strText1, MsgType, MsgColor))
delete pErrMsgText;
else
{
pErrvecMsgs->push_back(pErrMsgText);
}
}
if (MsgType == TYPE_SYSTEM_MESSAGE)
{
nScrollSystemLines++;
}
else if ((GetCurrentMsgType() == TYPE_ALL_MESSAGE || GetCurrentMsgType() == MsgType) && MsgType != TYPE_SYSTEM_MESSAGE)
{
nScrollLines++;
}
}
if (!strText2.empty())
{
CMessageText* pMsgText = new CMessageText;
if (!pMsgText->Create("", strText2, MsgType, MsgColor))
delete pMsgText;
else
{
pvecMsgs->push_back(pMsgText);
}
CMessageText* pAllMsgText = new CMessageText;
if (!pAllMsgText->Create("", strText2, MsgType, MsgColor))
delete pAllMsgText;
else
{
m_vecAllMsgs.push_back(pAllMsgText);
}
if ((MsgType == TYPE_ERROR_MESSAGE) && (ErrMsgType != TYPE_ERROR_MESSAGE && ErrMsgType != TYPE_ALL_MESSAGE))
{
type_vector_msgs* pErrvecMsgs = GetMsgs(ErrMsgType);
if (pErrvecMsgs == NULL)
{
assert(!"Error chat 2");
return;
}
CMessageText* pErrMsgText = new CMessageText;
if (!pErrMsgText->Create("", strText2, MsgType, MsgColor))
delete pErrMsgText;
else
{
pErrvecMsgs->push_back(pErrMsgText);
}
}
if (MsgType == TYPE_SYSTEM_MESSAGE)
{
nScrollSystemLines++;
}
else if (MsgType != TYPE_SYSTEM_MESSAGE && (GetCurrentMsgType() == TYPE_ALL_MESSAGE || GetCurrentMsgType() == MsgType))
{
nScrollLines++;
}
}
}
else
{
CMessageText* pMsgText = new CMessageText;
if (!pMsgText->Create(strID, strText, MsgType, MsgColor))
delete pMsgText;
else
{
pvecMsgs->push_back(pMsgText);
}
if (MsgType != TYPE_SYSTEM_MESSAGE)
{
CMessageText* pAllMsgText = new CMessageText;
if (!pAllMsgText->Create(strID, strText, MsgType, MsgColor))
delete pAllMsgText;
else
{
m_vecAllMsgs.push_back(pAllMsgText);
}
}
if ((MsgType == TYPE_ERROR_MESSAGE) && (ErrMsgType != TYPE_ERROR_MESSAGE && ErrMsgType != TYPE_ALL_MESSAGE))
{
type_vector_msgs* pErrvecMsgs = GetMsgs(ErrMsgType);
if (pErrvecMsgs == NULL)
{
assert(!"Error chat 3");
return;
}
CMessageText* pErrMsgText = new CMessageText;
if (!pErrMsgText->Create(strID, strText, MsgType, MsgColor))
delete pErrMsgText;
else
{
pErrvecMsgs->push_back(pErrMsgText);
}
}
if (MsgType == TYPE_SYSTEM_MESSAGE)
{
nScrollSystemLines++;
}
else if (MsgType != TYPE_SYSTEM_MESSAGE && (GetCurrentMsgType() == TYPE_ALL_MESSAGE || GetCurrentMsgType() == MsgType))
{
nScrollLines++;
}
}
if (MsgType == TYPE_SYSTEM_MESSAGE)
{
type_vector_msgs* pvecSystemMsgs = GetMsgs(TYPE_SYSTEM_MESSAGE);
if (pvecSystemMsgs != NULL)
{
m_iCurrentRenderEndSystemLine = pvecSystemMsgs->size() - 1;
}
}
else
{
type_vector_msgs* pvecMsgs = GetMsgs(GetCurrentMsgType());
if (pvecMsgs != NULL)
{
m_iCurrentRenderEndLine = pvecMsgs->size() - 1;
}
}
}
void SEASON3B::CNewUIChatLogWindow::RemoveFrontLine(MESSAGE_TYPE MsgType)
{
type_vector_msgs* pvecMsgs = GetMsgs(MsgType);
if (pvecMsgs == NULL)
{
assert(!"Empty Message RemoveFrontLine");
return;
}
type_vector_msgs::iterator vi = pvecMsgs->begin();
if (vi != pvecMsgs->end())
{
delete (*vi);
vi = pvecMsgs->erase(vi);
}
if (MsgType == GetCurrentMsgType())
{
Scrolling(GetCurrentRenderEndLine());
}
}
void SEASON3B::CNewUIChatLogWindow::Clear(MESSAGE_TYPE MsgType)
{
type_vector_msgs* pvecMsgs = GetMsgs(MsgType);
if (pvecMsgs == NULL)
{
assert(!"Empty Message CNewUIChatLogWindow");
return;
}
type_vector_msgs::iterator vi_msg = pvecMsgs->begin();
for (; vi_msg != pvecMsgs->end(); vi_msg++)
delete (*vi_msg);
pvecMsgs->clear();
if (MsgType == GetCurrentMsgType())
{
m_iCurrentRenderEndLine = -1;
}
}
size_t SEASON3B::CNewUIChatLogWindow::GetNumberOfLines(MESSAGE_TYPE MsgType)
{
type_vector_msgs* pvecMsgs = GetMsgs(MsgType);
if (pvecMsgs == NULL)
{
return 0;
}
return pvecMsgs->size();
}
int SEASON3B::CNewUIChatLogWindow::GetCurrentRenderEndSystemLine() const
{
return m_iCurrentRenderEndSystemLine;
}
int SEASON3B::CNewUIChatLogWindow::GetCurrentRenderEndLine() const
{
return m_iCurrentRenderEndLine;
}
void SEASON3B::CNewUIChatLogWindow::Scrolling(int nRenderEndLine)
{
type_vector_msgs* pvecMsgs = GetMsgs(m_CurrentRenderMsgType);
if (pvecMsgs == NULL)
{
assert(!"Empty message Scrolling");
return;
}
if ((int)pvecMsgs->size() <= m_nShowingLines)
{
m_iCurrentRenderEndLine = pvecMsgs->size() - 1;
}
else
{
if (nRenderEndLine < m_nShowingLines)
m_iCurrentRenderEndLine = m_nShowingLines - 1;
else if (nRenderEndLine >= (int)pvecMsgs->size())
m_iCurrentRenderEndLine = pvecMsgs->size() - 1;
else
m_iCurrentRenderEndLine = nRenderEndLine;
}
}
void SEASON3B::CNewUIChatLogWindow::SetFilterText(const type_string& strFilterText)
{
bool bPrevFilter = false;
if (!m_vecFilters.empty())
{
bPrevFilter = true;
ResetFilter();
}
unicode::t_char szTemp[MAX_CHAT_BUFFER_SIZE + 1] = { 0, };
unicode::_strncpy(szTemp, strFilterText.c_str(), MAX_CHAT_BUFFER_SIZE);
szTemp[MAX_CHAT_BUFFER_SIZE] = '\0';
unicode::t_char* token = unicode::_strtok(szTemp, " ");
token = unicode::_strtok(NULL, " ");
if (token == NULL)
{
ResetFilter();
AddText("", GlobalText[756], TYPE_SYSTEM_MESSAGE, 0);
}
else
{
for (int i = 0; i < 5; i++)
{
if (NULL == token)
{
break;
}
AddFilterWord(token);
token = unicode::_strtok(NULL, " ");
}
AddText("", GlobalText[755], TYPE_SYSTEM_MESSAGE, 0);
}
}
void SEASON3B::CNewUIChatLogWindow::ResetFilter()
{
m_vecFilters.clear();
}
void SEASON3B::CNewUIChatLogWindow::SetSizeAuto()
{
SetNumberOfShowingLines(3);
}
void SEASON3B::CNewUIChatLogWindow::SetNumberOfShowingLines(int nShowingLines, OUT LPSIZE lpBoxSize/* = NULL*/)
{
m_nShowingLines = (int)(nShowingLines / 3) * 3;
if (m_nShowingLines < 3)
m_nShowingLines = 3;
if (m_nShowingLines > 15)
m_nShowingLines = 3;
if (m_nShowingLines > GetCurrentRenderEndLine())
Scrolling(m_nShowingLines - 1);
UpdateWndSize();
UpdateScrollPos();
if (lpBoxSize)
{
lpBoxSize->cx = WND_WIDTH;
lpBoxSize->cy = (SCROLL_MIDDLE_PART_HEIGHT * GetNumberOfShowingLines()) + (SCROLL_TOP_BOTTOM_PART_HEIGHT * 2) + (WND_TOP_BOTTOM_EDGE * 2);
}
}
size_t SEASON3B::CNewUIChatLogWindow::GetNumberOfShowingLines() const
{
return m_nShowingLines;
}
size_t SEASON3B::CNewUIChatLogWindow::GetNumberOfShowingLinesSystem() const
{
return m_nShowingSystemLines;
}
void SEASON3B::CNewUIChatLogWindow::SetBackAlphaAuto()
{
m_fBackAlpha += 0.2f;
if (m_fBackAlpha > 0.9f)
{
m_fBackAlpha = 0.2f;
}
}
void SEASON3B::CNewUIChatLogWindow::SetBackAlpha(float fAlpha)
{
if (fAlpha < 0.f)
m_fBackAlpha = 0.f;
else if (fAlpha > 1.f)
m_fBackAlpha = 1.f;
else
m_fBackAlpha = fAlpha;
}
float SEASON3B::CNewUIChatLogWindow::GetBackAlpha() const
{
return m_fBackAlpha;
}
void SEASON3B::CNewUIChatLogWindow::ShowFrame()
{
m_bShowFrame = true;
}
void SEASON3B::CNewUIChatLogWindow::HideFrame()
{
m_bShowFrame = false;
}
bool SEASON3B::CNewUIChatLogWindow::IsShowFrame()
{
return m_bShowFrame;
}
bool SEASON3B::CNewUIChatLogWindow::UpdateMouseEvent()
{
extern float g_fScreenRate_x;
if (m_EventState == EVENT_NONE && false == MouseLButtonPush &&
SEASON3B::CheckMouseIn(m_WndPos.x, m_WndPos.y - m_WndSize.cy, m_WndSize.cx, m_WndSize.cy))
{
m_EventState = EVENT_CLIENT_WND_HOVER;
return false;
}
if (false == MouseLButtonPush && m_EventState == EVENT_CLIENT_WND_HOVER &&
false == SEASON3B::CheckMouseIn(m_WndPos.x, m_WndPos.y - m_WndSize.cy, m_WndSize.cx, m_WndSize.cy))
{
m_EventState = EVENT_NONE;
return true;
}
if (m_EventState == EVENT_CLIENT_WND_HOVER)
{
if (MouseWheel > 0)
Scrolling(GetCurrentRenderEndLine() - 1);
if (MouseWheel < 0)
Scrolling(GetCurrentRenderEndLine() + 1);
if (MouseWheel != 0)
MouseWheel = 0;
}
m_bPointedMessage = false;
if (SEASON3B::CheckMouseIn(m_WndPos.x, m_WndPos.y - m_WndSize.cy, m_WndSize.cx, m_WndSize.cy))
{
int iRenderStartLine = 0;
if (GetCurrentRenderEndLine() >= m_nShowingLines)
iRenderStartLine = GetCurrentRenderEndLine() - m_nShowingLines + 1;
for (int i = iRenderStartLine, s = 0; i <= GetCurrentRenderEndLine(); i++, s++)
{
type_vector_msgs* pvecMsgs = GetMsgs(GetCurrentMsgType());
if (pvecMsgs == NULL)
{
return false;
}
CMessageText* pMsgText = (*pvecMsgs)[i];
if (pMsgText->GetType() == TYPE_WHISPER_MESSAGE
|| pMsgText->GetType() == TYPE_CHAT_MESSAGE
|| pMsgText->GetType() == TYPE_PARTY_MESSAGE
|| pMsgText->GetType() == TYPE_GUILD_MESSAGE
|| pMsgText->GetType() == TYPE_UNION_MESSAGE
|| pMsgText->GetType() == TYPE_GENS_MESSAGE
|| pMsgText->GetType() == TYPE_GM_MESSAGE
)
{
float fRenderPosX = m_WndPos.x;
float fRenderPosY = m_WndPos.y - m_WndSize.cy + SCROLL_TOP_BOTTOM_PART_HEIGHT;
if (GetCurrentRenderEndLine() < m_nShowingLines)
{
fRenderPosY = fRenderPosY + FONT_LEADING + (SCROLL_MIDDLE_PART_HEIGHT * (m_nShowingLines - GetCurrentRenderEndLine() - 1));
}
POINT ptRenderPos;
ptRenderPos.x = fRenderPosX + WND_LEFT_RIGHT_EDGE;
ptRenderPos.y = fRenderPosY + FONT_LEADING + (SCROLL_MIDDLE_PART_HEIGHT * s);
if (SEASON3B::CheckMouseIn(ptRenderPos.x, ptRenderPos.y, WND_WIDTH, SCROLL_MIDDLE_PART_HEIGHT))
{
m_bPointedMessage = true;
m_iPointedMessageIndex = i;
std::string strID = pMsgText->GetID();
if (SEASON3B::IsPress(VK_RBUTTON) && strID.empty() == false)
{
g_pChatInputBox->SetWhsprID(strID.c_str());
}
}
}
}
}
if (m_bShowFrame)
{
if (m_EventState == EVENT_CLIENT_WND_HOVER && MouseLButtonPush &&
SEASON3B::CheckMouseIn(m_ScrollBtnPos.x, m_ScrollBtnPos.y, SCROLL_BTN_WIDTH, SCROLL_BTN_HEIGHT))
{
extern int MouseY;
m_EventState = EVENT_SCROLL_BTN_DOWN;
m_iGrapRelativePosY = MouseY - m_ScrollBtnPos.y;
return false;
}
if (m_EventState == EVENT_SCROLL_BTN_DOWN)
{
if (SEASON3B::IsRepeat(VK_LBUTTON))
{
if (GetNumberOfLines(GetCurrentMsgType()) > GetNumberOfShowingLines())
{
extern int MouseY;
if (MouseY - m_iGrapRelativePosY < m_WndPos.y - m_WndSize.cy + WND_TOP_BOTTOM_EDGE)
{
Scrolling(GetNumberOfShowingLines() - 1);
m_ScrollBtnPos.y = m_WndPos.y - m_WndSize.cy + WND_TOP_BOTTOM_EDGE;
}
else if (MouseY - m_iGrapRelativePosY > m_WndPos.y - SCROLL_BTN_HEIGHT - WND_TOP_BOTTOM_EDGE)
{
Scrolling(GetNumberOfLines(GetCurrentMsgType()) - 1);
m_ScrollBtnPos.y = m_WndPos.y - SCROLL_BTN_HEIGHT - WND_TOP_BOTTOM_EDGE;
}
else
{
float fScrollRate = (float)((MouseY - m_iGrapRelativePosY) - (m_WndPos.y - m_WndSize.cy + WND_TOP_BOTTOM_EDGE)) / (float)(m_WndSize.cy - WND_TOP_BOTTOM_EDGE * 2 - SCROLL_BTN_HEIGHT);
Scrolling(GetNumberOfShowingLines() + (float)(GetNumberOfLines(GetCurrentMsgType()) - GetNumberOfShowingLines()) * fScrollRate);
m_ScrollBtnPos.y = MouseY - m_iGrapRelativePosY;
}
}
return false;
}
if (SEASON3B::IsRelease(VK_LBUTTON))
{
m_EventState = EVENT_NONE;
return true;
}
}
POINT ptResizingBtn = { m_WndPos.x, m_WndPos.y - m_WndSize.cy - RESIZING_BTN_HEIGHT };
if (m_EventState == EVENT_NONE && false == MouseLButtonPush &&
SEASON3B::CheckMouseIn(ptResizingBtn.x, ptResizingBtn.y, RESIZING_BTN_WIDTH, RESIZING_BTN_HEIGHT))
{
m_EventState = EVENT_RESIZING_BTN_HOVER;
return false;
}
if (false == MouseLButtonPush && m_EventState == EVENT_RESIZING_BTN_HOVER &&
false == SEASON3B::CheckMouseIn(ptResizingBtn.x, ptResizingBtn.y, RESIZING_BTN_WIDTH, RESIZING_BTN_HEIGHT))
{
m_EventState = EVENT_NONE;
return true;
}
if (m_EventState == EVENT_RESIZING_BTN_HOVER && MouseLButtonPush &&
SEASON3B::CheckMouseIn(ptResizingBtn.x, ptResizingBtn.y, RESIZING_BTN_WIDTH, RESIZING_BTN_HEIGHT))
{
m_EventState = EVENT_RESIZING_BTN_DOWN;
return false;
}
if (m_EventState == EVENT_RESIZING_BTN_DOWN)
{
if (MouseLButtonPush)
{
int nTopSections = (15 - GetNumberOfShowingLines()) / 3;
int nBottomSections = (GetNumberOfShowingLines() - 3) / 3;
for (int i = 0; i < nTopSections; i++)
{
if (SEASON3B::CheckMouseIn(0, ptResizingBtn.y - RESIZING_BTN_HEIGHT - ((i + 1) * SCROLL_MIDDLE_PART_HEIGHT * 3 * 2),
640, SCROLL_MIDDLE_PART_HEIGHT * 3 + RESIZING_BTN_HEIGHT))
{
SetNumberOfShowingLines(GetNumberOfShowingLines() + (i + 1) * 3);
return false;
}
}
for (int i = 0; i < nBottomSections; i++)
{
if (SEASON3B::CheckMouseIn(0, ptResizingBtn.y + RESIZING_BTN_HEIGHT + ((i + 1) * SCROLL_MIDDLE_PART_HEIGHT * 3),
640, RESIZING_BTN_HEIGHT + SCROLL_MIDDLE_PART_HEIGHT * 3))
{
SetNumberOfShowingLines(GetNumberOfShowingLines() - (i + 1) * 3);
return false;
}
}
if (SEASON3B::CheckMouseIn(0, 0, 640, m_WndPos.y - (SCROLL_MIDDLE_PART_HEIGHT * 15 + RESIZING_BTN_HEIGHT + SCROLL_TOP_BOTTOM_PART_HEIGHT * 2)))
{
SetNumberOfShowingLines(15);
}
if (SEASON3B::CheckMouseIn(0, m_WndPos.y - (SCROLL_MIDDLE_PART_HEIGHT * 3 + SCROLL_TOP_BOTTOM_PART_HEIGHT * 2),
640, SCROLL_MIDDLE_PART_HEIGHT * 3 + SCROLL_TOP_BOTTOM_PART_HEIGHT * 2))
{
SetNumberOfShowingLines(3);
}
return false;
}
if (false == MouseLButtonPush || true == MouseLButtonPop)
{
m_EventState = EVENT_NONE;
return true;
}
}
}
return true;
}
bool SEASON3B::CNewUIChatLogWindow::UpdateKeyEvent()
{
return true;
}
bool SEASON3B::CNewUIChatLogWindow::Update()
{
UpdateScrollPos();
return true;
}
bool SEASON3B::CNewUIChatLogWindow::Render()
{
if (RenderBackground() == false)
{
return false;
}
if (m_bShowChatLog == true)
{
type_vector_msgs* pvecSystemMsgs = GetMsgs(TYPE_SYSTEM_MESSAGE);
type_vector_msgs* pvecGlobalMsgs = GetMsgs(GetCurrentMsgType());
int systemCount = (pvecSystemMsgs != NULL) ? pvecSystemMsgs->size() : 0;
int globalCount = (pvecGlobalMsgs != NULL) ? pvecGlobalMsgs->size() : 0;
int systemLines = (systemCount > m_nShowingSystemLines) ? m_nShowingSystemLines : systemCount;
int globalLines = (globalCount > m_nShowingLines) ? m_nShowingLines : globalCount;
if (systemLines == 0 && globalLines == 0)
{
return true;
}
float fRenderPosX = m_NewWndPos.x;
float fRenderPosY = 40;
if (systemLines > 0 && pvecSystemMsgs != NULL)
{
int iStartIndex = pvecSystemMsgs->size() - systemLines;
if (iStartIndex < 0) iStartIndex = 0;
EnableAlphaTest();
for (int i = 0; i < systemLines; i++)
{
CMessageText* pMsgText = (*pvecSystemMsgs)[iStartIndex + i];
bool bRenderMessage = true;
g_pRenderText->SetFont(g_hFont);
if (pMsgText->GetType() == TYPE_SYSTEM_MESSAGE)
{
if (pMsgText->GetColor() >= 25 && pMsgText->GetColor() <= 100)
{
if (gMessageColor.CheckIsColor(pMsgText->GetColor(), 0))
{
gMessageColor.SetMessageColor(pMsgText->GetColor());
}
}
if(pMsgText->GetColor() == 0)
{
g_pRenderText->SetBgColor(0, 0, 0, 150);
g_pRenderText->SetTextColor(100, 150, 255, 255);
}
}
if (bRenderMessage && !pMsgText->GetText().empty())
{
POINT ptRenderPos = { (long)fRenderPosX + (long)WND_LEFT_RIGHT_EDGE, (long)fRenderPosY + (i * 16) };
if (!pMsgText->GetID().empty())
{
std::string strIDUTF8 = "";
g_pMultiLanguage->ConvertANSIToUTF8OrViceVersa(strIDUTF8, (pMsgText->GetID()).c_str());
type_string strLine = strIDUTF8 + " : " + pMsgText->GetText();
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, strLine.c_str());
}
else
{
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, pMsgText->GetText().c_str());
}
}
}
DisableAlphaBlend();
}
if (globalLines > 0 && pvecGlobalMsgs != NULL)
{
int iStartIndex = pvecGlobalMsgs->size() - globalLines;
if (iStartIndex < 0) iStartIndex = 0;
EnableAlphaTest();
for (int i = 0; i < globalLines; i++)
{
CMessageText* pMsgText = (*pvecGlobalMsgs)[iStartIndex + i];
bool bRenderMessage = true;
g_pRenderText->SetFont(g_hFont);
if (pMsgText->GetType() == TYPE_WHISPER_MESSAGE)
{
if (pMsgText->GetColor() >= 25 && pMsgText->GetColor() <= 100)
{
if (gMessageColor.CheckIsColor(pMsgText->GetColor(), 1))
{
gMessageColor.SetMessageColor(pMsgText->GetColor());
}
}
if (pMsgText->GetColor() == 0)
{
g_pRenderText->SetBgColor(255, 200, 50, 150);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
}
else if (pMsgText->GetType() == TYPE_ERROR_MESSAGE)
{
g_pRenderText->SetBgColor(0, 0, 0, 150);
g_pRenderText->SetTextColor(255, 30, 0, 255);
}
else if (pMsgText->GetType() == TYPE_CHAT_MESSAGE)
{
g_pRenderText->SetBgColor(0, 0, 0, 150);
g_pRenderText->SetTextColor(205, 220, 239, 255);
}
else if (pMsgText->GetType() == TYPE_PARTY_MESSAGE)
{
g_pRenderText->SetBgColor(0, 200, 255, 150);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_GUILD_MESSAGE)
{
g_pRenderText->SetBgColor(0, 255, 150, 200);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_UNION_MESSAGE)
{
g_pRenderText->SetBgColor(200, 200, 0, 200);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_GENS_MESSAGE)
{
g_pRenderText->SetBgColor(150, 200, 100, 200);
g_pRenderText->SetTextColor(0, 0, 0, 255);
}
else if (pMsgText->GetType() == TYPE_GM_MESSAGE)
{
g_pRenderText->SetBgColor(30, 30, 30, 200);
g_pRenderText->SetTextColor(250, 200, 50, 255);
g_pRenderText->SetFont(g_hFontBold);
}
else
{
bRenderMessage = false;
}
if (bRenderMessage && !pMsgText->GetText().empty())
{
POINT ptRenderPos = { (long)fRenderPosX + (long)WND_LEFT_RIGHT_EDGE, (long)fRenderPosY + (systemLines * 16) + (i * 16) };
if (!pMsgText->GetID().empty())
{
std::string strIDUTF8 = "";
g_pMultiLanguage->ConvertANSIToUTF8OrViceVersa(strIDUTF8, (pMsgText->GetID()).c_str());
type_string strLine = strIDUTF8 + " : " + pMsgText->GetText();
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, strLine.c_str());
}
else
{
g_pRenderText->RenderText(ptRenderPos.x, ptRenderPos.y, pMsgText->GetText().c_str());
}
}
}
DisableAlphaBlend();
}
}
if (RenderFrame() == false)
{
return false;
}
return true;
}
float SEASON3B::CNewUIChatLogWindow::GetLayerDepth()
{
return 6.1f;
}
float SEASON3B::CNewUIChatLogWindow::GetKeyEventOrder()
{
return 8.0f;
}
bool SEASON3B::CNewUIChatLogWindow::CheckChatRedundancy(const type_string& strText, int iSearchLine/* = 1*/)
{
type_vector_msgs* pvecMsgs = GetMsgs(TYPE_ALL_MESSAGE);
if (pvecMsgs == NULL)
{
return 0;
}
if (pvecMsgs->empty()) return false;
type_vector_msgs::reverse_iterator vri_msgs = pvecMsgs->rbegin();
for (int i = 0; (i < iSearchLine) || (vri_msgs != pvecMsgs->rend()); vri_msgs++, i++)
if (0 == (*vri_msgs)->GetText().compare(strText)) return true;
return false;
}
void SEASON3B::CNewUIChatLogWindow::SeparateText(IN const type_string& strID, IN const type_string& strText, OUT type_string& strText1, OUT type_string& strText2)
{
extern float g_fScreenRate_x;
SIZE TextSize;
type_string strIDPart = strID + " : ";
std::wstring wstrUTF16 = L"";
g_pMultiLanguage->ConvertCharToWideStr(wstrUTF16, strIDPart.c_str());
g_pMultiLanguage->_GetTextExtentPoint32(g_pRenderText->GetFontDC(), wstrUTF16.c_str(), wstrUTF16.length(), &TextSize);
size_t MaxFirstLineWidth = CLIENT_WIDTH - (size_t)(TextSize.cx / g_fScreenRate_x);
g_pMultiLanguage->ConvertCharToWideStr(wstrUTF16, strText.c_str());
g_pMultiLanguage->_GetTextExtentPoint32(g_pRenderText->GetFontDC(), wstrUTF16.c_str(), wstrUTF16.length(), &TextSize);
BOOL bSpaceExist = (wstrUTF16.find_last_of(L" ") != std::wstring::npos) ? TRUE : FALSE;
int iLocToken = wstrUTF16.length();
while (((size_t)(TextSize.cx / g_fScreenRate_x) > MaxFirstLineWidth) && (iLocToken > -1))
{
iLocToken = (bSpaceExist) ? wstrUTF16.find_last_of(L" ", iLocToken - 1) : iLocToken - 1;
g_pMultiLanguage->_GetTextExtentPoint32(g_pRenderText->GetFontDC(), (wstrUTF16.substr(0, iLocToken)).c_str(), iLocToken, &TextSize);
}
g_pMultiLanguage->ConvertWideCharToStr(strText1, (wstrUTF16.substr(0, iLocToken)).c_str(), CP_UTF8);
g_pMultiLanguage->ConvertWideCharToStr(strText2, (wstrUTF16.substr(iLocToken, wstrUTF16.length() - iLocToken)).c_str(), CP_UTF8);
}
bool SEASON3B::CNewUIChatLogWindow::CheckFilterText(const type_string& strTestText)
{
type_vector_filters::iterator vi_filters = m_vecFilters.begin();
for (; vi_filters != m_vecFilters.end(); vi_filters++)
{
if (FindText(strTestText.c_str(), (*vi_filters).c_str()) == true)
{
return true;
}
}
return false;
}
void SEASON3B::CNewUIChatLogWindow::UpdateWndSize()
{
m_WndSize.cx = WND_WIDTH - 28;
m_WndSize.cy = (SCROLL_MIDDLE_PART_HEIGHT * GetNumberOfShowingLines()) + (SCROLL_TOP_BOTTOM_PART_HEIGHT * 2) + (WND_TOP_BOTTOM_EDGE * 2);
}
void SEASON3B::CNewUIChatLogWindow::UpdateScrollPos()
{
float fPosRate = 1.f;
if (GetNumberOfLines(GetCurrentMsgType()) > GetNumberOfShowingLines())
{
if ((int)GetNumberOfShowingLines() > GetCurrentRenderEndLine())
{
fPosRate = 0.f;
}
else
{
fPosRate = (float)(GetCurrentRenderEndLine() + 1 - GetNumberOfShowingLines()) / (float)(GetNumberOfLines(GetCurrentMsgType()) - GetNumberOfShowingLines());
}
}
if (m_EventState != EVENT_SCROLL_BTN_DOWN)
{
m_ScrollBtnPos.x = m_WndPos.x + m_WndSize.cx - SCROLL_BAR_WIDTH - WND_LEFT_RIGHT_EDGE - 4;
m_ScrollBtnPos.y = m_WndPos.y - m_WndSize.cy + WND_TOP_BOTTOM_EDGE + ((float)(m_WndSize.cy - SCROLL_BTN_HEIGHT - WND_TOP_BOTTOM_EDGE * 2) * fPosRate);
}
}
void SEASON3B::CNewUIChatLogWindow::AddFilterWord(const type_string& strWord)
{
if (m_vecFilters.size() > 5)
return;
type_vector_filters::iterator vi_filters = m_vecFilters.begin();
for (; vi_filters != m_vecFilters.end(); vi_filters++)
{
if (0 == (*vi_filters).compare(strWord))
{
return;
}
}
m_vecFilters.push_back(strWord);
}
void SEASON3B::CNewUIChatLogWindow::ClearAll()
{
for (int i = TYPE_ALL_MESSAGE; i < NUMBER_OF_TYPES; i++)
{
Clear((MESSAGE_TYPE)i);
}
m_iCurrentRenderEndLine = -1;
}
SEASON3B::CNewUIChatLogWindow::type_vector_msgs* SEASON3B::CNewUIChatLogWindow::GetMsgs(MESSAGE_TYPE MsgType)
{
switch (MsgType)
{
case TYPE_ALL_MESSAGE:
return &m_vecAllMsgs;
case TYPE_CHAT_MESSAGE:
return &m_VecChatMsgs;
case TYPE_WHISPER_MESSAGE:
return &m_vecWhisperMsgs;
case TYPE_SYSTEM_MESSAGE:
return &m_VecSystemMsgs;
case TYPE_ERROR_MESSAGE:
return &m_vecErrorMsgs;
case TYPE_PARTY_MESSAGE:
return &m_vecPartyMsgs;
case TYPE_GUILD_MESSAGE:
return &m_vecGuildMsgs;
case TYPE_UNION_MESSAGE:
return &m_vecUnionMsgs;
case TYPE_GENS_MESSAGE:
return &m_vecGensMsgs;
case TYPE_GM_MESSAGE:
return &m_vecGMMsgs;
}
return NULL;
}
void SEASON3B::CNewUIChatLogWindow::ChangeMessage(MESSAGE_TYPE MsgType)
{
m_CurrentRenderMsgType = MsgType;
type_vector_msgs* pvecMsgs = GetMsgs(GetCurrentMsgType());
if (pvecMsgs == NULL)
{
return;
}
m_iCurrentRenderEndLine = pvecMsgs->size() - 1;
}
SEASON3B::MESSAGE_TYPE SEASON3B::CNewUIChatLogWindow::GetCurrentMsgType() const
{
return m_CurrentRenderMsgType;
}
void SEASON3B::CNewUIChatLogWindow::ShowChatLog()
{
m_bShowChatLog = true;
type_vector_msgs* pvecMsgs = GetMsgs(GetCurrentMsgType());
if (pvecMsgs == NULL)
{
return;
}
m_iCurrentRenderEndLine = pvecMsgs->size() - 1;
}
void SEASON3B::CNewUIChatLogWindow::HideChatLog()
{
m_bShowChatLog = false;
}