Extract tile overlays into a shp instead of rolling our own in code; Remove UIOverlay. Fixes #1061.

This commit is contained in:
Paul Chote
2011-07-27 21:17:24 +12:00
parent 08ed7f0316
commit c84f53c10d
10 changed files with 35 additions and 56 deletions

View File

@@ -22,8 +22,6 @@ namespace OpenRA.Graphics
public readonly World world;
internal readonly TerrainRenderer terrainRenderer;
internal readonly ShroudRenderer shroudRenderer;
public readonly UiOverlay uiOverlay;
internal readonly HardwarePalette palette;
internal WorldRenderer(World world)
@@ -35,7 +33,6 @@ namespace OpenRA.Graphics
terrainRenderer = new TerrainRenderer(world, this);
shroudRenderer = new ShroudRenderer(world);
uiOverlay = new UiOverlay();
}
public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); }

View File

@@ -137,7 +137,6 @@
<Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Network\UnitOrders.cs" />
<Compile Include="Traits\Util.cs" />
<Compile Include="UiOverlay.cs" />
<Compile Include="Graphics\Util.cs" />
<Compile Include="Graphics\Viewport.cs" />
<Compile Include="Orders\UnitOrderGenerator.cs" />

View File

@@ -1,44 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
namespace OpenRA
{
public class UiOverlay
{
Sprite buildOk, buildBlocked;
public UiOverlay()
{
buildOk = SynthesizeTile(0x0f);
buildBlocked = SynthesizeTile(0x08);
}
public static Sprite SynthesizeTile(byte paletteIndex)
{
byte[] data = new byte[Game.CellSize * Game.CellSize];
for (int i = 0; i < Game.CellSize; i++)
for (int j = 0; j < Game.CellSize; j++)
data[i * Game.CellSize + j] = ((i+j) % 4 != 0) ? (byte)0 : paletteIndex;
return Game.modData.SheetBuilder.Add(data, new Size(Game.CellSize, Game.CellSize));
}
public void DrawGrid( WorldRenderer wr, Dictionary<int2, bool> cells )
{
foreach( var c in cells )
( c.Value ? buildOk : buildBlocked ).DrawAt( wr, Game.CellSize * c.Key, "terrain" );
}
}
}

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.RA.Orders
readonly string Building;
readonly IEnumerable<Renderable> Preview;
BuildingInfo BuildingInfo { get { return Rules.Info[ Building ].Traits.Get<BuildingInfo>(); } }
Sprite buildOk, buildBlocked;
public PlaceBuildingOrderGenerator(Actor producer, string name)
{
@@ -31,6 +32,9 @@ namespace OpenRA.Mods.RA.Orders
Preview = Rules.Info[Building].Traits.Get<RenderBuildingInfo>()
.RenderPreview(Rules.Info[Building], producer.Owner);
buildOk = SequenceProvider.GetSequence("overlay", "build-valid").GetSprite(0);
buildBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
}
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
@@ -95,8 +99,9 @@ namespace OpenRA.Mods.RA.Orders
foreach (var t in FootprintUtils.Tiles(Building, BuildingInfo, topLeft))
cells.Add( t, isCloseEnough && world.IsCellBuildable(t, BuildingInfo.WaterBound) && res.GetResource(t) == null );
}
wr.uiOverlay.DrawGrid( wr, cells );
foreach( var c in cells )
( c.Value ? buildOk : buildBlocked ).DrawAt( wr, Game.CellSize * c.Key, "terrain" );
}
public string GetCursor(World world, int2 xy, MouseInput mi) { return "default"; }

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.RA
this.order = order;
this.power = power;
this.range = (power.Info as ChronoshiftPowerInfo).Range;
tile = UiOverlay.SynthesizeTile(0x04);
tile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
}
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
@@ -142,10 +142,9 @@ namespace OpenRA.Mods.RA
this.sourceLocation = sourceLocation;
this.range = (power.Info as ChronoshiftPowerInfo).Range;
// todo: this burns up more texture space every time someone uses chronoshift.
validTile = UiOverlay.SynthesizeTile(0x0f);
invalidTile = UiOverlay.SynthesizeTile(0x08);
sourceTile = UiOverlay.SynthesizeTile(0x04);
validTile = SequenceProvider.GetSequence("overlay", "target-valid").GetSprite(0);
invalidTile = SequenceProvider.GetSequence("overlay", "target-invalid").GetSprite(0);
sourceTile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
}
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA
this.order = order;
this.power = power;
this.range = (power.Info as IronCurtainPowerInfo).Range;
tile = UiOverlay.SynthesizeTile(0x04);
tile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
}
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)

BIN
mods/cnc/bits/overlay.shp Normal file

Binary file not shown.

View File

@@ -212,3 +212,15 @@ pips:
groups: pdigits
Start: 0
Length: *
overlay:
build-valid:
Start: 0
build-invalid:
Start: 1
target-select:
Start: 2
target-valid:
Start: 0
target-invalid:
Start: 1

BIN
mods/ra/bits/overlay.shp Normal file

Binary file not shown.

View File

@@ -1999,3 +1999,14 @@ gpsdot:
Harvester:
Start: 5
overlay:
build-valid:
Start: 0
build-invalid:
Start: 1
target-select:
Start: 2
target-valid:
Start: 0
target-invalid:
Start: 1