Help: formatting/doc/include cleanup
This commit is contained in:
parent
88d8b9c933
commit
e82471a972
2 changed files with 77 additions and 97 deletions
|
@ -21,133 +21,103 @@
|
|||
|
||||
#include "help/help.hpp"
|
||||
|
||||
#include "config.hpp" // for config, etc
|
||||
#include "events.hpp" // for raise_draw_event, pump, etc
|
||||
#include "font/constants.hpp" // for relative_size
|
||||
#include "preferences/game.hpp"
|
||||
#include "gettext.hpp" // for _
|
||||
#include "config.hpp" // for config, etc
|
||||
#include "gettext.hpp" // for _
|
||||
#include "gui/dialogs/help_browser.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "help/help_impl.hpp" // for hidden_symbol, toplevel, etc
|
||||
#include "key.hpp" // for CKey
|
||||
#include "log.hpp" // for LOG_STREAM, log_domain
|
||||
#include "sdl/surface.hpp" // for surface
|
||||
#include "terrain/terrain.hpp" // for terrain_type
|
||||
#include "units/unit.hpp" // for unit
|
||||
#include "units/types.hpp" // for unit_type, unit_type_data, etc
|
||||
#include "video.hpp" // for CVideo, resize_lock
|
||||
#include "widgets/button.hpp" // for button
|
||||
#include "help/help_impl.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
#include "terrain/terrain.hpp" // for terrain_type
|
||||
#include "units/types.hpp" // for unit_type, unit_type_data, etc
|
||||
#include "units/unit.hpp" // for unit
|
||||
|
||||
#include <cassert> // for assert
|
||||
#include <algorithm> // for min
|
||||
#include <ostream> // for basic_ostream, operator<<, etc
|
||||
#include <vector> // for vector, vector<>::iterator
|
||||
#include <SDL.h>
|
||||
#include <cassert> // for assert
|
||||
#include <ostream> // for basic_ostream, operator<<, etc
|
||||
#include <vector> // for vector, vector<>::iterator
|
||||
|
||||
|
||||
static lg::log_domain log_display("display");
|
||||
#define WRN_DP LOG_STREAM(warn, log_display)
|
||||
|
||||
static lg::log_domain log_help("help");
|
||||
#define WRN_HP LOG_STREAM(warn, log_help)
|
||||
#define DBG_HP LOG_STREAM(debug, log_help)
|
||||
|
||||
namespace help {
|
||||
|
||||
void show_unit_description(const unit &u)
|
||||
namespace help
|
||||
{
|
||||
void show_unit_description(const unit& u)
|
||||
{
|
||||
help::show_unit_description(u.type());
|
||||
}
|
||||
|
||||
void show_terrain_description(const terrain_type &t)
|
||||
void show_terrain_description(const terrain_type& t)
|
||||
{
|
||||
help::show_terrain_help(t.id(), t.hide_in_editor() || t.is_combined());
|
||||
}
|
||||
|
||||
void show_unit_description(const unit_type &t)
|
||||
void show_unit_description(const unit_type& t)
|
||||
{
|
||||
std::string var_id = t.get_cfg()["variation_id"].str();
|
||||
if (var_id.empty())
|
||||
if(var_id.empty()) {
|
||||
var_id = t.get_cfg()["variation_name"].str();
|
||||
}
|
||||
|
||||
bool hide_help = t.hide_help();
|
||||
bool use_variation = false;
|
||||
if (!var_id.empty()) {
|
||||
const unit_type *parent = unit_types.find(t.id());
|
||||
|
||||
if(!var_id.empty()) {
|
||||
const unit_type* parent = unit_types.find(t.id());
|
||||
assert(parent);
|
||||
if (hide_help) {
|
||||
|
||||
if(hide_help) {
|
||||
hide_help = parent->hide_help();
|
||||
} else {
|
||||
use_variation = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (use_variation)
|
||||
if(use_variation) {
|
||||
help::show_variation_help(t.id(), var_id, hide_help);
|
||||
else
|
||||
} else {
|
||||
help::show_unit_help(t.id(), t.show_variations_in_help(), hide_help);
|
||||
}
|
||||
}
|
||||
|
||||
extern config dummy_cfg;
|
||||
|
||||
help_manager::help_manager(const config *cfg) //, gamemap *_map)
|
||||
help_manager::help_manager(const config* cfg) //, gamemap *_map)
|
||||
{
|
||||
game_cfg = cfg == nullptr ? &dummy_cfg : cfg;
|
||||
// map = _map;
|
||||
// map = _map;
|
||||
}
|
||||
|
||||
help_manager::~help_manager()
|
||||
{
|
||||
game_cfg = nullptr;
|
||||
// map = nullptr;
|
||||
|
||||
// map = nullptr;
|
||||
default_toplevel.clear();
|
||||
hidden_sections.clear();
|
||||
// These last numbers must be reset so that the content is regenerated.
|
||||
// Upon next start.
|
||||
|
||||
// These last numbers must be reset so that the content is regenerated.
|
||||
// Upon next start.
|
||||
last_num_encountered_units = -1;
|
||||
last_num_encountered_terrains = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the help browser, show topic with id show_topic.
|
||||
*
|
||||
* If show_topic is the empty string, the default topic will be shown.
|
||||
*/
|
||||
void show_help(const std::string& show_topic)
|
||||
{
|
||||
show_help(default_toplevel, show_topic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the help browser, show unit with id unit_id.
|
||||
*
|
||||
* If show_topic is the empty string, the default topic will be shown.
|
||||
*/
|
||||
void show_unit_help(const std::string& show_topic, bool has_variations, bool hidden)
|
||||
{
|
||||
show_help(default_toplevel,
|
||||
hidden_symbol(hidden) + (has_variations ? ".." : "") + unit_prefix + show_topic);
|
||||
show_help(default_toplevel, hidden_symbol(hidden) + (has_variations ? ".." : "") + unit_prefix + show_topic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the help browser, show terrain with id terrain_id.
|
||||
*
|
||||
* If show_topic is the empty string, the default topic will be shown.
|
||||
*/
|
||||
void show_terrain_help(const std::string& show_topic, bool hidden)
|
||||
{
|
||||
show_help(default_toplevel, hidden_symbol(hidden) + terrain_prefix + show_topic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the help browser, show the variation of the unit matching.
|
||||
*/
|
||||
void show_variation_help(const std::string& unit, const std::string &variation, bool hidden)
|
||||
void show_variation_help(const std::string& unit, const std::string& variation, bool hidden)
|
||||
{
|
||||
show_help(default_toplevel, hidden_symbol(hidden) + variation_prefix + unit + "_" + variation);
|
||||
}
|
||||
|
||||
void init_help() {
|
||||
void init_help()
|
||||
{
|
||||
// Find all unit_types that have not been constructed yet and fill in the information
|
||||
// needed to create the help topics
|
||||
unit_types.build_all(unit_type::HELP_INDEXED);
|
||||
|
@ -160,17 +130,12 @@ void init_help() {
|
|||
last_num_encountered_units = preferences::encountered_units().size();
|
||||
last_num_encountered_terrains = preferences::encountered_terrains().size();
|
||||
last_debug_state = game_config::debug;
|
||||
|
||||
generate_contents();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a help dialog using a toplevel other than the default.
|
||||
*
|
||||
* This allows for complete customization of the contents, although not in a
|
||||
* very easy way.
|
||||
*/
|
||||
void show_help(const section &toplevel_sec, const std::string& show_topic)
|
||||
void show_help(const section& toplevel_sec, const std::string& show_topic)
|
||||
{
|
||||
gui2::dialogs::help_browser::display(toplevel_sec, show_topic);
|
||||
}
|
||||
|
|
|
@ -14,46 +14,61 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class config;
|
||||
class terrain_type;
|
||||
class unit;
|
||||
class unit_type;
|
||||
class CVideo;
|
||||
#include <string>
|
||||
|
||||
namespace help {
|
||||
|
||||
struct help_manager {
|
||||
help_manager(const config *game_config);
|
||||
namespace help
|
||||
{
|
||||
struct help_manager
|
||||
{
|
||||
help_manager(const config* game_config);
|
||||
~help_manager();
|
||||
};
|
||||
|
||||
struct section;
|
||||
|
||||
void init_help();
|
||||
|
||||
/// Open a help dialog using a toplevel other than the default. This
|
||||
/// allows for complete customization of the contents, although not in a
|
||||
/// very easy way.
|
||||
void show_help(const section &toplevel, const std::string& show_topic="");
|
||||
/**
|
||||
* Open a help dialog using a toplevel other than the default.
|
||||
*
|
||||
* This allows for complete customization of the contents, although not in a
|
||||
* very easy way.
|
||||
*/
|
||||
void show_help(const section& toplevel, const std::string& show_topic = "");
|
||||
|
||||
/// Open the help browser. The help browser will have the topic with id
|
||||
/// show_topic open if it is not the empty string. The default topic
|
||||
/// will be shown if show_topic is the empty string.
|
||||
void show_help(const std::string& show_topic="");
|
||||
/**
|
||||
* Open the help browser, show topic with id show_topic.
|
||||
*
|
||||
* If show_topic is the empty string, the default topic will be shown.
|
||||
*/
|
||||
void show_help(const std::string& show_topic = "");
|
||||
|
||||
/// wrapper to add unit prefix and hiding symbol
|
||||
void show_unit_help(const std::string& unit_id, bool has_variations=false,
|
||||
bool hidden = false);
|
||||
/**
|
||||
* Open the help browser, show unit with id unit_id.
|
||||
*
|
||||
* If show_topic is the empty string, the default topic will be shown.
|
||||
*/
|
||||
void show_unit_help(const std::string& unit_id, bool has_variations = false, bool hidden = false);
|
||||
|
||||
/// wrapper to add variation prefix and hiding symbol
|
||||
void show_variation_help(const std::string &unit_id, const std::string &variation,
|
||||
bool hidden = false);
|
||||
/**
|
||||
* Open the help browser, show the variation of the unit matching.
|
||||
*/
|
||||
void show_variation_help(const std::string& unit_id, const std::string& variation, bool hidden = false);
|
||||
|
||||
/// wrapper to add terrain prefix and hiding symbol
|
||||
/**
|
||||
* Open the help browser, show terrain with id terrain_id.
|
||||
*
|
||||
* If show_topic is the empty string, the default topic will be shown.
|
||||
*/
|
||||
void show_terrain_help(const std::string& unit_id, bool hidden = false);
|
||||
|
||||
void show_unit_description(const unit_type &t);
|
||||
void show_unit_description(const unit &u);
|
||||
void show_unit_description(const unit_type& t);
|
||||
void show_unit_description(const unit& u);
|
||||
void show_terrain_description(const terrain_type& t);
|
||||
|
||||
} // End namespace help.
|
||||
|
|
Loading…
Add table
Reference in a new issue