From a50177c96ac7422b7b8e635725fd4a27fe6bd03f Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 16 Jun 2014 17:16:36 +1000 Subject: [PATCH] Removed messages.?pp files (and used the strings directly where they are needed). --- src/online/messages.cpp | 109 ------------------ src/online/messages.hpp | 49 -------- src/states_screens/create_server_screen.cpp | 4 +- .../dialogs/change_password_dialog.cpp | 4 +- .../dialogs/recovery_dialog.cpp | 4 +- .../dialogs/registration_dialog.cpp | 1 - .../dialogs/server_info_dialog.cpp | 4 +- .../dialogs/user_info_dialog.cpp | 4 +- src/states_screens/dialogs/vote_dialog.cpp | 9 +- .../online_profile_achievements.cpp | 7 +- src/states_screens/online_profile_friends.cpp | 6 +- src/states_screens/online_screen.cpp | 7 +- src/states_screens/online_user_search.cpp | 6 +- src/states_screens/register_screen.cpp | 4 +- src/states_screens/server_selection.cpp | 7 +- src/states_screens/user_screen.cpp | 5 +- src/utils/string_utils.cpp | 24 ++++ src/utils/string_utils.hpp | 2 + 18 files changed, 61 insertions(+), 195 deletions(-) delete mode 100644 src/online/messages.cpp delete mode 100644 src/online/messages.hpp diff --git a/src/online/messages.cpp b/src/online/messages.cpp deleted file mode 100644 index 9bdfce9b9..000000000 --- a/src/online/messages.cpp +++ /dev/null @@ -1,109 +0,0 @@ -// -// 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. - -#include "online/messages.hpp" -#include "utils/translation.hpp" -#include "utils/time.hpp" - -namespace Online -{ - namespace Messages - { - irr::core::stringw signingIn() - { - return irr::core::stringw(_("Signing in")) + loadingDots(); - } - // ------------------------------------------------------------------------ - - irr::core::stringw signingOut() - { - return irr::core::stringw(_("Signing out")) + loadingDots(); - } - // ------------------------------------------------------------------------ - irr::core::stringw validatingInfo() - { - return irr::core::stringw(_("Validating info")) + loadingDots(); - } - // ------------------------------------------------------------------------ - irr::core::stringw searching() - { - return irr::core::stringw(_("Searching")) + loadingDots(); - } - // ------------------------------------------------------------------------ - - irr::core::stringw joiningServer() - { - return irr::core::stringw(_("Joining server")) + loadingDots(); - } - // ------------------------------------------------------------------------ - - irr::core::stringw creatingServer() - { - return irr::core::stringw(_("Creating server")) + loadingDots(); - } - - // ------------------------------------------------------------------------ - - irr::core::stringw fetchingServers() - { - return irr::core::stringw(_("Fetching servers")) + loadingDots(); - } - - // ------------------------------------------------------------------------ - - irr::core::stringw fetchingFriends() - { - return irr::core::stringw(_("Fetching friends")) + loadingDots(); - } - - // ------------------------------------------------------------------------ - - irr::core::stringw fetchingAchievements() - { - return irr::core::stringw(_("Fetching achievements")) + loadingDots(); - } - - // ------------------------------------------------------------------------ - - irr::core::stringw processing() - { - return irr::core::stringw(_("Processing")) + loadingDots(); - } - - // ------------------------------------------------------------------------ - /** Convenience function to type less in calls. */ - irr::core::stringw loadingDots(const wchar_t *s) - { - return irr::core::stringw(s)+loadingDots(); - } - // ------------------------------------------------------------------------ - /** - * Shows a increasing number of dots. - * \param interval A float representing the time it takes to add a new dot - * \param max_dots The number of dots used. Defaults to 3. - */ - irr::core::stringw loadingDots(float interval, int max_dots) - { - int nr_dots = int(floor(StkTime::getRealTime() / interval)) % (max_dots+1); - return irr::core::stringw((std::string(nr_dots,'.') + std::string(max_dots-nr_dots,' ')).c_str()); - } - } // namespace messages -} // namespace Online - - -/* EOF */ diff --git a/src/online/messages.hpp b/src/online/messages.hpp deleted file mode 100644 index 9349caf91..000000000 --- a/src/online/messages.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// -// 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_MESSAGES_HPP -#define HEADER_ONLINE_MESSAGES_HPP - -#include -#include - -namespace Online -{ - /** - * \brief Messages to be shown related to API communication - * \ingroup online - */ - namespace Messages - { - irr::core::stringw loadingDots (float interval = 0.5f, int max_dots = 3); - irr::core::stringw loadingDots (const wchar_t *s); - irr::core::stringw signingIn (); - irr::core::stringw signingOut (); - irr::core::stringw validatingInfo (); - irr::core::stringw searching (); - irr::core::stringw joiningServer (); - irr::core::stringw creatingServer (); - irr::core::stringw fetchingServers (); - irr::core::stringw fetchingFriends (); - irr::core::stringw fetchingAchievements (); - irr::core::stringw processing (); - } // namespace Messages -}// namespace Online -#endif - -/* EOF */ diff --git a/src/states_screens/create_server_screen.cpp b/src/states_screens/create_server_screen.cpp index cf3f49fd4..7189302e7 100644 --- a/src/states_screens/create_server_screen.cpp +++ b/src/states_screens/create_server_screen.cpp @@ -24,7 +24,6 @@ #include "config/player_manager.hpp" #include "modes/demo_world.hpp" #include "online/servers_manager.hpp" -#include "online/messages.hpp" #include "states_screens/online_screen.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/dialogs/message_dialog.hpp" @@ -115,7 +114,8 @@ void CreateServerScreen::onUpdate(float delta) else { m_info_widget->setDefaultColor(); - m_info_widget->setText(Online::Messages::creatingServer(), false); + m_info_widget->setText(StringUtils::loadingDots(_("Creating server")), + false); } } } // onUpdate diff --git a/src/states_screens/dialogs/change_password_dialog.cpp b/src/states_screens/dialogs/change_password_dialog.cpp index 632414d19..16aaf3b63 100644 --- a/src/states_screens/dialogs/change_password_dialog.cpp +++ b/src/states_screens/dialogs/change_password_dialog.cpp @@ -21,7 +21,6 @@ #include "config/player_manager.hpp" #include "guiengine/engine.hpp" #include "guiengine/widgets.hpp" -#include "online/messages.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" @@ -227,7 +226,8 @@ void ChangePasswordDialog::error(const irr::core::stringw & error) void ChangePasswordDialog::onUpdate(float dt) { if(!m_options_widget->isActivated()) - m_info_widget->setText(Online::Messages::validatingInfo(), false); + m_info_widget->setText(StringUtils::loadingDots(_("Validating info")), + false ); // It's unsafe to delete from inside the event handler so we do it here if (m_self_destroy) diff --git a/src/states_screens/dialogs/recovery_dialog.cpp b/src/states_screens/dialogs/recovery_dialog.cpp index 7d396e3d5..b8ba2d12b 100644 --- a/src/states_screens/dialogs/recovery_dialog.cpp +++ b/src/states_screens/dialogs/recovery_dialog.cpp @@ -20,7 +20,6 @@ #include "audio/sfx_manager.hpp" #include "config/player_manager.hpp" #include "guiengine/engine.hpp" -#include "online/messages.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" @@ -200,7 +199,8 @@ void RecoveryDialog::onUpdate(float dt) } else { - m_info_widget->setText(Messages::validatingInfo(), false); + m_info_widget->setText(StringUtils::loadingDots(_("Validating info")), + false); } } // It's unsafe to delete from inside the event handler so we do it here diff --git a/src/states_screens/dialogs/registration_dialog.cpp b/src/states_screens/dialogs/registration_dialog.cpp index 2ebfbdc95..61533f9ff 100644 --- a/src/states_screens/dialogs/registration_dialog.cpp +++ b/src/states_screens/dialogs/registration_dialog.cpp @@ -24,7 +24,6 @@ #include "states_screens/register_screen.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" -#include "online/messages.hpp" #include diff --git a/src/states_screens/dialogs/server_info_dialog.cpp b/src/states_screens/dialogs/server_info_dialog.cpp index 0dbe551a4..3887ca1b9 100644 --- a/src/states_screens/dialogs/server_info_dialog.cpp +++ b/src/states_screens/dialogs/server_info_dialog.cpp @@ -21,7 +21,6 @@ #include "guiengine/engine.hpp" #include "network/protocol_manager.hpp" #include "network/protocols/connect_to_server.hpp" -#include "online/messages.hpp" #include "online/servers_manager.hpp" #include "states_screens/dialogs/registration_dialog.hpp" #include "states_screens/networking_lobby.hpp" @@ -152,7 +151,8 @@ void ServerInfoDialog::onUpdate(float dt) else { m_info_widget->setDefaultColor(); - m_info_widget->setText(Online::Messages::joiningServer(), false); + m_info_widget->setText(StringUtils::loadingDots(_("Joining server")), + false); } } diff --git a/src/states_screens/dialogs/user_info_dialog.cpp b/src/states_screens/dialogs/user_info_dialog.cpp index 22a937561..71ec898fa 100644 --- a/src/states_screens/dialogs/user_info_dialog.cpp +++ b/src/states_screens/dialogs/user_info_dialog.cpp @@ -22,7 +22,6 @@ #include "guiengine/dialog_queue.hpp" #include "guiengine/engine.hpp" #include "online/online_profile.hpp" -#include "online/messages.hpp" #include "states_screens/online_profile_friends.hpp" #include "states_screens/online_profile_overview.hpp" #include "states_screens/state_manager.hpp" @@ -453,7 +452,8 @@ bool UserInfoDialog::onEscapePressed() void UserInfoDialog::onUpdate(float dt) { - if(m_processing) m_info_widget->setText(Messages::processing(), false); + if(m_processing) + m_info_widget->setText(StringUtils::loadingDots(_("Processing")), false); //If we want to open the registration dialog, we need to close this one first if (m_enter_profile) m_self_destroy = true; diff --git a/src/states_screens/dialogs/vote_dialog.cpp b/src/states_screens/dialogs/vote_dialog.cpp index f0efb36de..8fb5895d6 100644 --- a/src/states_screens/dialogs/vote_dialog.cpp +++ b/src/states_screens/dialogs/vote_dialog.cpp @@ -21,7 +21,6 @@ #include "audio/sfx_manager.hpp" #include "config/player_manager.hpp" #include "guiengine/engine.hpp" -#include "online/messages.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" @@ -164,8 +163,8 @@ void VoteDialog::updateFetchVote() if (!m_fetch_vote_request->isDone()) { // request still pending - m_info_widget->setText(irr::core::stringw(_("Fetching last vote")) - + Messages::loadingDots(), false); + m_info_widget->setText(StringUtils::loadingDots(_("Fetching last vote")), + false ); return; } // !isDone @@ -236,8 +235,8 @@ void VoteDialog::onUpdate(float dt) } // isDone else { - m_info_widget->setText(irr::core::stringw(_("Performing vote")) - + Messages::loadingDots(), false); + m_info_widget->setText(StringUtils::loadingDots(_("Performing vote")), + false); } // !isDone } diff --git a/src/states_screens/online_profile_achievements.cpp b/src/states_screens/online_profile_achievements.cpp index 44c89b3ee..07e0c4bb3 100644 --- a/src/states_screens/online_profile_achievements.cpp +++ b/src/states_screens/online_profile_achievements.cpp @@ -24,7 +24,6 @@ #include "guiengine/scalable_font.hpp" #include "guiengine/screen.hpp" #include "guiengine/widget.hpp" -#include "online/messages.hpp" #include "online/online_profile.hpp" #include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/state_manager.hpp" @@ -122,7 +121,7 @@ void OnlineProfileAchievements::init() m_visiting_profile->fetchAchievements(); m_achievements_list_widget->clear(); m_achievements_list_widget->addItem("loading", - Messages::fetchingAchievements()); + StringUtils::loadingDots(_("Fetching achievements"))); } } // init @@ -161,8 +160,8 @@ void OnlineProfileAchievements::onUpdate(float delta) if (!m_visiting_profile->isReady()) { // This will display an increasing number of dots while waiting. - m_achievements_list_widget->renameItem("loading", - Messages::fetchingAchievements()); + m_achievements_list_widget->renameItem("loading", + StringUtils::loadingDots(_("Fetching achievements"))); return; } diff --git a/src/states_screens/online_profile_friends.cpp b/src/states_screens/online_profile_friends.cpp index 4ffe2c1f3..c925ce85c 100644 --- a/src/states_screens/online_profile_friends.cpp +++ b/src/states_screens/online_profile_friends.cpp @@ -21,7 +21,6 @@ #include "guiengine/scalable_font.hpp" #include "guiengine/screen.hpp" #include "guiengine/widget.hpp" -#include "online/messages.hpp" #include "states_screens/dialogs/user_info_dialog.hpp" #include "states_screens/online_user_search.hpp" #include "states_screens/state_manager.hpp" @@ -85,7 +84,8 @@ void OnlineProfileFriends::init() m_visiting_profile->fetchFriends(); m_waiting_for_friends = true; m_friends_list_widget->clear(); - m_friends_list_widget->addItem("loading", Messages::fetchingFriends()); + m_friends_list_widget->addItem("loading", + StringUtils::loadingDots(_("Fetching friends"))); } // init // ----------------------------------------------------------------------------- @@ -171,7 +171,7 @@ void OnlineProfileFriends::onUpdate(float delta) else { m_friends_list_widget->renameItem("loading", - Messages::fetchingFriends()); + StringUtils::loadingDots(_("Fetching friends"))); } } } // onUpdate diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp index 2423d3ce8..bcfc746e0 100644 --- a/src/states_screens/online_screen.cpp +++ b/src/states_screens/online_screen.cpp @@ -32,7 +32,6 @@ #include "network/protocol_manager.hpp" #include "network/protocols/connect_to_server.hpp" #include "network/protocols/request_connection.hpp" -#include "online/messages.hpp" #include "online/profile_manager.hpp" #include "online/request.hpp" #include "online/servers_manager.hpp" @@ -153,11 +152,13 @@ void OnlineScreen::onUpdate(float delta) if (m_recorded_state == PlayerProfile::OS_SIGNING_IN) { - m_online_status_widget->setText(Messages::signingIn(), false); + m_online_status_widget->setText(StringUtils::loadingDots(_("Signing in")), + false ); } else if (m_recorded_state == PlayerProfile::OS_SIGNING_OUT) { - m_online_status_widget->setText(Messages::signingOut(), false); + m_online_status_widget->setText(StringUtils::loadingDots(_("Signing out")), + false ); } } // onUpdate diff --git a/src/states_screens/online_user_search.cpp b/src/states_screens/online_user_search.cpp index c24cc1959..71bc6ba3b 100644 --- a/src/states_screens/online_user_search.cpp +++ b/src/states_screens/online_user_search.cpp @@ -20,7 +20,6 @@ #include "audio/sfx_manager.hpp" #include "config/player_manager.hpp" #include "guiengine/modaldialog.hpp" -#include "online/messages.hpp" #include "online/profile_manager.hpp" #include "states_screens/dialogs/user_info_dialog.hpp" #include "states_screens/dialogs/message_dialog.hpp" @@ -199,7 +198,7 @@ void OnlineUserSearch::search() m_user_list_widget->clear(); m_user_list_widget->addItem("spacer", L""); - m_user_list_widget->addItem("loading", Messages::searching()); + m_user_list_widget->addItem("loading", StringUtils::loadingDots(_("Searching"))); m_back_widget->setDeactivated(); m_search_box_widget->setDeactivated(); m_search_button_widget->setDeactivated(); @@ -276,7 +275,8 @@ void OnlineUserSearch::onUpdate(float dt) } else { - m_user_list_widget->renameItem("loading", Messages::searching()); + m_user_list_widget->renameItem("loading", + StringUtils::loadingDots(_("Searching")) ); } } } // onUpdate diff --git a/src/states_screens/register_screen.cpp b/src/states_screens/register_screen.cpp index 30b634fdb..941943dfa 100644 --- a/src/states_screens/register_screen.cpp +++ b/src/states_screens/register_screen.cpp @@ -24,7 +24,6 @@ #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/text_box_widget.hpp" -#include "online/messages.hpp" #include "online/xml_request.hpp" #include "states_screens/dialogs/registration_dialog.hpp" #include "states_screens/dialogs/message_dialog.hpp" @@ -286,7 +285,8 @@ void RegisterScreen::onUpdate(float dt) if(m_signup_request) { if(!m_options_widget->isActivated()) - m_info_widget->setText(Messages::validatingInfo(), false); + m_info_widget->setText(StringUtils::loadingDots(_("Validating info")), + false); if(m_signup_request->isDone()) { diff --git a/src/states_screens/server_selection.cpp b/src/states_screens/server_selection.cpp index 985e26dea..08bd94c97 100644 --- a/src/states_screens/server_selection.cpp +++ b/src/states_screens/server_selection.cpp @@ -26,7 +26,6 @@ #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" -#include "online/messages.hpp" #include "audio/sfx_manager.hpp" using namespace Online; @@ -64,7 +63,8 @@ void ServerSelection::refresh() m_fake_refresh = (m_refresh_request == NULL ? true : false); m_server_list_widget->clear(); m_server_list_widget->addItem("spacer", L""); - m_server_list_widget->addItem("loading", Messages::fetchingServers()); + m_server_list_widget->addItem("loading", + StringUtils::loadingDots(_("Fetching servers"))); m_reload_widget->setDeactivated(); } @@ -206,7 +206,8 @@ void ServerSelection::onUpdate(float dt) } else { - m_server_list_widget->renameItem("loading", Messages::fetchingServers()); + m_server_list_widget->renameItem("loading", + StringUtils::loadingDots(_("Fetching servers"))); } } else if(m_fake_refresh) diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index 266d73db6..de5b1fa72 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -26,7 +26,6 @@ #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/list_widget.hpp" #include "guiengine/widgets/text_box_widget.hpp" -#include "online/messages.hpp" #include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/options_screen_audio.hpp" @@ -395,8 +394,8 @@ void BaseUserScreen::onUpdate(float dt) core::stringw message = (m_state & STATE_LOGOUT) ? _(L"Signing out '%s'",m_sign_out_name.c_str()) : _(L"Signing in '%s'", m_sign_in_name.c_str()); - m_info_widget->setText(Online::Messages::loadingDots(message.c_str()), - false ); + m_info_widget->setText(StringUtils::loadingDots(message.c_str()), + false ); } PlayerProfile *player = getSelectedPlayer(); if(player) diff --git a/src/utils/string_utils.cpp b/src/utils/string_utils.cpp index 8c61bc40b..734dcdce9 100644 --- a/src/utils/string_utils.cpp +++ b/src/utils/string_utils.cpp @@ -21,6 +21,7 @@ #include "utils/string_utils.hpp" #include "utils/log.hpp" +#include "utils/time.hpp" #include "coreutil.h" @@ -523,6 +524,29 @@ namespace StringUtils return std::string(s); } // timeToString + // ------------------------------------------------------------------------ + /** Shows a increasing number of dots. + * \param interval A float representing the time it takes to add a new dot + * \param max_dots The number of dots used. Defaults to 3. + */ + irr::core::stringw loadingDots(float interval, int max_dots) + { + int nr_dots = int(floor(StkTime::getRealTime() / interval)) + % (max_dots + 1); + return irr::core::stringw((std::string(nr_dots, '.') + + std::string(max_dots - nr_dots, ' ')).c_str()); + } // loadingDots + + // ------------------------------------------------------------------------ + /** Returns the string given with loadingDots appended. A simple + * convenience function to type less in calls. + * \parameter s The string to which the loading dots are appended. + */ + irr::core::stringw loadingDots(const wchar_t *s) + { + return irr::core::stringw(s) + loadingDots(); + } // loadingDots + // ------------------------------------------------------------------------ /** Replaces values in a string. * \param other string in which to replace stuff diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index b1e70eeec..19d9f3fe5 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -46,6 +46,8 @@ namespace StringUtils bool notEmpty(const irr::core::stringw& input); std::string timeToString(float time); + irr::core::stringw loadingDots(float interval = 0.5f, int max_dots = 3); + irr::core::stringw loadingDots(const wchar_t *s); std::string toUpperCase(const std::string&); std::string toLowerCase(const std::string&); std::vector split(const std::string& s, char c,