PDA

View Full Version : Nested Windowlist Controls



Foen
October 25th, 2007, 22:21
Hi

I am messing around with a ruleset and want to have one windowlist control nested inside another. For example, a list of domains, each of which has a nested list of spells, on a character sheet.

I am interested to understand the following:


Right-clicking on the list - does it select the outer list (Domains) or the inner list (Spells) and how are the radial menu items managed?
Dragging and dropping - how do I pass the dragitem to the correct list? If I drag a Domain, I want it to be added to the outer list, if I drag a Spell I want it to be added to the inner list.

Many thanks

Stuart

Dachannien
October 26th, 2007, 01:09
Sheridan: Have you ever wondered what would happen if you opened a jump point inside a jumpgate?
Ivanova: No, and neither should you.

Sorry, I know it doesn't help with your question, but it seemed appropriate somehow ;)

Toadwart
October 26th, 2007, 07:59
Hmm... haven't done this with nested windowlists (bod-standard windows in a windowlist) but I image the behaviour would be the same.


If you right click on the inner list the radial menu should contain the menu items for both the inner list and the outer list (not sure which one win if you the bioth added a menu at the same 'position')

For events, I'd expect that the inner list would get the onDrop first and then the outer list would get the onDrop. You could prevent the outer list from getting th eonDrop by returning true from the inner lists onDrop function (telling FG that we have handled the drop and no further processing should happen for it)

Foen
October 27th, 2007, 07:29
Thanks Toadwart.

On the event side of things, I've played around with it and it does exactly what you say. A spell window is passed the event first, which then bubbles up (spell->spelllist->domain->domainlist) triggering each onDrop handler until one of them returns boolean true.

On the radial menu, I have yet to get stuck into programming but the default behavious seems to apply to the top-most list. When I "delete item" using the radial menu, the domain (and all the spells within it) get removed, rather than just the spell I'm selecting: not very useful.

I'll play with radial menus to see if I can enhance this default behaviour.

Stuart

Foen
October 27th, 2007, 22:12
OK, an update.

The radial default handling isn't what I need (it removes whole domains, rather than individual spells) and I think the only way to get the functionality I need is to remove the allowcreate and allowdelete tags, and to implement insert/delete functionality the hard way.

Insert seems to work fine: each windowlist has its own menu position at the top level (domain are at position 5, and spells at position 6); I can add an insert command to the windowlists at the second level of the menu (the domains windowlist registers an insert sub-menu at 5,5 and the script responds properly).

Delete seems to be a problem however. I can add a sub-menu in the windowlist (so the domain windowlist has a delete sub-menu which can be clicked), but then I don't know which domain was selected for deletion. If I try to add the delete sub-menu at the windowclass level (within the windowlist, so I know it is this window that needs to be deleted) then it doesn't show on the radial menu.

Am I missing something?

Snippets of code, in case it helps:

From Domains windowlist:


function onInit()
registerMenuItem("Domains","icon",5);
registerMenuItem("New domain","insert",5,5);
end

function onMenuSelection(lvl1, lvl2)
if lvl2 then
if lvl2==5 then
createWindow();
end
end
end


From Domain windowclass:


function onInit()
registerMenuItem("Delete domain","delete",5,6);
end

function onMenuSelection(lvl1, lvl2)
if lvl2 then
if lvl2==6 then
getDatabaseNode().delete();
end
end
end


Cheers

Stuart

Foen
October 28th, 2007, 07:58
Confessions: I give up trying to use sub-menus.

I was able to register top-level menus (one for Domains and one for Spells) from the onInit handler of the DomainList and SpellList windowlists. I was also able to add second-level menu items to insert a new domain or spell, again from the onInit handlers of the windowlists (which is where insert commands need to sit).

I was not able to add second-level menu items to the (already-existing) top-level menus from the onInit handlers of the Spell and Domain windowclasses (which is where the delete commands need to sit).

Oh well, I'll make do with an over-crowded top-level menu with all four items on it (New Domain, Delete Domain, New Spell, Delete Spell).

Stuart

Toadwart
October 29th, 2007, 20:35
I suspect the order the init events are being called in is causing the problem. i.e. radial menu 5 has not been created when the "delete domain" menu item is being created.

You could try creating the 'higher' level menu in within the oninit of the windowclass.


function onInit()
registerMenuItem("Domains","icon",5);
registerMenuItem("Delete domain","delete",5,6);
registerMenuItem("New domain","insert",5,5);
end

However, this might error because you are redifining the position 5 menu item. It also may be slow as it's trying to create that item for every entry in the list.

This sounds more plausible:
Try creating the "Delete domain" item in the domainlist oninit. Maybe the domain windowclass can handle the "delete domain" menu item even though that item was registered by it's 'parent'?

Foen
October 29th, 2007, 23:45
Thanks Toadwart. The thought had crossed my mind and I tried both those approaches to no avail.

The former option just plain failed (no error, just no menu). The latter option also failed silently, though I think it does not 'see' the event as it hasn't registered any handlers successfully (the event is raised in an outer context).

It also strikes me that scripted menus are a new feature (only working as of release 2.1.0) and hence there may be a few further issues to iron out.

Cheers

Stuart