-
February 5th, 2024, 03:57 #1
- Join Date
- Mar 2020
- Posts
- 34
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)?
-
February 5th, 2024, 17:50 #2
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>
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!
-
February 6th, 2024, 02:57 #3
- Join Date
- Mar 2020
- Posts
- 34
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>
Code:<importruleset source="CoreRPG" />
Code:<windowclass name="imagepanelwindow" merge="join"> <script file="lua/my_imagewindow.lua" /> </windowclass>
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
Last edited by SieferSeesSomething; February 6th, 2024 at 03:05.
-
February 6th, 2024, 04:02 #4
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>
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!
-
February 7th, 2024, 03:39 #5
- Join Date
- Mar 2020
- Posts
- 34
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>
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!
-
February 7th, 2024, 15:16 #6
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!
-
February 7th, 2024, 15:54 #7
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!
-
February 10th, 2024, 02:20 #8
- Join Date
- Mar 2020
- Posts
- 34
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?
-
February 10th, 2024, 02:41 #9
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks