celestian
March 21st, 2017, 00:38
I've coded a method to hide spells from the action window listing (powers->*power_item*) when the spells are memorized and it works except I get a bit of extra space. I've tried to find the cause (double checked I've hidden all the items in power_item when needed) but no joy.... so I thought I'd see if perhaps there was a way to just flat out hide a windowlist item entry. I suspect not but google perhaps might have failed me.
"powers" is a windowlist. Each item listed is a spell and displayed via "power_item" (both record_power.xml if you have the 5e ruleset).
Is there a method with the listed usage that would let me hide a child item of powers.windows()?
Or must I do it for each item (as I do in the onModeChanged()).
I was hoping if I could do it by windowlist item instead somehow I could bypass trying to figure out what is causing the "extra" space".
This is mostly all 5e ruleset code cept for the "mode change" but I'll post.
The template used for "powers"
<template name="list_powers">
<windowlist>
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="5" />
<left />
<right />
</anchored>
<datasource>.powers</datasource>
<class>power_item</class>
<noscroll />
<footer>footer_wide</footer>
<script file="campaign/scripts/power_list.lua" />
</windowlist>
</template>
The power_item (where the items are listed)
<windowclass name="power_item">
<margins control="0,0,0,2" />
<script file="campaign/scripts/power_item.lua" />
<sheetdata>
<hs name="group" />
<hn name="level" />
<hs name="type" />
<hs name="name" />
<hn name="cast" />
<hn name="prepared" />
<hs name="usesperiod" />
<genericcontrol name="rightanchor">
<anchored height="0" width="0">
<top offset="2" />
<right />
</anchored>
</genericcontrol>
<linkcontrol name="shortcut">
<anchored to="rightanchor" width="20" height="20">
<top />
<right anchor="left" relation="relative" offset="-5" />
</anchored>
<class>power</class>
<readonly />
</linkcontrol>
<button_idelete name="idelete">
<anchored to="rightanchor">
<top />
<right anchor="left" offset="-5" />
</anchored>
</button_idelete>
<button_toggledetail name="activatedetail">
<anchored to="rightanchor">
<top />
<right anchor="left" relation="relative" offset="0" />
</anchored>
<invisible />
<script>
function onInit()
local node = window.getDatabaseNode();
DB.addHandler(DB.getPath(node, "actions"), "onChildAdded", update);
DB.addHandler(DB.getPath(node, "actions"), "onChildDeleted", update);
local bShow = (DB.getChildCount(window.getDatabaseNode(), "actions") > 0);
setVisible(bShow);
end
function onClose()
local node = window.getDatabaseNode();
DB.removeHandler(DB.getPath(node, "actions"), "onChildAdded", update);
DB.removeHandler(DB.getPath(node, "actions"), "onChildDeleted", update);
end
function update()
if DB.getChildCount(window.getDatabaseNode(), "actions") > 0 then
setValue(1);
setVisible(true);
else
setValue(0);
setVisible(false);
end
end
</script>
</button_toggledetail>
<!-- spell name/group name, prep count/etc-->
<subwindow name="header">
<anchored>
<top />
<left />
<right parent="rightanchor" anchor="left" relation="relative" offset="-2" />
</anchored>
<class>power_item_header</class>
<activate />
<fastinit />
</subwindow>
<list_poweraction name="actions">
<anchored>
<top parent="header" anchor="bottom" relation="relative" offset="5" />
<left offset="10" />
<right offset="-10" />
</anchored>
<invisible />
</list_poweraction>
</sheetdata>
</windowclass>
Lastly, the code I use to currently hide the items within power_item.
function onModeChanged(v)
if v then
local node = getDatabaseNode();
local nodeChar = node.getChild("...");
local bMemorized = (DB.getValue(node,"memorized",0) > 0);
local sMode = DB.getValue(nodeChar, "powermode", "");
local nLevel = DB.getValue(node, "level",0);
local sGroup = DB.getValue(node, "group",""):lower();
-- make sure it's a spell, with level and in group "Spells"
local bisCastSpell = ( (nLevel > 0) and (sGroup == "spells") );
if sMode ~= "preparation" and bisCastSpell then
-- only show spells that are memorized
v.shortcut.setVisible(bMemorized);
v.activatedetail.setVisible(bMemorized);
v.header.setVisible(bMemorized);
-- only set this if false, not if true.
if not bMemorized then
v.actions.setVisible(false);
v.idelete.setVisible(false);
-- toggle the gear/config button to not pressed
v.activatedetail.setValue(0);
end
else
v.shortcut.setVisible(true);
v.activatedetail.setVisible(true);
v.header.setVisible(true);
--v.actions.setVisible(bMemorized);
end
end
end
Here is the prep-window view with all spells.
https://i.imgur.com/LV7cxRS.png
Now here it is when in combat/standard (notice the space above magic missle).
https://i.imgur.com/O7c7SJp.png
Everytime I start to ask something here my posts end up WAY longer than I intended ;(
"powers" is a windowlist. Each item listed is a spell and displayed via "power_item" (both record_power.xml if you have the 5e ruleset).
Is there a method with the listed usage that would let me hide a child item of powers.windows()?
Or must I do it for each item (as I do in the onModeChanged()).
I was hoping if I could do it by windowlist item instead somehow I could bypass trying to figure out what is causing the "extra" space".
This is mostly all 5e ruleset code cept for the "mode change" but I'll post.
The template used for "powers"
<template name="list_powers">
<windowlist>
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="5" />
<left />
<right />
</anchored>
<datasource>.powers</datasource>
<class>power_item</class>
<noscroll />
<footer>footer_wide</footer>
<script file="campaign/scripts/power_list.lua" />
</windowlist>
</template>
The power_item (where the items are listed)
<windowclass name="power_item">
<margins control="0,0,0,2" />
<script file="campaign/scripts/power_item.lua" />
<sheetdata>
<hs name="group" />
<hn name="level" />
<hs name="type" />
<hs name="name" />
<hn name="cast" />
<hn name="prepared" />
<hs name="usesperiod" />
<genericcontrol name="rightanchor">
<anchored height="0" width="0">
<top offset="2" />
<right />
</anchored>
</genericcontrol>
<linkcontrol name="shortcut">
<anchored to="rightanchor" width="20" height="20">
<top />
<right anchor="left" relation="relative" offset="-5" />
</anchored>
<class>power</class>
<readonly />
</linkcontrol>
<button_idelete name="idelete">
<anchored to="rightanchor">
<top />
<right anchor="left" offset="-5" />
</anchored>
</button_idelete>
<button_toggledetail name="activatedetail">
<anchored to="rightanchor">
<top />
<right anchor="left" relation="relative" offset="0" />
</anchored>
<invisible />
<script>
function onInit()
local node = window.getDatabaseNode();
DB.addHandler(DB.getPath(node, "actions"), "onChildAdded", update);
DB.addHandler(DB.getPath(node, "actions"), "onChildDeleted", update);
local bShow = (DB.getChildCount(window.getDatabaseNode(), "actions") > 0);
setVisible(bShow);
end
function onClose()
local node = window.getDatabaseNode();
DB.removeHandler(DB.getPath(node, "actions"), "onChildAdded", update);
DB.removeHandler(DB.getPath(node, "actions"), "onChildDeleted", update);
end
function update()
if DB.getChildCount(window.getDatabaseNode(), "actions") > 0 then
setValue(1);
setVisible(true);
else
setValue(0);
setVisible(false);
end
end
</script>
</button_toggledetail>
<!-- spell name/group name, prep count/etc-->
<subwindow name="header">
<anchored>
<top />
<left />
<right parent="rightanchor" anchor="left" relation="relative" offset="-2" />
</anchored>
<class>power_item_header</class>
<activate />
<fastinit />
</subwindow>
<list_poweraction name="actions">
<anchored>
<top parent="header" anchor="bottom" relation="relative" offset="5" />
<left offset="10" />
<right offset="-10" />
</anchored>
<invisible />
</list_poweraction>
</sheetdata>
</windowclass>
Lastly, the code I use to currently hide the items within power_item.
function onModeChanged(v)
if v then
local node = getDatabaseNode();
local nodeChar = node.getChild("...");
local bMemorized = (DB.getValue(node,"memorized",0) > 0);
local sMode = DB.getValue(nodeChar, "powermode", "");
local nLevel = DB.getValue(node, "level",0);
local sGroup = DB.getValue(node, "group",""):lower();
-- make sure it's a spell, with level and in group "Spells"
local bisCastSpell = ( (nLevel > 0) and (sGroup == "spells") );
if sMode ~= "preparation" and bisCastSpell then
-- only show spells that are memorized
v.shortcut.setVisible(bMemorized);
v.activatedetail.setVisible(bMemorized);
v.header.setVisible(bMemorized);
-- only set this if false, not if true.
if not bMemorized then
v.actions.setVisible(false);
v.idelete.setVisible(false);
-- toggle the gear/config button to not pressed
v.activatedetail.setValue(0);
end
else
v.shortcut.setVisible(true);
v.activatedetail.setVisible(true);
v.header.setVisible(true);
--v.actions.setVisible(bMemorized);
end
end
end
Here is the prep-window view with all spells.
https://i.imgur.com/LV7cxRS.png
Now here it is when in combat/standard (notice the space above magic missle).
https://i.imgur.com/O7c7SJp.png
Everytime I start to ask something here my posts end up WAY longer than I intended ;(