Show current players on server in server info dialog
This commit is contained in:
parent
24b3e09429
commit
bb61c3425a
@ -1,44 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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" 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 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>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" text_align="left" I18N="In the networking lobby" text="Difficulty:"/>
|
||||
<label proportion="2" text_align="left" id="server_difficulty" text=""/>
|
||||
</div>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" text_align="left" I18N="In the networking lobby" text="Game mode:"/>
|
||||
<label proportion="2" text_align="left" id="server_game_mode" text=""/>
|
||||
</div>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label id="label_password" text_align="left" proportion="1" text="Password"/>
|
||||
<textbox id="password" proportion="2" height="fit"/>
|
||||
</div>
|
||||
<div x="2%" y="0%" width="96%" height="100%" layout="vertical-row" >
|
||||
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"/>
|
||||
<spacer height="30"/>
|
||||
<label id="server-info" width="90%" height="fit" align="left" text_align="left" text=""/>
|
||||
<box x="0%" width="90%" height="50%" align="center" layout="vertical-row">
|
||||
<list id="player-list" x="0" y="0" width="100%" height="100%"/>
|
||||
</box>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label id="label_password" text_align="left" proportion="1" text="Password"/>
|
||||
<textbox id="password" proportion="2" height="fit"/>
|
||||
</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">
|
||||
<buttonbar id="options" width="90%" height="15%" align="center">
|
||||
<icon-button id="join" width="64" height="64" icon="gui/green_check.png"
|
||||
I18N="In the server info dialog" text="Join" label_location="bottom"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
/** Constructor based on XML data received from the stk server.
|
||||
* \param xml The data for one server as received as part of the
|
||||
* get-all stk-server request.
|
||||
@ -65,6 +67,40 @@ Server::Server(const XMLNode& server_info) : m_supports_encrytion(true)
|
||||
m_server_owner_name = L"-";
|
||||
m_server_owner_lower_case_name = "-";
|
||||
|
||||
const XMLNode* players = server_info.getNode("players");
|
||||
assert(players);
|
||||
for (unsigned int i = 0; i < players->getNumNodes(); i++)
|
||||
{
|
||||
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;
|
||||
// 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);
|
||||
player_info->get("scores", &std::get<2>(t));
|
||||
int cur_time = StkTime::getTimeSinceEpoch();
|
||||
player_info->get("connected-since", &cur_time);
|
||||
std::get<3>(t) = (float)(StkTime::getTimeSinceEpoch() - cur_time)
|
||||
/ 60.0f;
|
||||
m_players.emplace_back(std::move(p));
|
||||
}
|
||||
// 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
|
||||
{
|
||||
return std::get<0>(a.second) < std::get<0>(b.second);
|
||||
});
|
||||
|
||||
// Show owner name as Official right now if official server hoster account
|
||||
m_official = false;
|
||||
xml.get("official", &m_official);
|
||||
|
@ -30,7 +30,9 @@
|
||||
|
||||
#include <irrString.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
class XMLNode;
|
||||
|
||||
@ -86,6 +88,11 @@ protected:
|
||||
bool m_supports_encrytion;
|
||||
|
||||
bool m_game_started;
|
||||
|
||||
std::vector<std::pair</*lower case username*/std::string, std::tuple<
|
||||
/*rank*/int, core::stringw, /*scores*/double, /*playing time*/float
|
||||
> > > m_players;
|
||||
|
||||
public:
|
||||
|
||||
/** Initialises the object from an XML node. */
|
||||
@ -138,5 +145,24 @@ public:
|
||||
bool isOfficial() const { return m_official; }
|
||||
// ------------------------------------------------------------------------
|
||||
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; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool searchByName(const std::string& lower_case_word)
|
||||
{
|
||||
bool server_name_found =
|
||||
m_lower_case_name.find(lower_case_word) != std::string::npos;
|
||||
if (!server_name_found)
|
||||
{
|
||||
for (auto& p : m_players)
|
||||
{
|
||||
if (p.first.find(lower_case_word) != std::string::npos)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return server_name_found;
|
||||
}
|
||||
}; // Server
|
||||
#endif // HEADER_SERVER_HPP
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "network/server.hpp"
|
||||
@ -51,18 +52,7 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr<Server> server)
|
||||
m_self_destroy = false;
|
||||
|
||||
loadFromFile("online/server_info_dialog.stkgui");
|
||||
|
||||
GUIEngine::LabelWidget *name = getWidget<LabelWidget>("server_name");
|
||||
assert(name);
|
||||
name->setText(server->getName(),false);
|
||||
|
||||
core::stringw difficulty = race_manager->getDifficultyName(server->getDifficulty());
|
||||
GUIEngine::LabelWidget *lbldifficulty = getWidget<LabelWidget>("server_difficulty");
|
||||
lbldifficulty->setText(difficulty, false);
|
||||
|
||||
core::stringw mode = NetworkConfig::get()->getModeName(server->getServerMode());
|
||||
GUIEngine::LabelWidget *gamemode = getWidget<LabelWidget>("server_game_mode");
|
||||
gamemode->setText(mode, false);
|
||||
getWidget<LabelWidget>("title")->setText(server->getName(), true);
|
||||
|
||||
m_options_widget = getWidget<RibbonWidget>("options");
|
||||
assert(m_options_widget != NULL);
|
||||
@ -84,6 +74,65 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr<Server> server)
|
||||
getWidget("password")->setVisible(false);
|
||||
}
|
||||
|
||||
auto& players = m_server->getPlayers();
|
||||
core::stringw server_info;
|
||||
core::stringw difficulty = race_manager->getDifficultyName(
|
||||
server->getDifficulty());
|
||||
|
||||
//I18N: In server info dialog
|
||||
core::stringw each_line = _("Difficulty: %s", difficulty);
|
||||
server_info += each_line;
|
||||
server_info += L"\n";
|
||||
|
||||
//I18N: In server info dialog
|
||||
core::stringw mode =
|
||||
NetworkConfig::get()->getModeName(server->getServerMode());
|
||||
each_line = _("Game mode: %s", mode);
|
||||
server_info += each_line;
|
||||
server_info += L"\n";
|
||||
|
||||
if (!players.empty())
|
||||
{
|
||||
// I18N: Show above the player list in server info dialog to
|
||||
// indicate the row meanings
|
||||
ListWidget* player_list = getWidget<ListWidget>("player-list");
|
||||
std::vector<ListWidget::ListCell> row;
|
||||
row.push_back(ListWidget::ListCell(_("Rank"), -1, 1, true));
|
||||
// I18N: Show above the player list in server info dialog, tell
|
||||
// the user name on server
|
||||
row.push_back(ListWidget::ListCell(_("Player"), -1, 2, true));
|
||||
// I18N: Show above the player list in server info dialog, tell
|
||||
// the scores of user calculated by player rankings
|
||||
row.push_back(ListWidget::ListCell(_("Scores"), -1, 1, true));
|
||||
// I18N: Show above the player list in server info dialog, tell
|
||||
// the user time played on server
|
||||
row.push_back(ListWidget::ListCell(_("Time played"),
|
||||
-1, 1, true));
|
||||
player_list->addItem("player", row);
|
||||
for (auto& p : players)
|
||||
{
|
||||
auto& r = p.second;
|
||||
row.clear();
|
||||
row.push_back(ListWidget::ListCell(
|
||||
std::get<0>(r) == -1 ? L"-" :
|
||||
StringUtils::toWString(std::get<0>(r)), -1, 1, true));
|
||||
row.push_back(ListWidget::ListCell(std::get<1>(r), -1,
|
||||
2, true));
|
||||
row.push_back(ListWidget::ListCell(
|
||||
std::get<0>(r) == -1 ? L"-" :
|
||||
StringUtils::toWString(std::get<2>(r)), -1, 1, true));
|
||||
row.push_back(ListWidget::ListCell(
|
||||
StringUtils::toWString(std::get<3>(r)), -1, 1, true));
|
||||
player_list->addItem("player", row);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
getWidget("player-list")->setVisible(false);
|
||||
}
|
||||
getWidget("server-info")->setVisible(true);
|
||||
getWidget<LabelWidget>("server-info")->setText(server_info, true);
|
||||
|
||||
} // ServerInfoDialog
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user