The Battle for Wesnoth  1.13.4+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 - 2016 by Mark de Wever <[email protected]>
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 #ifndef GUI_AUXILIARY_TIPS_HPP_INCLUDED
16 #define GUI_AUXILIARY_TIPS_HPP_INCLUDED
17 
18 #include "tstring.hpp"
19 
20 #include <vector>
21 
22 class config;
23 
24 namespace gui2
25 {
26 
27 class ttip;
28 
29 namespace tips
30 {
31 
32 /**
33  * Loads the tips from a config.
34  *
35  * @param cfg A config with the tips.
36  *
37  * @returns The loaded tips.
38  */
39 std::vector<ttip> load(const config& cfg);
40 
41 /**
42  * Shuffles the tips.
43  *
44  * This routine shuffles the tips and filters out the unwanted ones.
45  *
46  * @param tips The tips.
47  *
48  * @returns The filtered tips in random order.
49  */
50 std::vector<ttip> shuffle(const std::vector<ttip>& tips);
51 
52 } // namespace tips {
53 
54 /** The tips of day structure. */
55 class ttip
56 {
57 public:
58  const t_string& text() const
59  {
60  return text_;
61  }
62  const t_string& source() const
63  {
64  return source_;
65  }
66 
67 private:
68  friend std::vector<ttip> tips::load(const config&);
69  friend std::vector<ttip> tips::shuffle(const std::vector<ttip>& tips);
70  ttip(const t_string& text,
71  const t_string& source,
72  const std::string& unit_filter);
73 
74  /** The text of the tip. */
76 
77  /** The source of the tip. */
79 
80  /**
81  * List of units to filter the tip upon.
82  *
83  * If the list is empty the tip is shown.
84  * Else the unit must have encountered at least one of the units in the
85  * list.
86  */
87  std::vector<std::string> unit_filter_;
88 };
89 
90 } // namespace gui2
91 
92 #endif
std::vector< std::string > unit_filter_
List of units to filter the tip upon.
Definition: tips.hpp:87
const t_string & source() const
Definition: tips.hpp:62
std::vector< ttip > load(const config &cfg)
Loads the tips from a config.
Definition: tips.cpp:36
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
t_string text_
The text of the tip.
Definition: tips.hpp:75
std::vector< ttip > shuffle(const std::vector< ttip > &tips)
Shuffles the tips.
Definition: tips.cpp:49
ttip()
Definition: tip.cpp:71
const t_string & text() const
Definition: tips.hpp:58
t_string source_
The source of the tip.
Definition: tips.hpp:78
The tips of day structure.
Definition: tips.hpp:55
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
GLsizei GLsizei GLchar * source
Definition: glew.h:1800
static std::vector< ttip > tips
Definition: settings.cpp:65