DICE PACKS BUNDLE
  1. #1

    Using Windowcontrol Function for an Existing Class

    So my current practice project involves wanting something to happen when someone double clicks an image. I found a function to do that for tokens, and successfully used it to trigger an event when a token was double-clicked in my practice project using Token.addEventHandler and connecting it to my own on double click event, but I was hoping to make something more generic for when they double click anywhere on an image.

    The closest I could find is an onDoubleClick(x, y) for the windowcontrol class, which I know is inherited by everything else, including image controls.

    There's got to be some way to put together this information, but I'm not sure what the next step is lol.

    Is it related to the "merge" thing I found in the API documents? Do I need to create my own image control windowclass and give it an onDoubleClick event of some sort and then merge it to the normal one somehow? Does that sound close, or is there something else I do (if it's possible)?

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,413
    Look at campaign\record_image.xml in the CoreRPG ruleset. There's the top level "imagewindow" windowclass and also the "imagepanelwindow" windowclass that is specific to just the image (not the surrounding toolbars).

    Both of these windowclasses have the same script associated with them - campaign/scripts/imagewindow.lua which doesn't have an onDoubleClick handler (which is good, so we don't need to worry about overwriting).

    Assuming you just want to add the onDoubleClick handler to the "imagepanelwindow" windowclass then you could do something like the following in an extension or ruleset layered on top of CoreRPG:

    Code:
    	<windowclass name="imagepanelwindow" merge="join">
    		<script file="campaign/scripts/my_imagewindow.lua" />
    	</windowclass>
    Then code your onDoubleClick handler function in campaign/scripts/my_imagewindow.lua in your extension/layered ruleset.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Thanks for the help! I was hoping it would be that simple. So far, it's not working, but I'm guessing I just missed something minor. I'll keep trying stuff, but if you can see something obvious I'm missing here, I'd appreciate it.

    So, my project is organized like one of the stickied extension tutorials, which what I started with, got halfway through, and have been adding onto doing my own thing with since then. Only important part relevant here is to confirm that I'm pointing to TutorialWindow.xml.
    In extension.xml,
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!-- This is our MVP for the Extension Tutorial -->
    <root release="4.4" version="3">
    	<properties>
    		<name>Extension Tutorial - Jeffery W. Redding</name>
    		<version>0.0.1</version>
    		<author>Jeffery W. Redding</author>
    		<description>
    		A really simple extension file for
    		creating a really simple extension
    		</description>
    	</properties>
    	<base>
    		<script name="ExtTutorial" file="lua/ExtensionTutorial.lua" />
    		<script name="LibraryDataTutorial" file="lua/data_library_tutorialext.lua" />
    
    		<includefile source="xml/TutorialWindow.xml" />
    		<includefile source="xml/ExtTutorial_Templates.xml" />
    
    		<!-- String resources -->
    		<includefile source="strings/strings.xml" />
    
    		<!-- Image resources -->
    		<icon name="ping_img" file="graphics/TutorialTitle5E.png" />
    	</base>
    </root>
    I tried adding this to my extension.xml file below <properties> and above <base> and it didn't help either, but let me know if I'm supposed to add it back in.
    Code:
    <importruleset source="CoreRPG" />
    In TutorialWindow.xml, below root and next to another windowclass I already defined:
    Code:
    	<windowclass name="imagepanelwindow" merge="join">
    		<script file="lua/my_imagewindow.lua" />
    	</windowclass>
    (But in my app data folder, it's organized like C:\Users\me\AppData\Roaming\SmiteWorks\Fantasy Grounds\extensions\ext_tutorial\lua, so I assume my different file location is okay.)

    In my_imagewindow.lua, I only have the following code right now:
    Code:
    function onDoubleClick(x, y)
    	Debug.console("my_imagewindow.onDoubleClick", "Double clicking successful.");
    
    	return true;
    end
    Not sure what else I could be missing. I keep opening the console, and double-clicking in an open image with this practice extension loaded and no message is popping up in the console. Other functions in my ExtensionTutorial.lua file are working, so it's not like my whole extension is broken, just this new part I'm trying to add so far. And of course I appreciate the help so far!
    Last edited by SieferSeesSomething; February 6th, 2024 at 03:05.

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,413
    Ah yes, sorry - I didn't check whether the windowinstance object has the onDoubleClick handler, and it doesn't. My mistake for making that assumption.

    We need to have the code in the image control:

    Code:
    <windowclass name="imagepanelwindow" merge="join">
    	<sheetdata>
    		<imagepanel_record name="image">
    			<script file="lua/my_imagewindow.lua" />
    		</imagepanel_record>
    	</sheetdata>
    </windowclass>
    I haven't tested this, I think this should work, but it might not be 100% correct.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  5. #5
    Nothing so far. But I know I'm close because I've tried variations of the code you sent me, such as this:
    Code:
    <windowclass name="char_attribute" merge="join">
    		<script file="lua/my_imagewindow.lua" />
    	</windowclass>
    and it displayed the text in the console when i double-clicked attributes in the character sheet.

    No idea why it's not working for images, though. I've been drilling into the logic and the xml templates and I can see where you were going: <imagepanel_record> contains <image_record_step> which contains <imagecontrol name="image">. And according to the developer guide docs, imagecontrol inherits windowcontrol, which has onDoubleClick(x,y) as a function. So this has been very educational so far, and it all makes sense to me, I just don't get why the code you gave me isn't working. That's the only part I don't understand so far..

    I'll keep trying! But let me know if you get any more ideas on what might not be working. Once again, thanks! And appreciate all the help!

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,413
    I wonder if it makes a difference what image edit mode you're in? We may need to see if an FG dev gives us some feedback in regards to when/if onDoubleClick works in an image control.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,413
    Quote Originally Posted by Trenloe View Post
    Ah yes, sorry - I didn't check whether the windowinstance object has the onDoubleClick handler, and it doesn't. My mistake for making that assumption.

    We need to have the code in the image control:

    Code:
    <windowclass name="imagepanelwindow" merge="join">
    	<sheetdata>
    		<imagepanel_record name="image">
    			<script file="lua/my_imagewindow.lua" />
    		</imagepanel_record>
    	</sheetdata>
    </windowclass>
    I haven't tested this, I think this should work, but it might not be 100% correct.
    I added some code to check if this was being initialized (onInit), and it wasn't - the following does initialize the code when an image is opened, but mouse click events don't trigger, so I'm guessing that the imagecontrol suppresses these events:

    Code:
    	<windowclass name="imagewindow" merge="join">
    		<sheetdata>			
    			<image_record name="image">
    				<script file="campaign/scripts/my_imagewindow.lua" />
    			</image_record>
    		</sheetdata>
    	</windowclass>
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  8. #8
    Thanks for looking into it! That's interesting that OnInit triggers for that imagewindow but not mouse click events. If a dev can confirm or not, that would be great. But maybe I'll change tack on my practice project because I think I'm running out of ideas lol. Like, add a context menu option and run the code i made that way instead. Extensions can do that, right?

  9. #9
    pindercarl's Avatar
    Join Date
    Jan 2015
    Posts
    976
    Blog Entries
    2
    Quote Originally Posted by Trenloe View Post
    I wonder if it makes a difference what image edit mode you're in? We may need to see if an FG dev gives us some feedback in regards to when/if onDoubleClick works in an image control.
    The double-click event on image controls overrides the base window control behavior and does not call the onDoubleClick function.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
5E Character Create Playlist

Log in

Log in