PDA

View Full Version : Context Menus



Ken L
September 15th, 2017, 19:43
I did a quick scan during break through the radial controls but only found references to the radial graphics themselves within graphics_radial.

I assume there's no way to create my own custom radial settings or replace it with a context menu.

I currently have a semi-experimental window I hacked together a few days ago that shows the 3.5 effect icons along with a few extras on a right context click. The intent is to be able to right click a token and add an effect with the eventual side-effect of snapping the CT to that entry with the expanded effect tree for further input.

The goal here is to bind that window to the radial, or outright replace it with a context menu so I can decorate it as I please.

Is this possible before I go Easter egg hunting?

Moon Wizard
September 15th, 2017, 21:01
Radial menus are the only context menus available within the FG client.

You can use the windowcontrol.registerMenuItem function, and windowcontrol.onMenuSelection event to specify your own radial menu options. You can find examples of this usage in the CoreRPG ruleset. (There are also versions for tokeninstance and windowinstance.)

I don't remember off the top of my head, but I believe the built-in radial menus override any custom defined menus.

Regards,
JPG

Ken L
September 17th, 2017, 16:20
Hm, there's a way to jury ring this. I guess there's no plans for focus gain/loss for window controls until unity, and even then there's a backlog for that.

Moon Wizard
September 17th, 2017, 17:19
There are already windowcontrol.onGainFocus and windowcontrol.onLoseFocus events for keyboard focus.

I can't tell from your post whether that is what you were looking for, but that's what is available for focus change.

Regards,
JPG

