54 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
70 const bool has_input = !lua_isnoneornil(L, 3) &&
luaW_toconfig(L, 3, txt_cfg) && !txt_cfg.
empty();
73 input.
caption = txt_cfg[
"label"].str();
74 input.
text = txt_cfg[
"text"].str();
79 if(!lua_isnoneornil(L, 2)) {
80 luaL_checktype(L, 2, LUA_TTABLE);
81 std::size_t
n = lua_rawlen(L, 2);
82 for(std::size_t
i = 1;
i <=
n;
i++) {
87 opt[
"label"] = short_opt;
89 std::ostringstream error;
90 error <<
"expected array of config and/or translatable strings, but index ";
91 error <<
i <<
" was a " << lua_typename(L, lua_type(L, -1));
92 return luaL_argerror(L, 2, error.str().c_str());
95 if(opt[
"default"].to_bool(
false)) {
96 options.chosen_option =
i - 1;
98 options.option_list.push_back(option);
101 lua_getfield(L, 2,
"default");
102 if(lua_isnumber(L, -1)) {
103 int i = lua_tointeger(L, -1);
104 if(
i < 1 || std::size_t(
i) >
n) {
105 std::ostringstream error;
106 error <<
"default= key in options list is not a valid option index (1-" <<
n <<
")";
107 return luaL_argerror(L, 2, error.str().c_str());
109 options.chosen_option =
i - 1;
115 const std::string& title = def_cfg[
"title"];
116 const std::string& message = def_cfg[
"message"];
119 std::unique_ptr<portrait> left;
120 std::unique_ptr<portrait> right;
121 const bool is_double = def_cfg.
has_attribute(
"second_portrait");
122 const bool left_side = def_cfg[
"left_side"].to_bool(
true);
123 if(is_double || left_side) {
124 left.reset(
new portrait {def_cfg[
"portrait"], def_cfg[
"mirror"].to_bool(
false)});
127 right.reset(
new portrait {def_cfg[
"portrait"], def_cfg[
"mirror"].to_bool(
false)});
130 right.reset(
new portrait {def_cfg[
"second_portrait"], def_cfg[
"second_mirror"].to_bool(
false)});
135 if(!has_input && options.option_list.empty()) {
136 lua_pushinteger(L, dlg_result);
138 lua_pushinteger(L, options.chosen_option + 1);
142 lua_pushlstring(L, input.
text.c_str(), input.
text.length());
159 std::string
image = lua_isnoneornil(L, 3) ?
"" : luaL_checkstring(L, 3);
182 std::string theme_id = luaL_checkstring(L, 1);
194 std::vector<config> items = lua_check<std::vector<config>>(L, 1);
199 if(lua_isnumber(L, 2)) {
200 initial = lua_tointeger(L, 2) - 1;
202 }
else if(lua_isnumber(L, 3)) {
203 initial = lua_tointeger(L, 3) - 1;
205 }
else if(lua_isboolean(L, 2)) {
220 std::string button = luaL_optstring(L, 3,
"ok"), btn_style;
221 std::transform(button.begin(), button.end(), std::inserter(btn_style, btn_style.begin()), [](
char c) { return std::tolower(c); });
224 utils::optional<button_style> style;
225 if(btn_style.empty()) {
226 style = button_style::auto_close;
227 }
else if(btn_style ==
"ok") {
228 style = button_style::ok_button;
229 }
else if(btn_style ==
"close") {
230 style = button_style::close_button;
231 }
else if(btn_style ==
"ok_cancel") {
232 style = button_style::ok_cancel_buttons;
233 }
else if(btn_style ==
"cancel") {
234 style = button_style::cancel_button;
235 }
else if(btn_style ==
"yes_no") {
236 style = button_style::yes_no_buttons;
240 if(style == button_style::ok_cancel_buttons || style == button_style::yes_no_buttons) {
265 const size_t len = lua_rawlen(L, idx);
266 if (!lua_istable(L, idx)) {
267 return luaL_error(L,
"List of unit types not specified!");
270 std::vector<const unit_type*> types;
272 for (
size_t i = 1;
i <= len;
i++) {
273 lua_rawgeti(L, idx,
i);
282 if (!types.empty() && disp !=
nullptr) {
288 if (!cfg[
"title"].empty()) {
289 dlg->set_title(cfg[
"title"]);
292 if (!cfg[
"ok_label"].empty()) {
293 dlg->set_ok_label(cfg[
"ok_label"]);
296 if (!cfg[
"cancel_label"].empty()) {
297 dlg->set_cancel_label(cfg[
"cancel_label"]);
300 if (!cfg[
"help_topic"].empty()) {
301 dlg->set_help_topic(cfg[
"help_topic"]);
305 if(dlg->show() && dlg->is_selected()) {
310 ERR_LUA <<
"Unable to show recruit dialog";
320 const size_t len = lua_rawlen(L, idx);
321 if (!lua_istable(L, idx)) {
322 return luaL_error(L,
"List of units not specified!");
325 std::vector<unit_const_ptr> units;
327 for (
size_t i = 1;
i <= len;
i++) {
328 lua_rawgeti(L, idx,
i);
337 if (!units.empty() && disp !=
nullptr) {
343 if (!cfg[
"title"].empty()) {
344 dlg->set_title(cfg[
"title"]);
347 if (!cfg[
"ok_label"].empty()) {
348 dlg->set_ok_label(cfg[
"ok_label"]);
351 if (!cfg[
"cancel_label"].empty()) {
352 dlg->set_cancel_label(cfg[
"cancel_label"]);
355 if (!cfg[
"help_topic"].empty()) {
356 dlg->set_help_topic(cfg[
"help_topic"]);
360 if(dlg->show() && dlg->is_selected()) {
361 luaW_pushunit(L, units[dlg->get_selected_index()]->underlying_id());
365 ERR_LUA <<
"Unable to show recall dialog";
385 std::string
type = luaL_checkstring(L, 1);
386 std::string
id = luaL_checkstring(L, 2);
389 lua_kernel_base::get_lua_kernel<lua_kernel_base>(L).add_widget_definition(
type,
id);
391 }
catch(
const std::invalid_argument&
e) {
392 return luaL_argerror(L, 1,
e.what());
399 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
400 lk.add_log(
"Adding gui module...\n");
401 static luaL_Reg
const gui_callbacks[] = {
411 {
nullptr,
nullptr },
413 std::vector<lua_cpp::Reg>
const cpp_gui_callbacks {
418 luaL_setfuncs(L, gui_callbacks, 0);
421 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
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
const team & playing_team() const
static display * get_singleton()
Returns the display object if a display object exists.
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)
static std::unique_ptr< units_dialog > build_recruit_dialog(const std::vector< const unit_type * > &recruit_list, const team &team)
static std::unique_ptr< units_dialog > build_recall_dialog(std::vector< unit_const_ptr > &recall_list, const team &team)
Helper class for message options.
int intf_show_lua_console(lua_State *L)
A single unit type that the player may recruit.
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")
unit_ptr luaW_tounit_ptr(lua_State *L, int index, bool only_on_map)
Similar to luaW_tounit but returns a unit_ptr; use this instead of luaW_tounit when using an api that...
lua_unit * luaW_pushunit(lua_State *L, Args... args)
const unit_type * luaW_tounittype(lua_State *L, int idx)
Test if a stack element is a unit type, and return it if so.
void luaW_pushunittype(lua_State *L, const unit_type &ut)
Create a lua object containing a reference to a unittype, and a metatable to access the properties.
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.
int intf_show_recall_dialog(lua_State *L)
int intf_show_recruit_dialog(lua_State *L)
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="")
std::shared_ptr< const unit > unit_const_ptr
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