#include "stdafx.h" /// 2011.07.14 #include "SUINoticeWnd.h" #include #include "SMessage.h" //#include "SGameMessageUI.h" #include "SGameMessage.h" #include "SChatType.h" #include "KUIControlStatic.h" void sNoticeLine::init(char const* text, int chatType) { m_alpha = 1.0f; m_updateTime = 0.0f; m_text = text; m_chatType = chatType; if (CHAT_NOTICE == chatType) { m_normalTime = 10.0f; m_alphaTime = 5.0f; } else if (CHAT_ANNOUNCE == chatType) { m_normalTime = 5.0f; m_alphaTime = 2.5f; } else { m_normalTime = 2.3f; m_alphaTime = 1.0f; } setState(STATE_NORMAL); } void sNoticeLine::setState(int state) { m_state = state; if (STATE_NORMAL == state) { m_v = 1.0f/m_normalTime; } else if (STATE_ALPHA == state) { m_v = 1.0f/m_alphaTime; } } bool sNoticeLine::isShow() const { return m_control ? m_control->IsShow() : false; } void sNoticeLine::updateCaption(bool show) { m_control->SetShow(show); if (show) { std::string caption = getCaptionTag(m_chatType); caption += m_text; m_control->SetCaption(caption.c_str()); m_control->SetShow(true); m_control->ChangeAlpha(m_alpha); } } bool sNoticeLine::updateAlpha(float elapsedtime) { bool end = false; m_updateTime += elapsedtime; if (STATE_NORMAL == m_state) { if (m_updateTime > m_normalTime) { setState(STATE_ALPHA); } } else if (STATE_ALPHA == m_state) { float updateAlphaTime = m_updateTime - m_normalTime; float a = m_v * updateAlphaTime; m_alpha = 1.0f - a; if (0 >= m_alpha) { m_control->SetShow(false); end = true; } m_control->ChangeAlpha(m_alpha); } return end; } char const* sNoticeLine::getCaptionTag(int chatType) { if (chatType == CHAT_NOTICE) { return "<#ffea00>"; // 주의!! 태그를 빼게 되면 한개의 라인이 멀티로 형성될 때 글자 겹침현상이 발생하므로 빼지 말것 2012. 1. 17 - marine } else if( chatType == CHAT_ANNOUNCE) { return "<#00ff00>"; } else { return ""; } return ""; } int sNoticeLine::getHeight() { return m_control->GetCaptionPhraseSize().height; } void sNoticeLine::movePos(int x, int y) { m_control->MovePos(x, y); } bool SUINoticeWnd::CreateControls( class KUIWndManager* pWndManager ) { for (int i = 0; i < MAX_LINE_NUM; ++i) { KUIWND_CREATE_ARG arg; arg.lpszAniName = ""; arg.lpszSprName = m_sSprName.c_str(); arg.lpszClassName = "static"; arg.lpszID = "notice"; // arg.dwFlag = KFLAG_NO_GET_MESSAGE; arg.dwStyle = 0; arg.rcRect = m_rcRegion; arg.pParent = this; //arg.dwFlag = KFLAG_GET_PASS_MESSAGE; arg.dwFlag = KFLAG_GET_PASS_MESSAGE | KFLAG_NO_GET_MESSAGE | KFLAG_NO_GET_FOCUS; /// 2011.06.01 - prodongi KUIWnd* pWnd = pWndManager->CreateControl(arg); m_line[i].m_control = ((KUIControlStatic*)pWnd);; } m_curLine = 0; m_ProcTime = 0; #ifdef _KUI_INVALIDATION AddPopupControl( m_stNotice->m_pStatic[i] ); #endif return true; } void SUINoticeWnd::GetCenterPos(int& x, int& y) { x = KUIWndManager::GetResolution().width/2 - LINE_WIDTH/2; y = LINE_Y * KUIWndManager::GetResolution().height / 1024; } void SUINoticeWnd::ProcMsgAtStatic( SGameMessage* pMsg ) { switch( pMsg->nType ) { case MSG_CHATTING: { SMSG_CHATTING* pChatMsg = (SMSG_CHATTING*)pMsg; if( 0 == ::_stricmp( pChatMsg->szSender.c_str(), "@NOTICE" ) ) { addText( pChatMsg->strText.c_str(), pChatMsg->nChatType); } if( 0 == ::_stricmp( pChatMsg->szSender.c_str(), "@ANNOUNCE" ) ) { addText( pChatMsg->strText.c_str(), pChatMsg->nChatType); } } break; case IMSG_UI_SEND_DATA: { SIMSG_UI_SEND_DATA* pSendMsg = (SIMSG_UI_SEND_DATA*)pMsg; if( pSendMsg->m_strString == "questupdate" ) { addText( pSendMsg->m_strText.c_str(), CHAT_QUEST_SYSTEM ); } } break; } } DWORD SUINoticeWnd::OnMouseMessage(DWORD dwMessage, int x, int y) { //return 0; return KMR_GET_PASS; /// 2011.06.01 - prodongi } void SUINoticeWnd::Process(DWORD dwTime) { KUIWnd::Process(dwTime); DWORD elapsedtime = 0; if (0 != m_ProcTime) elapsedtime = dwTime - m_ProcTime; m_ProcTime = dwTime; updateLineAlpha(elapsedtime); } void SUINoticeWnd::addText(char const* str, int chatType) { if (isFullLine()) { for (int i = 0; i < m_curLine-1; ++i) { m_line[i] = m_line[i+1]; m_line[i].updateCaption(true); } m_line[m_curLine-1].init(str, chatType); m_line[m_curLine-1].updateCaption(true); } else { m_line[m_curLine].init(str, chatType); m_line[m_curLine].updateCaption(true); setCurLine(m_curLine+1); } updateLinePos(); } void SUINoticeWnd::setCurLine(int line) { if (0 > line) line = 0; else if (MAX_LINE_NUM < line) line = MAX_LINE_NUM; m_curLine = line; } void SUINoticeWnd::updateLinePos() { int x, y; GetCenterPos(x, y); sNoticeLine* line; for (int i = 0; i < m_curLine; ++i) { line = m_line + i; line->movePos(x, y); y += line->getHeight(); } } bool SUINoticeWnd::isFullLine() { return m_curLine == MAX_LINE_NUM; } void SUINoticeWnd::updateLineAlpha(DWORD elapsedtime) { bool modify = false; std::vector lineList; float t = (float)elapsedtime/1000.0f; for (int i = 0; i < m_curLine; ++i) { if (m_line[i].isShow()) { if (!m_line[i].updateAlpha(t)) { lineList.push_back(i); } else { modify = true; } } } if (modify) { size_t s = 0; for (; s < lineList.size(); ++s) { m_line[s] = m_line[lineList[s]]; m_line[s].updateCaption(true); } for (; s < MAX_LINE_NUM; ++s) { m_line[s].updateCaption(false); } setCurLine(lineList.size()); updateLinePos(); } lineList.clear(); }