vultraz's lua questions
Moderator: Forum Moderators
Re: vultraz's lua questions
Here's the full code so as to avoid confusion:
The other set_dialogue_value s are for other parts of the code.
Code: Select all
-- This brings up the custom inventory control window
function wml_actions.inventory_controller(cfg)
local item_list = T.listbox { id = "inventory_list",
definition = "default",
T.list_definition { T.row { T.column { vertical_grow = "true",
horizontal_grow = "true",
T.toggle_panel { T.grid { T.row { T.column { grow_factor = 0,
horizontal_alignment = "left",
border = "all",
border_size = 5,
T.toggle_button { id = "checkbox",
definition = "default",
linked_group = "checkbox" } },
T.column { grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.image { id = "image",
definition = "default" } },
T.column { grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.label { id = "name",
definition = "default",
linked_group = "name" } } } } } } } } }
--T.list_data { temp_list_data } }
local main_window = { T.helptip { id="tooltip_large" }, -- mandatory field
T.tooltip { id="tooltip_large" }, -- mandatory field
window_height = 600,
window_width = 700,
T.grid { T.row { growth_factor = 0,
T.column { grow_factor = 1,
horizontal_alignment = "left",
border = "all",
border_size = 5,
T.label { definition = "title",
label = _"Inventory" } },
T.column { T.spacer { definition = "default" } },
T.column { T.spacer { definition = "default" } } },
T.row { T.column { T.grid { T.row { item_list } } },
T.column { T.spacer { definition = "default" } },
T.column { T.spacer { definition = "default" } } },
T.row { T.column { vertical_alignment = "center",
horizontal_alignment = "center",
border = "all",
border_size = 5,
T.image { id = image } },
T.column { vertical_alignment = "top",
horizontal_alignment = "center",
border = "all",
border_size = 5,
T.label { id = "description" } },
T.column { T.grid { T.row { T.column { T.button { id = "switch_button", return_value = 3 } } },
T.row { T.column { T.button { id = "leave_chest_button", return_value = 2 } } },
T.row { T.column { T.button { id = "ok_button", return_value = 1 } } } } } }
} }
local function item_preshow()
local u_id = wesnoth.get_variable("unit.id") -- just to check, is unit a WML variable which contains the name of another WML variable?
local function inventory_category_scan(section) -- changed function name to match usage
for i = 1, wesnoth.get_variable(string.format("%s.%s.length", u_id, section)) do -- using .. works too, but I personally prefer string.format for all but the simplest uses
-- additionally, should this be "%s.variables.%s.length"? (assuming u_id holds the name of a WML variable that contains a stored unit here)
-- also, a for loop seems simpler here, since it only needs to perform the get_variable once
wesnoth.set_dialog_value(wesnoth.get_variable(string.format("%s.%s[%d].name", u_id, section, i - 1)), "inventory_list", i, "name")
wesnoth.set_dialog_value(wesnoth.get_variable(string.format("%s.%s[%d].image", u_id, section, i - 1)), "inventory_list", i, "image")
end
end
inventory_category_scan("items")
inventory_category_scan("weapons")
inventory_category_scan("potions")
wesnoth.set_dialog_value("DESCRIPTION PLACEHOLDER", "description")
wesnoth.set_dialog_value("Switch items", "switch_button")
wesnoth.set_dialog_value("Leave in chest", "leave_chest_button")
wesnoth.set_dialog_value("Exit", "ok_button")
end
local function sync()
local function item_postshow()
end
local return_value = wesnoth.show_dialog( main_window, item_preshow, item_postshow )
return { return_value = return_value }
end
local return_table = wesnoth.synchronize_choice(sync)
end
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: vultraz's lua questions
I see one obvious issue with the widget ids.
This will try to make the id of this widget the string contained in the variable image (which has a fair chance of not existing). You also might want to make your widget ids a little more descriptive; if you changed this one to id = "image", you would have a conflict with another widget (widget ids are supposed to be unique).
Also, you don't need to leave in my comments, most of them are completely unnecessary at this point.
Looking at it again, you declare what linked group a couple of the widgets belong to, but don't actually declare those linked groups? I'm also not sure if a linked group and a widget with identical ids will conflict, and you have a couple of cases of that.
Code: Select all
T.image { id = image } }
Also, you don't need to leave in my comments, most of them are completely unnecessary at this point.
Looking at it again, you declare what linked group a couple of the widgets belong to, but don't actually declare those linked groups? I'm also not sure if a linked group and a widget with identical ids will conflict, and you have a couple of cases of that.
Re: vultraz's lua questions
Thanks for the tips so far
Anyway, I should have said how I was trying to get this to looks and behave before this, because I just realize how complicated this is. I'm not sure it will get finished/completed
-What I'm trying to get the window to appear as: (yes, it is missing one of the buttons. I decided to put it in after I drew that)
-The left column is supposed to be your personal items (that's what the unit.id stuff is for), the right column the shared items (from the container shared_items)
-Behavior:
--I'm not sure we want the two images in the same linked_group (assuming a linked_group means they display the same thing), as the image at the bottom is supposed to be the same image as the currently selected option in the list (not checked in the checkbox). Basically the .image var of the array[index] used to print that item.
--Same as above for the description part (variable .description.
--I realized items could either be carried and in effect or carried and not in effect. This'd need some way to designate that. Maybe have the name text a different color whether it was in use or not.
--Related to above. Instead of making a new button to 'use' the item, I could just make the list entry clickable, which would then change the var and the name's color (like the campaign list). Is that hard?
--The button 'Switch items' it supposed to change the .status var of every item with its checkbox checked to the opposite .status var of the array[index] used to print it (personal --> shared and vice versa). This should make the item switch column, but as the code for printing is only in the preshow event, I'm not sure how to do this. Unless there was a way to force a refresh of the display each time this was done? BTW, this button would be grayed out unless the unit using the inventory was adjacent to another allied hero unit (one with role=hero).
--The 'Leave in chest' button is supposed to behave the same as the 'Switch items' button, except instead of switching the .status var it should delete the respective checked entries, chuck them in some kind of chest_at_x_y var, and place some image in the map designating their presence. Someone else could then pick the items up (reapplying them is a whole other story that I need to figure out. ).
--I had the items separated into sections as I wanted them to be able to be grouped my category when printed. Not sure if this is worth it (might be good to have the .weapons section at least, as the weapons are supposed to be printed out from the unit's weapon list, which would be complicated if I needed another scan function just for that).
==============================================================================================================================================================================
Seems a lot of that relies on knowing the path to the variables that printed each respective option. I guess that shouldn't be too hard...maybe.
I have this partially working in a WML version. I wonder if it would be less hassle to go with that instead of this fancy custom GUI window stuff (though this would be really cool if we could get it to work).
Thank you for your help.
Anyway, I should have said how I was trying to get this to looks and behave before this, because I just realize how complicated this is. I'm not sure it will get finished/completed
-What I'm trying to get the window to appear as:
Spoiler:
-The left column is supposed to be your personal items (that's what the unit.id stuff is for), the right column the shared items (from the container shared_items)
-Behavior:
--I'm not sure we want the two images in the same linked_group (assuming a linked_group means they display the same thing), as the image at the bottom is supposed to be the same image as the currently selected option in the list (not checked in the checkbox). Basically the .image var of the array[index] used to print that item.
--Same as above for the description part (variable .description.
--I realized items could either be carried and in effect or carried and not in effect. This'd need some way to designate that. Maybe have the name text a different color whether it was in use or not.
--Related to above. Instead of making a new button to 'use' the item, I could just make the list entry clickable, which would then change the var and the name's color (like the campaign list). Is that hard?
--The button 'Switch items' it supposed to change the .status var of every item with its checkbox checked to the opposite .status var of the array[index] used to print it (personal --> shared and vice versa). This should make the item switch column, but as the code for printing is only in the preshow event, I'm not sure how to do this. Unless there was a way to force a refresh of the display each time this was done? BTW, this button would be grayed out unless the unit using the inventory was adjacent to another allied hero unit (one with role=hero).
--The 'Leave in chest' button is supposed to behave the same as the 'Switch items' button, except instead of switching the .status var it should delete the respective checked entries, chuck them in some kind of chest_at_x_y var, and place some image in the map designating their presence. Someone else could then pick the items up (reapplying them is a whole other story that I need to figure out. ).
--I had the items separated into sections as I wanted them to be able to be grouped my category when printed. Not sure if this is worth it (might be good to have the .weapons section at least, as the weapons are supposed to be printed out from the unit's weapon list, which would be complicated if I needed another scan function just for that).
==============================================================================================================================================================================
Seems a lot of that relies on knowing the path to the variables that printed each respective option. I guess that shouldn't be too hard...maybe.
I have this partially working in a WML version. I wonder if it would be less hassle to go with that instead of this fancy custom GUI window stuff (though this would be really cool if we could get it to work).
Thank you for your help.
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: vultraz's lua questions
First of all, let me say that the GUI/Lua interface still has some bugs (for example, the Minimap widget did not work at all for me some time ago). Also, the grid structure may be quite confusing.vultraz wrote:Anyway, I should have said how I was trying to get this to looks and behave before this, because I just realize how complicated this is. I'm not sure it will get finished/completed
That said, a quick look to your image suggests me that you'll need at least four grids for your dialog:
- one for the firt inventory column
- one for the second inventory column
- one for the item description
- one for the buttonbox
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: vultraz's lua questions
humm good advice.
anyway, I'm still confused as to these 'widget not found' errors in set_dialogue_value. I know it has the wrong path, but I can't figure what the path is supposed to be. ID of which containing widget? Containing widget name?
anyway, I'm still confused as to these 'widget not found' errors in set_dialogue_value. I know it has the wrong path, but I can't figure what the path is supposed to be. ID of which containing widget? Containing widget name?
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: vultraz's lua questions
The "container widget" is the listbox itself. So, you must supply both the listbox ID and the widget (label, image...) ID.vultraz wrote:I'm still confused as to these 'widget not found' errors in set_dialogue_value. I know it has the wrong path, but I can't figure what the path is supposed to be. ID of which containing widget? Containing widget name?
In fact, if the listbox has ID "foo" and the label has ID "bar, the wiki says that it should be like this:
Code: Select all
wesnoth.set_dialog_value(_"Hello world", "foo", 7, "bar")
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: vultraz's lua questions
Ok..well....it still doesn't work. For some reason I still get that 'widget not found' error. I'm sure what I'm doing wrong.
Code: Select all
-- This brings up the custom inventory control window
function wml_actions.inventory_controller(cfg)
local item_list = T.listbox { id = "inventory_list",
definition = "default",
T.scrollbar { T.grid { T.row { T.column { T.vertical_scrollbar { } } } } },
T.list_definition { id = "panel_pre",
T.row { T.column { vertical_grow = "true",
horizontal_grow = "true",
T.toggle_panel { id = "panel",
T.grid { T.row { T.column { grow_factor = 0,
horizontal_alignment = "left",
border = "all",
border_size = 5,
T.toggle_button { id = "list_checkbox",
definition = "default",
linked_group = "checkbox" } },
T.column { grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.image { id = "list_image",
definition = "default",
linked_group = "name" } },
T.column { grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.label { id = "list_name",
definition = "default",
linked_group = "name" } } } } } } } } }
--T.list_data { temp_list_data } }
local main_window_temp = { T.helptip { id="tooltip_large" }, -- mandatory field
T.tooltip { id="tooltip_large" }, -- mandatory field
T.linked_group { id = "image",
fixed_height = "true",
fixed_width = "true" },
T.linked_group { id = "checkbox",
fixed_height = "true",
fixed_width = "true" },
T.linked_group { id = "name",
fixed_height = "true",
fixed_width = "false" },
height = 600,
width = 700,
T.grid { T.row { item_list } } }
local function item_preshow()
local u_id = wesnoth.get_variable("unit.id")
local function inventory_category_scan(section)
for i = 1, wesnoth.get_variable(string.format("%s.%s.length", u_id, section)) do
wesnoth.set_dialog_value("checkbox", "inventory_list", i, "list_checkbox")
wesnoth.set_dialog_value(wesnoth.get_variable(string.format("%s.%s[%d].image", u_id, section, i - 1)), "inventory_list", i, "list_image")
wesnoth.set_dialog_value(wesnoth.get_variable(string.format("%s.%s[%d].name", u_id, section, i - 1)), "inventory_list", i, "list_name")
end
end
inventory_category_scan("items")
inventory_category_scan("weapons")
inventory_category_scan("potions")
end
local function sync()
local function item_postshow()
end
local return_value = wesnoth.show_dialog( main_window_temp, item_preshow, item_postshow )
return { return_value = return_value }
end
local return_table = wesnoth.synchronize_choice(sync)
end
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Re: vultraz's lua questions
All right, I simplified as anonymissimus suggested, but this STILL gives errors...Am I terminally stupid, or is there maybe a bug (also a suggestion of anonymissimus)?
SIMPLIFIED TO (FOR TESTING):
SIMPLIFIED TO (FOR TESTING):
Code: Select all
-- This brings up the custom inventory control window
function wml_actions.inventory_controller(cfg)
local item_list = T.listbox { id = "inventory_list",
definition = "default",
T.list_definition { T.row { T.column { vertical_grow = "true",
horizontal_grow = "true",
T.toggle_panel { id = "panel",
T.grid { T.row { T.column { grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.label { id = "list_name",
definition = "default",
linked_group = "name" } } } } } } } } }
--T.list_data { temp_list_data } }
local main_window_temp = { T.helptip { id="tooltip_large" },
T.tooltip { id="tooltip_large" },
T.linked_group { id = "name",
fixed_height = "true",
fixed_width = "false" },
height = 600,
width = 700,
T.grid { T.row { item_list } } }
local function item_preshow()
for i = 1, 5 do
wesnoth.set_dialog_value("NAME TEST", "inventory_list", i, "list_name")
end
end
local function sync()
local function item_postshow()
end
local return_value = wesnoth.show_dialog( main_window_temp, item_preshow, item_postshow )
return { return_value = return_value }
end
local return_table = wesnoth.synchronize_choice(sync)
end
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: vultraz's lua questions
Well, with your simplified test code, I figured out what's wrong:
should be
Making that change gets rid of the error for me, and the 5 test labels show up correctly.
Code: Select all
T.grid { T.row { item_list } } }
Code: Select all
T.grid { T.row { T.column { item_list } } } }
Re: vultraz's lua questions
Augh.....didn't see THAT....oh well....
So I guess at least one column is always mandatory when using a row?
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: vultraz's lua questions
Yeah, the layout rules are pretty strict (if you haven't read it already, http://wiki.wesnoth.org/GUILayout may help). And I stared at that missing column for a pretty long time before I saw it, too.
Re: vultraz's lua questions
OK thanks for all your help so far! It's looking good! I'll post a screenshot soon.
Now what I have to do is try to implement those behaviors I mentioned above But...I have absolutely no idea how to. Help?
Thanks for putting up with my nwebishness
Now what I have to do is try to implement those behaviors I mentioned above But...I have absolutely no idea how to. Help?
Thanks for putting up with my nwebishness
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Re: vultraz's lua questions
For this part:
If it's not supported, that'd be a shame, this Imagepathfunction stuff (http://wiki.wesnoth.org/ImagePathFunctionWML) is pretty cool
You might be able to use the imagepathfunction stuff (if that's supported by the layout/dialog lua) to overlay a star or a glow or something over the item if it's in effect.--I realized items could either be carried and in effect or carried and not in effect. This'd need some way to designate that. Maybe have the name text a different color whether it was in use or not.
If it's not supported, that'd be a shame, this Imagepathfunction stuff (http://wiki.wesnoth.org/ImagePathFunctionWML) is pretty cool
"UM BROK HIT YOU!" -- Um Brok, Swamplings
Re: vultraz's lua questions
Humm...that's an idea thanks.
Also, as I mentioned above, a lot seems to rest on being able to read/write from/to the exact array used to print the option currently selected (like the campaign selection dialogue). How might I do that?
Also, as I mentioned above, a lot seems to rest on being able to read/write from/to the exact array used to print the option currently selected (like the campaign selection dialogue). How might I do that?
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: vultraz's lua questions
You'll need to use wesnoth.get_dialog_value (to read each widget value) and then wesnoth.set_variable or helper.set_variable_array.vultraz wrote:a lot seems to rest on being able to read/write from/to the exact array used to print the option currently selected (like the campaign selection dialogue). How might I do that?
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)