Add current track info to server screen

This commit is contained in:
Benau 2019-01-04 18:53:45 +08:00
parent 4b22465836
commit 72db382c76
3 changed files with 44 additions and 10 deletions

View File

@ -4,6 +4,7 @@
<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=""/>
<spacer height="10"/>
<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>

View File

@ -28,6 +28,7 @@
#include "network/stk_host.hpp"
#include "states_screens/online/networking_lobby.hpp"
#include "states_screens/state_manager.hpp"
#include "tracks/track.hpp"
#include "utils/string_utils.hpp"
#include <IGUIEnvironment.h>
@ -79,17 +80,28 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr<Server> server)
core::stringw difficulty = race_manager->getDifficultyName(
server->getDifficulty());
//I18N: In server info dialog
core::stringw each_line = _("Difficulty: %s", difficulty);
//I18N: In server info dialog
server_info += each_line;
server_info += L"\n";
//I18N: In server info dialog
core::stringw mode = ServerConfig::getModeName(server->getServerMode());
//I18N: In server info dialog
each_line = _("Game mode: %s", mode);
server_info += each_line;
server_info += L"\n";
Track* t = server->getCurrentTrack();
if (t)
{
core::stringw track_name = t->getName();
//I18N: In server info dialog, showing the current track playing in
//server
each_line = _("Current track: %s", track_name);
server_info += each_line;
server_info += L"\n";
}
if (!players.empty())
{
// I18N: Show above the player list in server info dialog to

View File

@ -32,6 +32,8 @@
#include "states_screens/dialogs/message_dialog.hpp"
#include "states_screens/dialogs/server_info_dialog.hpp"
#include "states_screens/state_manager.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
@ -102,12 +104,6 @@ void ServerSelection::loadedFromFile()
assert(m_searcher != NULL);
m_game_started->setState(false);
m_icon_bank = new irr::gui::STKModifiedSpriteBank(GUIEngine::getGUIEnv());
video::ITexture* icon1 = irr_driver->getTexture(
file_manager->getAsset(FileManager::GUI_ICON, "green_check.png"));
video::ITexture* icon2 = irr_driver->getTexture(
file_manager->getAsset(FileManager::GUI_ICON, "hourglass.png"));
m_icon_bank->addTextureAsSprite(icon1);
m_icon_bank->addTextureAsSprite(icon2);
} // loadedFromFile
// ----------------------------------------------------------------------------
@ -115,6 +111,7 @@ void ServerSelection::loadedFromFile()
*/
void ServerSelection::beforeAddingWidget()
{
m_icon_bank->clear();
m_server_list_widget->clearColumns();
m_server_list_widget->addColumn( _C("column_name", "Name"), 7);
m_server_list_widget->addColumn(_C("column_name", "Game mode"), 3);
@ -139,7 +136,28 @@ void ServerSelection::init()
m_current_column = 5/*distance*/;
m_searcher->clearListeners();
m_searcher->addListener(this);
m_icon_bank->setScale((float)getHeight() / 15.0f / 128.0f);
m_icon_bank->setTargetIconSize(128, 128);
video::ITexture* icon1 = irr_driver->getTexture(
file_manager->getAsset(FileManager::GUI_ICON, "green_check.png"));
video::ITexture* icon2 = irr_driver->getTexture(
file_manager->getAsset(FileManager::GUI_ICON, "hourglass.png"));
m_icon_bank->addTextureAsSprite(icon1);
m_icon_bank->addTextureAsSprite(icon2);
for (unsigned i = 0; i < track_manager->getNumberOfTracks(); i++)
{
Track* t = track_manager->getTrack(i);
video::ITexture* tex =irr_driver->getTexture(t->getScreenshotFile());
if (!tex)
{
tex = irr_driver->getTexture(file_manager
->getAsset(FileManager::GUI_ICON, "main_help.png"));
}
assert(tex);
m_icon_bank->addTextureAsSprite(tex);
}
int row_height = UserConfigParams::m_hidpi_enabled ? getHeight() / 12.0f
: getHeight() / 15.0f;
@ -190,7 +208,10 @@ void ServerSelection::loadList()
});
for (auto& server : m_servers)
{
const int icon = server->isGameStarted() ? 1 : 0;
int icon = server->isGameStarted() ? 1 : 0;
Track* t = server->getCurrentTrack();
if (t)
icon = track_manager->getTrackIndexByIdent(t->getIdent()) + 2;
core::stringw num_players;
num_players.append(StringUtils::toWString(server->getCurrentPlayers()));
num_players.append("/");