How to make a point selection tool (like artillery remote)?

Place to get help with not working mods / modding interface.
Post Reply
beiju
Inserter
Inserter
Posts: 42
Joined: Thu Feb 02, 2017 3:52 pm
Contact:

How to make a point selection tool (like artillery remote)?

Post by beiju »

I'm trying to make a tool that the player can hold in their cursor and click to select a single point, like the artillery remote. My first attempt was to use a capsule of type artillery-remote, but that seems hard-coded to have artillery behavior. All the capsule types seem to have some undesired hardcoded behavior. I settled on using the use-on-self type with an action that has infinite range and does 0 damage on yourself. The undesired behavior here is that the item gets used up, so in my event handler I have to give the player another one -- but, it doesn't get used up until after the event handler so what I actually have to do is set a flag so that the on_tick handler (which I use anyway) can give it back on the next tick.

Obviously, that's a mess. Is there a better way to do this? Note that I don't want to allow the user to select an area, so selection-tool is not helpful unless I missed a way to tell it to only select a point. Also, being able to use it in the zoomed-out map view, like the artillery-remote, would be ideal but isn't required.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to make a point selection tool (like artillery remote)?

Post by Klonan »

I would recommend the selection tool

If you make the selection box invisible, people won't be inclined to select an area,
And even if they do select and area, you can always just use the center of that area or something

maybe we could be some way to select from the map view, not sure

It also has the added benefit that 'shift + click' can have different functionality

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

Re: How to make a point selection tool (like artillery remote)?

Post by eradicator »

Klonan wrote:I would recommend the selection tool

If you make the selection box invisible, people won't be inclined to select an area,
And even if they do select and area, you can always just use the center of that area or something
You have to make extra sprites to also hide the selection boxes around everything in the selected area for that to work, because there is no selection_mode = 'none' (Consider this a request ;). Here's the comment in my code from when i tried that last week:

Code: Select all

  -- Valid values are: blueprint, deconstruct, cancel-deconstruct, items, trees, buildable-type, tiles, items-to-place, any-entity, any-tile, matches-force
  selection_mode = {'any-entity'},
Apart from that it's probably the cleanest implementation you can get. Remaining side effect would be that that event is raised on mouse_up instead of mouse_down like everything else. Where right_bottom would be the coordinates of the cursor on mouse_up.

An easier implementation would be to add an invisible (or visible if you want a targeting marker) place_result entity with (collision_mask={},flags={'placeable-off-grid'}) to your item and use on_put_item, which is also raised if the player uses it outside of building_reach. Side effects: The entity-preview is dynamicallay tinted green/yellow/red depending on building_reach.
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.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to make a point selection tool (like artillery remote)?

Post by Klonan »

eradicator wrote:
Klonan wrote:I would recommend the selection tool

If you make the selection box invisible, people won't be inclined to select an area,
And even if they do select and area, you can always just use the center of that area or something
You have to make extra sprites to also hide the selection boxes around everything in the selected area for that to work, because there is no selection_mode = 'none' (Consider this a request ;). Here's the comment in my code from when i tried that last week:

Code: Select all

  -- Valid values are: blueprint, deconstruct, cancel-deconstruct, items, trees, buildable-type, tiles, items-to-place, any-entity, any-tile, matches-force
  selection_mode = {'any-entity'},
Apart from that it's probably the cleanest implementation you can get. Remaining side effect would be that that event is raised on mouse_up instead of mouse_down like everything else. Where right_bottom would be the coordinates of the cursor on mouse_up.

An easier implementation would be to add an invisible (or visible if you want a targeting marker) place_result entity with (collision_mask={},flags={'placeable-off-grid'}) to your item and use on_put_item, which is also raised if the player uses it outside of building_reach. Side effects: The entity-preview is dynamicallay tinted green/yellow/red depending on building_reach.
in 0.17 we have force conditions you can set on the flag, so you can hide it with two incompatible conditions:

Code: Select all

selection_mode = {"friend", "enemy"}
Right bottom isn't always the last mouse position, you can create the selection box in any direction:



The other solution of the entity and on_put_item works well, I use it in MIRV:
https://github.com/Klonan/MIRV/blob/master/control.lua

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

Re: How to make a point selection tool (like artillery remote)?

Post by eradicator »

Klonan wrote: in 0.17 we have force conditions you can set on the flag, so you can hide it with two incompatible conditions:

Code: Select all

selection_mode = {"friend", "enemy"}
I didn't even consider multi-conditions. Though intuitively i'd have assumed they'd be combined by OR and not AND, had you not explained that.
Klonan wrote:Right bottom isn't always the last mouse position, you can create the selection box in any direction:
Hrng. Yea.
Klonan wrote: The other solution of the entity and on_put_item works well, I use it in MIRV:
https://github.com/Klonan/MIRV/blob/master/control.lua
Haven't used MIRV yet. Does it have a target marker ala command-and-conquer? And if yes how do you handle the tinting of the entity preview? (Can we perhaps get a prototype flag/property to disable the tinting?)
cctarget.png
cctarget.png (9.06 KiB) Viewed 1233 times
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.

Post Reply

Return to “Modding help”