git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1343 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -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 )
|
||||
return new HarvestOrder( this );
|
||||
return base.Order( xy );
|
||||
return base.Order( game, xy );
|
||||
}
|
||||
|
||||
void AcceptHarvestOrder()
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
interface IOrderGenerator
|
||||
{
|
||||
//Sprite CurrentCursor( int x, int y );
|
||||
IOrder Order( int2 xy );
|
||||
IOrder Order( Game game, int2 xy );
|
||||
void PrepareOverlay( Game game, int2 xy );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,10 @@ namespace OpenRa.Game
|
||||
game.viewport.Scroll(lastPos - p);
|
||||
lastPos = p;
|
||||
}
|
||||
|
||||
if (game.world.orderGenerator != null)
|
||||
game.world.orderGenerator.PrepareOverlay(game,
|
||||
new int2(e.Location.X / 24, e.Location.Y / 24));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
return new DeployMcvOrder( this );
|
||||
|
||||
return base.Order( xy );
|
||||
return base.Order( game, xy );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ namespace OpenRa.Game
|
||||
|
||||
public void Build(SidebarItem item)
|
||||
{
|
||||
if( item != null )
|
||||
game.world.orderGenerator = new PlaceBuilding( game.players[ 1 ], item.techTreeItem.tag.ToLowerInvariant() );
|
||||
if (item != null)
|
||||
game.world.orderGenerator = new PlaceBuilding(game.players[1], item.techTreeItem.tag.ToLowerInvariant());
|
||||
}
|
||||
|
||||
void LoadSprites(string filename)
|
||||
@@ -141,12 +141,18 @@ namespace OpenRa.Game
|
||||
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
|
||||
return new PlaceBuildingOrder( this, xy );
|
||||
}
|
||||
|
||||
public void PrepareOverlay(Game game, int2 xy)
|
||||
{
|
||||
game.world.uiOverlay.SetCurrentOverlay(false, xy, 2, 3);
|
||||
}
|
||||
|
||||
class PlaceBuildingOrder : IOrder
|
||||
{
|
||||
PlaceBuilding building;
|
||||
|
||||
@@ -34,9 +34,31 @@ namespace OpenRa.Game
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
spriteRenderer.DrawSprite(buildOk, new float2(48, 48), 0);
|
||||
spriteRenderer.DrawSprite(buildBlocked, new float2(96, 48), 0);
|
||||
spriteRenderer.Flush();
|
||||
if (!hasOverlay)
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,9 @@ namespace OpenRa.Game
|
||||
}
|
||||
|
||||
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 void PrepareOverlay(Game game, int2 xy) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace OpenRa.Game
|
||||
Game game;
|
||||
Region region;
|
||||
public IOrderGenerator orderGenerator;
|
||||
UiOverlay uiOverlay;
|
||||
public UiOverlay uiOverlay;
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace OpenRa.Game
|
||||
lastTime = t;
|
||||
|
||||
Range<float2> range = new Range<float2>(region.Location, region.Location + region.Size);
|
||||
|
||||
|
||||
foreach (Actor a in actors)
|
||||
{
|
||||
a.Tick( game, dt );
|
||||
|
||||
Reference in New Issue
Block a user