PDA

View Full Version : How to set user radial menu option on token in map?



SilentRuin
September 13th, 2020, 17:07
I have a generic asset that I add onto the map for FGU (using 5E but calling only coreRPG related stuff). When the token is added I do the following to that token:



newTokenInstance.registerMenuItem(Interface.getStr ing("my_special_menu_lock"), "lock", 4);
newTokenInstance.registerMenuItem(Interface.getStr ing("my_special_menu_unlock"), "unlock", 6);
newTokenInstance.onMenuSelection = onMenuSelection;


But I will never see these options in the right mouse radial menu - nor ever get my onMenuSelection called. I cannot find any examples in 5E/coreRPG that do anything with a tokeninstance radial menus and the dev doc for unity has some cryptic warning about needing a handler for these things.



registerMenuItem
function registerMenuItem(label, icon, ...)
This function registers a new user defined menu item. If the user selects the item, the script is notified of this through the onMenuSelection handler, if registered.

The menu item is defined by specifying the bitmap and label to use, as well as the position of the item on the menu. The position is given as a number value. To define entries in submenus, use multiple number values, with the first being the position value of the outermost submenu, and the last being the position of the actual menu item in the innermost submenu.

Trying to redefine an existing menu item will fail.

The token interface for menus is different than other objects in that a handler must be registered to intercept menu events.

Parameters

label (string)
A string to be used as the label of the menu item

icon (string)
The name of an icon resource to use as the bitmap for the menu item...A list of numbers specifying the menu item position as a number between 1 and 8, with one being the top slot, and the progression of numbers proceeding in a clockwise direction.


I know FGU has tokeninstance things defined for its radial menu that I will never be able to see or interact with - but all I can see is when I right mouse over a generic asset placed on map I see menu items at positions 1,3,7,8 so I picked 4,6 for my user defined ones. But I see nothing. I'm doing the above code when my Token.onTokenAdd callback detects my brand of token was placed.

Any clues on why this is not working?

SilentRuin
September 14th, 2020, 16:06
Has no one ever tried to get radial menus on the map to support user defined menus in FGU? It's kind of surprising nobody knows how to do this.

Moon Wizard
September 16th, 2020, 17:55
The short answer is that no one has used this capability, and it hasn't been looked at in years. Thus, it's unknown to me at this point whether it works and what the limitations are. I do know that custom menus can not override built-in menus.

I'll add it to the list of tasks to investigate.

Regards,
JPG

SilentRuin
September 16th, 2020, 18:06
The short answer is that no one has used this capability, and it hasn't been looked at in years. Thus, it's unknown to me at this point whether it works and what the limitations are. I do know that custom menus can not override built-in menus.

I'll add it to the list of tasks to investigate.

Regards,
JPG

Thanks for the answer - yeah the FGU hardcoded things would not be triggering the onMenuSelection so I understood that only user stuff would. Just could not get it to work per my example and that mysterious warning in the document that I did not understand.

I'll probably just work around it with a new window that pops up on double click and provide the options in there as I know that stuff works.

Stv
June 22nd, 2022, 21:46
oldonTokenAdd=ImageManager.onTokenAdd
ImageManager.onTokenAdd=newonTokenAdd


end


function newonTokenAdd(tokenMap)
Debug.chat("Token added to map",tokenMap)
oldonTokenAdd(tokenMap)
tokenMap.registerMenuItem(Interface.getString("ct_searchtip"), "stv", 4)
Debug.chat("Combat tracker entry is")
end


Well, some progress :)

The above works for adding a new item to the radial menu, but I am unable to get an onMenuSelection function to associate with it.
Any idea what I'm missing ?

Cheers, Steve.

JustinFreitas
June 23rd, 2022, 00:38
I've been using the radial menus for an extension and it's been going well. I looked for a way to query the radial menu to see what's there already, to avoid menu item position conflicts at runtime, but couldn't find anything. Any guidance for avoiding radial menu position conflicts with other extensions, etc? Thanks, Justin

Moon Wizard
June 23rd, 2022, 02:45
No, there’s no way to query. You’ll have to coordinate with other extension creators.

Regards,
JPG