00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "Common/Time.h"
00012 #include "Common/LocalizedString.h"
00013 #include "Render/Render.h"
00014 #include "Render/Font.h"
00015 #include "Common/Command.h"
00016 #include "Common/Game.h"
00017 #include "Mod_Aeternis_Client/A_WinLoading.h"
00018
00019 #include "Mod_Aeternis_Client/A_Interface.h"
00020
00021 #include "Mod_Aeternis_Client/A_WinMultiPlayer.h"
00022
00023 #define GUIDIR( __gui ) KStr( "GUI/%s/%s", GETLANGUAGEPREFIX(), __gui )
00024 #define BUTTONBACK GUIDIR("Return")
00025 #define BUTTONBACKHL GUIDIR("Return_HL")
00026 #define BUTTONBACKC GUIDIR("Return_C")
00027 #define BUTTONFIGHT GUIDIR("Fight")
00028 #define BUTTONFIGHTHL GUIDIR("Fight_HL")
00029 #define BUTTONFIGHTC GUIDIR("Fight_C")
00030 #define BUTTONREFRESH GUIDIR("Refresh")
00031 #define BUTTONREFRESHHL GUIDIR("Refresh_HL")
00032 #define BUTTONREFRESHC GUIDIR("Refresh_C")
00033
00034
00035
00036
00037 KAWinMultiPlayer::KAWinMultiPlayer( KWin* pFather, KFPt& Pos, KFPt& Size, KInterface* pInterface )
00038 : KWin( pFather, Pos, Size, pInterface )
00039 {
00040 m_hBackGround = KSHADER_NO;
00041
00042 KFPt ButtonSize = KFPt( 0.2f, 0.04f );
00043
00044 m_pButtonFight = new KButton( this, KFPt( 0.6f, 0.35f ) - ButtonSize / 2, ButtonSize, m_pInterface );
00045 m_pButtonRefresh = new KButton( this, KFPt( 0.8f, 0.35f ) - ButtonSize / 2, ButtonSize, m_pInterface );
00046 m_pButtonBack = new KButton( this, KFPt( 0.8f, 0.9f ) - ButtonSize / 2, ButtonSize, m_pInterface );
00047 m_pButtonConnect = NULL;
00048
00049 m_pButtonFight->Enable( false );
00050
00051
00052
00053
00054 m_pWinBrowser = new KWinBrowser(this, KFPt( 0.05f, 0.4f ), KFPt( 0.9f, 0.45f ), pInterface ) ;
00055 m_pWinBrowser->SetNbColumn(4) ;
00056 m_pWinBrowser->SetColumnName(0,(char*)GETLOCALSTRING(LS_HOSTNAME)) ;
00057 m_pWinBrowser->SetColumnName(1,(char*)GETLOCALSTRING(LS_SERVERNAME)) ;
00058 m_pWinBrowser->SetColumnName(2,(char*)GETLOCALSTRING(LS_PLAYERS)) ;
00059 m_pWinBrowser->SetColumnName(3,(char*)GETLOCALSTRING(LS_VERSION)) ;
00060 m_pWinBrowser->SetColumnWidth(0,0.35f) ;
00061 m_pWinBrowser->SetColumnWidth(1,0.3f) ;
00062 m_pWinBrowser->SetColumnWidth(2,0.13f) ;
00063 m_pWinBrowser->AdjustLastColumnSize() ;
00064
00065 new KText( this, KFPt( 0.12f, 0.28f ), ButtonSize, pInterface, (char*)GETLOCALSTRING(LS_PLAYERNAME) );
00066 m_pPlayerName = new KEdit( this, KFPt( 0.1f, 0.3f ), ButtonSize, pInterface, "" );
00067 }
00068
00069
00070 KAWinMultiPlayer::~KAWinMultiPlayer()
00071 {
00072 }
00073
00074
00075 void KAWinMultiPlayer::Display()
00076 {
00077 u8 FadeAlpha = (u8)(255.0f * GetFade());
00078
00079 m_pInterface->ShowMouse();
00080 DrawQuad( 0.0f, 0.0f, 1.0f, 1.0f, m_hBackGround, KRGBA( 255, 255, 255, FadeAlpha ) );
00081 }
00082
00083
00084 void KAWinMultiPlayer::Manage()
00085 {
00086
00087 if( m_pButtonFight->IsClicked() )
00088 {
00089 m_pButtonFight->Reset() ;
00090
00091 g_pGame->GetpIniFile()->WriteString( "GAME", "PlayerName", m_pPlayerName->GetpText() );
00092
00093 if(m_pWinBrowser->GetpSelectedItem())
00094 {
00095 KBrowserListBoxItem *pItem = (KBrowserListBoxItem*)m_pWinBrowser->GetpSelectedItem() ;
00096 KServerInfo *serverinfo = (KServerInfo*)pItem->GetpData() ;
00097 KStr sArgument;
00098
00099 sArgument = serverinfo->GetsHostName();
00100 sArgument += " ";
00101 sArgument += (s32)serverinfo->GetListenPort();
00102
00103 g_pGame->GetpCommand()->ExecCommand( KStr("connect"), sArgument );
00104 ((KAInterface*)m_pInterface)->GetpWinLoading()->SetState( E_LOADING_STATE_CONNECTION );
00105 ((KAInterface*)m_pInterface)->SetWin( KAIW_LOADING,false );
00106 }
00107 }
00108
00109
00110 if( m_pButtonConnect && m_pButtonConnect->IsClicked() )
00111 {
00112 m_pButtonConnect->Reset();
00113
00114
00115 g_pGame->GetpCommand()->ExecCommand( KStr("connect"), KStr() );
00116 ((KAInterface*)m_pInterface)->GetpWinLoading()->SetState( E_LOADING_STATE_CONNECTION );
00117 ((KAInterface*)m_pInterface)->SetWin( KAIW_LOADING );
00118 }
00119
00120
00121 if( m_pButtonRefresh->IsClicked() )
00122 {
00123 m_pButtonRefresh->Reset();
00124 Refresh();
00125 }
00126
00127
00128 if( m_pButtonBack->IsClicked() )
00129 {
00130
00131 g_pGame->GetpIniFile()->WriteString( "GAME", "PlayerName", m_pPlayerName->GetpText() );
00132
00133 m_pButtonBack->Reset() ;
00134 ((KAInterface*)m_pInterface)->SetWin( KAIW_START );
00135 }
00136
00137 if(m_pWinBrowser->GetpSelectedItem())
00138 m_pButtonFight->Enable( true );
00139 else
00140 m_pButtonFight->Enable( false );
00141 }
00142
00143
00144 void KAWinMultiPlayer::OnShow()
00145 {
00146 KWin::OnShow();
00147
00148 m_pInterface->ShowMouse();
00149 }
00150
00151
00152 void KAWinMultiPlayer::Load()
00153 {
00154 KWin::Load();
00155
00156 Refresh();
00157
00158 m_pButtonBack->SetShaders( BUTTONBACK, BUTTONBACKHL, BUTTONBACKC );
00159 m_pButtonFight->SetShaders( BUTTONFIGHT, BUTTONFIGHTHL, BUTTONFIGHTC );
00160 m_pButtonRefresh->SetShaders( BUTTONREFRESH, BUTTONREFRESHHL, BUTTONREFRESHC );
00161 m_hBackGround = m_pRender->GetpShaderBank()->LoadShader( GUIDIR("Multiplayer_bg") );
00162
00163 m_pPlayerName->SetpText( (char*)g_pGame->GetpIniFile()->ReadString( "GAME", "PlayerName", "Neuneu" ) );
00164 }
00165
00166
00167 void KAWinMultiPlayer::Unload()
00168 {
00169 KWin::Unload();
00170
00171 m_pRender->GetpShaderBank()->UnloadShader( m_hBackGround );
00172 }
00173
00174
00175 void KAWinMultiPlayer::Refresh()
00176 {
00177 g_pGame->GetpCommand()->ExecCommand( "GetServersList", "" );
00178 }
00179
00180
00181 void KAWinMultiPlayer::OnAddServersList( KServerInfo& ServerInfo)
00182 {
00183
00184 char pText[1024] = "" ;
00185
00186 char* pName = ServerInfo.GetsName() ;
00187 char* pHostName = ServerInfo.GetsHostName() ;
00188 sprintf( pText, "%s %s:%i (%i/%i) v%i.%i", pName,pHostName, (u32)ServerInfo.GetListenPort(), ServerInfo.GetPlayers(), ServerInfo.GetMaxPlayers(), KVERSION_GETMAJOR( ServerInfo.GetVersion() ), KVERSION_GETMINOR( ServerInfo.GetVersion() ) );
00189
00190 KServerInfo *ServerInfoTemp = new KServerInfo ;
00191 ServerInfoTemp->SetsHostName((KStr)pHostName) ;
00192 ServerInfoTemp->SetsName((KStr)pName) ;
00193 ServerInfoTemp->SetListenPort(ServerInfo.GetListenPort()) ;
00194 ServerInfoTemp->SetMaxPlayers(ServerInfo.GetMaxPlayers()) ;
00195 ServerInfoTemp->SetPlayers(ServerInfo.GetPlayers()) ;
00196 ServerInfoTemp->SetVersion(ServerInfo.GetVersion()) ;
00197
00198 u32 iNewLine = m_pWinBrowser->AddLine() ;
00199
00200 m_pWinBrowser->SetElem(0,iNewLine,(KStr)pHostName,ServerInfoTemp) ;
00201 sprintf( pText, "%s : %i", pName, (u32)ServerInfo.GetListenPort()) ;
00202 m_pWinBrowser->SetElem(1,iNewLine,(KStr)pText) ;
00203 sprintf( pText, "(%i/%i)",ServerInfo.GetPlayers(), ServerInfo.GetMaxPlayers() );
00204 m_pWinBrowser->SetElem(2,iNewLine,(KStr)pText) ;
00205 sprintf( pText, "v%i.%i",KVERSION_GETMAJOR( ServerInfo.GetVersion() ), KVERSION_GETMINOR( ServerInfo.GetVersion() ) );
00206 m_pWinBrowser->SetElem(3,iNewLine,(KStr)pText) ;
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 }
00232
00233
00234 void KAWinMultiPlayer::OnFlushServersList()
00235 {
00236 u32 nItems = m_pWinBrowser->GetnItems() ;
00237
00238 for( u32 i = 0; i < nItems; i ++ )
00239 {
00240 KServerInfo* pServerInfoTemp = (KServerInfo*)m_pWinBrowser->GetpItem( i )->GetpData();
00241 SafeDeletep( pServerInfoTemp );
00242 }
00243
00244 m_pWinBrowser->Flush() ;
00245 m_nServers = 0 ;
00246 }