Kill PowerBarWidget. Fixes #3446.

This commit is contained in:
Paul Chote
2013-07-04 22:02:02 +12:00
parent 6fa4e54022
commit f8313672ff
15 changed files with 221 additions and 236 deletions

View File

@@ -125,11 +125,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
siloBar.GetProvided = () => playerResources.OreCapacity;
siloBar.GetUsed = () => playerResources.Ore;
siloBar.TooltipFormat = "Silo Usage: {0}/{1}";
siloBar.RightIndicator = true;
siloBar.GetBarColor = () =>
{
if (playerResources.Ore == playerResources.OreCapacity) return Color.Red;
if (playerResources.Ore >= 0.8 * playerResources.OreCapacity) return Color.Orange;
if (playerResources.Ore == playerResources.OreCapacity)
return Color.Red;
if (playerResources.Ore >= 0.8 * playerResources.OreCapacity)
return Color.Orange;
return Color.LimeGreen;
};
@@ -137,11 +138,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
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;
if (powerManager.PowerState == PowerState.Critical)
return Color.Red;
if (powerManager.PowerState == PowerState.Low)
return Color.Orange;
return Color.LimeGreen;
};
}

View File

@@ -1,41 +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 OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets.Logic
{
public class SimpleTooltipLogic
{
[ObjectCreator.UseCtor]
public SimpleTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Func<string> getText)
{
var label = widget.Get<LabelWidget>("LABEL");
var font = Game.Renderer.Fonts[label.Font];
var cachedWidth = 0;
var labelText = "";
tooltipContainer.BeforeRender = () =>
{
labelText = getText();
var textWidth = font.Measure(labelText).X;
if (textWidth != cachedWidth)
{
label.Bounds.Width = textWidth;
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
}
};
label.GetText = () => labelText;
}
}
}

View File

@@ -1,84 +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.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets
{
public class ResourceBarWidget : Widget
{
public readonly string TooltipTemplate = "SIMPLE_TOOLTIP";
public readonly string TooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
public float LowStorageThreshold = 0.8f;
EWMA providedLerp = new EWMA(0.3f);
EWMA usedLerp = new EWMA(0.3f);
public Func<float> GetProvided = () => 0;
public Func<float> GetUsed = () => 0;
public string TooltipFormat = "";
public bool RightIndicator = false;
public Func<Color> GetBarColor = () => Color.White;
[ObjectCreator.UseCtor]
public ResourceBarWidget(World world)
{
tooltipContainer = Lazy.New(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
public override void MouseEntered()
{
if (TooltipContainer == null) return;
Func<string> getText = () => TooltipFormat.F(GetUsed(), GetProvided());
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "getText", getText }});
}
public override void MouseExited()
{
if (TooltipContainer == null) return;
tooltipContainer.Value.RemoveTooltip();
}
public override void Draw()
{
var scaleBy = 100.0f;
var provided = GetProvided();
var used = GetUsed();
var max = Math.Max(provided, used);
while (max >= scaleBy) scaleBy *= 2;
var providedFrac = providedLerp.Update(provided/scaleBy);
var usedFrac = usedLerp.Update(used/scaleBy);
var color = GetBarColor();
var b = RenderBounds;
var rect = new RectangleF(b.X, float2.Lerp( b.Bottom, b.Top, providedFrac ),
b.Width, providedFrac*b.Height);
Game.Renderer.LineRenderer.FillRect(rect, color);
var indicator = ChromeProvider.GetImage("sidebar-bits",
RightIndicator ? "right-indicator" : "left-indicator");
var indicatorX = RightIndicator ? (b.Right - indicator.size.X) : b.Left;
var pos = new float2(indicatorX, float2.Lerp( b.Bottom, b.Top, usedFrac ) - indicator.size.Y / 2);
Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, pos);
}
}
}