PDA

View Full Version : Dynamic dropdown/cycler examples?



celestian
April 16th, 2017, 06:54
Are there any good examples of a "dynamic" drop down and/or cycler menu?

My goal is to have a list of "weapon skills" that the player can associate with a weapon and gain special bonuses because of that skill. I plan to let the player set those values to the weapon from the "actions" tab per weapon (much like you set ranged/melee, tohit/damage, infact might be from that menu).

The list of weapon skills will be completely dependent on if the player added the skill or not. Example weapon skills would be "proficient" and then "specialized" and maybe double specialized and/or mastery/etc. Or racial bonuses that improve skills for certain types.

So what I need to have is a dynamic menu list of weapon skills for the player to be able to select from.

Are there any rulesets that have a dynamic menu list like this I could look at ?

Moon Wizard
April 16th, 2017, 07:46
There are a few options:

Combo Box (Drop Down / Drop Up) (base templates: combobox / comboboxc)
* 3.5E/5E campaign list specific field filters (see Item and NPC lists)
* Language font selection (see Options->Language window)
* 3.5E/4E/5E party sheet group rolls

Radio Buttons (base template: buttongroup_radio)
* 3.5E NPC creature/trap/vehicle toggle
* 4E NPC/Item/Encounter toggles

Cyclers (base templates: button_stringcycler / button_iconcycler)
* Used heavily on 3.5E/4E/5E PC sheets for ability selection among other things
* Options window

Hope that helps,
Regards,
JPG

celestian
April 16th, 2017, 16:33
There are a few options:

Combo Box (Drop Down / Drop Up) (base templates: combobox / comboboxc)
* 3.5E/5E campaign list specific field filters (see Item and NPC lists)
* Language font selection (see Options->Language window)
* 3.5E/4E/5E party sheet group rolls

Radio Buttons (base template: buttongroup_radio)
* 3.5E NPC creature/trap/vehicle toggle
* 4E NPC/Item/Encounter toggles

Cyclers (base templates: button_stringcycler / button_iconcycler)
* Used heavily on 3.5E/4E/5E PC sheets for ability selection among other things
* Options window

Hope that helps,
Regards,
JPG


I think you're talking about just drop downs and cyclers with static data. That's kinda my problem. I can use cyclers and drop downs with data that a user doesn't enter, like a static list of skills/etc. What I need is if a player adds skill a, skill c and skill z that the cycler will only list those. While another player in the same game might have skill c, skill j and skill b.

Another example would be building a drop down that would let the player select a ammo (arrow, arrow+1 or holy water) from his inventory and then the system could be configured to manage the amount of ammo that is used directly from inventory.

I'm going to re-review what I've looked at (party sheet) and see if I can hack it to work with how I need.

Bidmaron
April 17th, 2017, 00:04
celestial, look at the window list code. It builds a dropdown of group names you can select from, and it is 'dynamic' as you call it in that it is not a fixed set of options at all.

Moon Wizard
April 17th, 2017, 00:35
Also, you can use the combobox code, and rebuild the list when the underlying available options change. You'll also need to update any underlying field which tracks the user's current choice when the combobox changes, or when an existing choice is removed.

Regards,
JPG

celestian
April 17th, 2017, 02:05
Also, you can use the combobox code, and rebuild the list when the underlying available options change. You'll also need to update any underlying field which tracks the user's current choice when the combobox changes, or when an existing choice is removed.

Regards,
JPG

This is actually what I've been sorting out today. Took me a bit to realize having a "up" box in a list window wasn't ever gonna show anything but once I started using "down" it's been lots of progress.

Once I get this looking a bit better I'll post the lua/xml for how I ended up doing it.

Moon Wizard
April 17th, 2017, 02:43
It depends on the placement of the combo box. Because a control can not extend outside the window layout space, any combo list box which projects past the edge of the window containing it will be clipped.

JPG

celestian
April 17th, 2017, 16:45
So, the goal is to have a dynamic list of abilities that the player has on their character sheet and reference them in the weapon configuration so we can apply those modifiers to that attack. Here is what it looks like.


https://i.imgur.com/KtPTk9G.png

With dropdown opened.
https://i.imgur.com/o3Byi3J.png

The end result worked for my goals. Here is the majority of the code I used to add it. There are obviously some bits missing for applying it on attacks and such. This is just so others can see an example of dynamic drop down lists. I plan to eventually use something similar to manage inventory of ammo.

XML from record_char_weapon.xml



<!-- included as point of ref only -->
<label_fieldtop>
<anchored to="prof" />
<static textres="weapon_label_atkprof" />
</label_fieldtop>
<!-- end point of ref entry -->

<!-- prof entries -->
<header_column name="header_prof">
<static textres="weapon_header_prof" />
<center />
</header_column>
<button_iadd name="prof_list_iadd">
<anchored to="header_prof" position="insidetopright" offset="-5,0" />
<target>prof_list</target>
</button_iadd>

<list_editor_grouped name="prof_list">
<datasource>.proflist</datasource>
<class>char_weapon_prof_entry</class>
<script>
function addEntry(bFocus)
local n = getWindowCount();

local w = createWindow();
if w then
if bFocus then
w.profselected.setFocus();
end
end

return w;
end
</script>
</list_editor_grouped>

<label_fieldtop>
<anchored to="prof_list" position="aboveleft" offset="5,1" width="200" />
<static textres="weapon_label_profname" />
</label_fieldtop>
<label_fieldtop>
<anchored to="prof_list" position="aboveleft" offset="224,1" width="30" />
<tooltip textres="weapon_label_hitadj_tooltip" />
<static textres="weapon_label_hitadj" />
</label_fieldtop>
<label_fieldtop>
<anchored to="prof_list" position="aboveleft" offset="283,1" width="35" />
<tooltip textres="weapon_label_dmgadj_tooltip" />
<static textres="weapon_label_dmgadj" />
</label_fieldtop>

