Tracking a multiple selection

Place to get help with not working mods / modding interface.
Post Reply
galibert
Inserter
Inserter
Posts: 42
Joined: Fri Sep 15, 2017 7:42 am
Contact:

Tracking a multiple selection

Post by galibert »

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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Tracking a multiple selection

Post by eradicator »

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
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

galibert
Inserter
Inserter
Posts: 42
Joined: Fri Sep 15, 2017 7:42 am
Contact:

Re: Tracking a multiple selection

Post by galibert »

I'm trying to do https://mods.factorio.com/mods/galibert ... dPlacement. Square selection wouldn't work, I'll see what autofill does. Thanks for the hints.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Tracking a multiple selection

Post by eradicator »

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".
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

galibert
Inserter
Inserter
Posts: 42
Joined: Fri Sep 15, 2017 7:42 am
Contact:

Re: Tracking a multiple selection

Post by galibert »

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).

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Tracking a multiple selection

Post by eradicator »

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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

galibert
Inserter
Inserter
Posts: 42
Joined: Fri Sep 15, 2017 7:42 am
Contact:

Re: Tracking a multiple selection

Post by galibert »

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.

Post Reply

Return to “Modding help”