Updated the observer ui

This commit is contained in:
teinarss
2019-05-22 14:56:52 +02:00
committed by Paul Chote
parent b90b3095a6
commit 9fc8b829e4
23 changed files with 3773 additions and 2076 deletions

View File

@@ -236,6 +236,11 @@ namespace OpenRA.Mods.Common.Traits
return Queue.Count > 0 && Queue[0] == item;
}
public ProductionItem CurrentItem()
{
return Queue.ElementAtOrDefault(0);
}
public virtual IEnumerable<ProductionItem> AllQueued()
{
return Queue;

View File

@@ -148,19 +148,19 @@ namespace OpenRA.Mods.Common.Widgets
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.DrawText(GetXAxisValueFormat().F(n), origin + new float2(x, 2), Color.White);
tiny.DrawTextWithShadow(GetXAxisValueFormat().F(n), origin + new float2(x, 2), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
}
bold.DrawText(GetXAxisLabel(), origin + new float2(width / 2, 20), Color.White);
bold.DrawTextWithShadow(GetXAxisLabel(), origin + new float2(width / 2, 20), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
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.DrawText(GetYAxisValueFormat().F(yValue), origin + new float2(width + 2, -y), Color.White);
tiny.DrawTextWithShadow(GetYAxisValueFormat().F(yValue), origin + new float2(width + 2, -y), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
}
bold.DrawText(GetYAxisLabel(), origin + new float2(width + 40, -(height / 2)), Color.White);
bold.DrawTextWithShadow(GetYAxisLabel(), origin + new float2(width + 40, -(height / 2)), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
cr.DrawLine(origin, origin + new float2(width, 0), 1, Color.White);
cr.DrawLine(origin, origin + new float2(0, -height), 1, Color.White);

View File

@@ -12,13 +12,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Lint;
using OpenRA.Mods.Common.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
[ChromeLogicArgsHotkeys("StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsCombatKey", "StatisticsGraphKey", "StatisticsArmyGraphKey")]
public class MenuButtonsChromeLogic : ChromeLogic
{
readonly World world;
@@ -38,10 +36,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
menuRoot = Ui.Root.Get("MENU_ROOT");
MiniYaml yaml;
string[] keyNames = Enum.GetNames(typeof(ObserverStatsPanel));
var statsHotkeys = new HotkeyReference[keyNames.Length];
for (var i = 0; i < keyNames.Length; i++)
statsHotkeys[i] = logicArgs.TryGetValue("Statistics" + keyNames[i] + "Key", out yaml) ? modData.Hotkeys[yaml.Value] : new HotkeyReference();
// System buttons
var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
@@ -91,35 +85,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
}
var stats = widget.GetOrNull<MenuButtonWidget>("OBSERVER_STATS_BUTTON");
if (stats != null)
{
stats.IsDisabled = () => disableSystemButtons || world.Map.Visibility.HasFlag(MapVisibility.MissionSelector);
stats.OnClick = () => OpenMenuPanel(stats, new WidgetArgs() { { "activePanel", ObserverStatsPanel.Basic } });
}
var keyListener = widget.GetOrNull<LogicKeyListenerWidget>("OBSERVER_KEY_LISTENER");
if (keyListener != null)
{
keyListener.AddHandler(e =>
{
if (e.Event == KeyInputEvent.Down && !e.IsRepeat)
{
for (var i = 0; i < statsHotkeys.Length; i++)
{
if (statsHotkeys[i].IsActivatedBy(e))
{
Game.Sound.PlayNotification(modData.DefaultRules, null, "Sounds", clickSound, null);
OpenMenuPanel(stats, new WidgetArgs() { { "activePanel", i } });
return true;
}
}
}
return false;
});
}
if (logicArgs.TryGetValue("ClickSound", out yaml))
clickSound = yaml.Value;
}

View File

@@ -21,14 +21,16 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
public enum ObserverStatsPanel { Basic, Economy, Production, Combat, Graph, ArmyGraph }
public enum ObserverStatsPanel { None, Basic, Economy, Production, SupportPowers, Combat, Graph, ArmyGraph }
[ChromeLogicArgsHotkeys("StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsCombatKey", "StatisticsGraphKey", "StatisticsArmyGraphKey")]
[ChromeLogicArgsHotkeys("StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsSupportPowersKey", "StatisticsCombatKey", "StatisticsGraphKey",
"StatisticsArmyGraphKey")]
public class ObserverStatsLogic : ChromeLogic
{
readonly ContainerWidget basicStatsHeaders;
readonly ContainerWidget economyStatsHeaders;
readonly ContainerWidget productionStatsHeaders;
readonly ContainerWidget supportPowerStatsHeaders;
readonly ContainerWidget combatStatsHeaders;
readonly ContainerWidget earnedThisMinuteGraphHeaders;
readonly ContainerWidget armyThisMinuteGraphHeaders;
@@ -36,19 +38,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ScrollItemWidget basicPlayerTemplate;
readonly ScrollItemWidget economyPlayerTemplate;
readonly ScrollItemWidget productionPlayerTemplate;
readonly ScrollItemWidget supportPowersPlayerTemplate;
readonly ScrollItemWidget combatPlayerTemplate;
readonly ContainerWidget earnedThisMinuteGraphTemplate;
readonly ContainerWidget armyThisMinuteGraphTemplate;
readonly ContainerWidget earnedThisMinuteGraphContainer;
readonly ContainerWidget armyThisMinuteGraphContainer;
readonly LineGraphWidget earnedThisMinuteGraph;
readonly LineGraphWidget armyThisMinuteGraph;
readonly ScrollItemWidget teamTemplate;
readonly IEnumerable<Player> players;
readonly IOrderedEnumerable<IGrouping<int, Player>> teams;
readonly bool hasTeams;
readonly World world;
readonly WorldRenderer worldRenderer;
readonly string clickSound = ChromeMetrics.Get<string>("ClickSound");
bool noneSelected = true;
[ObjectCreator.UseCtor]
public ObserverStatsLogic(World world, ModData modData, WorldRenderer worldRenderer, Widget widget,
Action onExit, ObserverStatsPanel activePanel, Dictionary<string, MiniYaml> logicArgs)
public ObserverStatsLogic(World world, ModData modData, WorldRenderer worldRenderer, Widget widget, Dictionary<string, MiniYaml> logicArgs)
{
this.world = world;
this.worldRenderer = worldRenderer;
@@ -60,28 +67,49 @@ namespace OpenRA.Mods.Common.Widgets.Logic
statsHotkeys[i] = logicArgs.TryGetValue("Statistics" + keyNames[i] + "Key", out yaml) ? modData.Hotkeys[yaml.Value] : new HotkeyReference();
players = world.Players.Where(p => !p.NonCombatant);
teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
hasTeams = !(teams.Count() == 1 && teams.First().Key == 0);
basicStatsHeaders = widget.Get<ContainerWidget>("BASIC_STATS_HEADERS");
economyStatsHeaders = widget.Get<ContainerWidget>("ECONOMY_STATS_HEADERS");
productionStatsHeaders = widget.Get<ContainerWidget>("PRODUCTION_STATS_HEADERS");
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;
if (ShowScrollBar)
{
playerStatsPanel.ScrollBar = ScrollBar.Left;
AdjustHeader(basicStatsHeaders);
AdjustHeader(economyStatsHeaders);
AdjustHeader(productionStatsHeaders);
AdjustHeader(supportPowerStatsHeaders);
AdjustHeader(combatStatsHeaders);
}
basicPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("BASIC_PLAYER_TEMPLATE");
economyPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("ECONOMY_PLAYER_TEMPLATE");
productionPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("PRODUCTION_PLAYER_TEMPLATE");
supportPowersPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("SUPPORT_POWERS_PLAYER_TEMPLATE");
combatPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("COMBAT_PLAYER_TEMPLATE");
earnedThisMinuteGraphTemplate = playerStatsPanel.Get<ContainerWidget>("EARNED_THIS_MIN_GRAPH_TEMPLATE");
armyThisMinuteGraphTemplate = playerStatsPanel.Get<ContainerWidget>("ARMY_THIS_MIN_GRAPH_TEMPLATE");
earnedThisMinuteGraphContainer = widget.Get<ContainerWidget>("EARNED_THIS_MIN_GRAPH_CONTAINER");
earnedThisMinuteGraph = earnedThisMinuteGraphContainer.Get<LineGraphWidget>("EARNED_THIS_MIN_GRAPH");
armyThisMinuteGraphContainer = widget.Get<ContainerWidget>("ARMY_THIS_MIN_GRAPH_CONTAINER");
armyThisMinuteGraph = armyThisMinuteGraphContainer.Get<LineGraphWidget>("ARMY_THIS_MIN_GRAPH");
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
var statsDropDown = widget.Get<DropDownButtonWidget>("STATS_DROPDOWN");
Func<string, ContainerWidget, Action, StatsDropDownOption> createStatsOption = (title, headers, a) =>
Func<string, ContainerWidget, ScrollItemWidget, Action, StatsDropDownOption> createStatsOption = (title, headers, template, a) =>
{
return new StatsDropDownOption
{
@@ -89,21 +117,40 @@ namespace OpenRA.Mods.Common.Widgets.Logic
IsSelected = () => headers.Visible,
OnClick = () =>
{
noneSelected = false;
ClearStats();
playerStatsPanel.Visible = true;
statsDropDown.GetText = () => title;
if (template != null)
AdjustStatisticsPanel(template);
a();
Ui.ResetTooltips();
}
};
};
var statsDropDownOptions = new StatsDropDownOption[]
{
createStatsOption("Basic", basicStatsHeaders, () => DisplayStats(BasicStats)),
createStatsOption("Economy", economyStatsHeaders, () => DisplayStats(EconomyStats)),
createStatsOption("Production", productionStatsHeaders, () => DisplayStats(ProductionStats)),
createStatsOption("Combat", combatStatsHeaders, () => DisplayStats(CombatStats)),
createStatsOption("Earnings (graph)", earnedThisMinuteGraphHeaders, () => EarnedThisMinuteGraph()),
createStatsOption("Army (graph)", armyThisMinuteGraphHeaders, () => ArmyThisMinuteGraph()),
new StatsDropDownOption
{
Title = "Information: None",
IsSelected = () => noneSelected,
OnClick = () =>
{
noneSelected = true;
statsDropDown.GetText = () => "Information: None";
playerStatsPanel.Visible = false;
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()),
};
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
@@ -113,17 +160,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return item;
};
statsDropDown.OnMouseDown = _ => statsDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 155, statsDropDownOptions, setupItem);
statsDropDownOptions[(int)activePanel].OnClick();
var statsDropDownPanelTemplate = logicArgs.TryGetValue("StatsDropDownPanelTemplate", out yaml) ? yaml.Value : "LABEL_DROPDOWN_TEMPLATE";
var close = widget.GetOrNull<ButtonWidget>("CLOSE");
if (close != null)
close.OnClick = () =>
{
Ui.CloseWindow();
Ui.Root.RemoveChild(widget);
onExit();
};
statsDropDown.OnMouseDown = _ => statsDropDown.ShowDropDown(statsDropDownPanelTemplate, 205, statsDropDownOptions, setupItem);
statsDropDownOptions[0].OnClick();
var keyListener = statsDropDown.Get<LogicKeyListenerWidget>("STATS_DROPDOWN_KEYHANDLER");
keyListener.AddHandler(e =>
@@ -154,53 +194,70 @@ namespace OpenRA.Mods.Common.Widgets.Logic
basicStatsHeaders.Visible = false;
economyStatsHeaders.Visible = false;
productionStatsHeaders.Visible = false;
supportPowerStatsHeaders.Visible = false;
combatStatsHeaders.Visible = false;
earnedThisMinuteGraphHeaders.Visible = false;
armyThisMinuteGraphHeaders.Visible = false;
earnedThisMinuteGraphContainer.Visible = false;
armyThisMinuteGraphContainer.Visible = false;
earnedThisMinuteGraph.GetSeries = null;
armyThisMinuteGraph.GetSeries = null;
}
void EarnedThisMinuteGraph()
{
playerStatsPanel.Visible = false;
earnedThisMinuteGraphHeaders.Visible = true;
var template = earnedThisMinuteGraphTemplate.Clone();
earnedThisMinuteGraphContainer.Visible = true;
var graph = template.Get<LineGraphWidget>("EARNED_THIS_MIN_GRAPH");
graph.GetSeries = () =>
earnedThisMinuteGraph.GetSeries = () =>
players.Select(p => new LineGraphSeries(
p.PlayerName,
p.Color,
(p.PlayerActor.TraitOrDefault<PlayerStatistics>() ?? new PlayerStatistics(p.PlayerActor)).EarnedSamples.Select(s => (float)s)));
playerStatsPanel.AddChild(template);
playerStatsPanel.ScrollToTop();
}
void ArmyThisMinuteGraph()
{
playerStatsPanel.Visible = false;
armyThisMinuteGraphHeaders.Visible = true;
var template = armyThisMinuteGraphTemplate.Clone();
armyThisMinuteGraphContainer.Visible = true;
var graph = template.Get<LineGraphWidget>("ARMY_THIS_MIN_GRAPH");
graph.GetSeries = () =>
armyThisMinuteGraph.GetSeries = () =>
players.Select(p => new LineGraphSeries(
p.PlayerName,
p.Color,
(p.PlayerActor.TraitOrDefault<PlayerStatistics>() ?? new PlayerStatistics(p.PlayerActor)).ArmySamples.Select(s => (float)s)));
playerStatsPanel.AddChild(template);
playerStatsPanel.ScrollToTop();
}
void DisplayStats(Func<Player, ScrollItemWidget> createItem)
{
var teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
foreach (var t in teams)
foreach (var team in teams)
{
var team = t;
var tt = ScrollItemWidget.Setup(teamTemplate, () => false, () => { });
tt.IgnoreMouseOver = true;
tt.Get<LabelWidget>("TEAM").GetText = () => team.Key == 0 ? "No Team" : "Team " + team.Key;
playerStatsPanel.AddChild(tt);
if (hasTeams)
{
var tt = ScrollItemWidget.Setup(teamTemplate, () => false, () => { });
tt.IgnoreMouseOver = true;
var teamLabel = tt.Get<LabelWidget>("TEAM");
teamLabel.GetText = () => team.Key == 0 ? "No Team" : "Team " + team.Key;
tt.Bounds.Width = teamLabel.Bounds.Width = Game.Renderer.Fonts[tt.Font].Measure(tt.Get<LabelWidget>("TEAM").GetText()).X;
var colorBlockWidget = tt.Get<ColorBlockWidget>("TEAM_COLOR");
var scrollBarOffset = playerStatsPanel.ScrollBar != ScrollBar.Hidden
? playerStatsPanel.ScrollbarWidth
: 0;
var boundsWidth = tt.Parent.Bounds.Width - scrollBarOffset;
colorBlockWidget.Bounds.Width = boundsWidth - 200;
var gradient = tt.Get<GradientColorBlockWidget>("TEAM_GRADIENT");
gradient.Bounds.X = boundsWidth - 200;
playerStatsPanel.AddChild(tt);
}
foreach (var p in team)
{
var player = p;
@@ -216,6 +273,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
LobbyUtils.AddPlayerFlagAndName(template, player);
var playerName = template.Get<LabelWidget>("PLAYER");
playerName.GetColor = () => Color.White;
var playerColor = template.Get<ColorBlockWidget>("PLAYER_COLOR");
var playerGradient = template.Get<GradientColorBlockWidget>("PLAYER_GRADIENT");
SetupPlayerColor(player, template, playerColor, playerGradient);
var stats = player.PlayerActor.TraitOrDefault<PlayerStatistics>();
if (stats == null) return template;
template.Get<LabelWidget>("ASSETS_DESTROYED").GetText = () => "$" + stats.KillsCost;
@@ -236,7 +301,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic
LobbyUtils.AddPlayerFlagAndName(template, player);
var playerName = template.Get<LabelWidget>("PLAYER");
playerName.GetColor = () => Color.White;
var playerColor = template.Get<ColorBlockWidget>("PLAYER_COLOR");
var playerGradient = template.Get<GradientColorBlockWidget>("PLAYER_GRADIENT");
SetupPlayerColor(player, template, playerColor, playerGradient);
template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS").GetPlayer = () => player;
template.IgnoreChildMouseOver = false;
return template;
}
ScrollItemWidget SupportPowerStats(Player player)
{
supportPowerStatsHeaders.Visible = true;
var template = SetupPlayerScrollItemWidget(supportPowersPlayerTemplate, player);
LobbyUtils.AddPlayerFlagAndName(template, player);
var playerName = template.Get<LabelWidget>("PLAYER");
playerName.GetColor = () => Color.White;
var playerColor = template.Get<ColorBlockWidget>("PLAYER_COLOR");
var playerGradient = template.Get<GradientColorBlockWidget>("PLAYER_GRADIENT");
SetupPlayerColor(player, template, playerColor, playerGradient);
template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWER_ICONS").GetPlayer = () => player;
template.IgnoreChildMouseOver = false;
@@ -250,6 +343,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
LobbyUtils.AddPlayerFlagAndName(template, player);
var playerName = template.Get<LabelWidget>("PLAYER");
playerName.GetColor = () => Color.White;
var playerColor = template.Get<ColorBlockWidget>("PLAYER_COLOR");
var playerGradient = template.Get<GradientColorBlockWidget>("PLAYER_GRADIENT");
SetupPlayerColor(player, template, playerColor, playerGradient);
var res = player.PlayerActor.Trait<PlayerResources>();
var stats = player.PlayerActor.TraitOrDefault<PlayerStatistics>();
if (stats == null) return template;
@@ -278,6 +379,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
LobbyUtils.AddPlayerFlagAndName(template, player);
var playerName = template.Get<LabelWidget>("PLAYER");
playerName.GetColor = () => Color.White;
var playerColor = template.Get<ColorBlockWidget>("PLAYER_COLOR");
var playerGradient = template.Get<GradientColorBlockWidget>("PLAYER_GRADIENT");
SetupPlayerColor(player, template, playerColor, playerGradient);
var res = player.PlayerActor.Trait<PlayerResources>();
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.Cash + res.Resources);
template.Get<LabelWidget>("EARNED_MIN").GetText = () => AverageEarnedPerMinute(res.Earned);
@@ -302,6 +411,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return template;
}
void SetupPlayerColor(Player player, ScrollItemWidget template, ColorBlockWidget colorBlockWidget, GradientColorBlockWidget gradientColorBlockWidget)
{
var color = Color.FromArgb(128, player.Color.R, player.Color.G, player.Color.B);
var hoverColor = Color.FromArgb(192, player.Color.R, player.Color.G, player.Color.B);
var isMouseOver = new CachedTransform<Widget, bool>(w => w == template || template.Children.Contains(w));
colorBlockWidget.GetColor = () => isMouseOver.Update(Ui.MouseOverWidget) ? hoverColor : color;
gradientColorBlockWidget.GetTopLeftColor = () => isMouseOver.Update(Ui.MouseOverWidget) ? hoverColor : color;
gradientColorBlockWidget.GetBottomLeftColor = () => isMouseOver.Update(Ui.MouseOverWidget) ? hoverColor : color;
gradientColorBlockWidget.GetTopRightColor = () => isMouseOver.Update(Ui.MouseOverWidget) ? hoverColor : Color.Transparent;
gradientColorBlockWidget.GetBottomRightColor = () => isMouseOver.Update(Ui.MouseOverWidget) ? hoverColor : Color.Transparent;
}
ScrollItemWidget SetupPlayerScrollItemWidget(ScrollItemWidget template, Player player)
{
return ScrollItemWidget.Setup(template, () => false, () =>
@@ -312,9 +436,28 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
}
static string MapControl(double control)
void AdjustStatisticsPanel(Widget itemTemplate)
{
return (control * 100).ToString("F1") + "%";
var height = playerStatsPanel.Bounds.Height;
var scrollbarWidth = playerStatsPanel.ScrollBar != ScrollBar.Hidden ? playerStatsPanel.ScrollbarWidth : 0;
playerStatsPanel.Bounds.Width = itemTemplate.Bounds.Width + scrollbarWidth;
if (playerStatsPanel.Bounds.Height < height)
playerStatsPanel.ScrollToTop();
}
void AdjustHeader(ContainerWidget headerTemplate)
{
var offset = playerStatsPanel.ScrollbarWidth;
headerTemplate.Get<ColorBlockWidget>("HEADER_COLOR").Bounds.Width += offset;
headerTemplate.Get<GradientColorBlockWidget>("HEADER_GRADIENT").Bounds.X += offset;
foreach (var headerLabel in headerTemplate.Children.OfType<LabelWidget>())
{
headerLabel.Bounds.X += offset;
}
}
string AverageOrdersPerMinute(double orders)
@@ -324,13 +467,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
string AverageEarnedPerMinute(double earned)
{
return "$" + (world.WorldTick == 0 ? 0 : earned / (world.WorldTick / 1500.0)).ToString("F2");
}
string KillDeathRatio(int killed, int dead)
{
var kdr = (float)killed / Math.Max(1.0, dead);
return kdr.ToString("F2");
return "$" + (world.WorldTick == 0 ? 0 : earned / (world.WorldTick / 1500.0)).ToString("F0");
}
static Color GetPowerColor(PowerState state)
@@ -340,6 +477,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return Color.LimeGreen;
}
// HACK The height of the templates and the scrollpanel needs to be kept in synch
bool ShowScrollBar
{
get { return players.Count() + (hasTeams ? teams.Count() : 0) > 10; }
}
class StatsDropDownOption
{
public string Title;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Widgets
public int IconWidth = 32;
public int IconHeight = 24;
public int IconSpacing = 8;
public int IconSpacing = 1;
public string ClockAnimation = "clock";
public string ClockSequence = "idle";
@@ -41,12 +41,12 @@ namespace OpenRA.Mods.Common.Widgets
public Func<ProductionIcon> GetTooltipIcon;
Dictionary<ProductionQueue, Animation> clocks;
readonly Lazy<TooltipContainerWidget> tooltipContainer;
readonly List<ProductionIcon> productionIcons = new List<ProductionIcon>();
readonly List<Rectangle> productionIconsBounds = new List<Rectangle>();
float2 iconSize;
Rectangle[] iconRects = new Rectangle[0];
ProductionIcon[] icons;
Rectangle renderBounds;
int lastIconIdx;
Lazy<TooltipContainerWidget> tooltipContainer;
[ObjectCreator.UseCtor]
public ObserverProductionIconsWidget(World world, WorldRenderer worldRenderer)
@@ -87,11 +87,13 @@ namespace OpenRA.Mods.Common.Widgets
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
renderBounds = Rectangle.Empty;
}
public override void Draw()
{
productionIcons.Clear();
productionIconsBounds.Clear();
var player = GetPlayer();
if (player == null)
return;
@@ -100,57 +102,75 @@ namespace OpenRA.Mods.Common.Widgets
.Where(a => a.Actor.Owner == player)
.Select((a, i) => new { a.Trait, i });
if (renderBounds != RenderBounds)
{
renderBounds = RenderBounds;
InitIcons(renderBounds);
}
else
for (var i = 0; i < icons.Length; i++)
icons[i].Actor = null;
foreach (var queue in queues)
{
if (!clocks.ContainsKey(queue.Trait))
clocks.Add(queue.Trait, new Animation(world, ClockAnimation));
var current = queue.Trait.AllQueued().FirstOrDefault();
if (current == null || queue.i >= icons.Length)
continue;
var currentItemsByItem = queues
.Select(a => a.Trait.CurrentItem())
.Where(pi => pi != null)
.GroupBy(pr => pr.Item)
.OrderBy(g => g.First().Queue.Info.Type)
.ThenBy(g => g.First().Item)
.ToList();
var faction = queue.Trait.Actor.Owner.Faction.InternalName;
var actor = queue.Trait.AllItems().FirstOrDefault(a => a.Name == current.Item);
Bounds.Width = currentItemsByItem.Count * (IconWidth + IconSpacing);
var queueCol = 0;
foreach (var currentItems in currentItemsByItem)
{
var current = currentItems.OrderBy(pi => pi.Done ? 0 : (pi.Paused ? 2 : 1)).ThenBy(q => q.RemainingTimeActual).First();
var queue = current.Queue;
var faction = queue.Actor.Owner.Faction.InternalName;
var actor = queue.AllItems().FirstOrDefault(a => a.Name == current.Item);
if (actor == null)
continue;
var rsi = actor.TraitInfo<RenderSpritesInfo>();
var icon = new Animation(world, rsi.GetImage(actor, world.Map.Rules.Sequences, faction));
var bi = actor.TraitInfo<BuildableInfo>();
icon.Play(bi.Icon);
var location = new float2(iconRects[queue.i].Location);
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(bi.IconPalette), 0.5f);
var topLeftOffset = new float2(queueCol * (IconWidth + IconSpacing), 0);
icons[queue.i].Actor = actor;
icons[queue.i].ProductionQueue = queue.Trait;
var iconTopLeft = RenderOrigin + topLeftOffset;
var centerPosition = iconTopLeft;
var pio = queue.Trait.Actor.Owner.PlayerActor.TraitsImplementing<IProductionIconOverlay>()
WidgetUtils.DrawSHPCentered(icon.Image, centerPosition + 0.5f * iconSize, worldRenderer.Palette(bi.IconPalette), 0.5f);
productionIcons.Add(new ProductionIcon { Actor = actor, ProductionQueue = current.Queue });
productionIconsBounds.Add(new Rectangle((int)iconTopLeft.X, (int)iconTopLeft.Y, (int)iconSize.X, (int)iconSize.Y));
var pio = queue.Actor.Owner.PlayerActor.TraitsImplementing<IProductionIconOverlay>()
.FirstOrDefault(p => p.IsOverlayActive(actor));
if (pio != null)
WidgetUtils.DrawSHPCentered(pio.Sprite, location + 0.5f * iconSize + pio.Offset(iconSize),
WidgetUtils.DrawSHPCentered(pio.Sprite, centerPosition + 0.5f * iconSize + pio.Offset(iconSize),
worldRenderer.Palette(pio.Palette), 0.5f);
var clock = clocks[queue.Trait];
clock.PlayFetchIndex(ClockSequence,
() => current.TotalTime == 0 ? 0 : ((current.TotalTime - current.RemainingTime)
* (clock.CurrentSequence.Length - 1) / current.TotalTime));
var clock = clocks[queue];
clock.PlayFetchIndex(ClockSequence, () => current.TotalTime == 0 ? 0 :
(current.TotalTime - current.RemainingTime) * (clock.CurrentSequence.Length - 1) / current.TotalTime);
clock.Tick();
WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer.Palette(ClockPalette), 0.5f);
WidgetUtils.DrawSHPCentered(clock.Image, centerPosition + 0.5f * iconSize, worldRenderer.Palette(ClockPalette), 0.5f);
var tiny = Game.Renderer.Fonts["Tiny"];
var text = GetOverlayForItem(current, timestep);
tiny.DrawTextWithContrast(text,
location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0),
centerPosition + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),
Color.White, Color.Black, 1);
if (currentItems.Count() > 1)
{
var bold = Game.Renderer.Fonts["Small"];
text = currentItems.Count().ToString();
bold.DrawTextWithContrast(text, centerPosition + new float2(16, 0) - new float2(bold.Measure(text).X / 2, 0),
Color.White, Color.Black, 1);
}
queueCol++;
}
}
@@ -172,9 +192,19 @@ namespace OpenRA.Mods.Common.Widgets
public override void MouseEntered()
{
if (TooltipContainer != null)
tooltipContainer.Value.SetTooltip(TooltipTemplate,
new WidgetArgs() { { "player", GetPlayer() }, { "getTooltipIcon", GetTooltipIcon } });
if (TooltipContainer == null)
return;
for (var i = 0; i < productionIconsBounds.Count; i++)
{
if (!productionIconsBounds[i].Contains(Viewport.LastMousePos))
continue;
TooltipIcon = productionIcons[i];
break;
}
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs { { "player", GetPlayer() }, { "getTooltipIcon", GetTooltipIcon } });
}
public override void MouseExited()
@@ -187,34 +217,26 @@ namespace OpenRA.Mods.Common.Widgets
public override void Tick()
{
if (TooltipIcon != null && iconRects[lastIconIdx].Contains(Viewport.LastMousePos))
if (lastIconIdx >= productionIconsBounds.Count)
{
TooltipIcon = null;
return;
}
if (TooltipIcon != null && productionIconsBounds[lastIconIdx].Contains(Viewport.LastMousePos))
return;
for (var i = 0; i < iconRects.Length; i++)
for (var i = 0; i < productionIconsBounds.Count; i++)
{
if (iconRects[i].Contains(Viewport.LastMousePos))
{
lastIconIdx = i;
TooltipIcon = icons[i];
return;
}
if (!productionIconsBounds[i].Contains(Viewport.LastMousePos))
continue;
lastIconIdx = i;
TooltipIcon = productionIcons[i];
return;
}
TooltipIcon = null;
}
void InitIcons(Rectangle renderBounds)
{
var iconWidthWithSpacing = IconWidth + IconSpacing;
var numOfIcons = renderBounds.Width / iconWidthWithSpacing;
iconRects = new Rectangle[numOfIcons];
icons = new ProductionIcon[numOfIcons];
for (var i = 0; i < numOfIcons; i++)
{
iconRects[i] = new Rectangle(renderBounds.X + i * iconWidthWithSpacing, renderBounds.Y, IconWidth, IconHeight);
icons[i] = new ProductionIcon();
}
}
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Widgets
public int IconWidth = 32;
public int IconHeight = 24;
public int IconSpacing = 8;
public int IconSpacing = 1;
public string ClockAnimation = "clock";
public string ClockSequence = "idle";
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Widgets
var tiny = Game.Renderer.Fonts["Tiny"];
var text = GetOverlayForItem(item, timestep);
tiny.DrawTextWithContrast(text,
location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0),
location + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),
Color.White, Color.Black, 1);
}
}