2023-05-04 13:43:03 +06:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using Content.Shared.Popups;
|
2024-01-28 18:37:24 +07:00
|
|
|
|
using Content.Shared._White;
|
|
|
|
|
|
using Content.Shared._White.Jukebox;
|
2023-05-04 13:43:03 +06:00
|
|
|
|
using Robust.Client.AutoGenerated;
|
|
|
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
|
|
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
|
|
using Robust.Shared.Configuration;
|
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
2024-01-28 17:32:55 +07:00
|
|
|
|
namespace Content.Client._White.Jukebox;
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
|
|
|
|
|
[GenerateTypedNameReferences]
|
|
|
|
|
|
public sealed partial class TapeCreatorMenu : DefaultWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly EntityManager _entityManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IFileDialogManager _fileDialogManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
|
|
private readonly CheZaHuetaSystem _huetaSystem = default!;
|
|
|
|
|
|
private readonly SharedPopupSystem _popupSystem = default!;
|
|
|
|
|
|
|
|
|
|
|
|
private bool _fileDialogOpened;
|
|
|
|
|
|
private double _maxFileSize;
|
|
|
|
|
|
private double _currentFileSize;
|
|
|
|
|
|
private readonly List<byte> _songBytes = new();
|
|
|
|
|
|
private TapeCreatorComponent _component;
|
|
|
|
|
|
|
|
|
|
|
|
private const double BytesToMegabytes = 0.000001d;
|
|
|
|
|
|
|
|
|
|
|
|
public TapeCreatorMenu(TapeCreatorComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
RobustXamlLoader.Load(this);
|
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
|
|
|
|
|
|
_huetaSystem = _entityManager.System<CheZaHuetaSystem>();
|
|
|
|
|
|
_popupSystem = _entityManager.System<SharedPopupSystem>();
|
|
|
|
|
|
|
2023-08-29 05:59:14 +06:00
|
|
|
|
_cfg.OnValueChanged(WhiteCVars.MaxJukeboxSongSizeInMb, x => _maxFileSize = x, true);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
|
|
|
|
|
_component = component;
|
|
|
|
|
|
|
|
|
|
|
|
LoadSongButton.OnPressed += TryLoadSong;
|
|
|
|
|
|
UploadSong.OnPressed += OnUploadButtonPressed;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnUploadButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!CanUploadSong()) return;
|
|
|
|
|
|
|
|
|
|
|
|
var input = SongNameField.Text;
|
|
|
|
|
|
|
|
|
|
|
|
string pattern = @"[^a-zA-Zа-яА-Я ]+";
|
|
|
|
|
|
string replacement = "";
|
|
|
|
|
|
|
|
|
|
|
|
var songName = Regex.Replace(input, pattern, replacement);
|
|
|
|
|
|
songName = Regex.Replace(songName, @"\s+", " ");
|
|
|
|
|
|
|
|
|
|
|
|
var songBytes = _songBytes;
|
|
|
|
|
|
|
|
|
|
|
|
var msg = new JukeboxSongUploadRequest()
|
|
|
|
|
|
{
|
|
|
|
|
|
SongName = songName,
|
|
|
|
|
|
SongBytes = songBytes,
|
2024-01-13 12:24:00 +03:00
|
|
|
|
TapeCreatorUid = _entityManager.GetNetEntity(_component.Owner)
|
2023-05-04 13:43:03 +06:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_huetaSystem.SendNetMessage(msg);
|
|
|
|
|
|
|
|
|
|
|
|
_currentFileSize = 0;
|
|
|
|
|
|
_songBytes.Clear();
|
|
|
|
|
|
SongNameField.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
_popupSystem.PopupEntity("Внимание. Начинается запись мозговой активности.", _component.Owner);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void TryLoadSong(BaseButton.ButtonEventArgs obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
var fileFilter = new FileDialogFilters(new FileDialogFilters.Group("ogg"));
|
|
|
|
|
|
|
|
|
|
|
|
var file = await _fileDialogManager.OpenFile(fileFilter);
|
|
|
|
|
|
|
|
|
|
|
|
if (Disposed) return;
|
|
|
|
|
|
|
|
|
|
|
|
if(file == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
_currentFileSize = file.Length * BytesToMegabytes;
|
|
|
|
|
|
|
|
|
|
|
|
if (_currentFileSize > _maxFileSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
_popupSystem.PopupEntity($"Лимит активности мозговых волн превышен на {_currentFileSize - _maxFileSize} мегахрюков", _component.Owner);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Песня слишком длинная пиздец
|
|
|
|
|
|
|
|
|
|
|
|
_songBytes.AddRange(file.CopyToArray());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.FrameUpdate(args);
|
|
|
|
|
|
|
|
|
|
|
|
CoinsLabel.Text = _component.CoinBalance.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
if (CanUploadSong())
|
|
|
|
|
|
{
|
|
|
|
|
|
UploadSong.Disabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UploadSong.Disabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool CanUploadSong()
|
|
|
|
|
|
{
|
|
|
|
|
|
return SongNameField.Text.Length > 0 && _songBytes.Count > 0 && _component.CoinBalance > 0 && _component.InsertedTape.HasValue && !_component.Recording;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|