-
December 11th, 2017, 03:33 #1
onDragStart event not being captured for templated buttoncontrol
I'm running into an issue with the onDragStart event that should be attached to a buttoncontrol that I have in my extension. Actually, the event works fine when I define the control directly in my windowclass, but if I attempt to wrap everything up into a reusable template which I then reference in the same windowclass, I can't get the event to fire any more. Other events (onButtonPress, onClickDown, even onDrag) still seem to occur correctly, just not the one I need for the behavior I want.
Below is a lot of xml and lua snippets and chat log output documenting the problem. Feel free to skip over it if I'm missing something obvious (I almost hope I am!)
The following xml contains both a fully defined version of the control (highconcept_buttoneffect) which correctly captures onDragStart, followed by a templated one (trouble_buttoneffect) which does not. They both reference the same script file and should be identical as far as the final control definition goes. This all is meant to be merged with the charsheet_main windowclass defined in record_char_main.xml of the Fate Core ruleset—the <string_labeled> controls are part of the original ruleset, and the ones whose names end in _buttoneffect are original to my extension.
Code:<root> <windowclass name="charsheet_main" merge="merge"> <sheetdata> <string_labeled name="highconcept" > <anchored offset="15,13"> <right offset="-38" /> </anchored> </string_labeled> <buttoncontrol name="highconcept_buttoneffect"> <anchored to="highconcept" width="20" height="20"> <top /> <left anchor="right" relation="relative" offset="2" /> </anchored> <icon normal="button_action_effect" pressed="button_action_effect_down" /> <script file="common/scripts/aspect_effect.lua" /> </buttoncontrol> <string_labeled name="trouble"> <anchored offset="15,43"> <right offset="-38" /> </anchored> </string_labeled> <button_aspecteffect name="trouble_buttoneffect"> <anchored to="trouble"/> </button_aspecteffect> </sheetdata> </windowclass> </root>
Code:<root> <template name="button_aspecteffect"> <buttoncontrol> <anchored width="20" height="20"> <top /> <left anchor="right" relation="relative" offset="2" /> </anchored> <icon normal="button_action_effect" pressed="button_action_effect_down" /> <script file="common/scripts/aspect_effect.lua" /> </buttoncontrol> </template> </root>
Code:function onDragStart(button, x, y, draginfo) Debug.chat("onDragStart", getName(), button, x, y, draginfo); return true; end function onDrag(button, x, y, draginfo) --Debug.chat("onDrag", getName(), button, x, y, draginfo); return true; end function onClickDown(button, x, y) Debug.chat("onClickDown", getName(), button, x, y); return true; end function onButtonPress() Debug.chat("onButtonPress", getName()); return true; end
s'onClickDown' | s'highconcept_buttoneffect' | #1 | #9 | #3
s'onButtonPress' | s'highconcept_buttoneffect'
s'onClickDown' | s'trouble_buttoneffect' | #1 | #12 | #11
s'onButtonPress' | s'trouble_buttoneffect'
s'onClickDown' | s'highconcept_buttoneffect' | #1 | #6 | #15
s'onDragStart' | s'highconcept_buttoneffect' | #1 | #6 | #15 | dragdata = { type = s'none', desc = s'', #slots = #1, slot = #1, string = s'', num = #0, dice = { }, shortcut = { }, token = { prototype = , instance = }, custom = nil }
s'onClickDown' | s'trouble_buttoneffect' | #1 | #12 | #10
(...nothing else)
s'onDrag' | s'highconcept_buttoneffect' | #1 | #-366 | #213 | dragdata = { type = s'none', desc = s'', #slots = #1, slot = #1, string = s'', num = #0, dice = { }, shortcut = { }, token = { prototype = , instance = }, custom = nil }
s'onDrag' | s'trouble_buttoneffect' | #1 | #-284 | #109 | dragdata = { type = s'none', desc = s'', #slots = #1, slot = #1, string = s'', num = #0, dice = { }, shortcut = { }, token = { prototype = , instance = }, custom = nil }
At this point I'm completely stumped. I would appreciate any help or insight, even if it's just to point out how dumb I am for missing something obvious, or that this is intended and I'm supposed to define my controls inline. Thanks in advance.Last edited by ElementalAjah; December 11th, 2017 at 23:38. Reason: Minor correction in definition for onButtonPress debugging function.
-
December 11th, 2017, 03:59 #2
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
A couple of things:
1. I am leery of trying to do both onClickDown and onDragStart. I do not understand how the architecture can support both because yet need a click down to get a drag start. When you return true from onClickDown it should prevent the drag start (IMO) because you handled the click down. Now, if that theory is operative, it doesn't explain why there is a difference between templated version and non-templated.
2. Try using debug.console instead. The FG engine has some wonky stuff with debug.chat where debug messages are buffered and not always output to chat when the system is busy with events (I have had many occasions where a bug in my program eventually caused a crash and several messages never got written to chat window (console always seems to work though).
There also could be some other stuff going on with your controls in code you haven't posted? Do you monkey with those controls anywhere else (onInit, e.g.)?
-
December 11th, 2017, 04:26 #3
Thanks for the quick response.
1. I didn't put the onClickDown function in there until I started trying to track down the issue. On the same note, I stripped out all other script except for the four events you see there, just in case it was due to other code interfering, such as something in onInit as you suggest. To be sure, I just now removed even the other three events, with only onDragStart containing the debug statement remaining in my script. No (Fate) dice.
2. Same thing with outputting to Debug.console. I get the onDragStart message for the inline control and not the templated one.Last edited by ElementalAjah; December 11th, 2017 at 04:40. Reason: clarity
-
December 11th, 2017, 04:41 #4
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
You will find a fairly recent thread where I was having similar problems. I don't know what fixed my problems, as the code now works. I was messing with a lot, and I think I had my return statements screwed up (the three cases, true-if you handled event and no further processing, false to pass to encasing control (if any) and nil to let FG handle the even). Plus, I think I may have been inheriting from a template that had disabled in its tags without enabling it.
I am using a template that implements Dragging (see this thread), but it inherits from genericcontrol and not buttoncontrol.
-
December 12th, 2017, 00:28 #5
In an attempt to demonstrate the problem, I've created a stripped down version of the extension I'm working on to reduce everything down to the simplest case. If you load the extension with any Fate Core campaign you should see two "effect" buttons on the right side of the High Concept and Trouble fields of the main section of the character sheet window. Interacting with these buttons should recreate the same behavior shown above, log statements and all.
Last edited by ElementalAjah; December 12th, 2017 at 01:10. Reason: Added screenshot
-
December 13th, 2017, 22:41 #6
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,563
Thank you very much for narrowing this down to a simple test case. It helped tremendously to investigate the issue.
It turns out that this is related to compatibility settings. The Fate ruleset is set for FG v3.0+ compatibility, and your extension is set for FG v2.6+ compatibility. This means that any controls defined directly in the Fate ruleset, including any merges from extensions, use the v3.0+ compatibility settings and capabilities. However, any templates or classes fully defined within the extension will use the v2.6+ compatibility settings.
The big difference turns out that the "onDragStart" event did not exist until FG v3.0. Prior to v3.0, rulesets and extensions would have to figure out if it was the first onDrag call by using a tracking variable, and also capturing the onDragEnd event. A lot of code ended up resetting the drag object constantly by building a new drag object every time that onDrag was called.
If you change the version attribute of the root tag in the extension.xml file to "3.0", then both versions will work the same.
Regards,
JPG
-
December 14th, 2017, 01:52 #7
Confirmed, changing the version attribute of the root tag solved my problem. I knew it was some mistake I made somewhere, but darned if I could ever have found that on my own! Thank you SO much for your help, Moon Wizard.
-
December 14th, 2017, 04:09 #8
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
Man, I should have come up with that. I had an even stupider problem in that my own extension had compatibility set to something less than 3.0, and MW eventually got me to find that (because I started with an extension shell from a project I built a long time ago). Sorry I wasn't more helpful, Ajah.
-
December 14th, 2017, 05:14 #9
It's fine Bidmaron, your help was much appreciated just the same. And yeah, starting with an older project is more or less how I ended up in the same boat.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks