[GUI] selecting multipage

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
white_haired_uncle
Posts: 1230
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

[GUI] selecting multipage

Post by white_haired_uncle »

Currently, I'm doing this:

Code: Select all

dialog.unit_info_mp:add_item_of_type("empty_page")
dialog.unit_info_mp:add_item_of_type("unit_info_page")
...
dialog.unit_info_mp[2].unit_info_preview.unit = wesnoth.units.find{ id = unit.id }[1]
dialog.unit_info_mp.selected_index = 2
I'd like to be doing this:

Code: Select all

empty_item, empty_pos = dialog.unit_info_mp:add_item_of_type("empty_page")
unit_item, unit_pos = dialog.unit_info_mp:add_item_of_type("unit_info_page")
...
unit_item.unit_info_preview.unit = wesnoth.units.find{ id = unit.id }[1]
dialog.unit_info_mp.selected_index = unit_pos
However, I believe add_item_of_type is currently broken, always returning -1 for pos.

https://github.com/wesnoth/wesnoth/issues/8490

Is there an alternative to selected_index that uses item instead of position, or can I somehow get the (real) position from item, for example:

Code: Select all

dialog.unit_info_mp.selected_item = item
or

Code: Select all

dialog.unit_info_mp.selected_index = item.pos
I don't think those examples make a lot of sense, but hopefully they convey what I'm trying to accomplish.

It's really not a big deal either way, I'm just trying to break a bad habit before it takes hold.
Speak softly, and carry Doombringer.
Post Reply