133 lines
3.0 KiB
C++
133 lines
3.0 KiB
C++
#include "stdafx.h"
|
|
#include "KPrimitiveSprite.h"
|
|
#include "KUITextureManager.h"
|
|
#include "KResourceManager.h"
|
|
#include "KUIControlFuryGauge.h"
|
|
#include "KViewport.h"
|
|
|
|
namespace
|
|
{
|
|
KUIWnd* Creator()
|
|
{
|
|
return new KUIControlFuryGauge;
|
|
}
|
|
bool bRegister = KUIFactory::GetInstance()->RegisterCreator( Creator, "fury_gauge");
|
|
|
|
const int X_MARGIN = 1;
|
|
const int LEVEL_PER_PERCENT = 25;
|
|
const int TOTAL_GAUGE_LEVEL = 100 / LEVEL_PER_PERCENT;
|
|
}
|
|
|
|
KUIControlFuryGauge::KUIControlFuryGauge()
|
|
{
|
|
m_curPercent = 0;
|
|
m_curNumberOfSprite = 0;
|
|
}
|
|
KUIControlFuryGauge::~KUIControlFuryGauge()
|
|
{
|
|
SAFE_DELETE_VECTOR(m_vtGaugeSprite);
|
|
}
|
|
|
|
void KUIControlFuryGauge::SetPercent(size_t percent)
|
|
{
|
|
size_t curPercent = std::min(static_cast<size_t>( 100 ),percent);
|
|
|
|
if( m_curPercent != curPercent )
|
|
{
|
|
m_curPercent = curPercent;
|
|
|
|
_CalculateCurNumberOfSprite();
|
|
if( _UpdateAninameByPercent() )
|
|
_UpdateSpriteRes();
|
|
|
|
InvalidateWnd();
|
|
}
|
|
}
|
|
|
|
void KUIControlFuryGauge::Render(KViewportObject * pViewport, bool isFront)
|
|
{
|
|
if(false == m_bShowFlag)
|
|
return;
|
|
|
|
_RenderPrimitive( pViewport);
|
|
}
|
|
void KUIControlFuryGauge::OnChagneBackNotify()
|
|
{
|
|
_initControl();
|
|
|
|
#ifdef _KUI_INVALIDATION
|
|
//인벨리데이트로 추가된부분 주의요망
|
|
KUIControl::OnChagneBackNotify();
|
|
#endif
|
|
}
|
|
|
|
void KUIControlFuryGauge::_initControl()
|
|
{
|
|
if( m_sAniName.empty() )
|
|
{
|
|
m_rcCaptionArea = m_rcRegion;
|
|
return;
|
|
}
|
|
|
|
KResSprite* pFrame = _getSpriteSet()->GetSpriteRes( m_sAniName.c_str(), 0);
|
|
size_t xSize = pFrame->GetSizeX() + X_MARGIN;
|
|
|
|
assert( pFrame && "Cannot find Sprite Res Frame" );
|
|
size_t totalSpriteSize = m_rcCaptionArea.GetWidth() / xSize;
|
|
|
|
for(size_t i = 0; i < totalSpriteSize; ++i)
|
|
{
|
|
KSpritePrimitive* pSprite = new KSpritePrimitive;
|
|
pSprite->SetPosition(m_rcRegion.left + i * xSize, m_rcRegion.top , m_fZPos);
|
|
m_vtGaugeSprite.push_back( pSprite);
|
|
_registerSprite(pSprite);
|
|
}
|
|
|
|
_CalculateCurNumberOfSprite();
|
|
_UpdateAninameByPercent();
|
|
_UpdateSpriteRes();
|
|
|
|
}
|
|
|
|
void KUIControlFuryGauge::_UpdateSpriteRes()
|
|
{
|
|
KUITextureManager::GetManager()->GetSprAni( m_sSprName.c_str(), m_sAniName.c_str() );
|
|
KResSprite* pFrame = _getSpriteSet()->GetSpriteRes( m_sAniName.c_str(), 0);
|
|
assert( pFrame && "Cannot find Sprite Res Frame" );
|
|
|
|
for(size_t i = 0; i < m_vtGaugeSprite.size(); ++i)
|
|
{
|
|
m_vtGaugeSprite.at(i)->SetRes(pFrame);
|
|
}
|
|
}
|
|
void KUIControlFuryGauge::_RenderPrimitive(KViewportObject* pViewport)
|
|
{
|
|
for(size_t i = 0; i < m_curNumberOfSprite; ++i)
|
|
{
|
|
pViewport->Register(m_vtGaugeSprite.at(i) );
|
|
}
|
|
}
|
|
|
|
void KUIControlFuryGauge::_CalculateCurNumberOfSprite()
|
|
{
|
|
m_curNumberOfSprite = m_vtGaugeSprite.size() * m_curPercent / 100;
|
|
}
|
|
bool KUIControlFuryGauge::_UpdateAninameByPercent()
|
|
{
|
|
size_t curLevel = std::max(static_cast<size_t>( 0 ), (m_curPercent - 1) / LEVEL_PER_PERCENT );
|
|
|
|
char buf[10];
|
|
_snprintf(buf,10,"%d",curLevel);
|
|
|
|
size_t lastPos = m_sAniName.size() - 1;
|
|
|
|
// 비교
|
|
if(m_sAniName.empty() == false && m_sAniName.at(lastPos) != buf[0] )
|
|
{
|
|
m_sAniName.at(lastPos) = buf[0];
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|