FG Spreadshirt Swag
  1. #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>
    This is my template, defined in another file in my extension (common/template_common.xml, if it matters)
    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>
    So why do I think the onDragStart event isn't being captured? I have the following functions which output debug statements to the chat window defined in my script file which is used by both controls. Note that the onDrag Debug statement is commented out, because it's incredibly spammy with how often it gets called, but it does appear for both controls when it's uncommented.

    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
    With these functions set up, when I click and release on both controls, I see the onClick and on onButtonPress events captured as I would expect.
    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'
    When I try dragging both though, I only get the onDragStart for the first, inline defined control (highconcept_buttoneffect) and not the second, templated one (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)
    When I uncomment the debug line in the onDrag event, I even see that one happening for both controls, just not the "start" event for the drag.
    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 }
    And finally, just to rule out the possibility that it's the control positions or anything like that, when I switch the approach for both controls, I get the reverse behavior: the highconcept_buttoneffect control does not capture onDragStart when defined as a templated control and the trouble_buttoneffect control does when defined inline.

    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.

  2. #2

    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.)?

  3. #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

  4. #4

    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.

  5. #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.

    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by ElementalAjah; December 12th, 2017 at 01:10. Reason: Added screenshot

  6. #6
    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

  7. #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.

  8. #8

    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.

  9. #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)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Starfinder Playlist

Log in

Log in