Files
itgmania212121/src/ScreenNetworkOptions.cpp
T

181 lines
5.5 KiB
C++
Raw Normal View History

#include "global.h"
2004-09-10 23:21:56 +00:00
#if !defined(WITHOUT_NETWORKING)
#include "NetworkSyncManager.h"
#include "ScreenNetworkOptions.h"
#include "RageLog.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
#include "ThemeManager.h"
#include "PrefsManager.h"
#include "ScreenManager.h"
#include "ScreenTextEntry.h"
#include "ScreenPrompt.h"
2005-12-22 03:10:04 +00:00
#include "LocalizedString.h"
2006-01-17 22:10:03 +00:00
#include "OptionRowHandler.h"
2004-10-25 12:40:05 +00:00
2006-08-10 07:05:16 +00:00
static LocalizedString CLIENT_CONNECT ( "ScreenNetworkOptions", "Connect" );
2006-05-16 03:33:22 +00:00
static LocalizedString CLIENT_DISCONNECT ( "ScreenNetworkOptions", "Disconnect" );
2006-08-10 07:05:16 +00:00
static LocalizedString SCORE_ON ( "ScreenNetworkOptions", "ScoreOn" );
static LocalizedString SCORE_OFF ( "ScreenNetworkOptions", "ScoreOff" );
2006-05-16 03:33:22 +00:00
2006-08-10 07:05:16 +00:00
static LocalizedString DISCONNECTED ( "ScreenNetworkOptions", "Disconnected from server." );
static LocalizedString ENTER_NETWORK_ADDRESS ( "ScreenNetworkOptions", "Enter a network address." );
static LocalizedString CONNECT_TO_YOURSELF ( "ScreenNetworkOptions", "Use 127.0.0.1 to connect to yourself." );
2006-05-16 03:33:22 +00:00
2006-08-10 07:05:16 +00:00
enum
{
PO_CONNECTION,
2005-08-15 02:10:57 +00:00
PO_SCOREBOARD,
PO_SERVERS,
NUM_NETWORK_OPTIONS_LINES
};
2005-08-15 02:10:57 +00:00
enum
{
NO_SCOREBOARD_OFF=0,
NO_SCOREBOARD_ON
};
AutoScreenMessage( SM_DoneConnecting )
2006-01-22 01:00:06 +00:00
Preference<RString> g_sLastServer( "LastConnectedServer", "" );
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenNetworkOptions );
void ScreenNetworkOptions::Init()
{
ScreenOptions::Init();
2004-10-19 06:15:42 +00:00
2006-01-17 22:10:03 +00:00
vector<OptionRowHandler*> vHands;
{
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
vHands.push_back( pHand );
pHand->m_Def.m_sName = "Connection";
pHand->m_Def.m_bOneChoiceForAllPlayers = true;
if ( NSMAN->useSMserver )
2006-05-16 03:33:22 +00:00
pHand->m_Def.m_vsChoices.push_back(CLIENT_DISCONNECT);
2006-01-17 22:10:03 +00:00
else
2006-05-16 03:33:22 +00:00
pHand->m_Def.m_vsChoices.push_back(CLIENT_CONNECT);
2006-01-17 22:10:03 +00:00
}
{
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
vHands.push_back( pHand );
pHand->m_Def.m_sName = "Scoreboard";
pHand->m_Def.m_vsChoices.clear();
pHand->m_Def.m_bOneChoiceForAllPlayers = true;
2006-05-16 03:33:22 +00:00
pHand->m_Def.m_vsChoices.push_back(SCORE_OFF);
pHand->m_Def.m_vsChoices.push_back(SCORE_ON);
2006-01-17 22:10:03 +00:00
}
{
2006-01-17 22:10:03 +00:00
// Get info on all received servers from NSMAN.
AllServers.clear();
2006-01-17 22:10:03 +00:00
NSMAN->GetListOfLANServers( AllServers );
if( !AllServers.empty() )
{
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Servers";
2008-10-06 08:09:58 +00:00
pHand->m_Def.m_bAllowThemeItems = false;
for( unsigned int j = 0; j < AllServers.size(); j++ )
pHand->m_Def.m_vsChoices.push_back( AllServers[j].Name );
vHands.push_back( pHand );
}
2006-01-17 22:10:03 +00:00
}
2006-01-17 22:10:03 +00:00
InitMenu( vHands );
2005-08-15 02:10:57 +00:00
m_pRows[PO_SCOREBOARD]->SetOneSharedSelection(PREFSMAN->m_bEnableScoreboard);
}
void ScreenNetworkOptions::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_DoneConnecting )
{
if( !ScreenTextEntry::s_bCancelledLast )
{
2006-01-22 01:00:06 +00:00
RString sNewName = ScreenTextEntry::s_sLastAnswer;
NSMAN->PostStartUp(sNewName);
NSMAN->DisplayStartupStatus();
2004-10-19 06:15:42 +00:00
UpdateConnectStatus( );
2005-05-06 20:41:05 +00:00
g_sLastServer.Set( ScreenTextEntry::s_sLastAnswer );
}
}
ScreenOptions::HandleScreenMessage( SM );
}
void ScreenNetworkOptions::MenuStart( const InputEventPlus &input )
{
switch( GetCurrentRow() )
{
case PO_CONNECTION:
2004-10-19 06:15:42 +00:00
if ( !NSMAN->useSMserver )
2004-10-25 12:40:05 +00:00
{
2005-12-21 12:55:20 +00:00
ScreenTextEntry::TextEntry( SM_DoneConnecting, ENTER_NETWORK_ADDRESS.GetValue()+"\n\n"+CONNECT_TO_YOURSELF.GetValue(), g_sLastServer, 128 );
2004-10-25 12:40:05 +00:00
}
2005-03-22 20:15:24 +00:00
else
{
NSMAN->CloseConnection();
2005-12-20 08:35:47 +00:00
SCREENMAN->SystemMessage( DISCONNECTED );
2004-10-19 06:15:42 +00:00
UpdateConnectStatus( );
}
break;
2005-08-15 02:10:57 +00:00
case PO_SCOREBOARD:
if (m_pRows[PO_SCOREBOARD]->GetOneSharedSelection() == NO_SCOREBOARD_ON)
PREFSMAN->m_bEnableScoreboard.Set(true);
else
PREFSMAN->m_bEnableScoreboard.Set(false);
break;
case PO_SERVERS:
if ( !AllServers.empty() )
{
string sNewName = AllServers[m_pRows[GetCurrentRow()]->GetOneSharedSelection()].Address;
NSMAN->PostStartUp(sNewName);
NSMAN->DisplayStartupStatus();
UpdateConnectStatus( );
}
else
{
//If the server list is empty, keep passing the message on so exit works
ScreenOptions::MenuStart( input );
}
break;
default:
ScreenOptions::MenuStart( input );
}
}
2005-07-13 19:01:42 +00:00
void ScreenNetworkOptions::ImportOptions( int iRow, const vector<PlayerNumber> &vpns ) { }
void ScreenNetworkOptions::ExportOptions( int iRow, const vector<PlayerNumber> &vpns ) { }
2004-10-19 06:15:42 +00:00
void ScreenNetworkOptions::UpdateConnectStatus( )
{
2005-09-26 19:08:15 +00:00
SCREENMAN->SetNewScreen( m_sName );
2004-06-08 05:22:33 +00:00
}
2004-09-10 23:21:56 +00:00
#endif
2004-06-08 05:22:33 +00:00
/*
2005-08-15 02:10:57 +00:00
* (c) 2004 Charles Lohr, Josh Allen
2004-06-08 05:22:33 +00:00
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/