44 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
58 auto wp = std::make_unique<gui2::window>(def);
60 if(!lua_isnoneornil(L, 2)) {
68 if (!lua_isnoneornil(L, 3)) {
74 lua_pushinteger(L, v);
82 for(; !lua_isnoneornil(L,
i); ++
i)
86 int v = lua_tointeger(L,
i);
88 throw std::invalid_argument(
"negative index");
90 int n = list->get_item_count();
93 throw std::invalid_argument(
"index out of range");
100 w = list->get_row_grid(v - 1);
102 int v = lua_tointeger(L,
i);
104 throw std::invalid_argument(
"negative index");
106 int n = multi_page->get_page_count();
109 throw std::invalid_argument(
"index out of range");
113 multi_page->add_page(
dummy);
116 w = &multi_page->page_grid(v - 1);
119 if(lua_isnumber(L,
i)) {
120 int v = lua_tointeger(L,
i);
122 throw std::invalid_argument(
"negative index");
126 throw std::invalid_argument(
"index out of range");
131 std::string m = luaL_checkstring(L,
i);
132 w = tvn.
find(m,
false);
135 if(lua_isnumber(L,
i)) {
136 int v = lua_tointeger(L,
i);
138 throw std::invalid_argument(
"negative index");
140 int n = tree_view_node->count_children();
142 throw std::invalid_argument(
"index out of range");
144 w = &tree_view_node->get_child_at(v - 1);
147 std::string m = luaL_checkstring(L,
i);
148 w = tree_view_node->find(m,
false);
151 if(lua_isnumber(L,
i)) {
152 int v = lua_tointeger(L,
i);
154 throw std::invalid_argument(
"negative index");
156 int n = stacked_widget->get_layer_count();
158 throw std::invalid_argument(
"index out of range");
160 w = stacked_widget->get_layer_grid(v - 1);
162 std::string m = luaL_checkstring(L,
i);
163 w = stacked_widget->find(m,
false);
166 char const *m = lua_tostring(L,
i);
168 throw std::invalid_argument(
"expected a string");
170 w =
w->find(m,
false);
173 throw std::invalid_argument(
"widget not found");
196 return mp.get_item_count();
200 return mp.get_page_count();
205 return mp.count_children();
210 return number_of_items(
mp.get_root_node());
215 template<
typename TW
idget>
216 int check_index(lua_State* L,
int arg, TWidget&
w,
bool for_insertion, utils::optional<int>&
index)
218 int nitems = number_of_items(
w);
221 int max = for_insertion ? nitems + 1 : nitems;
226 if(*index <= 0 || *index > max) {
227 luaL_argerror(L, arg,
"widget child index out of range");
242 for(
int i = 0;
i < number; ++
i) {
257 utils::optional<int> pos = lua_check<utils::optional<int>>(L, 2);
258 int number = lua_check<utils::optional<int>>(L, 3).value_or(1);
261 int realpos = check_index(L, 2, *list,
false, pos);
262 list->remove_row(realpos, number);
264 int realpos = check_index(L, 2, *multi_page,
false, pos);
265 multi_page->remove_page(realpos, number);
267 int realpos = check_index(L, 2, *tree_view,
false, pos);
268 remove_treeview_node(tree_view->get_root_node(), realpos, number);
270 int realpos = check_index(L, 2, *tree_view_node,
false, pos);
271 remove_treeview_node(*tree_view_node, realpos, number);
273 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
296 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
307 ERR_LUA <<
"widget was deleted";
312 ERR_LUA <<
"cannot find window in widget callback";
331 throw std::invalid_argument(
"the widget has no window assigned");
333 if(!lua_isfunction(L, 2)) {
334 return luaL_argerror(L, 2,
"callback must be a function");
347 c->connect_click_handler(std::bind(&dialog_callback, L, wp,
"callback"));
357 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
373 int i = luaL_checkinteger(L, 2);
376 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
379 std::vector<gui2::canvas> &cv =
c->get_canvases();
380 if(
i < 1 ||
static_cast<unsigned>(
i) > cv.size()) {
381 return luaL_argerror(L, 2,
"out of bounds");
385 cv[
i - 1].set_cfg(cfg);
414 const std::string node_type = luaL_checkstring(L, 2);
415 utils::optional<int> insert_pos = lua_check<utils::optional<int>>(L, 3);
419 int realpos = check_index(L, 2, *twn,
true, insert_pos);
420 res = &twn->add_child(node_type,
data, realpos);
422 int realpos = check_index(L, 2, *tw,
true, insert_pos);
423 res = &tw->get_root_node().add_child(node_type,
data, realpos);
425 int realpos = check_index(L, 2, *
mp,
true, insert_pos);
426 res = &
mp->add_page(node_type, realpos,
data);
428 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
445 utils::optional<int> insert_pos = lua_check<utils::optional<int>>(L, 2);
451 int realpos = check_index(L, 2, *lb,
true, insert_pos);
452 res = &lb->add_row(
data, realpos);
454 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
472 return luaL_argerror(L, lua_gettop(L),
"unsupported widget");
478 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
479 lk.add_log(
"Adding widgets module...\n");
480 static luaL_Reg
const gui_callbacks[] = {
493 {
nullptr,
nullptr },
496 luaL_setfuncs(L, gui_callbacks, 0);
This file contains the canvas object which is the part where the widgets draw (temporally) images on.
A config object defines a single node in a WML file, with access to child nodes.
Small abstract helper class.
Small abstract helper class.
tree_view & get_tree_view()
tree_view_node & get_child_at(int index)
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
std::size_t count_children() const
The number of children in this widget.
std::pair< std::shared_ptr< tree_view_node >, int > remove_node(tree_view_node *node)
Removes the given node as a child of its parent node.
base class of top level items, the only item which needs to store the final canvases to draw on.
void keyboard_capture(widget *widget)
void close()
Requests to close the window.
Tmust inherit enable_lua_ptr<T>
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.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
Main entry points of multiplayer mode.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void lua_push(lua_State *L, const T &val)
static map_location::direction n