Larkinabout / fvtt-token-action-hud-core

Token Action HUD is a repositionable HUD of actions for a selected token.
14 stars 22 forks source link

How should a checkable/selectable item be initialised? #41

Closed farling42 closed 1 year ago

farling42 commented 1 year ago

I have some entries which I want to show if they are selected or not.

What field needs adding to the action that I create?

I can see a "selected" field being set, but it doesn't change how anything is displayed in the HUD.

Larkinabout commented 1 year ago

The selected flag is to track actions added/removed by the user.

If I'm understanding correctly, you'll want to add the 'toggle' class to the cssClass property of the action and add 'active' class when the action is selected/toggled on.

Larkinabout commented 1 year ago

Here's an example from the D&D 5e code:

const active = this.actors.every((actor) => {
                const effects = actor.effects
                return effects
                    .map((effect) => effect.flags?.core?.statusId)
                    .some((statusId) => statusId === id)
            })
                ? ' active'
                : ''
            const cssClass = `toggle${active}`
farling42 commented 1 year ago

Which file is the dnd5e extract from? So that I can see it in more context.

Larkinabout commented 1 year ago

That one is from the _buildConditions method in action-handler.js.

farling42 commented 1 year ago

I'm setting the cssClass parameter to either "toggle" or "toggleactive", but that only changes the colour of the glow when I hover the mouse over the button, it doesn't show when I open the menu.

I can see it working properly in dnd5e.

Larkinabout commented 1 year ago

'toggle' and 'active' are separate css classes, so you'll need to put a space between them.

farling42 commented 1 year ago

Thanks, that is working now.