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