Moved the graph widget into OpenRA.Game - it doesn't really have any dependencies on the RA mod

This commit is contained in:
Scott_NZ
2012-11-27 20:16:00 +13:00
parent d5b37d4343
commit a78f8865b8
5 changed files with 34 additions and 21 deletions

View File

@@ -192,6 +192,7 @@
<Compile Include="Widgets\ChromeMetrics.cs" />
<Compile Include="Widgets\ColorBlockWidget.cs" />
<Compile Include="Widgets\DropDownButtonWidget.cs" />
<Compile Include="Widgets\GraphWidget.cs" />
<Compile Include="Widgets\GridLayout.cs" />
<Compile Include="Widgets\ImageWidget.cs" />
<Compile Include="Widgets\LabelWidget.cs" />

View File

@@ -16,10 +16,9 @@ using OpenRA.FileFormats;
namespace OpenRA.Widgets
{
public class ObserverStatsGraphWidget : Widget
public class GraphWidget : Widget
{
public Func<IEnumerable<Pair<Player, IEnumerable<float>>>> GetDataSource;
public Func<float> GetDataScale;
public Func<string> GetValueFormat;
public Func<string> GetXAxisValueFormat;
public Func<string> GetYAxisValueFormat;
@@ -27,7 +26,9 @@ namespace OpenRA.Widgets
public Func<int> GetYAxisSize;
public Func<string> GetXAxisLabel;
public Func<string> GetYAxisLabel;
public Func<bool> GetDisplayYAxisZero;
public Func<bool> GetDisplayFirstYAxisValue;
public Func<string> GetLabelFont;
public Func<string> GetAxisFont;
public string ValueFormat = "{0}";
public string XAxisValueFormat = "{0}";
public string YAxisValueFormat = "{0}";
@@ -35,9 +36,11 @@ namespace OpenRA.Widgets
public int YAxisSize = 10;
public string XAxisLabel = "";
public string YAxisLabel = "";
public bool DisplayYAxisZero = true;
public bool DisplayFirstYAxisValue = false;
public string LabelFont;
public string AxisFont;
public ObserverStatsGraphWidget()
public GraphWidget()
: base()
{
GetValueFormat = () => ValueFormat;
@@ -47,10 +50,12 @@ namespace OpenRA.Widgets
GetYAxisSize = () => YAxisSize;
GetXAxisLabel = () => XAxisLabel;
GetYAxisLabel = () => YAxisLabel;
GetDisplayYAxisZero = () => DisplayYAxisZero;
GetDisplayFirstYAxisValue = () => DisplayFirstYAxisValue;
GetLabelFont = () => LabelFont;
GetAxisFont = () => AxisFont;
}
protected ObserverStatsGraphWidget(ObserverStatsGraphWidget other)
protected GraphWidget(GraphWidget other)
: base(other)
{
GetDataSource = other.GetDataSource;
@@ -61,7 +66,9 @@ namespace OpenRA.Widgets
GetYAxisSize = other.GetYAxisSize;
GetXAxisLabel = other.GetXAxisLabel;
GetYAxisLabel = other.GetYAxisLabel;
GetDisplayYAxisZero = other.GetDisplayYAxisZero;
GetDisplayFirstYAxisValue = other.GetDisplayFirstYAxisValue;
GetLabelFont = other.GetLabelFont;
GetAxisFont = other.GetAxisFont;
ValueFormat = other.ValueFormat;
XAxisValueFormat = other.XAxisValueFormat;
YAxisValueFormat = other.YAxisValueFormat;
@@ -69,12 +76,16 @@ namespace OpenRA.Widgets
YAxisSize = other.YAxisSize;
XAxisLabel = other.XAxisLabel;
YAxisLabel = other.YAxisLabel;
DisplayYAxisZero = other.DisplayYAxisZero;
DisplayFirstYAxisValue = other.DisplayFirstYAxisValue;
LabelFont = other.LabelFont;
AxisFont = other.AxisFont;
}
public override void Draw()
{
if (GetDataSource == null || !GetDataSource().Any())
if (GetDataSource == null || !GetDataSource().Any()
|| GetLabelFont == null || GetLabelFont() == null
|| GetAxisFont == null || GetAxisFont() == null)
{
return;
}
@@ -89,8 +100,8 @@ namespace OpenRA.Widgets
Game.Renderer.LineRenderer.DrawLine(origin + new float2(width, 0), origin + new float2(width, -height), Color.White, Color.White);
Game.Renderer.LineRenderer.DrawLine(origin + new float2(0, -height), origin + new float2(width, -height), Color.White, Color.White);
var tinyBold = Game.Renderer.Fonts["TinyBold"];
var bold = Game.Renderer.Fonts["Bold"];
var tiny = Game.Renderer.Fonts[GetLabelFont()];
var bold = Game.Renderer.Fonts[GetAxisFont()];
var xAxisSize = GetXAxisSize();
var yAxisSize = GetYAxisSize();
@@ -109,15 +120,15 @@ namespace OpenRA.Widgets
for (int n = visibleNodeStart, x = 0; n <= visibleNodeEnd; n++, x += xStep)
{
Game.Renderer.LineRenderer.DrawLine(origin + new float2(x, 0), origin + new float2(x, -5), Color.White, Color.White);
tinyBold.DrawText(GetXAxisValueFormat().F(n), origin + new float2(x, 2), Color.White);
tiny.DrawText(GetXAxisValueFormat().F(n), origin + new float2(x, 2), Color.White);
}
bold.DrawText(GetXAxisLabel(), origin + new float2(width / 2, 20), Color.White);
for (var y = (GetDisplayYAxisZero() ? 0f : yStep); y <= height; y += yStep)
for (var y = (GetDisplayFirstYAxisValue() ? 0f : yStep); y <= height; y += yStep)
{
var value = y / scale;
Game.Renderer.LineRenderer.DrawLine(origin + new float2(width - 5, -y), origin + new float2(width, -y), Color.White, Color.White);
tinyBold.DrawText(GetYAxisValueFormat().F(value), origin + new float2(width + 2, -y), Color.White);
tiny.DrawText(GetYAxisValueFormat().F(value), origin + new float2(width + 2, -y), Color.White);
}
bold.DrawText(GetYAxisLabel(), origin + new float2(width + 40, -(height / 2)), Color.White);
@@ -146,18 +157,18 @@ namespace OpenRA.Widgets
if (value != 0)
{
var scaledValue = value * scale;
tinyBold.DrawText(GetValueFormat().F(value), origin + new float2(x, -scaledValue - 2), color);
tiny.DrawText(GetValueFormat().F(value), origin + new float2(x, -scaledValue - 2), color);
}
}
tinyBold.DrawText(player.PlayerName, new float2(rect.Left, rect.Top) + new float2(5, 10 * playerNameOffset + 3), color);
tiny.DrawText(player.PlayerName, new float2(rect.Left, rect.Top) + new float2(5, 10 * playerNameOffset + 3), color);
playerNameOffset++;
}
}
public override Widget Clone()
{
return new ObserverStatsGraphWidget(this);
return new GraphWidget(this);
}
}
}

