real queues
This commit is contained in:
@@ -23,9 +23,9 @@ namespace OpenRa.Game
|
||||
readonly SpriteRenderer buildPaletteRenderer;
|
||||
readonly Animation cantBuild;
|
||||
readonly Animation ready;
|
||||
readonly Animation clock;
|
||||
|
||||
readonly List<Pair<Rectangle, Action<bool>>> buttons = new List<Pair<Rectangle, Action<bool>>>();
|
||||
readonly Cache<string, Animation> clockAnimations;
|
||||
readonly List<Sprite> digitSprites;
|
||||
readonly Dictionary<string, Sprite[]> tabSprites;
|
||||
readonly Sprite[] shimSprites;
|
||||
@@ -70,14 +70,6 @@ namespace OpenRa.Game
|
||||
cantBuild = new Animation("clock");
|
||||
cantBuild.PlayFetchIndex("idle", () => 0);
|
||||
|
||||
clockAnimations = new Cache<string, Animation>(
|
||||
s =>
|
||||
{
|
||||
var anim = new Animation("clock");
|
||||
anim.PlayFetchIndex("idle", ClockAnimFrame(s));
|
||||
return anim;
|
||||
});
|
||||
|
||||
digitSprites = Util.MakeArray(10, a => a)
|
||||
.Select(n => new Sprite(specialBin, new Rectangle(32 + 13 * n, 0, 13, 17), TextureChannel.Alpha)).ToList();
|
||||
|
||||
@@ -92,6 +84,7 @@ namespace OpenRa.Game
|
||||
|
||||
ready = new Animation("pips");
|
||||
ready.PlayRepeating("ready");
|
||||
clock = new Animation("clock");
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
@@ -250,7 +243,6 @@ namespace OpenRa.Game
|
||||
.OrderBy(a => Rules.UnitInfo[a].TechLevel);
|
||||
|
||||
var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||
var currentItem = queue.CurrentItem( queueName );
|
||||
|
||||
var overlayBits = new List<Pair<Sprite, float2>>();
|
||||
|
||||
@@ -260,39 +252,39 @@ namespace OpenRa.Game
|
||||
{
|
||||
var rect = new Rectangle(origin.X + x * 64, origin.Y + 48 * y, 64, 48);
|
||||
var drawPos = Game.viewport.Location + new float2(rect.Location);
|
||||
var isBuildingThis = currentItem != null && currentItem.Item == item;
|
||||
var isBuildingSomethingElse = currentItem != null && currentItem.Item != item;
|
||||
var isBuildingSomething = queue.CurrentItem(queueName) != null;
|
||||
|
||||
buildPaletteRenderer.DrawSprite(sprites[item], drawPos, PaletteType.Chrome);
|
||||
|
||||
var firstOfThis = queue.AllItems(queueName).FirstOrDefault(a => a.Item == item);
|
||||
|
||||
if (rect.Contains(lastMousePos.ToPoint()))
|
||||
tooltipItem = item;
|
||||
|
||||
if (!buildableItems.Contains(item) || isBuildingSomethingElse)
|
||||
overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
|
||||
|
||||
var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2);
|
||||
|
||||
if (isBuildingThis)
|
||||
if (firstOfThis != null)
|
||||
{
|
||||
clockAnimations[queueName].Tick();
|
||||
buildPaletteRenderer.DrawSprite(clockAnimations[queueName].Image,
|
||||
drawPos, PaletteType.Chrome);
|
||||
clock.PlayFetchIndex( "idle",
|
||||
() => (firstOfThis.TotalTime - firstOfThis.RemainingTime)
|
||||
* NumClockFrames / firstOfThis.TotalTime);
|
||||
clock.Tick();
|
||||
|
||||
if (currentItem.Done)
|
||||
buildPaletteRenderer.DrawSprite(clock.Image, drawPos, PaletteType.Chrome);
|
||||
|
||||
if (firstOfThis.Done)
|
||||
{
|
||||
ready.Play("ready");
|
||||
overlayBits.Add(Pair.New(ready.Image, overlayPos));
|
||||
}
|
||||
else if (currentItem.Paused)
|
||||
else if (firstOfThis.Paused)
|
||||
{
|
||||
ready.Play("hold");
|
||||
overlayBits.Add(Pair.New(ready.Image, overlayPos));
|
||||
}
|
||||
}
|
||||
|
||||
var repeats = queue.AllItems(queueName).Count(a => a.Item == item);
|
||||
if (repeats > 1 || isBuildingThis)
|
||||
if (repeats > 1 || queue.CurrentItem(queueName) != firstOfThis)
|
||||
{
|
||||
var offset = -20;
|
||||
var digits = repeats.ToString();
|
||||
@@ -304,6 +296,10 @@ namespace OpenRa.Game
|
||||
offset += 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!buildableItems.Contains(item) || isBuildingSomething)
|
||||
overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
|
||||
|
||||
var closureItem = item;
|
||||
buttons.Add(Pair.New(rect,
|
||||
@@ -344,48 +340,48 @@ namespace OpenRa.Game
|
||||
return y*48+9;
|
||||
}
|
||||
|
||||
void StartProduction( string item )
|
||||
{
|
||||
var group = Rules.UnitCategory[item];
|
||||
Sound.Play((group == "Building" || group == "Defense") ? "abldgin1.aud" : "train1.aud");
|
||||
Game.controller.AddOrder(Order.StartProduction(Game.LocalPlayer, item));
|
||||
}
|
||||
|
||||
void HandleBuildPalette(string item, bool isLmb)
|
||||
{
|
||||
var player = Game.LocalPlayer;
|
||||
var group = Rules.UnitCategory[item];
|
||||
var queue = player.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||
var producing = queue.CurrentItem( group );
|
||||
var producing = queue.AllItems(group).FirstOrDefault( a => a.Item == item );
|
||||
|
||||
Sound.Play("ramenu1.aud");
|
||||
|
||||
if (isLmb)
|
||||
{
|
||||
if (producing == null)
|
||||
{
|
||||
Game.controller.AddOrder(Order.StartProduction(player, item));
|
||||
Sound.Play((group == "Building" || group == "Defense") ? "abldgin1.aud" : "train1.aud");
|
||||
}
|
||||
else if (producing.Item == item)
|
||||
if (producing != null && producing == queue.CurrentItem(group))
|
||||
{
|
||||
if (producing.Done)
|
||||
{
|
||||
if (group == "Building" || group == "Defense")
|
||||
Game.controller.orderGenerator = new PlaceBuilding(player.PlayerActor, item);
|
||||
return;
|
||||
}
|
||||
else if (producing.Paused)
|
||||
Game.controller.AddOrder(Order.PauseProduction(player, item, false));
|
||||
else
|
||||
{
|
||||
Sound.Play((group == "Building" || group == "Defense") ? "abldgin1.aud" : "train1.aud");
|
||||
Game.controller.AddOrder(Order.StartProduction(player, item));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Sound.Play("progres1.aud");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (producing == null) return;
|
||||
if (item != producing.Item) return;
|
||||
|
||||
if (producing.Paused || producing.Done)
|
||||
if (producing.Paused)
|
||||
{
|
||||
Game.controller.AddOrder(Order.PauseProduction(player, item, false));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
StartProduction(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (producing != null)
|
||||
{
|
||||
// instant cancel of things we havent really started yet, and things that are finished
|
||||
if (producing.Paused || producing.Done || producing.TotalCost == producing.RemainingCost)
|
||||
{
|
||||
Sound.Play("cancld1.aud");
|
||||
Game.controller.AddOrder(Order.CancelProduction(player, item));
|
||||
@@ -397,6 +393,7 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int2 lastMousePos;
|
||||
public bool HandleInput(MouseInput mi)
|
||||
|
||||
@@ -73,9 +73,7 @@ namespace OpenRa.Game.Traits
|
||||
}
|
||||
case "CancelProduction":
|
||||
{
|
||||
var producing = CurrentItem( Rules.UnitCategory[ order.TargetString ] );
|
||||
if( producing != null && producing.Item == order.TargetString )
|
||||
CancelProduction( Rules.UnitCategory[ order.TargetString ] );
|
||||
CancelProduction(order.TargetString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -95,12 +93,13 @@ namespace OpenRa.Game.Traits
|
||||
return production[category];
|
||||
}
|
||||
|
||||
public void CancelProduction( string category )
|
||||
public void CancelProduction( string itemName )
|
||||
{
|
||||
var category = Rules.UnitCategory[itemName];
|
||||
var queue = production[ category ];
|
||||
if (queue.Count == 0) return;
|
||||
|
||||
var lastIndex = queue.FindLastIndex( a => a.Item == queue[0].Item );
|
||||
var lastIndex = queue.FindLastIndex( a => a.Item == itemName );
|
||||
if (lastIndex > 0)
|
||||
{
|
||||
queue.RemoveAt(lastIndex);
|
||||
|
||||
Reference in New Issue
Block a user