FAForever / FA-Binary-Patches

FA Engine Patches
MIT License
6 stars 6 forks source link

Add a hook to the 'drag-filter' event that happens in the engine #30

Open Garanas opened 1 year ago

Garanas commented 1 year ago

Description

When you drag-select units the engine automatically attempts to filter them. As an example: if you drag select a tank and an engineer you'll select the tank.

Even though this behavior is fine, it doesn't give us control to customize the behavior.

Suggested change

To completely disable the engine behavior and to give Lua a chance to implement its own filtering. Specifically it would be a function that gives you all the units in the drag selection event, and the units it ends up returning would become your selection.

At the moment this is done as a post processing step as part of the OnSelectionChanged function in lua\ui\game\gamemain.lua.

As an example of the new Lua function: OnSelectionDrag(units: UserUnit[]) : UserUnit[]. It would be part of the module lua\ui\game\gamemain.lua.

What we can do with it

This would allow us to properly implement the filtering of the selection. It would also prevent 'accidentally' filtering of a selection when, for example, a UI script calls SelectUnits.

A few examples of what we can do with it are in https://github.com/FAForever/fa/pull/4905/files , which is on hold because it would likely break any UI mod that relies on how the selection works.

4z0t commented 4 weeks ago

Draft is done https://github.com/4z0t/FA-Binary-Patches/blob/SelectionFilter/section/Selection/Selection.cxx

Garanas commented 4 weeks ago

That is really nice 👍 , let's discuss how it works over voice next weekend.