User searching! Very close to adding friends now ;)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13469 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
b2a0198c34
commit
c1e36b02de
@ -12,18 +12,23 @@
|
||||
</tabs>
|
||||
|
||||
<box proportion="1" width="100%" layout="vertical-row">
|
||||
<div x="1%" y="2%" width="98%" height="96%" layout="vertical-row" >
|
||||
<div proportion="1" width="100%" layout="horizontal-row">
|
||||
<box proportion="1" height="100%" align="center" layout="vertical-row" padding="6">
|
||||
<div x="1%" y="2%" width="98%" height="96%" layout="horizontal-row" >
|
||||
<div proportion="2" height="100%" layout="vertical-row">
|
||||
<box proportion="2" width="100%" align="center" layout="vertical-row" padding="6">
|
||||
<list id="friends_list" x="0" y="0" width="100%" height="100%"/>
|
||||
</box>
|
||||
<spacer width="2%" height="10"/>
|
||||
<div proportion="1" height="100%" layout="vertical-row" > </div>
|
||||
<spacer width="10" height="10"/>
|
||||
<label height="fit" text_align="left" I18N="Profile friends" text="Look for more friends:"/>
|
||||
<spacer width="10" height="10"/>
|
||||
<div height="fit" width="100%" layout="horizontal-row" align="center">
|
||||
<textbox id="search_box" proportion="1" height="100%"/>
|
||||
<spacer width="30" height="10"/>
|
||||
<button id="search_button" height="fit" width="fit" text="Search" />
|
||||
<spacer width="10" height="10"/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div proportion="1" width="100%" layout="horizontal-row" > </div>
|
||||
</div>
|
||||
<spacer width="2%" height="10"/>
|
||||
<div proportion="1" height="100%" layout="horizontal-row" > </div>
|
||||
</div>
|
||||
</box>
|
||||
</div>
|
||||
|
23
data/gui/online/user_search.stkgui
Normal file
23
data/gui/online/user_search.stkgui
Normal file
@ -0,0 +1,23 @@
|
||||
<stkgui>
|
||||
|
||||
<div x="0%" y="0%" width="100%" height="98%" layout="vertical-row" >
|
||||
|
||||
<div x="0" y="0" width="100%" layout="horizontal-row" height="8%">
|
||||
<icon-button id="back" height="100%" icon="gui/back.png"/>
|
||||
<header text_align="center" proportion="1" text="Server Selection" align="center"/>
|
||||
</div>
|
||||
|
||||
<div height="fit" width="100%" layout="horizontal-row" align="center">
|
||||
<textbox id="search_box" proportion="1" height="100%"/>
|
||||
<spacer width="30" height="10"/>
|
||||
<button id="search_button" height="fit" width="fit" text="Search" />
|
||||
<spacer width="10" height="10"/>
|
||||
</div>
|
||||
|
||||
<box proportion="1" width="98%" align="center" layout="vertical-row" padding="6">
|
||||
<list id="user_list" x="0" y="0" width="100%" height="100%"/>
|
||||
</box>
|
||||
|
||||
</div>
|
||||
|
||||
</stkgui>
|
@ -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
|
||||
|
@ -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());
|
||||
|
@ -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(); }
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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 ();
|
||||
|
@ -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
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <irrString.h>
|
||||
#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(); }
|
||||
|
@ -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<GUIEngine::ListWidget>("friends_list");
|
||||
assert(m_friends_list_widget != NULL);
|
||||
m_search_button_widget = getWidget<GUIEngine::ButtonWidget>("search_button");
|
||||
assert(m_search_button_widget != NULL);
|
||||
m_search_box_widget = getWidget<GUIEngine::TextBoxWidget>("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
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -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;
|
||||
|
||||
|
210
src/states_screens/online_user_search.cpp
Normal file
210
src/states_screens/online_user_search.cpp
Normal file
@ -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 <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
#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<GUIEngine::ListWidget::ListCell> * row = new PtrVector<GUIEngine::ListWidget::ListCell>;
|
||||
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<GUIEngine::IconButtonWidget>("back");
|
||||
assert(m_back_widget != NULL);
|
||||
m_search_button_widget = getWidget<GUIEngine::ButtonWidget>("search_button");
|
||||
assert(m_search_button_widget != NULL);
|
||||
m_search_box_widget = getWidget<GUIEngine::TextBoxWidget>("search_box");
|
||||
assert(m_search_box_widget != NULL);
|
||||
m_user_list_widget = getWidget<GUIEngine::ListWidget>("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
|
85
src/states_screens/online_user_search.hpp
Normal file
85
src/states_screens/online_user_search.hpp
Normal file
@ -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<OnlineUserSearch>
|
||||
{
|
||||
friend class GUIEngine::ScreenSingleton<OnlineUserSearch>;
|
||||
|
||||
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<Online::User> 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
|
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user