Clear up tips manager

This commit is contained in:
Benau 2019-12-18 12:52:45 +08:00
parent ad8ef2df11
commit 4d0952c716
7 changed files with 48 additions and 21 deletions

View File

@ -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

View File

@ -1364,7 +1364,11 @@ namespace GUIEngine
{
#ifndef SERVER_ONLY
if (update_tips)
g_tips_string = _("Tip: ") + TipsManager::get()->getTip("general");
{
//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();

View File

@ -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)

View File

@ -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
//-----------------------------------------------------------------------------

View File

@ -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"
@ -43,26 +46,24 @@ TipsManager::TipsManager()
}
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))
{
Log::error("TipSet",
"Undefined id for tipset.");
}
for (unsigned int n = 0; n < input->getNumNodes(); n++)
{
@ -78,13 +79,25 @@ void TipsManager::addTipSet(const XMLNode *input)
m_all_tip_sets[id].push_back(_(text.c_str()));
}
if (m_all_tip_sets[id].size() != input->getNumNodes())
{
Log::error("TipSet",
"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

View File

@ -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 <assert.h>
#include <irrString.h>
@ -42,7 +43,6 @@ private:
std::map<std::string, TipSet> 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
#endif