#include "stdafx.h" #include #include "SUIDefine.h" #include "SGameManager.h" #include "SGameSystem.h" //#include "SGameMessageUI.h" #include "SNetMessage.h" #include "SGameMessage.h" #include "ErrorCode/ErrorCode.h" #include "KUIWndManager.h" #include "KUIControlStatic.h" #include "KUIControlButton.h" #include "SStringDB.h" #include "SHuntaHolicResourceDB.h" #include "TemplateUtil.h" #include "SHuntaHolicSystem.h" #include "SGameSystem.h" #include "SUIHuntaHolicLobbyWnd.h" #include #include "SDebug_Util.h" extern SGameSystem* g_pCurrentGameSystem; #define HUNTAHOLICSYSTEM g_pCurrentGameSystem->GetContentsMgr().acquire< SHuntaHolicSystem >( "huntaholic" ) namespace hhi = huntaholic_interface; namespace { const char* ctrl_title = "static_entrance_title"; const char* ctrl_roomNumber = "number_box%.2d"; const char* ctrl_roomTitle = "room_title%.2d"; const char* ctrl_roomSetup = "room_setup%.2d"; const char* ctrl_roomVisitor = "person_box%.2d"; const char* ctrl_enterRoom = "button_entrance_%.2d"; const char* ctrl_leaveHuntaHolic = "bearload_off"; const char* ctrl_makeRoom = "room_make"; const char* ctrl_prevPage = "button_page_left"; const char* ctrl_nextPage = "button_page_right"; const char* ctrl_currPage = "static_page_01"; const char* ctrl_lastPage = "static_page_02"; const char* ctrl_scroll = "vscroll_bearload"; const char* ctrl_refresh = "room_refrash"; const char* ctrl_close = "button_close"; } SUIHuntaHolicLobbyWnd::SUIHuntaHolicLobbyWnd( SGameManager* pGameManager ) : SUIWnd( pGameManager ) , mTitle( 0 ) , mScroll( 0 ) , mOffset( 0 ) , mUserCommandEnabled( true ) { } SUIHuntaHolicLobbyWnd::~SUIHuntaHolicLobbyWnd() { cleanUp(); } void SUIHuntaHolicLobbyWnd::cleanUp() { rp::safe_delete( mTitle ); rp::wipe_seq( mInstances ); mPage.SetButton( 0, 0 ); mPage.Update( 0, 0 ); mScroll = 0; mOffset = 0; mUserCommandEnabled = true; KUIControlButton* makeRoom = dynamicCast(GetChild( ctrl_makeRoom )); KUIControlButton* leaveHuntaHolic = dynamicCast(GetChild( ctrl_leaveHuntaHolic )); if( makeRoom ) makeRoom->Enable(); if( leaveHuntaHolic ) leaveHuntaHolic->Enable(); } void SUIHuntaHolicLobbyWnd::Process( DWORD time ) { SUIWnd::Process( time ); } bool SUIHuntaHolicLobbyWnd::InitControls( KPoint pos ) { cleanUp(); // // 타이틀 // mTitle = sui::MakeUpdatableWindow( "title", sui::SCaptionUpdator( "<#ff8a3c>%s" ), GetChild( ctrl_title ) ); // // 인스턴스 방 목록 // mInstances.reserve( GameRule::HUNTAHOLIC_MAX_INSTANCE_SLOT_ON_GUI ); for( int i = 0; i < GameRule::HUNTAHOLIC_MAX_INSTANCE_SLOT_ON_GUI; ++i ) { sui::kui_updatable_window_array* instance = new sui::kui_updatable_window_array; instance->add( sui::MakeUpdatableWindow( "room_number", sui::SCaptionUpdator( "%s" ), GetChild( sui::helper::indexed_id( ctrl_roomNumber, i + 1 ).c_str() ) ) ); instance->add( sui::MakeUpdatableWindow( "room_title", sui::SCaptionUpdator( "%s" ), GetChild( sui::helper::indexed_id( ctrl_roomTitle, i + 1 ).c_str() ) ) ); instance->add( sui::MakeUpdatableWindow( "room_setup", sui::SCaptionUpdator( "%s" ), GetChild( sui::helper::indexed_id( ctrl_roomSetup, i + 1 ).c_str() ) ) ); instance->add( sui::MakeUpdatableWindow( "room_visitor", sui::SCaptionUpdator( "<#ffffff>%s" ), GetChild( sui::helper::indexed_id( ctrl_roomVisitor, i + 1 ).c_str() ) ) ); instance->add( sui::MakeUpdatableWindow( "room_enter", sui::SOnOffUpdator(), GetChild( sui::helper::indexed_id( ctrl_enterRoom, i + 1 ).c_str() ) ) ); mInstances.push_back( instance ); } // // 페이지 // { mPage.SetButton( dynamicCast(GetChild( ctrl_prevPage )), dynamicCast(GetChild( ctrl_nextPage )) ); mPageView.add( sui::MakeUpdatableWindow( "curr_page", sui::SCaptionUpdator( "%s /" ), GetChild( ctrl_currPage ) ) ); mPageView.add( sui::MakeUpdatableWindow( "last_page", sui::SCaptionUpdator( "%s" ), GetChild( ctrl_lastPage ) ) ); } // // 스크롤 // mScroll = dynamicCast< KUIControlScrollBase* >( GetChild( ctrl_scroll ) ); return SUIWnd::InitControls( pos ); } bool SUIHuntaHolicLobbyWnd::InitData( bool reload ) { return SUIWnd::InitData( reload ); } void* SUIHuntaHolicLobbyWnd::Perform( KID id, KArg& msg ) { if( id == hhi::id_refreshLobby ) { SHuntaHolicSystem* huntaholic = HUNTAHOLICSYSTEM; const HuntaHolicLobby& lobby = huntaholic->getLobby(); mTitle->set_data( GetStringDB().GetString( GetHuntaHolicResourceDB().Find( lobby.huntaholic_id ).name_id ) ); mTitle->update(); mPage.Update( lobby.page, lobby.total_page ); mPageView[ "curr_page" ].set_data( mPage.Current() ); mPageView[ "last_page" ].set_data( mPage.End() ); mPageView.update(); mOffset = 0; mScroll->SetScrollRange( GameRule::HUNTAHOLIC_MAX_INSTANCE_SLOT_ON_GUI / 2, lobby.count / 2 + lobby.count % 2 ); //cleanUpAllInstance(); return (void*)1; } else if( id == hhi::id_refreshInstance ) { hhi::refreshInstance* realMsg = static_cast< hhi::refreshInstance* >( &msg ); int index = getListIndex( realMsg->index ); if( index >= 0 && index < GameRule::HUNTAHOLIC_MAX_INSTANCE_SLOT_ON_GUI ) { refreshInstance( index, HUNTAHOLICSYSTEM->getInstanceList()[ realMsg->index ] ); } return (void*)1; } else if( id == hhi::id_disableUserCommand ) { mUserCommandEnabled = false; KUIControlButton* makeRoom = dynamicCast(GetChild( ctrl_makeRoom )); KUIControlButton* leaveHuntaHolic = dynamicCast(GetChild( ctrl_leaveHuntaHolic )); if( makeRoom ) makeRoom->Disable(); //if( leaveHuntaHolic ) leaveHuntaHolic->Disable(); } else if( id == hhi::id_enableUserCommand ) { mUserCommandEnabled = true; KUIControlButton* makeRoom = dynamicCast(GetChild( ctrl_makeRoom )); KUIControlButton* leaveHuntaHolic = dynamicCast(GetChild( ctrl_leaveHuntaHolic )); if( makeRoom ) makeRoom->Enable(); if( leaveHuntaHolic ) leaveHuntaHolic->Enable(); } return SUIWnd::Perform( id, msg ); } void SUIHuntaHolicLobbyWnd::PumpUpMessage( LPCTSTR controlID, DWORD msg, DWORD lparam, DWORD wparam ) { switch( msg ) { case KUI_MESSAGE::KSCROLL_SELECT: { if( mScroll && ::stricmp( controlID, mScroll->GetID() ) == 0 ) { const HuntaHolicLobby& lobby = HUNTAHOLICSYSTEM->getLobby(); int totalCount = lobby.count / 2 + lobby.count % 2; int visibleCount = GameRule::HUNTAHOLIC_MAX_INSTANCE_SLOT_ON_GUI / 2; int maxOffset = ::max( 0, totalCount - visibleCount ); mOffset = ::max( 0, ::min( maxOffset, int( lparam ) ) ) * 2; refreshInstanceAll(); } } break; case KUI_MESSAGE::KBUTTON_CLICK: { if( !::stricmp( controlID, ctrl_prevPage ) ) { //cleanUpLobby(); //cleanUpAllInstance(); cleanUpAllInstance(); HUNTAHOLICSYSTEM->reqInstanceList( HUNTAHOLICSYSTEM->getLobby().page - 1 ); } else if( !::stricmp( controlID, ctrl_nextPage ) ) { //cleanUpLobby(); //cleanUpAllInstance(); cleanUpAllInstance(); HUNTAHOLICSYSTEM->reqInstanceList( HUNTAHOLICSYSTEM->getLobby().page + 1 ); } else if( !::stricmp( controlID, ctrl_makeRoom ) ) { HUNTAHOLICSYSTEM->reqCreateInstance(); } else if( !::stricmp( controlID, ctrl_leaveHuntaHolic ) ) { //HUNTAHOLICSYSTEM->reqLeaveHuntaHolic(); //베어로드 로비에서 게임으로.. SMSG_INSTANCE_GAME_EXIT *pMsg = new SMSG_INSTANCE_GAME_EXIT(); m_pGameManager->PostMsgAtDynamic( pMsg ); m_pGameManager->InterfaceMsg( &SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_HUNTAHOLIC_LOBBY, false ) ); } else if( !::stricmp( controlID, ctrl_refresh ) ) { //cleanUpLobby(); //cleanUpAllInstance(); cleanUpAllInstance(); if(HUNTAHOLICSYSTEM->getLobby().page < 1) HUNTAHOLICSYSTEM->reqInstanceList( 1 ); else HUNTAHOLICSYSTEM->reqInstanceList( HUNTAHOLICSYSTEM->getLobby().page ); } else if( !::stricmp( controlID, ctrl_close ) ) { m_pGameManager->InterfaceMsg( &SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_HUNTAHOLIC_LOBBY, false ) ); } else { for( int i = 0; i < GameRule::HUNTAHOLIC_MAX_INSTANCE_SLOT_ON_GUI; ++i ) { if( !::stricmp( controlID, sui::helper::indexed_id( ctrl_enterRoom, i + 1 ).c_str() ) ) { HUNTAHOLICSYSTEM->reqJoinInstance( i + mOffset ); break; } } } } break; } SUIWnd::PumpUpMessage( controlID, msg, lparam, wparam ); } void SUIHuntaHolicLobbyWnd::ProcMsgAtStatic( SGameMessage* msg ) { } void SUIHuntaHolicLobbyWnd::OnNotifyUIWindowOpen( bool open, bool limitWnd ) { if( open ) { cleanUpLobby(); cleanUpAllInstance(); #if defined( __TEST_HUNTAHOLICSYSTEM ) HUNTAHOLICSYSTEM->testInstanceList(); #else HUNTAHOLICSYSTEM->reqInstanceList(); #endif } } DWORD SUIHuntaHolicLobbyWnd::OnMouseMessage( DWORD msg, int x, int y ) { DWORD ret = SUIWnd::OnMouseMessage( msg, x, y ); if( KMR_NO_GET & ret ) return ret; // do something ... return ret; } void SUIHuntaHolicLobbyWnd::refreshInstance( int index, const HuntaHolicInstance& instance ) { if( index >= mInstances.size() ) return; sui::kui_updatable_window_array& gui = *mInstances[ index ]; char buffer[ 256 ]; ::sprintf_s( buffer, "%.3d", instance.instance_no ); gui[ "room_number" ].set_data( buffer ); gui[ "room_title" ].set_data( instance.name ); if( instance.require_password ) gui[ "room_setup" ].set_data( GetStringDB().GetString( 6635 ) ); else gui[ "room_setup" ].set_data( GetStringDB().GetString( 6634 ) ); std::string visitor; nsl::sprintf_str( visitor, "%d / %d", instance.current_member_count, instance.max_member_count ); gui[ "room_visitor" ].set_data( visitor.c_str() ); gui[ "room_enter" ].set_data( mUserCommandEnabled ); gui.update(); } void SUIHuntaHolicLobbyWnd::refreshInstanceAll() { const HuntaHolicInstanceList& list = HUNTAHOLICSYSTEM->getInstanceList(); cleanUpAllInstance(); int instanceBegin = getInstanceIndex( 0 ); int instanceEnd = getInstanceIndexOfListEnd(); if( !list.empty() ) { for( int i = instanceBegin; i < instanceEnd; ++i ) { refreshInstance( getListIndex( i ), list[ i ] ); } } } void SUIHuntaHolicLobbyWnd::cleanUpLobby() { mTitle->set_data( "" ); mTitle->update(); mPageView[ "curr_page" ].set_data( "" ); mPageView[ "last_page" ].set_data( "" ); mPageView[ "curr_page" ].update(); mPageView[ "last_page" ].update(); mScroll->SetScrollRange( 0, 0 ); } void SUIHuntaHolicLobbyWnd::cleanUpAllInstance() { for( int i = 0; i < mInstances.size(); ++i ) { sui::kui_updatable_window_array& instance = *mInstances[ i ]; instance[ "room_number" ].set_data( "" ); instance[ "room_title" ].set_data( "" ); instance[ "room_setup" ].set_data( "" ); instance[ "room_visitor" ].set_data( "" ); instance[ "room_enter" ].set_data( false ); instance.update(); } } int SUIHuntaHolicLobbyWnd::getInstanceIndex( int listIndex ) const { return listIndex + mOffset; } int SUIHuntaHolicLobbyWnd::getInstanceIndexOfListEnd() const { int end = GameRule::HUNTAHOLIC_MAX_INSTANCE_SLOT_ON_GUI + mOffset; end = std::min( end, (int)HUNTAHOLICSYSTEM->getInstanceList().size() ); return end; } int SUIHuntaHolicLobbyWnd::getListIndex( int instanceIndex ) const { return instanceIndex - mOffset; }