Add lobby tooltips for registered / anonymous players.
This commit is contained in:
@@ -10,7 +10,11 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -18,7 +22,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public class LocalProfileLogic : ChromeLogic
|
||||
{
|
||||
readonly LocalPlayerProfile localProfile;
|
||||
readonly Widget detailsContainer;
|
||||
bool notFound;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
@@ -75,8 +78,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
destroyKey.OnClick = localProfile.DeleteKeypair;
|
||||
destroyKey.IsDisabled = minimalProfile;
|
||||
|
||||
detailsContainer = widget.Get("PROFILE_DETAILS");
|
||||
detailsContainer.IsVisible = () => localProfile.State == LocalPlayerProfile.LinkState.Linked && !minimalProfile();
|
||||
localProfile.RefreshPlayerData(() => RefreshComplete(false));
|
||||
}
|
||||
|
||||
@@ -88,4 +89,129 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Game.RunAfterTick(Ui.ResetTooltips);
|
||||
}
|
||||
}
|
||||
|
||||
public class RegisteredProfileTooltipLogic : ChromeLogic
|
||||
{
|
||||
readonly PlayerDatabase playerDatabase;
|
||||
PlayerProfile profile;
|
||||
bool profileLoaded;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public RegisteredProfileTooltipLogic(Widget widget, WorldRenderer worldRenderer, ModData modData, Session.Client client)
|
||||
{
|
||||
playerDatabase = modData.Manifest.Get<PlayerDatabase>();
|
||||
|
||||
var header = widget.Get("HEADER");
|
||||
|
||||
var profileHeader = header.Get("PROFILE_HEADER");
|
||||
var messageHeader = header.Get("MESSAGE_HEADER");
|
||||
var message = messageHeader.Get<LabelWidget>("MESSAGE");
|
||||
var messageFont = Game.Renderer.Fonts[message.Font];
|
||||
|
||||
profileHeader.IsVisible = () => profileLoaded;
|
||||
messageHeader.IsVisible = () => !profileLoaded;
|
||||
|
||||
var profileWidth = 0;
|
||||
var messageText = "Loading player profile...";
|
||||
var messageWidth = messageFont.Measure(messageText).X + 2 * message.Bounds.Left;
|
||||
|
||||
Action<DownloadDataCompletedEventArgs> onQueryComplete = i =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (i.Error == null)
|
||||
{
|
||||
var yaml = MiniYaml.FromString(Encoding.UTF8.GetString(i.Result)).First();
|
||||
if (yaml.Key == "Player")
|
||||
{
|
||||
profile = FieldLoader.Load<PlayerProfile>(yaml.Value);
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
var nameLabel = profileHeader.Get<LabelWidget>("PROFILE_NAME");
|
||||
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
|
||||
var rankLabel = profileHeader.Get<LabelWidget>("PROFILE_RANK");
|
||||
var rankFont = Game.Renderer.Fonts[rankLabel.Font];
|
||||
|
||||
var adminContainer = profileHeader.Get("GAME_ADMIN");
|
||||
var adminLabel = adminContainer.Get<LabelWidget>("LABEL");
|
||||
var adminFont = Game.Renderer.Fonts[adminLabel.Font];
|
||||
|
||||
var headerSizeOffset = profileHeader.Bounds.Height - messageHeader.Bounds.Height;
|
||||
|
||||
nameLabel.GetText = () => profile.ProfileName;
|
||||
rankLabel.GetText = () => profile.ProfileRank;
|
||||
|
||||
profileWidth = Math.Max(profileWidth, nameFont.Measure(profile.ProfileName).X + 2 * nameLabel.Bounds.Left);
|
||||
profileWidth = Math.Max(profileWidth, rankFont.Measure(profile.ProfileRank).X + 2 * rankLabel.Bounds.Left);
|
||||
|
||||
header.Bounds.Height += headerSizeOffset;
|
||||
if (client.IsAdmin)
|
||||
{
|
||||
profileWidth = Math.Max(profileWidth, adminFont.Measure(adminLabel.Text).X + 2 * adminLabel.Bounds.Left);
|
||||
|
||||
adminContainer.IsVisible = () => true;
|
||||
profileHeader.Bounds.Height += adminLabel.Bounds.Height;
|
||||
header.Bounds.Height += adminLabel.Bounds.Height;
|
||||
}
|
||||
|
||||
profileWidth = Math.Min(profileWidth, widget.Bounds.Width);
|
||||
header.Bounds.Width = widget.Bounds.Width = profileWidth;
|
||||
widget.Bounds.Height = header.Bounds.Height;
|
||||
|
||||
profileLoaded = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Write("debug", "Failed to parse player data result with exception: {0}", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (profile == null)
|
||||
{
|
||||
messageText = "Failed to load player profile.";
|
||||
messageWidth = messageFont.Measure(messageText).X + 2 * message.Bounds.Left;
|
||||
header.Bounds.Width = widget.Bounds.Width = messageWidth;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
message.GetText = () => messageText;
|
||||
header.Bounds.Height += messageHeader.Bounds.Height;
|
||||
header.Bounds.Width = widget.Bounds.Width = messageWidth;
|
||||
widget.Bounds.Height = header.Bounds.Height;
|
||||
|
||||
new Download(playerDatabase.Profile + client.Fingerprint, _ => { }, onQueryComplete);
|
||||
}
|
||||
}
|
||||
|
||||
public class AnonymousProfileTooltipLogic : ChromeLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public AnonymousProfileTooltipLogic(Widget widget, OrderManager orderManager, Session.Client client)
|
||||
{
|
||||
var address = LobbyUtils.GetExternalIP(client, orderManager);
|
||||
var cachedDescriptiveIP = address ?? "Unknown IP";
|
||||
|
||||
var nameLabel = widget.Get<LabelWidget>("NAME");
|
||||
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
|
||||
widget.Bounds.Width = nameFont.Measure(nameLabel.Text).X + 2 * nameLabel.Bounds.Left;
|
||||
|
||||
var ipLabel = widget.Get<LabelWidget>("IP");
|
||||
ipLabel.GetText = () => cachedDescriptiveIP;
|
||||
|
||||
var locationLabel = widget.Get<LabelWidget>("LOCATION");
|
||||
var cachedCountryLookup = GeoIP.LookupCountry(address);
|
||||
locationLabel.GetText = () => cachedCountryLookup;
|
||||
|
||||
if (client.IsAdmin)
|
||||
{
|
||||
var adminLabel = widget.Get("GAME_ADMIN");
|
||||
adminLabel.IsVisible = () => client.IsAdmin;
|
||||
widget.Bounds.Height += adminLabel.Bounds.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user