PDA

View Full Version : Windowlist troubles



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() &gt; 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>

Xarxus
September 18th, 2022, 11:43
I am debugging to understand how it works and I have discovered this sequence. I've got 2 onInit on the spelllist_entry.
I guess the first one is the reason why I delete the original when use the menu without closing and reopening the window.



onDrop enter
addElement enter
verifyElement enter
verifyElement exit with nil
onInit --> spelllist_entry - the spell has the DB node of the original spell (spelldescription.id-00003)
addElement exit without parameters (last return)
onDrop exit (after addElement)
onInit --> spelllist_entry - the spell has the DB node of the copy in the spelllist

Xarxus
September 19th, 2022, 22:00
I have solved some of the problems regarding points 1 and 2.

Now when I drop a spell it only spawns one line in the windowlist. Unfortunately I only see the level field that I set to -1, while I don't see the other fields until I close and reopen the window. However, I no longer have the problem of deletion: only the data inside the windowlist is deleted. So I would say that, of problems 1 and 2, I only have the fact that the data is seen only when the window is reopened. :cry:

Problem 3 for now I have not addressed it.

Below I show you what I have changed. I don't put everything on, just the essentials.


I removed the allowdrop tag.
I changed the createWindow as follows


local newWin= createWindow ();
newWin.name.setValue(source.getChild("name").getValue());
... [same for other fields]



Does onybody knows why I don't see data when I drop?
Please help... :confused:

Moon Wizard
September 20th, 2022, 03:20
We use that sort of behavior all the time in FG when handling addEntry(...) calls in lists; so I don't think it's a general thing.

It must have something to do with the way you have it set up in your code, which we only see a small sliver of. You would need to provide your windowlist/template definitions; as well as all the functions in the script which handle the onDrop behavior.

Also, you should look at using DB.getValue API when pulling database information [i.e. DB.getValue(source, "name", "")]

Regards,
JPG

Xarxus
September 20th, 2022, 11:05
Thanks Moon, here is the code.

windowlist


<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>
<allowdelete />
<class>spelllist_entry</class>
<datasource>.spells</datasource>
<script file="campaign/scripts/manager_spelllist.lua" />
</windowlist>


LUA code


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 false;
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 newentry = createWindow();

newentry.areaofeffect.setValue(source.getChild("areaofeffect").getValue());
newentry.description.setValue(source.getChild("description").getValue());
newentry.duration.setValue(source.getChild("duration").getValue());
newentry.instantaneous.setValue(source.getChild("instantaneous").getValue());
newentry.level.setValue(-1);
newentry.name.setValue(source.getChild("name").getValue());
newentry.no_power_points.setValue(source.getChild("no_power_points").getValue());
newentry.part_of_set.setValue(source.getChild("part_of_set").getValue());
newentry.range.setValue(source.getChild("range").getValue());
newentry.spelltype.setValue(source.getChild("spelltype").getValue());

return newentry;
end


If I've understood your hint, I should change addElement code using DB.getValue(source, "name", "")
in place of source.getChild("name").getValue(), right?

spelllist_entry


<windowclass name="spelllist_entry">
<sizelimits>
<maximum>
<height>16</height>
</maximum>
<minimum>
<height>16</height>
</minimum>
</sizelimits>
<script>
function update(bReadOnly)
self.level.setReadOnly(bReadOnly);
end
</script>
<sheetdata>
<ft_record name="description" source="description">
<bounds>0,0,0,0</bounds>
<invisible/>
</ft_record>
<button_checkbox_column name="instantaneous" source="instantaneous">
<bounds>0,0,0,0</bounds>
<invisible/>
</button_checkbox_column>
<button_checkbox_column name="no_power_points" source="no_power_points">
<bounds>0,0,0,0</bounds>
<invisible/>
</button_checkbox_column>
<button_checkbox_column name="part_of_set" source="part_of_set">
<bounds>0,0,0,0</bounds>
<invisible/>
</button_checkbox_column>


<stringfield_columnx name="level" source="level">
<bounds>5,0,20,12</bounds>
<font>sheetlabel16</font>
<nodrag/>
</stringfield_columnx>
<stringfield_columnx name="name" source="name">
<anchored>
<to>level</to>
<position>right</position>
<offset>5</offset>
<size>
<width>150</width>
</size>
</anchored>
<font>sheetlabel16</font>
<readonly/>
<nodrag/>
</stringfield_columnx>
<stringfield_columnx name="areaofeffect" source="areaofeffect">
<anchored>
<to>name</to>
<position>right</position>
<offset>5</offset>
<size>
<width>90</width>
</size>
</anchored>
<font>sheetlabel16</font>
<center/>
<readonly/>
<nodrag/>
</stringfield_columnx>
<stringfield_columnx name="duration" source="duration">
<anchored>
<to>areaofeffect</to>
<position>right</position>
<offset>5</offset>
<size>
<width>90</width>
</size>
</anchored>
<font>sheetlabel16</font>
<center/>
<readonly/>
<nodrag/>
</stringfield_columnx>
<stringfield_columnx name="range" source="range">
<anchored>
<to>duration</to>
<position>right</position>
<offset>5</offset>
<size>
<width>40</width>
</size>
</anchored>
<font>sheetlabel16</font>
<center/>
<readonly/>
<nodrag/>
</stringfield_columnx>
<stringfield_columnx name="spelltype" source="spelltype">
<anchored>
<to>range</to>
<position>right</position>
<offset>5</offset>
<size>
<width>40</width>
</size>
</anchored>
<font>sheetlabel16</font>
<center/>
<readonly/>
<nodrag/>
</stringfield_columnx>
</sheetdata>
</windowclass>

Moon Wizard
September 20th, 2022, 16:37
What is "stringfield_columnx" template do? And why do you have name/source as the same value? If you're using a field, then source is automatically equal to name.

Is there any reason why you're not just performing a full copy, instead of a piecemeal per-field copy? You could always start with full-copy, then reset any fields you might need to reset.

Example:
local nodeNew = newentry.getDatabaseNode();
DB.copyNode(source, nodeNew);
DB.setValue(nodeNew, "locked", "number", 1);

If you have "hidden fields", there are already hidden field templates in CoreRPG to use ("hn", "hnc", "hs", "hsc").
Also, you don't even need the hidden fields if you are doing the full copy.

Regards,
JPG

Xarxus
September 20th, 2022, 22:38
Moon is official, you are great! ;)
You gave me the cue to understand, I was stuck.
There was a problem on stringfield_columnx!