Add ActorInfo.TraitInfo[OrDefault]<T>() requiring ITraitIfo types
This commit is contained in:
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (!actor.HasTraitInfo<IRenderActorPreviewInfo>())
|
||||
continue;
|
||||
|
||||
var filter = actor.Traits.GetOrDefault<EditorTilesetFilterInfo>();
|
||||
var filter = actor.TraitInfoOrDefault<EditorTilesetFilterInfo>();
|
||||
if (filter != null)
|
||||
{
|
||||
if (filter.ExcludeTilesets != null && filter.ExcludeTilesets.Contains(world.TileSet.Id))
|
||||
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
item.Bounds.Height = preview.Bounds.Height + 2 * preview.Bounds.Y;
|
||||
item.IsVisible = () => true;
|
||||
|
||||
var tooltip = actor.Traits.GetOrDefault<TooltipInfo>();
|
||||
var tooltip = actor.TraitInfoOrDefault<TooltipInfo>();
|
||||
item.GetTooltipText = () => tooltip == null ? actor.Name : tooltip.Name + " (" + actor.Name + ")";
|
||||
|
||||
panel.AddChild(item);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs());
|
||||
var sidebarTicker = playerWidgets.Get<LogicTickerWidget>("SIDEBAR_TICKER");
|
||||
var objectives = world.LocalPlayer.PlayerActor.Info.Traits.GetOrDefault<MissionObjectivesInfo>();
|
||||
var objectives = world.LocalPlayer.PlayerActor.Info.TraitInfoOrDefault<MissionObjectivesInfo>();
|
||||
|
||||
sidebarTicker.OnTick = () =>
|
||||
{
|
||||
|
||||
@@ -54,9 +54,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (actor == null || actor == lastActor)
|
||||
return;
|
||||
|
||||
var tooltip = actor.Traits.Get<TooltipInfo>();
|
||||
var buildable = actor.Traits.Get<BuildableInfo>();
|
||||
var cost = actor.Traits.Get<ValuedInfo>().Cost;
|
||||
var tooltip = actor.TraitInfo<TooltipInfo>();
|
||||
var buildable = actor.TraitInfo<BuildableInfo>();
|
||||
var cost = actor.TraitInfo<ValuedInfo>().Cost;
|
||||
|
||||
nameLabel.GetText = () => tooltip.Name;
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai) && ai.HasTraitInfo<TooltipInfo>())
|
||||
return ai.Traits.Get<TooltipInfo>().Name;
|
||||
return ai.TraitInfo<TooltipInfo>().Name;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -438,7 +438,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Map.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash);
|
||||
startingCash.OnMouseDown = _ =>
|
||||
{
|
||||
var options = modRules.Actors["player"].Traits.Get<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
|
||||
var options = modRules.Actors["player"].TraitInfo<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
|
||||
{
|
||||
Title = "${0}".F(c),
|
||||
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c,
|
||||
@@ -689,7 +689,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)));
|
||||
|
||||
// Restore default starting cash if the last map set it to something invalid
|
||||
var pri = modRules.Actors["player"].Traits.Get<PlayerResourcesInfo>();
|
||||
var pri = modRules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
|
||||
if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash))
|
||||
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (actor == null)
|
||||
continue;
|
||||
|
||||
var rsi = actor.Traits.Get<RenderSpritesInfo>();
|
||||
var rsi = actor.TraitInfo<RenderSpritesInfo>();
|
||||
var icon = new Animation(world, rsi.GetImage(actor, world.Map.SequenceProvider, faction));
|
||||
icon.Play(actor.Traits.Get<TooltipInfo>().Icon);
|
||||
var bi = actor.Traits.Get<BuildableInfo>();
|
||||
icon.Play(actor.TraitInfo<TooltipInfo>().Icon);
|
||||
var bi = actor.TraitInfo<BuildableInfo>();
|
||||
var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
|
||||
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(bi.IconPalette), 0.5f);
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (CurrentQueue == null)
|
||||
return Enumerable.Empty<ActorInfo>();
|
||||
|
||||
return CurrentQueue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
|
||||
return CurrentQueue.AllItems().OrderBy(a => a.TraitInfo<BuildableInfo>().BuildPaletteOrder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,11 +319,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var y = DisplayedIconCount / Columns;
|
||||
var rect = new Rectangle(rb.X + x * (IconSize.X + IconMargin.X), rb.Y + y * (IconSize.Y + IconMargin.Y), IconSize.X, IconSize.Y);
|
||||
|
||||
var rsi = item.Traits.Get<RenderSpritesInfo>();
|
||||
var rsi = item.TraitInfo<RenderSpritesInfo>();
|
||||
var icon = new Animation(World, rsi.GetImage(item, World.Map.SequenceProvider, faction));
|
||||
icon.Play(item.Traits.Get<TooltipInfo>().Icon);
|
||||
icon.Play(item.TraitInfo<TooltipInfo>().Icon);
|
||||
|
||||
var bi = item.Traits.Get<BuildableInfo>();
|
||||
var bi = item.TraitInfo<BuildableInfo>();
|
||||
|
||||
var pi = new ProductionIcon()
|
||||
{
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (actor.First == null)
|
||||
return true;
|
||||
|
||||
var ati = actor.First.Info.Traits.GetOrDefault<AutoTargetInfo>();
|
||||
var ati = actor.First.Info.TraitInfoOrDefault<AutoTargetInfo>();
|
||||
if (ati == null || !ati.EnableStances)
|
||||
return false;
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var facilities = world.ActorsWithTrait<Production>()
|
||||
.Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.Info.HasTraitInfo<BaseBuildingInfo>())
|
||||
.OrderBy(f => f.Actor.Info.Traits.Get<ProductionInfo>().Produces.First())
|
||||
.OrderBy(f => f.Actor.Info.TraitInfo<ProductionInfo>().Produces.First())
|
||||
.Select(b => b.Actor)
|
||||
.ToList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user