mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-21 16:40:18 +00:00

lua now has a widget userdata that can be used to set/get widgets properties as one would expect, a lot of the set/get_dialog_xy function were converted into modifiable properties of the widget userdata. This in particular allows us to get rid of the strange 'path to widget' type of arguments of gui2 functions. It currently generates lot of compiler wanrings, I will fix this in a later commit. One of the main advantage is that it makes it much easier to add new api, previously a lot of functions where overused, probably because that was just easier than creatign a new function. For example set_dialog_value returned multiple value of listbox objects. (the compatibility path doesn't support this particular feature yet but i don't think it is important, it probably wasn't even used at all, since it also wasn't documented). This also adds some new features, like an 'add_item' function to add an item to a listbox, a 'type' property of widgets to query the type of a widget and a 'item_count' property to count the number of children in an item. Im still not 100% sure about the property /function names, in particular: 1) i might rename 'items' to 'elements' or 'children' in some functions. Not sure yet 2) I might rename the 'value' property to 'value_compat' to make clear that its only supposed to be used by the backwards_compat.lua code. A next step in improving this api might be to introduce a (reusable!) 'window' userdata so that the implementaion of wesnoth.show_dialog would become: ``` function wesnoth.show_dialog(wml, preshow, postshow) local dialog = gui.create_dialog(wml) preshow(dialog) local res = dialog:show() postshow(dialog) return res end ``` However this is currently not really possble since the pure existance of a gui2::window object blocks the gui1 code (the main game view) from receiving events. So we clearly cannot luas gc take ownership of gui2::window objects.