Add a backup for unloaded bots
This commit is contained in:
@@ -249,11 +249,26 @@ namespace OpenRA
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetMessage(string key, object[] args = null)
|
public string GetMessage(string key, object[] args = null)
|
||||||
{
|
{
|
||||||
// PERF: instead of loading mod level strings per each MapPreview, reuse the already loaded one in FluentProvider.
|
if (TryGetMessage(key, out var message, args))
|
||||||
if (FluentProvider.TryGetModMessage(key, out var message, args))
|
|
||||||
return message;
|
return message;
|
||||||
|
|
||||||
return innerData.FluentBundle?.GetMessage(key, args) ?? key;
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Functionality mirrors <see cref="FluentProvider.TryGetMessage"/>, except instead of using
|
||||||
|
/// loaded <see cref="Map"/>'s fluent bundle as backup, we use this <see cref="MapPreview"/>'s.
|
||||||
|
/// </summary>
|
||||||
|
public bool TryGetMessage(string key, out string message, object[] args = null)
|
||||||
|
{
|
||||||
|
// PERF: instead of loading mod level strings per each MapPreview, reuse the already loaded one in FluentProvider.
|
||||||
|
if (FluentProvider.TryGetModMessage(key, out message, args))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (innerData.FluentBundle == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return innerData.FluentBundle.TryGetMessage(key, out message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite minimap;
|
Sprite minimap;
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
[FluentReference]
|
[FluentReference]
|
||||||
const string Bots = "options-lobby-slot.bots";
|
const string Bots = "options-lobby-slot.bots";
|
||||||
|
|
||||||
|
[FluentReference]
|
||||||
|
const string BotPlayer = "label-bot-player";
|
||||||
|
|
||||||
[FluentReference]
|
[FluentReference]
|
||||||
const string BotsDisabled = "options-lobby-slot.bots-disabled";
|
const string BotsDisabled = "options-lobby-slot.bots-disabled";
|
||||||
|
|
||||||
@@ -432,7 +435,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var font = Game.Renderer.Fonts[label.Font];
|
var font = Game.Renderer.Fonts[label.Font];
|
||||||
|
|
||||||
var clientName = new CachedTransform<MapStatus, string>(s =>
|
var clientName = new CachedTransform<MapStatus, string>(s =>
|
||||||
WidgetUtils.TruncateText(c.IsBot ? map.GetMessage(c.Name) : c.Name, label.Bounds.Width, font));
|
{
|
||||||
|
var name = c.Name;
|
||||||
|
if (c.IsBot && !map.TryGetMessage(c.Name, out name))
|
||||||
|
name = FluentProvider.GetMessage(BotPlayer);
|
||||||
|
|
||||||
|
return WidgetUtils.TruncateText(name, label.Bounds.Width, font);
|
||||||
|
});
|
||||||
|
|
||||||
label.GetText = () => clientName.Update(map.Status);
|
label.GetText = () => clientName.Update(map.Status);
|
||||||
|
|
||||||
@@ -453,7 +462,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var closed = FluentProvider.GetMessage(Closed);
|
var closed = FluentProvider.GetMessage(Closed);
|
||||||
var open = FluentProvider.GetMessage(Open);
|
var open = FluentProvider.GetMessage(Open);
|
||||||
|
|
||||||
var clientName = new CachedTransform<MapStatus, string>(s => c.IsBot ? map.GetMessage(c.Name) : c.Name);
|
var clientName = new CachedTransform<MapStatus, string>(s =>
|
||||||
|
{
|
||||||
|
if (c.IsBot)
|
||||||
|
{
|
||||||
|
if (map.TryGetMessage(c.Name, out var message))
|
||||||
|
return message;
|
||||||
|
else
|
||||||
|
return FluentProvider.GetMessage(BotPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Name;
|
||||||
|
});
|
||||||
|
|
||||||
slot.GetText = () => truncated.Update(c != null ?
|
slot.GetText = () => truncated.Update(c != null ?
|
||||||
clientName.Update(map.Status)
|
clientName.Update(map.Status)
|
||||||
: s.Closed ? closed : open);
|
: s.Closed ? closed : open);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BeaconLib;
|
using BeaconLib;
|
||||||
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Server;
|
using OpenRA.Server;
|
||||||
@@ -49,6 +50,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
[FluentReference("bots")]
|
[FluentReference("bots")]
|
||||||
const string BotsLabel = "label-bots-count";
|
const string BotsLabel = "label-bots-count";
|
||||||
|
|
||||||
|
[FluentReference]
|
||||||
|
const string BotPlayer = "label-bot-player";
|
||||||
|
|
||||||
[FluentReference("spectators")]
|
[FluentReference("spectators")]
|
||||||
const string SpectatorsLabel = "label-spectators-count";
|
const string SpectatorsLabel = "label-spectators-count";
|
||||||
|
|
||||||
@@ -604,15 +608,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
foreach (var option in kv.Value)
|
foreach (var option in kv.Value)
|
||||||
{
|
{
|
||||||
var o = option;
|
var o = option;
|
||||||
var playerName = o.IsBot ? currentMap.GetMessage(o.Name) : o.Name;
|
var playerName = new CachedTransform<(MapStatus, int, SpriteFont), string>(s =>
|
||||||
|
{
|
||||||
|
var name = o.IsBot
|
||||||
|
? currentMap.TryGetMessage(o.Name, out var msg) ? msg : FluentProvider.GetMessage(BotPlayer)
|
||||||
|
: o.Name;
|
||||||
|
|
||||||
|
return WidgetUtils.TruncateText(name, s.Item2, s.Item3);
|
||||||
|
});
|
||||||
|
|
||||||
var item = ScrollItemWidget.Setup(clientTemplate, () => false, () => { });
|
var item = ScrollItemWidget.Setup(clientTemplate, () => false, () => { });
|
||||||
if (!o.IsSpectator && server.Mod == modData.Manifest.Id)
|
if (!o.IsSpectator && server.Mod == modData.Manifest.Id)
|
||||||
{
|
{
|
||||||
var label = item.Get<LabelWidget>("LABEL");
|
var label = item.Get<LabelWidget>("LABEL");
|
||||||
var font = Game.Renderer.Fonts[label.Font];
|
var font = Game.Renderer.Fonts[label.Font];
|
||||||
var name = WidgetUtils.TruncateText(playerName, label.Bounds.Width, font);
|
label.GetText = () => playerName.Update((currentMap.Status, label.Bounds.Width, font));
|
||||||
label.GetText = () => name;
|
|
||||||
label.GetColor = () => o.Color;
|
label.GetColor = () => o.Color;
|
||||||
|
|
||||||
var flag = item.Get<ImageWidget>("FLAG");
|
var flag = item.Get<ImageWidget>("FLAG");
|
||||||
@@ -624,11 +634,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
var label = item.Get<LabelWidget>("NOFLAG_LABEL");
|
var label = item.Get<LabelWidget>("NOFLAG_LABEL");
|
||||||
var font = Game.Renderer.Fonts[label.Font];
|
var font = Game.Renderer.Fonts[label.Font];
|
||||||
var name = WidgetUtils.TruncateText(playerName, label.Bounds.Width, font);
|
|
||||||
|
|
||||||
// Force spectator color to prevent spoofing by the server
|
// Force spectator color to prevent spoofing by the server
|
||||||
var color = o.IsSpectator ? Color.White : o.Color;
|
var color = o.IsSpectator ? Color.White : o.Color;
|
||||||
label.GetText = () => name;
|
label.GetText = () => playerName.Update((currentMap.Status, label.Bounds.Width, font));
|
||||||
label.GetColor = () => color;
|
label.GetColor = () => color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,7 +774,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var preview = modData.MapCache[game.Map];
|
var preview = modData.MapCache[game.Map];
|
||||||
var tooltip = new CachedTransform<MapStatus, string>(s =>
|
var tooltip = new CachedTransform<MapStatus, string>(s =>
|
||||||
{
|
{
|
||||||
var displayClients = game.Clients.Select(c => c.IsBot ? preview.GetMessage(c.Name) : c.Name);
|
var displayClients = game.Clients.Select(c => c.IsBot
|
||||||
|
? preview.TryGetMessage(c.Name, out var msg) ? msg : FluentProvider.GetMessage(BotPlayer)
|
||||||
|
: c.Name);
|
||||||
|
|
||||||
if (game.Clients.Length > 10)
|
if (game.Clients.Length > 10)
|
||||||
displayClients = displayClients
|
displayClients = displayClients
|
||||||
.Take(9)
|
.Take(9)
|
||||||
|
|||||||
@@ -205,6 +205,9 @@ label-chat-availability =
|
|||||||
*[other] Chat available in { $seconds } seconds...
|
*[other] Chat available in { $seconds } seconds...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## LobbyLogic, ServerListLogic
|
||||||
|
label-bot-player = AI Player
|
||||||
|
|
||||||
## IngameMenuLogic
|
## IngameMenuLogic
|
||||||
menu-ingame =
|
menu-ingame =
|
||||||
.leave = Leave
|
.leave = Leave
|
||||||
|
|||||||
Reference in New Issue
Block a user