Use "and" search for server

This commit is contained in:
Benau 2018-09-14 09:06:03 +08:00
parent 99a4fac85e
commit ea3215aad6
3 changed files with 18 additions and 27 deletions

View File

@ -75,30 +75,26 @@ Server::Server(const XMLNode& server_info) : m_supports_encrytion(true)
const XMLNode* player_info = players->getNode(i);
assert(player_info->getName() == "player-info");
std::string username;
std::pair<std::string, std::tuple<int, core::stringw, double, float> >
p;
auto& t = p.second;
std::tuple<int, core::stringw, double, float> t;
// Default rank and scores if none
std::get<0>(t) = -1;
std::get<2>(t) = 2000.0;
player_info->get("rank", &std::get<0>(t));
player_info->get("username", &username);
std::get<1>(t) = StringUtils::utf8ToWide(username);
p.first = StringUtils::toLowerCase(username);
m_lower_case_player_names += StringUtils::toLowerCase(username);
player_info->get("scores", &std::get<2>(t));
float time_played = 0.0f;
player_info->get("time-played", &time_played);
std::get<3>(t) = time_played;
m_players.emplace_back(std::move(p));
m_players.push_back(t);
}
// Sort by rank
std::sort(m_players.begin(), m_players.end(),
[](const std::pair<std::string,
std::tuple<int, core::stringw, double, float> >& a,
const std::pair<std::string,
std::tuple<int, core::stringw, double, float> >& b)->bool
[](const std::tuple<int, core::stringw, double, float>& a,
const std::tuple<int, core::stringw, double, float>& b)->bool
{
return std::get<0>(a.second) < std::get<0>(b.second);
return std::get<0>(a) < std::get<0>(b);
});
// Show owner name as Official right now if official server hoster account

View File

@ -52,6 +52,8 @@ protected:
std::string m_server_owner_lower_case_name;
std::string m_lower_case_player_names;
uint32_t m_server_id;
uint32_t m_server_owner;
@ -89,9 +91,9 @@ protected:
bool m_game_started;
std::vector<std::pair</*lower case username*/std::string, std::tuple<
std::vector<std::tuple<
/*rank*/int, core::stringw, /*scores*/double, /*playing time*/float
> > > m_players;
> > m_players;
public:
@ -145,9 +147,8 @@ public:
// ------------------------------------------------------------------------
bool isGameStarted() const { return m_game_started; }
// ------------------------------------------------------------------------
const std::vector<std::pair<std::string,
std::tuple<int, core::stringw, double, float> > >& getPlayers() const
{ return m_players; }
const std::vector<std::tuple<int, core::stringw, double, float> >&
getPlayers() const { return m_players; }
// ------------------------------------------------------------------------
void setServerId(unsigned id) { m_server_id = id; }
// ------------------------------------------------------------------------
@ -158,18 +159,13 @@ public:
bool searchByName(const std::string& lower_case_word)
{
auto list = StringUtils::split(lower_case_word, ' ', false);
bool server_name_found = false;
bool server_name_found = true;
for (auto& word : list)
{
server_name_found =
m_lower_case_name.find(word) != std::string::npos;
if (server_name_found)
break;
for (auto& p : m_players)
{
if (p.first.find(word) != std::string::npos)
return true;
}
const std::string& for_search = m_lower_case_name +
m_lower_case_player_names;
server_name_found = server_name_found &&
for_search.find(word) != std::string::npos;
}
return server_name_found;
}

View File

@ -108,9 +108,8 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr<Server> server)
row.push_back(ListWidget::ListCell(_("Time played"),
-1, 1, true));
player_list->addItem("player", row);
for (auto& p : players)
for (auto& r : players)
{
auto& r = p.second;
row.clear();
row.push_back(ListWidget::ListCell(
std::get<0>(r) == -1 ? L"-" :