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

402 lines
13 KiB
C++

#include "stdafx.h"
#include "KUITabControl.h"
#include "KUIControlStatic.h"
#include "KUIControlScroll.h"
#include "SGameManager.h"
#include "SUICommunityGuild.h"
#include "SMessengerMgr.h"
//#include "SGameMessageUI.h"
#include "SStringDB.h"
#include "SJobDB.h"
//#include "Util.h"
#include <toolkit/nsl.h>
#include <toolkit/nsluni.h>
#include "CInput.h" //길드명출력하는 부분에서 이용함 -N4-
#include "SDebug_Util.h"
#include "SGameMessage.h"
namespace
{
const int c_nLineSize = 10;
const int c_nLineHeight = 20;
const int c_nLineDelta = 2;
const int c_nMaxGuildName = 24;
const int c_nMaxGuildNameCaption = 512;
const char * c_szDEF_SPR_NAME = "ui_frame.spr";
}
namespace
{
const int c_nClickedIconMoveX = 19;
const int c_nClickedIconMoveY = 2;
}
SUICommunityGuild::~SUICommunityGuild()
{
}
bool SUICommunityGuild::InitControls( KPoint kPos )
{
//총 10개 9개는 Copy
//copy control
RECT rc;
rc.left = 0; rc.top = c_nLineHeight+c_nLineDelta; rc.right = 0; rc.bottom = c_nLineHeight+c_nLineDelta;
for( int i = 1; i < c_nLineSize; i++ )
{
CopyControl( CStringUtil::StringFormat( "static_connection_state%02d", i-1 ).c_str(), CStringUtil::StringFormat( "static_connection_state%02d", i ).c_str(), rc ); //상태 아이콘
CopyControl( CStringUtil::StringFormat( "icon_member_job_icon%02d" , i-1 ).c_str(), CStringUtil::StringFormat( "icon_member_job_icon%02d" , i ).c_str(), rc ); //직업 아이콘
CopyControl( CStringUtil::StringFormat( "static_member_level%02d" , i-1 ).c_str(), CStringUtil::StringFormat( "static_member_level%02d" , i ).c_str(), rc ); //레벨
CopyControl( CStringUtil::StringFormat( "static_member_name%02d" , i-1 ).c_str(), CStringUtil::StringFormat( "static_member_name%02d" , i ).c_str(), rc ); //이름
}
for( int i(0); c_nLineSize>i; i++ )
{
SetChildShow( CStringUtil::StringFormat( "static_connection_state%02d", i ).c_str(), false );
SetChildShow( CStringUtil::StringFormat( "icon_member_job_icon%02d" , i ).c_str(), false );
SetChildShow( CStringUtil::StringFormat( "static_member_level%02d" , i ).c_str(), false );
SetChildShow( CStringUtil::StringFormat( "static_member_name%02d" , i ).c_str(), false );
SetChildCaption( CStringUtil::StringFormat( "static_member_level%02d", i ).c_str(), "" );
SetChildCaption( CStringUtil::StringFormat( "static_member_name%02d", i ).c_str(), "" );
KUIWnd * pIcon = GetChild( CStringUtil::StringFormat( "icon_member_job_icon%02d", i ).c_str() );
if( pIcon ) pIcon->SetCorrectionRect( KRect( 0, 0, 142, 0 ) );
}
SetChildShow( "common_selectclickbackground", false );
m_nSelectIndex = -1;
SetChildCaption( "guild_master_name", S(6368) );
return SUIWnd::InitControls( kPos );
}
bool SUICommunityGuild::InitData( bool bReload /*= false*/ )
{
m_nScrollPos = 0;
return SUIWnd::InitData( bReload );
}
void SUICommunityGuild::PumpUpMessage( LPCSTR lpszControlID, DWORD nMessage, DWORD lparam, DWORD wparam )
{
switch( nMessage )
{
case KUI_MESSAGE::KBUTTON_CLICK:
{
if( ::_stricmp( lpszControlID, "button_close" ) == 0 )
{
}
else if( ::_stricmp( lpszControlID, "button00" ) == 0 )
{
ReqWhisper();
}
else if( ::_stricmp( lpszControlID, "button01" ) == 0 )
{
ReqParty();
}
}
break;
case KUI_MESSAGE::KSCROLL_SELECT: // 스크롤 선택
{
int nPos = int(lparam);
nPos = max( nPos, 0 );
m_nScrollPos = nPos;
RefreshMember( m_nScrollPos );
// _oprint( "Scroll Pos : %d\n", nPos );
}
break;
case KUI_MESSAGE::KFOCUS_ACTIVATED :
{
int x = static_cast<int>(lparam);
int y = static_cast<int>(wparam);
if( GetRect().IsInRect( x, y ) ) //윈도우 안에 클릭되었다면
{
bool bClickedMember(false);
for( int i(0); c_nLineSize>i; i++ ) //윈도우에 보여지는 라인수 10개만큼 돌면서
{
KUIWnd * pIcon = GetChild( CStringUtil::StringFormat( "icon_member_job_icon%02d", i ).c_str() ); //아이콘을 얻어오고
if( pIcon && pIcon->IsInRect( x, y ) ) //아이콘이 클릭되었는지 알아보고
{
m_nSelectIndex = i;
KUIWnd * pSelect = GetChild( "common_selectclickbackground" ); //클릭된곳 그려줄 이미지 가져오고서
if( pSelect )
{
KRect rt = pIcon->GetRect();
pSelect->MovePos( rt.left-c_nClickedIconMoveX, rt.top-c_nClickedIconMoveY ); //아이콘 있는 위치로 이동
pSelect->SetShow(true); //클릭된것이니 랜더링건다
bClickedMember = true;
}
KUIWnd * pIcon = GetChild( CStringUtil::StringFormat( "static_member_name%02d", i ).c_str() ); //클릭된곳의 캐릭이름
if( pIcon )
{
m_strClickedMamber = pIcon->GetCaption();
std::string::size_type pos = m_strClickedMamber.rfind( '>' );
if( pos != std::string::npos )
m_strClickedMamber.erase( 0 , pos+1 );
}
break;
}
}
if( !bClickedMember )
{
//타이틀바를 클릭했을때는 랜더링을 끄는게 더 이상해서 예외처리
KUIWnd * pTitle = GetChild( "static_common_titlebar01" );
if( pTitle && !pTitle->GetRect().IsInRect( x, y ) )
{
SetChildShow( "common_selectclickbackground", false ); //다른곳이 클릭되면 랜더링 끈다.
m_strClickedMamber.clear();
m_nSelectIndex = -1;
}
}
}
}
break;
case KUI_MESSAGE::KGENWND_MOVE:
{
LimitMoveWnd();
}
break;
}
SUIWnd::PumpUpMessage( lpszControlID, nMessage, lparam, wparam );
}
void SUICommunityGuild::ProcMsgAtStatic( SGameMessage* pMsg )
{
switch(pMsg->nType)
{
case MSG_CHANGE_NAME :
{
RefreshMember( m_nScrollPos );
RefreshStatic();
}
break;
case IMSG_UI_SEND_DATA:
{
SIMSG_UI_SEND_DATA *pData = (SIMSG_UI_SEND_DATA *)pMsg;
if( pData->m_strString == "guild_update" )
{
RefreshStatic();
RefreshScrollbar();
RefreshMember( m_nScrollPos );
}
}
break;
}
}
void SUICommunityGuild::GuildUpdate()
{
RefreshStatic();
RefreshScrollbar();
RefreshMember( m_nScrollPos );
}
void SUICommunityGuild::RefreshStatic()
{
std::string strGuileName;
CuttingGuildName( strGuileName );
SetChildCaption( "guild_name" , CStringUtil::StringFormat( "<B>%s<SIZE:9><top><left><#fbe8ad>%s</B>", S(6425), strGuileName.c_str() ).c_str() );
SetChildCaption( "guild_master_name_value" , CStringUtil::StringFormat( "%s<top><left>%s" , S(6425), m_GuildMgr.GetGuildLeaderName() ).c_str() );
SetChildCaption( "guild_connection_state_value", CStringUtil::StringFormat( "%s<top><left>( %d / %d )", S(6425), m_GuildMgr.GetLoginMemberCount(), m_GuildMgr.GetMemberCount() ).c_str() );
}
void SUICommunityGuild::CuttingGuildName( std::string& rGuildName ) //길드명이 커뮤니티창을 넘는것 방지하기 위한 함수 -N4-
{
KUIControl* pGuildNameCtr = dynamicCast<KUIControl*>(GetChild( "guild_name" ));
if( pGuildNameCtr != NULL )
{
rGuildName = m_GuildMgr.GetGuildName();
std::vector<std::string> lineList;
pGuildNameCtr->SplitLine(lineList, rGuildName, S(6425), 9, true);
if( lineList.size() > 1 )
{
/*
wchar_t wtempCmpStr[c_nMaxGuildNameCaption] ={NULL,};
DWORD CodePage = GetCodePageFromLang((LANGID)GetSystemDefaultLangID()); //이것을 삭제할때는 위의 #include "CInput.h"도 삭제할 것
MultiByteToWideChar(CodePage, 0, lineList[0].c_str(), lineList[0].length(), wtempCmpStr, c_nMaxGuildNameCaption);
std::wstring wCmpStr = wtempCmpStr;
wCmpStr.erase( wCmpStr.end()-1 );
wCmpStr += L"..";
char tempCutStr[c_nMaxGuildNameCaption] = {NULL,};
ConvertString(CodePage, wCmpStr.c_str(), wCmpStr.length(), tempCutStr, c_nMaxGuildNameCaption);
rGuildName = tempCutStr;
*/
///
//유코드 변환 과정에서 윈도우 로컬 관련 문제점을 iconv로 수정
//2009-06-24: hunee
std::wstring wstr = nsl::uni::conv(lineList[0].c_str());
wstr.erase(wstr.end()-1);
wstr += L"..";
std::string str = nsl::uni::conv(wstr.c_str());
rGuildName = str;
}
lineList.clear();
}
}
void SUICommunityGuild::OnNotifyUIWindowOpen( bool bOpen, bool bLimitWnd /* = true*/ )
{
if( bOpen )
{
RefreshScrollbar();
RefreshMember( m_nScrollPos );
RefreshStatic();
}
else
{
}
SUIWnd::OnNotifyUIWindowOpen( bOpen, bLimitWnd );
}
void SUICommunityGuild::RefreshScrollbar()
{
int nScrollRange = std::max(m_GuildMgr.GetMemberCount() - c_nLineSize, 0);
KUIControlVScroll* pScrollBar = dynamicCast<KUIControlVScroll*>(GetChild( "scrollbar_guild_list" ));
if( NULL != pScrollBar )
{
pScrollBar->SetMaxRange( DWORD(nScrollRange+1) );
}
}
void SUICommunityGuild::EnableSlot( int nIndex, bool bEnable )
{
SetChildShow( CStringUtil::StringFormat( "static_connection_state%02d", nIndex ).c_str(), bEnable );
SetChildShow( CStringUtil::StringFormat( "icon_member_job_icon%02d" , nIndex ).c_str(), bEnable );
SetChildShow( CStringUtil::StringFormat( "static_member_level%02d" , nIndex ).c_str(), bEnable );
SetChildShow( CStringUtil::StringFormat( "static_member_name%02d" , nIndex ).c_str(), bEnable );
}
void SUICommunityGuild::SetGuildData( int nIndex, SPlayerSlot * pData )
{
SPlayerSlot * pPlayerSlot = pData;
KUIControlIconStatic* pConnectionIcon = dynamicCast<KUIControlIconStatic*>(GetChild( CStringUtil::StringFormat( "static_connection_state%02d" , nIndex ).c_str() ));
if( pConnectionIcon )
{
//"static_messenger_away"
//"static_messenger_busy"
pConnectionIcon->SetIcon( c_szDEF_SPR_NAME, (pPlayerSlot->IsLogin() ? "static_messenger_online" : "static_messenger_offline") );
pConnectionIcon->SetTooltip(NULL);
}
KUIControlIconStatic* pJobIcon = dynamicCast<KUIControlIconStatic*>(GetChild( CStringUtil::StringFormat( "icon_member_job_icon%02d" , nIndex ).c_str() ));
if( pJobIcon )
{
pJobIcon->SetIcon( c_szDEF_SPR_NAME, GetJobDB().GetJobIconName( pPlayerSlot->GetJobID() ) );
pJobIcon->SetTooltip(NULL);
}
SetChildCaption( CStringUtil::StringFormat( "static_member_level%02d", nIndex ).c_str(), CStringUtil::StringFormat( "%s<left><vcenter><#93fe00>%d", S(6425), pPlayerSlot->GetLevel() ).c_str() );
SetChildCaption( CStringUtil::StringFormat( "static_member_name%02d" , nIndex ).c_str(), CStringUtil::StringFormat( "%s<left><#fbe8ad><vcenter>%s", S(6425), pPlayerSlot->GetName() ).c_str() );
}
void SUICommunityGuild::RefreshMember( int nRange )
{
int nStart = nRange;
std::vector< SPlayerSlot * > & memberList = m_GuildMgr.GetMemberList();
bool bClikedMemberRender(false);
for( int i = 0; i < c_nLineSize; i++ )
{
if( i >= c_nLineSize )
{
EnableSlot(i, false);
continue;
}
if( i+nRange < static_cast<int>(memberList.size()) )
{
SPlayerSlot * pPlayerSlot = memberList[i+nRange];
EnableSlot(i, true );
SetGuildData( i, pPlayerSlot );
if( m_strClickedMamber.length() && m_strClickedMamber == pPlayerSlot->GetName() )
{
KUIWnd * pIcon = GetChild( CStringUtil::StringFormat( "icon_member_job_icon%02d", i ).c_str() ); //아이콘을 얻어오고
if( pIcon )
{
KUIWnd * pSelect = GetChild( "common_selectclickbackground" ); //클릭된곳 그려줄 이미지 가져오고서
if( pSelect )
{
KRect rt = pIcon->GetRect();
pSelect->MovePos( rt.left-c_nClickedIconMoveX, rt.top-c_nClickedIconMoveY ); //아이콘 있는 위치로 이동
pSelect->SetShow(true); //클릭된것이니 랜더링건다
bClikedMemberRender = true;
}
}
}
}
else
EnableSlot(i, false );
}
if( bClikedMemberRender == false )
{
KUIWnd * pSelect = GetChild( "common_selectclickbackground" ); //클릭된곳 그려줄 이미지 가져오고서
if( pSelect )
{
pSelect->SetShow(false); //클릭이 안된것이니 랜더링끈다
m_nSelectIndex = -1;
}
}
}
void SUICommunityGuild::ReqWhisper()
{
if( m_nSelectIndex == -1 ) return;
KUIControlStatic* pStatic = dynamicCast<KUIControlStatic*>(GetChild( CStringUtil::StringFormat( "static_member_name%02d", m_nSelectIndex).c_str() ));
if( pStatic )
{
std::string SelectUserName = pStatic->GetCaption();
GetSelectPlayerName( SelectUserName );
m_pGameManager->PostMsgAtDynamic( new SIMSG_UI_WHISPER( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_CHATTING, SelectUserName.c_str() ) );
}
}
void SUICommunityGuild::ReqParty()
{
if( m_nSelectIndex == -1 ) return;
KUIControlStatic* pStatic = dynamicCast<KUIControlStatic*>(GetChild( CStringUtil::StringFormat( "static_member_name%02d", m_nSelectIndex).c_str() ));
if( pStatic )
{
std::string SelectUserName = pStatic->GetCaption();
GetSelectPlayerName( SelectUserName );
SMSG_PARTY_COMMAND* pMsg = new SMSG_PARTY_COMMAND;
pMsg->mode = SMSG_PARTY_COMMAND::PARTY_INVITE;
pMsg->strName = SelectUserName.c_str();
m_pGameManager->PostMsgAtDynamic( pMsg );
}
}
void SUICommunityGuild::GetSelectPlayerName( std::string& SelectUserName )
{
SelectUserName = SelectUserName.substr( ::strlen( CStringUtil::StringFormat( "%s<left><#fbe8ad><vcenter>", S(6425) ).c_str() ),
SelectUserName.size()-1 );
}