Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: ActorEditLogic: support for dynamic generation of items in dropdown #21274

Open
wants to merge 1 commit into
base: bleed
Choose a base branch
from

Conversation

michaeldgg2
Copy link
Contributor

This PR makes it possible for EditorActorDropdown to dynamically generate items for particular actor.

This requires second constructor for EditorActorDropdown to keep backward-compatibility with existing traits (which will still use old callbacks GetLabels and GetValue).

@@ -340,14 +340,16 @@ ScrollItemWidget SetupItem(PlayerReference option, ScrollItemWidget template)
initContainer.Bounds.Height += dropdownContainer.Bounds.Height;
dropdownContainer.Get<LabelWidget>("LABEL").GetText = () => ddo.Name;

var editorActionHandle = new EditorActorOptionActionHandle<string>(ddo.OnChange, ddo.GetValue(actor));
var labels = ddo.GetLabels(actor);
Copy link
Member

@PunkPun PunkPun Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't cacheing this defeat the desire for labels to be dynamic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the labels are still cached, just the cache is not directly inside EditorActorDropdown as a field, but instead it's in a closure in one of the constructors.

@pchote
Copy link
Member

pchote commented Dec 27, 2023

IMO adding a new constructor just for downstream use isn't a great idea - it is likely to break or be removed in the future. If there's a good motivation for per-actor items then we should make the default logic use the same code paths.

@michaeldgg2
Copy link
Contributor Author

Yes, it might seem it's somewhat specific to our mod, but this can be used any other mod. But I agree that there might be a better solution for our specific use case.

I'm reposting two more solutions from Discord here:

Another solution that I can think of is to create a completely separate IEditorActorOptions object and then widget for it - just for actor references. The trait creating IEditorActorOptions could then customize, which actors to show, or other stuff. But I believe this would be even more specific to our situation.

Yet another solution: make it possible to create entirely custom IEditorActorOptions in mod code, i.e. insert extensibility point in ActorEditLogic, which could add widgets into initContainer. This would make editor more extensible and customizable by a mod, but it would require some more work to hook it up into the infrastructure of ActorEditLogic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants