#include "stdafx.h" #include "KUIControlClockBox.h" #include "SGameObject.h" #include "SGameManager.h" #include "SUIServerListWnd.h" #include "SGameMessage.h" //#include "SGameMessageUI.h" #include "SNetMessageBill.h" #include #include #include "SStringDB.h" #include #include "SGameOption.h" #include "SGameLobbyDefine.h" #include "KUIControlScroll.h" const int SERVER_COUNT_MAX = 8; const int SERVER_DELTA = 24; extern void MsgSplit( const char* szMsg, std::vector& vecText, const wchar_t* lpDelimiter, bool bProcSpecialCharacter=false ); SUIServerListWnd::~SUIServerListWnd() { SAFE_DELETE_ARRAY( m_pServerList ); } bool SUIServerListWnd::InitControls( KPoint kPos ) { RECT rc; rc.left = 0; rc.top = SERVER_DELTA; rc.right = 0; rc.bottom = SERVER_DELTA; /* NUI상에는 서버 두개의 경우를 가정하여 접미어 00, 01 의 ui컨트롤이 존재하며, 그 컨트롤의 간격을 계산해서 나머지 추가 서버와 관련된 ui컨트롤을 생성하고 배치하도록 한다. */ for( int i = 2; i < SERVER_COUNT_MAX; i++ ) { CopyControl( CStringUtil::StringFormat("server_list_text_%02d", i-1).c_str(), CStringUtil::StringFormat("server_list_text_%02d", i).c_str(), rc ); CopyControl( CStringUtil::StringFormat("common_selectclickbackground_%02d", i-1).c_str(), CStringUtil::StringFormat("common_selectclickbackground_%02d", i).c_str(), rc ); CopyControl( CStringUtil::StringFormat("static_condition_check_%02d", i-1).c_str(), CStringUtil::StringFormat("static_condition_check_%02d", i).c_str(), rc ); CopyControl( CStringUtil::StringFormat("server_select_sample_%02d", i-1).c_str(), CStringUtil::StringFormat("server_select_sample_%02d", i).c_str(), rc ); } SetChildAsTop("server_select"); for( int i = 0; i < SERVER_COUNT_MAX; i++ ) { SetChildAsTop( CStringUtil::StringFormat("server_list_text_%02d", i).c_str() ); SetChildAsTop( CStringUtil::StringFormat("static_condition_check_%02d", i).c_str() ); } return SUIWnd::InitControls(kPos); } bool SUIServerListWnd::InitData( bool bReload ) { SetChildShow( "server_select", false ); //셀렉트 바 숨기기 if( GetChild("common_selectclickbackground_00") == NULL || GetChild("common_selectclickbackground_01") == NULL || GetChild("server_list_text_00") == NULL || GetChild("server_list_text_01") == NULL || GetChild("static_condition_check_00") == NULL || GetChild("static_condition_check_01") == NULL ) { assert( 0 && "Server List Nui 파일이 잘못되었음" ); } KUIWnd *wnddd =GetChild("common_selectclickbackground_01"); int nGap1 = GetChild("common_selectclickbackground_01")->GetRect().top - GetChild("common_selectclickbackground_00")->GetRect().top; int nGap2 = GetChild("server_list_text_01")->GetRect().top - GetChild("server_list_text_00")->GetRect().top; int nGap3 = GetChild("static_condition_check_01")->GetRect().top - GetChild("static_condition_check_00")->GetRect().top; int nGap4 = GetChild("server_select_sample_01")->GetRect().top - GetChild("server_select_sample_00")->GetRect().top; std::string strName; for( int i = 0; i < SERVER_COUNT_MAX; i++ ) { SetChildShow( CStringUtil::StringFormat("common_selectclickbackground_%02d", i).c_str() , false ); //컨트롤 숨기기 SetChildShow( CStringUtil::StringFormat("static_condition_check_%02d", i).c_str() , false ); //컨트롤 숨기기 SetChildShow( CStringUtil::StringFormat("server_select_sample_%02d", i).c_str() , false ); //컨트롤 숨기기 strName = CStringUtil::StringFormat("server_list_text_%02d", i); SetChildCaption( strName.c_str(), CStringUtil::StringFormat( "No Server : %02d", i+1 ).c_str() ); SetChildShow( strName.c_str(), false ); //컨트롤 숨기기 if(i>=2) { SetMovePos( CStringUtil::StringFormat("common_selectclickbackground_%02d", i).c_str(), GetChild( CStringUtil::StringFormat("common_selectclickbackground_%02d", i-1).c_str() )->GetRect().left, GetChild( CStringUtil::StringFormat("common_selectclickbackground_%02d", i-1).c_str() )->GetRect().top + nGap1 ); SetMovePos( CStringUtil::StringFormat("server_list_text_%02d", i).c_str(), GetChild( CStringUtil::StringFormat("server_list_text_%02d", i-1).c_str() )->GetRect().left, GetChild( CStringUtil::StringFormat("server_list_text_%02d", i-1).c_str() )->GetRect().top + nGap2 ); SetMovePos( CStringUtil::StringFormat("static_condition_check_%02d", i).c_str(), GetChild( CStringUtil::StringFormat("static_condition_check_%02d", i-1).c_str() )->GetRect().left, GetChild( CStringUtil::StringFormat("static_condition_check_%02d", i-1).c_str() )->GetRect().top + nGap3 ); SetMovePos( CStringUtil::StringFormat("server_select_sample_%02d", i).c_str(), GetChild( CStringUtil::StringFormat("server_select_sample_%02d", i-1).c_str() )->GetRect().left, GetChild( CStringUtil::StringFormat("server_select_sample_%02d", i-1).c_str() )->GetRect().top + nGap4 ); } } //서버 상태 박스 초기값 m_server_ratio[0] = 80; m_server_ratio[1] = 60; m_server_ratio[2] = 40; m_server_ratio[3] = 20; return SUIWnd::InitData(bReload); } void SUIServerListWnd::ShowSelectBar( KUIWnd* pStaticServerName ) { // 아이콘 선택 보이기 if( pStaticServerName ) { SetMovePos( "server_select", pStaticServerName->GetRect().left, pStaticServerName->GetRect().top ); SetChildShow( "server_select", true ); } else { SetChildShow( "server_select", false ); } } void SUIServerListWnd::ProcMsgAtStatic( SGameMessage* pMsg ) { SMSG_AC_SERVER_LIST* pServerList = (SMSG_AC_SERVER_LIST*)pMsg; SetServerListData(pMsg); int nLastServer( GetServerIndex(pServerList->last_login_server_idx) ); InitScroll( nLastServer ); SetServerListControlAll(); SelectServer( nLastServer ); //0번째 기본 선택, 추 후에 마지막 서버 저장해서 선택 처리 필요함. } int SUIServerListWnd::GetServerIndex(int idx) { for( int i(0); m_nServerCount>i; i++ ) { if( m_pServerList[i].server_idx == idx ) return i; } return 0; } void SUIServerListWnd::SetServerListData( SGameMessage* pMsg ) { SMSG_AC_SERVER_LIST* pServerList = (SMSG_AC_SERVER_LIST*)pMsg; if( pServerList->count > 0 ) { SAFE_DELETE_ARRAY( m_pServerList ); m_nServerCount = pServerList->count; m_pServerList = new TS_SERVER_INFO[m_nServerCount]; int nSelectServerIndex( -1 ); TS_SERVER_INFO* pServerInfo = pServerList->m_pServerInfo; for( int i(0); m_nServerCount>i; i++ ) { m_pServerList[i].server_idx = pServerInfo[i].server_idx; if( pServerList->last_login_server_idx == m_pServerList[i].server_idx ) nSelectServerIndex = i; m_pServerList[i].user_ratio = pServerInfo[i].user_ratio; m_pServerList[i].server_ip[15] = '\0'; //IP m_pServerList[i].server_name[20] = '\0'; //Name m_pServerList[i].server_screenshot_url[256] = '\0'; //URL m_pServerList[i].server_port = pServerInfo[i].server_port; //PORT m_pServerList[i].is_adult_server = pServerInfo[i].is_adult_server; strncpy( m_pServerList[i].server_ip , pServerInfo[i].server_ip , 15 ); strncpy( m_pServerList[i].server_name, pServerInfo[i].server_name, 20 ); strncpy( m_pServerList[i].server_screenshot_url, pServerInfo[i].server_screenshot_url, 256 ); } } } void SUIServerListWnd::InitScroll( int nServerIndex ) { KUIControlVScroll* pScrollBar = dynamicCast< KUIControlVScroll* >(GetChild("severform_scroll")); if( pScrollBar ) { pScrollBar->SetMaxRange( max(m_nServerCount-SERVER_COUNT_MAX+1, 0) ); if( nServerIndex >= SERVER_COUNT_MAX ) { if( m_nServerCount - nServerIndex <= SERVER_COUNT_MAX ) m_nScrollPos = m_nServerCount - SERVER_COUNT_MAX; else m_nScrollPos = nServerIndex; pScrollBar->SetPosition( m_nScrollPos ); } } } void SUIServerListWnd::SetServerListControlAll() { if( m_nServerCount > 0 ) { for( int i = 0; i < SERVER_COUNT_MAX; i++ ) { if( i < m_nServerCount ) { SetServerListControl(i, i+m_nScrollPos, true); //우선은 시간 없으니 칼라컨트롤을 show할지만 해주고 추후에 인자로 국가를 넘겨주자.. -N4- } else { SetChildShow( CStringUtil::StringFormat("server_list_text_%02d", i).c_str(), false); SetChildShow( CStringUtil::StringFormat("common_selectclickbackground_%02d", i).c_str(), false); } } } } void SUIServerListWnd::SetServerListControl( int nCtrIndex, int nDataIndex, bool bColoeShow ) { if( nDataIndex >= m_nServerCount ) return; std::string strServerCaption; KUIWnd *textsample_wnd = NULL; KUIWnd *serverconditionsample_wnd = NULL; if(m_server_ratio[0] <= m_pServerList[nDataIndex].user_ratio) { textsample_wnd = GetChild("server_list_text_sample_a"); serverconditionsample_wnd = GetChild("static_condition_check_a"); } else if(m_server_ratio[1] <= m_pServerList[nDataIndex].user_ratio) { textsample_wnd = GetChild("server_list_text_sample_b"); serverconditionsample_wnd = GetChild("static_condition_check_b"); } else if(m_server_ratio[2] <= m_pServerList[nDataIndex].user_ratio) { textsample_wnd = GetChild("server_list_text_sample_c"); serverconditionsample_wnd = GetChild("static_condition_check_c"); } else if(m_server_ratio[3] <= m_pServerList[nDataIndex].user_ratio) { textsample_wnd = GetChild("server_list_text_sample_d"); serverconditionsample_wnd = GetChild("static_condition_check_d"); } else { textsample_wnd = GetChild("server_list_text_sample_e"); serverconditionsample_wnd = GetChild("static_condition_check_e"); } if(textsample_wnd) strServerCaption = textsample_wnd->GetCaption(); strServerCaption += m_pServerList[nDataIndex].server_name; SetChildCaption( CStringUtil::StringFormat("server_list_text_%02d" , nCtrIndex).c_str(), strServerCaption.c_str() ); //서버 이름 설정 SetChildShow ( CStringUtil::StringFormat("server_list_text_%02d" , nCtrIndex).c_str(), true ); SetChildShow ( CStringUtil::StringFormat("common_selectclickbackground_%02d", nCtrIndex).c_str(), true ); //서버 상태 박스 생성 및 출력. if(serverconditionsample_wnd) { SetChildAniName( CStringUtil::StringFormat("static_condition_check_%02d", nCtrIndex).c_str(), serverconditionsample_wnd->GetAniName() ); SetChildShow ( CStringUtil::StringFormat("static_condition_check_%02d", nCtrIndex).c_str(), true ); } else { SetChildShow ( CStringUtil::StringFormat("static_condition_check_%02d", nCtrIndex).c_str(), false ); } } void SUIServerListWnd::SelectOK( const char * pServerName ) { if( pServerName ) { //m_pGameManager->StartSound( "ui_click_login01.wav" ); m_pGameManager->StartSound( "ui_bgm_antechamber02.wav" ); std::string strSelectServer = pServerName; if( GetServerIP( strSelectServer ) ) //서버이름|서버IP { PumpUpMessage( strSelectServer.c_str(), KUI_MESSAGE::KBUTTON_CLICK, 0, 0 ); } else { assert( 0 && "접속 할 서버의 정보를 찾을 수 없음" ); } } } bool SUIServerListWnd::GetServerIP( std::string & strServerName ) { std::string strSelectServer = strServerName; std::string::size_type pos = strSelectServer.rfind(">"); if( pos != std::string::npos ) strSelectServer = strSelectServer.erase( 0, pos+1 ); if( m_pServerList && m_nServerCount ) { for( int i(0); m_nServerCount>i; i++ ) { if( m_pServerList[i].server_name == strSelectServer ) { XStringUtil::Format( strServerName, "!!!SELECT_SERVER|%s|%s|%d|%d", m_pServerList[i].server_name, m_pServerList[i].server_ip, m_pServerList[i].server_idx, m_pServerList[i].server_port ); return true; } } } return false; } void SUIServerListWnd::PumpUpMessage( LPCSTR lpszControlID, DWORD nMessage, DWORD lparam, DWORD wparam ) { switch( nMessage ) { case KUI_MESSAGE::KBUTTON_CLICK: { if( strcmp( lpszControlID, "button_choice" ) == 0 ) { //서버 선택을 눌렀음. //m_pGameManager->StartSound( "ui_bgm_antechamber02.wav" ); KUIWnd* pStaticServerName = GetChild( m_strSelectCtrl.c_str() ); if( NULL != pStaticServerName ) SelectOK( pStaticServerName->GetCaption() ); } else if( strcmp( lpszControlID, "button_back" ) == 0 ) { m_pGameManager->StartSound( "ui_bgm_antechamber02.wav" ); } m_pGameManager->ProcMsgAtStatic( &SIMSG_UIWND_NOTIFY_TO_LOBBY( lpszControlID ) ); //SGameLogin 에 알려줌. } break; case KUI_MESSAGE::KFOCUS_ACTIVATED: case KUI_MESSAGE::KICON_DBLCLK: { if( 0 == ::_stricmp( GetID(), lpszControlID ) ) // 일단 좀 임시적 ... { for( int i(0); SERVER_COUNT_MAX>i; i++ ) { std::string strServer; XStringUtil::Format( strServer , "server_list_text_%02d", i ); KUIWnd* pStaticServerName = GetChild( strServer.c_str() ); if( NULL != pStaticServerName && pStaticServerName->IsShow() && pStaticServerName->GetRect().IsInRect( lparam, wparam ) ) { SelectServer(i); if( nMessage == KUI_MESSAGE::KICON_DBLCLK ) { SelectOK( pStaticServerName->GetCaption() ); } break; } } } } break; case KUI_MESSAGE::KSCROLL_SELECT: // 스크롤 선택 { //로비에서 서버선택시 다운되는것 수정 2009.07.30. sfreer KUIControlVScroll* pScrollBar = dynamicCast< KUIControlVScroll* >(GetChild("severform_scroll")); if(pScrollBar) { if( max( int(lparam), 0 ) < pScrollBar->GetMaxRange() ) m_nScrollPos = max( int(lparam), 0 ); } SetServerListControlAll(); SelectCtrUpdate(); } break; } SUIWnd::PumpUpMessage( lpszControlID, nMessage, lparam, wparam ); } void SUIServerListWnd::SelectCtrUpdate() { int nCtrIndex( m_nSelectDataIndex-m_nScrollPos ); if( nCtrIndex >= 0 && nCtrIndex < SERVER_COUNT_MAX ) { std::string strServerState; XStringUtil::Format( strServerState, "server_select_sample_%02d", nCtrIndex ); KUIWnd* pStaticServerState = GetChild( strServerState.c_str() ); ShowSelectBar( pStaticServerState ); //ShowSelectBar 함수로 NULL 들어가도 된다. 안에서 NULL이면 태두리 없엔다. } else ShowSelectBar( NULL ); } void SUIServerListWnd::SelectServer( int nCtrIndex ) { if( m_pServerList == NULL ) return; m_nSelectDataIndex = nCtrIndex+m_nScrollPos; std::string strServerState; XStringUtil::Format( m_strSelectCtrl, "server_list_text_%02d", nCtrIndex ); //현재 선택된 넘. XStringUtil::Format( strServerState, "server_select_sample_%02d", nCtrIndex ); g_UserInfo.SetSelServerName( m_pServerList[m_nSelectDataIndex].server_name ); g_UserInfo.SetAdultServer( m_pServerList[m_nSelectDataIndex].is_adult_server ); KUIWnd* pStaticServerState = GetChild( strServerState.c_str() ); if( pStaticServerState ) ShowSelectBar( pStaticServerState ); m_pGameManager->PostMsgAtDynamic( new SMSG_SEND_DATA( m_nSelectDataIndex, "select_surver" ) ); } void SUIServerListWnd::OnNotifyUIWindowOpen( bool bOpen, bool bLimitWnd ) { if( GetGameOption().IsEnterChat() ) { if( bOpen ) { SetFocus( true ); } else { SetFocus( false ); } } } DWORD SUIServerListWnd::OnKeyMessage(DWORD dwMessage, DWORD dwKeyCode) //-N4- { if( IsShow() ) { if( dwKeyCode == VK_UP || dwKeyCode == VK_DOWN ) { for( int i(0); i(GetChild("severform_scroll")); // KUIControlVScroll* pScrollBar = dynamicCast< KUIControlVScroll* >(GetChild("vscroll_server")); int nDataIndex(pos+m_nScrollPos); if( pos >= SERVER_COUNT_MAX || pos >= m_nServerCount ) { if( nDataIndex >= m_nServerCount ) { pos = 0; m_nScrollPos = 0; if( pScrollBar ) pScrollBar->SetPosition( m_nScrollPos ); } else { pos--; m_nScrollPos = min(++m_nScrollPos, SERVER_COUNT_MAX); if( pScrollBar ) pScrollBar->SetPosition( m_nScrollPos ); } SetServerListControlAll(); } else if( pos < 0 ) { if( nDataIndex < 0 ) { pos = min(m_nServerCount-1, SERVER_COUNT_MAX-1); m_nScrollPos = max(0, m_nServerCount-SERVER_COUNT_MAX); if( pScrollBar ) pScrollBar->SetPosition( m_nScrollPos ); } else { pos++; m_nScrollPos = min(--m_nScrollPos, 0); if( pScrollBar ) pScrollBar->SetPosition( m_nScrollPos ); } SetServerListControlAll(); } SelectServer(pos); break; } } } else if( dwKeyCode == VK_RETURN && m_nServerCount ) //서버리스트가 없으면 처리할 필요 없어서 넣은것 { if( m_strSelectCtrl.empty() ) m_strSelectCtrl = "server_list_text_00"; KUIWnd* pStaticServerName = GetChild( m_strSelectCtrl.c_str() ); if( pStaticServerName ) SelectOK( pStaticServerName->GetCaption() ); //현재 선택되있는 서버로 접속처리 } } return KUIWnd::OnKeyMessage(dwMessage, dwKeyCode); }