From a8bb03aa3431bfbf84b46b85a3396d5146d21095 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 26 Mar 2017 21:15:29 +0000 Subject: [PATCH] Draw TS line-build cell previews with increased translucency. --- .../Orders/PlaceBuildingOrderGenerator.cs | 30 ++++++++++++++----- .../Traits/Player/PlaceBuilding.cs | 3 ++ mods/ts/rules/palettes.yaml | 4 +++ mods/ts/rules/player.yaml | 1 + mods/ts/rules/world.yaml | 1 + 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index 41661f75c3..a25706fd36 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -22,6 +22,9 @@ namespace OpenRA.Mods.Common.Orders { public class PlaceBuildingOrderGenerator : IOrderGenerator { + [Flags] + enum CellType { Valid = 0, Invalid = 1, LineBuild = 2 } + readonly ProductionQueue queue; readonly string building; readonly BuildingInfo buildingInfo; @@ -62,6 +65,15 @@ namespace OpenRA.Mods.Common.Orders buildingInfluence = world.WorldActor.Trait(); } + CellType MakeCellType(bool valid, bool lineBuild = false) + { + var cell = valid ? CellType.Valid : CellType.Invalid; + if (lineBuild) + cell |= CellType.LineBuild; + + return cell; + } + public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button == MouseButton.Right) @@ -160,7 +172,7 @@ namespace OpenRA.Mods.Common.Orders foreach (var r in dec.Render(wr, world, actorInfo, offset)) yield return r; - var cells = new Dictionary(); + var cells = new Dictionary(); var plugInfo = rules.Actors[building].TraitInfoOrDefault(); if (plugInfo != null) @@ -168,7 +180,7 @@ namespace OpenRA.Mods.Common.Orders if (buildingInfo.Dimensions.X != 1 || buildingInfo.Dimensions.Y != 1) throw new InvalidOperationException("Plug requires a 1x1 sized Building"); - cells.Add(topLeft, AcceptsPlug(topLeft, plugInfo)); + cells.Add(topLeft, MakeCellType(AcceptsPlug(topLeft, plugInfo))); } else if (rules.Actors[building].HasTraitInfo()) { @@ -178,9 +190,9 @@ namespace OpenRA.Mods.Common.Orders if (!Game.GetModifierKeys().HasModifier(Modifiers.Shift)) foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, building, buildingInfo)) - cells.Add(t.First, buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, t.First)); - else - cells.Add(topLeft, buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, topLeft)); + cells.Add(t.First, MakeCellType(buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, t.First), true)); + + cells[topLeft] = MakeCellType(buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, topLeft)); } else { @@ -211,14 +223,16 @@ namespace OpenRA.Mods.Common.Orders var res = world.WorldActor.Trait(); var isCloseEnough = buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, topLeft); foreach (var t in FootprintUtils.Tiles(rules, building, buildingInfo, topLeft)) - cells.Add(t, isCloseEnough && world.IsCellBuildable(t, buildingInfo) && res.GetResource(t) == null); + cells.Add(t, MakeCellType(isCloseEnough && world.IsCellBuildable(t, buildingInfo) && res.GetResource(t) == null)); } - var pal = wr.Palette(placeBuildingInfo.Palette); + var cellPalette = wr.Palette(placeBuildingInfo.Palette); + var linePalette = wr.Palette(placeBuildingInfo.LineBuildSegmentPalette); var topLeftPos = world.Map.CenterOfCell(topLeft); foreach (var c in cells) { - var tile = c.Value ? buildOk : buildBlocked; + var tile = !c.Value.HasFlag(CellType.Invalid) ? buildOk : buildBlocked; + var pal = c.Value.HasFlag(CellType.LineBuild) ? linePalette : cellPalette; var pos = world.Map.CenterOfCell(c.Key); yield return new SpriteRenderable(tile, pos, new WVec(0, 0, topLeftPos.Z - pos.Z), -511, pal, 1f, true); diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index 57d36c582b..2fe669ee23 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -22,6 +22,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Palette to use for rendering the placement sprite.")] [PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName; + [Desc("Palette to use for rendering the placement sprite for line build segments.")] + [PaletteReference] public readonly string LineBuildSegmentPalette = TileSet.TerrainPaletteInternalName; + [Desc("Play NewOptionsNotification this many ticks after building placement.")] public readonly int NewOptionsNotificationDelay = 10; diff --git a/mods/ts/rules/palettes.yaml b/mods/ts/rules/palettes.yaml index 555467c58f..5c96fd2e1f 100644 --- a/mods/ts/rules/palettes.yaml +++ b/mods/ts/rules/palettes.yaml @@ -113,6 +113,10 @@ Name: placebuilding BasePalette: ra Alpha: 0.75 + PaletteFromPaletteWithAlpha@placelinesegment: + Name: placelinesegment + BasePalette: ra + Alpha: 0.4 TSShroudPalette@shroud: Name: shroud Type: Shroud diff --git a/mods/ts/rules/player.yaml b/mods/ts/rules/player.yaml index e226adf553..75d30071d9 100644 --- a/mods/ts/rules/player.yaml +++ b/mods/ts/rules/player.yaml @@ -33,6 +33,7 @@ Player: SpeedUp: True PlaceBuilding: Palette: placebuilding + LineBuildSegmentPalette: placelinesegment SupportPowerManager: ScriptTriggers: MissionObjectives: diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index e1bc34cc61..131bcac616 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -189,4 +189,5 @@ EditorWorld: EditorResourceLayer: EditorSelectionLayer: Palette: placebuilding + LineBuildSegmentPalette: placelinesegment LoadWidgetAtGameStart: