git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1343 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
(no author)
2007-07-24 10:04:54 +00:00
parent fce2dcda8a
commit 60e6f36042
8 changed files with 50 additions and 16 deletions

View File

@@ -11,11 +11,11 @@ namespace OpenRa.Game
{ {
} }
public override IOrder Order( int2 xy ) public override IOrder Order( Game game, int2 xy )
{ {
if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy ) if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy )
return new HarvestOrder( this ); return new HarvestOrder( this );
return base.Order( xy ); return base.Order( game, xy );
} }
void AcceptHarvestOrder() void AcceptHarvestOrder()

View File

@@ -6,7 +6,7 @@ namespace OpenRa.Game
{ {
interface IOrderGenerator interface IOrderGenerator
{ {
//Sprite CurrentCursor( int x, int y ); IOrder Order( Game game, int2 xy );
IOrder Order( int2 xy ); void PrepareOverlay( Game game, int2 xy );
} }
} }

View File

@@ -89,6 +89,10 @@ namespace OpenRa.Game
game.viewport.Scroll(lastPos - p); game.viewport.Scroll(lastPos - p);
lastPos = p; lastPos = p;
} }
if (game.world.orderGenerator != null)
game.world.orderGenerator.PrepareOverlay(game,
new int2(e.Location.X / 24, e.Location.Y / 24));
} }
} }
} }

View File

@@ -35,12 +35,12 @@ namespace OpenRa.Game
}; };
} }
public override IOrder Order( int2 xy ) public override IOrder Order( Game game, int2 xy )
{ {
if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy ) if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy )
return new DeployMcvOrder( this ); return new DeployMcvOrder( this );
return base.Order( xy ); return base.Order( game, xy );
} }
} }
} }

View File

@@ -141,12 +141,18 @@ namespace OpenRa.Game
this.buildingName = buildingName; this.buildingName = buildingName;
} }
public IOrder Order( int2 xy ) public IOrder Order( Game game, int2 xy )
{ {
game.world.uiOverlay.KillOverlay();
// todo: check that space is free // todo: check that space is free
return new PlaceBuildingOrder( this, xy ); return new PlaceBuildingOrder( this, xy );
} }
public void PrepareOverlay(Game game, int2 xy)
{
game.world.uiOverlay.SetCurrentOverlay(false, xy, 2, 3);
}
class PlaceBuildingOrder : IOrder class PlaceBuildingOrder : IOrder
{ {
PlaceBuilding building; PlaceBuilding building;

View File

@@ -34,9 +34,31 @@ namespace OpenRa.Game
public void Draw() public void Draw()
{ {
spriteRenderer.DrawSprite(buildOk, new float2(48, 48), 0); if (!hasOverlay)
spriteRenderer.DrawSprite(buildBlocked, new float2(96, 48), 0); return;
spriteRenderer.Flush();
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
spriteRenderer.DrawSprite(blocked ? buildBlocked : buildOk,
24 * (position + new int2(i, j)), 0);
}
bool hasOverlay = false, blocked;
int2 position;
int width, height;
public void KillOverlay()
{
hasOverlay = false;
}
public void SetCurrentOverlay(bool blocked, int2 cell, int width, int height)
{
hasOverlay = true;
position = cell;
this.width = width;
this.height = height;
this.blocked = blocked;
} }
} }
} }

View File

@@ -126,7 +126,9 @@ namespace OpenRa.Game
} }
public int2 Location { get { return toCell; } } public int2 Location { get { return toCell; } }
public virtual IOrder Order(int2 xy) { return new MoveOrder(this, xy); } public virtual IOrder Order(Game game, int2 xy) { return new MoveOrder(this, xy); }
public override Sprite[] CurrentImages { get { return animation.Images; } } public override Sprite[] CurrentImages { get { return animation.Images; } }
public void PrepareOverlay(Game game, int2 xy) { }
} }
} }

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Game
Game game; Game game;
Region region; Region region;
public IOrderGenerator orderGenerator; public IOrderGenerator orderGenerator;
UiOverlay uiOverlay; public UiOverlay uiOverlay;
public World(Renderer renderer, Game game) public World(Renderer renderer, Game game)
{ {
@@ -40,7 +40,7 @@ namespace OpenRa.Game
float2 xy = (1 / 24.0f) * (new float2(e.Location) + game.viewport.Location); float2 xy = (1 / 24.0f) * (new float2(e.Location) + game.viewport.Location);
if (orderGenerator != null) if (orderGenerator != null)
{ {
IOrder order = orderGenerator.Order(new int2((int)xy.X, (int)xy.Y)); IOrder order = orderGenerator.Order(game, new int2((int)xy.X, (int)xy.Y));
game.Issue(order); game.Issue(order);
} }
} }