231 lines
4.8 KiB
C++
231 lines
4.8 KiB
C++
#include "stdafx.h"
|
|
#include "SUIAnnounceWnd.h"
|
|
#include "SGameManager.h"
|
|
//#include "SGameMessageUI.h"
|
|
#include "CommonUtil.h"
|
|
#include "KUIControlStatic.h"
|
|
|
|
struct sAnnounceWnd
|
|
{
|
|
public:
|
|
void init(char const* str, float showingTime, float alpha)
|
|
{
|
|
m_text = "<font:font_02><size:16><hcenter>";
|
|
m_text += str;
|
|
m_textControl->SetCaption(m_text.c_str());
|
|
m_showingTime = showingTime;
|
|
m_wnd->SetShow(true);
|
|
m_wnd->ChangeAlpha(alpha);
|
|
reHeightAtText();
|
|
}
|
|
void moveText(sAnnounceWnd const& wnd)
|
|
{
|
|
float alpha = wnd.m_wnd->GetAlpha() - 0.25f;
|
|
init(wnd.m_text.c_str(), wnd.m_showingTime, alpha);
|
|
}
|
|
void setCenterPosX()
|
|
{
|
|
int width = KUIWndManager::GetResolution().width;
|
|
int centerx = width >> 1;
|
|
int x = centerx - (m_wnd->GetRect().GetWidth() >> 1);
|
|
|
|
m_wnd->MovePos(x, m_wnd->GetRect().top);
|
|
}
|
|
void process(float elapsedTime)
|
|
{
|
|
if (!isShow())
|
|
return ;
|
|
|
|
m_showingTime += elapsedTime;
|
|
if ((float)SHOWING_TIME <= m_showingTime)
|
|
{
|
|
m_wnd->SetShow(false);
|
|
}
|
|
}
|
|
void setPosY(int& y)
|
|
{
|
|
y -= m_wnd->GetRect().GetHeight();
|
|
y += 2; /// 공지들이 서로 붙어야 되는데, 약간의 갭이 있다, 갭이 없어야 되는데,,,
|
|
m_wnd->MovePos(m_wnd->GetRect().left, y);
|
|
}
|
|
void setWnd(SUIWnd* wnd)
|
|
{
|
|
m_wnd = wnd;
|
|
m_textControl = dynamicCast<KUIControlStatic*>(wnd->GetChild("arena_msg_00"));
|
|
m_bgControl = dynamicCast<KUIControlStatic*>(wnd->GetChild("msg_bg"));
|
|
|
|
m_minHeight = m_wnd->GetRect().GetHeight();
|
|
}
|
|
bool isShow() const { return m_wnd->IsShow(); }
|
|
|
|
private:
|
|
void reHeightAtText()
|
|
{
|
|
int textHeight = m_textControl->GetCaptionPhraseSize().height;
|
|
textHeight = ::max(m_minHeight, textHeight);
|
|
|
|
KRect r;
|
|
/// text
|
|
r = m_textControl->GetRect();
|
|
r.bottom = r.top + textHeight;
|
|
m_textControl->Resize(r);
|
|
|
|
/// bg
|
|
r = m_bgControl->GetRect();
|
|
r.bottom = r.top + textHeight;
|
|
m_bgControl->Resize(r);
|
|
|
|
/// wnd
|
|
/// resize로 하면 최소 사이즈에 걸려서 setRect로 함
|
|
m_wnd->SetRect(r);
|
|
m_wnd->ClipRect(r);
|
|
}
|
|
|
|
private:
|
|
enum { SHOWING_TIME = 3 }; /// window 가 보여지는 시간(초)
|
|
|
|
std::string m_text;
|
|
SUIWnd* m_wnd;
|
|
KUIControlStatic* m_textControl;
|
|
KUIControlStatic* m_bgControl;
|
|
float m_showingTime;
|
|
int m_minHeight;
|
|
};
|
|
|
|
|
|
SUIAnnounceWnd::SUIAnnounceWnd(SGameManager *pGameManager) : SUIWnd(pGameManager),
|
|
m_announceWnd(NULL),
|
|
m_time(0)
|
|
{
|
|
}
|
|
|
|
SUIAnnounceWnd::~SUIAnnounceWnd()
|
|
{
|
|
SAFE_DELETE_ARRAY(m_announceWnd);
|
|
}
|
|
|
|
bool SUIAnnounceWnd::InitControls(KPoint kPos)
|
|
{
|
|
bool ret = SUIWnd::InitControls(kPos);
|
|
createAnnounceWnd();
|
|
|
|
SetShow(false);
|
|
SetRect(KRect(0, 0, KUIWndManager::GetResolution().width, KUIWndManager::GetResolution().height));
|
|
|
|
return ret;
|
|
}
|
|
|
|
void SUIAnnounceWnd::OnNotifyUIWindowOpen(bool bOpen, bool bLimitWnd)
|
|
{
|
|
if (bOpen)
|
|
{
|
|
initDatas();
|
|
}
|
|
}
|
|
|
|
void SUIAnnounceWnd::initDatas()
|
|
{
|
|
m_time = 0;
|
|
}
|
|
|
|
void SUIAnnounceWnd::ProcMsgAtStatic(SGameMessage *pMsg)
|
|
{
|
|
switch (pMsg->nType)
|
|
{
|
|
case IMSG_ANNOUNCE: setText(pMsg);
|
|
initDatas();
|
|
postShowMsg(true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void SUIAnnounceWnd::createAnnounceWnd()
|
|
{
|
|
m_announceWnd = new sAnnounceWnd[MAX_ANNOUNCE_NUM];
|
|
|
|
for (int i = 0; i < MAX_ANNOUNCE_NUM; ++i)
|
|
{
|
|
SUIWnd* wnd = new SUIWnd(m_pGameManager);
|
|
wnd->CreateWnd("window_system_main_message.nui", m_pManager, KPoint(0, 0));
|
|
wnd->SetParent(this);
|
|
wnd->SetShow(false);
|
|
AddChild(wnd);
|
|
|
|
m_announceWnd[i].setWnd(wnd);
|
|
}
|
|
|
|
setAnnounceWndCenterPosX();
|
|
}
|
|
|
|
void SUIAnnounceWnd::Process(DWORD dwTime)
|
|
{
|
|
DWORD elapsedTime = 0;
|
|
if (m_time)
|
|
elapsedTime = dwTime - m_time;
|
|
m_time = dwTime;
|
|
|
|
float e = elapsedTime/1000.0f;
|
|
procShowing(e);
|
|
}
|
|
|
|
void SUIAnnounceWnd::procShowing(float elapsedTime)
|
|
{
|
|
bool isAllHide = true;
|
|
for (int i = 0; i < MAX_ANNOUNCE_NUM; ++i)
|
|
{
|
|
m_announceWnd[i].process(elapsedTime);
|
|
if (m_announceWnd[i].isShow())
|
|
isAllHide = false;
|
|
}
|
|
|
|
if (isAllHide)
|
|
postShowMsg(false);
|
|
}
|
|
|
|
void SUIAnnounceWnd::setText(SGameMessage* msg)
|
|
{
|
|
SIMSG_ANNOUNCE* announceMsg = dynamicCast<SIMSG_ANNOUNCE*>(msg);
|
|
if (!announceMsg)
|
|
return ;
|
|
|
|
moveAnnounceTextToUp();
|
|
m_announceWnd[0].init(announceMsg->text.c_str(), 0.0f, 1.0f);
|
|
alignAnnounceWndPosY(BASE_ANNOUNCE_POS_Y);
|
|
postShowMsg(true);
|
|
}
|
|
|
|
void SUIAnnounceWnd::moveAnnounceTextToUp()
|
|
{
|
|
for (int i = MAX_ANNOUNCE_NUM-1; i >= 1; --i)
|
|
{
|
|
if (m_announceWnd[i-1].isShow())
|
|
{
|
|
m_announceWnd[i].moveText(m_announceWnd[i-1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void SUIAnnounceWnd::alignAnnounceWndPosY(int baseY)
|
|
{
|
|
int y = baseY;
|
|
for (int i = 0; i < MAX_ANNOUNCE_NUM; ++i)
|
|
{
|
|
m_announceWnd[i].setPosY(y);
|
|
}
|
|
}
|
|
|
|
void SUIAnnounceWnd::setAnnounceWndCenterPosX()
|
|
{
|
|
for (int i = 0; i < MAX_ANNOUNCE_NUM; ++i)
|
|
{
|
|
m_announceWnd[i].setCenterPosX();
|
|
}
|
|
}
|
|
|
|
void SUIAnnounceWnd::postShowMsg(bool show)
|
|
{
|
|
if (IsShow() == show)
|
|
return ;
|
|
m_pGameManager->PostMsgAtDynamic( new SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_ANNOUNCE, show) );
|
|
}
|