From 74602474e35e23ff3d2af10e521be89a9f6a58d3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 25 Sep 2016 16:43:45 +0100 Subject: [PATCH 1/4] Change shroud tooltip to match the original games. --- OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs index c0c58af94f..3abe8ff6cf 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic switch (viewport.TooltipType) { case WorldTooltipType.Unexplored: - labelText = "Unexplored Terrain"; + labelText = "Unrevealed Terrain"; break; case WorldTooltipType.Actor: { From 404d8235c81b009aab75dcb853cc456fc056e20c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 25 Sep 2016 13:21:22 +0100 Subject: [PATCH 2/4] Show a tooltip over map resources. --- .../Widgets/Logic/Ingame/WorldTooltipLogic.cs | 3 ++ .../Widgets/ViewportControllerWidget.cs | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs index 3abe8ff6cf..ef0b137d9d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs @@ -57,6 +57,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic case WorldTooltipType.Unexplored: labelText = "Unrevealed Terrain"; break; + case WorldTooltipType.Resource: + labelText = viewport.ResourceTooltip.Info.Name; + break; case WorldTooltipType.Actor: { o = viewport.ActorTooltip.Owner; diff --git a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs index bd5e9c0314..afe88e4fa9 100644 --- a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs @@ -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 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(TooltipContainer)); + + resourceLayer = world.WorldActor.TraitOrDefault(); } 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().Any(t => !t.IsVisible(actor, world.RenderPlayer))) + if (actor != null && actor.TraitsImplementing().All(t => t.IsVisible(actor, world.RenderPlayer))) + { + FrozenActorTooltip = frozen; + if (frozen.Actor != null) + ActorTooltipExtra = frozen.Actor.TraitsImplementing().ToArray(); + TooltipType = WorldTooltipType.FrozenActor; return; + } + } - FrozenActorTooltip = frozen; - if (frozen.Actor != null) - ActorTooltipExtra = frozen.Actor.TraitsImplementing().ToArray(); - TooltipType = WorldTooltipType.FrozenActor; + if (resourceLayer != null) + { + var resource = resourceLayer.GetRenderedResource(cell); + if (resource != null) + { + TooltipType = WorldTooltipType.Resource; + ResourceTooltip = resource; + } } } From fdc6ea4564900c2aa41dcb3050af8e6e80756032 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 25 Sep 2016 13:33:01 +0100 Subject: [PATCH 3/4] Add trait descriptions to ResourceType. --- OpenRA.Game/Traits/World/ResourceType.cs | 29 ++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Traits/World/ResourceType.cs b/OpenRA.Game/Traits/World/ResourceType.cs index 2fc3ebd8c2..9618e02e29 100644 --- a/OpenRA.Game/Traits/World/ResourceType.cs +++ b/OpenRA.Game/Traits/World/ResourceType.cs @@ -16,21 +16,46 @@ namespace OpenRA.Traits { public class ResourceTypeInfo : ITraitInfo { + [Desc("Sequence image that holds the different variants.")] public readonly string Sequence = "resources"; - [SequenceReference("Sequence")] public readonly string[] Variants = { }; - [PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName; + + [SequenceReference("Sequence")] + [Desc("Randomly chosen image sequences.")] + public readonly string[] Variants = { }; + + [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; + + [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 Name = null; + + [Desc("Terrain type used to determine unit movement and minimap colors.")] public readonly string TerrainType = "Ore"; + [Desc("Terrain types that this resource can spawn on.")] public readonly HashSet AllowedTerrainTypes = new HashSet(); + + [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); } From 365bd5b9bdf912075fe6eac387e1419e6a2da095 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 25 Sep 2016 13:36:06 +0100 Subject: [PATCH 4/4] Rename ResourceType trait fields for consistency. --- OpenRA.Game/Traits/World/ResourceType.cs | 18 ++++++++---- OpenRA.Mods.Common/ActorExts.cs | 2 +- .../EditorBrushes/EditorDefaultBrush.cs | 2 +- .../EditorBrushes/EditorResourceBrush.cs | 2 +- OpenRA.Mods.Common/Traits/Harvester.cs | 2 +- OpenRA.Mods.Common/Traits/SeedsResource.cs | 2 +- .../UtilityCommands/UpgradeRules.cs | 19 ++++++++++++ .../Warheads/CreateResourceWarhead.cs | 2 +- .../Logic/Editor/LayerSelectorLogic.cs | 4 +-- OpenRA.Mods.D2k/Traits/SpiceBloom.cs | 2 +- mods/cnc/rules/world.yaml | 14 +++++---- mods/d2k/rules/world.yaml | 7 +++-- mods/ra/rules/world.yaml | 18 +++++++----- mods/ts/rules/world.yaml | 29 ++++++++++--------- 14 files changed, 78 insertions(+), 45 deletions(-) diff --git a/OpenRA.Game/Traits/World/ResourceType.cs b/OpenRA.Game/Traits/World/ResourceType.cs index 9618e02e29..9099ca031e 100644 --- a/OpenRA.Game/Traits/World/ResourceType.cs +++ b/OpenRA.Game/Traits/World/ResourceType.cs @@ -17,11 +17,12 @@ namespace OpenRA.Traits public class ResourceTypeInfo : ITraitInfo { [Desc("Sequence image that holds the different variants.")] - public readonly string Sequence = "resources"; + public readonly string Image = "resources"; - [SequenceReference("Sequence")] + [FieldLoader.Require] + [SequenceReference("Image")] [Desc("Randomly chosen image sequences.")] - public readonly string[] Variants = { }; + public readonly string[] Sequences = { }; [PaletteReference] [Desc("Palette used for rendering the resource sprites.")] @@ -38,10 +39,15 @@ namespace OpenRA.Traits [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 = "Ore"; + public readonly string TerrainType = null; [Desc("Terrain types that this resource can spawn on.")] public readonly HashSet AllowedTerrainTypes = new HashSet(); @@ -71,9 +77,9 @@ namespace OpenRA.Traits { Info = info; Variants = new Dictionary(); - 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); } diff --git a/OpenRA.Mods.Common/ActorExts.cs b/OpenRA.Mods.Common/ActorExts.cs index 4142576230..a687cee394 100644 --- a/OpenRA.Mods.Common/ActorExts.cs +++ b/OpenRA.Mods.Common/ActorExts.cs @@ -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) diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs index 017bf9fa90..8b04bfb1b3 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs @@ -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); diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs index ab47677569..e537227ae8 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs @@ -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; diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 23c2050351..1cb9c859e8 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -478,7 +478,7 @@ namespace OpenRA.Mods.Common.Traits var res = self.World.WorldActor.Trait().GetRenderedResource(location); var info = self.Info.TraitInfo(); - if (res == null || !info.Resources.Contains(res.Info.Name)) + if (res == null || !info.Resources.Contains(res.Info.Type)) return false; cursor = "harvest"; diff --git a/OpenRA.Mods.Common/Traits/SeedsResource.cs b/OpenRA.Mods.Common/Traits/SeedsResource.cs index 695b43d359..33242b12dd 100644 --- a/OpenRA.Mods.Common/Traits/SeedsResource.cs +++ b/OpenRA.Mods.Common/Traits/SeedsResource.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits this.info = info; resourceType = self.World.WorldActor.TraitsImplementing() - .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)); diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 486228374a..254c0a6c45 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -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); } diff --git a/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs b/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs index 8caaa40b52..0c985a8a05 100644 --- a/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Warheads var allCells = world.Map.FindTilesInAnnulus(targetTile, minRange, Size[0]); var resourceType = world.WorldActor.TraitsImplementing() - .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)); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/LayerSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/LayerSelectorLogic.cs index c007e87519..87502e8583 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/LayerSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/LayerSelectorLogic.cs @@ -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); } diff --git a/OpenRA.Mods.D2k/Traits/SpiceBloom.cs b/OpenRA.Mods.D2k/Traits/SpiceBloom.cs index f6ab56f095..e14f46ac9f 100644 --- a/OpenRA.Mods.D2k/Traits/SpiceBloom.cs +++ b/OpenRA.Mods.D2k/Traits/SpiceBloom.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.D2k.Traits self = init.Self; resLayer = self.World.WorldActor.Trait(); - resType = self.World.WorldActor.TraitsImplementing().First(t => t.Info.Name == info.ResourceType); + resType = self.World.WorldActor.TraitsImplementing().First(t => t.Info.Type == info.ResourceType); var render = self.Trait(); anim = new AnimationWithOffset(new Animation(init.Self.World, render.GetImage(self)), null, () => self.IsDead); diff --git a/mods/cnc/rules/world.yaml b/mods/cnc/rules/world.yaml index 34a52e37ee..85a0516be6 100644 --- a/mods/cnc/rules/world.yaml +++ b/mods/cnc/rules/world.yaml @@ -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 diff --git a/mods/d2k/rules/world.yaml b/mods/d2k/rules/world.yaml index 779f0cfdf4..75365d7018 100644 --- a/mods/d2k/rules/world.yaml +++ b/mods/d2k/rules/world.yaml @@ -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 diff --git a/mods/ra/rules/world.yaml b/mods/ra/rules/world.yaml index bb58bbf0ad..b8b4f374eb 100644 --- a/mods/ra/rules/world.yaml +++ b/mods/ra/rules/world.yaml @@ -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 diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index 97013fd14c..f466036d5d 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -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