Tracking a multiple selection

Place to get help with not working mods / modding interface.

Tracking a multiple selection

Postby galibert » Thu Oct 12, 2017 7:01 pm

Hi,

I'm trying to build a QoL mod, which I'd like in some aspects to behave like the standard build key. Specifically, I'd like to press my binding (control-mouse-1) and make it possible to drag the mouse over a series of entities and act on them. That's similar to what build-click or fill-click do. I get the initial press with a custom-input and associated on_event easily, but I'm not getting any more events when the selection changes or when the button is released, so I'm a bit at a loss there.

Is there a way to do what I want?

OG.
galibert
Burner Inserter
Burner Inserter
 
Posts: 5
Joined: Fri Sep 15, 2017 7:42 am

Re: Tracking a multiple selection

Postby eradicator » Thu Oct 12, 2017 9:52 pm

The "drag & draw" style actions you mention are not exposed to the Lua API, you'll have to build something yourself. If you want more specific hints you'll need to describe what you're trying to do in more detail. Here's a few generic hints:

defines.events.on_selected_entity_changed notifies you when the players cursor hovers over a different entity (or none?) than before.

Autofill (Modportal) might have code related to what you want to do.

If a square selection works for you there's also Selection Tool item type with associated event: defines.events.on_player_selected_area
User avatar
eradicator
Fast Inserter
Fast Inserter
 
Posts: 199
Joined: Tue Jul 12, 2016 9:03 am

Re: Tracking a multiple selection

Postby galibert » Mon Oct 16, 2017 7:00 pm

I'm trying to do https://mods.factorio.com/mods/galibert/FilteredPlacement. Square selection wouldn't work, I'll see what autofill does. Thanks for the hints.
galibert
Burner Inserter
Burner Inserter
 
Posts: 5
Joined: Fri Sep 15, 2017 7:42 am

Re: Tracking a multiple selection

Postby eradicator » Mon Oct 16, 2017 9:18 pm

I'm not sure how modifier keys like ctrl interact with custom hotkey events. You'll have to look at autofill for that. (report back tho, kinda interested :P).
If it doesn't work you could still implement a toggle-build-mode switching between normal and blueprint-fill. Also take care when reving ghosts that are fast-replacable with themselfs (inserters, belts, drills,...). Circuit connections don't properly resurrect on those if done wrong (and was labeled not-a-bug *sigh*). I tried to make something similar myself before (here's some unfinished sample code) and came to the conclusion that it would be easier to have a seperate item using on_put_item that revives ghosts from items in inventory instead of having to build the exact thing on them. Sort of like a "fill-brush".
User avatar
eradicator
Fast Inserter
Fast Inserter
 
Posts: 199
Joined: Tue Jul 12, 2016 9:03 am

Re: Tracking a multiple selection

Postby galibert » Tue Oct 17, 2017 7:21 am

eradicator wrote:I'm not sure how modifier keys like ctrl interact with custom hotkey events. You'll have to look at autofill for that. (report back tho, kinda interested :P).


Not sure what you mean. At least I can tell you that key_sequence = "CONTROL + mouse-button-1" works as I expected it, and in particular does *not* invoke item placement.

eradicator wrote:If it doesn't work you could still implement a toggle-build-mode switching between normal and blueprint-fill.


Yeah, that would work, nowhere near as nicely though obviously.

eradicator wrote:Also take care when reving ghosts that are fast-replacable with themselfs (inserters, belts, drills,...). Circuit connections don't properly resurrect on those if done wrong (and was labeled not-a-bug *sigh*).


I suspect they resurrected properly then the entity was replaced by an identical one and they went away. In my case C-M1 does not invoke item placement so I think the second step won't happen. In-place upgrade killing wiring is sad though. Wires are iffy anyway w.r.t ghosts, and copper wires are the iffiest (you can't blueprint them, bye bye power control tricks).
galibert
Burner Inserter
Burner Inserter
 
Posts: 5
Joined: Fri Sep 15, 2017 7:42 am

Re: Tracking a multiple selection

Postby eradicator » Tue Oct 17, 2017 11:26 am

galibert wrote:
eradicator wrote:I'm not sure how modifier keys like ctrl interact with custom hotkey events. You'll have to look at autofill for that. (report back tho, kinda interested :P).


Not sure what you mean. At least I can tell you that key_sequence = "CONTROL + mouse-button-1" works as I expected it, and in particular does *not* invoke item placement.

I mean that the normal mouseclick is draggable while ctrl+lmb is probably not? And i don't know how autofill does it because i've actually never used it ;P.
galibert wrote:
eradicator wrote:If it doesn't work you could still implement a toggle-build-mode switching between normal and blueprint-fill.


Yeah, that would work, nowhere near as nicely though obviously.

Some of the uglyness could be "fixed" by a complicated user-intention-detection algorithm that tries to guess what the user is trying to do. I.e. standing near ghost? Did just place a blueprint? But that's a lot of work. Which is why i concluded that i'd go for a "fill-brush" style item.
galibert wrote:
eradicator wrote:Also take care when reving ghosts that are fast-replacable with themselfs (inserters, belts, drills,...). Circuit connections don't properly resurrect on those if done wrong (and was labeled not-a-bug *sigh*).


I suspect they resurrected properly then the entity was replaced by an identical one and they went away. In my case C-M1 does not invoke item placement so I think the second step won't happen. In-place upgrade killing wiring is sad though. Wires are iffy anyway w.r.t ghosts, and copper wires are the iffiest (you can't blueprint them, bye bye power control tricks).


You can read the detailed description if you want: Self-replacable entity revive in on_put_item. If i ever have time and motivation i might make a video that properly demonstrates the behavior. Maybe then they recognize it's a bug. But probably not before 0.16.
Hm...yea. If you trigger that by an event that doesn't also trigger normal build the bug wouldn't happen. I only tested without modifier because that was the behavior i wanted.
User avatar
eradicator
Fast Inserter
Fast Inserter
 
Posts: 199
Joined: Tue Jul 12, 2016 9:03 am

Re: Tracking a multiple selection

Postby galibert » Wed Oct 18, 2017 6:46 am

eradicator wrote:I mean that the normal mouseclick is draggable while ctrl+lmb is probably not? And i don't know how autofill does it because i've actually never used it ;P.


Ctrl-LMB is also used in vanilla to fill/empty entities (with ammo, coal, modules, etc), which is definitely draggable. Technically, it's not purely dragging too, since you can have the same effect with the mouse standing still but the player moving.

What's missing is being able to get activate/deactivate events on custom inputs. Which is probably not entirely trivial if you want to allow movement, etc. Sadly, implementing the behaviour I want would take five minutes with source access. To which you add a couple of days to decide whether you want a different input than entity-fill, to name it, to translate it and to create the text and screenshot for the start-of-game hint, and of course testing. But I digress. I hope we get something similar in vanilla at one point, it would make early-game blueprints so much nicer.
galibert
Burner Inserter
Burner Inserter
 
Posts: 5
Joined: Fri Sep 15, 2017 7:42 am


Return to Modding help

Who is online

Users browsing this forum: No registered users and 3 guests