Big commit related to server joining.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13196 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -6,8 +6,10 @@
|
||||
<div proportion="1" x="2%" width="96%" layout="vertical-row">
|
||||
<div width="100%" proportion="2" layout="horizontal-row">
|
||||
<box id="info" proportion="2" height="100%" layout="vertical-row">
|
||||
<label I18N="In networking lobby" word_wrap="true" text="Description about room"
|
||||
align="center" text-align="center"/>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" text_align="left" I18N="In the networking lobby" text="Server name :"/>
|
||||
<label proportion="2" text_align="left" id="server_name" text=""/>
|
||||
</div>
|
||||
</box>
|
||||
<spacer width="20" height="20"/>
|
||||
<box proportion="1" height="100%" layout="vertical-row">
|
||||
|
||||
33
data/gui/online/server_info_dialog.stkgui
Normal file
33
data/gui/online/server_info_dialog.stkgui
Normal file
@@ -0,0 +1,33 @@
|
||||
<stkgui>
|
||||
|
||||
<div x="2%" y="5%" width="96%" height="85%" layout="vertical-row" >
|
||||
|
||||
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
|
||||
I18N="In the server info dialog' dialog" text="Server Info"/>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<div width="80%" align="center" layout="vertical-row" height="fit" >
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" text_align="left" I18N="In the server info dialog" text="Name"/>
|
||||
<label id="name" proportion="2" text_align="left" text=""/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<buttonbar id="options" width="90%" height="20%" align="center">
|
||||
<icon-button id="join" width="64" height="64" icon="gui/main_options.png"
|
||||
I18N="Login dialog" text="Join" label_location="bottom"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
|
||||
I18N="Login dialog" text="Cancel" label_location="bottom"/>
|
||||
</buttonbar>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</stkgui>
|
||||
@@ -148,6 +148,7 @@ src/online/current_online_user.cpp
|
||||
src/online/http_connector.cpp
|
||||
src/online/online_user.cpp
|
||||
src/online/server.cpp
|
||||
src/online/servers_manager.cpp
|
||||
src/physics/btKart.cpp
|
||||
src/physics/btKartRaycast.cpp
|
||||
src/physics/btUprightConstraint.cpp
|
||||
@@ -181,6 +182,7 @@ src/states_screens/dialogs/press_a_key_dialog.cpp
|
||||
src/states_screens/dialogs/race_paused_dialog.cpp
|
||||
src/states_screens/dialogs/registration_dialog.cpp
|
||||
src/states_screens/dialogs/select_challenge.cpp
|
||||
src/states_screens/dialogs/server_info_dialog.cpp
|
||||
src/states_screens/dialogs/track_info_dialog.cpp
|
||||
src/states_screens/dialogs/tutorial_message_dialog.cpp
|
||||
src/states_screens/feature_unlocked.cpp
|
||||
@@ -415,6 +417,7 @@ src/online/current_online_user.hpp
|
||||
src/online/http_connector.hpp
|
||||
src/online/online_user.hpp
|
||||
src/online/server.hpp
|
||||
src/online/servers_manager.hpp
|
||||
src/physics/btKart.hpp
|
||||
src/physics/btKartRaycast.hpp
|
||||
src/physics/btUprightConstraint.hpp
|
||||
@@ -451,6 +454,7 @@ src/states_screens/dialogs/press_a_key_dialog.hpp
|
||||
src/states_screens/dialogs/race_paused_dialog.hpp
|
||||
src/states_screens/dialogs/registration_dialog.hpp
|
||||
src/states_screens/dialogs/select_challenge.hpp
|
||||
src/states_screens/dialogs/server_info_dialog.hpp
|
||||
src/states_screens/dialogs/track_info_dialog.hpp
|
||||
src/states_screens/dialogs/tutorial_message_dialog.hpp
|
||||
src/states_screens/feature_unlocked.hpp
|
||||
|
||||
@@ -153,13 +153,14 @@ bool CurrentOnlineUser::createServer( const irr::core::stringw &name,
|
||||
|
||||
|
||||
// ============================================================================
|
||||
bool CurrentOnlineUser::signOut(){
|
||||
bool CurrentOnlineUser::signOut(irr::core::stringw &info){
|
||||
assert(m_is_signed_in == true);
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||
connector->setParameter("action",std::string("disconnect"));
|
||||
connector->setParameter("token",m_token);
|
||||
connector->setParameter("userid",m_id);
|
||||
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
std::string rec_success = "";
|
||||
if(result->get("success", &rec_success))
|
||||
@@ -172,35 +173,45 @@ bool CurrentOnlineUser::signOut(){
|
||||
m_is_signed_in = false;
|
||||
m_is_guest = false;
|
||||
}
|
||||
result->get("info", &info);
|
||||
}
|
||||
else
|
||||
{
|
||||
info = _("Unable to connect to the server. Check your internet connection or try again later.");
|
||||
}
|
||||
return !m_is_signed_in;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
PtrVector<Server> * CurrentOnlineUser::getServerList(){
|
||||
|
||||
bool CurrentOnlineUser::requestJoin(uint32_t server_id, irr::core::stringw &info){
|
||||
assert(m_is_signed_in == true);
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||
connector->setParameter("action",std::string("get_server_list"));
|
||||
connector->setParameter("token",m_token);
|
||||
connector->setParameter("userid",m_id);
|
||||
|
||||
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
|
||||
connector->setParameter("action",std::string("request-connection"));
|
||||
connector->setParameter("token", m_token);
|
||||
connector->setParameter("id", m_id);
|
||||
connector->setParameter("server_id", server_id);
|
||||
bool success = false;
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
std::string rec_success = "";
|
||||
if(result->get("success", &rec_success))
|
||||
{
|
||||
if (rec_success =="yes")
|
||||
{
|
||||
const XMLNode * servers_xml = result->getNode("servers");
|
||||
PtrVector<Server> * servers = new PtrVector<Server>;
|
||||
for (unsigned int i = 0; i < servers_xml->getNumNodes(); i++)
|
||||
{
|
||||
servers->push_back(new Server(*servers_xml->getNode(i)));
|
||||
}
|
||||
return servers;
|
||||
m_token = "";
|
||||
m_name = "";
|
||||
m_id = 0;
|
||||
m_is_signed_in = false;
|
||||
m_is_guest = false;
|
||||
success = true;
|
||||
}
|
||||
result->get("info", &info);
|
||||
}
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
info = _("Unable to connect to the server. Check your internet connection or try again later.");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -22,10 +22,11 @@
|
||||
#include "online/online_user.hpp"
|
||||
#include <string>
|
||||
#include <irrString.h>
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "utils/types.hpp"
|
||||
#include "online/server.hpp"
|
||||
|
||||
|
||||
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
@@ -58,13 +59,14 @@ class CurrentOnlineUser : public OnlineUser
|
||||
bool terms,
|
||||
irr::core::stringw &info);
|
||||
// Logout - Best to be followed by CurrentOnlineUser::deallocate
|
||||
bool signOut();
|
||||
bool signOut( irr::core::stringw &info);
|
||||
|
||||
bool createServer( const irr::core::stringw &name,
|
||||
int max_players,
|
||||
irr::core::stringw &info);
|
||||
|
||||
PtrVector<Server> * getServerList();
|
||||
bool requestJoin( uint32_t server_id,
|
||||
irr::core::stringw &info);
|
||||
|
||||
/** Returns the username if signed in. */
|
||||
irr::core::stringw getUserName() const;
|
||||
|
||||
@@ -24,28 +24,21 @@
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
Server::SortOrder Server::m_sort_order=Server::SO_NAME;
|
||||
Server::SortOrder Server::m_sort_order=Server::SO_NAME; //FIXME change to some other default
|
||||
|
||||
Server::Server(const XMLNode & xml)
|
||||
{
|
||||
assert(xml.getName() == "server");
|
||||
m_name = "";
|
||||
m_server_id = 0;
|
||||
m_description = "";
|
||||
m_current_players = 0;
|
||||
m_max_players = 0;
|
||||
m_name = "";
|
||||
m_satisfaction_score = 0;
|
||||
m_server_id = 0;
|
||||
m_current_players = 0;
|
||||
m_max_players = 0;
|
||||
|
||||
xml.get("name", &m_lower_case_name);
|
||||
m_name = StringUtils::decodeFromHtmlEntities(m_lower_case_name);
|
||||
m_lower_case_name = StringUtils::toLowerCase(m_lower_case_name);
|
||||
|
||||
std::string description;
|
||||
xml.get("description", &description);
|
||||
m_description = StringUtils::decodeFromHtmlEntities(description);
|
||||
// resolve XML entities
|
||||
//m_description = StringUtils::replace(m_description, " ", "\n");
|
||||
//m_description = StringUtils::replace(m_description, " ", ""); // ignore \r
|
||||
|
||||
xml.get("id", &m_server_id);
|
||||
xml.get("max_players", &m_max_players);
|
||||
xml.get("current_players", &m_current_players);
|
||||
@@ -73,11 +66,6 @@ bool Server::filterByWords(const core::stringw words) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((core::stringw(m_description)).make_lower().find(list[i].c_str()) != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <string>
|
||||
#include <irrString.h>
|
||||
#include "io/xml_node.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
class XMLNode;
|
||||
|
||||
@@ -48,9 +49,7 @@ protected:
|
||||
irr::core::stringw m_name;
|
||||
std::string m_lower_case_name; //Used for comparison
|
||||
|
||||
irr::core::stringw m_description;
|
||||
|
||||
int m_server_id;
|
||||
uint32_t m_server_id;
|
||||
|
||||
int m_max_players;
|
||||
|
||||
@@ -76,13 +75,10 @@ public:
|
||||
const irr::core::stringw& getName() const { return m_name; }
|
||||
const std::string & getLowerCaseName() const { return m_lower_case_name; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the server. */
|
||||
const irr::core::stringw& getDescription() const { return m_description; }
|
||||
// ------------------------------------------------------------------------
|
||||
const float getScore() const { return m_satisfaction_score; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the ID of this server. */
|
||||
const int getServerId() const { return m_server_id; }
|
||||
const uint32_t getServerId() const { return m_server_id; }
|
||||
const int getMaxPlayers() const { return m_max_players; }
|
||||
const int getCurrentPlayers() const { return m_current_players; }
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -103,6 +99,9 @@ public:
|
||||
// m_id is the lower case name
|
||||
return m_name < server.getName();
|
||||
break;
|
||||
case SO_PLAYERS:
|
||||
return m_current_players < server.getCurrentPlayers();
|
||||
break;
|
||||
} // switch
|
||||
return true;
|
||||
} // operator<
|
||||
@@ -116,9 +115,9 @@ public:
|
||||
{
|
||||
switch(m_sort_order)
|
||||
{
|
||||
/*case SO_SCORE:
|
||||
case SO_SCORE:
|
||||
return m_satisfaction_score > server.getScore();
|
||||
break;*/
|
||||
break;
|
||||
case SO_NAME:
|
||||
return m_lower_case_name > server.getLowerCaseName();
|
||||
break;
|
||||
|
||||
71
src/online/servers_manager.cpp
Normal file
71
src/online/servers_manager.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#include "online/servers_manager.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <irrString.h>
|
||||
#include <assert.h>
|
||||
#include "online/http_connector.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
static ServersManager* user_singleton = NULL;
|
||||
|
||||
ServersManager* ServersManager::get()
|
||||
{
|
||||
if (user_singleton == NULL)
|
||||
user_singleton = new ServersManager();
|
||||
return user_singleton;
|
||||
} // get
|
||||
|
||||
void ServersManager::deallocate()
|
||||
{
|
||||
delete user_singleton;
|
||||
user_singleton = NULL;
|
||||
} // deallocate
|
||||
|
||||
// ============================================================================
|
||||
ServersManager::ServersManager(){
|
||||
m_servers = new PtrVector<Server>;
|
||||
refresh();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
void ServersManager::refresh()
|
||||
{
|
||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||
connector->setParameter("action",std::string("get_server_list"));
|
||||
|
||||
const XMLNode * result = connector->getXMLFromPage();
|
||||
std::string rec_success = "";
|
||||
if(result->get("success", &rec_success))
|
||||
{
|
||||
if (rec_success =="yes")
|
||||
{
|
||||
const XMLNode * servers_xml = result->getNode("servers");
|
||||
m_servers->clearAndDeleteAll();
|
||||
for (unsigned int i = 0; i < servers_xml->getNumNodes(); i++)
|
||||
{
|
||||
m_servers->push_back(new Server(*servers_xml->getNode(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
//FIXME error message
|
||||
}
|
||||
56
src/online/servers_manager.hpp
Normal file
56
src/online/servers_manager.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_SERVERS_MANAGER_HPP
|
||||
#define HEADER_CURRENT_ONLINE_USER_HPP
|
||||
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "online/server.hpp"
|
||||
|
||||
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* \ingroup online
|
||||
*/
|
||||
class ServersManager
|
||||
{
|
||||
private:
|
||||
ServersManager();
|
||||
PtrVector<Server> * m_servers;
|
||||
bool m_not_fetched;
|
||||
Server * m_joined_server;
|
||||
|
||||
public:
|
||||
// singleton
|
||||
static ServersManager* get();
|
||||
static void deallocate();
|
||||
|
||||
void refresh();
|
||||
PtrVector<Server> * getServers () const { return m_servers; };
|
||||
int getNumServers () const { return m_servers->size(); };
|
||||
Server * getServer (int index) const { return m_servers->get(index);};
|
||||
void sort(bool sort_desc) { m_servers->insertionSort(0, sort_desc); };
|
||||
void setJoinedServer(Server * server){ m_joined_server = server;};
|
||||
Server * getJoinedServer(){ return m_joined_server;};
|
||||
}; // class ServersManager
|
||||
|
||||
#endif
|
||||
|
||||
/*EOF*/
|
||||
@@ -160,7 +160,7 @@ void LoginDialog::onUpdate(float dt)
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
if (m_open_registration_dialog)
|
||||
new RegistrationDialog(0.8f, 0.9f);
|
||||
new RegistrationDialog();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ using namespace irr::gui;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
RegistrationDialog::RegistrationDialog(const float w, const float h, const Phase phase) :
|
||||
ModalDialog(w,h)
|
||||
RegistrationDialog::RegistrationDialog(const Phase phase) :
|
||||
ModalDialog(0.8f,0.9f)
|
||||
{
|
||||
m_self_destroy = false;
|
||||
m_show_registration_info = false;
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
Activation = 4
|
||||
};
|
||||
|
||||
RegistrationDialog(const float percentWidth, const float percentHeight, const Phase phase = Info);
|
||||
RegistrationDialog(const Phase phase = Info);
|
||||
~RegistrationDialog();
|
||||
|
||||
void onEnterPressedInternal();
|
||||
|
||||
134
src/states_screens/dialogs/server_info_dialog.cpp
Normal file
134
src/states_screens/dialogs/server_info_dialog.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "states_screens/dialogs/server_info_dialog.hpp"
|
||||
|
||||
#include <IGUIEnvironment.h>
|
||||
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "config/player.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "online/current_online_user.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "states_screens/dialogs/registration_dialog.hpp"
|
||||
#include "states_screens/networking_lobby.hpp"
|
||||
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr;
|
||||
using namespace irr::gui;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ServerInfoDialog::ServerInfoDialog(Server * server) :
|
||||
ModalDialog(0.8f,0.8f)
|
||||
{
|
||||
m_server = server;
|
||||
m_self_destroy = false;
|
||||
m_enter_lobby = false;
|
||||
|
||||
loadFromFile("online/server_info_dialog.stkgui");
|
||||
|
||||
m_name_widget = getWidget<LabelWidget>("name");
|
||||
assert(m_name_widget != NULL);
|
||||
m_name_widget->setText(server->getName(),false);
|
||||
|
||||
m_info_widget = getWidget<LabelWidget>("info");
|
||||
assert(m_info_widget != NULL);
|
||||
|
||||
m_options_widget = getWidget<RibbonWidget>("options");
|
||||
assert(m_options_widget != NULL);
|
||||
m_join_widget = getWidget<IconButtonWidget>("join");
|
||||
assert(m_join_widget != NULL);
|
||||
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
||||
assert(m_cancel_widget != NULL);
|
||||
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
ServerInfoDialog::~ServerInfoDialog()
|
||||
{
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void ServerInfoDialog::requestJoin()
|
||||
{
|
||||
//FIXME totally not correct. Receiving an answer, not kept in mind.
|
||||
irr::core::stringw info;
|
||||
if (CurrentOnlineUser::get()->requestJoin( m_server->getServerId(), info))
|
||||
{
|
||||
ServersManager::get()->setJoinedServer(m_server);
|
||||
m_enter_lobby = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
m_info_widget->setColor(irr::video::SColor(255, 255, 0, 0));
|
||||
m_info_widget->setText(info, false);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation ServerInfoDialog::processEvent(const std::string& eventSource)
|
||||
{
|
||||
|
||||
if (eventSource == m_options_widget->m_properties[PROP_ID])
|
||||
{
|
||||
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (selection == m_cancel_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_self_destroy = true;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if(selection == m_join_widget->m_properties[PROP_ID])
|
||||
{
|
||||
requestJoin();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ServerInfoDialog::onEnterPressedInternal()
|
||||
{
|
||||
|
||||
//If enter was pressed while none of the buttons was focused interpret as join event
|
||||
const int playerID = PLAYER_ID_GAME_MASTER;
|
||||
if (GUIEngine::isFocusedForPlayer(m_options_widget, playerID))
|
||||
return;
|
||||
requestJoin();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ServerInfoDialog::onUpdate(float dt)
|
||||
{
|
||||
//If we want to open the registration dialog, we need to close this one first
|
||||
m_enter_lobby && (m_self_destroy = true);
|
||||
|
||||
// It's unsafe to delete from inside the event handler so we do it here
|
||||
if (m_self_destroy)
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
if (m_enter_lobby)
|
||||
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
|
||||
}
|
||||
}
|
||||
63
src/states_screens/dialogs/server_info_dialog.hpp
Normal file
63
src/states_screens/dialogs/server_info_dialog.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#ifndef HEADER_SERVER_INFO_DIALOG_HPP
|
||||
#define HEADER_SERVER_INFO_DIALOG_HPP
|
||||
|
||||
#include <irrString.h>
|
||||
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "online/server.hpp"
|
||||
/**
|
||||
* \brief Dialog that allows a user to sign in
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class ServerInfoDialog : public GUIEngine::ModalDialog
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
bool m_self_destroy;
|
||||
bool m_enter_lobby;
|
||||
|
||||
Server * m_server;
|
||||
|
||||
GUIEngine::LabelWidget * m_name_widget;
|
||||
GUIEngine::LabelWidget * m_info_widget;
|
||||
|
||||
GUIEngine::RibbonWidget * m_options_widget;
|
||||
GUIEngine::IconButtonWidget * m_join_widget;
|
||||
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||
|
||||
void requestJoin();
|
||||
|
||||
public:
|
||||
ServerInfoDialog(Server * server);
|
||||
~ServerInfoDialog();
|
||||
|
||||
void onEnterPressedInternal();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
|
||||
virtual void onUpdate(float dt);
|
||||
//virtual void onTextUpdated();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
|
||||
#include "online/current_online_user.hpp"
|
||||
|
||||
@@ -47,13 +48,16 @@ DEFINE_SCREEN_SINGLETON( NetworkingLobby );
|
||||
|
||||
NetworkingLobby::NetworkingLobby() : Screen("online/lobby.stkgui")
|
||||
{
|
||||
|
||||
m_server = ServersManager::get()->getJoinedServer();
|
||||
} // NetworkingLobby
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void NetworkingLobby::loadedFromFile()
|
||||
{
|
||||
m_server_name_widget = getWidget<LabelWidget>("server_name");
|
||||
assert(m_server_name_widget != NULL);
|
||||
|
||||
m_online_status_widget = getWidget<LabelWidget>("online_status");
|
||||
assert(m_online_status_widget != NULL);
|
||||
|
||||
@@ -65,12 +69,6 @@ void NetworkingLobby::loadedFromFile()
|
||||
|
||||
} // loadedFromFile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool NetworkingLobby::hasLostConnection()
|
||||
{
|
||||
return !CurrentOnlineUser::get()->isSignedIn();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void NetworkingLobby::beforeAddingWidget()
|
||||
{
|
||||
@@ -85,7 +83,8 @@ void NetworkingLobby::init()
|
||||
Screen::init();
|
||||
setInitialFocus();
|
||||
DemoWorld::resetIdleTime(); //FIXME : what's this?
|
||||
m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + CurrentOnlineUser::get()->getUserName() + ".", false);
|
||||
m_server_name_widget->setText(m_server->getName(),false);
|
||||
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "online/server.hpp"
|
||||
|
||||
namespace GUIEngine { class Widget; class ListWidget; }
|
||||
|
||||
@@ -35,8 +36,12 @@ class NetworkingLobby : public GUIEngine::Screen,
|
||||
private:
|
||||
friend class GUIEngine::ScreenSingleton<NetworkingLobby>;
|
||||
|
||||
Server * m_server;
|
||||
|
||||
NetworkingLobby();
|
||||
|
||||
GUIEngine::LabelWidget * m_server_name_widget;
|
||||
|
||||
GUIEngine::LabelWidget * m_online_status_widget;
|
||||
|
||||
GUIEngine::RibbonWidget * m_bottom_menu_widget;
|
||||
@@ -44,8 +49,6 @@ private:
|
||||
GUIEngine::IconButtonWidget * m_register_widget;
|
||||
GUIEngine::IconButtonWidget * m_sign_out_widget;
|
||||
|
||||
/** \brief Checks if the user is still signed in. */
|
||||
bool hasLostConnection();
|
||||
/** \brief Sets which widget has to be focused. Depends on the user state. */
|
||||
void setInitialFocus();
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "main_loop.hpp"
|
||||
#include "states_screens/online_screen.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "states_screens/dialogs/login_dialog.hpp"
|
||||
#include "states_screens/dialogs/registration_dialog.hpp"
|
||||
#include "states_screens/networking_lobby.hpp"
|
||||
#include "states_screens/networking_lobby_settings.hpp"
|
||||
#include "states_screens/server_selection.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
@@ -167,22 +167,22 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
|
||||
}
|
||||
else if (selection == "sign_out")
|
||||
{
|
||||
if (CurrentOnlineUser::get()->signOut())
|
||||
irr::core::stringw info;
|
||||
if (CurrentOnlineUser::get()->signOut(info))
|
||||
{
|
||||
new MessageDialog( _("Signed out successfully.") );
|
||||
new MessageDialog(_("Signed out successfully."));
|
||||
//GUIEngine::reshowCurrentScreen();
|
||||
}
|
||||
else
|
||||
new MessageDialog( _("An error occured while signing out.") );
|
||||
new MessageDialog(info);
|
||||
}
|
||||
else if (selection == "register")
|
||||
{
|
||||
new RegistrationDialog(0.8f, 0.9f);
|
||||
new RegistrationDialog();
|
||||
}
|
||||
else if (selection == "find_server")
|
||||
{
|
||||
//if (m_recorded_state == Registered)
|
||||
new MessageDialog("Coming soon!");
|
||||
StateManager::get()->pushScreen(ServerSelection::getInstance());
|
||||
}
|
||||
else if (selection == "create_server")
|
||||
{
|
||||
@@ -208,7 +208,8 @@ void OnlineScreen::onDisabledItemClicked(const std::string& item)
|
||||
{
|
||||
if (item == "find_server")
|
||||
{
|
||||
new LoginDialog(LoginDialog::Registration_Required);
|
||||
StateManager::get()->pushScreen(ServerSelection::getInstance());
|
||||
// FIXME new LoginDialog(LoginDialog::Registration_Required);
|
||||
}
|
||||
else if (item =="create_server")
|
||||
{
|
||||
|
||||
@@ -23,16 +23,17 @@
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "states_screens/dialogs/server_info_dialog.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "online/current_online_user.hpp"
|
||||
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
|
||||
DEFINE_SCREEN_SINGLETON( ServerSelection );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ServerSelection::ServerSelection() : Screen("server_selection.stkgui")
|
||||
ServerSelection::ServerSelection() : Screen("online/server_selection.stkgui")
|
||||
{
|
||||
m_selected_index = -1;
|
||||
m_reload_timer = 0.0f;
|
||||
@@ -49,8 +50,6 @@ void ServerSelection::loadedFromFile()
|
||||
m_server_list_widget = getWidget<GUIEngine::ListWidget>("server_list");
|
||||
assert(m_server_list_widget != NULL);
|
||||
m_server_list_widget->setColumnListener(this);
|
||||
|
||||
m_servers = CurrentOnlineUser::get()->getServerList();
|
||||
} // loadedFromFile
|
||||
|
||||
|
||||
@@ -60,8 +59,7 @@ void ServerSelection::beforeAddingWidget()
|
||||
{
|
||||
m_server_list_widget->clearColumns();
|
||||
m_server_list_widget->addColumn( _("Name"), 4 );
|
||||
m_server_list_widget->addColumn( _("Players"), 1 );
|
||||
m_server_list_widget->addColumn( _("Max"), 1 );
|
||||
m_server_list_widget->addColumn( _("Players"), 2);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -94,25 +92,26 @@ void ServerSelection::tearDown()
|
||||
* updated.
|
||||
* \param type Must be 'kart' or 'track'.
|
||||
*/
|
||||
void ServerSelection::loadList()
|
||||
void ServerSelection::loadList(bool refresh)
|
||||
{
|
||||
// First create a list of sorted entries
|
||||
|
||||
m_servers->insertionSort(/*start=*/0, m_sort_desc);
|
||||
|
||||
m_server_list_widget->clear();
|
||||
ServersManager * manager = ServersManager::get();
|
||||
if (refresh)
|
||||
manager->refresh();
|
||||
manager->sort(m_sort_desc);
|
||||
|
||||
for(int i=0; i<m_servers->size(); i++)
|
||||
for(int i=0; i < manager->getNumServers(); i++)
|
||||
{
|
||||
Server * server = manager->getServer(i);
|
||||
core::stringw table_entry;
|
||||
table_entry.append((*m_servers)[i].getName());
|
||||
table_entry.append(server->getName());
|
||||
table_entry.append("\t");
|
||||
table_entry.append((*m_servers)[i].getCurrentPlayers());
|
||||
table_entry.append("\t");
|
||||
table_entry.append((*m_servers)[i].getMaxPlayers());
|
||||
table_entry.append(StringUtils::toWString(server->getCurrentPlayers()));
|
||||
table_entry.append("/");
|
||||
table_entry.append(StringUtils::toWString(server->getMaxPlayers()));
|
||||
m_server_list_widget->addItem("server", table_entry);
|
||||
|
||||
}
|
||||
|
||||
} // loadList
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -122,7 +121,6 @@ void ServerSelection::onColumnClicked(int column_id)
|
||||
{
|
||||
case 0: Server::setSortOrder(Server::SO_NAME); break;
|
||||
case 1: Server::setSortOrder(Server::SO_PLAYERS); break;
|
||||
case 2: Server::setSortOrder(Server::SO_PLAYERS); break;
|
||||
default: assert(0); break;
|
||||
} // switch
|
||||
/** \brief Toggle the sort order after column click **/
|
||||
@@ -146,7 +144,6 @@ void ServerSelection::eventCallback( GUIEngine::Widget* widget,
|
||||
{
|
||||
m_reloading = true;
|
||||
m_server_list_widget->clear();
|
||||
|
||||
m_server_list_widget->addItem("spacer", L"");
|
||||
m_server_list_widget->addItem("loading", _("Please wait while the list is being updated."));
|
||||
}
|
||||
@@ -155,7 +152,7 @@ void ServerSelection::eventCallback( GUIEngine::Widget* widget,
|
||||
else if (name == m_server_list_widget->m_properties[GUIEngine::PROP_ID])
|
||||
{
|
||||
m_selected_index = m_server_list_widget->getSelectionID();
|
||||
//new ServerInfoDialog(0.8f, 0.8f, id);
|
||||
new ServerInfoDialog(ServersManager::get()->getServer(m_selected_index));
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
@@ -186,9 +183,12 @@ void ServerSelection::onUpdate(float dt, irr::video::IVideoDriver*)
|
||||
m_reloading = false;
|
||||
if(m_reload_timer > 5000.0f)
|
||||
{
|
||||
m_servers = CurrentOnlineUser::get()->getServerList();
|
||||
loadList(true);
|
||||
m_reload_timer = 0.0f;
|
||||
}
|
||||
loadList();
|
||||
else
|
||||
{
|
||||
loadList(false);
|
||||
}
|
||||
}
|
||||
} // onUpdate
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "online/server.hpp"
|
||||
|
||||
namespace GUIEngine { class Widget; }
|
||||
|
||||
@@ -60,12 +58,10 @@ private:
|
||||
|
||||
float m_reload_timer;
|
||||
|
||||
PtrVector<Server> * m_servers;
|
||||
|
||||
public:
|
||||
|
||||
/** Load the addons into the main list.*/
|
||||
void loadList();
|
||||
void loadList(bool refresh = false);
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
|
||||
Reference in New Issue
Block a user