Lua API: Replace wesnoth.skipping_replay() with is_skipping_messages() and skip_messages()
This commit is contained in:
parent
03580ed9a9
commit
907d527cc3
6 changed files with 51 additions and 15 deletions
|
@ -33,7 +33,7 @@ Version 1.13.1+dev:
|
|||
* Added wesnoth.show_message_dialog function
|
||||
* Added wesnoth.show_popup_dialog function
|
||||
* Added wesnoth.deselect_hex function
|
||||
* Added wesnoth.skipping_replay function
|
||||
* Added wesnoth.is_skipping_messages and wesnoth.skip_messages functions
|
||||
* New parameter write_to_mods in wesnoth.add_modification
|
||||
* Added wesnoth.random function
|
||||
* helper.shuffle is now synced
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local location_set = wesnoth.require "lua/location_set.lua"
|
||||
local skip_messages = false
|
||||
|
||||
local function log(msg, level)
|
||||
wesnoth.wml_actions.wml_message({
|
||||
|
@ -92,7 +91,7 @@ local function message_user_choice(cfg, speaker, options, text_input)
|
|||
local option_chosen, ti_content = wesnoth.show_message_dialog(msg_cfg, options, text_input)
|
||||
|
||||
if option_chosen == -2 then -- Pressed Escape (only if no input)
|
||||
skip_messages = true
|
||||
wesnoth.skip_messages()
|
||||
end
|
||||
|
||||
local result_cfg = {}
|
||||
|
@ -143,7 +142,7 @@ function wesnoth.wml_actions.message(cfg)
|
|||
-- Check if there is any input to be made, if not the message may be skipped
|
||||
local has_input = text_input ~= nil or #options > 0
|
||||
|
||||
if not has_input and (wesnoth.skipping_replay() or skip_messages) then
|
||||
if not has_input and wesnoth.is_skipping_messages() then
|
||||
-- No input to get and the user is not interested either
|
||||
log("Skipping [message] because user not interested", "debug")
|
||||
return
|
||||
|
@ -220,8 +219,3 @@ function wesnoth.wml_actions.message(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
local on_event = wesnoth.game_events.on_event
|
||||
function wesnoth.game_events.on_event(...)
|
||||
if type(on_event) == "function" then on_event(...) end
|
||||
skip_messages = false
|
||||
end
|
||||
|
|
|
@ -75,8 +75,9 @@ namespace context {
|
|||
/// State when processing a particular flight of events or commands.
|
||||
struct state {
|
||||
bool mutated;
|
||||
bool skip_messages;
|
||||
|
||||
explicit state(bool m = true) : mutated(m) {}
|
||||
explicit state(bool s, bool m = true) : mutated(m), skip_messages(s) {}
|
||||
};
|
||||
|
||||
class scoped {
|
||||
|
@ -416,7 +417,8 @@ context::scoped::scoped(std::stack<context::state> & contexts, bool m)
|
|||
//The default context at least should always be on the stack
|
||||
assert(contexts_.size() > 0);
|
||||
|
||||
contexts_.push(context::state(m));
|
||||
bool skip_messages = (contexts_.size() > 1) && contexts_.top().skip_messages;
|
||||
contexts_.push(context::state(skip_messages, m));
|
||||
}
|
||||
|
||||
context::scoped::~scoped()
|
||||
|
@ -439,6 +441,18 @@ void t_pump::context_mutated(bool b)
|
|||
impl_->contexts_.top().mutated = b;
|
||||
}
|
||||
|
||||
bool t_pump::context_skip_messages()
|
||||
{
|
||||
assert(impl_->contexts_.size() > 0);
|
||||
return impl_->contexts_.top().skip_messages;
|
||||
}
|
||||
|
||||
void t_pump::context_skip_messages(bool b)
|
||||
{
|
||||
assert(impl_->contexts_.size() > 0);
|
||||
impl_->contexts_.top().skip_messages = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function which determines whether a wml_message text can
|
||||
* really be pushed into the wml_messages_stream, and does it.
|
||||
|
|
|
@ -71,6 +71,10 @@ namespace game_events
|
|||
bool context_mutated();
|
||||
/// Sets whether or not we believe WML might have changed something.
|
||||
void context_mutated(bool mutated);
|
||||
/// Returns whether or not we are skipping messages.
|
||||
bool context_skip_messages();
|
||||
/// Sets whether or not we are skipping messages.
|
||||
void context_skip_messages(bool skip);
|
||||
|
||||
/// Helper function which determines whether a wml_message text can
|
||||
/// really be pushed into the wml_messages_stream, and does it.
|
||||
|
|
|
@ -124,6 +124,10 @@
|
|||
#include "lua/lauxlib.h" // for luaL_checkinteger, etc
|
||||
#include "lua/lua.h" // for lua_setfield, etc
|
||||
|
||||
#include "resources.hpp"
|
||||
#include "game_events/manager.hpp"
|
||||
#include "game_events/pump.hpp"
|
||||
|
||||
class CVideo;
|
||||
|
||||
#ifdef DEBUG_LUA
|
||||
|
@ -2868,12 +2872,30 @@ int game_lua_kernel::intf_deselect_hex(lua_State*)
|
|||
/**
|
||||
* Return true if a replay is in progress but the player has chosen to skip it
|
||||
*/
|
||||
int game_lua_kernel::intf_skipping_replay(lua_State *L)
|
||||
int game_lua_kernel::intf_is_skipping_messages(lua_State *L)
|
||||
{
|
||||
lua_pushboolean(L, play_controller_.is_skipping_replay());
|
||||
bool skipping = play_controller_.is_skipping_replay();
|
||||
if (!skipping && resources::game_events) {
|
||||
skipping = resources::game_events->pump().context_skip_messages();
|
||||
}
|
||||
lua_pushboolean(L, skipping);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to skip messages
|
||||
* Arg 1 (optional) - boolean
|
||||
*/
|
||||
int game_lua_kernel::intf_skip_messages(lua_State *L)
|
||||
{
|
||||
bool skip = true;
|
||||
if (!lua_isnone(L, 1)) {
|
||||
skip = lua_toboolean(L, 1);
|
||||
}
|
||||
resources::game_events->pump().context_skip_messages(skip);
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct lua_synchronize : mp_sync::user_choice
|
||||
{
|
||||
|
@ -4184,7 +4206,8 @@ game_lua_kernel::game_lua_kernel(CVideo * video, game_state & gs, play_controlle
|
|||
{ "scroll_to_tile", &dispatch<&game_lua_kernel::intf_scroll_to_tile > },
|
||||
{ "select_hex", &dispatch<&game_lua_kernel::intf_select_hex > },
|
||||
{ "deselect_hex", &dispatch<&game_lua_kernel::intf_deselect_hex > },
|
||||
{ "skipping_replay", &dispatch<&game_lua_kernel::intf_skipping_replay > },
|
||||
{ "skip_messages", &dispatch<&game_lua_kernel::intf_skip_messages > },
|
||||
{ "is_skipping_messages", &dispatch<&game_lua_kernel::intf_is_skipping_messages > },
|
||||
{ "set_end_campaign_credits", &dispatch<&game_lua_kernel::intf_set_end_campaign_credits > },
|
||||
{ "set_end_campaign_text", &dispatch<&game_lua_kernel::intf_set_end_campaign_text > },
|
||||
{ "set_menu_item", &dispatch<&game_lua_kernel::intf_set_menu_item > },
|
||||
|
|
|
@ -130,7 +130,8 @@ class game_lua_kernel : public lua_kernel_base
|
|||
int intf_scroll_to_tile(lua_State *L);
|
||||
int intf_select_hex(lua_State *L);
|
||||
int intf_deselect_hex(lua_State *L);
|
||||
int intf_skipping_replay(lua_State *L);
|
||||
int intf_is_skipping_messages(lua_State *L);
|
||||
int intf_skip_messages(lua_State *L);
|
||||
int intf_synchronize_choice(lua_State *L);
|
||||
int intf_get_locations(lua_State *L);
|
||||
int intf_get_villages(lua_State *L);
|
||||
|
|
Loading…
Add table
Reference in a new issue