Add Order counter for rough APM estimation. Rename Support to Production and move the production icons there

This commit is contained in:
Scott_NZ
2012-11-25 00:28:22 +13:00
parent 30a374b9e9
commit 36f349ecba
6 changed files with 102 additions and 38 deletions

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Traits
public int DisplayCash; public int DisplayCash;
public int DisplayOre; public int DisplayOre;
public int IncomePerMin; public int IncomePerMinute;
int incomeCounter; int incomeCounter;
public double IncomeChange; public double IncomeChange;
@@ -206,8 +206,8 @@ namespace OpenRA.Traits
if (self.World.FrameNumber % 1500 == 0) if (self.World.FrameNumber % 1500 == 0)
{ {
IncomeChange = IncomePerMin == 0 ? 0 : (double)(incomeCounter - IncomePerMin) / IncomePerMin; IncomeChange = IncomePerMinute == 0 ? 0 : (double)(incomeCounter - IncomePerMinute) / IncomePerMinute;
IncomePerMin = incomeCounter; IncomePerMinute = incomeCounter;
incomeCounter = 0; incomeCounter = 0;
} }
} }

View File

@@ -256,6 +256,7 @@
<Compile Include="NukePaletteEffect.cs" /> <Compile Include="NukePaletteEffect.cs" />
<Compile Include="NullLoadScreen.cs" /> <Compile Include="NullLoadScreen.cs" />
<Compile Include="OpenWidgetAtGameStart.cs" /> <Compile Include="OpenWidgetAtGameStart.cs" />
<Compile Include="OrderCounter.cs" />
<Compile Include="Orders\DeployOrderTargeter.cs" /> <Compile Include="Orders\DeployOrderTargeter.cs" />
<Compile Include="Orders\EnterBuildingOrderTargeter.cs" /> <Compile Include="Orders\EnterBuildingOrderTargeter.cs" />
<Compile Include="Orders\PlaceBuildingOrderGenerator.cs" /> <Compile Include="Orders\PlaceBuildingOrderGenerator.cs" />

View File

@@ -0,0 +1,49 @@
#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.Traits;
namespace OpenRA.Mods.RA
{
public class OrderCounterInfo : TraitInfo<OrderCounter> { }
public class OrderCounter : IResolveOrder
{
public int Orders;
public void ResolveOrder(Actor self, Order order)
{
switch (order.OrderString)
{
case "Chat":
case "TeamChat":
case "HandshakeResponse":
case "PauseRequest":
case "PauseGame":
case "StartGame":
case "Disconnected":
case "ServerError":
case "SyncInfo":
return;
}
if (order.OrderString.StartsWith("Dev"))
{
return;
}
Orders++;
}
public static double OrdersPerMinute(OrderCounter counter, World world)
{
return world.FrameNumber == 0 ? 0 : counter.Orders / (world.FrameNumber / 1500.0);
}
}
}

View File

