Improves observer camera focus fallback when the player's (or bot's) Construction Yard is destroyed
Currently, when an observer clicks on a player's name in the stats panel, the camera centers on that player's Construction Yard. However, if the Construction Yard has been destroyed, the click does nothing. This commit searches for the Construction Yard, then a MCV, then any remaining building.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
a6c58c0f68
commit
156122f9e3
@@ -546,12 +546,32 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
return ScrollItemWidget.Setup(template, () => false, () =>
|
||||
{
|
||||
var playerBase = world.ActorsHavingTrait<BaseBuilding>().FirstOrDefault(a => !a.IsDead && a.Owner == player);
|
||||
if (playerBase != null)
|
||||
worldRenderer.Viewport.Center(playerBase.CenterPosition);
|
||||
var targetActor = FindPlayerBaseActor(player);
|
||||
if (targetActor != null)
|
||||
worldRenderer.Viewport.Center(targetActor.CenterPosition);
|
||||
});
|
||||
}
|
||||
|
||||
Actor FindPlayerBaseActor(Player player)
|
||||
{
|
||||
// Priority 1: Primary BaseBuilding (Construction Yard or MCV), closest to viewport
|
||||
var primaryBase = world.ActorsHavingTrait<BaseBuilding>()
|
||||
.Where(a => a.Owner == player)
|
||||
.OrderByDescending(a => a.IsPrimaryBuilding())
|
||||
.ThenBy(a => (worldRenderer.Viewport.CenterPosition - a.CenterPosition).LengthSquared)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (primaryBase != null)
|
||||
return primaryBase;
|
||||
|
||||
// Priority 2: Any selectable Building (fallback), closest to viewport
|
||||
var building = world.ActorsHavingTrait<Building>()
|
||||
.OrderBy(a => (worldRenderer.Viewport.CenterPosition - a.CenterPosition).LengthSquared)
|
||||
.FirstOrDefault(a => a.Owner == player && a.Info.HasTraitInfo<SelectableInfo>());
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
void AdjustStatisticsPanel(Widget itemTemplate)
|
||||
{
|
||||
var height = playerStatsPanel.Bounds.Height;
|
||||
|
||||
Reference in New Issue
Block a user