PDA

View Full Version : setStatic with campaigns



JMessmer
July 26th, 2013, 13:34
I have just tried to set some nodes within a campaign db.xml to static. I hoped that the nodes would turn read-only.
Basically, it works. However, there is a huge flaw that comes with it: once the db.xml is saved the nodes that have been set to static simply disappear inside the xml.



function update()
local bLock = windowlist.isReadOnly();
local parNode = name.getDatabaseNode().getParent();
...
name.setReadOnly(bLock);
...
parNode.setStatic(bLock);
-- child nodes are not automatically set to static (bug?) -> therefore set them to static, too
for _,v in pairs(parNode.getChildren()) do
v.setStatic(bLock);
end
end


I would like to set all elements on the same level like name to read-only. setStatic seemed to be the right choice but I cannot live with the consequence that my static content is gone afterwards.
Any suggestions how to get this working?

Moon Wizard
July 26th, 2013, 18:48
The campaign is more for dynamic data vs modules for static data. The setStatic function must be locking down the content like a module, where unchanged data is not changed. The setStatic function was added before I took over, so not sure of its intent.

Most times, the way to display read only data in a campaign is to control through the ruleset. The best way is to only allow access through read only control objects, or do not offer direct access to data at all. The calendar in the 3.5E and 4E rulesets works this way.

Regards,
JPG

JMessmer
July 26th, 2013, 20:11
Thx for the response, JPG.

I know that campaigns are for dynamic data. Let me try to explain what I intend to do:
for our ruleset (DSA, Drachenzwinge) I am enhancing our NPC management and developing it more into the direction of how the 4E ruleset is working. Therefore I added the lock button on our NPCs GUI. The lock button switches all fields on the NPC to read-only.

Unlike D&D I added lists where I can drag&drop spells and abilities from modules onto the NPC. In order to look at the details of one spell/ability, the user has to click on a link and a pop-up opens.
In the underlying code all xml nodes are copied from the module to the NPC so that the user is able to change certain modifiers or fields within the spell (of course only on the copied instance).

This leads me now to the problem that I described above: once the NPC is locked all fields are read-only ... except for the details within the pop-up window. These fields are always read-write. In order to indicate to the users that these fields are editable each one has a frame around when not read-only. And this does not look so good.
So I thought that it would be good to add some code to make the lock button work on the pop-up as well so that the frames are not visible all the time.
Since the pop-up window based on a different windowclass I cannot set the GUI elements of the other class to read-only from the NPC scripts. However, I can access the DB nodes since they are actually based within the NPC elements. This is why I used an approach on DB level.

Moon Wizard
July 27th, 2013, 10:17
If the fields are available to edit, then the controls should be available to set read only status on the controls themselves. You would basically just be propagating what the locking code already does down to the spell detail level.

In other words, any control can be set to read-only mode by a script.

JPG

JMessmer
July 27th, 2013, 10:59
I thought that I can only set GUI controls to read-only when they are visible. The user could click any time on the lock button on the NPC. The pop up window with the spell details might not be open then and therefore not accessible.

I also thought that it is probably possible to implement the read-only behaviour on the script of the pop-up spell detail window. However, several NPC windows might be open and I have no way to know which one might have opened the spell detail - if any opened it at all. The same pop-up window is also used in modules (the spell detail windowclass is actually declared within subfolder ref).

In the end I need to check if one of the parent nodes of the spell details is within the NPC. If yes, then the spell detail can be opened on NPC level and this spell detail might have to be set to read-only.
Therefore, the only way seems to be to define my own hidden read-only flag on xml/DB level (new element called read_only) within the NPC so that I can use that.

Perhaps it might be an idea to review the functionality of setStatic or to add setReadOnly on databaseinstance level in one of the future updates?

Dakadin
July 27th, 2013, 23:03
You should be able to check the database node of the NPC for the node that tracks that the NPC is read only when the spell detail window is open. Then you can set the window controls on the spell detail window to read only. You shouldn't have to change the nodes for the spell detail window to read only.

JMessmer
July 28th, 2013, 17:29
Yes, I agree, Dakadin. That is also a possible solution and a bit simpler than to create a new hidden field.