diff --git a/data/gui/online/profile_friends.stkgui b/data/gui/online/profile_friends.stkgui index 5f3fb1423..978ba720f 100644 --- a/data/gui/online/profile_friends.stkgui +++ b/data/gui/online/profile_friends.stkgui @@ -12,18 +12,23 @@ -
-
- +
+
+ - -
+ +
- - - -
+ +
diff --git a/data/gui/online/user_search.stkgui b/data/gui/online/user_search.stkgui new file mode 100644 index 000000000..3d2a4eee5 --- /dev/null +++ b/data/gui/online/user_search.stkgui @@ -0,0 +1,23 @@ + + +
+ +
+ +
+
+ +
+ + +
+ + + + + +
+ +
diff --git a/sources.cmake b/sources.cmake index e53d72d15..d27ed15f3 100644 --- a/sources.cmake +++ b/sources.cmake @@ -234,6 +234,7 @@ src/states_screens/online_profile_base.cpp src/states_screens/online_profile_friends.cpp src/states_screens/online_profile_overview.cpp src/states_screens/online_screen.cpp +src/states_screens/online_user_search.cpp src/states_screens/options_screen_audio.cpp src/states_screens/options_screen_input2.cpp src/states_screens/options_screen_input.cpp @@ -534,6 +535,7 @@ src/states_screens/online_profile_base.hpp src/states_screens/online_profile_friends.hpp src/states_screens/online_profile_overview.hpp src/states_screens/online_screen.hpp +src/states_screens/online_user_search.hpp src/states_screens/options_screen_audio.hpp src/states_screens/options_screen_input2.hpp src/states_screens/options_screen_input.hpp diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp index 36802d206..3abe05959 100644 --- a/src/online/current_user.cpp +++ b/src/online/current_user.cpp @@ -263,6 +263,21 @@ namespace Online{ // ============================================================================ + const XMLRequest * CurrentUser::requestUserSearch( const irr::core::stringw & search_string) const + { + assert(isRegisteredUser()); + XMLRequest * request = new XMLRequest(); + request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + request->setParameter("action", std::string("user-search")); + request->setParameter("token", getToken()); + request->setParameter("userid", getUserID()); + request->setParameter("search-string", search_string); + HTTPManager::get()->addRequest(request); + return request; + } + + // ============================================================================ + const CurrentUser::setAddonVoteRequest * CurrentUser::requestSetAddonVote( const std::string & addon_id, float rating) const { assert(isRegisteredUser()); diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp index 48b9e9cee..7f8798e84 100644 --- a/src/online/current_user.hpp +++ b/src/online/current_user.hpp @@ -139,6 +139,8 @@ namespace Online{ const XMLRequest * requestGetAddonVote(const std::string & addon_id) const; const setAddonVoteRequest * requestSetAddonVote(const std::string & addon_id, float rating) const; + const XMLRequest * requestUserSearch(const irr::core::stringw & search_string) const; + /** Returns the username if signed in. */ const irr::core::stringw getUserName() const; const UserState getUserState() const { return m_state.getAtomic(); } diff --git a/src/online/messages.cpp b/src/online/messages.cpp index d70dffb65..65fc94676 100644 --- a/src/online/messages.cpp +++ b/src/online/messages.cpp @@ -45,6 +45,11 @@ namespace Online return irr::core::stringw(_("Validating recovery info")) + loadingDots(); } // ------------------------------------------------------------------------ + irr::core::stringw searching() + { + return irr::core::stringw(_("Searching")) + loadingDots(); + } + // ------------------------------------------------------------------------ irr::core::stringw signedInAs(const irr::core::stringw & name) { diff --git a/src/online/messages.hpp b/src/online/messages.hpp index 1020b836d..ce4e09f49 100644 --- a/src/online/messages.hpp +++ b/src/online/messages.hpp @@ -31,6 +31,7 @@ namespace Online irr::core::stringw signingOut (); irr::core::stringw signingUp (); irr::core::stringw recovery (); + irr::core::stringw searching (); irr::core::stringw joiningServer (); irr::core::stringw creatingServer (); irr::core::stringw fetchingServers (); diff --git a/src/online/user.cpp b/src/online/user.cpp index b06bd3505..cc8563e5c 100644 --- a/src/online/user.cpp +++ b/src/online/user.cpp @@ -33,4 +33,15 @@ namespace Online{ setUserName(username); setUserID(userid); } + + // ============================================================================ + User::User ( const XMLNode * xml) + { + irr::core::stringw username(""); + xml->get("user_name", &username); + setUserName(username); + uint32_t id; + xml->get("id", &id); + setUserID(id); + } } // namespace Online diff --git a/src/online/user.hpp b/src/online/user.hpp index 31807c40b..a4dde877b 100644 --- a/src/online/user.hpp +++ b/src/online/user.hpp @@ -22,6 +22,7 @@ #include #include "utils/types.hpp" #include "utils/synchronised.hpp" +#include "io/xml_node.hpp" namespace Online{ @@ -43,6 +44,7 @@ namespace Online{ User( const irr::core::stringw & username, const uint32_t & userid ); + User( const XMLNode * xml); virtual ~User() {}; virtual const irr::core::stringw getUserName() const { return m_name.getAtomic(); } diff --git a/src/states_screens/online_profile_friends.cpp b/src/states_screens/online_profile_friends.cpp index 1cbc9dc86..34cb619d2 100644 --- a/src/states_screens/online_profile_friends.cpp +++ b/src/states_screens/online_profile_friends.cpp @@ -22,6 +22,7 @@ #include "guiengine/screen.hpp" #include "guiengine/widget.hpp" #include "states_screens/state_manager.hpp" +#include "states_screens/online_user_search.hpp" #include "utils/translation.hpp" #include "online/messages.hpp" @@ -50,6 +51,10 @@ void OnlineProfileFriends::loadedFromFile() OnlineProfileBase::loadedFromFile(); m_friends_list_widget = getWidget("friends_list"); assert(m_friends_list_widget != NULL); + m_search_button_widget = getWidget("search_button"); + assert(m_search_button_widget != NULL); + m_search_box_widget = getWidget("search_box"); + assert(m_search_box_widget != NULL); } // loadedFromFile @@ -80,6 +85,12 @@ void OnlineProfileFriends::init() void OnlineProfileFriends::eventCallback(Widget* widget, const std::string& name, const int playerID) { OnlineProfileBase::eventCallback( widget, name, playerID); + if (name == m_search_button_widget->m_properties[GUIEngine::PROP_ID]) + { + OnlineUserSearch * instance = OnlineUserSearch::getInstance(); + instance->setSearchString(m_search_box_widget->getText().trim()); + StateManager::get()->pushScreen(instance); + } } // eventCallback // ---------------------------------------------------------------------------- diff --git a/src/states_screens/online_profile_friends.hpp b/src/states_screens/online_profile_friends.hpp index 1b1eb9d8d..ef38623a2 100644 --- a/src/states_screens/online_profile_friends.hpp +++ b/src/states_screens/online_profile_friends.hpp @@ -41,6 +41,9 @@ private: OnlineProfileFriends(); GUIEngine::ListWidget * m_friends_list_widget; + GUIEngine::ButtonWidget * m_search_button_widget; + GUIEngine::TextBoxWidget * m_search_box_widget; + Online::Profile * m_visiting_profile; bool m_waiting_for_friends; diff --git a/src/states_screens/online_user_search.cpp b/src/states_screens/online_user_search.cpp new file mode 100644 index 000000000..a3a1cb030 --- /dev/null +++ b/src/states_screens/online_user_search.cpp @@ -0,0 +1,210 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2010 Lucas Baudin, Joerg Henrichs +// +// 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/online_user_search.hpp" + +#include +#include + +#include "guiengine/modaldialog.hpp" +//#include "states_screens/dialogs/user_info_dialog.hpp" +#include "states_screens/state_manager.hpp" +#include "states_screens/dialogs/message_dialog.hpp" +#include "utils/translation.hpp" +#include "utils/string_utils.hpp" +#include "online/messages.hpp" +#include "online/current_user.hpp" +#include "audio/sfx_manager.hpp" + +using namespace Online; + +DEFINE_SCREEN_SINGLETON( OnlineUserSearch ); + +// ---------------------------------------------------------------------------- + +OnlineUserSearch::OnlineUserSearch() : Screen("online/user_search.stkgui") +{ + m_selected_index = -1; + m_search_request = NULL; + m_search_string = ""; + m_last_search_string = ""; +} // OnlineUserSearch + +// ---------------------------------------------------------------------------- + +OnlineUserSearch::~OnlineUserSearch() +{ + delete m_search_request; + m_users.clearAndDeleteAll(); +} // OnlineUserSearch + +// ---------------------------------------------------------------------------- + +void OnlineUserSearch::tearDown() +{ + delete m_search_request; + m_search_request = NULL; +} // tearDown + + +// ---------------------------------------------------------------------------- + +void OnlineUserSearch::parseResult(const XMLNode * input) +{ + m_users.clearAndDeleteAll(); + const XMLNode * users_xml = input->getNode("users"); + for (unsigned int i = 0; i < users_xml->getNumNodes(); i++) + { + m_users.push_back(new User(users_xml->getNode(i))); + } +} + +void OnlineUserSearch::showList() +{ + m_user_list_widget->clear(); + for(int i=0; i < m_users.size(); i++) + { + PtrVector * row = new PtrVector; + row->push_back(new GUIEngine::ListWidget::ListCell(m_users[i].getUserName(),-1,3)); + m_user_list_widget->addItem("user", row); + } +} + +// ---------------------------------------------------------------------------- + +void OnlineUserSearch::search() +{ + if ( m_search_string != "" && m_last_search_string != m_search_string ) + m_search_request = CurrentUser::get()->requestUserSearch(m_search_string); + else + m_fake_refresh = true; + m_user_list_widget->addItem("loading", Messages::searching()); + m_back_widget->setDeactivated(); + m_search_box_widget->setDeactivated(); + m_search_button_widget->setDeactivated(); +} + + +// ---------------------------------------------------------------------------- + +void OnlineUserSearch::loadedFromFile() +{ + m_back_widget = getWidget("back"); + assert(m_back_widget != NULL); + m_search_button_widget = getWidget("search_button"); + assert(m_search_button_widget != NULL); + m_search_box_widget = getWidget("search_box"); + assert(m_search_box_widget != NULL); + m_user_list_widget = getWidget("user_list"); + assert(m_user_list_widget != NULL); +} // loadedFromFile + + +// ---------------------------------------------------------------------------- + +void OnlineUserSearch::beforeAddingWidget() +{ + m_user_list_widget->clearColumns(); + m_user_list_widget->addColumn( _("Username"), 3 ); +} +// ---------------------------------------------------------------------------- + +void OnlineUserSearch::init() +{ + Screen::init(); + search(); + m_fake_refresh = false; + m_search_box_widget->setText(m_search_string); +} // init + +// ---------------------------------------------------------------------------- +void OnlineUserSearch::eventCallback( GUIEngine::Widget* widget, + const std::string& name, + const int playerID) +{ + if (name == m_back_widget->m_properties[GUIEngine::PROP_ID]) + { + StateManager::get()->escapePressed(); + } + else if (name == m_user_list_widget->m_properties[GUIEngine::PROP_ID]) + { + m_selected_index = m_user_list_widget->getSelectionID(); + //new UserInfoDialog(m_users[m_selected_index]); FIXME + } + else if (name == m_search_button_widget->m_properties[GUIEngine::PROP_ID]) + { + m_last_search_string = m_search_string; + m_search_string = m_search_box_widget->getText().trim(); + search(); + } + +} // eventCallback + +// ---------------------------------------------------------------------------- +/** Selects the last selected item on the list (which is the item that + * is just being installed) again. This function is used from the + * addons_loading screen: when it is closed, it will reset the + * select item so that people can keep on installing from that + * point on. +*/ +void OnlineUserSearch::setLastSelected() //FIXME actually use this here and in server selection +{ + if(m_selected_index>-1) + { + m_user_list_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + m_user_list_widget->setSelectionID(m_selected_index); + } +} // setLastSelected + +// ---------------------------------------------------------------------------- + +void OnlineUserSearch::onUpdate(float dt, irr::video::IVideoDriver*) +{ + if(m_search_request != NULL) + { + if(m_search_request->isDone()) + { + if(m_search_request->isSuccess()) + { + parseResult(m_search_request->getResult()); + showList(); + } + else + { + sfx_manager->quickSound( "anvil" ); + new MessageDialog(m_search_request->getInfo()); + } + delete m_search_request; + m_search_request = NULL; + m_back_widget->setActivated(); + m_search_box_widget->setActivated(); + m_search_button_widget->setActivated(); + } + else + { + m_user_list_widget->renameItem("loading", Messages::searching()); + } + } + else if(m_fake_refresh) + { + showList(); + m_fake_refresh = false; + m_back_widget->setActivated(); + m_search_box_widget->setActivated(); + m_search_button_widget->setActivated(); + } +} // onUpdate diff --git a/src/states_screens/online_user_search.hpp b/src/states_screens/online_user_search.hpp new file mode 100644 index 000000000..b5ec1b985 --- /dev/null +++ b/src/states_screens/online_user_search.hpp @@ -0,0 +1,85 @@ +// 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_ONLINE_USER_SEARCH_HPP +#define HEADER_ONLINE_USER_SEARCH_HPP + +#include "guiengine/screen.hpp" +#include "guiengine/widgets.hpp" +#include "online/user.hpp" +#include "online/request.hpp" +#include "utils/ptr_vector.hpp" + +namespace GUIEngine { class Widget; } + +/** + * \brief + * \ingroup + */ +class OnlineUserSearch : public GUIEngine::Screen, + public GUIEngine::ScreenSingleton +{ + friend class GUIEngine::ScreenSingleton; + +private: + OnlineUserSearch(); + ~OnlineUserSearch(); + + GUIEngine::IconButtonWidget * m_back_widget; + GUIEngine::ButtonWidget * m_search_button_widget; + GUIEngine::TextBoxWidget * m_search_box_widget; + GUIEngine::ListWidget * m_user_list_widget; + + /** The currently selected index, used to re-select this item after + * addons_loading is being displayed. */ + int m_selected_index; + irr::core::stringw m_search_string; + irr::core::stringw m_last_search_string; + PtrVector m_users; + const Online::XMLRequest * m_search_request; + bool m_fake_refresh; + + void parseResult(const XMLNode * input); + void showList(); + void search(); + + +public: + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void loadedFromFile() OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, + const int playerID) OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void beforeAddingWidget() OVERRIDE; + + virtual void init() OVERRIDE; + + virtual void tearDown() OVERRIDE; + + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void onUpdate(float dt, irr::video::IVideoDriver*) OVERRIDE; + + void setLastSelected(); + void setSearchString(const irr::core::stringw & search_string) {m_search_string = search_string;} + +}; + +#endif diff --git a/src/states_screens/server_selection.hpp b/src/states_screens/server_selection.hpp index fa0e2c067..724f48792 100644 --- a/src/states_screens/server_selection.hpp +++ b/src/states_screens/server_selection.hpp @@ -43,8 +43,6 @@ private: GUIEngine::LabelWidget * m_update_status; GUIEngine::ListWidget * m_server_list_widget; - /** Currently selected type. */ - std::string m_type; /** The currently selected index, used to re-select this item after * addons_loading is being displayed. */