PDA

View Full Version : Preventing clearing of diecontrols



phantomwhale
December 12th, 2010, 09:11
After a tour around the documentation and some trial and error, I'm admitting (temporary) defeat on a simple thing - preventing the clearing of a diecontrol element.

Currently, the numbercontrol has the <noreset /> tag which prevents middle-click resetting of a number field to zero - this is essentially what I want. as middle-clicking my diecontrol's causing their contents to clear, which leads to nasty bugs around the ruleset codebase.

I tried capturing the database onUpdate event, or the onClickReleased event, to reset the value to d4 when it's been set to zero, but these seem to get called before the diecontrol has actually been cleared (e.g. getDice() still returns a die). I also tried the <disabled /> tag, but this goes too far, and disables everything.

I suspect there is a way of wrapping it in a genericcontrol, and restricting the supported interactions that way, but I was having trouble rewiring up the drag, drop, double-click and other event driven functions correctly - this seems like a lot of work too, just to disable a simple function. However, in lieu of any other suggestions, this appears to be the only avenue I've left to explore.

I also tried turning to the excellent BRP ruleset (never played with it, but worth it's weight in example code !) - but the only diecontrol I found was a diefield for the damage modifier - and surely enough, middle-clicking on this clears the dice out of it too. So I suspect Stuart might be able to make use of a <noreset /> tag here too ;)

So in summary, I'm wondering shouldn't the diecontrol have some more tags to alter it's base behaviour ? According to the ruleset documentation, it has no more tags that a basic windowcontrol, unlike the numbercontrol that has several extra ones.

Or is there possibly another way to achieve this that I'm not thinking of right now ? Ok, it's late, apologies if above e-mail comes across grumpy - I'm really not, just tired ! Thanks for any assistance :D

Ikael
December 12th, 2010, 09:45
I have been dealing with the control 'reseting' by adding following code to the controller definition. This will cease/prevent the middle-click functionality in most cases.



function onClickDown(button, x, y)
if button == 2 then
return true
end
end

phantomwhale
December 12th, 2010, 10:09
Glad I stopped trashing about all tired like and asked - almost exactly what I was looking for.

The only tweak is it was the onClickRelease() function I needed to override - which I accidently typed with a "d" on the end, couldn't make work, and composed a reply here to appeal for cosmic justice, before I remembered I was tired and it was probably a good idea to check my spelling :o

And, of course, now you've said it I can now see standing out from the documentation quite clearly (for onClickRelease() and onClickDown())


Return values

(boolean)
This function should return true if it handled the event and the processing of the event should be stopped. A value of false indicates that the default framework functionality for the this particular control should not be executed, but the processing should continue for the element below this control, if any. A return value of nil (or the absence of a return statement) indicates that the framework should continue handling the event normally.

Perfect, final bug fixed. Now to bundle up what I've been slogging through all weekend into something installable. Thanks Ikael, I owe you... several :D

Moon Wizard
December 13th, 2010, 05:54
Also, I've already added a noreset tag for the diecontrol and diefield components in the next big release (2.8.x).

Cheers,
JPG

phantomwhale
December 13th, 2010, 05:58
Also, I've already added a noreset tag for the diecontrol and diefield components in the next big release (2.8.x).

Cheers,
JPG

Yey ! I'm bleeding edge coding :D