Updated the LineGraphWidget with new layout
This commit is contained in:
@@ -42,6 +42,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public string AxisFont;
|
||||
public Color BackgroundColorDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
|
||||
public Color BackgroundColorLight = ChromeMetrics.Get<Color>("TextContrastColorLight");
|
||||
public int Padding = 5;
|
||||
|
||||
public LineGraphWidget()
|
||||
{
|
||||
@@ -83,31 +84,46 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
AxisFont = other.AxisFont;
|
||||
BackgroundColorDark = other.BackgroundColorDark;
|
||||
BackgroundColorLight = other.BackgroundColorLight;
|
||||
Padding = other.Padding;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (GetSeries == null || !GetSeries().Any()
|
||||
|| GetLabelFont == null || GetLabelFont() == null
|
||||
|| GetAxisFont == null || GetAxisFont() == null)
|
||||
|| GetLabelFont == null || GetLabelFont() == null)
|
||||
return;
|
||||
|
||||
var cr = Game.Renderer.RgbaColorRenderer;
|
||||
var rect = RenderBounds;
|
||||
var origin = new float2(rect.Left, rect.Bottom);
|
||||
|
||||
var width = rect.Width;
|
||||
var height = rect.Height;
|
||||
|
||||
var tiny = Game.Renderer.Fonts[GetLabelFont()];
|
||||
var bold = Game.Renderer.Fonts[GetAxisFont()];
|
||||
var labelFont = Game.Renderer.Fonts[GetLabelFont()];
|
||||
var axisFont = Game.Renderer.Fonts[GetAxisFont()];
|
||||
|
||||
var xAxisSize = GetXAxisSize();
|
||||
var yAxisSize = GetYAxisSize();
|
||||
|
||||
var xAxisLabel = GetXAxisLabel();
|
||||
var xAxisLabelSize = axisFont.Measure(xAxisLabel);
|
||||
|
||||
var xAxisPointLabelHeight = labelFont.Measure("0").Y;
|
||||
|
||||
var graphBottomOffset = Padding * 2 + xAxisLabelSize.Y + xAxisPointLabelHeight;
|
||||
var height = rect.Height - (graphBottomOffset + Padding);
|
||||
|
||||
var maxValue = GetSeries().Select(p => p.Points).SelectMany(d => d).Concat(new[] { 0f }).Max();
|
||||
var longestName = GetSeries().Select(s => s.Key).OrderByDescending(s => s.Length).FirstOrDefault() ?? "";
|
||||
|
||||
var scale = 200 / Math.Max(5000, (float)Math.Ceiling(maxValue / 1000) * 1000);
|
||||
|
||||
var widthMaxValue = labelFont.Measure(GetYAxisValueFormat().F(height / scale)).X;
|
||||
var widthLongestName = labelFont.Measure(longestName).X;
|
||||
|
||||
// y axis label
|
||||
var yAxisLabel = GetYAxisLabel();
|
||||
var yAxisLabelSize = axisFont.Measure(yAxisLabel);
|
||||
|
||||
var width = rect.Width - (Padding * 4 + widthMaxValue + widthLongestName + yAxisLabelSize.Y);
|
||||
|
||||
var xStep = width / xAxisSize;
|
||||
var yStep = height / yAxisSize;
|
||||
|
||||
@@ -115,6 +131,10 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var pointStart = Math.Max(0, pointCount - xAxisSize);
|
||||
var pointEnd = Math.Max(pointCount, xAxisSize);
|
||||
|
||||
var graphOrigin = new float2(rect.Left, rect.Bottom) + new float2(Padding * 2 + widthMaxValue + yAxisLabelSize.Y, -graphBottomOffset);
|
||||
|
||||
var origin = new float2(rect.Left, rect.Bottom);
|
||||
|
||||
var keyOffset = 0;
|
||||
foreach (var series in GetSeries())
|
||||
{
|
||||
@@ -131,41 +151,53 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
lastX = x;
|
||||
lastPoint = point;
|
||||
return origin + new float3(x * xStep, -point * scale, 0);
|
||||
return graphOrigin + new float3(x * xStep, -point * scale, 0);
|
||||
}), 1, color);
|
||||
|
||||
if (lastPoint != 0f)
|
||||
tiny.DrawTextWithShadow(GetValueFormat().F(lastPoint), origin + new float2(lastX * xStep, -lastPoint * scale - 2),
|
||||
labelFont.DrawTextWithShadow(GetValueFormat().F(lastPoint), graphOrigin + new float2(lastX * xStep, -lastPoint * scale - 2),
|
||||
color, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
}
|
||||
|
||||
tiny.DrawTextWithShadow(key, new float2(rect.Left, rect.Top) + new float2(5, 10 * keyOffset + 3),
|
||||
labelFont.DrawTextWithShadow(key, new float2(rect.Right, rect.Top) + new float2(-(widthLongestName + Padding), 10 * keyOffset + 3),
|
||||
color, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
keyOffset++;
|
||||
}
|
||||
|
||||
// Draw x axis
|
||||
axisFont.DrawTextWithShadow(xAxisLabel, new float2(graphOrigin.X, origin.Y) + new float2(width / 2 - xAxisLabelSize.X / 2, -(xAxisLabelSize.Y + Padding)), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
|
||||
// TODO: make this stuff not draw outside of the RenderBounds
|
||||
for (int n = pointStart, x = 0; n <= pointEnd; n++, x += xStep)
|
||||
{
|
||||
cr.DrawLine(origin + new float2(x, 0), origin + new float2(x, -5), 1, Color.White);
|
||||
tiny.DrawTextWithShadow(GetXAxisValueFormat().F(n), origin + new float2(x, 2), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
cr.DrawLine(graphOrigin + new float2(x, 0), graphOrigin + new float2(x, -5), 1, Color.White);
|
||||
var xAxisText = GetXAxisValueFormat().F(n);
|
||||
var xAxisTickTextWidth = labelFont.Measure(xAxisText).X;
|
||||
var xLocation = x - (xAxisTickTextWidth / 2);
|
||||
labelFont.DrawTextWithShadow(xAxisText, graphOrigin + new float2(xLocation, 2), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
}
|
||||
|
||||
bold.DrawTextWithShadow(GetXAxisLabel(), origin + new float2(width / 2, 20), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
// Draw y axis
|
||||
axisFont.DrawTextWithShadow(yAxisLabel, new float2(origin.X, graphOrigin.Y) + new float2(5 - axisFont.TopOffset, -(height / 2 - yAxisLabelSize.X / 2)), Color.White, BackgroundColorDark, BackgroundColorLight, 1, (float)Math.PI / 2);
|
||||
|
||||
for (var y = GetDisplayFirstYAxisValue() ? 0 : yStep; y <= height; y += yStep)
|
||||
{
|
||||
var yValue = y / scale;
|
||||
cr.DrawLine(origin + new float2(width - 5, -y), origin + new float2(width, -y), 1, Color.White);
|
||||
tiny.DrawTextWithShadow(GetYAxisValueFormat().F(yValue), origin + new float2(width + 2, -y), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
cr.DrawLine(graphOrigin + new float2(0, -y), graphOrigin + new float2(5, -y), 1, Color.White);
|
||||
var text = GetYAxisValueFormat().F(yValue);
|
||||
|
||||
var textWidth = labelFont.Measure(text);
|
||||
|
||||
var yLocation = y + (textWidth.Y + labelFont.TopOffset) / 2;
|
||||
|
||||
labelFont.DrawTextWithShadow(text, graphOrigin + new float2(-(textWidth.X + 3), -yLocation), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
}
|
||||
|
||||
bold.DrawTextWithShadow(GetYAxisLabel(), origin + new float2(width + 40, -(height / 2)), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
// Bottom line
|
||||
cr.DrawLine(graphOrigin, graphOrigin + new float2(width, 0), 1, Color.White);
|
||||
|
||||
cr.DrawLine(origin, origin + new float2(width, 0), 1, Color.White);
|
||||
cr.DrawLine(origin, origin + new float2(0, -height), 1, Color.White);
|
||||
cr.DrawLine(origin + new float2(width, 0), origin + new float2(width, -height), 1, Color.White);
|
||||
cr.DrawLine(origin + new float2(0, -height), origin + new float2(width, -height), 1, Color.White);
|
||||
// Left line
|
||||
cr.DrawLine(graphOrigin, graphOrigin + new float2(0, -height), 1, Color.White);
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
|
||||
@@ -32,8 +32,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ContainerWidget productionStatsHeaders;
|
||||
readonly ContainerWidget supportPowerStatsHeaders;
|
||||
readonly ContainerWidget combatStatsHeaders;
|
||||
readonly ContainerWidget earnedThisMinuteGraphHeaders;
|
||||
readonly ContainerWidget armyThisMinuteGraphHeaders;
|
||||
readonly ScrollPanelWidget playerStatsPanel;
|
||||
readonly ScrollItemWidget basicPlayerTemplate;
|
||||
readonly ScrollItemWidget economyPlayerTemplate;
|
||||
@@ -53,6 +51,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
readonly string clickSound = ChromeMetrics.Get<string>("ClickSound");
|
||||
bool noneSelected = true;
|
||||
ObserverStatsPanel activePanel;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ObserverStatsLogic(World world, ModData modData, WorldRenderer worldRenderer, Widget widget, Dictionary<string, MiniYaml> logicArgs)
|
||||
@@ -76,9 +75,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
supportPowerStatsHeaders = widget.Get<ContainerWidget>("SUPPORT_POWERS_HEADERS");
|
||||
combatStatsHeaders = widget.Get<ContainerWidget>("COMBAT_STATS_HEADERS");
|
||||
|
||||
earnedThisMinuteGraphHeaders = widget.Get<ContainerWidget>("EARNED_THIS_MIN_GRAPH_HEADERS");
|
||||
armyThisMinuteGraphHeaders = widget.Get<ContainerWidget>("ARMY_THIS_MIN_GRAPH_HEADERS");
|
||||
|
||||
playerStatsPanel = widget.Get<ScrollPanelWidget>("PLAYER_STATS_PANEL");
|
||||
playerStatsPanel.Layout = new GridLayout(playerStatsPanel);
|
||||
playerStatsPanel.IgnoreMouseOver = true;
|
||||
@@ -109,18 +105,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
|
||||
|
||||
var statsDropDown = widget.Get<DropDownButtonWidget>("STATS_DROPDOWN");
|
||||
Func<string, ContainerWidget, ScrollItemWidget, Action, StatsDropDownOption> createStatsOption = (title, headers, template, a) =>
|
||||
Func<string, ObserverStatsPanel, ScrollItemWidget, Action, StatsDropDownOption> createStatsOption = (title, panel, template, a) =>
|
||||
{
|
||||
return new StatsDropDownOption
|
||||
{
|
||||
Title = title,
|
||||
IsSelected = () => headers.Visible,
|
||||
IsSelected = () => activePanel == panel,
|
||||
OnClick = () =>
|
||||
{
|
||||
noneSelected = false;
|
||||
ClearStats();
|
||||
playerStatsPanel.Visible = true;
|
||||
statsDropDown.GetText = () => title;
|
||||
activePanel = panel;
|
||||
if (template != null)
|
||||
AdjustStatisticsPanel(template);
|
||||
|
||||
@@ -144,13 +141,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
ClearStats();
|
||||
}
|
||||
},
|
||||
createStatsOption("Basic", basicStatsHeaders, basicPlayerTemplate, () => DisplayStats(BasicStats)),
|
||||
createStatsOption("Economy", economyStatsHeaders, economyPlayerTemplate, () => DisplayStats(EconomyStats)),
|
||||
createStatsOption("Production", productionStatsHeaders, productionPlayerTemplate, () => DisplayStats(ProductionStats)),
|
||||
createStatsOption("Support Powers", supportPowerStatsHeaders, supportPowersPlayerTemplate, () => DisplayStats(SupportPowerStats)),
|
||||
createStatsOption("Combat", combatStatsHeaders, combatPlayerTemplate, () => DisplayStats(CombatStats)),
|
||||
createStatsOption("Earnings (graph)", earnedThisMinuteGraphHeaders, null, () => EarnedThisMinuteGraph()),
|
||||
createStatsOption("Army (graph)", armyThisMinuteGraphHeaders, null, () => ArmyThisMinuteGraph()),
|
||||
createStatsOption("Basic", ObserverStatsPanel.Basic, basicPlayerTemplate, () => DisplayStats(BasicStats)),
|
||||
createStatsOption("Economy", ObserverStatsPanel.Economy, economyPlayerTemplate, () => DisplayStats(EconomyStats)),
|
||||
createStatsOption("Production", ObserverStatsPanel.Production, productionPlayerTemplate, () => DisplayStats(ProductionStats)),
|
||||
createStatsOption("Support Powers", ObserverStatsPanel.SupportPowers, supportPowersPlayerTemplate, () => DisplayStats(SupportPowerStats)),
|
||||
createStatsOption("Combat", ObserverStatsPanel.Combat, combatPlayerTemplate, () => DisplayStats(CombatStats)),
|
||||
createStatsOption("Earnings (graph)", ObserverStatsPanel.Graph, null, () => EarnedThisMinuteGraph()),
|
||||
createStatsOption("Army (graph)", ObserverStatsPanel.ArmyGraph, null, () => ArmyThisMinuteGraph()),
|
||||
};
|
||||
|
||||
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
@@ -196,8 +193,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
productionStatsHeaders.Visible = false;
|
||||
supportPowerStatsHeaders.Visible = false;
|
||||
combatStatsHeaders.Visible = false;
|
||||
earnedThisMinuteGraphHeaders.Visible = false;
|
||||
armyThisMinuteGraphHeaders.Visible = false;
|
||||
|
||||
earnedThisMinuteGraphContainer.Visible = false;
|
||||
armyThisMinuteGraphContainer.Visible = false;
|
||||
@@ -209,7 +204,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
void EarnedThisMinuteGraph()
|
||||
{
|
||||
playerStatsPanel.Visible = false;
|
||||
earnedThisMinuteGraphHeaders.Visible = true;
|
||||
earnedThisMinuteGraphContainer.Visible = true;
|
||||
|
||||
earnedThisMinuteGraph.GetSeries = () =>
|
||||
@@ -222,7 +216,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
void ArmyThisMinuteGraph()
|
||||
{
|
||||
playerStatsPanel.Visible = false;
|
||||
armyThisMinuteGraphHeaders.Visible = true;
|
||||
armyThisMinuteGraphContainer.Visible = true;
|
||||
|
||||
armyThisMinuteGraph.GetSeries = () =>
|
||||
|
||||
Reference in New Issue
Block a user