@@ -23,11 +23,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
ContainerWidget basicStatsHeaders; ContainerWidget basicStatsHeaders;
ContainerWidget economicStatsHeaders; ContainerWidget economicStatsHeaders;
ContainerWidget supportStatsHeaders; ContainerWidget productionStatsHeaders;
ScrollPanelWidget playerStatsPanel; ScrollPanelWidget playerStatsPanel;
ScrollItemWidget basicPlayerTemplate; ScrollItemWidget basicPlayerTemplate;
ScrollItemWidget economicPlayerTemplate; ScrollItemWidget economicPlayerTemplate;
ScrollItemWidget supportPlayerTemplate; ScrollItemWidget productionPlayerTemplate;
ScrollItemWidget teamTemplate; ScrollItemWidget teamTemplate;
DropDownButtonWidget statsDropDown; DropDownButtonWidget statsDropDown;
LabelWidget title; LabelWidget title;
@@ -44,14 +44,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
basicStatsHeaders = widget.Get<ContainerWidget>("BASIC_STATS_HEADERS"); basicStatsHeaders = widget.Get<ContainerWidget>("BASIC_STATS_HEADERS");
economicStatsHeaders = widget.Get<ContainerWidget>("ECONOMIC_STATS_HEADERS"); economicStatsHeaders = widget.Get<ContainerWidget>("ECONOMIC_STATS_HEADERS");
supportStatsHeaders = widget.Get<ContainerWidget>("SUPPORT_STATS_HEADERS"); productionStatsHeaders = widget.Get<ContainerWidget>("PRODUCTION_STATS_HEADERS");
playerStatsPanel = widget.Get<ScrollPanelWidget>("PLAYER_STATS_PANEL"); playerStatsPanel = widget.Get<ScrollPanelWidget>("PLAYER_STATS_PANEL");
playerStatsPanel.Layout = new GridLayout(playerStatsPanel); playerStatsPanel.Layout = new GridLayout(playerStatsPanel);
basicPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("BASIC_PLAYER_TEMPLATE"); basicPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("BASIC_PLAYER_TEMPLATE");
economicPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("ECONOMIC_PLAYER_TEMPLATE"); economicPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("ECONOMIC_PLAYER_TEMPLATE");
supportPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("SUPPORT_PLAYER_TEMPLATE"); productionPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("PRODUCTION_PLAYER_TEMPLATE");
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE"); teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
@@ -85,13 +85,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}, },
new StatsDropDownOption new StatsDropDownOption
{ {
Title = "Support", Title = "Production",
IsSelected = () => supportStatsHeaders.Visible, IsSelected = () => productionStatsHeaders.Visible,
OnClick = () => OnClick = () =>
{ {
ClearStats(); ClearStats();
statsDropDown.GetText = () => "Support"; statsDropDown.GetText = () => "Production";
LoadStats(SupportStats); LoadStats(ProductionStats);
} }
} }
}; };
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
playerStatsPanel.Children.Clear(); playerStatsPanel.Children.Clear();
basicStatsHeaders.Visible = false; basicStatsHeaders.Visible = false;
economicStatsHeaders.Visible = false; economicStatsHeaders.Visible = false;
supportStatsHeaders.Visible = false; productionStatsHeaders.Visible = false;
} }
void LoadStats(Func<Player, ScrollItemWidget> forEachPlayer) void LoadStats(Func<Player, ScrollItemWidget> forEachPlayer)
@@ -137,14 +137,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
} }
} }
ScrollItemWidget SupportStats(Player player) ScrollItemWidget ProductionStats(Player player)
{ {
supportStatsHeaders.Visible = true; productionStatsHeaders.Visible = true;
var template = SetupPlayerScrollItemWidget(supportPlayerTemplate, player); var template = SetupPlayerScrollItemWidget(productionPlayerTemplate, player);
AddPlayerFlagAndName(template, player); AddPlayerFlagAndName(template, player);
var supportPowers = template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWERS"); var production = template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS");
production.GetPlayer = () => player;
var supportPowers = template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWER_ICONS");
supportPowers.GetPlayer = () => player; supportPowers.GetPlayer = () => player;
return template; return template;
@@ -159,12 +162,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var res = player.PlayerActor.Trait<PlayerResources>(); var res = player.PlayerActor.Trait<PlayerResources>();
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre); template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMin; template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMinute;
var change = template.Get<LabelWidget>("INCOME_CHANGE"); var change = template.Get<LabelWidget>("INCOME_CHANGE");
change.GetText = () => Math.Round(res.IncomeChange * 100, 1, MidpointRounding.AwayFromZero) + "%"; change.GetText = () => Math.Round(res.IncomeChange * 100, 1, MidpointRounding.AwayFromZero) + "%";
change.GetColor = () => change.GetColor = () =>
{ {
var c = Math.Round(res.IncomeChange, 1, MidpointRounding.AwayFromZero); var c = Math.Round(res.IncomeChange * 100, 1, MidpointRounding.AwayFromZero);
if (c < 0) return Color.Red; if (c < 0) return Color.Red;
if (c > 0) return Color.LimeGreen; if (c > 0) return Color.LimeGreen;
return Color.White; return Color.White;
@@ -178,8 +181,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template.Get<LabelWidget>("TOTAL_EARNED").GetText = () => "$" + res.TotalEarned; template.Get<LabelWidget>("TOTAL_EARNED").GetText = () => "$" + res.TotalEarned;
template.Get<LabelWidget>("TOTAL_SPENT").GetText = () => "$" + res.TotalSpent; template.Get<LabelWidget>("TOTAL_SPENT").GetText = () => "$" + res.TotalSpent;
var numHarvesters = template.Get<LabelWidget>("NUMBER_HARVESTERS"); var harvesters = template.Get<LabelWidget>("NUMBER_HARVESTERS");
numHarvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait<Harvester>()).ToString(); harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait<Harvester>()).ToString();
return template; return template;
} }
@@ -193,7 +196,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var res = player.PlayerActor.Trait<PlayerResources>(); var res = player.PlayerActor.Trait<PlayerResources>();
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre); template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMin; template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMinute;
var powerRes = player.PlayerActor.Trait<PowerManager>(); var powerRes = player.PlayerActor.Trait<PowerManager>();
var power = template.Get<LabelWidget>("POWER"); var power = template.Get<LabelWidget>("POWER");
@@ -202,9 +205,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template.Get<LabelWidget>("KILLS").GetText = () => player.Kills.ToString(); template.Get<LabelWidget>("KILLS").GetText = () => player.Kills.ToString();
template.Get<LabelWidget>("DEATHS").GetText = () => player.Deaths.ToString(); template.Get<LabelWidget>("DEATHS").GetText = () => player.Deaths.ToString();
template.Get<LabelWidget>("ORDERS").GetText = () => OrderCounter.OrdersPerMinute(player.PlayerActor.Trait<OrderCounter>(), world).ToString("F1");
var production = template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS");
production.GetPlayer = () => player;
return template; return template;
} }

