much better building support; phantom selection is dead AGAIN.

This commit is contained in:
Chris Forbes
2009-10-31 23:17:59 +13:00
parent 6cd9d468d3
commit a3dba77f99
7 changed files with 59 additions and 12 deletions

View File

@@ -8,5 +8,6 @@ namespace OpenRa.Game
{
IEnumerable<Order> Order( int2 xy, bool lmb );
void PrepareOverlay( int2 xy );
void Tick();
}
}

View File

@@ -80,6 +80,8 @@ namespace OpenRa.Game
{
Game.Tick();
Game.viewport.cursor = Game.controller.ChooseCursor();
if (Game.controller.orderGenerator != null)
Game.controller.orderGenerator.Tick();
Application.DoEvents();
}
}

View File

@@ -49,5 +49,7 @@ namespace OpenRa.Game
{
Game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name);
}
public void Tick() { }
}
}

View File

@@ -86,12 +86,14 @@ namespace OpenRa.Game
public int RemainingCost { get; private set; }
public bool Paused = false, Done = false;
public Action OnComplete;
public ProductionItem( string item, int time, int cost )
public ProductionItem( string item, int time, int cost, Action onComplete )
{
Item = item;
RemainingTime = TotalTime = time;
RemainingCost = TotalCost = cost;
OnComplete = onComplete;
}
public void Tick( Player player )
@@ -107,6 +109,8 @@ namespace OpenRa.Game
// item finished; do whatever needs done.
Done = true;
if (OnComplete != null)
OnComplete();
}
}
}

View File

@@ -16,6 +16,8 @@ namespace OpenRa.Game
SpriteRenderer spriteRenderer, clockRenderer;
Sprite blank;
Animation ready;
Animation cantBuild;
readonly GRegion region;
public GRegion Region { get { return region; } }
@@ -49,6 +51,11 @@ namespace OpenRa.Game
}
blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16);
ready = new Animation("pips");
ready.PlayRepeating("ready");
cantBuild = new Animation("clock");
cantBuild.PlayFetchIndex("idle", () => 0);
}
const int NumClockFrames = 54;
@@ -125,7 +132,12 @@ namespace OpenRa.Game
void Paint()
{
PopulateItemList();
foreach( SidebarItem i in items )
foreach( var i in items ) /* draw the buttons */
i.Paint(spriteRenderer, region.Location);
spriteRenderer.Flush();
foreach( var i in items ) /* draw the status overlays */
{
var group = Rules.UnitCategory[ i.Tag ];
var producing = player.Producing( group );
@@ -133,8 +145,12 @@ namespace OpenRa.Game
{
clockAnimations[ group ].Tick();
clockRenderer.DrawSprite( clockAnimations[ group ].Image, region.Location.ToFloat2() + i.location, 0 );
if (producing.Done)
clockRenderer.DrawSprite(ready.Image, region.Location.ToFloat2() + i.location + new float2((64 - ready.Image.size.X) / 2, 2), 0);
}
i.Paint( spriteRenderer, region.Location );
else if (producing != null)
clockRenderer.DrawSprite(cantBuild.Image, region.Location.ToFloat2() + i.location, 0);
}
Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X, buildPos + region.Location.Y));
@@ -153,6 +169,11 @@ namespace OpenRa.Game
return null;
}
static bool IsAutoCompleting(string group)
{
return group != "Building";
}
void MouseHandler(MouseInput mi)
{
var point = mi.Location.ToFloat2();
@@ -172,17 +193,21 @@ namespace OpenRa.Game
* (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */
/ 1000;
Action complete = null;
if (IsAutoCompleting(group)) complete = () => Build(item);
player.BeginProduction(group,
new ProductionItem(item.Tag, (int)time, ui.Cost));
//Build(item);
new ProductionItem(item.Tag, (int)time, ui.Cost, complete));
}
else if (producing.Item == item.Tag)
else if (producing.Item == item.Tag && producing.Done)
{
Build(item);
}
}
else if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down)
{
player.CancelProduction(Rules.UnitCategory[item.Tag]);
}
}
}
}

View File

@@ -24,6 +24,11 @@ namespace OpenRa.Game
}
}
public void Tick()
{
selection.RemoveAll(a => a.IsDead);
}
public void PrepareOverlay(int2 xy) {}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- openra/sequences.xml
this file describes animation sequences for structures and units.
@@ -468,4 +468,12 @@
<unit name="lst">
<sequence name="idle" start="0" length="1" />
</unit>
<unit name="pips">
<sequence name="groups" start="8" length="10" />
<sequence name="ore" start="0" length="2" />
<sequence name="cargo" start="5" length="3" />
<sequence name="medic" start="20" length="1" />
<sequence name="ready" start="3" length="1" />
<sequence name="hold" start="4" length="1" />
</unit>
</sequences>