159 lines
5.4 KiB
C#
159 lines
5.4 KiB
C#
using Content.Shared._Sunrise.MentorHelp;
|
|
using Content.Shared.Database;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Input;
|
|
using Robust.Shared.Localization;
|
|
|
|
namespace Content.Client._Sunrise.MentorHelp
|
|
{
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class TicketEntryControl : Control
|
|
{
|
|
[Dependency] private readonly ILocalizationManager _loc = default!;
|
|
|
|
private static readonly Color NormalColor = Color.FromHex("#202023");
|
|
private static readonly Color UnreadColor = Color.FromHex("#4A1F1F");
|
|
private static readonly Color AuthorUnreadColor = Color.FromHex("#17395C");
|
|
private static readonly Color UnassignedColor = Color.FromHex("#1E3A1E");
|
|
private static readonly Color ClosedColor = Color.FromHex("#3B0F0F");
|
|
private static readonly Color AwaitingColor = Color.FromHex("#3A2F12");
|
|
private static readonly Color UnassignedAssigneeLabelColor = Color.FromHex("#7CFF7C");
|
|
|
|
private const float HoverColorLerp = 0.06f;
|
|
|
|
private MentorHelpTicketData? _ticketData;
|
|
private bool _newMessageFromAuthor;
|
|
private bool _isHovering;
|
|
|
|
public event Action<MentorHelpTicketData>? OnTicketSelected;
|
|
|
|
public TicketEntryControl()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
TooltipDelay = 0.5f;
|
|
|
|
BackgroundColorPanel.PanelOverride = new StyleBoxFlat
|
|
{
|
|
BackgroundColor = NormalColor
|
|
};
|
|
|
|
BackgroundColorPanel.OnMouseEntered += args =>
|
|
{
|
|
_isHovering = true;
|
|
UpdateBackgroundColor();
|
|
};
|
|
|
|
BackgroundColorPanel.OnMouseExited += args =>
|
|
{
|
|
_isHovering = false;
|
|
UpdateBackgroundColor();
|
|
};
|
|
|
|
BackgroundColorPanel.OnKeyBindDown += args =>
|
|
{
|
|
if (args.Function != EngineKeyFunctions.Use)
|
|
return;
|
|
|
|
if (_ticketData != null)
|
|
OnTicketSelected?.Invoke(_ticketData);
|
|
};
|
|
}
|
|
|
|
public void UpdateData(MentorHelpTicketData ticketData)
|
|
{
|
|
_ticketData = ticketData;
|
|
|
|
IdLabel.Text = $"#{ticketData.Id}";
|
|
PlayerLabel.Text = ticketData.PlayerName;
|
|
|
|
AssignedLabel.Text = ticketData.AssignedToName ?? _loc.GetString("mentor-help-unassigned");
|
|
AssignedLabel.FontColorOverride = ticketData.AssignedToUserId == null
|
|
&& ticketData.Status != MentorHelpTicketStatus.Closed
|
|
? UnassignedAssigneeLabelColor
|
|
: null;
|
|
|
|
SubjectLabel.Text = ticketData.Subject;
|
|
UpdateStatusLabel();
|
|
UpdateBackgroundColor();
|
|
}
|
|
|
|
public void SetNewMessageFromAuthor(bool newMessageFromAuthor)
|
|
{
|
|
if (_newMessageFromAuthor == newMessageFromAuthor)
|
|
return;
|
|
|
|
_newMessageFromAuthor = newMessageFromAuthor;
|
|
UpdateStatusLabel();
|
|
UpdateBackgroundColor();
|
|
}
|
|
|
|
private void UpdateStatusLabel()
|
|
{
|
|
if (_ticketData == null)
|
|
return;
|
|
|
|
var statusText = GetStatusText(_ticketData.Status);
|
|
StatusLabel.Text = statusText;
|
|
}
|
|
|
|
private void UpdateBackgroundColor()
|
|
{
|
|
if (BackgroundColorPanel.PanelOverride is not StyleBoxFlat panel || _ticketData == null)
|
|
return;
|
|
|
|
var isUnread = _ticketData.HasUnreadMessages;
|
|
var isAuthorUnread = isUnread && _newMessageFromAuthor;
|
|
var isUnassigned = !isUnread && _ticketData.AssignedToUserId == null;
|
|
var isClosed = _ticketData.Status == MentorHelpTicketStatus.Closed;
|
|
var isAwaiting = _ticketData.Status == MentorHelpTicketStatus.AwaitingResponse;
|
|
|
|
var normal = GetNormalBackgroundColor(isClosed, isAwaiting, isAuthorUnread, isUnread, isUnassigned);
|
|
var hover = Color.InterpolateBetween(normal, Color.White, HoverColorLerp);
|
|
|
|
panel.BackgroundColor = _isHovering ? hover : normal;
|
|
}
|
|
|
|
private static Color GetNormalBackgroundColor(
|
|
bool isClosed,
|
|
bool isAwaiting,
|
|
bool isAuthorUnread,
|
|
bool isUnread,
|
|
bool isUnassigned)
|
|
{
|
|
if (isClosed)
|
|
return ClosedColor;
|
|
|
|
if (isAwaiting)
|
|
return AwaitingColor;
|
|
|
|
if (isAuthorUnread)
|
|
return AuthorUnreadColor;
|
|
|
|
if (isUnread)
|
|
return UnreadColor;
|
|
|
|
if (isUnassigned)
|
|
return UnassignedColor;
|
|
|
|
return NormalColor;
|
|
|
|
}
|
|
|
|
private string GetStatusText(MentorHelpTicketStatus status)
|
|
{
|
|
return status switch
|
|
{
|
|
MentorHelpTicketStatus.Open => _loc.GetString("mentor-help-status-open"),
|
|
MentorHelpTicketStatus.Assigned => _loc.GetString("mentor-help-status-assigned"),
|
|
MentorHelpTicketStatus.AwaitingResponse => _loc.GetString("mentor-help-status-awaiting"),
|
|
MentorHelpTicketStatus.Closed => _loc.GetString("mentor-help-status-closed"),
|
|
_ => _loc.GetString("mentor-help-status-unknown")
|
|
};
|
|
}
|
|
}
|
|
}
|