Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "gui/auxiliary/tips.hpp"
00019
00020 #include "config.hpp"
00021 #include "foreach.hpp"
00022 #include "game_preferences.hpp"
00023 #include "serialization/string_utils.hpp"
00024
00025 namespace gui2 {
00026
00027 ttip::ttip(const t_string& text
00028 , const t_string& source
00029 , const std::string& unit_filter)
00030 : text_(text)
00031 , source_(source)
00032 , unit_filter_(utils::split(unit_filter))
00033 {
00034 }
00035
00036 namespace tips {
00037
00038 std::vector<ttip> load(const config& cfg)
00039 {
00040 std::vector<ttip> result;
00041
00042 foreach(const config &tip, cfg.child_range("tip")) {
00043 result.push_back(ttip(tip["text"]
00044 , tip["source"]
00045 , tip["encountered_units"]));
00046 }
00047
00048 return result;
00049 }
00050
00051 std::vector<ttip> shuffle(const std::vector<ttip>& tips)
00052 {
00053 std::vector<ttip> result;
00054
00055 const std::set<std::string>& units = preferences::encountered_units();
00056
00057 foreach(const ttip& tip, tips) {
00058 if(tip.unit_filter_.empty()) {
00059 result.push_back(tip);
00060 } else {
00061 foreach(const std::string& unit, tip.unit_filter_) {
00062 if(units.find(unit) != units.end()) {
00063 result.push_back(tip);
00064 break;
00065 }
00066 }
00067 }
00068 }
00069
00070 std::random_shuffle(result.begin(), result.end());
00071 return result;
00072 }
00073
00074 }
00075
00076 }