Moved the graph widget into OpenRA.Game - it doesn't really have any dependencies on the RA mod
This commit is contained in:
@@ -192,6 +192,7 @@
|
|||||||
<Compile Include="Widgets\ChromeMetrics.cs" />
|
<Compile Include="Widgets\ChromeMetrics.cs" />
|
||||||
<Compile Include="Widgets\ColorBlockWidget.cs" />
|
<Compile Include="Widgets\ColorBlockWidget.cs" />
|
||||||
<Compile Include="Widgets\DropDownButtonWidget.cs" />
|
<Compile Include="Widgets\DropDownButtonWidget.cs" />
|
||||||
|
<Compile Include="Widgets\GraphWidget.cs" />
|
||||||
<Compile Include="Widgets\GridLayout.cs" />
|
<Compile Include="Widgets\GridLayout.cs" />
|
||||||
<Compile Include="Widgets\ImageWidget.cs" />
|
<Compile Include="Widgets\ImageWidget.cs" />
|
||||||
<Compile Include="Widgets\LabelWidget.cs" />
|
<Compile Include="Widgets\LabelWidget.cs" />
|
||||||
|
|||||||
@@ -16,10 +16,9 @@ using OpenRA.FileFormats;
|
|||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
public class ObserverStatsGraphWidget : Widget
|
public class GraphWidget : Widget
|
||||||
{
|
{
|
||||||
public Func<IEnumerable<Pair<Player, IEnumerable<float>>>> GetDataSource;
|
public Func<IEnumerable<Pair<Player, IEnumerable<float>>>> GetDataSource;
|
||||||
public Func<float> GetDataScale;
|
|
||||||
public Func<string> GetValueFormat;
|
public Func<string> GetValueFormat;
|
||||||
public Func<string> GetXAxisValueFormat;
|
public Func<string> GetXAxisValueFormat;
|
||||||
public Func<string> GetYAxisValueFormat;
|
public Func<string> GetYAxisValueFormat;
|
||||||
@@ -27,7 +26,9 @@ namespace OpenRA.Widgets
|
|||||||
public Func<int> GetYAxisSize;
|
public Func<int> GetYAxisSize;
|
||||||
public Func<string> GetXAxisLabel;
|
public Func<string> GetXAxisLabel;
|
||||||
public Func<string> GetYAxisLabel;
|
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 ValueFormat = "{0}";
|
||||||
public string XAxisValueFormat = "{0}";
|
public string XAxisValueFormat = "{0}";
|
||||||
public string YAxisValueFormat = "{0}";
|
public string YAxisValueFormat = "{0}";
|
||||||
@@ -35,9 +36,11 @@ namespace OpenRA.Widgets
|
|||||||
public int YAxisSize = 10;
|
public int YAxisSize = 10;
|
||||||
public string XAxisLabel = "";
|
public string XAxisLabel = "";
|
||||||
public string YAxisLabel = "";
|
public string YAxisLabel = "";
|
||||||
public bool DisplayYAxisZero = true;
|
public bool DisplayFirstYAxisValue = false;
|
||||||
|
public string LabelFont;
|
||||||
|
public string AxisFont;
|
||||||
|
|
||||||
public ObserverStatsGraphWidget()
|
public GraphWidget()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
GetValueFormat = () => ValueFormat;
|
GetValueFormat = () => ValueFormat;
|
||||||
@@ -47,10 +50,12 @@ namespace OpenRA.Widgets
|
|||||||
GetYAxisSize = () => YAxisSize;
|
GetYAxisSize = () => YAxisSize;
|
||||||
GetXAxisLabel = () => XAxisLabel;
|
GetXAxisLabel = () => XAxisLabel;
|
||||||
GetYAxisLabel = () => YAxisLabel;
|
GetYAxisLabel = () => YAxisLabel;
|
||||||
GetDisplayYAxisZero = () => DisplayYAxisZero;
|
GetDisplayFirstYAxisValue = () => DisplayFirstYAxisValue;
|
||||||
|
GetLabelFont = () => LabelFont;
|
||||||
|
GetAxisFont = () => AxisFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObserverStatsGraphWidget(ObserverStatsGraphWidget other)
|
protected GraphWidget(GraphWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
GetDataSource = other.GetDataSource;
|
GetDataSource = other.GetDataSource;
|
||||||
@@ -61,7 +66,9 @@ namespace OpenRA.Widgets
|
|||||||
GetYAxisSize = other.GetYAxisSize;
|
GetYAxisSize = other.GetYAxisSize;
|
||||||
GetXAxisLabel = other.GetXAxisLabel;
|
GetXAxisLabel = other.GetXAxisLabel;
|
||||||
GetYAxisLabel = other.GetYAxisLabel;
|
GetYAxisLabel = other.GetYAxisLabel;
|
||||||
GetDisplayYAxisZero = other.GetDisplayYAxisZero;
|
GetDisplayFirstYAxisValue = other.GetDisplayFirstYAxisValue;
|
||||||
|
GetLabelFont = other.GetLabelFont;
|
||||||
|
GetAxisFont = other.GetAxisFont;
|
||||||
ValueFormat = other.ValueFormat;
|
ValueFormat = other.ValueFormat;
|
||||||
XAxisValueFormat = other.XAxisValueFormat;
|
XAxisValueFormat = other.XAxisValueFormat;
|
||||||
YAxisValueFormat = other.YAxisValueFormat;
|
YAxisValueFormat = other.YAxisValueFormat;
|
||||||
@@ -69,12 +76,16 @@ namespace OpenRA.Widgets
|
|||||||
YAxisSize = other.YAxisSize;
|
YAxisSize = other.YAxisSize;
|
||||||
XAxisLabel = other.XAxisLabel;
|
XAxisLabel = other.XAxisLabel;
|
||||||
YAxisLabel = other.YAxisLabel;
|
YAxisLabel = other.YAxisLabel;
|
||||||
DisplayYAxisZero = other.DisplayYAxisZero;
|
DisplayFirstYAxisValue = other.DisplayFirstYAxisValue;
|
||||||
|
LabelFont = other.LabelFont;
|
||||||
|
AxisFont = other.AxisFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
if (GetDataSource == null || !GetDataSource().Any())
|
if (GetDataSource == null || !GetDataSource().Any()
|
||||||
|
|| GetLabelFont == null || GetLabelFont() == null
|
||||||
|
|| GetAxisFont == null || GetAxisFont() == null)
|
||||||
{
|
{
|
||||||
return;
|
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(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);
|
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 tiny = Game.Renderer.Fonts[GetLabelFont()];
|
||||||
var bold = Game.Renderer.Fonts["Bold"];
|
var bold = Game.Renderer.Fonts[GetAxisFont()];
|
||||||
|
|
||||||
var xAxisSize = GetXAxisSize();
|
var xAxisSize = GetXAxisSize();
|
||||||
var yAxisSize = GetYAxisSize();
|
var yAxisSize = GetYAxisSize();
|
||||||
@@ -109,15 +120,15 @@ namespace OpenRA.Widgets
|
|||||||
for (int n = visibleNodeStart, x = 0; n <= visibleNodeEnd; n++, x += xStep)
|
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);
|
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);
|
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;
|
var value = y / scale;
|
||||||
Game.Renderer.LineRenderer.DrawLine(origin + new float2(width - 5, -y), origin + new float2(width, -y), Color.White, Color.White);
|
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);
|
bold.DrawText(GetYAxisLabel(), origin + new float2(width + 40, -(height / 2)), Color.White);
|
||||||
|
|
||||||
@@ -146,18 +157,18 @@ namespace OpenRA.Widgets
|
|||||||
if (value != 0)
|
if (value != 0)
|
||||||
{
|
{
|
||||||
var scaledValue = value * scale;
|
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++;
|
playerNameOffset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone()
|
||||||
{
|
{
|
||||||
return new ObserverStatsGraphWidget(this);
|
return new GraphWidget(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,7 +384,6 @@
|
|||||||
<Compile Include="Widgets\Logic\SettingsMenuLogic.cs" />
|
<Compile Include="Widgets\Logic\SettingsMenuLogic.cs" />
|
||||||
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
||||||
<Compile Include="Widgets\ObserverProductionIconsWidget.cs" />
|
<Compile Include="Widgets\ObserverProductionIconsWidget.cs" />
|
||||||
<Compile Include="Widgets\ObserverStatsGraphWidget.cs" />
|
|
||||||
<Compile Include="Widgets\ObserverSupportPowerIconsWidget.cs" />
|
<Compile Include="Widgets\ObserverSupportPowerIconsWidget.cs" />
|
||||||
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
||||||
<Compile Include="Widgets\PowerBinWidget.cs" />
|
<Compile Include="Widgets\PowerBinWidget.cs" />
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
earnedThisMinuteGraphHeaders.Visible = true;
|
earnedThisMinuteGraphHeaders.Visible = true;
|
||||||
var template = earnedThisMinuteGraphTemplate.Clone();
|
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)));
|
graph.GetDataSource = () => players.Select(p => Pair.New(p, p.PlayerActor.Trait<PlayerStatistics>().EarnedSamples.Select(s => (float)s)));
|
||||||
|
|
||||||
playerStatsPanel.AddChild(template);
|
playerStatsPanel.AddChild(template);
|
||||||
|
|||||||
@@ -865,7 +865,7 @@ Container@OBSERVER_ROOT:
|
|||||||
Width:PARENT_RIGHT-100
|
Width:PARENT_RIGHT-100
|
||||||
Height:PARENT_BOTTOM-50
|
Height:PARENT_BOTTOM-50
|
||||||
Children:
|
Children:
|
||||||
ObserverStatsGraph@EARNED_THIS_MIN_GRAPH:
|
Graph@EARNED_THIS_MIN_GRAPH:
|
||||||
X:0
|
X:0
|
||||||
Y:0
|
Y:0
|
||||||
Width:PARENT_RIGHT
|
Width:PARENT_RIGHT
|
||||||
@@ -878,6 +878,8 @@ Container@OBSERVER_ROOT:
|
|||||||
XAxisLabel:m
|
XAxisLabel:m
|
||||||
YAxisLabel:$
|
YAxisLabel:$
|
||||||
DisplayYAxisZero:false
|
DisplayYAxisZero:false
|
||||||
|
LabelFont:TinyBold
|
||||||
|
AxisFont:Bold
|
||||||
Background@FMVPLAYER:
|
Background@FMVPLAYER:
|
||||||
Width:WINDOW_RIGHT
|
Width:WINDOW_RIGHT
|
||||||
Height:WINDOW_BOTTOM
|
Height:WINDOW_BOTTOM
|
||||||
|
|||||||
Reference in New Issue
Block a user