Replace "$/min" by "Income" and increase graph update rates
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
@@ -29,14 +28,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public int OrderCount;
|
||||
|
||||
public int EarnedThisMinute
|
||||
{
|
||||
get
|
||||
{
|
||||
return resources != null ? resources.Earned - earnedAtBeginningOfMinute : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int Experience
|
||||
{
|
||||
get
|
||||
@@ -45,8 +36,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public List<int> EarnedSamples = new List<int>(100);
|
||||
int earnedAtBeginningOfMinute;
|
||||
// Low resolution (every 30 seconds) record of earnings, covering the entire game
|
||||
public List<int> IncomeSamples = new List<int>(100);
|
||||
public int Income;
|
||||
public int DisplayIncome;
|
||||
|
||||
public List<int> ArmySamples = new List<int>(100);
|
||||
|
||||
@@ -60,8 +53,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public int BuildingsDead;
|
||||
|
||||
public int ArmyValue;
|
||||
int replayTimestep;
|
||||
|
||||
// High resolution (every second) record of earnings, limited to the last minute
|
||||
readonly Queue<int> earnedSeconds = new Queue<int>(60);
|
||||
|
||||
int lastIncome;
|
||||
int lastIncomeTick;
|
||||
int ticks;
|
||||
int replayTimestep;
|
||||
|
||||
public PlayerStatistics(Actor self) { }
|
||||
|
||||
@@ -71,32 +70,37 @@ namespace OpenRA.Mods.Common.Traits
|
||||
experience = self.TraitOrDefault<PlayerExperience>();
|
||||
}
|
||||
|
||||
void UpdateEarnedThisMinute()
|
||||
{
|
||||
EarnedSamples.Add(EarnedThisMinute);
|
||||
earnedAtBeginningOfMinute = resources != null ? resources.Earned : 0;
|
||||
}
|
||||
|
||||
void UpdateArmyThisMinute()
|
||||
{
|
||||
ArmySamples.Add(ArmyValue);
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
if (self.Owner.WinState != WinState.Undefined)
|
||||
return;
|
||||
|
||||
ticks++;
|
||||
|
||||
var timestep = self.World.IsReplay ? replayTimestep : self.World.Timestep;
|
||||
|
||||
if (ticks * timestep >= 60000)
|
||||
if (ticks * timestep >= 30000)
|
||||
{
|
||||
ticks = 0;
|
||||
UpdateEarnedThisMinute();
|
||||
UpdateArmyThisMinute();
|
||||
|
||||
if (ArmyValue != 0 || self.Owner.WinState == WinState.Undefined)
|
||||
ArmySamples.Add(ArmyValue);
|
||||
|
||||
if (resources != null && (Income != 0 || self.Owner.WinState == WinState.Undefined))
|
||||
IncomeSamples.Add(Income);
|
||||
}
|
||||
|
||||
if (resources == null)
|
||||
return;
|
||||
|
||||
var tickDelta = self.World.WorldTick - lastIncomeTick;
|
||||
if (tickDelta * timestep >= 1000)
|
||||
{
|
||||
lastIncomeTick = self.World.WorldTick;
|
||||
|
||||
var lastEarned = earnedSeconds.Count > 59 ? earnedSeconds.Dequeue() : 0;
|
||||
lastIncome = DisplayIncome = Income;
|
||||
Income = resources.Earned - lastEarned;
|
||||
earnedSeconds.Enqueue(resources.Earned);
|
||||
}
|
||||
else
|
||||
DisplayIncome = int2.Lerp(lastIncome, Income, tickDelta * timestep, 1000);
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
@@ -130,8 +134,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (w.IsReplay)
|
||||
replayTimestep = w.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
|
||||
|
||||
UpdateEarnedThisMinute();
|
||||
UpdateArmyThisMinute();
|
||||
ArmySamples.Add(ArmyValue);
|
||||
IncomeSamples.Add(Income);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ScrollItemWidget productionPlayerTemplate;
|
||||
readonly ScrollItemWidget supportPowersPlayerTemplate;
|
||||
readonly ScrollItemWidget combatPlayerTemplate;
|
||||
readonly ContainerWidget earnedThisMinuteGraphContainer;
|
||||
readonly ContainerWidget armyThisMinuteGraphContainer;
|
||||
readonly LineGraphWidget earnedThisMinuteGraph;
|
||||
readonly LineGraphWidget armyThisMinuteGraph;
|
||||
readonly ContainerWidget incomeGraphContainer;
|
||||
readonly ContainerWidget armyValueGraphContainer;
|
||||
readonly LineGraphWidget incomeGraph;
|
||||
readonly LineGraphWidget armyValueGraph;
|
||||
readonly ScrollItemWidget teamTemplate;
|
||||
readonly IEnumerable<Player> players;
|
||||
readonly IOrderedEnumerable<IGrouping<int, Player>> teams;
|
||||
@@ -95,11 +95,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
supportPowersPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("SUPPORT_POWERS_PLAYER_TEMPLATE");
|
||||
combatPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("COMBAT_PLAYER_TEMPLATE");
|
||||
|
||||
earnedThisMinuteGraphContainer = widget.Get<ContainerWidget>("EARNED_THIS_MIN_GRAPH_CONTAINER");
|
||||
earnedThisMinuteGraph = earnedThisMinuteGraphContainer.Get<LineGraphWidget>("EARNED_THIS_MIN_GRAPH");
|
||||
incomeGraphContainer = widget.Get<ContainerWidget>("INCOME_GRAPH_CONTAINER");
|
||||
incomeGraph = incomeGraphContainer.Get<LineGraphWidget>("INCOME_GRAPH");
|
||||
|
||||
armyThisMinuteGraphContainer = widget.Get<ContainerWidget>("ARMY_THIS_MIN_GRAPH_CONTAINER");
|
||||
armyThisMinuteGraph = armyThisMinuteGraphContainer.Get<LineGraphWidget>("ARMY_THIS_MIN_GRAPH");
|
||||
armyValueGraphContainer = widget.Get<ContainerWidget>("ARMY_VALUE_GRAPH_CONTAINER");
|
||||
armyValueGraph = armyValueGraphContainer.Get<LineGraphWidget>("ARMY_VALUE_GRAPH");
|
||||
|
||||
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
|
||||
|
||||
@@ -144,8 +144,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
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()),
|
||||
createStatsOption("Earnings (graph)", ObserverStatsPanel.Graph, null, () => IncomeGraph()),
|
||||
createStatsOption("Army (graph)", ObserverStatsPanel.ArmyGraph, null, () => ArmyValueGraph()),
|
||||
};
|
||||
|
||||
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
@@ -192,31 +192,31 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
supportPowerStatsHeaders.Visible = false;
|
||||
combatStatsHeaders.Visible = false;
|
||||
|
||||
earnedThisMinuteGraphContainer.Visible = false;
|
||||
armyThisMinuteGraphContainer.Visible = false;
|
||||
incomeGraphContainer.Visible = false;
|
||||
armyValueGraphContainer.Visible = false;
|
||||
|
||||
earnedThisMinuteGraph.GetSeries = null;
|
||||
armyThisMinuteGraph.GetSeries = null;
|
||||
incomeGraph.GetSeries = null;
|
||||
armyValueGraph.GetSeries = null;
|
||||
}
|
||||
|
||||
void EarnedThisMinuteGraph()
|
||||
void IncomeGraph()
|
||||
{
|
||||
playerStatsPanel.Visible = false;
|
||||
earnedThisMinuteGraphContainer.Visible = true;
|
||||
incomeGraphContainer.Visible = true;
|
||||
|
||||
earnedThisMinuteGraph.GetSeries = () =>
|
||||
incomeGraph.GetSeries = () =>
|
||||
players.Select(p => new LineGraphSeries(
|
||||
p.PlayerName,
|
||||
p.Color,
|
||||
(p.PlayerActor.TraitOrDefault<PlayerStatistics>() ?? new PlayerStatistics(p.PlayerActor)).EarnedSamples.Select(s => (float)s)));
|
||||
(p.PlayerActor.TraitOrDefault<PlayerStatistics>() ?? new PlayerStatistics(p.PlayerActor)).IncomeSamples.Select(s => (float)s)));
|
||||
}
|
||||
|
||||
void ArmyThisMinuteGraph()
|
||||
void ArmyValueGraph()
|
||||
{
|
||||
playerStatsPanel.Visible = false;
|
||||
armyThisMinuteGraphContainer.Visible = true;
|
||||
armyValueGraphContainer.Visible = true;
|
||||
|
||||
armyThisMinuteGraph.GetSeries = () =>
|
||||
armyValueGraph.GetSeries = () =>
|
||||
players.Select(p => new LineGraphSeries(
|
||||
p.PlayerName,
|
||||
p.Color,
|
||||
@@ -344,10 +344,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var res = player.PlayerActor.Trait<PlayerResources>();
|
||||
var stats = player.PlayerActor.TraitOrDefault<PlayerStatistics>();
|
||||
if (stats == null) return template;
|
||||
if (stats == null)
|
||||
return template;
|
||||
|
||||
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.Cash + res.Resources);
|
||||
template.Get<LabelWidget>("EARNED_MIN").GetText = () => AverageEarnedPerMinute(res.Earned);
|
||||
template.Get<LabelWidget>("INCOME").GetText = () => "$" + stats.DisplayIncome;
|
||||
template.Get<LabelWidget>("EARNED").GetText = () => "$" + res.Earned;
|
||||
template.Get<LabelWidget>("SPENT").GetText = () => "$" + res.Spent;
|
||||
|
||||
@@ -393,7 +394,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
|
||||
var stats = player.PlayerActor.TraitOrDefault<PlayerStatistics>();
|
||||
if (stats == null) return template;
|
||||
if (stats == null)
|
||||
return template;
|
||||
|
||||
template.Get<LabelWidget>("KILLS").GetText = () => (stats.UnitsKilled + stats.BuildingsKilled).ToString();
|
||||
template.Get<LabelWidget>("DEATHS").GetText = () => (stats.UnitsDead + stats.BuildingsDead).ToString();
|
||||
template.Get<LabelWidget>("ASSETS_DESTROYED").GetText = () => "$" + stats.KillsCost;
|
||||
@@ -484,11 +487,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return (world.WorldTick == 0 ? 0 : orders / (world.WorldTick / 1500.0)).ToString("F1");
|
||||
}
|
||||
|
||||
string AverageEarnedPerMinute(double earned)
|
||||
{
|
||||
return "$" + (world.WorldTick == 0 ? 0 : earned / (world.WorldTick / 1500.0)).ToString("F0");
|
||||
}
|
||||
|
||||
static Color GetPowerColor(PowerState state)
|
||||
{
|
||||
if (state == PowerState.Critical) return Color.Red;
|
||||
|
||||
Reference in New Issue
Block a user