View File

@@ -384,7 +384,6 @@
<Compile Include="Widgets\Logic\SettingsMenuLogic.cs" />
<Compile Include="Widgets\MoneyBinWidget.cs" />
<Compile Include="Widgets\ObserverProductionIconsWidget.cs" />
<Compile Include="Widgets\ObserverStatsGraphWidget.cs" />
<Compile Include="Widgets\ObserverSupportPowerIconsWidget.cs" />
<Compile Include="Widgets\OrderButtonWidget.cs" />
<Compile Include="Widgets\PowerBinWidget.cs" />

View File

@@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
earnedThisMinuteGraphHeaders.Visible = true;
var template = earnedThisMinuteGraphTemplate.Clone();
var graph = template.Get<ObserverStatsGraphWidget>("EARNED_THIS_MIN_GRAPH");
var graph = template.Get<GraphWidget>("EARNED_THIS_MIN_GRAPH");
graph.GetDataSource = () => players.Select(p => Pair.New(p, p.PlayerActor.Trait<PlayerStatistics>().EarnedSamples.Select(s => (float)s)));
playerStatsPanel.AddChild(template);

View File

@@ -865,7 +865,7 @@ Container@OBSERVER_ROOT:
Width:PARENT_RIGHT-100
Height:PARENT_BOTTOM-50
Children:
ObserverStatsGraph@EARNED_THIS_MIN_GRAPH:
Graph@EARNED_THIS_MIN_GRAPH:
X:0
Y:0
Width:PARENT_RIGHT
@@ -878,6 +878,8 @@ Container@OBSERVER_ROOT:
XAxisLabel:m
YAxisLabel:$
DisplayYAxisZero:false
LabelFont:TinyBold
AxisFont:Bold
Background@FMVPLAYER:
Width:WINDOW_RIGHT
Height:WINDOW_BOTTOM