Add server location to dialog

This commit is contained in:
Benau 2019-05-14 15:16:21 +08:00
parent b9f82ebdf0
commit 206a3d8aec
4 changed files with 29 additions and 4 deletions

View File

@ -3,7 +3,11 @@
<div x="2%" y="0%" width="96%" height="100%" layout="vertical-row" > <div x="2%" y="0%" width="96%" height="100%" layout="vertical-row" >
<header id="title" width="96%" proportion="4" text_align="center" word_wrap="true"/> <header id="title" width="96%" proportion="4" text_align="center" word_wrap="true"/>
<spacer height="1%" width="5"/> <spacer height="1%" width="5"/>
<label id="server-info" width="90%" proportion="4" align="left" text_align="left" text=""/> <div width="90%" height="fit" layout="horizontal-row">
<label id="server-info-1" align="top" proportion="2" text_align="left" word_wrap="true" text=""/>
<label id="server-info-2" align="top" proportion="2" text_align="left" word_wrap="true" text=""/>
</div>
<spacer height="1%"/> <spacer height="1%"/>
<box x="0%" width="90%" proportion="12" align="center" layout="vertical-row"> <box x="0%" width="90%" proportion="12" align="center" layout="vertical-row">
<list id="player-list" x="0" y="0" width="100%" height="100%" <list id="player-list" x="0" y="0" width="100%" height="100%"

View File

@ -67,6 +67,7 @@ Server::Server(const XMLNode& server_info) : m_supports_encrytion(true)
xml.get("password", &m_password_protected); xml.get("password", &m_password_protected);
xml.get("game_started", &m_game_started); xml.get("game_started", &m_game_started);
xml.get("distance", &m_distance); xml.get("distance", &m_distance);
xml.get("country_code", &m_country_code);
m_server_owner_name = L"-"; m_server_owner_name = L"-";
m_server_owner_lower_case_name = "-"; m_server_owner_lower_case_name = "-";

View File

@ -97,6 +97,8 @@ protected:
> > m_players; > > m_players;
std::string m_current_track; std::string m_current_track;
std::string m_country_code;
public: public:
/** Initialises the object from an XML node. */ /** Initialises the object from an XML node. */
@ -174,5 +176,7 @@ public:
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
Track* getCurrentTrack() const; Track* getCurrentTrack() const;
// ------------------------------------------------------------------------
const std::string& getCountryCode() const { return m_country_code; }
}; // Server }; // Server
#endif // HEADER_SERVER_HPP #endif // HEADER_SERVER_HPP

View File

@ -101,6 +101,25 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr<Server> server)
server_info += each_line; server_info += each_line;
server_info += L"\n"; server_info += L"\n";
} }
getWidget("server-info-1")->setVisible(true);
getWidget<LabelWidget>("server-info-1")->setText(server_info, true);
server_info = L"";
each_line = L"";
#ifndef SERVER_ONLY
if (!server->getCountryCode().empty())
{
core::stringw country_name =
translations->getLocalizedCountryName(server->getCountryCode());
//I18N: In the server info dialog, show the server location with
//country name (based on IP geolocation)
each_line = _("Server location: %s", country_name);
server_info += each_line;
server_info += L"\n";
}
#endif
getWidget("server-info-2")->setVisible(true);
getWidget<LabelWidget>("server-info-2")->setText(server_info, true);
if (!players.empty()) if (!players.empty())
{ {
@ -140,9 +159,6 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr<Server> server)
{ {
getWidget("player-list")->setVisible(false); getWidget("player-list")->setVisible(false);
} }
getWidget("server-info")->setVisible(true);
getWidget<LabelWidget>("server-info")->setText(server_info, true);
} // ServerInfoDialog } // ServerInfoDialog
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------