PDA

View Full Version : Issues hiding, using windowlist



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

Moon Wizard
March 21st, 2017, 04:48
That's because the power_item window has some built in control margins and/or spacing controls. You'll probably have to use the onFilter callback of the power list to actually filter the window out completely.

Regards,
JPG

celestian
March 21st, 2017, 05:24
That's because the power_item window has some built in control margins and/or spacing controls. You'll probably have to use the onFilter callback of the power list to actually filter the window out completely.

Regards,
JPG

That's what I thought (spacing/controls) but I even used hide on those (no spacers, just anchor) and it didn't seem to matter. I removed the margins as a test also.

I'll look at the filter (had been poking at it also a bit) and see if I can figure it out. It is a much cleaner option.

celestian
March 21st, 2017, 06:28
Ok, thanks to the nudge from Moonwizard I figured out a way and it is much better than what I had done.

So in power_page.lui there is a onFilter() for powers already and it does a call to w.getFilter() (each item in the power list).


function onFilter(w)
if w.getClass() == "power_group_header" then
return w.getFilter();
end

-- Check to see if this category is hidden
local sCategory = window.getWindowSort(w);
if aFilters[sCategory] then
return false;
end

return w.getFilter();
end




So, I just changed the getFilter() for list items (power_item.lua) and walla, perfect look!



function getFilter()
local bShow = bFilter;
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") );

-- this is so when they cast a spell it doesn't go away instantly
-- otherwise they can't use save/damage/heal/etc
-- it's reset when they visit the preparation windows.
local bWasMemorized = (DB.getValue(node,"wasmemorized",0) > 0);

if sMode ~= "preparation" and bisCastSpell then
if (bMemorized) then
DB.setValue(node,"wasmemorized","number",1);
end
bShow = (bMemorized or bWasMemorized);
else
DB.setValue(node,"wasmemorized","number",0);
bShow = true;
end

return bShow;
end

No more "erroneous" space:
https://i.imgur.com/lnFLDA9.png

Once again thanks for the help, tips and suggestions!
;)

Nickademus
March 21st, 2017, 06:43
Does the list still filter what it originally did?

celestian
March 21st, 2017, 07:11
Does the list still filter what it originally did?

That's what the "local bShow = bFilter;" should do. It keeps the "setFilter" (bFilter) option for those items but the memorization bit will override if they conflict obviously.

The original code was just

function getFilter()
return bFilter;
end

setFilter set bFilter and was being run for UpdateSlots/etc in page_item.lua which for me is not really necessary. In fact I changed how it works because I want it to list spells regardless of used/unused slots. For 5e, all slots tic'd is considered "used/spent". My version of the ruleset for AD&D it considers that slot a currently memorized slot if tic'd and a available slot to memorize if not.

Moon Wizard
March 21st, 2017, 08:07
The "Standard" mode on the Actions tab shows all spells regardless of how many spell slots have been used. The "Combat" mode is specifically to hide unequipped weapons and spells unable to be cast due to lack of spell slots.

Regards,
JPG

Bidmaron
March 21st, 2017, 12:59
Thanks for posting your solution celestia

celestian
March 21st, 2017, 15:29
The "Standard" mode on the Actions tab shows all spells regardless of how many spell slots have been used. The "Combat" mode is specifically to hide unequipped weapons and spells unable to be cast due to lack of spell slots.

Regards,
JPG

Indeed. Very useful... it was why I wanted to make mine do something similar and only list memorized spells when in "combat" mode. Still have a few tweaks to make but very happy with how it looks.

Minty23185Fresh
March 14th, 2018, 16:32
Thanks for posting your solution celestia

I parrot Bidmaron's thank you.
So many questions are posted in the forums, and one assumes solutions are eventually worked out.
But mostly it seems as though the final resolution in rarely posted. Mostly.

Nickademus
March 14th, 2018, 19:10
I parrot Bidmaron's thank you.
So many questions are posted in the forums, and one assumes solutions are eventually worked out.
But mostly it seems as though the final resolution in rarely posted. Mostly.

To be honest, I'm probably guilty of this. I assume, though, that a fellow developer that wishes information about the solution to a problem I posted on the forums here would feel free to send me a message to get that information. I think of the developer community here as open and friendly, and we communicate with each other often.

I know I've contacted devs here about stuff before.

Bidmaron
March 15th, 2018, 00:29
But we don’t have to bug you if it is posted. Plus I always learn things by looking at code even if I don’t think I will ever use it.

Nickademus
March 15th, 2018, 04:49
True enough.