#include "StdAfx.h" #include "Icon.h" #include "Token.h" #include "Parser.h" #include "UIContainer.h" #include "PlaneObject.h" #include "FontAgent.h" cIcon::cIcon( eUINodeType type ) : cBaseIcon( type ) , mImageFont( 0 ) , mNumber( 0 ) , mShowGauge( true ) , mShowNumber( true ) , mpEdgeImage(0) , mpCountImage(0) , mpFlashImage(0) , mAniEnable( true ) , mpTipImage(0) { mTipType = eTOOLTIP_NONE; mProcessEnable = true; } cIcon::~cIcon() { SAFE_DELETE( mpFlashImage ); SAFE_DELETE( mpTipImage ); SAFE_DELETE( mpCountImage ); SAFE_DELETE( mpEdgeImage ); } /// ÅøÆÁ À̹ÌÁö ÁöÁ¤ void cIcon::SetTipType( unsigned int type ) { if( mTipType == (eTooltipType)type ) return; mTipType = (eTooltipType)type; if( type == eTOOLTIP_NONE ) return; cIconParam* pTipParam = UIMAN->GetIconParam( 10 ); if( pTipParam ) { unsigned int w = GetAbsoluteRect().GetWidth(); unsigned int h = GetAbsoluteRect().GetWidth(); unsigned int tx = pTipParam->mTexPos.mX + ( type * w ); unsigned int ty = pTipParam->mTexPos.mY; if( mpTipImage ) mpTipImage->SetTextureRect( tx, ty, tx + w, ty + h ); } } void cIcon::ShowGauge( bool show ) { mShowGauge = show; if( mShowGauge == true ) mGauge.SetPos( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } void cIcon::ChangeGauge( cUIRoundGauge& gauge ) { /// ÇÊ¿äÇÑ ¼Ó¼º¸¸ ´ëÀÔ mGauge = gauge; mShowGauge = true; } void cIcon::UpdateGauge( unsigned long startTime, unsigned long elapsedTime, unsigned long maintainTime, bool active ) { mGauge.UpdateGauge( startTime, elapsedTime, maintainTime, active ); } /// ¿À¶ó½ºÅ³ ¼¼ÆÃ void cIcon::SetAuraOn( bool set ) { mAniParam[eANI_AURA].mAniOn = set; mAniParam[eANI_AURA].mLastAccumTime = mAniParam[eANI_AURA].mAccumTime; if( set == true ) { /// ÅØ½ºÃÄ ÁÂÇ¥ ¼¼ÆÃ unsigned int w = mAniParam[eANI_AURA].mWidth; unsigned int h = mAniParam[eANI_AURA].mHeight; unsigned int tx = mAniParam[eANI_AURA].mTexX; unsigned int ty = mAniParam[eANI_AURA].mTexY; /// ¿À¶ó ŸÀÔ mAniParam[eANI_AURA].mCurFrame = 0; if( mpEdgeImage ) mpEdgeImage->SetTextureRect( tx, ty, tx + w, ty + h ); } } bool cIcon::IsAuraOn() { return mAniParam[eANI_AURA].mAniOn; } /// ¾Ö´Ï¸ÞÀÌ¼Ç º¸±â ¼³Á¤ void cIcon::SetAniOn( eAniType type, short frame ) { /// ÅØ½ºÃÄ ÁÂÇ¥ ¼¼ÆÃ unsigned int w = mAniParam[type].mWidth; unsigned int h = mAniParam[type].mHeight; unsigned int tx = mAniParam[type].mTexX; unsigned int ty = mAniParam[type].mTexY; /// Ä«¿îÆ® ŸÀÔ / ¹Ý¦À̱â ŸÀÔ if( type == eANI_COUNT ) { mAniParam[eANI_COUNT].mAniOn = true; mAniParam[eANI_COUNT].mLastAccumTime = mAniParam[eANI_COUNT].mAccumTime; tx = mAniParam[eANI_COUNT].mTexX + ( frame * w ); mAniParam[eANI_COUNT].mCurFrame = frame; if( mpCountImage ) mpCountImage->SetTextureRect( tx, ty, tx + w, ty + h ); } else if( type == eANI_FLASH ) { mAniParam[eANI_FLASH].mAniOn = true; mAniParam[eANI_FLASH].mLastAccumTime = mAniParam[eANI_FLASH].mAccumTime; mAniParam[eANI_FLASH].mCurFrame = 0; mAniParam[eANI_FLASH].mReturn = false; if( mpFlashImage ) mpFlashImage->SetTextureRect( tx, ty, tx + w, ty + h ); } } void cIcon::SetAniParam( sAniParam* param ) { if( param == 0 ) { for( unsigned int i = 0; i < eANI_MAX; ++i ) { mAniParam[i].mAniOn = false; } } else { for( unsigned int i = 0; i < eANI_MAX; ++i, ++param ) { mAniParam[i].mFrame = (*param).mFrame; mAniParam[i].mTexX = (*param).mTexX; mAniParam[i].mTexY = (*param).mTexY; mAniParam[i].mWidth = (*param).mWidth; mAniParam[i].mHeight = (*param).mHeight; mAniParam[i].mCurFrame = (*param).mCurFrame; mAniParam[i].mAniOn = (*param).mAniOn; mAniParam[i].mTimeOut = (*param).mTimeOut; mAniParam[i].mAccumTime = (*param).mAccumTime; mAniParam[i].mLastAccumTime = (*param).mLastAccumTime; mAniParam[i].mReturn = (*param).mReturn; } } } bool cIcon::OnCreate( cUINodeProperty* ) { mImageFont = UIMAN->GetImageFont( eIAMGEFONT_ITEMCOUNT ); /// ¿øÇü °ÔÀÌÁö »ý¼º ¹× ¼¼ÆÃ { cIconParam* pParam = UIMAN->GetIconParam( 1 ); if( pParam == 0 ) { assert(0); return false; } /// »ý¼º unsigned int x = pParam->mTexPos.mX; unsigned int y = pParam->mTexPos.mY; unsigned int w = GetAbsoluteRect().GetWidth(); unsigned int h = GetAbsoluteRect().GetHeight(); mGauge.Create( pParam->mpTexture, (unsigned short)x, (unsigned short)y, (unsigned short)(x + w), (unsigned short)(y + h)); mGauge.SetPos( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } /// ¾Ö´Ï¸ÞÀÌ¼Ç °ü·Ã ¼³Á¤ { /// ¿À¶ó½ºÅ³ Á¤º¸ ¼¼ÆÃ mAniParam[eANI_AURA].mTimeOut = 40; mAniParam[eANI_AURA].mLastAccumTime = 0; mAniParam[eANI_AURA].mFrame = 15; mAniParam[eANI_AURA].mTexX = 3; mAniParam[eANI_AURA].mTexY = 1024; mAniParam[eANI_AURA].mWidth = 30; mAniParam[eANI_AURA].mHeight = 30; mAniParam[eANI_AURA].mAniOn = false; mAniParam[eANI_AURA].mCurFrame = 0; mAniParam[eANI_AURA].mReturn = false; NiTexture* pTex = UIMAN->GetSkin()->GetTexture( 5002 ); unsigned int edgeTexX = mAniParam[eANI_AURA].mTexX; unsigned int edgeTexY = mAniParam[eANI_AURA].mTexY; unsigned int edgeX = GetAbsoluteRect().mLeft - 1; unsigned int edgeY = GetAbsoluteRect().mTop - 1; unsigned int edgeW = mAniParam[eANI_AURA].mWidth; unsigned int edgeH = mAniParam[eANI_AURA].mHeight; mpEdgeImage = new cPlaneObject; if( mpEdgeImage->Create( pTex, edgeX, edgeY, edgeW, edgeH, edgeTexX, edgeTexY, edgeTexX + edgeW, edgeTexY + edgeH ) == false ) { assert( 0 && "failed to create mpEdgeImage" ); return false; } /// Ä«¿îÆ®¿ë À̹ÌÁö ¼¼ÆÃ cIconParam* pCountParam = UIMAN->GetIconParam( 19 ); if( pCountParam ) { mAniParam[eANI_COUNT].mTimeOut = 1; mAniParam[eANI_COUNT].mLastAccumTime = 0; mAniParam[eANI_COUNT].mFrame = 9; mAniParam[eANI_COUNT].mTexX = pCountParam->mTexPos.mX; mAniParam[eANI_COUNT].mTexY = pCountParam->mTexPos.mY; mAniParam[eANI_COUNT].mWidth = 28; mAniParam[eANI_COUNT].mHeight = 28; mAniParam[eANI_COUNT].mAniOn = false; mAniParam[eANI_COUNT].mCurFrame = 9; mAniParam[eANI_COUNT].mReturn = false; } unsigned int countTexX = mAniParam[eANI_COUNT].mTexX; unsigned int countTexY = mAniParam[eANI_COUNT].mTexY; unsigned int countX = GetAbsoluteRect().mLeft; unsigned int countY = GetAbsoluteRect().mTop; unsigned int countW = mAniParam[eANI_COUNT].mWidth; unsigned int countH = mAniParam[eANI_COUNT].mHeight; mpCountImage = new cPlaneObject; if( mpCountImage->Create( pCountParam->mpTexture, countX, countY, countW, countH, countTexX, countTexY, countTexX + countW, countTexY + countH ) == false ) { assert( 0 && "failed to create mpCountImage" ); return false; } /// ¹Ý¦À̴¿ë À̹ÌÁö »ý¼º NiTexture* flashTex = UIMAN->GetSkin()->GetTexture( 3010 ); if( flashTex ) { mAniParam[eANI_FLASH].mTimeOut = 5; mAniParam[eANI_FLASH].mLastAccumTime = 0; mAniParam[eANI_FLASH].mFrame = 32; mAniParam[eANI_FLASH].mTexX = 0; mAniParam[eANI_FLASH].mTexY = 0; mAniParam[eANI_FLASH].mWidth = 28; mAniParam[eANI_FLASH].mHeight = 28; mAniParam[eANI_FLASH].mAniOn = false; mAniParam[eANI_FLASH].mCurFrame = 0; mAniParam[eANI_FLASH].mReturn = false; } unsigned int flashTexX = mAniParam[eANI_FLASH].mTexX; unsigned int flashTexY = mAniParam[eANI_FLASH].mTexY; unsigned int flashX = GetAbsoluteRect().mLeft; unsigned int flashY = GetAbsoluteRect().mTop; unsigned int flashW = mAniParam[eANI_FLASH].mWidth; unsigned int flashH = mAniParam[eANI_FLASH].mHeight; mpFlashImage = new cPlaneObject; if( mpFlashImage->Create( flashTex, flashX, flashY, flashW, flashH, flashTexX, flashTexY, flashTexX + flashW, flashTexY + flashH ) == false ) { assert( 0 && "failed to create mpCountImage" ); return false; } NiAlphaProperty* ap = mpFlashImage->GetAlphaProp(); if( ap ) { ap->SetSrcBlendMode( NiAlphaProperty::ALPHA_ONE ); ap->SetDestBlendMode( NiAlphaProperty::ALPHA_ONE ); } } /// ·¹¾îµµ °ü·Ã À̹ÌÁö Ãß°¡ { cIconParam* pTipParam = UIMAN->GetIconParam( 10 ); if( pTipParam == 0 ) { assert(0); return false; } mpTipImage = new cUIImage( pTipParam->mpTexture ); unsigned int tx = pTipParam->mTexPos.mX; unsigned int ty = pTipParam->mTexPos.mY; unsigned int w = GetAbsoluteRect().GetWidth(); unsigned int h = GetAbsoluteRect().GetWidth(); mpTipImage->SetTextureRect( tx, ty, tx + w, ty + h ); mpTipImage->SetScreenRect( mAbsoluteRect ); } return true; } void cIcon::UpdateRect() { cUINode::UpdateRect(); /// À̹ÌÁö ¿µ¿ªÀ» °»½Å if( mParam && mpImage ) mpImage->SetScreenRect( mAbsoluteRect ); mGauge.SetPos( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); if( mpEdgeImage ) mpEdgeImage->SetTranslate( (short)GetAbsoluteRect().mLeft - 1, (short)GetAbsoluteRect().mTop - 1 ); if( mpCountImage ) mpCountImage->SetTranslate( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); if( mpFlashImage ) mpFlashImage->SetTranslate( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); if( mpTipImage ) { unsigned int x = GetAbsoluteRect().mLeft; unsigned int y = GetAbsoluteRect().mTop; mpTipImage->SetPos( x, y ); } } bool cIcon::SetSkin( const cUINodeSkin* skin ) { if( skin->IsKindof( eUINODE_ICON ) == false ) { assert( 0 && "not icon skin type" ); return false; } /// ³ëµå ½ºÅ²ÀÇ ÀûÇÕ¼º °Ë»ç if( skin->IsValid() == false ) { assert( 0 && "invalid skin" ); return false; } /// À̹ÌÁö ¼³Á¤ if( skin->mpTexture ) { if( mpImage == 0 ) { mpImage = new cUIImage(skin->mpTexture); } else { assert(0); } /// Ä÷¯¸¦ ÁöÁ¤ SetColor( skin->mColor ); /// ÅØ½ºÃ³ ¿µ¿ª ¼³Á¤ unsigned int tx = skin->mSkinInfo->mTexX; unsigned int ty = skin->mSkinInfo->mTexY; unsigned int tw = skin->mSkinInfo->mTexWidth; unsigned int th = skin->mSkinInfo->mTexHeight; mpImage->SetTextureRect( tx, ty, tx + tw, ty + th ); } else { delete mpImage; mpImage = 0; } /// ·çÆ®ÀÇ ¹Ù·Î ÀÚ½ÄÀÎ À©µµ¿ìµéÀº ±âÁ¸ÁÂÇ¥¸¦ ÀúÀåÇÑä ÇØ»óµµ¸¦ º¯°æ if( mpParent == 0 ) { assert(0); return false; } unsigned int x = skin->mSkinInfo->mX; unsigned int y = skin->mSkinInfo->mY; unsigned int w = skin->mSkinInfo->mWidth; unsigned int h = skin->mSkinInfo->mHeight; /// ºÎ¸ð°¡ ·çÆ® ŸÀÔÀÌ¸é ¸ðµÎ °»½Å if( mpParent->GetType() == eUINODE_ROOT ) { x = ( GetScreenWidth() * skin->mSkinInfo->mX ) / mDefaultWidth; y = ( GetScreenHeight() * skin->mSkinInfo->mY ) / mDefaultHeight; /// ¿À¸¥ÂÊÀ̳ª ¾Æ·§ÂÊ¿¡ À©µµ¿ì°¡ ºÙ¾îÀÖÀ¸¸é ÇØ»óµµ º¯°æ½Ã¿¡µµ /// ºÙ¾îÀÖµµ·Ï ÇÑ´Ù if( (skin->mSkinInfo->mX + skin->mSkinInfo->mWidth) >= (int)mDefaultWidth ) { x = GetScreenWidth() - w; } if( (skin->mSkinInfo->mY + skin->mSkinInfo->mHeight) >= (int)mDefaultHeight ) { y = GetScreenHeight() - h; } } /// Àû¿ë SetRelativeRect( cUIRect( x, y, x + w, y + h) ); /// mHoverTipIndex = skin->mSkinInfo->mHoverTipIndex; return true; } void cIcon::OnRender( cUIFontItemKeeper* pKeeper ) { if( mParam == 0 ) return; /// À̹ÌÁö ·»´õ¸µ if( mpImage ) mpImage->Draw(); /// ¿øÇü °ÔÀÌÁö ·»´õ¸µ if( mShowGauge && mGauge.IsActive() ) { mGauge.Draw(); } /// ¹øÈ£ if( mShowNumber && mNumText.IsEmpty() == false ) { const cUIRect& rc = GetAbsoluteRect(); if( mNumber > 999 ) { cStringT str = _T("*"); int w = FONTAGENT->GetTextExtent( cFontAgent::eFont_UI, const_cast(str.Cstr()), str.GetLength() ); int h = FONTAGENT->GetTextHeight( cFontAgent::eFont_UI ); pKeeper->AddFontItem( cFontAgent::eFont_UI, const_cast(str.Cstr()), rc.mRight - w - 3, rc.mBottom - h + 1, COLOR_WHITE, mOutLine ); } else { if( mImageFont ) mImageFont->DrawText( rc.mRight - mImageFont->GetTextWidth(mNumber) - 1, rc.mBottom - mImageFont->GetTextHeight() - 1, mNumText.Cstr() ); } } if( mAniEnable ) { if( mpCountImage && mAniParam[eANI_COUNT].mAniOn == true ) mpCountImage->Draw(); if( mpFlashImage && mAniParam[eANI_FLASH].mAniOn == true ) mpFlashImage->Draw(); if( mpEdgeImage && mAniParam[eANI_AURA].mAniOn == true ) mpEdgeImage->Draw(); } /// ·¹¾îµµ °ü·Ã À̹ÌÁö if( mTipType != eTOOLTIP_NONE && mpTipImage ) mpTipImage->Draw(); } void cIcon::OnProcess( unsigned long /*deltaTime*/, unsigned long accumTime ) { if( mAniEnable ) { /// ŸÀÌ¸Ó for( unsigned int i = 0; i <= eANI_FLASH; ++i ) { /// ŸÀÌ¸Ó mAniParam[i].mAccumTime = accumTime; unsigned long elasedTime = mAniParam[i].mAccumTime - mAniParam[i].mLastAccumTime; if( mAniParam[i].mAniOn && elasedTime > mAniParam[i].mTimeOut ) { /// ŸÀÔ¿¡ µû¸¥ È£Ãâ OnTimer(i); mAniParam[i].mLastAccumTime = mAniParam[i].mAccumTime; } } } if( mGauge.IsActive() ) { unsigned int state = mGauge.Update( accumTime ); if( state == cUIRoundGauge::eGaugeState_End ) { /// ³¡³ª´Â ¼ø°£¿¡ ¾ÆÀÌÄÜ ¹Ý¦ÀÌ´Â À̹ÌÁö ÇÊ¿ä mAniParam[eANI_COUNT].mAniOn = false; SetAniOn( eANI_FLASH ); } else if( mGauge.GetRestTime() > 0 && mGauge.GetRestTime() < 9000 ) { /// ÄðŸÀÓ Ä«¿îÆ® À̹ÌÁö short frame = (short)mGauge.GetRestTime()/1000; SetAniOn( eANI_COUNT, frame ); } } } /// ¾Ö´Ï¸ÞÀÌ¼Ç µ¹¸®±â void cIcon::OnTimer( unsigned int type ) { if( type == eANI_AURA ) { /// ¿À¶ó ¾Ö´Ï¸ÞÀÌ¼Ç ÇÁ·¹ÀÓ µ¹¸®±â if( mAniParam[eANI_AURA].mAniOn == true ) { mAniParam[eANI_AURA].mCurFrame++; /// ÇÁ·¹ÀÓÀ» ³Ñ¾î°¡¸é ÃʱâÈ­ if( mAniParam[eANI_AURA].mCurFrame >= mAniParam[eANI_AURA].mFrame ) mAniParam[eANI_AURA].mCurFrame = 0; /// ÅØ½ºÃÄ ÁÂÇ¥ ¼¼ÆÃ unsigned int w = mAniParam[eANI_AURA].mWidth; unsigned int h = mAniParam[eANI_AURA].mHeight; unsigned int tx = mAniParam[eANI_AURA].mTexX + ( mAniParam[eANI_AURA].mCurFrame * w ); unsigned int ty = mAniParam[eANI_AURA].mTexY; if( mpEdgeImage ) mpEdgeImage->SetTextureRect( tx, ty, tx + w, ty + h ); } } else if( type == eANI_FLASH ) { /// ¹Ý¦ÀÌ´Â À̹ÌÁö ÇÁ·¹ÀÓ µ¹¸®±â if( mAniParam[eANI_FLASH].mAniOn == true ) { mAniParam[eANI_FLASH].mCurFrame++; /// max ³Ñ¾î°¡¸é ²ô±â if( mAniParam[eANI_FLASH].mCurFrame >= mAniParam[eANI_FLASH].mFrame ) mAniParam[eANI_FLASH].mAniOn = false; int line = (int)(mAniParam[eANI_FLASH].mCurFrame / 9); int num = (int)(mAniParam[eANI_FLASH].mCurFrame % 9); unsigned int w = mAniParam[eANI_FLASH].mWidth; unsigned int h = mAniParam[eANI_FLASH].mHeight; unsigned int tx = mAniParam[eANI_FLASH].mTexX + ( num * w ); unsigned int ty = mAniParam[eANI_FLASH].mTexY + ( line * h ); if( mpFlashImage ) mpFlashImage->SetTextureRect( tx, ty, tx + w, ty + h ); } } } void cIcon::StartDelay( unsigned long delayTime ) { mGauge.Activate( delayTime ); } void cIcon::StopDelay() { mGauge.DeActivate(); SetAniParam(0); } void cIcon::SetElapsedTime( unsigned long delta ) { mGauge.SetElapsedTime( delta ); } bool cIcon::IsActive() { return mGauge.IsActive(); } void cIcon::ClearCooltime() { if( IsAuraOn() == false ) StopDelay( ); SetAniOn( eANI_FLASH ); }