36 #ifdef GUI2_EXPERIMENTAL_LISTBOX
62 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
71 static scoped_dialog *current;
73 typedef std::map<gui2::twidget *, int> callback_map;
74 callback_map callbacks;
79 scoped_dialog(
const scoped_dialog &);
82 scoped_dialog *scoped_dialog::current =
nullptr;
97 scoped_dialog::~scoped_dialog()
113 if (!scoped_dialog::current) {
115 error_call_destructors_1:
117 error_call_destructors_2:
119 error_call_destructors_3:
127 #ifdef GUI2_EXPERIMENTAL_LISTBOX
128 if (gui2::tlist *
l = dynamic_cast<gui2::tlist *>(w))
135 goto error_call_destructors_1;
136 int n =
l->get_item_count();
139 goto error_call_destructors_1;
144 w =
l->get_row_grid(v - 1);
150 goto error_call_destructors_1;
151 int n =
l->get_page_count();
154 goto error_call_destructors_1;
159 w = &
l->page_grid(v - 1);
168 goto error_call_destructors_1;
171 goto error_call_destructors_1;
179 w = tvn.
find(m,
false);
188 goto error_call_destructors_1;
191 goto error_call_destructors_1;
193 w = &tvn->get_child_at(v - 1);
199 w = tvn->
find(m,
false);
205 if (!m)
goto error_call_destructors_2;
206 w = w->
find(m,
false);
208 if (!w)
goto error_call_destructors_3;
235 int v = scoped_dialog::current->window->show(
true, 0);
258 const std::string& input_caption = txt_cfg[
"label"];
260 unsigned int input_max_len = txt_cfg[
"max_length"].to_int(256);
262 std::vector<gui2::twml_message_option>
options;
263 int chosen_option = -1;
267 for(
size_t i = 1;
i <=
n;
i++) {
278 opt[
"image"] = item.
icon();
279 opt[
"label"] = item.
label();
282 if(!opt[
"image"].blank() || !opt[
"description"].blank() || !opt[
"default"].blank()) {
284 if(opt_str.find_first_of(
'=') == std::string::npos) {
286 ERR_LUA <<
"[option]message= is deprecated, use label= instead.\n";
288 ERR_LUA <<
"The &image=col1=col2 syntax is deprecated, use new DescriptionWML instead.\n";
292 std::ostringstream
error;
293 error <<
"expected array of config and/or translatable strings, but index ";
298 if(opt[
"default"].to_bool(
false)) {
299 chosen_option =
i - 1;
301 options.push_back(option);
307 if(i < 1 ||
size_t(i) > n) {
308 std::ostringstream
error;
309 error <<
"default= key in options list is not a valid option index (1-" << n <<
")";
312 chosen_option = i - 1;
321 const bool left_side = def_cfg[
"left_side"].to_bool(
true);
322 const bool mirror = def_cfg[
"mirror"].to_bool(
false);
325 left_side, video, title, message, portrait, mirror,
326 has_input, input_caption, &input_text, input_max_len,
327 options, &chosen_option
330 if (!has_input && options.empty()) {
369 #ifdef GUI2_EXPERIMENTAL_LISTBOX
370 if (gui2::tlist *
l = dynamic_cast<gui2::tlist *>(w))
376 int n =
l->get_item_count();
377 if (1 <= v && v <= n)
378 l->select_row(v - 1);
385 int n =
l->get_page_count();
386 if (1 <= v && v <= n)
387 l->select_page(v - 1);
393 if(
s->num_states() == 2) {
403 t->set_value(text.
str());
408 const int m =
s->get_minimum_value();
409 const int n =
s->get_maximum_value();
410 if (m <= v && v <= n)
418 if (0 <= v && v <= 100)
419 p->set_percentage(v);
443 #ifdef GUI2_EXPERIMENTAL_LISTBOX
444 if (gui2::tlist *
l = dynamic_cast<gui2::tlist *>(w))
454 if(
s->num_states() == 2) {
467 std::vector<int>
path = tv->selected_item()->describe_path();
469 for(
size_t i =0;
i < path.size(); ++
i) {
484 if(pos >= node.
size()) {
487 if(number <= 0 || number + pos > node.
size()) {
507 #ifdef GUI2_EXPERIMENTAL_LISTBOX
508 if (gui2::tlist *
l = dynamic_cast<gui2::tlist *>(w))
513 l->remove_row(pos, number);
515 l->remove_page(pos, number);
519 remove_treeview_node(*tvn, pos, number);
531 scoped_dialog::callback_map &
m = scoped_dialog::current->callbacks;
532 scoped_dialog::callback_map::const_iterator
i = m.find(&w);
533 if (i == m.end())
return;
536 lua_State *L = scoped_dialog::current->L;
546 struct tdialog_callback_wrapper
565 scoped_dialog::callback_map &
m = scoped_dialog::current->callbacks;
581 static tdialog_callback_wrapper wrapper;
582 c->connect_click_handler(std::bind(
583 &tdialog_callback_wrapper::forward
589 #ifdef GUI2_EXPERIMENTAL_LISTBOX
590 else if (gui2::tlist *
l = dynamic_cast<gui2::tlist *>(w)) {
591 static tdialog_callback_wrapper wrapper;
594 &tdialog_callback_wrapper::forward
650 std::vector<gui2::tcanvas> &cv = c->
canvas();
651 if (i < 1 ||
unsigned(i) > cv.size())
655 cv[i - 1].set_cfg(cfg);
667 scoped_dialog::current->window->keyboard_capture(w);
696 tvisible::scoped_enum
flag = tvisible::visible;
702 : tvisible::invisible;
707 if(str ==
"visible") {
708 flag = tvisible::visible;
709 }
else if(str ==
"hidden") {
710 flag = tvisible::hidden;
711 }
else if(str ==
"invisible") {
712 flag = tvisible::invisible;
714 return luaL_argerror(L, 1,
"string must be one of: visible, hidden, invisible");
728 if(flag == tvisible::hidden) {
731 scoped_dialog::current->window->invalidate_layout();
746 inspect_dialog.
show(video);
761 static const std::map<std::string, string_map>
data;
766 twn = &tw->get_root_node();
772 twn->
add_child(node_type, data, insert_pos);
int intf_set_dialog_active(lua_State *L)
Sets a widget's state to active or inactive.
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
#define lua_isnoneornil(L, n)
int show_lua_console(lua_State *, CVideo &video, lua_kernel_base *lk)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
size_t size() const
The "size" of the widget.
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
int intf_add_dialog_tree_node(lua_State *L)
Sets a widget's state to active or inactive.
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
LUA_API int lua_type(lua_State *L, int idx)
static void display(CVideo &video, lua_kernel_base *lk)
Display a new console, using given video and lua kernel.
twindow * build(CVideo &video, const twindow_builder::tresolution *definition)
Builds a window.
LUA_API void lua_pushboolean(lua_State *L, int b)
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
static l_noret error(LoadState *S, const char *why)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
void connect_signal_notify_modified(tdispatcher &dispatcher, const tsignal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
LUA_API int lua_gettop(lua_State *L)
virtual void set_label(const t_string &label)
#define lua_tointeger(L, i)
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
Class for a single line text area.
const std::string number
template to number regex
int intf_remove_dialog_item(lua_State *L)
Removes an entry from a list.
int intf_set_dialog_markup(lua_State *L)
Enables/disables Pango markup on the label of a widget of the current dialog.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
ttree_view_node & add_child(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
Adds a child item to the list of child nodes.
Definitions for the interface to Wesnoth Markup Language (WML).
int intf_set_dialog_focus(lua_State *L)
Sets a widget to have the focus.
base class of top level items, the only item which needs to store the final canvases to draw on ...
GLdouble GLdouble GLdouble b
void set_selection_change_callback(std::function< void(twidget &)> callback)
int show_dialog(lua_State *L, CVideo &video)
Displays a window.
virtual void set_use_markup(bool use_markup)
boost::scoped_ptr< sdl::twindow > window
virtual void set_active(const bool active)=0
Sets the control's state.
GLsizei const char ** path
std::map< std::string, t_string > string_map
bool luaW_toboolean(lua_State *L, int n)
GLubyte GLubyte GLubyte GLubyte w
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
This file contains the canvas object which is the part where the widgets draw (temporally) images on...
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
int show_message_dialog(lua_State *L, CVideo &video)
Displays a message window.
static gui2::twidget * find_widget(lua_State *L, int i, bool readonly)
LUA_API void lua_remove(lua_State *L, int idx)
int intf_set_dialog_canvas(lua_State *L)
Sets a canvas on a widget of the current dialog.
Helper class for message options.
LUA_API void lua_pushnil(lua_State *L)
Small abstract helper class.
static lg::log_domain log_scripting_lua("scripting/lua")
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
bool luaW_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
int intf_set_dialog_value(lua_State *L)
Sets the value of a widget on the current dialog.
LUA_API void lua_rawset(lua_State *L, int idx)
ttree_view_node & get_root_node()
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
int show_wml_message(const bool left_side, CVideo &video, const std::string &title, const std::string &message, const std::string &portrait, const bool mirror, const bool has_input, const std::string &input_caption, std::string *input_text, const unsigned maximum_length, const std::vector< twml_message_option > &option_list, int *chosen_option)
Helper function to show a portrait.
static const char * dlgclbkKey
int show_popup_dialog(lua_State *L, CVideo &video)
Displays a popup message.
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
#define lua_tostring(L, i)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
std::vector< tcanvas > & canvas()
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API int lua_isnumber(lua_State *L, int idx)
#define lua_call(L, n, r)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
int intf_set_dialog_callback(lua_State *L)
Sets a callback on a widget of the current dialog.
Base class for all visible items.
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
LUA_API size_t lua_rawlen(lua_State *L, int idx)
#define LUA_REGISTRYINDEX
A variable-expanding proxy for the config class.
this module manages the cache of images.
Standard logging facilities (interface).
GLsizei GLenum GLuint GLuint GLsizei char * message
void remove_node(ttree_view_node *tree_view_node)
int intf_get_dialog_value(lua_State *L)
Gets the value of a widget on the current dialog.
const std::string & str() const
ttree_view_node & get_child_at(int index)
int show_gamestate_inspector(CVideo &video, const vconfig &cfg)
A config object defines a single node in a WML file, with access to child nodes.
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *tname)
LUA_API void lua_rawget(lua_State *L, int idx)
GLsizei const GLcharARB ** string
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
void dialog_callback(twidget &caller)
Template for dialog callbacks.
int intf_set_dialog_visible(lua_State *L)
Sets the visiblity of a widget in the current dialog.
LUA_API const char * lua_typename(lua_State *L, int t)
#define luaL_checkstring(L, n)