Select counters via a button

I’m creating an extension, and I want to have a toolbar button that selects all counters of a certain type, e.g. “select all red counters”. I specifically want to change the state of all the red counters to selected, so the user can then do something else with them (i.e. delete just those counters, move them, rotate them, etc). As I understand it this is different to just defining a global key command which only the red counters react to?

I’m new to module and extension design, but have figured out enough to incorporate custom code into an extension so I’d be happy with not being limited to what’s in the extension editor. I can see many ways to find all the red counters, I just can’t see a way to change their state to selected (not using the mouse to click them individually). Is there a way to do this?

There is a trait to remove a piece from the current selection (Deselect), but I don’t believe there is any way to automatically add pieces to a selection, no. I’m sure it’s possible with custom code (probably can be reverse-engineered from the Deselect code).

Or, you could post a request in the Feature requests forum, and you might get lucky (I believe Cattlesquat only recently added Deselect, so he might be willing to add the reverse feature, too).

According to the reference, the deselect trait can be used to select a piece:

Deselection type:

Choose whether you wish to deselect this piece, deselect all pieces, or select only this piece.

This probably won’t result in multiple pieces being selected though. Instead a single GKC might just select every valid piece in turn.

Ah, the reference image in the docs is missing the Deselection type drop box, so I missed that. But yes, it only has the option to “Select ONLY this piece”, so not useful for selecting multiple pieces.

Success! Thanks @jrwatts and @Benkyo, I did as suggested and looked at the code for the Deselect trait, it removes pieces from the current DragBuffer and KeyBuffer, so all I had to do was the opposite and add my counters to these buffers. Seems to do what I intended…

1 Like