The Battle for Wesnoth  1.17.0-dev
help.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
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 config;
19 class terrain_type;
20 class unit;
21 class unit_type;
22 class CVideo;
23 class game_config_view;
24 
25 #include <memory>
26 #include <string>
27 
28 namespace help {
29 
30 /**
31  * The help implementation caches data parsed from the game_config. This class
32  * is used to control the lifecycle of that cache, so that the cache will be
33  * cleared before the game_config itself changes.
34  *
35  * Note: it's okay to call any of the help::show_* functions without creating
36  * an instance of help_manager - that will simply mean that the cache is
37  * cleared before the show function returns.
38  *
39  * Creating two instances of this will cause an assert.
40  */
41 struct help_manager {
43  help_manager(const help_manager&) = delete;
44  help_manager& operator=(const help_manager&) = delete;
45  ~help_manager();
46 };
47 
48 /**
49  * Helper function for any of the show_help functions to control the cache's
50  * lifecycle; can also be used by any other caller that wants to ensure the
51  * cache is reused over multiple show_help calls.
52  *
53  * Treat the return type as opaque, it can return nullptr on success. Also
54  * don't extend the cache lifecycle beyond the lifecycle of the
55  * game_config_manager or over a reload of the game config.
56  *
57  *@pre game_config_manager has been initialised
58  */
59 std::unique_ptr<help_manager> ensure_cache_lifecycle();
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="", int xloc=-1, int yloc=-1);
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, int xloc=-1, int yloc=-1);
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, int xloc=-1, int yloc=-1);
78 
79 /** wrapper to add terrain prefix and hiding symbol */
80 void show_terrain_help(const std::string& unit_id, bool hidden = false,
81  int xloc = -1, int yloc = -1);
82 
83 void show_unit_description(const unit_type &t);
84 void show_unit_description(const unit &u);
86 
87 } // End namespace help.
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
Definition: help.cpp:144
This class represents a single unit of a specific type.
Definition: unit.hpp:121
void show_terrain_description(const terrain_type &t)
Definition: help.cpp:81
Definition: video.hpp:32
std::unique_ptr< help_manager > ensure_cache_lifecycle()
Helper function for any of the show_help functions to control the cache&#39;s lifecycle; can also be used...
Definition: help.cpp:119
A single unit type that the player may recruit.
Definition: types.hpp:45
help_manager & operator=(const help_manager &)=delete
void show_terrain_help(const std::string &show_topic, bool hidden, int xloc, int yloc)
Open the help browser, show terrain with id terrain_id.
Definition: help.cpp:167
void show_unit_description(const unit &u)
Definition: help.cpp:75
Game configuration data as global variables.
Definition: build_info.cpp:59
void show_unit_help(const std::string &show_topic, bool has_variations, bool hidden, int xloc, int yloc)
Open the help browser, show unit with id unit_id.
Definition: help.cpp:155
The help implementation caches data parsed from the game_config.
Definition: help.hpp:41
help_manager(const game_config_view *game_config)
Definition: help.cpp:111
double t
Definition: astarsearch.cpp:65
Definition: help.cpp:57
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
void show_variation_help(const std::string &unit, const std::string &variation, bool hidden, int xloc, int yloc)
Open the help browser, show the variation of the unit matching.
Definition: help.cpp:176