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