diff --git a/CHANGELOG.md b/CHANGELOG.md index 74bb34340..1d59b56c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ For similar reasons, and because some features are vastly more complex than othe * Several changes or fixes to ensure proper behavior (input, screen-scaling, and more) ### User Interface +* Showing tips for players when loading and after race ends, by dumaosen * Better scaling of many many UI elements to large resolutions, by dumaosen and others * Show country flags for servers and players in online multiplayer, by Benau * Add a new option to change font size on the fly, by Benau and deveee diff --git a/sources.cmake b/sources.cmake index ba4868d71..d4f28ae4d 100644 --- a/sources.cmake +++ b/sources.cmake @@ -1,5 +1,5 @@ # Modify this file to change the last-modified date when you add/remove a file. -# This will then trigger a new cmake run automatically. +# This will then trigger a new cmake run automatically. file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp") file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp") file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*") diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index 64f66e5d6..475490a66 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -1363,8 +1363,12 @@ namespace GUIEngine void renderLoading(bool clearIcons, bool launching, bool update_tips) { #ifndef SERVER_ONLY - if(update_tips) - g_tips_string = _("Tip: ") + TipsManager::get()->getTip("general"); + if (update_tips) + { + //I18N: tip shown in gui for giving player hints + g_tips_string = _("Tip: "); + g_tips_string += TipsManager::get()->getTip("general"); + } if (clearIcons) g_loading_icons.clear(); diff --git a/src/main.cpp b/src/main.cpp index d5512851b..5e16a5f12 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2028,7 +2028,9 @@ int main(int argc, char *argv[]) stk_config->load(file_manager->getAsset("stk_config.xml")); bool no_graphics = !CommandLine::has("--graphical-server"); +#ifndef SERVER_ONLY TipsManager::create(); +#endif // Load current server config first, if any option is specified than // override it later @@ -2453,6 +2455,10 @@ static void cleanSuperTuxKart() if(Online::RequestManager::isRunning()) Online::RequestManager::get()->stopNetworkThread(); +#ifndef SERVER_ONLY + TipsManager::destroy(); +#endif + // Stop music (this request will go into the sfx manager queue, so it needs // to be done before stopping the thread). if (music_manager) diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index 2b92ce562..2158a0b97 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -144,8 +144,10 @@ void RaceResultGUI::init() m_end_track = (int)tracks.size(); } +#ifndef SERVER_ONLY core::stringw tips_string = _("Tip: ") + TipsManager::get()->getTip("race"); MessageQueue::add(MessageQueue::MT_GENERIC, tips_string); +#endif } // init //----------------------------------------------------------------------------- diff --git a/src/tips/tips_manager.cpp b/src/tips/tips_manager.cpp index 514497980..9b8b128e5 100644 --- a/src/tips/tips_manager.cpp +++ b/src/tips/tips_manager.cpp @@ -16,9 +16,12 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef SERVER_ONLY + #include "tips/tips_manager.hpp" #include "io/file_manager.hpp" +#include "io/xml_node.hpp" #include "utils/log.hpp" #include "utils/random_generator.hpp" #include "utils/string_utils.hpp" @@ -36,35 +39,33 @@ TipsManager::TipsManager() const XMLNode *root = file_manager->createXMLTree(file_name); unsigned int num_nodes = root->getNumNodes(); - for(unsigned int i = 0; i < num_nodes; i++) + for (unsigned int i = 0; i < num_nodes; i++) { const XMLNode *node = root->getNode(i); addTipSet(node); } - if(num_nodes != m_all_tip_sets.size()) + if (num_nodes != m_all_tip_sets.size()) + { Log::error("TipsManager", "Multiple tipsets with the same id!"); + } delete root; } // TipsManager -// ---------------------------------------------------------------------------- -TipsManager::~TipsManager() -{ - m_all_tip_sets.clear(); -} // ~TipsManager - // ---------------------------------------------------------------------------- void TipsManager::addTipSet(const XMLNode *input) { std::string id; - if(!input->get("id", &id)) + if (!input->get("id", &id)) + { Log::error("TipSet", "Undefined id for tipset."); + } - for(unsigned int n = 0; n < input->getNumNodes(); n++) + for (unsigned int n = 0; n < input->getNumNodes(); n++) { const XMLNode *node = input->getNode(n); if (node->getName() != "tip") @@ -77,14 +78,26 @@ void TipsManager::addTipSet(const XMLNode *input) // Gettext is used here m_all_tip_sets[id].push_back(_(text.c_str())); } - if(m_all_tip_sets[id].size() != input->getNumNodes()) + if (m_all_tip_sets[id].size() != input->getNumNodes()) + { Log::error("TipSet", - "Incorrect tips for the entries of tipset \"%s\".", id.c_str()); + "Incorrect tips for the entries of tipset \"%s\".", id.c_str()); + } } // ---------------------------------------------------------------------------- -irr::core::stringw TipsManager::getTip(std::string id) +const irr::core::stringw& TipsManager::getTip(const std::string& id) const { + auto ret = m_all_tip_sets.find(id); + if (ret == m_all_tip_sets.end()) + { + // Should not happen + static core::stringw empty; + return empty; + } RandomGenerator randgen; - return m_all_tip_sets[id][randgen.get(m_all_tip_sets[id].size())]; + unsigned pos = randgen.get(ret->second.size()); + return ret->second.at(pos); } // getTipSet + +#endif diff --git a/src/tips/tips_manager.hpp b/src/tips/tips_manager.hpp index da53943af..cdfb1ee47 100644 --- a/src/tips/tips_manager.hpp +++ b/src/tips/tips_manager.hpp @@ -15,11 +15,12 @@ // 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 SERVER_ONLY #ifndef HEADER_TIPS_MANAGER_HPP #define HEADER_TIPS_MANAGER_HPP -#include "io/xml_node.hpp" +class XMLNode; #include #include @@ -42,7 +43,6 @@ private: std::map m_all_tip_sets; TipsManager (); - ~TipsManager (); void addTipSet(const XMLNode *input); @@ -68,8 +68,9 @@ public: } // destroy // ======================================================================== /** Get a tip by ID. */ - irr::core::stringw getTip(std::string id); + const irr::core::stringw& getTip(const std::string& id) const; // ------------------------------------------------------------------------ }; // class TipsManager -#endif \ No newline at end of file +#endif +#endif