105 lines
3.4 KiB
C#
105 lines
3.4 KiB
C#
using Content.Shared._Sunrise.SunriseCCVars;
|
|
using Content.Sunrise.Interfaces.Client;
|
|
using Content.Sunrise.Interfaces.Shared;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Client._Sunrise.UserProfile;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class UserProfile : Control
|
|
{
|
|
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IUriOpener _uri = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
private readonly IClientServiceAuthManager? _serviceAuthManager;
|
|
private readonly ISharedSponsorsManager? _sponsorsManager;
|
|
|
|
public UserProfile()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
RobustXamlLoader.Load(this);
|
|
|
|
IoCManager.Instance!.TryResolveType(out _sponsorsManager);
|
|
IoCManager.Instance!.TryResolveType(out _serviceAuthManager);
|
|
|
|
BuySponsorButton.Disabled = _cfg.GetCVar(SunriseCCVars.InfoLinksDonate) == "";
|
|
|
|
if (_serviceAuthManager == null || _sponsorsManager == null)
|
|
return;
|
|
|
|
BuySponsorButton.OnPressed += BuySponsorPressed;
|
|
LinkTelegramButton.OnPressed += LinkTelegramPressed;
|
|
LinkDiscordButton.OnPressed += LinkDiscordPressed;
|
|
InfoSponsorButton.OnPressed += InfoSponsorPressed;
|
|
|
|
_serviceAuthManager.LoadedServiceLinkedServices += RefreshServiceLinkedServices;
|
|
_sponsorsManager.LoadedSponsorData += RefreshSponsorData;
|
|
}
|
|
|
|
private void RefreshSponsorData()
|
|
{
|
|
if (_sponsorsManager == null)
|
|
return;
|
|
|
|
if (_playerManager.LocalSession != null)
|
|
{
|
|
if (!_sponsorsManager.ClientIsSponsor())
|
|
return;
|
|
|
|
_sponsorsManager.TryGetOocTitle(_playerManager.LocalSession.UserId, out var sponsorTitle);
|
|
SponsorTierName.Text = sponsorTitle;
|
|
}
|
|
}
|
|
|
|
private void RefreshServiceLinkedServices(List<LinkedServiceData> linkedServices)
|
|
{
|
|
if (_serviceAuthManager == null)
|
|
return;
|
|
|
|
foreach (var serviceAuthData in _serviceAuthManager.ServiceLinkedServices)
|
|
{
|
|
switch (serviceAuthData.ServiceType)
|
|
{
|
|
case ServiceType.Discord:
|
|
LinkDiscordButton.Visible = false;
|
|
LinkedDiscordName.Text = serviceAuthData.Username;
|
|
break;
|
|
case ServiceType.Telegram:
|
|
LinkTelegramButton.Visible = false;
|
|
LinkedTelegramName.Text = serviceAuthData.Username;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void BuySponsorPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
_uri.OpenUri(_cfg.GetCVar(SunriseCCVars.InfoLinksDonate));
|
|
}
|
|
|
|
private void LinkTelegramPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
if (_serviceAuthManager == null)
|
|
return;
|
|
|
|
_serviceAuthManager.ToggleWindow(ServiceType.Telegram);
|
|
}
|
|
|
|
private void LinkDiscordPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
if (_serviceAuthManager == null)
|
|
return;
|
|
|
|
_serviceAuthManager.ToggleWindow(ServiceType.Discord);
|
|
}
|
|
|
|
private void InfoSponsorPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
|
|
}
|
|
}
|