49 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
65 const bool has_input = !lua_isnoneornil(L, 3) &&
luaW_toconfig(L, 3, txt_cfg) && !txt_cfg.
empty();
68 input.
caption = txt_cfg[
"label"].str();
69 input.
text = txt_cfg[
"text"].str();
74 if(!lua_isnoneornil(L, 2)) {
75 luaL_checktype(L, 2, LUA_TTABLE);
76 std::size_t
n = lua_rawlen(L, 2);
77 for(std::size_t
i = 1;
i <=
n;
i++) {
82 opt[
"label"] = short_opt;
84 std::ostringstream error;
85 error <<
"expected array of config and/or translatable strings, but index ";
86 error <<
i <<
" was a " << lua_typename(L, lua_type(L, -1));
87 return luaL_argerror(L, 2, error.str().c_str());
90 if(opt[
"default"].to_bool(
false)) {
91 options.chosen_option =
i - 1;
93 options.option_list.push_back(option);
96 lua_getfield(L, 2,
"default");
97 if(lua_isnumber(L, -1)) {
98 int i = lua_tointeger(L, -1);
99 if(
i < 1 || std::size_t(
i) >
n) {
100 std::ostringstream error;
101 error <<
"default= key in options list is not a valid option index (1-" <<
n <<
")";
102 return luaL_argerror(L, 2, error.str().c_str());
104 options.chosen_option =
i - 1;
110 const std::string& title = def_cfg[
"title"];
111 const std::string& message = def_cfg[
"message"];
114 std::unique_ptr<portrait> left;
115 std::unique_ptr<portrait> right;
116 const bool is_double = def_cfg.
has_attribute(
"second_portrait");
117 const bool left_side = def_cfg[
"left_side"].to_bool(
true);
118 if(is_double || left_side) {
119 left.reset(
new portrait {def_cfg[
"portrait"], def_cfg[
"mirror"].to_bool(
false)});
122 right.reset(
new portrait {def_cfg[
"portrait"], def_cfg[
"mirror"].to_bool(
false)});
125 right.reset(
new portrait {def_cfg[
"second_portrait"], def_cfg[
"second_mirror"].to_bool(
false)});
130 if(!has_input && options.option_list.empty()) {
131 lua_pushinteger(L, dlg_result);
133 lua_pushinteger(L, options.chosen_option + 1);
137 lua_pushlstring(L, input.
text.c_str(), input.
text.length());
154 std::string
image = lua_isnoneornil(L, 3) ?
"" : luaL_checkstring(L, 3);
177 std::string theme_id = luaL_checkstring(L, 1);
189 std::vector<config> items = lua_check<std::vector<config>>(L, 1);
194 if(lua_isnumber(L, 2)) {
195 initial = lua_tointeger(L, 2) - 1;
197 }
else if(lua_isnumber(L, 3)) {
198 initial = lua_tointeger(L, 3) - 1;
200 }
else if(lua_isboolean(L, 2)) {
215 std::string button = luaL_optstring(L, 3,
"ok"), btn_style;
216 std::transform(button.begin(), button.end(), std::inserter(btn_style, btn_style.begin()), [](
char c) { return std::tolower(c); });
219 utils::optional<button_style> style;
220 if(btn_style.empty()) {
221 style = button_style::auto_close;
222 }
else if(btn_style ==
"ok") {
223 style = button_style::ok_button;
224 }
else if(btn_style ==
"close") {
225 style = button_style::close_button;
226 }
else if(btn_style ==
"ok_cancel") {
227 style = button_style::ok_cancel_buttons;
228 }
else if(btn_style ==
"cancel") {
229 style = button_style::cancel_button;
230 }
else if(btn_style ==
"yes_no") {
231 style = button_style::yes_no_buttons;
235 if(style == button_style::ok_cancel_buttons || style == button_style::yes_no_buttons) {
271 std::string
type = luaL_checkstring(L, 1);
272 std::string
id = luaL_checkstring(L, 2);
275 lua_kernel_base::get_lua_kernel<lua_kernel_base>(L).add_widget_definition(
type,
id);
277 }
catch(
const std::invalid_argument&
e) {
278 return luaL_argerror(L, 1,
e.what());
285 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
286 lk.add_log(
"Adding gui module...\n");
287 static luaL_Reg
const gui_callbacks[] = {
297 {
nullptr,
nullptr },
299 std::vector<lua_cpp::Reg>
const cpp_gui_callbacks {
304 luaL_setfuncs(L, gui_callbacks, 0);
307 lua_pushstring(L,
"widget");
A config object defines a single node in a WML file, with access to child nodes.
bool has_attribute(config_key_type key) const
const std::unique_ptr< game_events::manager > events_manager_
static void display(lua_kernel_base *lk)
Display a new console, using given video and lua kernel.
button_style
Selects the style of the buttons to be shown.
bool show(const unsigned auto_close_time=0)
Shows the window.
static void display(const std::string &scenario_name, const config &story)
Helper class for message options.
int intf_show_lua_console(lua_State *L)
Definitions for the interface to Wesnoth Markup Language (WML).
Standard logging facilities (interface).
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
bool luaW_toboolean(lua_State *L, int n)
bool luaW_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
static lg::log_domain log_scripting_lua("scripting/lua")
int show_wml_message(const std::string &title, const std::string &message, const wml_message_portrait *left, const wml_message_portrait *right, const wml_message_options &options, const wml_message_input &input)
Helper function to show a portrait.
bool add_single_widget_definition(const std::string &widget_type, const std::string &definition_id, const config &cfg)
Adds a widget definition to the default GUI.
void switch_theme(const std::string ¤t_theme)
Set and activate the given gui2 theme.
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
@ OK
Dialog was closed with the OK button.
void show_help(const std::string &show_topic)
Open the help browser, show topic with id show_topic.
Functions to load and save images from/to disk.
void set_functions(lua_State *L, const std::vector< lua_cpp::Reg > &functions)
Analogous to lua_setfuncs, it registers a collection of function wrapper objects into a table,...
int show_popup_dialog(lua_State *L)
Displays a popup message.
static int show_help(lua_State *L)
int luaW_open(lua_State *L)
int show_lua_console(lua_State *, lua_kernel_base *lk)
int show_story(lua_State *L)
Displays a story screen.
int switch_theme(lua_State *L)
Changes the current ui(gui2) theme.
int show_message_box(lua_State *L)
Displays a simple message box.
int show_gamestate_inspector(const std::string &name, const game_data &data, const game_state &state)
int intf_add_widget_definition(lua_State *L)
int show_message_dialog(lua_State *L)
Displays a message window.
int show_menu(lua_State *L)
Displays a popup menu at the current mouse position Best used from a [set_menu_item],...
point get_mouse_location()
Returns the current mouse location in draw space.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Parameter pack for message list input options.
Parameter pack for message portrait.
An abstract description of a rectangle with integer coordinates.
static map_location::direction n