Allow mods to display Encyclopedia production info.
This commit is contained in:
@@ -28,6 +28,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Scale the actor preview.")]
|
[Desc("Scale the actor preview.")]
|
||||||
public readonly float Scale = 1f;
|
public readonly float Scale = 1f;
|
||||||
|
|
||||||
|
[Desc("Ignore the Buildable trait when listing information.")]
|
||||||
|
public readonly bool HideBuildable = false;
|
||||||
|
|
||||||
|
[Desc("Specifies a production queue type if the actor can be built from multiple queues.")]
|
||||||
|
public readonly string BuildableQueue = null;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return Encyclopedia.Instance; }
|
public override object Create(ActorInitializer init) { return Encyclopedia.Instance; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
@@ -23,6 +24,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
public class EncyclopediaLogic : ChromeLogic
|
public class EncyclopediaLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
|
[FluentReference("prerequisites")]
|
||||||
|
const string Requires = "label-requires";
|
||||||
|
|
||||||
readonly World world;
|
readonly World world;
|
||||||
readonly ModData modData;
|
readonly ModData modData;
|
||||||
readonly Dictionary<ActorInfo, EncyclopediaInfo> info = new();
|
readonly Dictionary<ActorInfo, EncyclopediaInfo> info = new();
|
||||||
@@ -41,6 +45,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly Sprite portraitSprite;
|
readonly Sprite portraitSprite;
|
||||||
readonly Png defaultPortrait;
|
readonly Png defaultPortrait;
|
||||||
|
|
||||||
|
readonly Widget productionContainer;
|
||||||
|
readonly LabelWidget productionCost;
|
||||||
|
readonly LabelWidget productionTime;
|
||||||
|
readonly Widget productionPowerIcon;
|
||||||
|
readonly LabelWidget productionPower;
|
||||||
|
|
||||||
ActorInfo selectedActor;
|
ActorInfo selectedActor;
|
||||||
ScrollItemWidget firstItem;
|
ScrollItemWidget firstItem;
|
||||||
|
|
||||||
@@ -79,6 +89,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
actorList.RemoveChildren();
|
actorList.RemoveChildren();
|
||||||
|
|
||||||
|
productionContainer = descriptionPanel.GetOrNull("ACTOR_PRODUCTION");
|
||||||
|
productionCost = productionContainer?.Get<LabelWidget>("COST");
|
||||||
|
productionTime = productionContainer?.Get<LabelWidget>("TIME");
|
||||||
|
productionPowerIcon = productionContainer?.Get("POWER_ICON");
|
||||||
|
productionPower = productionContainer?.Get<LabelWidget>("POWER");
|
||||||
|
|
||||||
foreach (var actor in modData.DefaultRules.Actors.Values)
|
foreach (var actor in modData.DefaultRules.Actors.Values)
|
||||||
{
|
{
|
||||||
if (actor.TraitInfos<IRenderActorPreviewSpritesInfo>().Count == 0)
|
if (actor.TraitInfos<IRenderActorPreviewSpritesInfo>().Count == 0)
|
||||||
@@ -184,20 +200,49 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (titleLabel != null)
|
if (titleLabel != null)
|
||||||
titleLabel.Text = ActorName(modData.DefaultRules, actor.Name);
|
titleLabel.Text = ActorName(modData.DefaultRules, actor.Name);
|
||||||
|
|
||||||
var text = "";
|
var bi = actor.TraitInfoOrDefault<BuildableInfo>();
|
||||||
var buildable = actor.TraitInfoOrDefault<BuildableInfo>();
|
|
||||||
if (buildable != null)
|
if (productionContainer != null && bi != null && !selectedInfo.HideBuildable)
|
||||||
{
|
{
|
||||||
var prerequisites = buildable.Prerequisites
|
productionContainer.Visible = true;
|
||||||
|
var cost = actor.TraitInfoOrDefault<ValuedInfo>()?.Cost ?? 0;
|
||||||
|
|
||||||
|
var time = BuildTime(selectedActor, selectedInfo.BuildableQueue);
|
||||||
|
productionTime.Text = WidgetUtils.FormatTime(time, world.Timestep);
|
||||||
|
|
||||||
|
var costText = cost.ToString(NumberFormatInfo.CurrentInfo);
|
||||||
|
productionCost.Text = costText;
|
||||||
|
|
||||||
|
var power = actor.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(i => i.Amount);
|
||||||
|
if (power != 0)
|
||||||
|
{
|
||||||
|
productionPowerIcon.Visible = true;
|
||||||
|
productionPower.Visible = true;
|
||||||
|
productionPower.Text = power.ToString(NumberFormatInfo.CurrentInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
productionPowerIcon.Visible = false;
|
||||||
|
productionPower.Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (productionContainer != null)
|
||||||
|
productionContainer.Visible = false;
|
||||||
|
|
||||||
|
var text = "";
|
||||||
|
if (bi != null)
|
||||||
|
{
|
||||||
|
var prereqs = bi.Prerequisites
|
||||||
.Select(a => ActorName(modData.DefaultRules, a))
|
.Select(a => ActorName(modData.DefaultRules, a))
|
||||||
.Where(s => !s.StartsWith('~') && !s.StartsWith('!'))
|
.Where(s => !s.StartsWith('~') && !s.StartsWith('!'))
|
||||||
.ToList();
|
.ToList();
|
||||||
if (prerequisites.Count != 0)
|
|
||||||
text += $"Requires {prerequisites.JoinWith(", ")}\n\n";
|
if (prereqs.Count != 0)
|
||||||
|
text += FluentProvider.GetMessage(Requires, "prerequisites", prereqs.JoinWith(", ")) + "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedInfo != null && !string.IsNullOrEmpty(selectedInfo.Description))
|
if (selectedInfo != null && !string.IsNullOrEmpty(selectedInfo.Description))
|
||||||
text += WidgetUtils.WrapText(FluentProvider.GetMessage(selectedInfo.Description) + "\n\n", descriptionLabel.Bounds.Width, descriptionFont);
|
text += WidgetUtils.WrapText(FluentProvider.GetMessage(selectedInfo.Description), descriptionLabel.Bounds.Width, descriptionFont);
|
||||||
|
|
||||||
var height = descriptionFont.Measure(text).Y;
|
var height = descriptionFont.Measure(text).Y;
|
||||||
descriptionLabel.GetText = () => text;
|
descriptionLabel.GetText = () => text;
|
||||||
@@ -218,5 +263,42 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BuildTime(ActorInfo info, string queue)
|
||||||
|
{
|
||||||
|
var bi = info.TraitInfoOrDefault<BuildableInfo>();
|
||||||
|
|
||||||
|
if (bi == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var time = bi.BuildDuration;
|
||||||
|
if (time == -1)
|
||||||
|
{
|
||||||
|
var valued = info.TraitInfoOrDefault<ValuedInfo>();
|
||||||
|
if (valued == null)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
time = valued.Cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pbi;
|
||||||
|
if (queue != null)
|
||||||
|
{
|
||||||
|
var pqueue = modData.DefaultRules.Actors.Values.SelectMany(a => a.TraitInfos<ProductionQueueInfo>()
|
||||||
|
.Where(x => x.Type == queue)).FirstOrDefault();
|
||||||
|
|
||||||
|
pbi = pqueue?.BuildDurationModifier ?? 100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var pqueue = modData.DefaultRules.Actors.Values.SelectMany(a => a.TraitInfos<ProductionQueueInfo>()
|
||||||
|
.Where(x => bi.Queue.Contains(x.Type))).FirstOrDefault();
|
||||||
|
|
||||||
|
pbi = pqueue?.BuildDurationModifier ?? 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
time = time * bi.BuildDurationModifier * pbi / 10000;
|
||||||
|
return time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -551,7 +551,7 @@ label-audio-unmuted = Audio unmuted.
|
|||||||
label-loading-player-profile = Loading player profile...
|
label-loading-player-profile = Loading player profile...
|
||||||
label-loading-player-profile-failed = Failed to load player profile.
|
label-loading-player-profile-failed = Failed to load player profile.
|
||||||
|
|
||||||
## ProductionTooltipLogic
|
## ProductionTooltipLogic, EncyclopediaLogic
|
||||||
label-requires = Requires { $prerequisites }.
|
label-requires = Requires { $prerequisites }.
|
||||||
|
|
||||||
## ReplayBrowserLogic
|
## ReplayBrowserLogic
|
||||||
|
|||||||
Reference in New Issue
Block a user