Applied Paul's network menu patch.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2374 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
f0ff625227
commit
68278f6847
@ -102,14 +102,14 @@ NetworkGUI::~NetworkGUI()
|
|||||||
void NetworkGUI::select()
|
void NetworkGUI::select()
|
||||||
{
|
{
|
||||||
const int selected = widget_manager->getSelectedWgt();
|
const int selected = widget_manager->getSelectedWgt();
|
||||||
switch (selected)
|
switch (selected)
|
||||||
{
|
{
|
||||||
case WTOK_SERVER_ADDRESS:
|
case WTOK_SERVER_ADDRESS:
|
||||||
// Switch to typing in the address of the server
|
// Switch to typing in the address of the server
|
||||||
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, (m_server_address + "<").c_str());
|
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, (m_server_address + "<").c_str());
|
||||||
inputDriver->setMode(SDLDriver::LOWLEVEL);
|
inputDriver->setMode(SDLDriver::LOWLEVEL);
|
||||||
break;
|
break;
|
||||||
case WTOK_CONNECT:
|
case WTOK_CONNECT:
|
||||||
// If we could connect here, no message could be displayed since
|
// If we could connect here, no message could be displayed since
|
||||||
// glflush isn't called. So we only set a message for the network
|
// glflush isn't called. So we only set a message for the network
|
||||||
// manager to display, and set the state so that the actual
|
// manager to display, and set the state so that the actual
|
||||||
@ -119,6 +119,7 @@ void NetworkGUI::select()
|
|||||||
widget_manager->resizeWgtToText(WTOK_MESSAGE);
|
widget_manager->resizeWgtToText(WTOK_MESSAGE);
|
||||||
widget_manager->showWgt(WTOK_MESSAGE);
|
widget_manager->showWgt(WTOK_MESSAGE);
|
||||||
widget_manager->hideWgt(WTOK_CONNECT, WTOK_SERVER_ADDRESS);
|
widget_manager->hideWgt(WTOK_CONNECT, WTOK_SERVER_ADDRESS);
|
||||||
|
widget_manager->hideWgt(WTOK_QUIT);
|
||||||
break;
|
break;
|
||||||
case WTOK_SERVER:
|
case WTOK_SERVER:
|
||||||
network_manager->becomeServer();
|
network_manager->becomeServer();
|
||||||
@ -135,17 +136,17 @@ void NetworkGUI::select()
|
|||||||
switchToWaitForConnectionMode();
|
switchToWaitForConnectionMode();
|
||||||
break;
|
break;
|
||||||
case WTOK_QUIT:
|
case WTOK_QUIT:
|
||||||
// Don't do networking if no clients are connected
|
|
||||||
if(network_manager->getNumClients()==0)
|
|
||||||
network_manager->setMode(NetworkManager::NW_NONE);
|
|
||||||
// Disable accepting of clients
|
// Disable accepting of clients
|
||||||
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
||||||
network_manager->setState(NetworkManager::NS_MAIN_MENU);
|
network_manager->setState(NetworkManager::NS_MAIN_MENU);
|
||||||
// Leave menu.
|
// Don't do networking if no clients are connected
|
||||||
|
if(network_manager->getNumClients()==0)
|
||||||
|
network_manager->disableNetworking();
|
||||||
|
// Leave menu.
|
||||||
menu_manager->popMenu();
|
menu_manager->popMenu();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // select
|
} // select
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -177,12 +178,13 @@ void NetworkGUI::update(float dt)
|
|||||||
{
|
{
|
||||||
widget_manager->setWgtText(WTOK_MESSAGE, _("Can't connect to server"));
|
widget_manager->setWgtText(WTOK_MESSAGE, _("Can't connect to server"));
|
||||||
widget_manager->resizeWgtToText(WTOK_MESSAGE);
|
widget_manager->resizeWgtToText(WTOK_MESSAGE);
|
||||||
|
widget_manager->showWgt(WTOK_QUIT);
|
||||||
network_manager->disableNetworking();
|
network_manager->disableNetworking();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
network_manager->sendConnectMessage();
|
network_manager->sendConnectMessage();
|
||||||
menu_manager->popMenu();
|
menu_manager->popMenu();
|
||||||
}
|
}
|
||||||
m_state=NGS_NONE;
|
m_state=NGS_NONE;
|
||||||
}
|
}
|
||||||
@ -205,60 +207,60 @@ void NetworkGUI::update(float dt)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void NetworkGUI::inputKeyboard(SDLKey key, int unicode)
|
void NetworkGUI::inputKeyboard(SDLKey key, int unicode)
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case SDLK_RSHIFT:
|
case SDLK_RSHIFT:
|
||||||
case SDLK_LSHIFT:
|
case SDLK_LSHIFT:
|
||||||
// Ignore shift, otherwise shift will disable input
|
// Ignore shift, otherwise shift will disable input
|
||||||
// (making it impossible to enter upper case characters)
|
// (making it impossible to enter upper case characters)
|
||||||
case SDLK_SPACE:
|
case SDLK_SPACE:
|
||||||
// Ignore space to prevent invisible names.
|
// Ignore space to prevent invisible names.
|
||||||
|
|
||||||
// Note: This will never happen as long as SPACE has a mapping which
|
// Note: This will never happen as long as SPACE has a mapping which
|
||||||
// causes GA_ENTER and therefore finishes the typing. Please leave this
|
// causes GA_ENTER and therefore finishes the typing. Please leave this
|
||||||
// because I am not sure whether this is good behavior (that SPACE
|
// because I am not sure whether this is good behavior (that SPACE
|
||||||
// cannot reach inputKeyboard()) and with some changes to the input
|
// cannot reach inputKeyboard()) and with some changes to the input
|
||||||
// driver this code has suddenly a useful effect.
|
// driver this code has suddenly a useful effect.
|
||||||
case SDLK_KP_ENTER:
|
case SDLK_KP_ENTER:
|
||||||
case SDLK_RETURN:
|
case SDLK_RETURN:
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
// Ignore some control keys. What they could provide is implemented
|
// Ignore some control keys. What they could provide is implemented
|
||||||
// in the handle() method.
|
// in the handle() method.
|
||||||
return;
|
return;
|
||||||
case SDLK_BACKSPACE:
|
case SDLK_BACKSPACE:
|
||||||
// Handle backspace.
|
// Handle backspace.
|
||||||
if (m_server_address.size() >=1)
|
if (m_server_address.size() >=1)
|
||||||
m_server_address.erase(m_server_address.size()-1, 1);
|
m_server_address.erase(m_server_address.size()-1, 1);
|
||||||
|
|
||||||
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, (m_server_address + "<").c_str());
|
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, (m_server_address + "<").c_str());
|
||||||
break;
|
break;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Adds the character to the name.
|
// Adds the character to the name.
|
||||||
// For this menu only unicode translation is enabled.
|
// For this menu only unicode translation is enabled.
|
||||||
// So we use the unicode character here, since this will
|
// So we use the unicode character here, since this will
|
||||||
// take care of upper/lower case etc.
|
// take care of upper/lower case etc.
|
||||||
if (unicode && (int)m_server_address.size() <= SERVER_NAME_MAX)
|
if (unicode && (int)m_server_address.size() <= SERVER_NAME_MAX)
|
||||||
m_server_address += (char) unicode;
|
m_server_address += (char) unicode;
|
||||||
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, (m_server_address + "<").c_str());
|
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, (m_server_address + "<").c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void NetworkGUI::handle(GameAction ga, int value)
|
void NetworkGUI::handle(GameAction ga, int value)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (ga)
|
switch (ga)
|
||||||
{
|
{
|
||||||
case GA_ENTER:
|
case GA_ENTER:
|
||||||
// If the user is typing her name this will be finished at this
|
// If the user is typing her name this will be finished at this
|
||||||
// point.
|
// point.
|
||||||
if (inputDriver->isInMode(SDLDriver::LOWLEVEL))
|
if (inputDriver->isInMode(SDLDriver::LOWLEVEL))
|
||||||
{
|
{
|
||||||
// Prevents zero-length names.
|
// Prevents zero-length names.
|
||||||
if (m_server_address.length() == 0)
|
if (m_server_address.length() == 0)
|
||||||
m_server_address = "localhost:2305";
|
m_server_address = "localhost:2305";
|
||||||
std::vector<std::string> sl=StringUtils::split(m_server_address,':');
|
std::vector<std::string> sl=StringUtils::split(m_server_address,':');
|
||||||
@ -274,29 +276,29 @@ void NetworkGUI::handle(GameAction ga, int value)
|
|||||||
s<<m_server_address<<":"<<user_config->m_server_port;
|
s<<m_server_address<<":"<<user_config->m_server_port;
|
||||||
m_server_address=s.str();
|
m_server_address=s.str();
|
||||||
}
|
}
|
||||||
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, m_server_address.c_str());
|
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, m_server_address.c_str());
|
||||||
|
|
||||||
inputDriver->setMode(SDLDriver::MENU);
|
inputDriver->setMode(SDLDriver::MENU);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
select();
|
select();
|
||||||
break;
|
break;
|
||||||
case GA_LEAVE:
|
case GA_LEAVE:
|
||||||
// If the user is typing her name this will be cancelled at this
|
// If the user is typing her name this will be cancelled at this
|
||||||
// point.
|
// point.
|
||||||
if (inputDriver->isInMode(SDLDriver::LOWLEVEL))
|
if (inputDriver->isInMode(SDLDriver::LOWLEVEL))
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s<<user_config->m_server_address<<":"<<user_config->m_server_port;
|
s<<user_config->m_server_address<<":"<<user_config->m_server_port;
|
||||||
m_server_address=s.str();
|
m_server_address=s.str();
|
||||||
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, m_server_address.c_str());
|
widget_manager->setWgtText(WTOK_SERVER_ADDRESS, m_server_address.c_str());
|
||||||
|
|
||||||
inputDriver->setMode(SDLDriver::MENU);
|
inputDriver->setMode(SDLDriver::MENU);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Fall through to reach the usual GA_LEAVE code (leave menu).
|
// Fall through to reach the usual GA_LEAVE code (leave menu).
|
||||||
default:
|
default:
|
||||||
BaseGUI::handle(ga, value);
|
BaseGUI::handle(ga, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ NetworkManager::NetworkManager()
|
|||||||
{
|
{
|
||||||
m_mode = NW_NONE;
|
m_mode = NW_NONE;
|
||||||
m_state = NS_ACCEPT_CONNECTIONS;
|
m_state = NS_ACCEPT_CONNECTIONS;
|
||||||
|
m_host = NULL;
|
||||||
|
|
||||||
m_num_clients = 0;
|
m_num_clients = 0;
|
||||||
m_host_id = 0;
|
m_host_id = 0;
|
||||||
@ -181,7 +182,12 @@ void NetworkManager::becomeServer()
|
|||||||
void NetworkManager::disableNetworking()
|
void NetworkManager::disableNetworking()
|
||||||
{
|
{
|
||||||
m_mode=NW_NONE;
|
m_mode=NW_NONE;
|
||||||
// FIXME: what enet data structures do we have to free/reset???
|
if (m_host != NULL)
|
||||||
|
{
|
||||||
|
enet_host_destroy(m_host);
|
||||||
|
m_host = NULL;
|
||||||
|
}
|
||||||
|
// FIXME: what other enet data structures do we have to free/reset???
|
||||||
|
|
||||||
} // disableNetworking
|
} // disableNetworking
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user