Files
2026-06-01 12:46:52 +02:00

274 lines
8.2 KiB
C++

#include "stdafx.h"
#include "SUITargetWnd_Npc.h"
#include "SLog.h"
#include "Util.h"
#include "CommonUtil.h"
#include "KUIDefine.h"
#include "KUIDragAndDrop.h"
#include "KUIControlGauge.h"
#include "KUIControlStatic.h"
#include "SGameManager.h"
namespace nsTargetUI_Npc
{
static const string NPC_JOB_ICON_CONTROL_NAME( "npc_target_job" ); // NPC 직업 아이콘 컨트롤 이름
static const string NPC_JOB_ICON_DEFAULT_NAME( "common_mark_icon_unknown_mini" ); // NPC 직업 아이콘 기본 이름
static const string NPC_NAME_CONTROL_NAME( "npc_target_name_text_long" ); // NPC 이름 컨트롤 이름
static const string NPC_JOB_CONTROL_NAME( "npc_target_text_job_01" ); // NPC 직업 컨트롤 이름
static const string HP_GAUGE_CONTROL_NAME( "npc_target_hpbar" ); // HP 게이지 컨트롤 이름
static const string HP_GAUGE_VALUE_CONTROL_NAME( "npc_static_hp_value" ); // HP 게이지 수치 컨트롤 이름
};
//-----------------------------------------------------------------------------------------------------------------
// 생성자
//-----------------------------------------------------------------------------------------------------------------
SUITargetWnd_Npc::SUITargetWnd_Npc( SGameManager * pGameManager, SUIDisplayInfo* pDisplayInfo )
: SUIWnd( pGameManager )
, m_pDisplayInfo( pDisplayInfo )
, m_pHpGauge( NULL )
, m_pHpGaugeValue( NULL )
, m_pNPCName( NULL )
, m_pNPCJob( NULL )
, m_pIconControl( NULL )
, m_strNpcNamePropertyTag( "" )
, m_strNpcJobPropertyTag( "" )
, m_strHpGaugeValuePropertyTag( "" )
{
}
//-----------------------------------------------------------------------------------------------------------------
// 파괴자
//-----------------------------------------------------------------------------------------------------------------
SUITargetWnd_Npc::~SUITargetWnd_Npc()
{
}
//-----------------------------------------------------------------------------------------------------------------
// 윈도우 생성
//-----------------------------------------------------------------------------------------------------------------
SUIWnd* SUITargetWnd_Npc::CreateWnd( const char* szFile, KUIWndManager* pWndManager, KPoint kPos, int nWindowID )
{
SUIWnd::CreateWnd( szFile, pWndManager, kPos, nWindowID );
return this;
}
//-----------------------------------------------------------------------------------------------------------------
// 데이터 초기화
//-----------------------------------------------------------------------------------------------------------------
bool SUITargetWnd_Npc::InitData( bool bReload /*= false*/ )
{
m_pHpGauge = dynamicCast<KUIControlGauge*>( GetChild( HP_GAUGE_CONTROL_NAME.c_str() ) );
if( NULL == m_pHpGauge )
{
SDEBUGLOG( "[타겟윈도우(NPC)] 컨트롤 정보 얻기 실패 - Name[%s]", HP_GAUGE_CONTROL_NAME.c_str() );
assert( m_pHpGauge );
}
m_pHpGaugeValue = dynamicCast<KUIControlStatic*>( GetChild( HP_GAUGE_VALUE_CONTROL_NAME.c_str() ) );
if( NULL == m_pHpGaugeValue )
{
SDEBUGLOG( "[타겟윈도우(NPC)] 컨트롤 정보 얻기 실패 - Name[%s]", HP_GAUGE_VALUE_CONTROL_NAME.c_str() );
assert( m_pHpGaugeValue );
}
else
{
string strCaption( m_pHpGaugeValue->GetCaption() );
GetTextDecoration( strCaption.c_str(), m_strHpGaugeValuePropertyTag );
m_pHpGaugeValue->SetShow( true );
}
m_pNPCName = dynamicCast<KUIControlStatic*>( GetChild( NPC_NAME_CONTROL_NAME.c_str() ) );
if( NULL == m_pNPCName )
{
SDEBUGLOG( "[타겟윈도우(NPC)] 컨트롤 정보 얻기 실패 - Name[%s]", NPC_NAME_CONTROL_NAME.c_str() );
assert( m_pNPCName );
}
else
{
string strCaption( m_pNPCName->GetCaption() );
GetTextDecoration( strCaption.c_str(), m_strNpcNamePropertyTag );
}
m_pNPCJob = dynamicCast<KUIControlStatic*>( GetChild( NPC_JOB_CONTROL_NAME.c_str() ) );
if( NULL == m_pNPCJob )
{
SDEBUGLOG( "[타겟윈도우(NPC)] 컨트롤 정보 얻기 실패 - Name[%s]", NPC_JOB_CONTROL_NAME.c_str() );
assert( m_pNPCJob );
}
else
{
string strCaption( m_pNPCJob->GetCaption() );
GetTextDecoration( strCaption.c_str(), m_strNpcJobPropertyTag );
}
m_pIconControl = dynamicCast<KUIControlIconStatic*>( GetChild( NPC_JOB_ICON_CONTROL_NAME.c_str() ) );
if( NULL == m_pIconControl )
{
SDEBUGLOG( "[타겟윈도우(NPC)] 컨트롤 정보 얻기 실패 - Name[%s]", NPC_JOB_ICON_CONTROL_NAME.c_str() );
assert( m_pIconControl );
}
return SUIWnd::InitData(bReload);
}
//-----------------------------------------------------------------------------------------------------------------
// 메시지 처리
//-----------------------------------------------------------------------------------------------------------------
void SUITargetWnd_Npc::PumpUpMessage( LPCSTR lpszControlID, DWORD nMessage, DWORD lparam, DWORD wparam )
{
if( NULL == lpszControlID )
return;
string strControlID( lpszControlID );
switch( nMessage )
{
case KBUTTON_CLICK:
case KBUTTON_PRESSING:
{
if( NULL == strControlID.compare( "npc_target_off_01" ) ) // 닫기 버튼 클릭
{
m_pGameManager->PostMsgAtDynamic( new SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_TARGET_NPC, false ) );
// 타겟 해제, 게임 내에 NULL 타겟을 보낸다
SIMSG_UI_ACT_TARGET msg;
msg.m_nTargetHandle = NULL;
m_pGameManager->ProcMsgAtStatic(&msg);
}
}
break;
default:
break;
}
SUIWnd::PumpUpMessage( lpszControlID, nMessage, lparam, wparam );
}
//-----------------------------------------------------------------------------------------------------------------
// 정적 메시지 처리
//-----------------------------------------------------------------------------------------------------------------
void SUITargetWnd_Npc::ProcMsgAtStatic( SGameMessage* pMsg )
{
if( NULL == pMsg )
return;
switch( pMsg->nType )
{
case IMSG_UI_TARGET_INFO:
{
SIMSG_UI_TARGET_INFO_NPC* pTargetMsg = static_cast<SIMSG_UI_TARGET_INFO_NPC*>( pMsg );
ProcessMessage_UITargetInfo( pTargetMsg );
}
break;
}
pMsg->bUse = true;
}
//-----------------------------------------------------------------------------------------------------------------
// 정적 메시지 처리 - UI 타겟 정보
//-----------------------------------------------------------------------------------------------------------------
bool SUITargetWnd_Npc::ProcessMessage_UITargetInfo( SIMSG_UI_TARGET_INFO_NPC* const pTargetMsg )
{
if( NULL == pTargetMsg )
{
SDEBUGLOG( "[타겟윈도우(PROP)] Msg 포인터가 유효하지 않습니다." );
assert( pTargetMsg );
return false;
}
if( NULL == pTargetMsg->handle )
{
SDEBUGLOG( "[타겟윈도우(PROP)] Msg 핸들 정보가 유효하지 않습니다." );
assert( pTargetMsg->handle );
return false;
}
if( m_pNPCName )
{
string strNpcName( m_strNpcNamePropertyTag );
string strTempName( pTargetMsg->strName );
if( NULL == strTempName.length() )
strNpcName.append( "Unknown Name" );
else
strNpcName.append( strTempName );
m_pNPCName->SetCaption( strNpcName.c_str() );
}
if( m_pNPCJob )
{
string strNpcJob( m_strNpcJobPropertyTag );
strNpcJob.append( pTargetMsg->strJobName );
m_pNPCJob->SetCaption( strNpcJob.c_str() );
}
int nMaxHP( max( pTargetMsg->nHP, pTargetMsg->nMaxHP ) );
int nCurrentHP( max( pTargetMsg->nHP, 0 ) );
if( m_pHpGaugeValue )
{
string strHpGaugeValue( m_strHpGaugeValuePropertyTag );
int nExp = 100, nRest = 0;
m_pDisplayInfo->GetPercentValue( nCurrentHP, nMaxHP, &nExp, &nRest );
strHpGaugeValue.append( StringFormat( "%d.%d", nExp, nRest ) );
strHpGaugeValue += "%";
#ifdef _DEV // HP TEXT 출력 부분 ( 개발 버젼에서만 보임 )
strHpGaugeValue.append( StringFormat( "[DEV]%u/%u", nCurrentHP, nMaxHP ) );
#endif
m_pHpGaugeValue->SetCaption( strHpGaugeValue.c_str() );
}
if( m_pHpGauge )
{
m_pHpGauge->SetMax( nMaxHP );
m_pHpGauge->SetGauge( nCurrentHP, NULL );
}
return true;
}
void SUITargetWnd_Npc::Render(KViewportObject * pViewport, bool isFront)
{
if ( m_bShowFlag )
{
std::list< KUIWnd* >::iterator end = m_listChild.end();
int n(0);
for (std::list< KUIWnd* >::iterator it = m_listChild.begin(); it != end ; ++it, n++ )
{
// if( n == 0 )
// continue;
#ifdef _KUI_INVALIDATION
if( !(*it)->IsPopup() )
#endif
(*it)->Render( pViewport, isFront );
}
}
// KUIWnd::Render( pViewport, isFront);
}