Please provide player's cursor position or a way to highlight around the cursor

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Yehn
Fast Inserter
Fast Inserter
Posts: 108
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Please provide player's cursor position or a way to highlight around the cursor

Post by Yehn »

When a mining drill is in the player's cursor, the resource mining area is displayed with a highlight.

However, as far as I know, there is no way to do this with a modded item that is not a mining drill nor a power pole.

Therefore, as part of LuaPlayer.cursor_stack or LuaPlayer.cursor_ghost, I would like it if the position of the entity to be placed were somehow provided so I can render a visualization to the player that shows what area will be affected by the entity - before this entity is actually built.


Honktown
Filter Inserter
Filter Inserter
Posts: 819
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Honktown »

Couldn't you get the cursor position, and place a sprite maybe with the brightness multiplied by day brightness at the position? Follow the mouse around every tick if they have the item in their hand. I don't know how to tell if the character puts the item away, but tracking if they had an item in their hand and it was one you want highlighted should work.
I have mods! I guess!
Link

Boodals
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun Feb 11, 2018 7:10 pm
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Boodals »

Getting the player's mouse position will never be done because then every player would have to send a network packet every time their mouse moved.
However something to draw LuaRendering objects relative to the player's cursor ghost could be done, and has been requested previously.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2883
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by darkfrei »

What about light about the cursor by godmode in the night? Can it be seen in the multiplayer?

Rseding91
Factorio Staff
Factorio Staff
Posts: 11923
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Rseding91 »

It has been on my mental to-do to make every entity support having some "area" visualization when in the cursor. I just haven't figured out how that would interact with already-built entities and such.

Right now electric poles show all areas in the world that have electric coverage when you hold one but things like beacons don't.

I could easily make a property which just shows "an area" around the item when in the cursor that has no other logic. Unless someone has better ideas.
If you want to get ahold of me I'm almost always on Discord.

IronCartographer
Filter Inserter
Filter Inserter
Posts: 431
Joined: Tue Jun 28, 2016 2:07 pm
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by IronCartographer »

Rseding91 wrote:
Wed Dec 11, 2019 9:24 pm
I just haven't figured out how that would interact with already-built entities and such.
Does this refer to potential interactions like custom filtering of highlighting for entities that would overlap the area?

Rseding91
Factorio Staff
Factorio Staff
Posts: 11923
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Rseding91 »

IronCartographer wrote:
Wed Dec 11, 2019 9:29 pm
Rseding91 wrote:
Wed Dec 11, 2019 9:24 pm
I just haven't figured out how that would interact with already-built entities and such.
Does this refer to potential interactions like custom filtering of highlighting for entities that would overlap the area?
Something like that. Although I don't see how it would ever really work out to be anything except "just draws a square when held".
If you want to get ahold of me I'm almost always on Discord.

Honktown
Filter Inserter
Filter Inserter
Posts: 819
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Honktown »

Rseding91 wrote:
Wed Dec 11, 2019 10:15 pm
IronCartographer wrote:
Wed Dec 11, 2019 9:29 pm
Rseding91 wrote:
Wed Dec 11, 2019 9:24 pm
I just haven't figured out how that would interact with already-built entities and such.
Does this refer to potential interactions like custom filtering of highlighting for entities that would overlap the area?
Something like that. Although I don't see how it would ever really work out to be anything except "just draws a square when held".
This sounds really dumb, but could the mouse cursor be made a luaEntity, that specifically only exists/updates for the current player? (to prevent network lag) Then it would have a position, and a sprite could be drawn using luarender if the player cursor stack changed and it matched a certain item.

I don't know if a sprite can be made to 'follow' an entity. An entity can be made a target, but the only things that draw I can think of are non-moving entities: power poles, miners, turrets, etc. I can think of many reasons it would be useful for a draw_<foo> to follow an entity.
I have mods! I guess!
Link

Bilka
Factorio Staff
Factorio Staff
Posts: 2790
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Bilka »

I don't know if a sprite can be made to 'follow' an entity. An entity can be made a target, but the only things that draw I can think of are non-moving entities: power poles, miners, turrets, etc. I can think of many reasons it would be useful for a draw_<foo> to follow an entity.
Ever heard of script rendering? https://lua-api.factorio.com/latest/LuaRendering.html
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Honktown
Filter Inserter
Filter Inserter
Posts: 819
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Honktown »

Bilka wrote:
Wed Dec 11, 2019 11:31 pm
I don't know if a sprite can be made to 'follow' an entity. An entity can be made a target, but the only things that draw I can think of are non-moving entities: power poles, miners, turrets, etc. I can think of many reasons it would be useful for a draw_<foo> to follow an entity.
Ever heard of script rendering? https://lua-api.factorio.com/latest/LuaRendering.html

Code: Select all

draw_sprite{sprite=…, orientation=…, x_scale=…, y_scale=…, tint=…, render_layer=…, orientation_target=…, orientation_target_offset=…, oriented_offset=…, target=…, target_offset=…, surface=…, time_to_live=…, forces=…, players=…, visible=…, only_in_alt_mode=…} → uint64
Create a sprite.

Parameters
Table with the following fields:
sprite :: SpritePath
orientation :: float (optional): The orientation of the sprite. Default is 0.
x_scale :: double (optional): Horizontal scale of the sprite. Default is 1.
y_scale :: double (optional): Vertical scale of the sprite. Default is 1.
tint :: Color (optional)
render_layer :: RenderLayer (optional)
orientation_target :: Position or LuaEntity (optional): If given, the sprite rotates so that it faces this target. Note that orientation is still applied to the sprite.
orientation_target_offset :: Vector (optional): Only used if orientation_target is a LuaEntity.
oriented_offset :: Vector (optional): Offsets the center of the sprite if orientation_target is given. This offset will rotate together with the sprite.
target :: Position or LuaEntity: Center of the sprite.
target_offset :: Vector (optional): Only used if target is a LuaEntity.
surface :: SurfaceSpecification
time_to_live :: uint (optional): In ticks. Defaults to living forever.
forces :: array of ForceSpecification (optional): The forces that this object is rendered to.
players :: array of PlayerSpecification (optional): The players that this object is rendered to.
visible :: boolean (optional): If this is rendered to anyone at all. Defaults to true.
only_in_alt_mode :: boolean (optional): If this should only be rendered in alt mode. Defaults to false.
Return value
Id of the render object
Doesn't say if the sprite moves with a target if the target is a lua-entity.
I have mods! I guess!
Link

Yehn
Fast Inserter
Fast Inserter
Posts: 108
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by Yehn »

Rseding91 wrote:
Wed Dec 11, 2019 9:24 pm
I could easily make a property which just shows "an area" around the item when in the cursor that has no other logic. Unless someone has better ideas.
For my purposes this would be perfect.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2883
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Please provide player's cursor position or a way to highlight around the cursor

Post by darkfrei »

Once I write the mod with player's selected highlighting: https://mods.factorio.com/mod/TorchLight
The mod creates small LuaRendering.light between player and selected entity, but the light can be attached only one for them.

Post Reply

Return to “Modding interface requests”