Mouse interaction events with tiles and positions on a surface

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 682
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Mouse interaction events with tiles and positions on a surface

Post by raiguard »

Hello. I have a few requests related to the mouse cursor. More specifically, in how the cursor interacts with a surface.

I would like to be able to detect when the cursor clicks on a surface. The idea is that an event is sent when the left, middle, or right mouse buttons are clicked, containing the surface clicked on, the position clicked on that surface, the player who clicked it, which mouse button was pressed, and whether it was a "down" click or an "up" click (press or release of the mouse button).

I would also like to be able to access the mouse cursor's position on a surface somehow. I have a few ideas:

1. Save the mouse position on a surface to a global variable that can be accessed
2. Create an event that fires whenever the mouse cursor moves to another tile on a surface
3. Use the already requested on_surface_click event, but make it so that if the mouse is clicked and held, it will fire that event every time the mouse moves to another tile

Each method has its own strengths and weaknesses. I'm not actually sure that the first method is possible, for I don't think the Factorio API does that kind of thing. The second method goes with the methodology of the API, but could get sort of performance heavy if a bunch of mods were calling it (after all, the mouse cursor moves all the time). It is also the most flexible. The third method is sort of convoluted, and only works for dragging the mouse (it won't give the mouse's position unless it's dragging), but would work for my specific usecase as well.

I hope that made sense. I'm not very good at explaining things so forgive me if I was confusing. I'll try to clarify anything if needed.

EDIT: While we're at it, why not add the ability to define a custom mouse cursor as well? :)
Don't forget, you're here forever.
Post Reply

Return to “Modding interface requests”