Tooltip when hovering over a custom property

Hello,
I made this script that simple creates a entityType string custom property on the selected images:

// Register a new action called "TemplateAction"
let TemplateAction4 = tiled.registerAction("TemplateAction4", function(action) 
{
    let tilemap = tiled.activeAsset;
    
    // Ensure there's a valid tilemap
    if (!tilemap) {
        tiled.alert("No active tilemap found.");
        return;
    }

    // Loop through all selected objects and print their IDs
    let selectedObjects = tilemap.selectedObjects; // Get selected objects
    if (selectedObjects.length === 0) {
        tiled.alert("No objects are selected.");
    } 
    else 
    {
        selectedObjects.forEach(obj => 
        {
            // Check if the "imagePath" property exists by trying to get its value
            let entityType = obj.property("entityType");
            if (entityType === undefined) 
            {
                // Create imagePath property if it doesn't exist
                obj.setProperty("entityType", "enemy" );
            }
            else 
            {
                tiled.alert("entityType already exists");
            }
        });
    }
});

TemplateAction4.text = "add entityType attr"; // Display name in the menu

tiled.extendMenu("Edit", [
	{ action: "TemplateAction4", before: "MapProperties" }
]);

It works fine. I just want to be able to see a tool tip when I hover over showing a message like: “valid entity types are enemy, npc, prop, collider and decoration”

I check the api the toolTip seems to be a function for Qt. I don’t know much about Tiled scripting but I think that what I am doing is an Action type script, but the toolTip is for Qt widgets right? So is it possible to dispaly a tool tip on my custom property?

Also, can I put the actions on a shelf to be more accessible?
I don’t like having to go to the edit menu each time.

thanks

This is currently not possible and is covered by this issue.

However, in your case it sounds like it would be better if you used a custom enum type. This way, the field will have only predefined options in a combo box:

By default enums store as strings, so no change should be necessary in your engine. From a script, the way to add such a custom type (once it is added to the project) is by using tiled.propertyValue:

obj.setProperty("entityType", tiled.propertyValue("EnemyType", "enemy"));

Unfortunately, it is not possible yet to put a scripted action on a tool bar. This is only possible for custom tools at the moment. This missing feature is covered by this issue. In the meantime, you can associate a shortcut with your action or use the Action Search (Ctrl+Shift+P) to trigger the action.

This feature may not be that hard to add, since it should be very similar to extending menus. I just didn’t get around to it so far.

1 Like

Great, thanks. That’s good enough.

1 Like