Xarxus
September 18th, 2022, 10:07
I need some help with the windowlist. I have created a windowlist which should contain a list of spells. In the list I have enabled acceptdrop and allowdelete because I want to be able to drag in the spells I want and if necessary I want to remove them.
Problem 1.
When I drag a spell into it it is recorded well on the campaign DB, but the list shows it leaving a blank line. I don't understand why and where I have to look.
I have implemented onDrop to verify that the spell does not already exist or that the user is the master. If it exists or if the user is not the master, I use return true to prevent the spell from being registered. None of this justifies the blank line for me.
Problem 2
The second problem is what worries me most.
Once a spell has been added, by right clicking the menu appears that allows me to delete it. If I do this now, it deletes the spell from the list only in appearance (closing and reopening the window I find it in the list) and removes it from the campaign DB (it was a spell created in the campaign DB, not coming from a module). I've no code for delete... :cry:
If before deleting it I close and reopen the window the blank line of Problem # 1 disappears and the deletion works fine, removing it from the list, but not from the campaign DB.
Problem 3
What is created in the windowlist is a copy of the spell, so if I change the original spell data, nothing changes in the list. I'd like to have the data update instead. How can I do?
<windowlist name="spell_list">
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="25" />
<left offset="0" />
<right offset="-5" />
<size>
<height>200</height>
</size>
</anchored>
<class>spelllist_entry</class>
<datasource>.spells</datasource>
<allowdelete />
<skipempty/>
<acceptdrop>
<class>reference_spell</class>
<field>name</field>
<field>areaofeffect</field>
<field>duration</field>
<field>range</field>
<field>spelltype</field>
<field>description</field>
</acceptdrop>
<script>
function onSortCompare(w1,w2)
return w1.level.getValue() > w2.level.getValue();
end
function onDrop(x, y, dragdata)
local bLocked = WindowManager.getLockedState(getDatabaseNode().get Parent());
local source = dragdata.getDescription();
if not User.isOwnedIdentity() then
return true;
end
if not bLocked then
if dragdata.isType("shortcut") then
local class = dragdata.getShortcutData();
if class == "reference_spell" then
return addElement(dragdata.getDatabaseNode(), "[message]")
end
end
end
return ;
end
function verifyElement(source)
local newname = source.getChild("name").getValue();
for i,win in ipairs(getWindows()) do
if win.name.getValue()==newname then
return win;
end
end
return nil;
end
function addElement(source, message)
if verifyElement(source)~=nil then
writeMessage(source, message);
return true;
end
local newWin = createWindow(source);
end
function writeMessage(source, message)
[code for message]
end
</script>
</windowlist>
Problem 1.
When I drag a spell into it it is recorded well on the campaign DB, but the list shows it leaving a blank line. I don't understand why and where I have to look.
I have implemented onDrop to verify that the spell does not already exist or that the user is the master. If it exists or if the user is not the master, I use return true to prevent the spell from being registered. None of this justifies the blank line for me.
Problem 2
The second problem is what worries me most.
Once a spell has been added, by right clicking the menu appears that allows me to delete it. If I do this now, it deletes the spell from the list only in appearance (closing and reopening the window I find it in the list) and removes it from the campaign DB (it was a spell created in the campaign DB, not coming from a module). I've no code for delete... :cry:
If before deleting it I close and reopen the window the blank line of Problem # 1 disappears and the deletion works fine, removing it from the list, but not from the campaign DB.
Problem 3
What is created in the windowlist is a copy of the spell, so if I change the original spell data, nothing changes in the list. I'd like to have the data update instead. How can I do?
<windowlist name="spell_list">
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="25" />
<left offset="0" />
<right offset="-5" />
<size>
<height>200</height>
</size>
</anchored>
<class>spelllist_entry</class>
<datasource>.spells</datasource>
<allowdelete />
<skipempty/>
<acceptdrop>
<class>reference_spell</class>
<field>name</field>
<field>areaofeffect</field>
<field>duration</field>
<field>range</field>
<field>spelltype</field>
<field>description</field>
</acceptdrop>
<script>
function onSortCompare(w1,w2)
return w1.level.getValue() > w2.level.getValue();
end
function onDrop(x, y, dragdata)
local bLocked = WindowManager.getLockedState(getDatabaseNode().get Parent());
local source = dragdata.getDescription();
if not User.isOwnedIdentity() then
return true;
end
if not bLocked then
if dragdata.isType("shortcut") then
local class = dragdata.getShortcutData();
if class == "reference_spell" then
return addElement(dragdata.getDatabaseNode(), "[message]")
end
end
end
return ;
end
function verifyElement(source)
local newname = source.getChild("name").getValue();
for i,win in ipairs(getWindows()) do
if win.name.getValue()==newname then
return win;
end
end
return nil;
end
function addElement(source, message)
if verifyElement(source)~=nil then
writeMessage(source, message);
return true;
end
local newWin = createWindow(source);
end
function writeMessage(source, message)
[code for message]
end
</script>
</windowlist>