Add a UI indicator for bot players.

This commit is contained in:
Matthias Mailänder
2024-07-26 19:42:38 +02:00
committed by Gustas
parent 9761a68cd4
commit c24913ea24
24 changed files with 82 additions and 9 deletions

View File

@@ -354,27 +354,32 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public static void SetupProfileWidget(Widget parent, Session.Client c, OrderManager orderManager, WorldRenderer worldRenderer)
{
var visible = c != null && c.Bot == null;
var profile = parent.GetOrNull<ImageWidget>("PROFILE");
if (profile != null)
{
var imageName = (c != null && c.IsAdmin ? "admin-" : "player-")
+ (c.Fingerprint != null ? "registered" : "anonymous");
var imageName = c.IsBot ? "bot" :
c.IsAdmin ? "admin-" :
"player-";
if (!c.IsBot)
imageName += c.Fingerprint != null ? "registered" : "anonymous";
profile.GetImageName = () => imageName;
profile.IsVisible = () => visible;
profile.IsVisible = () => true;
}
var profileTooltip = parent.GetOrNull<ClientTooltipRegionWidget>("PROFILE_TOOLTIP");
if (profileTooltip != null)
{
if (c != null && c.Fingerprint != null)
if (c.Fingerprint != null)
profileTooltip.Template = "REGISTERED_PLAYER_TOOLTIP";
if (visible)
profileTooltip.Bind(orderManager, worldRenderer, c);
if (c.IsBot)
profileTooltip.Template = "BOT_TOOLTIP";
profileTooltip.IsVisible = () => visible;
profileTooltip.Bind(orderManager, worldRenderer, c);
profileTooltip.IsVisible = () => true;
}
}

View File

@@ -352,4 +352,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
}
public class BotTooltipLogic : ChromeLogic
{
[TranslationReference("name")]
const string BotManagedBy = "label-bot-managed-by-tooltip";
[ObjectCreator.UseCtor]
public BotTooltipLogic(OrderManager orderManager, Widget widget, Session.Client client)
{
var nameLabel = widget.Get<LabelWidget>("NAME");
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
var controller = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.Index == client.BotControllerClientIndex);
if (controller != null)
nameLabel.GetText = () => TranslationProvider.GetString(BotManagedBy, Translation.Arguments("name", controller.Name));
widget.Bounds.Width = nameFont.Measure(nameLabel.GetText()).X + 2 * nameLabel.Bounds.Left;
}
}
}

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Widgets
public SpawnOccupant(Session.Client client)
{
Color = client.Color;
PlayerName = client.IsBot ? TranslationProvider.GetString(client.Name) : client.Name;;
PlayerName = client.IsBot ? TranslationProvider.GetString(client.Name) : client.Name;
Team = client.Team;
Faction = client.Faction;
SpawnPoint = client.SpawnPoint;