<!-- included as point of ref only -->
<header_column name="header_damage">
<static textres="weapon_header_damage" />
<center />
</header_column>
<!-- end point of ref entry -->


And then the window class for the new prof section



<!-- weapon prof selection -->
<windowclass name="char_weapon_prof_entry">
<margins control="0,0,0,5" />
<sheetdata>
<genericcontrol name="rightanchor">
<anchored width="0" height="0">
<top offset="2" />
<right />
</anchored>
<invisible />
</genericcontrol>

<button_idelete name="idelete">
<anchored to="rightanchor">
<top />
<right anchor="left" relation="relative" offset="-5" />
</anchored>
</button_idelete>

<combobox name="profselected">
<listdirection>down</listdirection>
<anchored position="insidetopleft" offset="5,2" width="200" height="20" />
<!-- <default textres="weapon_label_profdefault" /> -->
<script file="campaign/scripts/prof_select.lua"/>
</combobox>
<label name="label_plus">
<anchored to="profselected" position="righthigh" offset="5,0" width="10" />
<static>+</static>
</label>
<number_adjustment name="hitadj">
<readonly />
<anchored to="label_plus" position="righthigh" offset="2,0" width="35" height="20" />
</number_adjustment>
<label name="label_plus2">
<anchored to="hitadj" position="righthigh" offset="10,0" width="15" />
<static>&amp;</static>
</label>
<number_adjustment name="dmgadj">
<readonly />
<anchored to="label_plus2" position="righthigh" offset="2,0" width="35" height="20" />
</number_adjustment>

</sheetdata>
</windowclass>



LUA code for the xml above.


--
-- Code to manage combox box selection in record_char_weapon.xml
--
--
--
function onInit()
super.onInit();
local node = getDatabaseNode();
local nodeChar = node.getChild("......");
-- this should cause the values to update should the player tweak their profs.
DB.addHandler(DB.getPath(nodeChar, "proficiencylist"),"onChildUpdate", updateAllAdjustments);

updateAllAdjustments();
end

function onClose()
local node = getDatabaseNode();
local nodeChar = node.getChild("......");
DB.removeHandler(DB.getPath(nodeChar,"proficiencylist"),"onChildUpdate", updateAllAdjustments);
end

-- when value changed, update hit/dmg
function onValueChanged()
local node = getDatabaseNode();
updateAdjustments(node);
end

-- update hit/damage adjustments from Proficiency in the abilities tab
function updateAdjustments(node)
-- update hit/dmg modifiers for prof
-- flip through proflist
local nodeChar = node.getChild("......");
local sFindName = window.profselected.getValue();
local prof = getProf(nodeChar,sFindName);

if prof then
local nHitAdj = prof.hitadj;
local nDMGAdj = prof.dmgadj;
window.hitadj.setValue(nHitAdj);
window.dmgadj.setValue(nDMGAdj);
else
--Debug.console("prof_select.lua","updateAdjustments","!prof");
end
end


-- update all adjustments for this weapon
-- we do this when a proficiency is updated in the abilities tab
function updateAllAdjustments()
-- update hit/dmg modifiers
-- flip through proflist
local node = getDatabaseNode();
local nodeWeapon = node.getChild("....");
local nodeChar = node.getChild("......");
setProfList(nodeChar);

for _,v in pairs(DB.getChildren(nodeWeapon, "proflist")) do
local svName = DB.getValue(v,"profselected","Unnamed");
local prof = getProf(nodeChar,svName);
if prof then
local nHitAdj = prof.hitadj;
local nDMGAdj = prof.dmgadj;
DB.setValue(v,"hitadj","number",nHitAdj);
DB.setValue(v,"dmgadj","number",nDMGAdj);
end
end
end

-- fill in the drop down list values
function setProfList(nodeChar)
-- sort through player's list of profs and add them
-- proficiencylist
local aProfs = {};
local bNonProf = false;
for _,v in pairs(DB.getChildren(nodeChar, "proficiencylist")) do
local sName = DB.getValue(v, "name", "");
local sNameLower = sName:lower();
if (sName ~= "") then
-- at some point this will be a default prof, applies
-- the non-proficiency adjustment
if StringManager.contains({"not-prof", "non-prof","non prof", "not prof"}, sNameLower) then
bNonProf = true;
end
-- add to list of profs
table.insert(aProfs,sName);
end
end

-- if not bNonProf then
-- table.insert(aProfs,"Not-Proficient");
-- end

clear(); -- (removed existing items in list)
addItems(aProfs); -- add prof list to drop down
end

-- get prof hit/dmg adjustments by name of prof
function getProf(nodeChar,sFindName)
local sFindNameLower = sFindName:lower();
local prof = {};
prof.name = sFindName;

local bFoundMatch = false;
for _,v in pairs(DB.getChildren(nodeChar, "proficiencylist")) do
local sName = DB.getValue(v, "name", "");
local sNameLower = sName:lower();
if (sNameLower == sFindNameLower) then
bFoundMatch = true;
prof.hitadj = DB.getValue(v,"hitadj",0);
prof.dmgadj = DB.getValue(v,"dmgadj",0);
break;
end
end

if bFoundMatch then
return prof;
else
return nil;
end
end


Hopefully useful to someone else... at the very least was fun to figure out. I swear I spent more time figuring out the "up" version of a combobox not working in a window list "list" because the "list" filled "down". Don't be like me ;)

leozelig
April 17th, 2017, 17:01
Cool feature, celestian. Thanks for the walkthrough!