Fixed the building placement to have the cursor in the centre. Replaced magic numbers with Game.CellSize
Using the building footprint, the placement overlay is offset from the cursor so the cursor is in the approximate middle of the overlay (not precisely due to overlay snapping to tiles). The tile size (24) was used as a magic number in a lot of places, they have been replaced with Game.CellSize.
This commit is contained in:
@@ -23,7 +23,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
unitInfo = Rules.UnitInfo[ name ];
|
unitInfo = Rules.UnitInfo[ name ];
|
||||||
Location = location;
|
Location = location;
|
||||||
CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location;
|
CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location;
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
|
|
||||||
switch( name )
|
switch( name )
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ namespace OpenRa.Game
|
|||||||
if (!(orderGenerator is PlaceBuilding))
|
if (!(orderGenerator is PlaceBuilding))
|
||||||
{
|
{
|
||||||
if (dragStart != xy)
|
if (dragStart != xy)
|
||||||
orderGenerator = new UnitOrderGenerator( game.FindUnits( 24 * dragStart, 24 * xy ) ); /* band-box select */
|
orderGenerator = new UnitOrderGenerator( game.FindUnits( Game.CellSize * dragStart, Game.CellSize * xy ) ); /* band-box select */
|
||||||
else
|
else
|
||||||
orderGenerator = new UnitOrderGenerator( game.FindUnits( 24 * xy, 24 * xy ) ); /* click select */
|
orderGenerator = new UnitOrderGenerator( game.FindUnits( Game.CellSize * xy, Game.CellSize * xy ) ); /* click select */
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart = dragEnd;
|
dragStart = dragEnd;
|
||||||
@@ -67,7 +67,7 @@ namespace OpenRa.Game
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (dragStart == dragEnd) return null;
|
if (dragStart == dragEnd) return null;
|
||||||
return Pair.New(24 * dragStart, 24 * dragEnd);
|
return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ using IjwFramework.Collections;
|
|||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
|
public static readonly int CellSize = 24;
|
||||||
|
|
||||||
public readonly World world;
|
public readonly World world;
|
||||||
public readonly Map map;
|
public readonly Map map;
|
||||||
readonly TreeCache treeCache;
|
readonly TreeCache treeCache;
|
||||||
|
|||||||
@@ -41,13 +41,18 @@ namespace OpenRa.Game.GameRules
|
|||||||
var footprint = Rules.Footprint.GetFootprint(name);
|
var footprint = Rules.Footprint.GetFootprint(name);
|
||||||
var j = 0;
|
var j = 0;
|
||||||
|
|
||||||
|
int maxWidth = 0;
|
||||||
|
foreach (var row in footprint)
|
||||||
|
if (row.Length > maxWidth)
|
||||||
|
maxWidth = row.Length;
|
||||||
|
|
||||||
foreach (var row in footprint)
|
foreach (var row in footprint)
|
||||||
{
|
{
|
||||||
var i = 0;
|
var i = 0;
|
||||||
foreach (var c in row)
|
foreach (var c in row)
|
||||||
{
|
{
|
||||||
if (c != '_')
|
if (c != '_')
|
||||||
yield return position + new int2(i, j);
|
yield return position + new int2(i, j) - new int2(maxWidth / 2, footprint.Length / 2);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
++j;
|
++j;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
spriteIndex = 11;
|
spriteIndex = 11;
|
||||||
else if( overlayIsGems[ map.MapTiles[ x, y ].overlay ] )
|
else if( overlayIsGems[ map.MapTiles[ x, y ].overlay ] )
|
||||||
spriteIndex = 2;
|
spriteIndex = 2;
|
||||||
spriteRenderer.DrawSprite( sprites[ spriteIndex ], 24 * (float2)( location - map.Offset ), 0 );
|
spriteRenderer.DrawSprite( sprites[ spriteIndex ], Game.CellSize * (float2)( location - map.Offset ), 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
|
|
||||||
tileSet = new TileSet( map.TileSuffix );
|
tileSet = new TileSet( map.TileSuffix );
|
||||||
|
|
||||||
Size tileSize = new Size( 24, 24 );
|
Size tileSize = new Size( Game.CellSize, Game.CellSize );
|
||||||
|
|
||||||
var tileMapping = new Cache<TileReference, Sprite>(
|
var tileMapping = new Cache<TileReference, Sprite>(
|
||||||
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
|
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
|
||||||
@@ -44,7 +44,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
for (int i = 0; i < map.Width; i++)
|
for (int i = 0; i < map.Width; i++)
|
||||||
{
|
{
|
||||||
Sprite tile = tileMapping[map.MapTiles[i + map.XOffset, j + map.YOffset]];
|
Sprite tile = tileMapping[map.MapTiles[i + map.XOffset, j + map.YOffset]];
|
||||||
Util.FastCreateQuad(vertices, indices, 24 * new float2(i, j), tile, 0, nv, ni);
|
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni);
|
||||||
nv += 4;
|
nv += 4;
|
||||||
ni += 6;
|
ni += 6;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
public Viewport(float2 size, float2 mapSize, Renderer renderer)
|
public Viewport(float2 size, float2 mapSize, Renderer renderer)
|
||||||
{
|
{
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.mapSize = 24 * mapSize - size + new float2(128, 0);
|
this.mapSize = Game.CellSize * mapSize - size + new float2(128, 0);
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -214,7 +214,15 @@ namespace OpenRa.Game
|
|||||||
game.world.AddFrameEndTask(_ =>
|
game.world.AddFrameEndTask(_ =>
|
||||||
{
|
{
|
||||||
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
||||||
game.world.Add(new Actor(building.Name, xy, building.Owner));
|
|
||||||
|
//Adjust placement for cursor to be in middle
|
||||||
|
var footprint = Rules.Footprint.GetFootprint(building.Name);
|
||||||
|
int maxWidth = 0;
|
||||||
|
foreach (var row in footprint)
|
||||||
|
if (row.Length > maxWidth)
|
||||||
|
maxWidth = row.Length;
|
||||||
|
|
||||||
|
game.world.Add(new Actor(building.Name, xy - new int2(maxWidth / 2, footprint.Length / 2), building.Owner));
|
||||||
|
|
||||||
game.controller.orderGenerator = null;
|
game.controller.orderGenerator = null;
|
||||||
game.worldRenderer.uiOverlay.KillOverlay();
|
game.worldRenderer.uiOverlay.KillOverlay();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRa.Game.Traits
|
|||||||
if (first && self.Owner == game.LocalPlayer)
|
if (first && self.Owner == game.LocalPlayer)
|
||||||
{
|
{
|
||||||
self.Owner.TechTree.Build(self.unitInfo.Name, true);
|
self.Owner.TechTree.Build(self.unitInfo.Name, true);
|
||||||
self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize;
|
self.CenterLocation = Game.CellSize * (float2)self.Location + 0.5f * self.SelectedSize;
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenRa.Game.Traits
|
|||||||
void UpdateCenterLocation()
|
void UpdateCenterLocation()
|
||||||
{
|
{
|
||||||
float fraction = (moveFraction > 0) ? (float)moveFraction / moveFractionTotal : 0f;
|
float fraction = (moveFraction > 0) ? (float)moveFraction / moveFractionTotal : 0f;
|
||||||
self.CenterLocation = new float2(12, 12) + 24 * float2.Lerp(fromCell, toCell, fraction);
|
self.CenterLocation = new float2(12, 12) + Game.CellSize * float2.Lerp(fromCell, toCell, fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self, Game game, int dt)
|
public void Tick(Actor self, Game game, int dt)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
var mobile = self.traits.Get<Mobile>();
|
var mobile = self.traits.Get<Mobile>();
|
||||||
float fraction = (mobile.moveFraction > 0) ? (float)mobile.moveFraction / mobile.moveFractionTotal : 0f;
|
float fraction = (mobile.moveFraction > 0) ? (float)mobile.moveFraction / mobile.moveFractionTotal : 0f;
|
||||||
var centerLocation = new float2(12, 12) + 24 * float2.Lerp(mobile.fromCell, mobile.toCell, fraction);
|
var centerLocation = new float2(12, 12) + Game.CellSize * float2.Lerp(mobile.fromCell, mobile.toCell, fraction);
|
||||||
yield return Centered(anim.Image, centerLocation);
|
yield return Centered(anim.Image, centerLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
public IEnumerable<Pair<Sprite, float2>> Render(Actor self)
|
public IEnumerable<Pair<Sprite, float2>> Render(Actor self)
|
||||||
{
|
{
|
||||||
yield return Pair.New(Image, 24 * (float2)self.Location);
|
yield return Pair.New(Image, Game.CellSize * (float2)self.Location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
class Turreted : ITick // temporary.
|
class Turreted : ITick // temporary.
|
||||||
{
|
{
|
||||||
public int turretFacing = 24;
|
public int turretFacing = Game.CellSize;
|
||||||
|
|
||||||
public Turreted(Actor self)
|
public Turreted(Actor self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
static Sprite SynthesizeTile(byte paletteIndex)
|
static Sprite SynthesizeTile(byte paletteIndex)
|
||||||
{
|
{
|
||||||
byte[] data = new byte[24 * 24];
|
byte[] data = new byte[Game.CellSize * Game.CellSize];
|
||||||
|
|
||||||
for (int i = 0; i < 24; i++)
|
for (int i = 0; i < Game.CellSize; i++)
|
||||||
for (int j = 0; j < 24; j++)
|
for (int j = 0; j < Game.CellSize; j++)
|
||||||
data[i * 24 + j] = ((i + j) % 4 < 2) ? (byte)0 : paletteIndex;
|
data[i * Game.CellSize + j] = ((i + j) % 4 < 2) ? (byte)0 : paletteIndex;
|
||||||
|
|
||||||
return SheetBuilder.Add( data, new Size(24,24) );
|
return SheetBuilder.Add( data, new Size(Game.CellSize,Game.CellSize) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
@@ -38,7 +38,7 @@ namespace OpenRa.Game
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var t in Footprint.Tiles(name,position))
|
foreach (var t in Footprint.Tiles(name,position))
|
||||||
spriteRenderer.DrawSprite(game.IsCellBuildable(t) ? buildOk : buildBlocked, 24 * t, 0);
|
spriteRenderer.DrawSprite(game.IsCellBuildable(t) ? buildOk : buildBlocked, Game.CellSize * t, 0);
|
||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user