The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tips.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2017 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "tstring.hpp"
18 
19 #include <vector>
20 
21 class config;
22 
23 namespace gui2
24 {
25 class game_tip;
26 
27 namespace tip_of_the_day
28 {
29 /**
30  * Loads the tips from a config.
31  *
32  * @param cfg A config with the tips.
33  *
34  * @returns The loaded tips.
35  */
36 std::vector<game_tip> load(const config& cfg);
37 
38 /**
39  * Shuffles the tips.
40  *
41  * This routine shuffles the tips and filters out the unwanted ones.
42  *
43  * @param tips The tips.
44  *
45  * @returns The filtered tips in random order.
46  */
47 std::vector<game_tip> shuffle(const std::vector<game_tip>& tips);
48 
49 } // namespace tip_of_the_day
50 
51 /** The tips of day structure. */
52 class game_tip
53 {
54 public:
56 
57  const t_string& text() const
58  {
59  return text_;
60  }
61 
62  const t_string& source() const
63  {
64  return source_;
65  }
66 
67 private:
68  friend std::vector<game_tip> tip_of_the_day::load(const config&);
69  friend std::vector<game_tip> tip_of_the_day::shuffle(const std::vector<game_tip>& tips);
70 
71  /** The text of the tip. */
73 
74  /** The source of the tip. */
76 
77  /**
78  * List of units to filter the tip upon.
79  *
80  * If the list is empty the tip is shown.
81  * Else the unit must have encountered at least one of the units in the list.
82  */
83  std::vector<std::string> unit_filter_;
84 };
85 
86 } // namespace gui2
std::vector< char_t > string
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
Definition: tips.cpp:35
static std::vector< game_tip > tips
Definition: settings.cpp:60
t_string source_
The source of the tip.
Definition: tips.hpp:75
Generic file dialog.
Definition: text.hpp:37
const t_string & source() const
Definition: tips.hpp:62
game_tip(const t_string &text, const t_string &source, const std::string &unit_filter)
Definition: tips.cpp:26
const t_string & text() const
Definition: tips.hpp:57
std::vector< std::string > unit_filter_
List of units to filter the tip upon.
Definition: tips.hpp:83
std::vector< game_tip > shuffle(const std::vector< game_tip > &tips)
Shuffles the tips.
Definition: tips.cpp:46
t_string text_
The text of the tip.
Definition: tips.hpp:72
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
The tips of day structure.
Definition: tips.hpp:52