mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 05:59:03 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description This adds the Time Transfer Panel that Goobstation uses. This panel enables Admins to do Time Transfers without commands and makes their lives easier. This immediately has access to all playtime trackers and allows an Admin to Add Time and/or Set Time (overwriting the previous time) for any job role. It also enables extra strings since I ported from Wizden upstream as well, which can be seen in the commit history. A thing of note when testing this and using it in a server: the times **DO NOT UPDATE** for Client until your **RELOG**. This is how it works on Goobstation as well. The time adding process is faster and will be easier tool. This is tied to the AdminFlags.Admin so it can be customized on a per-server basis if a custom flag is added. --- # TODO - [x] Port Upstream Role Define. - [x] Port string extras for playtime commands. - [x] Port Time Transfer Panel - [x] Remove Overall (it just doesn't work on Goob either). --- <details><summary><h1>Media</h1></summary> <p>          </p> </details> --- # Changelog 🆑 ADMIN: - add: Add Time Transfer Panel --------- Co-authored-by: BombasterDS <115770678+BombasterDS@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: flyingkarii <123355664+flyingkarii@users.noreply.github.com> (cherry picked from commit a05bbce7491677a27656fd67ee72fb8dbdb4c53c)
211 lines
6.1 KiB
C#
211 lines
6.1 KiB
C#
using Content.Shared._Goobstation.Administration;
|
|
using Content.Shared.Roles;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
using System.Linq;
|
|
|
|
namespace Content.Client._Goobstation.Administration.UI.TimeTransferPanel;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class TimeTransferPanel : DefaultWindow
|
|
{
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
private readonly SpriteSystem _spriteSystem;
|
|
|
|
public Action<(string playerId, List<TimeTransferData> transferList, bool overwrite)>? OnTransferMessageSend;
|
|
private TimeSpan? SetButtonResetOn { get; set; }
|
|
|
|
public TimeTransferPanel()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
_spriteSystem = _entityManager.System<SpriteSystem>();
|
|
|
|
AddTimeButton.OnButtonUp += OnAddTimeButtonPressed;
|
|
SetTimeButton.OnButtonUp += OnSetTimeButtonPressed;
|
|
GroupCheckbox.OnPressed += OnGroupCheckboxPressed;
|
|
|
|
JobSearch.OnTextChanged += OnJobSearchTextChanged;
|
|
|
|
PopulateJobs();
|
|
UpdateGroup();
|
|
UpdateWarning(" ", Color.LightGreen);
|
|
}
|
|
|
|
public void PopulateJobs()
|
|
{
|
|
var jobs = _prototypeManager.EnumeratePrototypes<JobPrototype>()
|
|
.OrderBy(job => job.LocalizedName)
|
|
.ToList();
|
|
|
|
foreach(var job in jobs)
|
|
{
|
|
var jobEntry = new TimeTransferEntry(job, _spriteSystem, _prototypeManager);
|
|
JobContainer.AddChild(jobEntry);
|
|
}
|
|
}
|
|
|
|
public void UpdateFlag(bool hasFlag)
|
|
{
|
|
AddTimeButton.Visible = hasFlag;
|
|
SetTimeButton.Visible = hasFlag;
|
|
|
|
if (!hasFlag)
|
|
UpdateWarning(Loc.GetString("time-transfer-panel-warning-no-perms"), Color.DarkRed);
|
|
else
|
|
UpdateWarning(" ", Color.LightGreen);
|
|
}
|
|
|
|
public void TimeTransfer(bool overwrite = false)
|
|
{
|
|
var player = PlayerLine.Text;
|
|
|
|
if (string.IsNullOrEmpty(player))
|
|
{
|
|
UpdateWarning(Loc.GetString("time-transfer-panel-warning-no-player"), Color.DarkRed);
|
|
return;
|
|
}
|
|
|
|
var dataList = new List<TimeTransferData>();
|
|
|
|
if (GroupCheckbox.Pressed)
|
|
{
|
|
if (string.IsNullOrEmpty(GroupTimeLine.Text))
|
|
{
|
|
UpdateWarning(Loc.GetString("time-transfer-panel-warning-group-no-time"), Color.DarkRed);
|
|
return;
|
|
}
|
|
|
|
var entryList = GetGroupEntries();
|
|
foreach (var entry in entryList)
|
|
{
|
|
var data = new TimeTransferData(entry.PlaytimeTracker, GroupTimeLine.Text);
|
|
dataList.Add(data);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var entry in JobContainer.Children)
|
|
{
|
|
if (entry is not TimeTransferEntry jobEntry)
|
|
continue;
|
|
|
|
var tracker = jobEntry.PlaytimeTracker;
|
|
var timeString = jobEntry.GetJobTimeString();
|
|
|
|
if (string.IsNullOrEmpty(timeString))
|
|
continue;
|
|
|
|
var data = new TimeTransferData(tracker, timeString);
|
|
dataList.Add(data);
|
|
}
|
|
}
|
|
|
|
OnTransferMessageSend?.Invoke((player, dataList, overwrite));
|
|
UpdateWarning(Loc.GetString("time-transfer-panel-warning-transfer-process"), Color.Gold);
|
|
}
|
|
|
|
public List<TimeTransferEntry> GetGroupEntries()
|
|
{
|
|
var list = new List<TimeTransferEntry>();
|
|
|
|
foreach (var entry in JobContainer.Children)
|
|
{
|
|
if (entry is not TimeTransferEntry jobEntry)
|
|
continue;
|
|
|
|
if (jobEntry.InGroup())
|
|
list.Add(jobEntry);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public void UpdateGroup()
|
|
{
|
|
GroupTimeLine.Visible = GroupCheckbox.Pressed;
|
|
|
|
foreach (var entry in JobContainer.Children)
|
|
{
|
|
if (entry is not TimeTransferEntry jobEntry)
|
|
continue;
|
|
|
|
jobEntry.UpdateGroupVisibility(GroupCheckbox.Pressed);
|
|
}
|
|
}
|
|
|
|
public void OnJobSearchTextChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
UpdateSearch();
|
|
}
|
|
|
|
public void UpdateSearch()
|
|
{
|
|
foreach (var entry in JobContainer.Children)
|
|
{
|
|
if (entry is not TimeTransferEntry jobEntry)
|
|
continue;
|
|
|
|
jobEntry.Visible = ShouldShowJob(jobEntry);
|
|
}
|
|
}
|
|
|
|
public void UpdateWarning(string text, Color color)
|
|
{
|
|
WarningLabel.FontColorOverride = color;
|
|
WarningLabel.Text = text;
|
|
}
|
|
|
|
public bool ShouldShowJob(TimeTransferEntry jobEntry)
|
|
{
|
|
return jobEntry.JobName != null && JobSearch.Text != null && jobEntry.JobName.Contains(JobSearch.Text, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public void OnGroupCheckboxPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
UpdateGroup();
|
|
}
|
|
|
|
public void OnAddTimeButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
TimeTransfer(false);
|
|
}
|
|
|
|
public void OnSetTimeButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
if (SetButtonResetOn is null)
|
|
{
|
|
SetButtonResetOn = _gameTiming.CurTime.Add(TimeSpan.FromSeconds(3));
|
|
SetTimeButton.ModulateSelfOverride = Color.DarkRed;
|
|
SetTimeButton.Text = Loc.GetString("time-transfer-panel-set-time-confirm");
|
|
return;
|
|
}
|
|
|
|
TimeTransfer(true);
|
|
ResetSetButton();
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
base.FrameUpdate(args);
|
|
|
|
if (SetButtonResetOn != null && _gameTiming.CurTime > SetButtonResetOn)
|
|
ResetSetButton();
|
|
}
|
|
|
|
private void ResetSetButton()
|
|
{
|
|
SetButtonResetOn = null;
|
|
SetTimeButton.ModulateSelfOverride = null;
|
|
SetTimeButton.Text = Loc.GetString("time-transfer-panel-set-time");
|
|
}
|
|
}
|