Merge pull request #12103 from pchote/resource-tooltip
Add tooltips to map resources.
This commit is contained in:
@@ -16,21 +16,52 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public class ResourceTypeInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Sequence = "resources";
|
||||
[SequenceReference("Sequence")] public readonly string[] Variants = { };
|
||||
[PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName;
|
||||
[Desc("Sequence image that holds the different variants.")]
|
||||
public readonly string Image = "resources";
|
||||
|
||||
[FieldLoader.Require]
|
||||
[SequenceReference("Image")]
|
||||
[Desc("Randomly chosen image sequences.")]
|
||||
public readonly string[] Sequences = { };
|
||||
|
||||
[PaletteReference]
|
||||
[Desc("Palette used for rendering the resource sprites.")]
|
||||
public readonly string Palette = TileSet.TerrainPaletteInternalName;
|
||||
|
||||
[Desc("Resource index used in the binary map data.")]
|
||||
public readonly int ResourceType = 1;
|
||||
|
||||
[Desc("Credit value of a single resource unit.")]
|
||||
public readonly int ValuePerUnit = 0;
|
||||
public readonly int MaxDensity = 10;
|
||||
public readonly string Name = null;
|
||||
public readonly string TerrainType = "Ore";
|
||||
|
||||
[Desc("Maximum number of resource units allowed in a single cell.")]
|
||||
public readonly int MaxDensity = 10;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Resource identifier used by other traits.")]
|
||||
public readonly string Type = null;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Resource name used by tooltips.")]
|
||||
public readonly string Name = null;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Terrain type used to determine unit movement and minimap colors.")]
|
||||
public readonly string TerrainType = null;
|
||||
|
||||
[Desc("Terrain types that this resource can spawn on.")]
|
||||
public readonly HashSet<string> AllowedTerrainTypes = new HashSet<string>();
|
||||
|
||||
[Desc("Allow resource to spawn under Mobile actors.")]
|
||||
public readonly bool AllowUnderActors = false;
|
||||
|
||||
[Desc("Allow resource to spawn under Buildings.")]
|
||||
public readonly bool AllowUnderBuildings = false;
|
||||
|
||||
[Desc("Allow resource to spawn on ramp tiles.")]
|
||||
public readonly bool AllowOnRamps = false;
|
||||
|
||||
[Desc("Harvester content pip color.")]
|
||||
public PipType PipColor = PipType.Yellow;
|
||||
|
||||
public object Create(ActorInitializer init) { return new ResourceType(this, init.World); }
|
||||
@@ -46,9 +77,9 @@ namespace OpenRA.Traits
|
||||
{
|
||||
Info = info;
|
||||
Variants = new Dictionary<string, Sprite[]>();
|
||||
foreach (var v in info.Variants)
|
||||
foreach (var v in info.Sequences)
|
||||
{
|
||||
var seq = world.Map.Rules.Sequences.GetSequence(Info.Sequence, v);
|
||||
var seq = world.Map.Rules.Sequences.GetSequence(Info.Image, v);
|
||||
var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
|
||||
Variants.Add(v, sprites);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common
|
||||
return false;
|
||||
|
||||
// Can the harvester collect this kind of resource?
|
||||
if (!harvInfo.Resources.Contains(resType.Info.Name))
|
||||
if (!harvInfo.Resources.Contains(resType.Info.Type))
|
||||
return false;
|
||||
|
||||
if (territory != null)
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (underCursor != null)
|
||||
editorWidget.SetTooltip(underCursor.Tooltip);
|
||||
else if (mapResources.Contains(cell) && resources.TryGetValue(mapResources[cell].Type, out type))
|
||||
editorWidget.SetTooltip(type.Info.Name);
|
||||
editorWidget.SetTooltip(type.Info.Type);
|
||||
else
|
||||
editorWidget.SetTooltip(null);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
preview.GetScale = () => worldRenderer.Viewport.Zoom;
|
||||
preview.IsVisible = () => editorWidget.CurrentBrush == this;
|
||||
|
||||
var variant = resource.Variants.FirstOrDefault();
|
||||
var variant = resource.Sequences.FirstOrDefault();
|
||||
var sequence = wr.World.Map.Rules.Sequences.GetSequence("resources", variant);
|
||||
var sprite = sequence.GetSprite(resource.MaxDensity - 1);
|
||||
preview.GetSprite = () => sprite;
|
||||
|
||||
@@ -478,7 +478,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var res = self.World.WorldActor.Trait<ResourceLayer>().GetRenderedResource(location);
|
||||
var info = self.Info.TraitInfo<HarvesterInfo>();
|
||||
|
||||
if (res == null || !info.Resources.Contains(res.Info.Name))
|
||||
if (res == null || !info.Resources.Contains(res.Info.Type))
|
||||
return false;
|
||||
|
||||
cursor = "harvest";
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.info = info;
|
||||
|
||||
resourceType = self.World.WorldActor.TraitsImplementing<ResourceType>()
|
||||
.FirstOrDefault(t => t.Info.Name == info.ResourceType);
|
||||
.FirstOrDefault(t => t.Info.Type == info.ResourceType);
|
||||
|
||||
if (resourceType == null)
|
||||
throw new InvalidOperationException("No such resource type `{0}`".F(info.ResourceType));
|
||||
|
||||
@@ -367,6 +367,25 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Console.WriteLine("Actor type `{0}` is denoted as a RearmBuilding. Consider adding the `WithRearmAnimation` trait to it.".F(host));
|
||||
}
|
||||
|
||||
// Resource type properties were renamed, and support for tooltips added
|
||||
if (engineVersion < 20160925)
|
||||
{
|
||||
if (node.Key.StartsWith("ResourceType"))
|
||||
{
|
||||
var image = node.Value.Nodes.FirstOrDefault(n => n.Key == "Sequence");
|
||||
if (image != null)
|
||||
image.Key = "Image";
|
||||
|
||||
var sequences = node.Value.Nodes.FirstOrDefault(n => n.Key == "Variants");
|
||||
if (sequences != null)
|
||||
sequences.Key = "Sequences";
|
||||
|
||||
var name = node.Value.Nodes.FirstOrDefault(n => n.Key == "Name");
|
||||
if (name != null)
|
||||
node.Value.Nodes.Add(new MiniYamlNode("Type", name.Value.Value));
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
var allCells = world.Map.FindTilesInAnnulus(targetTile, minRange, Size[0]);
|
||||
|
||||
var resourceType = world.WorldActor.TraitsImplementing<ResourceType>()
|
||||
.FirstOrDefault(t => t.Info.Name == AddsResourceType);
|
||||
.FirstOrDefault(t => t.Info.Type == AddsResourceType);
|
||||
|
||||
if (resourceType == null)
|
||||
Log.Write("debug", "Warhead defines an invalid resource type '{0}'".F(AddsResourceType));
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
layerPreview.IsVisible = () => true;
|
||||
layerPreview.GetPalette = () => resource.Palette;
|
||||
|
||||
var variant = resource.Variants.FirstOrDefault();
|
||||
var variant = resource.Sequences.FirstOrDefault();
|
||||
var sequence = rules.Sequences.GetSequence("resources", variant);
|
||||
var frame = sequence.Frames != null ? sequence.Frames.Last() : resource.MaxDensity - 1;
|
||||
layerPreview.GetSprite = () => sequence.GetSprite(frame);
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
newResourcePreviewTemplate.Bounds.Height = tileSize.Height + (layerPreview.Bounds.Y * 2);
|
||||
|
||||
newResourcePreviewTemplate.IsVisible = () => true;
|
||||
newResourcePreviewTemplate.GetTooltipText = () => resource.Name;
|
||||
newResourcePreviewTemplate.GetTooltipText = () => resource.Type;
|
||||
|
||||
layerTemplateList.AddChild(newResourcePreviewTemplate);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
switch (viewport.TooltipType)
|
||||
{
|
||||
case WorldTooltipType.Unexplored:
|
||||
labelText = "Unexplored Terrain";
|
||||
labelText = "Unrevealed Terrain";
|
||||
break;
|
||||
case WorldTooltipType.Resource:
|
||||
labelText = viewport.ResourceTooltip.Info.Name;
|
||||
break;
|
||||
case WorldTooltipType.Actor:
|
||||
{
|
||||
|
||||
@@ -13,15 +13,18 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public enum WorldTooltipType { None, Unexplored, Actor, FrozenActor }
|
||||
public enum WorldTooltipType { None, Unexplored, Actor, FrozenActor, Resource }
|
||||
|
||||
public class ViewportControllerWidget : Widget
|
||||
{
|
||||
readonly ResourceLayer resourceLayer;
|
||||
|
||||
public readonly string TooltipTemplate = "WORLD_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
@@ -30,6 +33,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public ITooltip ActorTooltip { get; private set; }
|
||||
public IProvideTooltipInfo[] ActorTooltipExtra { get; private set; }
|
||||
public FrozenActor FrozenActorTooltip { get; private set; }
|
||||
public ResourceType ResourceTooltip { get; private set; }
|
||||
|
||||
public int EdgeScrollThreshold = 15;
|
||||
public int EdgeCornerScrollThreshold = 35;
|
||||
@@ -105,6 +109,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
this.worldRenderer = worldRenderer;
|
||||
tooltipContainer = Exts.Lazy(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
|
||||
resourceLayer = world.WorldActor.TraitOrDefault<ResourceLayer>();
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
@@ -198,13 +204,24 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (frozen != null)
|
||||
{
|
||||
var actor = frozen.Actor;
|
||||
if (actor != null && actor.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(actor, world.RenderPlayer)))
|
||||
if (actor != null && actor.TraitsImplementing<IVisibilityModifier>().All(t => t.IsVisible(actor, world.RenderPlayer)))
|
||||
{
|
||||
FrozenActorTooltip = frozen;
|
||||
if (frozen.Actor != null)
|
||||
ActorTooltipExtra = frozen.Actor.TraitsImplementing<IProvideTooltipInfo>().ToArray();
|
||||
TooltipType = WorldTooltipType.FrozenActor;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FrozenActorTooltip = frozen;
|
||||
if (frozen.Actor != null)
|
||||
ActorTooltipExtra = frozen.Actor.TraitsImplementing<IProvideTooltipInfo>().ToArray();
|
||||
TooltipType = WorldTooltipType.FrozenActor;
|
||||
if (resourceLayer != null)
|
||||
{
|
||||
var resource = resourceLayer.GetRenderedResource(cell);
|
||||
if (resource != null)
|
||||
{
|
||||
TooltipType = WorldTooltipType.Resource;
|
||||
ResourceTooltip = resource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
self = init.Self;
|
||||
|
||||
resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
resType = self.World.WorldActor.TraitsImplementing<ResourceType>().First(t => t.Info.Name == info.ResourceType);
|
||||
resType = self.World.WorldActor.TraitsImplementing<ResourceType>().First(t => t.Info.Type == info.ResourceType);
|
||||
|
||||
var render = self.Trait<RenderSprites>();
|
||||
anim = new AnimationWithOffset(new Animation(init.Self.World, render.GetImage(self)), null, () => self.IsDead);
|
||||
|
||||
@@ -26,25 +26,27 @@
|
||||
InternalName: nod
|
||||
Description: Brotherhood of Nod\nThe Brotherhood is a religious cult centered around their leader Kane\nand the alien substance Tiberium. They utilize stealth technology\nand guerilla tactics to defeat those who oppose them.
|
||||
ResourceType@green-tib:
|
||||
Type: Tiberium
|
||||
Name: Tiberium
|
||||
PipColor: Green
|
||||
ResourceType: 1
|
||||
Palette: staticterrain
|
||||
TerrainType: Tiberium
|
||||
Variants: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12
|
||||
Sequences: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12
|
||||
MaxDensity: 12
|
||||
ValuePerUnit: 35
|
||||
Name: Tiberium
|
||||
PipColor: Green
|
||||
AllowedTerrainTypes: Clear,Road
|
||||
AllowUnderActors: true
|
||||
ResourceType@blue-tib:
|
||||
Type: BlueTiberium
|
||||
Name: Tiberium
|
||||
PipColor: Blue
|
||||
ResourceType: 2
|
||||
Palette: bluetiberium
|
||||
TerrainType: BlueTiberium
|
||||
Variants: bti1,bti2,bti3,bti4,bti5,bti6,bti7,bti8,bti9,bti10,bti11,bti12
|
||||
Sequences: bti1,bti2,bti3,bti4,bti5,bti6,bti7,bti8,bti9,bti10,bti11,bti12
|
||||
MaxDensity: 12
|
||||
ValuePerUnit: 60
|
||||
Name: BlueTiberium
|
||||
PipColor: Blue
|
||||
AllowedTerrainTypes: Clear,Road
|
||||
AllowUnderActors: true
|
||||
|
||||
|
||||
@@ -44,14 +44,15 @@
|
||||
InternalName: smuggler
|
||||
Selectable: false
|
||||
ResourceType@Spice:
|
||||
Type: Spice
|
||||
Name: Spice
|
||||
PipColor: green
|
||||
ResourceType: 1
|
||||
Palette: d2k
|
||||
TerrainType: Spice
|
||||
Variants: spice
|
||||
Sequences: spice
|
||||
MaxDensity: 20
|
||||
ValuePerUnit: 25
|
||||
Name: Spice
|
||||
PipColor: green
|
||||
AllowedTerrainTypes: SpiceSand
|
||||
AllowUnderActors: true
|
||||
|
||||
|
||||
@@ -65,27 +65,29 @@
|
||||
Side: Random
|
||||
Description: A random Soviet country.
|
||||
ResourceType@ore:
|
||||
Type: Ore
|
||||
Name: Valuable Minerals
|
||||
PipColor: Yellow
|
||||
ResourceType: 1
|
||||
TerrainType: Ore
|
||||
Palette: player
|
||||
Variants: gold01,gold02,gold03,gold04
|
||||
Sequences: gold01,gold02,gold03,gold04
|
||||
MaxDensity: 12
|
||||
ValuePerUnit: 25
|
||||
Name: Ore
|
||||
PipColor: Yellow
|
||||
AllowedTerrainTypes: Clear,Road
|
||||
AllowUnderActors: true
|
||||
TerrainType: Ore
|
||||
ResourceType@gem:
|
||||
Type: Gems
|
||||
Name: Valuable Minerals
|
||||
PipColor: Red
|
||||
ResourceType: 2
|
||||
TerrainType: Gems
|
||||
Palette: player
|
||||
Variants: gem01,gem02,gem03,gem04
|
||||
Sequences: gem01,gem02,gem03,gem04
|
||||
MaxDensity: 3
|
||||
ValuePerUnit: 50
|
||||
Name: Gems
|
||||
PipColor: Red
|
||||
AllowedTerrainTypes: Clear,Road
|
||||
AllowUnderActors: true
|
||||
TerrainType: Gems
|
||||
|
||||
World:
|
||||
Inherits: ^BaseWorld
|
||||
|
||||
@@ -22,35 +22,38 @@
|
||||
Name: Nod
|
||||
InternalName: nod
|
||||
ResourceType@Tiberium:
|
||||
ResourceType: 1
|
||||
Palette: greentiberium
|
||||
Variants: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
|
||||
MaxDensity: 12
|
||||
ValuePerUnit: 50
|
||||
Type: Tiberium
|
||||
Name: Tiberium
|
||||
PipColor: Green
|
||||
ResourceType: 1
|
||||
Palette: greentiberium
|
||||
Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
|
||||
MaxDensity: 12
|
||||
ValuePerUnit: 50
|
||||
AllowedTerrainTypes: Clear, Rough, DirtRoad
|
||||
AllowUnderActors: true
|
||||
TerrainType: Tiberium
|
||||
ResourceType@BlueTiberium:
|
||||
Type: BlueTiberium
|
||||
Name: Tiberium
|
||||
PipColor: Blue
|
||||
ResourceType: 2
|
||||
Palette: bluetiberium
|
||||
Variants: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
|
||||
Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
|
||||
MaxDensity: 12
|
||||
ValuePerUnit: 100
|
||||
Name: BlueTiberium
|
||||
PipColor: Blue
|
||||
AllowedTerrainTypes: Clear, Rough, DirtRoad
|
||||
AllowUnderActors: true
|
||||
TerrainType: BlueTiberium
|
||||
ResourceType@Veins:
|
||||
ResourceType: 3
|
||||
Palette: player
|
||||
Variants: veins
|
||||
MaxDensity: 1
|
||||
ValuePerUnit: 0
|
||||
Type: Veins
|
||||
Name: Veins
|
||||
PipColor: Red
|
||||
ResourceType: 3
|
||||
Palette: player
|
||||
Sequences: veins
|
||||
MaxDensity: 1
|
||||
ValuePerUnit: 0
|
||||
AllowedTerrainTypes: Clear
|
||||
AllowUnderActors: true
|
||||
TerrainType: Veins
|
||||
|
||||
Reference in New Issue
Block a user