PDA

View Full Version : Locking down Subwindows under CoreRPG



S Ferguson
November 18th, 2014, 02:16
I have an NPC sheet with multiple tabs (3 to be exact). I was wondering if anyone could help me out here. I need to lock down every one of the tabs upon hitting the "lock" button. I found an example in the 4E ruleset, but it's too case specific to help (well for me anyway :o). Any help with this would be greatly appreciated.

Regards,
SF

dulux-oz
November 18th, 2014, 04:07
I do something similar in my Locations Extension - you could have a look at that and see if it helps

Cheers

S Ferguson
November 18th, 2014, 15:02
Thanks I'll take a look at it.

Edit: O.k. Where am I supposed to look? I don't see a "locking icon" in the extension. Could you point me to the right spot? :)
I'd optimally like this to be mini scripts that can be inserted inline the XML code IP. Otherwise a script will do.

Cheers,
SF

dulux-oz
November 18th, 2014, 16:46
Thanks I'll take a look at it.

Edit: O.k. Where am I supposed to look? I don't see a "locking icon" in the extension. Could you point me to the right spot? :)
I'd optimally like this to be mini scripts that can be inserted inline the XML code IP. Otherwise a script will do.

Cheers,
SF

OK, follow along using the files as I call them out:

We'll use the Town Record as an example, but (almost) all of the Place Records in the Locations Extension uses the same concepts, logic, etc.

OK, the definition for the Lock Button is on Line 147 of the 'xTownsWindowClasses.xml' file.

This calls the 'tLocationButtonRecordLocked' template definition found on Line 1064 of the 'xLocationsTemplates.xml' file. You'll note that this template is defined from another template called 'button_record_locked'. 'button_record_locked' is a template defined somewhere in the CoreRPG - you can tell this because all of my templates start with the letter "t" and are named in Camel-Case.

You'll note that the 'tLocationButtonRecordLocked' template has a name attribute of "locked" (see Line 1065). This means that every instance of this template will have a name of "locked" unless explicitly over-written. This also means that in the Database under each Town Record there is a Node called "locked".

So, if you take a look at Line 27 of the 'xTownsWindowClasses.xml' file you'll see that, as part of the form's onInit() function, we define a handler function 'fpOnLockChanged' linked to each Town Records' "locked" Node which will get called each time the "locked" Node is updated (the "onUpdate" part of the command).

'fpOnLockChanged()' is found on Line 42 of 'xTownsWindowClasses.xml' and we can see straight away that it calls the 'fpStateChanged()' function, which is on Line 46.

'fpStateChanged()' simply calls an update function for each of the subwindows of the main Towns Window ('wcTown'). It doesn't really matter that I'm using subwindows - the logic is still the same. Let's take the swMain subwinow's update function ('swMain.subwindow.fpUpdate()') as an example.

The windowclass called by 'swMain' is 'wcTownMain' (see Line 80-81 of 'xTownsWindowClasses.xml').

Looking at 'wcTownMain' we can see that there is a script file ('lsTownMain.lua') associated with 'wcTownMain' (see Line 192 of 'xTownsWindowClasses.xml').

Looking at Line 34 of 'lsTownMain.lua' we fine 'fpUpdate()'. Looking at Line 35 we can see a Boolean variable ('bReadOnly') is assigned either 'true' or 'false' depending upon if the Town Record's node in the Database is Read-Only or not.

Finally, if you look through the rest of the 'fpUpdate()' function you'll see that we use bReadOnly to turn on and off various windowcontrols and their functionality - you can do the same thing to enable/disable the "onClick()" functions on your Tabs (or whatever they are called), effectively unlocking/locking them.

Long, I know, but pretty clear (I hope) :)

Cheers

S Ferguson
November 18th, 2014, 16:50
Exceptionally clear. Thank you. :D

Edit: I thought I recognized that naming convention from somewhere. I don't know. When it comes to programming I'm more comfortable with LISP naming convention - type in exactly what the function does. <<sigh>> I miss those days.

Cheers,
SF

dulux-oz
November 19th, 2014, 02:45
Actually, I wrote that post as the last thing I did before switching off the light and going to sleep last night - I can sumerise it a bit better:

Steps To Provide WindowControl Locking In CoreRPG

Register a handler function in the WindowClass's onInit() function to be called when a specific Node in the Database changes.
Have a ButtonControl in the WindowClass that modifies the Node in the Database referred to in Step (1).
When the ButtonControl is Clicked, the value of the Node in the Database changes and therefore the handler function is called.
Have the handler function call the DB.isReadOnly() function on the WindowClass's Node and store the result in a Boolean Variable.
In the handler function use the Boolean Variable to turn on/off whatever functionality of whatever WindowControls (within the WindowClass) you like.


Cheers

S Ferguson
November 20th, 2014, 15:44
Does it have to be on all of the Windowclasses of just the "titled" entries? Work with me here. I'm rather slow at FG XML - it doesn't follow the official guidelines.


Cheers,

SF

dulux-oz
November 20th, 2014, 15:54
Does it have to be on all of the Windowclasses of just the "titled" entries? Work with me here. I'm rather slow at FG XML - it doesn't follow the official guidelines.


Cheers,

SF

Tell me an XML Implementation that does :rolleyes:

If I understand the question properly then only on the WindowClass (and thus the subwindows) that you want to lock down - if you only want to lock down the Tabs then that would only be the Windowclass that defines the tabs, not any subwindows called/linked to those tabs.

Yeah?

Cheers

S Ferguson
November 20th, 2014, 17:05
Got it. Thanks.

Cheers,
SF

S Ferguson
November 27th, 2014, 16:10
What would the handler function look like in it's barest possible form? For some reason I'm drawing a blank on how to implement the DB.isReadOnly() command into my inline script.

Regards,
SF

The code I have so far is:

function onInit()
update();
onLockChanged()
DB.addHandler(DB.getPath(getDatabaseNode(), "locked"), "onUpdate", onLockChanged);
end

function onClose()
DB.removeHandler(DB.getPath(getDatabaseNode(), "locked"), "onUpdate", onLockChanged);
end

function onLockChanged()

if npc_notes then
npc_notes.update();
end
...
end

The update function just does some bookkeeping. I'm working with NPC Notes in this particular example.

dulux-oz
November 28th, 2014, 02:41
What would the handler function look like in it's barest possible form? For some reason I'm drawing a blank on how to implement the DB.isReadOnly() command into my inline script.

Regards,
SF

The code I have so far is:

function onInit()
update();
onLockChanged()
DB.addHandler(DB.getPath(getDatabaseNode(), "locked"), "onUpdate", onLockChanged);
end

function onClose()
DB.removeHandler(DB.getPath(getDatabaseNode(), "locked"), "onUpdate", onLockChanged);
end

function onLockChanged()

if npc_notes then
npc_notes.update();
end
...
end

The update function just does some bookkeeping. I'm working with NPC Notes in this particular example.


The line you want is:

local bReadOnly = WindowManager.getReadOnlyState(getDatabaseNode());
and then use the bReadOnly variable. Looking at your code it should probably go into the onLockChanged() function. Then you could have something like:

tab.setReadOnly(bReadOnly);
for each tab.

Cheers

S Ferguson
November 28th, 2014, 15:39
Much obliged.

Regards,
SF