Move open_help to the gui module (as show_help)

This also exposes it in kernels besides the game kernel.
This commit is contained in:
Celtic Minstrel 2021-02-14 21:01:32 -05:00
parent 6e9826cfcd
commit 7b2ceb863c
6 changed files with 21 additions and 16 deletions

View file

@ -154,3 +154,7 @@ wesnoth.get_dialog_value = wesnoth.deprecate_api('wesnoth.get_dialog_value', val
wesnoth.add_dialog_tree_node = wesnoth.deprecate_api('wesnoth.add_dialog_tree_node', '<widget>:add_item_of_type', 1, nil, add_dialog_tree_node)
wesnoth.remove_dialog_item = wesnoth.deprecate_api('wesnoth.remove_dialog_item', '<widget>:remove_items_at', 1, nil, remove_dialog_item)
wesnoth.show_dialog = wesnoth.deprecate_api('wesnoth.show_dialog', 'gui.show_dialog', 1, nil, gui.show_dialog)
if wesnoth.kernel_type() == "Game Lua Kernel" then
-- The deprecated function was only available in Game Lua Kernel, so even though show_help is available in other kernels, there's no need to expose the deprecated function there.
wesnoth.open_help = wesnoth.deprecate_api('wesnoth.open_help', 'gui.show_help', 1, nil, gui.show_help)
end

View file

@ -753,7 +753,7 @@ function wml_actions.label( cfg )
end
function wml_actions.open_help(cfg)
wesnoth.open_help(cfg.topic)
gui.open_help(cfg.topic)
end
function wml_actions.redraw(cfg)

View file

@ -87,16 +87,14 @@ void show_unit_description(const unit_type &t)
help::show_unit_help(t.id(), t.show_variations_in_help(), hide_help);
}
help_manager::help_manager(const game_config_view *cfg) //, gamemap *_map)
static game_config_view dummy_view;
help_manager::help_manager(const game_config_view *cfg)
: guard(game_cfg, cfg == nullptr ? &dummy_view : cfg)
{
static game_config_view dummy_view;
game_cfg = cfg == nullptr ? &dummy_view : cfg;
// map = _map;
}
help_manager::~help_manager()
{
game_cfg = nullptr;
// map = nullptr;
default_toplevel.clear();
hidden_sections.clear();

View file

@ -22,12 +22,15 @@ class CVideo;
class game_config_view;
#include <string>
#include "utils/guard_value.hpp"
namespace help {
struct help_manager {
help_manager(const game_config_view *game_config);
~help_manager();
private:
utils::guard_value<const game_config_view*> guard;
};
struct section;

View file

@ -55,7 +55,6 @@
#include "game_events/entity_location.hpp"
#include "game_events/pump.hpp" // for queued_event
#include "preferences/game.hpp" // for encountered_units
#include "help/help.hpp"
#include "log.hpp" // for LOG_STREAM, logger, etc
#include "utils/make_enum.hpp" // for operator<<
#include "map/map.hpp" // for gamemap
@ -1292,14 +1291,6 @@ int game_lua_kernel::intf_message(lua_State *L)
return 0;
}
int game_lua_kernel::intf_open_help(lua_State *L)
{
if (game_display_) {
help::show_help(luaL_checkstring(L, 1));
}
return 0;
}
int game_lua_kernel::intf_zoom(lua_State* L)
{
if(!game_display_) {
@ -4005,7 +3996,6 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
{ "log_replay", &dispatch<&game_lua_kernel::intf_log_replay > },
{ "log", &dispatch<&game_lua_kernel::intf_log > },
{ "message", &dispatch<&game_lua_kernel::intf_message > },
{ "open_help", &dispatch<&game_lua_kernel::intf_open_help > },
{ "print", &dispatch<&game_lua_kernel::intf_print > },
{ "redraw", &dispatch<&game_lua_kernel::intf_redraw > },
{ "remove_event_handler", &dispatch<&game_lua_kernel::intf_remove_event > },

View file

@ -35,6 +35,8 @@
#include "scripting/lua_widget_methods.hpp"
#include "scripting/push_check.hpp"
#include "serialization/string_utils.hpp"
#include "help/help.hpp"
#include "game_config_manager.hpp"
#include "tstring.hpp"
#include "game_data.hpp"
#include "game_state.hpp"
@ -249,6 +251,13 @@ int show_gamestate_inspector(const vconfig& cfg, const game_data& data, const ga
return 0;
}
int show_help(lua_State *L)
{
help::help_manager help_manager(&game_config_manager::get()->game_config());
help::show_help(luaL_checkstring(L, 1));
return 0;
}
/**
* - Arg 1: string, widget type
@ -280,6 +289,7 @@ int luaW_open(lua_State* L)
{ "show_popup", &show_popup_dialog },
{ "show_story", &show_story },
{ "show_prompt", &show_message_box },
{ "show_help", &show_help },
{ "add_widget_definition", &intf_add_widget_definition },
{ "show_dialog", &intf_show_dialog },
{ nullptr, nullptr },