PDA

View Full Version : Can a Ruleset Be Built Only From Script?



PneumaPilot
December 9th, 2008, 17:36
I know that the XML makes editing the rulesets slightly more accessible, but I would really like to see an XML-free ruleset - one where all of the controls were created through script. This would make certain things so much easier. I would love to use loops to create very similar controls (like the dots on my nWoD ruleset). I would also like an easy way to have certain controls calculate their own size (like the lines for skill specialties in the nWoD ruleset).

Now, I have heard that there is a way to create controls through the scripting, but any attempt to do so will only make the thing harder to read, I think. If you start mix and matching controls created through XML and controls created through script onInit events, it will quickly become hard to tell how a given control got there.

I suppose I could be missing something, though. Is there a way to create controls with a looplike structure without resorting to the script control creation process? Like something pure XML? Can you create a template that would create several controls and then call that template from the XML? The only way I have found to do this is through windowlist, but could you use a windowclass just as another control, or does it have to be in a windowlist?

Some of my XML files are getting VERY large with boilerplate control definitions.

Foen
December 9th, 2008, 19:18
Instances of controls can be created from script, but the control must either be a built-in one (like stringfield) or else you need to define the template.

Complex controls can be created using a windowclass and then embedding it in another windowclass using a subwindow control. This is non-trivial, but does give you the ability to make your code more modular and re-useable.

An example in the Rolemaster ruleset is the tableview template control, which presents a grid of values, with column and row headers. The template inherits from a subwindow, which wraps a windowclass, which then creates the cells of the table dynamically. The code for this is neat to invoke from the parent window (adding a tableview to a window is quite easy), but the embedded code in the control definition is nightmarish.

As an example, say you want to bind the table to some underlying data (very relevant in Rolemaster), the structure of the control looks a bit like this:


mywindow (top level windowclass)
+mytable (instance of the tableview template)
+tableview (template inheriting from subwindow)
+tableview_table (windowclass created by the subwindow)
+tableview_cell (stringcontrol created dynamically at run time)

The top-level window (mywindow) just calls bind() on the tableview control (mytable), and then handles an onBound() event when the data has been processed.

Behind the scenes, the tableview template has to pass the call to its child windowclass (tableview_table), or else cache the call if the windowclass hasn't yet been created: windowclasses in subwindows are created asynchronously and you only become aware of them via onInstanceCreated, at which point you can pass on any cached calls. The inner windowclass then acts on the call, creates or updates the dynamic controls (tableview_cell which is a template class in its own right), and invokes onBound back to its containing subwindow (tableview). The subwindow template checks to see if an onBound handler exists in the inherited context (mytable) and invokes it, if present.

Phew!

I think there certainly should be an easier way, and my vote would be for some kind of container or group control which doesn't have to involve the subwindow/onInstanceCreated stuff, but allows you to create complex templates my simply.

Not sure if this answered your question, but it certainly got a weight off my own chest :D

Stuart

Sorontar
December 9th, 2008, 19:47
Not sure if this answered your question, but it certainly got a weight off my own chest :D

Stuart

Therapy Foen style ;)

Foen
December 9th, 2008, 19:53
*Pokes Sorontar* :p

PneumaPilot
December 9th, 2008, 20:18
Hehe, wow, that's pretty in-depth! I agree, it would be SO much easier if we just had some sort of container control. So many of my difficulties would just vanish if that were the case.

That's some pretty genius work on the tables, though. I'm not familiar with Rolemaster, but it sounds like you're giving it the TLC it needs!