View File

@@ -468,14 +468,14 @@ Container@OBSERVER_ROOT:
Font:Bold Font:Bold
Text:Deaths Text:Deaths
Align:Right Align:Right
Label@PRODUCTION_HEADER Label@ORDERS_HEADER:
X:585 X:605
Y:40 Y:40
Width:PARENT_RIGHT-625 Width:40
Height:25 Height:25
Font:Bold Font:Bold
Text:Production Text:APM
Align:Center Align:Right
Container@ECONOMIC_STATS_HEADERS: Container@ECONOMIC_STATS_HEADERS:
X:0 X:0
Y:0 Y:0
@@ -532,7 +532,7 @@ Container@OBSERVER_ROOT:
Font:Bold Font:Bold
Text:Harvesters Text:Harvesters
Align:Right Align:Right
Container@SUPPORT_STATS_HEADERS: Container@PRODUCTION_STATS_HEADERS:
X:0 X:0
Y:0 Y:0
Width:PARENT_RIGHT Width:PARENT_RIGHT
@@ -545,14 +545,20 @@ Container@OBSERVER_ROOT:
Height:25 Height:25
Font:Bold Font:Bold
Text:Player Text:Player
Label@SUPPORT_POWERS_HEADER: Label@PRODUCTION_HEADER
X:245 X:245
Y:40 Y:40
Width:300 Width:320
Height:25
Font:Bold
Text:Production
Label@SUPPORT_POWERS_HEADER:
X:565
Y:40
Width:320
Height:25 Height:25
Font:Bold Font:Bold
Text:Support Powers Text:Support Powers
Align:Center
ScrollPanel@PLAYER_STATS_PANEL: ScrollPanel@PLAYER_STATS_PANEL:
X:25 X:25
Y:70 Y:70
@@ -618,11 +624,12 @@ Container@OBSERVER_ROOT:
Width:40 Width:40
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Align:Right Align:Right
ObserverProductionIcons@PRODUCTION_ICONS: Label@ORDERS:
X:575 X:575
Y:0 Y:0
Width:240 Width:40
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Align:Right
ScrollItem@ECONOMIC_PLAYER_TEMPLATE: ScrollItem@ECONOMIC_PLAYER_TEMPLATE:
X:0 X:0
Y:0 Y:0
@@ -678,7 +685,7 @@ Container@OBSERVER_ROOT:
Width:60 Width:60
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Align:Right Align:Right
ScrollItem@SUPPORT_PLAYER_TEMPLATE: ScrollItem@PRODUCTION_PLAYER_TEMPLATE:
X:0 X:0
Y:0 Y:0
Width:PARENT_RIGHT-35 Width:PARENT_RIGHT-35
@@ -697,10 +704,15 @@ Container@OBSERVER_ROOT:
Width:160 Width:160
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Font:Bold Font:Bold
ObserverSupportPowerIcons@SUPPORT_POWERS: ObserverProductionIcons@PRODUCTION_ICONS:
X:215 X:215
Y:0 Y:0
Width:300 Width:320
Height:PARENT_BOTTOM
ObserverSupportPowerIcons@SUPPORT_POWER_ICONS:
X:535
Y:0
Width:320
Height:PARENT_BOTTOM Height:PARENT_BOTTOM
Background@FMVPLAYER: Background@FMVPLAYER:
Width:WINDOW_RIGHT Width:WINDOW_RIGHT

View File

@@ -190,6 +190,7 @@ Player:
GpsWatcher: GpsWatcher:
Shroud: Shroud:
BaseAttackNotifier: BaseAttackNotifier:
OrderCounter:
World: World:
OpenWidgetAtGameStart: OpenWidgetAtGameStart: