From 3e81a4bd7080b185eb164d23a0abf9c9c6e3e684 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 25 Sep 2012 19:51:03 +1200 Subject: [PATCH] remove PowerBarWidget entirely --- OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj | 1 - .../Widgets/Logic/CncIngameChromeLogic.cs | 14 +++ OpenRA.Mods.Cnc/Widgets/PowerBarWidget.cs | 87 ------------------- mods/cnc/chrome/ingame.yaml | 4 +- 4 files changed, 16 insertions(+), 90 deletions(-) delete mode 100755 OpenRA.Mods.Cnc/Widgets/PowerBarWidget.cs diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 4c4da7cdad..ad7f2da5d9 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -107,7 +107,6 @@ - diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index 63339018b2..5a97160f96 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -11,6 +11,7 @@ using System; using System.Drawing; using OpenRA.Mods.RA.Orders; +using OpenRA.Mods.RA.Buildings; using OpenRA.Traits; using OpenRA.Widgets; @@ -114,6 +115,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic BindOrderButton(world, sidebarRoot, "SELL_BUTTON", "sell"); BindOrderButton(world, sidebarRoot, "REPAIR_BUTTON", "repair"); + var powerManager = world.LocalPlayer.PlayerActor.Trait(); var playerResources = world.LocalPlayer.PlayerActor.Trait(); sidebarRoot.Get("CASH").GetText = () => "${0}".F(playerResources.DisplayCash + playerResources.DisplayOre); @@ -164,6 +166,18 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic if (playerResources.Ore >= 0.8 * playerResources.OreCapacity) return Color.Orange; return Color.LimeGreen; }; + + var powerBar = playerWidgets.Get("POWERBAR"); + powerBar.GetProvided = () => powerManager.PowerProvided; + powerBar.GetUsed = () => powerManager.PowerDrained; + powerBar.TooltipFormat = "Power Usage: {0}/{1}"; + powerBar.RightIndicator = false; + powerBar.GetBarColor = () => + { + if (powerManager.PowerState == PowerState.Critical) return Color.Red; + if (powerManager.PowerState == PowerState.Low) return Color.Orange; + return Color.LimeGreen; + }; } static void BindOrderButton(World world, Widget parent, string button, string icon) diff --git a/OpenRA.Mods.Cnc/Widgets/PowerBarWidget.cs b/OpenRA.Mods.Cnc/Widgets/PowerBarWidget.cs deleted file mode 100755 index f237f3c86b..0000000000 --- a/OpenRA.Mods.Cnc/Widgets/PowerBarWidget.cs +++ /dev/null @@ -1,87 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 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.FileFormats; -using OpenRA.Graphics; -using OpenRA.Mods.RA.Buildings; -using OpenRA.Widgets; - -namespace OpenRA.Mods.Cnc.Widgets -{ - public class PowerBarWidget : Widget - { - public readonly string TooltipTemplate = "SIMPLE_TOOLTIP"; - public readonly string TooltipContainer; - Lazy tooltipContainer; - - float? lastProvidedFrac; - float? lastDrainedFrac; - readonly PowerManager pm; - - [ObjectCreator.UseCtor] - public PowerBarWidget(World world) - { - pm = world.LocalPlayer.PlayerActor.Trait(); - tooltipContainer = Lazy.New(() => - Ui.Root.Get(TooltipContainer)); - } - - public override void MouseEntered() - { - if (TooltipContainer == null) return; - Func getText = () => "Power Usage: {0}/{1}".F(pm.PowerDrained, pm.PowerProvided); - tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "getText", getText }}); - } - - public override void MouseExited() - { - if (TooltipContainer == null) return; - tooltipContainer.Value.RemoveTooltip(); - } - - public override void Draw() - { - float powerScaleBy = 100; - var maxPower = Math.Max(pm.PowerProvided, pm.PowerDrained); - while (maxPower >= powerScaleBy) powerScaleBy *= 2; - var animRate = .3f; - - // Current power supply - var providedFrac = pm.PowerProvided / powerScaleBy; - lastProvidedFrac = providedFrac = float2.Lerp(lastProvidedFrac.GetValueOrDefault(providedFrac), providedFrac, animRate); - - var color = GetBarColor(); - - var b = RenderBounds; - var rect = new RectangleF(b.X, float2.Lerp(b.Bottom, b.Top, providedFrac), - (float)b.Width, providedFrac*b.Height); - Game.Renderer.LineRenderer.FillRect(rect, color); - - var indicator = ChromeProvider.GetImage("sidebar-bits", "left-indicator"); - - var drainedFrac = pm.PowerDrained / powerScaleBy; - lastDrainedFrac = drainedFrac = float2.Lerp(lastDrainedFrac.GetValueOrDefault(drainedFrac), drainedFrac, animRate); - - float2 pos = new float2(b.X + b.Width - indicator.size.X, - float2.Lerp(b.Bottom, b.Top, drainedFrac)); - - Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, pos); - } - - Color GetBarColor() - { - if (pm.PowerState == PowerState.Critical) return Color.Red; - if (pm.PowerState == PowerState.Low) return Color.Orange; - return Color.LimeGreen; - } - } -} diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index e7a8eeb7b6..7b5ec7b0a5 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -150,14 +150,14 @@ Container@PLAYER_WIDGETS: Width:PARENT_RIGHT-2 Height:PARENT_BOTTOM-2 WorldInteractionController:INTERACTION_CONTROLLER - Background@POWERBAR: + Background@POWERBAR_PANEL: X:4 Y:5 Width:10 Height:168 Background:panel-black Children: - PowerBar: + ResourceBar@POWERBAR: X:1 Y:1 Width:PARENT_RIGHT-2