The Battle for Wesnoth  1.19.5+dev
help.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
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 class terrain_type;
19 class unit;
20 class unit_type;
21 class game_config_view;
22 
23 #include <memory>
24 #include <string>
25 
26 namespace help {
27 
28 /**
29  * The help implementation caches data parsed from the game_config. This class
30  * is used to control the lifecycle of that cache, so that the cache will be
31  * cleared before the game_config itself changes.
32  *
33  * Note: it's okay to call any of the help::show_* functions without creating
34  * an instance of help_manager - that will simply mean that the cache is
35  * cleared before the show function returns.
36  *
37  * Creating two instances of this will cause an assert.
38  */
39 struct help_manager {
41  help_manager(const help_manager&) = delete;
42  help_manager& operator=(const help_manager&) = delete;
43  ~help_manager();
44 };
45 
46 /**
47  * Helper function for any of the show_help functions to control the cache's
48  * lifecycle; can also be used by any other caller that wants to ensure the
49  * cache is reused over multiple show_help calls.
50  *
51  * Treat the return type as opaque, it can return nullptr on success. Also
52  * don't extend the cache lifecycle beyond the lifecycle of the
53  * game_config_manager or over a reload of the game config.
54  *
55  *@pre game_config_manager has been initialised
56  */
57 std::unique_ptr<help_manager> ensure_cache_lifecycle();
58 
59 void init_help();
60 
61 /**
62  * Open the help browser. The help browser will have the topic with id
63  * show_topic open if it is not the empty string. The default topic
64  * will be shown if show_topic is the empty string.
65  *
66  *@pre game_config_manager has been initialised, or the instance of help_manager
67  * has been created with an alternative config.
68  */
69 void show_help(const std::string& show_topic="");
70 
71 /** wrapper to add unit prefix and hiding symbol */
72 void show_unit_help(const std::string& unit_id, bool has_variations=false,
73  bool hidden = false);
74 
75 /** wrapper to add variation prefix and hiding symbol */
76 void show_variation_help(const std::string &unit_id, const std::string &variation,
77  bool hidden = false);
78 
79 /** wrapper to add terrain prefix and hiding symbol */
80 void show_terrain_help(const std::string& unit_id, bool hidden = false);
81 
82 void show_unit_description(const unit_type &t);
83 void show_unit_description(const unit &u);
85 
86 } // End namespace help.
double t
Definition: astarsearch.cpp:63
A class grating read only view to a vector of config objects, viewed as one config with all children ...
A single unit type that the player may recruit.
Definition: types.hpp:43
This class represents a single unit of a specific type.
Definition: unit.hpp:133
Game configuration data as global variables.
Definition: build_info.cpp:61
std::unique_ptr< help_manager > ensure_cache_lifecycle()
Helper function for any of the show_help functions to control the cache's lifecycle; can also be used...
Definition: help.cpp:115
void show_help(const std::string &show_topic)
Open the help browser, show topic with id show_topic.
Definition: help.cpp:140
void show_terrain_description(const terrain_type &t)
Definition: help.cpp:77
void show_terrain_help(const std::string &show_topic, bool hidden)
Open the help browser, show terrain with id terrain_id.
Definition: help.cpp:163
void init_help()
Definition: help.cpp:178
void show_unit_description(const unit &u)
Definition: help.cpp:71
void show_unit_help(const std::string &show_topic, bool has_variations, bool hidden)
Open the help browser, show unit with id unit_id.
Definition: help.cpp:151
void show_variation_help(const std::string &unit, const std::string &variation, bool hidden)
Open the help browser, show the variation of the unit matching.
Definition: help.cpp:172
The help implementation caches data parsed from the game_config.
Definition: help.hpp:39
help_manager & operator=(const help_manager &)=delete
help_manager(const help_manager &)=delete
help_manager(const game_config_view *game_config)
Definition: help.cpp:107