diff --git a/OpenRA.Mods.Common/Traits/Encyclopedia.cs b/OpenRA.Mods.Common/Traits/Encyclopedia.cs index 320ec37f59..3f82486b89 100644 --- a/OpenRA.Mods.Common/Traits/Encyclopedia.cs +++ b/OpenRA.Mods.Common/Traits/Encyclopedia.cs @@ -25,6 +25,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Group under this heading.")] public readonly string Category; + [Desc("Scale the actor preview.")] + public readonly float Scale = 1f; + public override object Create(ActorInitializer init) { return Encyclopedia.Instance; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs index 9c8c565be4..36a906267c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs @@ -24,6 +24,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { readonly World world; readonly ModData modData; + readonly Dictionary info = new(); readonly ScrollPanelWidget descriptionPanel; readonly LabelWidget descriptionLabel; @@ -60,28 +61,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic actorList.RemoveChildren(); - var actorEncyclopediaPair = GetFilteredActorEncyclopediaPairs(); - var categories = actorEncyclopediaPair.Select(a => a.Value.Category).Distinct(). - OrderBy(string.IsNullOrWhiteSpace).ThenBy(s => s); - foreach (var category in categories) - { - CreateActorGroup(category, actorEncyclopediaPair - .Where(a => a.Value.Category == category) - .OrderBy(a => a.Value.Order) - .Select(a => a.Key)); - } - - widget.Get("BACK_BUTTON").OnClick = () => - { - Game.Disconnect(); - Ui.CloseWindow(); - onExit(); - }; - } - - IReadOnlyCollection> GetFilteredActorEncyclopediaPairs() - { - var actors = new List>(); foreach (var actor in modData.DefaultRules.Actors.Values) { if (actor.TraitInfos().Count == 0) @@ -95,10 +74,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (encyclopedia == null) continue; - actors.Add(new KeyValuePair(actor, encyclopedia)); + info.Add(actor, encyclopedia); } - return actors; + var categories = info.Select(a => a.Value.Category).Distinct(). + OrderBy(string.IsNullOrWhiteSpace).ThenBy(s => s); + + foreach (var category in categories) + { + CreateActorGroup(category, info + .Where(a => a.Value.Category == category) + .OrderBy(a => a.Value.Order) + .Select(a => a.Key)); + } + + widget.Get("BACK_BUTTON").OnClick = () => + { + Game.Disconnect(); + Ui.CloseWindow(); + onExit(); + }; } void CreateActorGroup(string title, IEnumerable actors) @@ -130,6 +125,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void SelectActor(ActorInfo actor) { + var selectedInfo = info[actor]; selectedActor = actor; var typeDictionary = new TypeDictionary() @@ -143,6 +139,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic typeDictionary.Add(inits); previewWidget.SetPreview(actor, typeDictionary); + previewWidget.GetScale = () => selectedInfo.Scale; var text = ""; @@ -157,9 +154,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic text += $"Requires {prerequisites.JoinWith(", ")}\n\n"; } - var info = actor.TraitInfoOrDefault(); - if (info != null && !string.IsNullOrEmpty(info.Description)) - text += WidgetUtils.WrapText(FluentProvider.GetMessage(info.Description) + "\n\n", descriptionLabel.Bounds.Width, descriptionFont); + if (selectedInfo != null && !string.IsNullOrEmpty(selectedInfo.Description)) + text += WidgetUtils.WrapText(FluentProvider.GetMessage(selectedInfo.Description) + "\n\n", descriptionLabel.Bounds.Width, descriptionFont); var height = descriptionFont.Measure(text).Y; descriptionLabel.GetText = () => text;