Files
Leviathan/Client/Game/game/Interface/Notification/NotificationEffect.cpp
T
2026-06-01 12:46:52 +02:00

184 lines
4.0 KiB
C++

#include "stdafx.h"
#include "NotificationEffect.h"
//#include "KUIControl.h"
#include "CommonUtil.h"
float sNotificationEffect::UPDATE_TIME = 0.5f;
float sNotificationEffect::UPDATE_WAITING_TIME = 0.2f;
int sNotificationControl::calcHeight(float t)
{
return (int)(m_v * t);
}
void sNotificationControl::animation(float t, KRect const& rect)
{
/// 현재의 높이
int height = calcHeight(t);
int newTop = rect.bottom - height;
int boundTop = rect.top + m_offsetTop;
if (newTop < boundTop)
newTop = boundTop;
modifyRect(newTop, height);
}
void sNotificationControl::modifyRect(int top, int height)
{
KRect r(m_control->GetRect());
r.top = top;
if (m_resize)
{
if (height < m_originalSize.y)
r.bottom = r.top + height;
else
r.bottom = r.top + m_originalSize.y;
m_control->Resize(r);
}
else
{
m_control->MovePos(r.left, r.top);
}
}
void sNotificationControlList::add(sNotificationControl const& control)
{
m_list.push_back(control);
}
void sNotificationControlList::animation(float t, bool firstOpen, KRect const& rect)
{
std::vector<sNotificationControl>::iterator it = m_list.begin();
for (; it != m_list.end(); ++it)
{
it->animation(t, rect);
}
}
void sNotificationControlTitleList::initPos(bool firstOpen, KRect const& rect)
{
std::vector<sNotificationControl>::iterator it = m_list.begin();
if (firstOpen)
{
for (; it != m_list.end(); ++it)
{
it->modifyRect(rect.bottom, it->m_originalSize.y);
}
}
else
{
for (; it != m_list.end(); ++it)
{
it->modifyRect(rect.top + it->m_offsetTop, it->m_originalSize.y);
}
}
}
void sNotificationControlTitleList::animation(float t, bool firstOpen, KRect const& rect)
{
if (!firstOpen)
return ;
sNotificationControlList::animation(t, firstOpen, rect);
}
void sNotificationControlBodyList::initPos(bool firstOpen, KRect const& rect)
{
std::vector<sNotificationControl>::iterator it = m_list.begin();
for (; it != m_list.end(); ++it)
{
it->modifyRect(rect.bottom, 0);
}
}
sNotificationEffect::sNotificationEffect() : m_active(false), m_totalElapsedTime(0.0f)
{
}
sNotificationEffect::~sNotificationEffect()
{
finalize();
}
void sNotificationEffect::initialize(SUIWnd* parent)
{
m_parent = parent;
m_list[CONTROL_TYPE_TITLE] = new sNotificationControlTitleList;
m_list[CONTROL_TYPE_BODY] = new sNotificationControlBodyList;
}
void sNotificationEffect::finalize()
{
for (int type = CONTROL_TYPE_TITLE; type < CONTROL_TYPE_NUM; ++type)
{
SAFE_DELETE(m_list[type]);
}
}
void sNotificationEffect::addControl(char const* controlName, int controlType, bool resize)
{
sNotificationControl control;
control.m_resize = resize;
control.m_control = dynamicCast<KUIControl*>(m_parent->GetChild(controlName));
control.m_offsetTop = control.m_control->GetRect().top - m_parent->GetRect().top;
control.m_originalSize.x = control.m_control->GetRect().GetWidth();
control.m_originalSize.y = control.m_control->GetRect().GetHeight();
int moveLen = m_parent->GetRect().bottom - control.m_control->GetRect().top;
control.m_v = (float)moveLen/sNotificationEffect::UPDATE_TIME;
m_list[controlType]->add(control);
}
void sNotificationEffect::start(bool firstOpen)
{
m_active = true;
m_firstOpen = firstOpen;
m_totalElapsedTime = 0.0f;
initControlPos(firstOpen);
}
void sNotificationEffect::initControlPos(bool firstOpen)
{
for (int type = CONTROL_TYPE_TITLE; type < CONTROL_TYPE_NUM; ++type)
{
m_list[type]->initPos(firstOpen, m_parent->GetRect());
}
}
bool sNotificationEffect::isEnd()
{
return m_totalElapsedTime >= (UPDATE_TIME + UPDATE_WAITING_TIME);
}
void sNotificationEffect::proc(float elapsedTime)
{
if (!m_active)
return ;
m_totalElapsedTime += elapsedTime;
bool end = false;
if (isEnd())
{
end = true;
m_totalElapsedTime = UPDATE_TIME + UPDATE_WAITING_TIME;
}
animation();
if (end)
{
m_active = false;
}
}
void sNotificationEffect::animation()
{
for (int type = CONTROL_TYPE_TITLE; type < CONTROL_TYPE_NUM; ++type)
{
m_list[type]->animation(m_totalElapsedTime, m_firstOpen, m_parent->GetRect());
}
}