diff --git a/changelog b/changelog index b1f2c74ae69..d471669200a 100644 --- a/changelog +++ b/changelog @@ -39,6 +39,7 @@ Version 1.13.7+dev: comparable with == or ~= * wesnoth.set_music is now deprecated, in favour of the above new API * New wesnoth.sound_volume function gets/sets the current sound volume, as [volume]sound= + * New wesnoth.show_story function launches the storyscreen viewer * Multiplayer: * Fixed statistics being lost when reloading an MP game. * Performance: @@ -71,6 +72,7 @@ Version 1.13.7+dev: * [kill]animate=yes now plays victory animations if applicable * Fix [volume] not accepting 100% as the new volume. * New concat_to_* keys in unit_type inheritance allow amending keys + * Accept [story] as ActionWML in events * Miscellaneous and bug fixes: * Fixed base animation showing on walking corpse & soulless bats (bug #25673) diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index 14f2388ee3f..2bc056633e9 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -1523,6 +1523,10 @@ function wesnoth.wml_actions.zoom(cfg) wesnoth.zoom(cfg.factor, cfg.relative) end +function wesnoth.wml_actions.story(cfg) + wesnoth.show_story(cfg, cfg.title) +end + function wesnoth.wml_conditionals.proceed_to_next_scenario(cfg) local endlevel_data = wesnoth.get_end_level_data() if not endlevel_data then diff --git a/src/gui/dialogs/story_viewer.hpp b/src/gui/dialogs/story_viewer.hpp index cc660c927eb..cc103c81272 100644 --- a/src/gui/dialogs/story_viewer.hpp +++ b/src/gui/dialogs/story_viewer.hpp @@ -36,20 +36,9 @@ public: ~story_viewer(); - static void display(const std::string& scenario_name, const config::const_child_itors& story, CVideo& video) + static void display(const std::string& scenario_name, const config& story, CVideo& video) { - // Combine all the [story] tags into a single config. Handle this here since - // storyscreen::controller doesn't have a default constructor. - config cfg; - for(const auto& iter : story) { - cfg.append_children(iter); - } - - if(cfg.empty()) { - return; - } - - story_viewer(scenario_name, cfg).show(video); + story_viewer(scenario_name, story).show(video); } private: diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 0886e79a4b0..3489285d094 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -235,7 +235,16 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level) sound::commit_music_changes(); if(!this->is_skipping_replay()) { - gui2::dialogs::story_viewer::display(get_scenario_name(), level.child_range("story"), gui_->video()); + // Combine all the [story] tags into a single config. Handle this here since + // storyscreen::controller doesn't have a default constructor. + config cfg; + for(const auto& iter : level.child_range("story")) { + cfg.append_children(iter); + } + + if(!cfg.empty()) { + gui2::dialogs::story_viewer::display(get_scenario_name(), cfg, gui_->video()); + } } gui_->labels().read(level); diff --git a/src/scripting/lua_gui2.cpp b/src/scripting/lua_gui2.cpp index 893f6afbc40..6258bb1aea6 100644 --- a/src/scripting/lua_gui2.cpp +++ b/src/scripting/lua_gui2.cpp @@ -21,6 +21,7 @@ #include "gui/dialogs/gamestate_inspector.hpp" #include "gui/dialogs/lua_interpreter.hpp" #include "gui/dialogs/wml_message.hpp" +#include "gui/dialogs/story_viewer.hpp" #include "gui/dialogs/transient_message.hpp" #include "gui/widgets/clickable_item.hpp" #include "gui/widgets/styled_widget.hpp" @@ -387,6 +388,18 @@ int show_popup_dialog(lua_State *L, CVideo & video) { return 0; } +/** + * Displays a story screen + * - Arg 1: The story config + * - Arg 2: The default title + */ +int show_story(lua_State* L, CVideo& video) { + config story = luaW_checkconfig(L, 1); + std::string title = luaL_checkstring(L, 2); + gui2::dialogs::story_viewer::display(title, story, video); + return 0; +} + /** * Displays a popup menu at the current mouse position * Best used from a [set_menu_item], to show a submenu diff --git a/src/scripting/lua_gui2.hpp b/src/scripting/lua_gui2.hpp index ed26f9586b3..b47f86d2812 100644 --- a/src/scripting/lua_gui2.hpp +++ b/src/scripting/lua_gui2.hpp @@ -38,6 +38,7 @@ int show_dialog(lua_State *L, CVideo & video); int show_message_dialog(lua_State *L, CVideo & video); int show_popup_dialog(lua_State *L, CVideo & video); int show_menu(lua_State* L, CVideo& video); +int show_story(lua_State* L, CVideo& video); int show_lua_console(lua_State*L, CVideo & video, lua_kernel_base * lk); int show_gamestate_inspector(CVideo& video, const vconfig& cfg, const game_data& data, const game_state& state); int intf_remove_dialog_item(lua_State *L); diff --git a/src/scripting/lua_kernel_base.cpp b/src/scripting/lua_kernel_base.cpp index 9533de00b49..241a1e6c9f6 100644 --- a/src/scripting/lua_kernel_base.cpp +++ b/src/scripting/lua_kernel_base.cpp @@ -367,6 +367,7 @@ lua_kernel_base::lua_kernel_base() { "show_menu", &video_dispatch }, { "show_message_dialog", &video_dispatch }, { "show_popup_dialog", &video_dispatch }, + { "show_story", &video_dispatch }, { "show_lua_console", &dispatch<&lua_kernel_base::intf_show_lua_console> }, { "compile_formula", &lua_formula_bridge::intf_compile_formula}, { "eval_formula", &lua_formula_bridge::intf_eval_formula},