Thread: Combobox troubles...
-
November 28th, 2015, 06:33 #1
Combobox troubles...
Well it has been a while since I bothered with my questions now.
I am currently trying to add a wizard's lab option to the Ars Magica ruleset to simplify for new players when they create their own spells.
I have the basic functions in place but they look somewhat lacking and still confusing. So I have decided to make use of a drop-list for ranges, durations etc.
... this is where I run full tilt into problems.
HOW do I populate the combobox that is offered in the CoreRPG? And how do I get a value back from it once it has been changed?
I am frankly stumped.
- Obe
-
November 28th, 2015, 21:04 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,412
You can find the code in the CoreRPG ruleset under:
* common/scripts/combobox*.lua
* common/template_combobox.xml
You can add items to the combobox using the add or addItems functions:
* The add function accepts a value parameter, with an optional display parameter. The value parameter is what is saved to the database as a string database value. If no display parameter is supplied, the value will also be used as the text to show in the combo box.
* The addItems function accepts a table as a parameter. It assumes a table of strings, and will add each one as a value. You can not override display text with this function.
You can get/set the value of the selected item by using the getListValue and setListValue functions.
Regards,
JPG
-
May 17th, 2018, 01:12 #3
Sorry to necro this but I'm having some issues with the description above.
I am using .add(node.getPath(),sName) to the combobox and this is what I see.
It does show the "string" value on the drop down but the selected section shows the currently selected node.getPath() and not the sName. Is that to be expected?
It does work other than that, this is a visual issue but I'd like to correct it if I can.
If it matters, here is the code I use to fill the combobox.
Code:-- fill in the drop down list values function setProfList(nodeChar) clear(); -- (removed existing items in list) -- sort through player's list of profs and add them -- proficiencylist for _,v in pairs(DB.getChildren(nodeChar, "proficiencylist")) do local sName = DB.getValue(v, "name", ""); add(v.getPath(),sName); end end
---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
May 17th, 2018, 17:38 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,412
Perhaps. The original combo box code was written by another community developer many years ago, and I have just been incorporating and slowly refining the template to work better and for more situations. I can almost guarantee that it was not designed for as many "use cases" as it has seen.
In this case, this is a limitation of the original design, which uses a stringfield as the base control. This means that whatever database value is stored will be what is displayed in the base value box.
I think you'll need to define a custom input template/control to do what you need.
Regards,
JPG
-
May 17th, 2018, 17:44 #5---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
June 17th, 2018, 03:45 #6
So, I have a working solution. It's not my favorite but I think for the return on investment it works well.
I replaced the combobox.lua with my own. First I tweaked the combo template to use my version of the combobox.lua
Code:<?xml version="1.0" encoding="iso-8859-1"?> <!-- Please see the license.html file included with this distribution for attribution and copyright information. --> <root> <template name="combobox" merge="join"> <simplestring> <script file="common/scripts/combobox_adnd.lua" mergerule="replace"/> </simplestring> </template> </root>
Code:-- grab text of this selection option function getListText() if wListItemSelected then return wListItemSelected.Text.getValue(); end return ""; end function selectItem(wNewSelection) if not ctrlList then return; end if wListItemSelected == wNewSelection then return; end if wListItemSelected then wListItemSelected.setSelected(false); end if wNewSelection then wNewSelection.setSelected(true); end wListItemSelected = wNewSelection; local sListValue = getListValue(); local sListText = getListText(); if getValue() ~= sListText then -- set source selected, since visible version is not the same -- get the name of this node, create a entry with same name_selected local sSourceNode = getName() .. "_selected"; local node = getDatabaseNode(); DB.setValue(node.getParent(),sSourceNode,"string",sListValue); setValue(sListText); end end
add("charsheet.id-00001.proficiencylist.id-00001","Weapon Proficiency with Long Sword")
add("charsheet.id-00001.proficiencylist.id-00002","Weapon Proficiency with Short Sword")
add("charsheet.id-00001.proficiencylist.id-00003","Weapon Proficiency with Dagger")
It displays the "Weapon Proficiency with *" string but lets you access the "value" (node path) programmatically.---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks