Author: mordante
Date: Sat Oct 16 21:53:29 2010
New Revision: 47062
URL: http://svn.gna.org/viewcvs/wesnoth?rev=47062&view=rev
Log:
Implement the unit filter in the tips of day.
Don't implement the count yet, want to discuss it with alink first
whether really wanted, or needed.
Modified:
trunk/src/gui/auxiliary/tips.cpp
trunk/src/gui/auxiliary/tips.hpp
Modified: trunk/src/gui/auxiliary/tips.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/tips.cpp?rev=47062&r1=47061&r2=47062&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/tips.cpp (original)
+++ trunk/src/gui/auxiliary/tips.cpp Sat Oct 16 21:53:29 2010
@@ -19,34 +19,54 @@
#include "config.hpp"
#include "foreach.hpp"
+#include "game_preferences.hpp"
+#include "serialization/string_utils.cpp"
namespace gui2 {
-ttip::ttip(const t_string& text, const t_string& source)
+ttip::ttip(const t_string& text
+ , const t_string& source
+ , const std::string& unit_filter)
: text_(text)
, source_(source)
+ , unit_filter_(utils::split(unit_filter))
{
}
namespace tips {
-
-/** @todo Implement the filtering of the tips. */
std::vector<ttip> load(const config& cfg)
{
std::vector<ttip> result;
foreach(const config &tip, cfg.child_range("tip")) {
- result.push_back(ttip(tip["text"], tip["source"]));
+ result.push_back(ttip(tip["text"]
+ , tip["source"]
+ , tip["encountered_units"]));
}
return result;
}
-/** @todo Implement the filtering of the tips. */
std::vector<ttip> shuffle(const std::vector<ttip>& tips)
{
- std::vector<ttip> result = tips;
+ std::vector<ttip> result;
+
+ const std::set<std::string>& units = preferences::encountered_units();
+
+ foreach(const ttip& tip, tips) {
+ if(tip.unit_filter_.empty()) {
+ result.push_back(tip);
+ } else {
+ foreach(const std::string& unit, tip.unit_filter_) {
+ if(units.find(unit) != units.end()) {
+ result.push_back(tip);
+ break;
+ }
+ }
+ }
+ }
+
std::random_shuffle(result.begin(), result.end());
return result;
}
Modified: trunk/src/gui/auxiliary/tips.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/tips.hpp?rev=47062&r1=47061&r2=47062&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/tips.hpp (original)
+++ trunk/src/gui/auxiliary/tips.hpp Sat Oct 16 21:53:29 2010
@@ -60,10 +60,25 @@
private:
friend std::vector<ttip> tips::load(const config&);
- ttip(const t_string& text, const t_string& source);
+ friend std::vector<ttip> tips::shuffle(const std::vector<ttip>& tips);
+ ttip(const t_string& text
+ , const t_string& source
+ , const std::string& unit_filter);
+ /** The text of the tip. */
t_string text_;
+
+ /** The source of the tip. */
t_string source_;
+
+ /**
+ * List of units to filter the tip upon.
+ *
+ * If the list is empty the tip is shown.
+ * Else the unit must have encountered at least one of the units in the
+ * list.
+ */
+ std::vector<std::string> unit_filter_;
};
} // namespace gui2
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits