The Battle for Wesnoth  1.15.0-dev
help.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 /**
16  * @file
17  * Routines for showing the help-dialog.
18  */
19 
20 #include "help/help.hpp"
21 
22 #include "help/constants.hpp"
23 #include "help/manager.hpp"
24 #include "help/utils.hpp"
25 #include "terrain/terrain.hpp"
26 #include "units/types.hpp"
27 #include "units/unit.hpp"
28 
29 #include <cassert>
30 
31 namespace help
32 {
33 /** The help manager. What else would it be? */
35 
36 void show_help(const std::string& show_topic)
37 {
38  manager.open_help_browser_to(show_topic);
39 }
40 
41 void reset()
42 {
43  manager.reset_contents();
44 }
45 
47 {
49 }
50 
52 {
53  std::string var_id = t.get_cfg()["variation_id"].str();
54  if(var_id.empty()) {
55  var_id = t.get_cfg()["variation_name"].str();
56  }
57 
58  bool hide_help = t.hide_help();
59  bool use_variation = false;
60 
61  if(!var_id.empty()) {
62  const unit_type* parent = unit_types.find(t.id());
63  assert(parent);
64 
65  if(hide_help) {
66  hide_help = parent->hide_help();
67  } else {
68  use_variation = true;
69  }
70  }
71 
72  if(use_variation) {
73  show_variation_help(t.id(), var_id, hide_help);
74  } else {
75  show_unit_help(t.id(), t.show_variations_in_help(), hide_help);
76  }
77 }
78 
79 void show_unit_help(const std::string& show_topic, bool has_variations, bool hidden)
80 {
81  show_help(hidden_symbol(hidden) + (has_variations ? ".." : "") + unit_prefix + show_topic);
82 }
83 
84 void show_variation_help(const std::string& unit, const std::string& variation, bool hidden)
85 {
86  show_help(hidden_symbol(hidden) + variation_prefix + unit + "_" + variation);
87 }
88 
90 {
92 }
93 
94 void show_terrain_help(const std::string& show_topic, bool hidden)
95 {
96  show_help(hidden_symbol(hidden) + terrain_prefix + show_topic);
97 }
98 
99 } // End namespace help.
void show_terrain_help(const std::string &show_topic, bool hidden)
Open the help browser, show terrain with id terrain_id.
Definition: help.cpp:94
const std::string unit_prefix
Definition: constants.cpp:32
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
Definition: types.cpp:1265
This class represents a single unit of a specific type.
Definition: unit.hpp:99
void show_terrain_description(const terrain_type &t)
Definition: help.cpp:89
void open_help_browser_to(std::string show_topic)
Displays the help browser.
Definition: manager.cpp:37
static help_manager manager
The help manager.
Definition: help.cpp:34
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:84
void reset()
Flags the help manager&#39;s contents for regeneration.
Definition: help.cpp:41
unit_type_data unit_types
Definition: types.cpp:1442
const config & get_cfg() const
Definition: types.hpp:269
const std::string terrain_prefix
Definition: constants.cpp:29
A single unit type that the player may recruit.
Definition: types.hpp:42
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:79
const unit_type & type() const
This unit&#39;s type, accounting for gender and variation.
Definition: unit.hpp:277
bool is_combined() const
Definition: terrain.hpp:80
std::string hidden_symbol(bool hidden)
Definition: utils.cpp:44
bool hide_help() const
Definition: types.cpp:576
const std::string & id() const
The id for this unit_type.
Definition: types.hpp:139
void show_unit_description(const unit &u)
Definition: help.cpp:46
void reset_contents()
Clears the generated section data.
Definition: manager.cpp:77
void show_help(const std::string &show_topic)
Open the help browser, show topic with id show_topic.
Definition: help.cpp:36
const std::string variation_prefix
Definition: constants.cpp:33
bool show_variations_in_help() const
Whether the unit type has at least one help-visible variation.
Definition: types.cpp:775
bool hide_in_editor() const
Definition: terrain.hpp:40
double t
Definition: astarsearch.cpp:63
const std::string & id() const
Definition: terrain.hpp:37