Page 1 of 1

LuaGuiElement{type="camera",entity=<follow this>}

Posted: Wed Sep 09, 2020 11:51 am
by eradicator
Aummary

A method to make camera guis automatically follow an entity.

Description

I've looked all through the API doc and through several mods, and it seems that currently the only method is on_tick? Which feels clunky for such a simple task.

What for?

Picture-in-Picture viewing of players, robots, biters, etcpp.

Re: LuaGuiElement{type="camera",entity=<follow this>}

Posted: Tue Apr 27, 2021 11:15 am
by Xorimuth
+1. Also for type = "minimap", which is how base game train GUI works.

Re: LuaGuiElement{type="camera",entity=<follow this>}

Posted: Wed Apr 28, 2021 9:37 am
by Klonan
Already exists: https://lua-api.factorio.com/latest/Lua ... ent.entity

You can write the entity to follow after creating the element

Re: LuaGuiElement{type="camera",entity=<follow this>}

Posted: Wed Apr 28, 2021 9:42 am
by Xorimuth
Klonan wrote:
Wed Apr 28, 2021 9:37 am
Already exists: https://lua-api.factorio.com/latest/Lua ... ent.entity

You can write the entity to follow after creating the element
Oh wow, thanks! I see for 'entity-preview' it says "The entity has to be set after the GUI element is created.", so maybe there's a technical reason why it can't be set in .add{} .

Re: LuaGuiElement{type="camera",entity=<follow this>}

Posted: Wed Apr 28, 2021 10:06 am
by Therenas
I added a note hinting at this functionality to the docs for the next release.

Re: LuaGuiElement{type="camera",entity=<follow this>}

Posted: Wed Apr 28, 2021 10:11 am
by Klonan
Xorimuth wrote:
Wed Apr 28, 2021 9:42 am
Oh wow, thanks! I see for 'entity-preview' it says "The entity has to be set after the GUI element is created.", so maybe there's a technical reason why it can't be set in .add{} .
Yea, something like, the creation is wrapped with propertyTree into creationParameters (Basically internal Lua format), which can't wrap an Entity* pointer,
But setting it afterwards, we can just pass the Entity* pointer right into the CustomCamera

Re: LuaGuiElement{type="camera",entity=<follow this>}

Posted: Wed Apr 28, 2021 10:39 am
by Xorimuth
Using flib.gui-beta, I can just do

Code: Select all

{type = "camera", position = spidertron.position, surface_index = spidertron.surface.index, elem_mods = {entity = spidertron}},
:D