diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj
index da83a159d9..e60412c267 100644
--- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj
+++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj
@@ -85,7 +85,6 @@
-
@@ -94,14 +93,9 @@
-
-
-
-
-
diff --git a/OpenRA.Mods.D2k/Traits/World/ChooseBuildTabOnSelect.cs b/OpenRA.Mods.D2k/Traits/World/ChooseBuildTabOnSelect.cs
deleted file mode 100644
index 1cce0d7465..0000000000
--- a/OpenRA.Mods.D2k/Traits/World/ChooseBuildTabOnSelect.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
- * This file is part of OpenRA, which is free software. It is made
- * available to you under the terms of the GNU General Public License
- * as published by the Free Software Foundation. For more information,
- * see COPYING.
- */
-#endregion
-
-using System.Linq;
-using OpenRA.Mods.Common.Traits;
-using OpenRA.Mods.D2k.Widgets;
-using OpenRA.Mods.RA.Traits;
-using OpenRA.Traits;
-using OpenRA.Widgets;
-
-namespace OpenRA.Mods.D2k.Traits
-{
- [Desc("If the BuildPaletteWidget is used, this trait needs to be added to world actor",
- "to make the build palette open automatically when a production facility is deployed.")]
- class ChooseBuildTabOnSelectInfo : ITraitInfo
- {
- public readonly string BuildPaletteWidgetName = "INGAME_BUILD_PALETTE";
-
- public object Create(ActorInitializer init) { return new ChooseBuildTabOnSelect(init, this); }
- }
-
- class ChooseBuildTabOnSelect : INotifySelection
- {
- readonly World world;
- readonly ChooseBuildTabOnSelectInfo info;
-
- public ChooseBuildTabOnSelect(ActorInitializer init, ChooseBuildTabOnSelectInfo info)
- {
- world = init.World;
- this.info = info;
- }
-
- public void SelectionChanged()
- {
- var palette = Ui.Root.GetOrNull(info.BuildPaletteWidgetName);
- if (palette == null)
- return;
-
- // Queue-per-structure
- var perqueue = world.Selection.Actors.FirstOrDefault(a => a.IsInWorld && a.World.LocalPlayer == a.Owner
- && a.TraitsImplementing().Any(q => q.Enabled));
-
- if (perqueue != null)
- {
- palette.SetCurrentTab(perqueue.TraitsImplementing().First(q => q.Enabled));
- return;
- }
-
- // Queue-per-player
- var types = world.Selection.Actors.Where(a => a.IsInWorld && (a.World.LocalPlayer == a.Owner))
- .SelectMany(a => a.TraitsImplementing())
- .SelectMany(t => t.Info.Produces)
- .ToHashSet();
-
- if (types.Count == 0)
- return;
-
- palette.SetCurrentTab(world.LocalPlayer.PlayerActor.TraitsImplementing()
- .FirstOrDefault(q => q.Enabled && types.Contains(q.Info.Type)));
- }
- }
-}
diff --git a/OpenRA.Mods.D2k/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.D2k/Widgets/BuildPaletteWidget.cs
deleted file mode 100644
index 08df66cc1e..0000000000
--- a/OpenRA.Mods.D2k/Widgets/BuildPaletteWidget.cs
+++ /dev/null
@@ -1,578 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
- * This file is part of OpenRA, which is free software. It is made
- * available to you under the terms of the GNU General Public License
- * as published by the Free Software Foundation. For more information,
- * see COPYING.
- */
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using OpenRA.Graphics;
-using OpenRA.Mods.Common.Orders;
-using OpenRA.Mods.Common.Traits;
-using OpenRA.Network;
-using OpenRA.Primitives;
-using OpenRA.Traits;
-using OpenRA.Widgets;
-
-namespace OpenRA.Mods.D2k.Widgets
-{
- [Desc("Classic BuildPaletteWidget. Needs ChooseBuildTabOnSelect trait to be added to world actor",
- "in order to make the build palette open automatically when a production facility is deployed.")]
- class BuildPaletteWidget : Widget
- {
- public enum ReadyTextStyleOptions { Solid, AlternatingColor, Blinking }
- public readonly ReadyTextStyleOptions ReadyTextStyle = ReadyTextStyleOptions.AlternatingColor;
- public readonly Color ReadyTextAltColor = Color.Gold;
- public int Columns = 3;
- public int Rows = 5;
-
- [Translate] public string ReadyText = "";
- [Translate] public string HoldText = "";
- [Translate] public string RequiresText = "";
-
- public int IconWidth = 64;
- public int IconHeight = 48;
-
- readonly WorldRenderer worldRenderer;
- readonly World world;
- readonly OrderManager orderManager;
-
- ProductionQueue currentQueue;
- List visibleQueues;
-
- bool paletteOpen = false;
-
- float2 paletteOpenOrigin;
- float2 paletteClosedOrigin;
- float2 paletteOrigin;
-
- int paletteAnimationLength = 7;
- int paletteAnimationFrame = 0;
- bool paletteAnimating = false;
-
- List>> buttons = new List>>();
- List>> tabs = new List>>();
- Animation cantBuild;
- Animation clock;
-
- [ObjectCreator.UseCtor]
- public BuildPaletteWidget(OrderManager orderManager, World world, WorldRenderer worldRenderer)
- {
- this.orderManager = orderManager;
- this.world = world;
- this.worldRenderer = worldRenderer;
-
- cantBuild = new Animation(world, "clock");
- cantBuild.PlayFetchIndex("idle", () => 0);
- clock = new Animation(world, "clock");
- visibleQueues = new List();
- currentQueue = null;
- }
-
- public override void Initialize(WidgetArgs args)
- {
- paletteOpenOrigin = new float2(Game.Renderer.Resolution.Width - Columns * IconWidth - 23, 280);
- paletteClosedOrigin = new float2(Game.Renderer.Resolution.Width - 16, 280);
- paletteOrigin = paletteClosedOrigin;
- base.Initialize(args);
- }
-
- public override Rectangle EventBounds
- {
- get { return new Rectangle((int)paletteOrigin.X - 24, (int)paletteOrigin.Y, 239, Math.Max(IconHeight * numActualRows, 40 * tabs.Count + 9)); }
- }
-
- public override void Tick()
- {
- visibleQueues.Clear();
-
- var queues = world.ActorsWithTrait()
- .Where(p => p.Actor.Owner == world.LocalPlayer)
- .Select(p => p.Trait);
-
- if (currentQueue != null && currentQueue.Actor.Destroyed)
- currentQueue = null;
-
- foreach (var queue in queues)
- {
- if (queue.AllItems().Any())
- visibleQueues.Add(queue);
- else if (currentQueue == queue)
- currentQueue = null;
- }
-
- if (currentQueue == null)
- currentQueue = visibleQueues.FirstOrDefault();
-
- TickPaletteAnimation(world);
- }
-
- void TickPaletteAnimation(World world)
- {
- if (!paletteAnimating)
- return;
-
- // Increment frame
- if (paletteOpen)
- paletteAnimationFrame++;
- else
- paletteAnimationFrame--;
-
- // Calculate palette position
- if (paletteAnimationFrame <= paletteAnimationLength)
- paletteOrigin = float2.Lerp(paletteClosedOrigin, paletteOpenOrigin, paletteAnimationFrame * 1.0f / paletteAnimationLength);
-
- // Play palette-open sound at the start of the activate anim (open)
- if (paletteAnimationFrame == 1 && paletteOpen)
- Sound.PlayNotification(world.Map.Rules, null, "Sounds", "BuildPaletteOpen", null);
-
- // Play palette-close sound at the start of the activate anim (close)
- if (paletteAnimationFrame == paletteAnimationLength + -1 && !paletteOpen)
- Sound.PlayNotification(world.Map.Rules, null, "Sounds", "BuildPaletteClose", null);
-
- // Animation is complete
- if ((paletteAnimationFrame == 0 && !paletteOpen)
- || (paletteAnimationFrame == paletteAnimationLength && paletteOpen))
- paletteAnimating = false;
- }
-
- public void SetCurrentTab(ProductionQueue queue)
- {
- if (!paletteOpen)
- paletteAnimating = true;
-
- paletteOpen = true;
- currentQueue = queue;
- }
-
- public override bool HandleKeyPress(KeyInput e)
- {
- if (e.Event == KeyInputEvent.Up)
- return false;
-
- var hotkey = Hotkey.FromKeyInput(e);
-
- if (hotkey == Game.Settings.Keys.NextProductionTabKey)
- return ChangeTab(false);
- else if (hotkey == Game.Settings.Keys.PreviousProductionTabKey)
- return ChangeTab(true);
-
- return DoBuildingHotkey(e, world);
- }
-
- public override bool HandleMouseInput(MouseInput mi)
- {
- if (mi.Event != MouseInputEvent.Scroll && mi.Event != MouseInputEvent.Down)
- return true;
-
- if (mi.Event == MouseInputEvent.Scroll && mi.ScrollDelta < 0)
- return ChangeTab(false);
-
- if (mi.Event == MouseInputEvent.Scroll && mi.ScrollDelta > 0)
- return ChangeTab(true);
-
- var action = tabs.Where(a => a.First.Contains(mi.Location))
- .Select(a => a.Second).FirstOrDefault();
- if (action == null && paletteOpen)
- action = buttons.Where(a => a.First.Contains(mi.Location))
- .Select(a => a.Second).FirstOrDefault();
-
- if (action == null)
- return false;
-
- action(mi);
- return true;
- }
-
- public override void Draw()
- {
- if (!IsVisible())
- return;
-
- // TODO: fix
- DrawPalette(currentQueue);
- DrawBuildTabs(world);
- }
-
- int numActualRows = 5;
- int DrawPalette(ProductionQueue queue)
- {
- buttons.Clear();
-
- var paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
- var origin = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9);
- var iconOffset = 0.5f * new float2(IconWidth, IconHeight);
- var x = 0;
- var y = 0;
-
- if (queue != null)
- {
- var buildableItems = queue.BuildableItems().ToList();
- var allBuildables = queue.AllItems().OrderBy(a => a.Traits.Get().BuildPaletteOrder).ToList();
-
- var overlayBits = new List>();
- var textBits = new List>();
- numActualRows = Math.Max((allBuildables.Count + Columns - 1) / Columns, Rows);
-
- // Palette Background
- WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "top"), new float2(origin.X - 9, origin.Y - 9));
- for (var w = 0; w < numActualRows; w++)
- WidgetUtils.DrawRGBA(
- ChromeProvider.GetImage(paletteCollection, "bg-" + (w % 4)),
- new float2(origin.X - 9, origin.Y + IconHeight * w));
- WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "bottom"),
- new float2(origin.X - 9, origin.Y - 1 + IconHeight * numActualRows));
-
- // Icons
- string tooltipItem = null;
- var tooltipHotkey = Hotkey.Invalid;
- var i = 0;
- foreach (var item in allBuildables)
- {
- var rect = new RectangleF(origin.X + x * IconWidth, origin.Y + IconHeight * y, IconWidth, IconHeight);
- var drawPos = new float2(rect.Location);
- var icon = new Animation(world, RenderSimple.GetImage(item));
- icon.Play(item.Traits.Get().Icon);
- WidgetUtils.DrawSHPCentered(icon.Image, drawPos + iconOffset, worldRenderer);
-
- var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);
-
- if (rect.Contains(Viewport.LastMousePos))
- {
- tooltipItem = item.Name;
- tooltipHotkey = Game.Settings.Keys.GetProductionHotkey(i);
- }
-
- var overlayPos = drawPos + new float2(32, 16);
-
- if (firstOfThis != null)
- {
- clock.PlayFetchIndex("idle",
- () => (firstOfThis.TotalTime - firstOfThis.RemainingTime)
- * (clock.CurrentSequence.Length - 1) / firstOfThis.TotalTime);
- clock.Tick();
- WidgetUtils.DrawSHPCentered(clock.Image, drawPos + iconOffset, worldRenderer);
-
- if (queue.CurrentItem() == firstOfThis)
- textBits.Add(Pair.New(overlayPos, GetOverlayForItem(firstOfThis)));
-
- var repeats = queue.AllQueued().Count(a => a.Item == item.Name);
- if (repeats > 1 || queue.CurrentItem() != firstOfThis)
- textBits.Add(Pair.New(overlayPos + new float2(-24, -14), repeats.ToString()));
- }
- else
- if (buildableItems.All(a => a.Name != item.Name))
- overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
-
- var closureName = buildableItems.Any(a => a.Name == item.Name) ? item.Name : null;
- buttons.Add(Pair.New(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), HandleClick(closureName, world)));
-
- if (++x == Columns) { x = 0; y++; }
- i++;
- }
-
- if (x != 0)
- y++;
-
- foreach (var ob in overlayBits)
- WidgetUtils.DrawSHPCentered(ob.First, ob.Second + iconOffset, worldRenderer);
-
- var font = Game.Renderer.Fonts["TinyBold"];
- foreach (var tb in textBits)
- {
- var size = font.Measure(tb.Second);
- if (ReadyTextStyle == ReadyTextStyleOptions.Solid || orderManager.LocalFrameNumber / 9 % 2 == 0 || tb.Second != ReadyText)
- font.DrawTextWithContrast(tb.Second, tb.First - new float2(size.X / 2, 0),
- Color.White, Color.Black, 1);
- else if (ReadyTextStyle == ReadyTextStyleOptions.AlternatingColor)
- font.DrawTextWithContrast(tb.Second, tb.First - new float2(size.X / 2, 0),
- ReadyTextAltColor, Color.Black, 1);
- }
-
- // Tooltip
- if (tooltipItem != null && !paletteAnimating && paletteOpen)
- DrawProductionTooltip(world, tooltipItem, tooltipHotkey,
- new float2(Game.Renderer.Resolution.Width, origin.Y + numActualRows * IconHeight + 9).ToInt2());
- }
-
- // Palette Dock
- WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-top"),
- new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 23));
-
- for (var i = 0; i < numActualRows; i++)
- WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4)),
- new float2(Game.Renderer.Resolution.Width - 14, origin.Y + IconHeight * i));
-
- WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"),
- new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 1 + IconHeight * numActualRows));
-
- return IconHeight * y + 9;
- }
-
- string GetOverlayForItem(ProductionItem item)
- {
- if (item.Paused)
- return HoldText;
-
- if (item.Done)
- return ReadyText;
-
- return WidgetUtils.FormatTime(item.RemainingTimeActual);
- }
-
- Action HandleClick(string name, World world)
- {
- return mi =>
- {
- Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
-
- if (name != null)
- HandleBuildPalette(world, name, mi.Button == MouseButton.Left);
- };
- }
-
- Action HandleTabClick(ProductionQueue queue, World world)
- {
- return mi =>
- {
- if (mi.Button != MouseButton.Left)
- return;
-
- Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
- var wasOpen = paletteOpen;
- paletteOpen = currentQueue != queue || !wasOpen;
- currentQueue = queue;
- if (wasOpen != paletteOpen)
- paletteAnimating = true;
- };
- }
-
- static string Description(Ruleset rules, string a)
- {
- ActorInfo ai;
- rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai);
- if (ai != null && ai.Traits.Contains())
- return ai.Traits.Get().Name;
-
- return a;
- }
-
- void HandleBuildPalette(World world, string item, bool isLmb)
- {
- var unit = world.Map.Rules.Actors[item];
- var producing = currentQueue.AllQueued().FirstOrDefault(a => a.Item == item);
-
- if (isLmb)
- {
- if (producing != null && producing == currentQueue.CurrentItem())
- {
- if (producing.Done)
- {
- if (unit.Traits.Contains())
- world.OrderGenerator = new PlaceBuildingOrderGenerator(currentQueue, item);
- else
- StartProduction(world, item);
- return;
- }
-
- if (producing.Paused)
- {
- world.IssueOrder(Order.PauseProduction(currentQueue.Actor, item, false));
- return;
- }
- }
- else
- {
- // Check if the item's build-limit has already been reached
- var queued = currentQueue.AllQueued().Count(a => a.Item == unit.Name);
- var inWorld = world.ActorsWithTrait().Count(a => a.Actor.Info.Name == unit.Name && a.Actor.Owner == world.LocalPlayer);
- var buildLimit = unit.Traits.Get().BuildLimit;
-
- if (!((buildLimit != 0) && (inWorld + queued >= buildLimit)))
- Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.QueuedAudio, world.LocalPlayer.Country.Race);
- else
- Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.BlockedAudio, world.LocalPlayer.Country.Race);
- }
-
- StartProduction(world, 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.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.CancelledAudio, world.LocalPlayer.Country.Race);
- var numberToCancel = Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1;
-
- world.IssueOrder(Order.CancelProduction(currentQueue.Actor, item, numberToCancel));
- }
- else
- {
- Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Speech", currentQueue.Info.OnHoldAudio, world.LocalPlayer.Country.Race);
- world.IssueOrder(Order.PauseProduction(currentQueue.Actor, item, true));
- }
- }
- }
- }
-
- void StartProduction(World world, string item)
- {
- world.IssueOrder(Order.StartProduction(currentQueue.Actor, item,
- Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1));
- }
-
- void DrawBuildTabs(World world)
- {
- const int TabWidth = 24;
- const int TabHeight = 40;
- var x = paletteOrigin.X - TabWidth;
- var y = paletteOrigin.Y + 9;
-
- tabs.Clear();
-
- foreach (var queue in visibleQueues)
- {
- string[] tabKeys = { "normal", "ready", "selected" };
- var producing = queue.CurrentItem();
- var index = queue == currentQueue ? 2 : (producing != null && producing.Done) ? 1 : 0;
-
- var race = world.LocalPlayer.Country.Race;
- WidgetUtils.DrawRGBA(ChromeProvider.GetImage("tabs-" + tabKeys[index], race + "-" + queue.Info.Type), new float2(x, y));
-
- var rect = new Rectangle((int)x, (int)y, TabWidth, TabHeight);
- tabs.Add(Pair.New(rect, HandleTabClick(queue, world)));
-
- if (rect.Contains(Viewport.LastMousePos))
- {
- var text = queue.Info.Type;
- var font = Game.Renderer.Fonts["Bold"];
- var sz = font.Measure(text);
- WidgetUtils.DrawPanelPartial("dialog4",
- Rectangle.FromLTRB(rect.Left - sz.X - 30, rect.Top, rect.Left - 5, rect.Bottom),
- PanelSides.All);
-
- font.DrawText(text, new float2(rect.Left - sz.X - 20, rect.Top + 12), Color.White);
- }
-
- y += TabHeight;
- }
- }
-
- static void DrawRightAligned(string text, int2 pos, Color c)
- {
- var font = Game.Renderer.Fonts["Bold"];
- font.DrawText(text, pos - new int2(font.Measure(text).X, 0), c);
- }
-
- void DrawProductionTooltip(World world, string unit, Hotkey hotkey, int2 pos)
- {
- pos.Y += 15;
-
- var pl = world.LocalPlayer;
- var p = pos.ToFloat2() - new float2(297, -3);
-
- var info = world.Map.Rules.Actors[unit];
- var tooltip = info.Traits.Get();
- var buildable = info.Traits.Get();
- var cost = info.Traits.Get().Cost;
- var canBuildThis = currentQueue.CanBuild(info);
-
- var longDescSize = Game.Renderer.Fonts["Regular"].Measure(tooltip.Description.Replace("\\n", "\n")).Y;
- if (!canBuildThis) longDescSize += 8;
-
- WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.Renderer.Resolution.Width - 300, pos.Y, 300, longDescSize + 65));
-
- Game.Renderer.Fonts["Bold"].DrawText(
- tooltip.Name + (hotkey.IsValid() ? " ({0})".F(hotkey.DisplayString()) : ""),
- p.ToInt2() + new int2(5, 5), Color.White);
-
- var resources = pl.PlayerActor.Trait();
- var power = pl.PlayerActor.Trait();
-
- DrawRightAligned("${0}".F(cost), pos + new int2(-5, 5),
- resources.DisplayCash + resources.DisplayResources >= cost ? Color.White : Color.Red);
-
- var lowpower = power.PowerState != PowerState.Normal;
- var time = currentQueue.GetBuildTime(info.Name)
- * (lowpower ? currentQueue.Info.LowPowerSlowdown : 1);
- DrawRightAligned(WidgetUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red : Color.White);
-
- var pis = info.Traits.WithInterface().Where(i => i.UpgradeMinEnabledLevel < 1);
- var amount = pis.Sum(i => i.Amount);
- if (pis != null)
- DrawRightAligned("{1}{0}".F(amount, amount > 0 ? "+" : ""), pos + new int2(-5, 20),
- ((power.PowerProvided - power.PowerDrained) >= -amount || amount > 0) ? Color.White : Color.Red);
-
- p += new int2(5, 35);
- if (!canBuildThis)
- {
- var prereqs = buildable.Prerequisites.Select(s => Description(world.Map.Rules, s)).Where(s => !s.StartsWith("~"));
- if (prereqs.Any())
- {
- Game.Renderer.Fonts["Regular"].DrawText(RequiresText.F(prereqs.JoinWith(", ")), p.ToInt2(), Color.White);
-
- p += new int2(0, 8);
- }
- }
-
- p += new int2(0, 15);
- Game.Renderer.Fonts["Regular"].DrawText(tooltip.Description.Replace("\\n", "\n"),
- p.ToInt2(), Color.White);
- }
-
- bool DoBuildingHotkey(KeyInput e, World world)
- {
- if (!paletteOpen) return false;
- if (currentQueue == null) return false;
-
- var key = Hotkey.FromKeyInput(e);
- var ks = Game.Settings.Keys;
- var slot = -1;
- for (var i = 0; i < 24; i++)
- {
- if (ks.GetProductionHotkey(i) == key)
- {
- slot = i;
- break;
- }
- }
-
- var allBuildables = currentQueue.AllItems().OrderBy(a => a.Traits.Get().BuildPaletteOrder).ToArray();
- var toBuild = allBuildables.ElementAtOrDefault(slot);
- if (toBuild != null)
- {
- Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
- HandleBuildPalette(world, toBuild.Name, true);
- return true;
- }
-
- return false;
- }
-
- // NOTE: Always return true here to prevent mouse events from passing through the sidebar and interacting with the world behind it.
- bool ChangeTab(bool reverse)
- {
- Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);
- var queues = visibleQueues.Concat(visibleQueues);
- if (reverse)
- queues = queues.Reverse();
- var nextQueue = queues.SkipWhile(q => q != currentQueue)
- .ElementAtOrDefault(1);
- if (nextQueue != null)
- {
- SetCurrentTab(nextQueue);
- return true;
- }
-
- return true;
- }
- }
-}
diff --git a/OpenRA.Mods.D2k/Widgets/Logic/SlidingRadarBinLogic.cs b/OpenRA.Mods.D2k/Widgets/Logic/SlidingRadarBinLogic.cs
deleted file mode 100644
index 44449c709a..0000000000
--- a/OpenRA.Mods.D2k/Widgets/Logic/SlidingRadarBinLogic.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
- * This file is part of OpenRA, which is free software. It is made
- * available to you under the terms of the GNU General Public License
- * as published by the Free Software Foundation. For more information,
- * see COPYING.
- */
-#endregion
-
-using System;
-using System.Drawing;
-using System.Linq;
-using OpenRA.Mods.Common.Traits;
-using OpenRA.Mods.Common.Widgets;
-using OpenRA.Mods.D2k.Widgets;
-using OpenRA.Mods.RA;
-using OpenRA.Mods.RA.Widgets;
-using OpenRA.Mods.RA.Widgets.Logic;
-using OpenRA.Traits;
-using OpenRA.Widgets;
-
-namespace OpenRA.Mods.D2k.Widgets.Logic
-{
- public class SlidingRadarBinLogic
- {
- enum RadarBinState { Closed, BinAnimating, RadarAnimating, Open }
-
- [ObjectCreator.UseCtor]
- public SlidingRadarBinLogic(Widget widget, World world)
- {
- var radarActive = false;
- var binState = RadarBinState.Closed;
- var radarBin = widget.Get("INGAME_RADAR_BIN");
- radarBin.IsOpen = () => radarActive || binState > RadarBinState.BinAnimating;
- radarBin.AfterOpen = () => binState = RadarBinState.RadarAnimating;
- radarBin.AfterClose = () => binState = RadarBinState.Closed;
-
- var radarMap = radarBin.Get("RADAR_MINIMAP");
- radarMap.IsEnabled = () => radarActive && binState >= RadarBinState.RadarAnimating;
- radarMap.AfterOpen = () => binState = RadarBinState.Open;
- radarMap.AfterClose = () => binState = RadarBinState.BinAnimating;
-
- radarBin.Get("RADAR_BIN_BG").GetImageCollection = () => "chrome-" + world.LocalPlayer.Country.Race;
-
- var cachedRadarActive = false;
- var radarTicker = widget.Get("RADAR_TICKER");
- radarTicker.OnTick = () =>
- {
- // Update radar bin
- radarActive = world.ActorsWithTrait()
- .Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
-
- if (radarActive != cachedRadarActive)
- Sound.PlayNotification(world.Map.Rules, null, "Sounds", radarActive ? "RadarUp" : "RadarDown", null);
- cachedRadarActive = radarActive;
- };
- }
- }
-}
diff --git a/OpenRA.Mods.D2k/Widgets/MoneyBinWidget.cs b/OpenRA.Mods.D2k/Widgets/MoneyBinWidget.cs
deleted file mode 100644
index 1d08e73bf5..0000000000
--- a/OpenRA.Mods.D2k/Widgets/MoneyBinWidget.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
- * This file is part of OpenRA, which is free software. It is made
- * available to you under the terms of the GNU General Public License
- * as published by the Free Software Foundation. For more information,
- * see COPYING.
- */
-#endregion
-
-using System.Linq;
-using OpenRA.Graphics;
-using OpenRA.Traits;
-using OpenRA.Widgets;
-
-namespace OpenRA.Mods.D2k.Widgets
-{
- class MoneyBinWidget : Widget
- {
- readonly World world;
- readonly PlayerResources playerResources;
-
- [ObjectCreator.UseCtor]
- public MoneyBinWidget(World world)
- {
- this.world = world;
- playerResources = world.LocalPlayer.PlayerActor.Trait();
- }
-
- public override void Draw()
- {
- if (world.LocalPlayer == null)
- return;
-
- if (world.LocalPlayer.WinState != WinState.Undefined)
- return;
-
- var digitCollection = "digits-" + world.LocalPlayer.Country.Race;
- var chromeCollection = "chrome-" + world.LocalPlayer.Country.Race;
-
- var spriteMoneyBin = ChromeProvider.GetImage(chromeCollection, "moneybin");
-
- if (spriteMoneyBin != null)
- Game.Renderer.RgbaSpriteRenderer.DrawSprite(spriteMoneyBin, new float2(Bounds.Left, 0));
-
- // Cash
- var cashDigits = (playerResources.DisplayCash + playerResources.DisplayResources).ToString();
- var x = Bounds.Right - 65;
-
- foreach (var d in cashDigits.Reverse())
- {
- var spriteDigit = ChromeProvider.GetImage(digitCollection, (d - '0').ToString());
-
- if (spriteDigit != null)
- Game.Renderer.RgbaSpriteRenderer.DrawSprite(spriteDigit, new float2(x, 6));
-
- x -= 14;
- }
- }
- }
-}
diff --git a/OpenRA.Mods.D2k/Widgets/SlidingContainerWidget.cs b/OpenRA.Mods.D2k/Widgets/SlidingContainerWidget.cs
deleted file mode 100644
index 9c59747bde..0000000000
--- a/OpenRA.Mods.D2k/Widgets/SlidingContainerWidget.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
- * This file is part of OpenRA, which is free software. It is made
- * available to you under the terms of the GNU General Public License
- * as published by the Free Software Foundation. For more information,
- * see COPYING.
- */
-#endregion
-
-using System;
-using System.Drawing;
-using OpenRA.Widgets;
-
-namespace OpenRA.Mods.D2k.Widgets
-{
- public class SlidingContainerWidget : Widget
- {
- public int2 OpenOffset = int2.Zero;
- public int2 ClosedOffset = int2.Zero;
- public int AnimationLength = 0;
- public Func IsOpen = () => false;
- public Action AfterOpen = () => { };
- public Action AfterClose = () => { };
-
- int2 offset;
- int frame;
-
- public override void Initialize(WidgetArgs args)
- {
- base.Initialize(args);
-
- // Start in the closed position
- offset = ClosedOffset;
- }
-
- public override void Tick()
- {
- var open = IsOpen();
-
- var targetFrame = open ? AnimationLength : 0;
- if (frame == targetFrame)
- return;
-
- // Update child origin
- frame += open ? 1 : -1;
- offset = int2.Lerp(ClosedOffset, OpenOffset, frame, AnimationLength);
-
- // Animation is complete
- if (frame == targetFrame)
- {
- if (open)
- AfterOpen();
- else
- AfterClose();
- }
- }
-
- public override Rectangle EventBounds { get { return Rectangle.Empty; } }
- public override int2 ChildOrigin { get { return RenderOrigin + offset; } }
- }
-}
diff --git a/OpenRA.Mods.D2k/Widgets/SupportPowerBinWidget.cs b/OpenRA.Mods.D2k/Widgets/SupportPowerBinWidget.cs
deleted file mode 100644
index d94454db27..0000000000
--- a/OpenRA.Mods.D2k/Widgets/SupportPowerBinWidget.cs
+++ /dev/null
@@ -1,184 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
- * This file is part of OpenRA, which is free software. It is made
- * available to you under the terms of the GNU General Public License
- * as published by the Free Software Foundation. For more information,
- * see COPYING.
- */
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using OpenRA.Graphics;
-using OpenRA.Mods.Common.Traits;
-using OpenRA.Primitives;
-using OpenRA.Widgets;
-
-namespace OpenRA.Mods.D2k.Widgets
-{
- class SupportPowerBinWidget : Widget
- {
- [Translate] public string ReadyText = "";
- [Translate] public string HoldText = "";
-
- public int IconWidth = 64;
- public int IconHeight = 48;
-
- readonly List>> buttons = new List>>();
-
- readonly World world;
- readonly WorldRenderer worldRenderer;
-
- Animation icon;
- Animation clock;
-
- [ObjectCreator.UseCtor]
- public SupportPowerBinWidget(World world, WorldRenderer worldRenderer)
- {
- this.world = world;
- this.worldRenderer = worldRenderer;
- }
-
- public override void Initialize(WidgetArgs args)
- {
- base.Initialize(args);
-
- icon = new Animation(world, "icon");
- clock = new Animation(world, "clock");
- }
-
- public override Rectangle EventBounds
- {
- get { return buttons.Any() ? buttons.Select(b => b.First).Aggregate(Rectangle.Union) : Bounds; }
- }
-
- public override bool HandleMouseInput(MouseInput mi)
- {
- if (mi.Event == MouseInputEvent.Down)
- {
- var action = buttons.Where(a => a.First.Contains(mi.Location))
- .Select(a => a.Second).FirstOrDefault();
- if (action == null)
- return false;
-
- action(mi);
- return true;
- }
-
- return false;
- }
-
- public override void Draw()
- {
- buttons.Clear();
-
- if (world.LocalPlayer == null)
- return;
-
- var manager = world.LocalPlayer.PlayerActor.Trait();
- var powers = manager.Powers.Where(p => !p.Value.Disabled);
- var numPowers = powers.Count();
- if (numPowers == 0) return;
-
- var rectBounds = RenderBounds;
- WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"), new float2(rectBounds.X, rectBounds.Y));
- for (var i = 1; i < numPowers; i++)
- WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-middle"), new float2(rectBounds.X, rectBounds.Y + i * 51));
- WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-bottom"), new float2(rectBounds.X, rectBounds.Y + numPowers * 51));
-
- // HACK: Hack Hack Hack
- rectBounds.Width = IconWidth + 5;
- rectBounds.Height = 31 + numPowers * (IconHeight + 3);
-
- var y = rectBounds.Y + 10;
- var iconSize = new float2(IconWidth, IconHeight);
- foreach (var kv in powers)
- {
- var sp = kv.Value;
- icon.Play(sp.Info.Icon);
-
- var drawPos = new float2(rectBounds.X + 5, y);
- var rect = new Rectangle(rectBounds.X + 5, y, 64, 48);
-
- if (rect.Contains(Viewport.LastMousePos))
- {
- var pos = drawPos.ToInt2();
- var tl = new int2(pos.X - 3, pos.Y - 3);
- var m = new int2(pos.X + 64 + 3, pos.Y + 48 + 3);
- var br = tl + new int2(64 + 3 + 20, 40);
-
- if (sp.TotalTime > 0)
- br += new int2(0, 20);
-
- if (sp.Info.LongDesc != null)
- br += Game.Renderer.Fonts["Regular"].Measure(sp.Info.LongDesc.Replace("\\n", "\n"));
- else
- br += new int2(300, 0);
-
- var border = WidgetUtils.GetBorderSizes("dialog4");
-
- WidgetUtils.DrawPanelPartial("dialog4", Rectangle.FromLTRB(tl.X, tl.Y, m.X + border[3], m.Y),
- PanelSides.Left | PanelSides.Top | PanelSides.Bottom | PanelSides.Center);
- WidgetUtils.DrawPanelPartial("dialog4", Rectangle.FromLTRB(m.X - border[2], tl.Y, br.X, m.Y + border[1]),
- PanelSides.Top | PanelSides.Right | PanelSides.Center);
- WidgetUtils.DrawPanelPartial("dialog4", Rectangle.FromLTRB(m.X, m.Y - border[1], br.X, br.Y),
- PanelSides.Left | PanelSides.Right | PanelSides.Bottom | PanelSides.Center);
-
- pos += new int2(77, 5);
- Game.Renderer.Fonts["Bold"].DrawText(sp.Info.Description, pos, Color.White);
-
- if (sp.TotalTime > 0)
- {
- pos += new int2(0, 20);
- Game.Renderer.Fonts["Bold"].DrawText(WidgetUtils.FormatTime(sp.RemainingTime), pos, Color.White);
- Game.Renderer.Fonts["Bold"].DrawText("/ {0}".F(WidgetUtils.FormatTime(sp.TotalTime)), pos + new int2(45, 0), Color.White);
- }
-
- if (sp.Info.LongDesc != null)
- {
- pos += new int2(0, 20);
- Game.Renderer.Fonts["Regular"].DrawText(sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White);
- }
- }
-
- WidgetUtils.DrawSHPCentered(icon.Image, drawPos + 0.5f * iconSize, worldRenderer);
-
- clock.PlayFetchIndex("idle",
- () => sp.TotalTime == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTime - sp.RemainingTime)
- * (clock.CurrentSequence.Length - 1) / sp.TotalTime);
- clock.Tick();
-
- WidgetUtils.DrawSHPCentered(clock.Image, drawPos + 0.5f * iconSize, worldRenderer);
-
- var overlay = sp.Ready ? ReadyText : sp.Active ? null : HoldText;
- var font = Game.Renderer.Fonts["TinyBold"];
- if (overlay != null)
- {
- var size = font.Measure(overlay);
- var overlayPos = drawPos + new float2(32, 16);
- font.DrawTextWithContrast(overlay, overlayPos - new float2(size.X / 2, 0), Color.White, Color.Black, 1);
- }
-
- buttons.Add(Pair.New(rect, HandleSupportPower(kv.Key, manager)));
-
- y += 51;
- }
- }
-
- static Action HandleSupportPower(string key, SupportPowerManager manager)
- {
- return mi =>
- {
- if (mi.Button == MouseButton.Left)
- {
- if (!manager.Powers[key].Active)
- Sound.PlayToPlayer(manager.Self.Owner, manager.Powers[key].Info.InsufficientPowerSound);
- manager.Target(key);
- }
- };
- }
- }
-}
\ No newline at end of file