PDA

View Full Version : Timing of updating windowcontrols within subwindows



phantomwhale
December 7th, 2010, 06:44
Hello all,

This post was almost several different appeals for assistance, but I've got what I need working now. What I therefore wanted to check was have I done it well !

The issue I was facing came from moving a number of windowcontrols into a subwindow; a windowclass called "header" that is being included at the top of every character sheet pane. This removes copy and paste coding between the character sheet xml files.

These windowcontrols are templates which have bitmap widgets dynamically rendered inside them using a LUA script (Fate chips for the Deadlands extension, very similar to the Bennies field in the original Savage Worlds ruleset). This script does the typical thing in onInit() of register for the underlying databasenode's update method to ensure it modifies its appearance whenever the underlying value changes. It then calls the local update() method for good measure to ensure the control is correctly setup before any changes take place.

The difference came in, I think, due to this being shown on a subwindow. Suddenly this initial update was putting the widgets in the wrong place, and this was due to the getSize() method returning "0,0".

The fix ended up being implementing the onSubwindowInstantiated() method on the window class containing the fate chip template windowcontrols, and then simply calling update() on each windowcontrol. I also removed the update() call from the template's onInit() method, since it wasn't doing anything helpful.

My only concern here is the fatechip template windowcontrol is no longer "portable" - e.g. if I include it in another subwindow, I'll have to remember to add in this special setup call there too. Before, all the code was in the template's own LUA script, and therefore I could include this control anywhere within the character sheet without any further work.

Not a big issue, but I was wondering if I've made some false assumptions here (I did rewrite quite a lot of the anchoring / sizing XML code, and muck about with a lot of script code today, so it's quite quite possible !) ?

Any insight or ideas around this gratefully received !

Thanks,
Ben

Ikael
December 7th, 2010, 06:56
for what do you need the value of getSize() for? Are you anchoring your widgets/windowcontrollers to somewhere using these values? I believe onInit functon is called before anything is rendered so there is no size calculated for the controller at that time, at least I have had the same kind of struggling before but I managed to beat it with different solution. Can you give more specs about what you want to do that was no possible using the onInit?

phantomwhale
December 7th, 2010, 07:07
I was using getSize() to layer the fate chips correctly (similar to the Savage Worlds Bennies) - e.g. it works out the width of the container, and the width of the fate chip icon, and then works out if it needs to overlap the icons to ensure they all fit within the box, then finally spins over all the chips, assigning a different "x" position to each one.

I want the control to work with variable size fate chip controls, rather than hardcode the width of the control in the script (which would need to be kept in step with any changes to the XML definition, so bad)

Zeus
December 7th, 2010, 09:43
I would say the approach you have adopted in using onSubWindowInstantiated() is correct. As Ikael says onInit() executes before the graphics are rendered therefore the results of a getSize() in onInit() will always return 0,0.

I remember having to do something very similar in some of the 4E extensions. Having said that if you are using a subwindow, you might also be able to make the update() call from within an onInstanceCreated() function when the subwindow is created.

Ikael
December 7th, 2010, 10:05
One alternative option would be reading width value from XML-tag from the controller's definition. For example you could put your own specified <width>50</width> tags in the controlelr definition and read it in the template script like if width then local width = tonumber(width[0]) ... end

In this way you can have width to be variable in each controller's definition but in the bad side you must input the width twice in the XML definition. On is for the rendering width (as in FG specs) and the another is for the widget usage. You could however read the width from rendering definitions but that would means that your controller must be used certain way. More failproof way is to define the width twice. In this way you can access the width value in onInit() function.

just a though

Zeus
December 7th, 2010, 11:42
Yes agree that would also work.

The former approach works well for dynamically sized controls whilst the latter approach seems a nice way of dealing with statically sized controls.