Ken L
September 17th, 2017, 18:27
I'm not aware? Last time I assumed this I corrected myself as only number control has that documented. Focus control for window control isn't on the ruleset reference (https://www.fantasygrounds.com/refdoc/windowcontrol.xcp). It's a hacky way to spawn/de-spawn a context like window from a radial selection.

The golden grail is to detect hover loss/gain.

Moon Wizard
September 17th, 2017, 19:35
You're right. The keyboard focus is only available for stringcontrol, chatentrycontrol, and numbercontrol; since most other fields don't have keyboard focus as a possibility.

For hover, have you already looked at windowcontrol.onHover and windowcontrol.onHoverUpdate events?

Regards,
JPG

Tielc
October 25th, 2018, 18:46
I'm struggling with even a control that has focus. The basicnumber control has the function setFocus. When I use this, and also attach listener functions to other controls using onGainFocus and onLoseFocus, it's telling me it's doing something. But as soon as I type a key on my keyboard, it's still entering in the previously focused control. Is there anyway to set focus from one number entry field to another?

Tielc
October 25th, 2018, 18:49
Actually I went back, it shows that the focus switched to the new control, and then immediately switched back. Is there anyway to stop this from happening?

Moon Wizard
October 25th, 2018, 19:51
It depends on why the focus is changing. The focus will only change if the user clicks somewhere, or another control calls setFocus.

Regards,
JPG

Tielc
October 25th, 2018, 23:52
I'm performing the setFocus() to a control we'll call editWounds (so editWounds.setFocus()) from within an onDoubleClick() event in a control we'll call wounds (so wounds.onDoubleClick()).
Each has the following events with the names changed
function onGainFocus()
Debug.chat("<controlname> gained focus");
end

and

function onLoseFocus()
Debug.chat("<controlname> lost focus");
end

The work flow is double click on the wounds control, at which point I would like focus to change to the editWounds control. Currently, when I do this, I can see that focus does change to the editWounds control, but then returns to the wounds control.
This is the output I get.
wounds has gained focus
wounds has lost focus
woundsEdit has gained focus
woundsEdit has lost focus
wounds has gained focus

So I'm not sure what is causing the focus to return to the original control. Is this possibly something at a very low level that the double click even is doing?

pindercarl
October 25th, 2018, 23:55
Shot in the dark, the second click on wounds may be resetting the focus to wounds. Try switching focus to woundsEdit on a single click and see what happens.

Tielc
October 26th, 2018, 00:19
So onClickDown() does the same thing as onDoubleClick(). onClickRelease does properly pass the focus to the other control, but this would never allow me to select the original control and edit its contents. I did try catching an onChat() and typing in a special character which I captured in an if statement and passing Focus, and that worked. So it feels like it's something with the click events themselves.

I've also looked at the hierarchy of classes that make the basic number up windowcontrol -> numberfield -> number -> basicnumber and their scripts, and none of them appear to have an override for the method.

pindercarl
October 26th, 2018, 00:27
I didn't mean for it to be a permanent solution, just trying to determine if the second click was return focus to the wounds control. I'm not sure from your post if that was the case, or not.

Tielc
October 26th, 2018, 00:41
I didn't mean to come across that way; onClickRelease() works, and onClickDown() gives me the same challenge I had before. It looks like maybe onHover() could internally setFocus maybe?

Edit: No, that's not doing it either.

Moon Wizard
October 26th, 2018, 00:50
Are you returning "true" in onClickDown to prevent FG from performing the default behavior?

Regards,
JPG

Tielc
October 26th, 2018, 00:58
I have tried returning true in both onClickDown and onDoubleClick, both give the same results. I can watch the focus change to the specified control for about a split second and then it returns.

Tielc
October 26th, 2018, 01:28
This is a private video where I'm hopefully trying to explain this a little better what I'm trying to accomplish. I am sorry for my dog chewing on the hardest toy he could find in the background.


https://www.youtube.com/watch?v=rPHbgpo5EU4

Moon Wizard
October 26th, 2018, 02:56
Do you have a copy of the current code extension which has the issue, and steps to recreate? That's the easiest way for me to investigate.

Regards,
JPG

Tielc
October 26th, 2018, 13:05
This is the extension as I would prefer it to work. One thing I noticed this morning. If I double click, before I release the cursor on the second double click; I move the cursor away from the initial control, the focus changes as expected. So it has to be something with the fact that the cursor is still over the control.

Tielc
October 26th, 2018, 15:08
You can actually see this issue happening without my extension. If you open the record_char_main.xml file from common in the 5e Ruleset and add a doubleclick event to say the wounds field like so

function onDoubleClick(x,y)
window.hp.setFocus();
return true;
end

Then when you run FG and double click on wounds, you can see the focus switch to the hp field and then immediately return to the wounds field.

Tielc
October 26th, 2018, 15:27
I just checked this on the inventory tab to make sure this wasn't an isolated incident. I added a double click to set focus to all of the coin fields to advance to the next one. The same thing happens. It for a split-second highlights the next coin field and then immediately returns. So this appears to be something fundamental with either the cursor hovering an element, or the numberfield itself capturing its own focus.

Tielc
October 26th, 2018, 16:03
GOT IT! It's something in the base level onClickRelease() event. I did an overwrite on numberboxes and it fixed the issue as shown below. So, there's something in the base class' onClickRelease event that's reclaiming Focus. I don't see it in the rulesets, so I'm guessing this is base level.

function onClickRelease(button,x,y)
return true;
end

Moon Wizard
October 26th, 2018, 16:04
I haven’t had a chance to load the files yet; but are you also capturing the onClickRelease event and returning true. Without having looked at the specific code yet; the FG client code could be setting focus on click release as well.

Regards,
JPG

Tielc
October 26th, 2018, 16:27
This is causing new issues now where onclick apparently doesn't capture focus. Working on a workaround for this now.

Moon Wizard
October 26th, 2018, 16:56
Whenever I capture an onClickDown event, I always add an onClickRelease event as well. This allows me full control over what happens when someone clicks on a field, including whether to setFocus or not.

JPG

Tielc
October 26th, 2018, 17:10
That's what I've done. I've removed the set focus from the OnClickRelease and added to the onClickDown. Seems to be working now as expected. Now going to template this for the 4 places I want to use it.

Just different from how I'm used to WinForms and XAML working with controls.

Tielc
October 28th, 2018, 00:11
Just wanted to drop in and say thanks for all the help. I got this extension working how I wanted. You can see the changed in the video in this post. I'm quite proud of the edit fields capability I added to the character sheet and combat trackers.

https://www.fantasygrounds.com/forums/showthread.php?44140-Current-HP-Extension-for-5E-Ruleset&p=392243&viewfull=1#post392243