PDA

View Full Version : Combobox troubles...



Oberoten
November 28th, 2015, 06:33
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

Moon Wizard
November 28th, 2015, 21:04
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

celestian
May 17th, 2018, 01:12
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

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.

https://i.imgur.com/6D0evE5.png

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.



-- 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

Moon Wizard
May 17th, 2018, 17:38
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

celestian
May 17th, 2018, 17:44
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

Understood. I suspected as much. Thanks for the information.

celestian
June 17th, 2018, 03:45
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



<?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>



And added getListText() and changed selectItem() (see inline)



-- 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


This creates a value you can reference in your code that uses the name of the entry and append "_selected". In my case the combobox control was called "prof" so it adds the "source" to "prof_selected". The "source" is the value you pass in the add(value,string) for each entry.

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.