Add Map Control statistic
This commit is contained in:
@@ -10,13 +10,13 @@
|
|||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
class RevealsShroudInfo : ITraitInfo
|
public class RevealsShroudInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly int Range = 0;
|
public readonly int Range = 0;
|
||||||
public object Create(ActorInitializer init) { return new RevealsShroud(this); }
|
public object Create(ActorInitializer init) { return new RevealsShroud(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class RevealsShroud : ITick
|
public class RevealsShroud : ITick
|
||||||
{
|
{
|
||||||
RevealsShroudInfo Info;
|
RevealsShroudInfo Info;
|
||||||
CPos previousLocation;
|
CPos previousLocation;
|
||||||
|
|||||||
@@ -24,13 +24,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
ContainerWidget basicStatsHeaders;
|
ContainerWidget basicStatsHeaders;
|
||||||
ContainerWidget economicStatsHeaders;
|
ContainerWidget economicStatsHeaders;
|
||||||
ContainerWidget productionStatsHeaders;
|
ContainerWidget productionStatsHeaders;
|
||||||
|
ContainerWidget combatStatsHeaders;
|
||||||
ScrollPanelWidget playerStatsPanel;
|
ScrollPanelWidget playerStatsPanel;
|
||||||
ScrollItemWidget basicPlayerTemplate;
|
ScrollItemWidget basicPlayerTemplate;
|
||||||
ScrollItemWidget economicPlayerTemplate;
|
ScrollItemWidget economicPlayerTemplate;
|
||||||
ScrollItemWidget productionPlayerTemplate;
|
ScrollItemWidget productionPlayerTemplate;
|
||||||
|
ScrollItemWidget combatPlayerTemplate;
|
||||||
ScrollItemWidget teamTemplate;
|
ScrollItemWidget teamTemplate;
|
||||||
DropDownButtonWidget statsDropDown;
|
DropDownButtonWidget statsDropDown;
|
||||||
LabelWidget title;
|
|
||||||
IEnumerable<Player> players;
|
IEnumerable<Player> players;
|
||||||
World world;
|
World world;
|
||||||
|
|
||||||
@@ -40,11 +41,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
players = world.Players.Where(p => !p.NonCombatant);
|
players = world.Players.Where(p => !p.NonCombatant);
|
||||||
|
|
||||||
title = widget.Get<LabelWidget>("TITLE");
|
|
||||||
|
|
||||||
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");
|
||||||
productionStatsHeaders = widget.Get<ContainerWidget>("PRODUCTION_STATS_HEADERS");
|
productionStatsHeaders = widget.Get<ContainerWidget>("PRODUCTION_STATS_HEADERS");
|
||||||
|
combatStatsHeaders = widget.Get<ContainerWidget>("COMBAT_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);
|
||||||
@@ -52,6 +52,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
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");
|
||||||
productionPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("PRODUCTION_PLAYER_TEMPLATE");
|
productionPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("PRODUCTION_PLAYER_TEMPLATE");
|
||||||
|
combatPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("COMBAT_PLAYER_TEMPLATE");
|
||||||
|
|
||||||
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
|
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
|
||||||
|
|
||||||
@@ -93,6 +94,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
statsDropDown.GetText = () => "Production";
|
statsDropDown.GetText = () => "Production";
|
||||||
LoadStats(ProductionStats);
|
LoadStats(ProductionStats);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
new StatsDropDownOption
|
||||||
|
{
|
||||||
|
Title = "Combat",
|
||||||
|
IsSelected = () => combatStatsHeaders.Visible,
|
||||||
|
OnClick = () =>
|
||||||
|
{
|
||||||
|
ClearStats();
|
||||||
|
statsDropDown.GetText = () => "Combat";
|
||||||
|
LoadStats(CombatStats);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||||
@@ -101,7 +113,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
statsDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 100, options, setupItem);
|
statsDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
|
||||||
};
|
};
|
||||||
|
|
||||||
widget.Height = (200 + (Math.Min(8, players.Count()) * 25)).ToString();
|
widget.Height = (200 + (Math.Min(8, players.Count()) * 25)).ToString();
|
||||||
@@ -117,6 +129,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
basicStatsHeaders.Visible = false;
|
basicStatsHeaders.Visible = false;
|
||||||
economicStatsHeaders.Visible = false;
|
economicStatsHeaders.Visible = false;
|
||||||
productionStatsHeaders.Visible = false;
|
productionStatsHeaders.Visible = false;
|
||||||
|
combatStatsHeaders.Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadStats(Func<Player, ScrollItemWidget> forEachPlayer)
|
void LoadStats(Func<Player, ScrollItemWidget> forEachPlayer)
|
||||||
@@ -137,6 +150,27 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScrollItemWidget CombatStats(Player player)
|
||||||
|
{
|
||||||
|
combatStatsHeaders.Visible = true;
|
||||||
|
var template = SetupPlayerScrollItemWidget(combatPlayerTemplate, player);
|
||||||
|
|
||||||
|
AddPlayerFlagAndName(template, player);
|
||||||
|
|
||||||
|
template.Get<LabelWidget>("MAP_CONTROL").GetText = () =>
|
||||||
|
{
|
||||||
|
var total = world.Map.Bounds.Width * world.Map.Bounds.Height;
|
||||||
|
var controlled = world.Actors
|
||||||
|
.Where(a => !a.IsDead() && a.IsInWorld && a.Owner == player && a.HasTrait<RevealsShroud>())
|
||||||
|
.SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().RevealRange))
|
||||||
|
.Distinct()
|
||||||
|
.Count();
|
||||||
|
return Round((double)controlled / total * 100).ToString("F1") + "%";
|
||||||
|
};
|
||||||
|
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
ScrollItemWidget ProductionStats(Player player)
|
ScrollItemWidget ProductionStats(Player player)
|
||||||
{
|
{
|
||||||
productionStatsHeaders.Visible = true;
|
productionStatsHeaders.Visible = true;
|
||||||
@@ -164,10 +198,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
|
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
|
||||||
template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMinute;
|
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 = () => Round(res.IncomeChange * 100) + "%";
|
||||||
change.GetColor = () =>
|
change.GetColor = () =>
|
||||||
{
|
{
|
||||||
var c = Math.Round(res.IncomeChange * 100, 1, MidpointRounding.AwayFromZero);
|
var c = Round(res.IncomeChange * 100);
|
||||||
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;
|
||||||
@@ -222,6 +256,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double Round(double value)
|
||||||
|
{
|
||||||
|
return Math.Round(value, 1, MidpointRounding.AwayFromZero);
|
||||||
|
}
|
||||||
|
|
||||||
static void AddPlayerFlagAndName(ScrollItemWidget template, Player player)
|
static void AddPlayerFlagAndName(ScrollItemWidget template, Player player)
|
||||||
{
|
{
|
||||||
var flag = template.Get<ImageWidget>("FLAG");
|
var flag = template.Get<ImageWidget>("FLAG");
|
||||||
|
|||||||
@@ -559,6 +559,26 @@ Container@OBSERVER_ROOT:
|
|||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Text:Support Powers
|
Text:Support Powers
|
||||||
|
Container@COMBAT_STATS_HEADERS:
|
||||||
|
X:0
|
||||||
|
Y:0
|
||||||
|
Width:PARENT_RIGHT
|
||||||
|
Height:PARENT_BOTTOM
|
||||||
|
Children:
|
||||||
|
Label@PLAYER_HEADER:
|
||||||
|
X:85
|
||||||
|
Y:40
|
||||||
|
Width:160
|
||||||
|
Height:25
|
||||||
|
Font:Bold
|
||||||
|
Text:Player
|
||||||
|
Label@MAP_CONTROL_HEADER:
|
||||||
|
X:245
|
||||||
|
Y:40
|
||||||
|
Width:60
|
||||||
|
Height:25
|
||||||
|
Font:Bold
|
||||||
|
Text:Map Control
|
||||||
ScrollPanel@PLAYER_STATS_PANEL:
|
ScrollPanel@PLAYER_STATS_PANEL:
|
||||||
X:25
|
X:25
|
||||||
Y:70
|
Y:70
|
||||||
@@ -714,6 +734,30 @@ Container@OBSERVER_ROOT:
|
|||||||
Y:0
|
Y:0
|
||||||
Width:320
|
Width:320
|
||||||
Height:PARENT_BOTTOM
|
Height:PARENT_BOTTOM
|
||||||
|
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
||||||
|
X:0
|
||||||
|
Y:0
|
||||||
|
Width:PARENT_RIGHT-35
|
||||||
|
Height:25
|
||||||
|
Children:
|
||||||
|
Image@FLAG:
|
||||||
|
X:20
|
||||||
|
Y:5
|
||||||
|
Width:35
|
||||||
|
Height:PARENT_BOTTOM-5
|
||||||
|
ImageName:random
|
||||||
|
ImageCollection:flags
|
||||||
|
Label@PLAYER:
|
||||||
|
X:55
|
||||||
|
Y:0
|
||||||
|
Width:160
|
||||||
|
Height:PARENT_BOTTOM
|
||||||
|
Font:Bold
|
||||||
|
Label@MAP_CONTROL
|
||||||
|
X:215
|
||||||
|
Y:0
|
||||||
|
Width:60
|
||||||
|
Height:PARENT_BOTTOM
|
||||||
Background@FMVPLAYER:
|
Background@FMVPLAYER:
|
||||||
Width:WINDOW_RIGHT
|
Width:WINDOW_RIGHT
|
||||||
Height:WINDOW_BOTTOM
|
Height:WINDOW_BOTTOM
|
||||||
|
|||||||
Reference in New Issue
Block a user