mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Make StationRecords YAML savable * Update SharedStationRecordsSystem.cs * Predict Station Records * Attribute subs, query Resolve & DirtyFields * Cleanup, prediction fixes, locale fixes * Update GeneralRecordsUi.cs Remove GeneralStationRecordConsoleState and obsolete SelectStationRecord
169 lines
4.9 KiB
C#
169 lines
4.9 KiB
C#
using Content.Shared.StationRecords;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.StationRecords;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow
|
|
{
|
|
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
|
|
|
public Action<uint?>? OnKeySelected;
|
|
|
|
public Action<StationRecordFilterType, string>? OnFiltersChanged;
|
|
public Action<uint>? OnDeleted;
|
|
|
|
private bool _isPopulating;
|
|
|
|
private StationRecordFilterType _currentFilterType;
|
|
|
|
public GeneralStationRecordConsoleWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_currentFilterType = StationRecordFilterType.Name;
|
|
|
|
foreach (var item in Enum.GetValues<StationRecordFilterType>())
|
|
{
|
|
StationRecordsFilterType.AddItem(GetTypeFilterLocals(item), (int)item);
|
|
}
|
|
|
|
RecordListing.OnItemSelected += args =>
|
|
{
|
|
if (_isPopulating || RecordListing[args.ItemIndex].Metadata is not uint cast)
|
|
return;
|
|
|
|
OnKeySelected?.Invoke(cast);
|
|
};
|
|
|
|
RecordListing.OnItemDeselected += _ =>
|
|
{
|
|
if (!_isPopulating)
|
|
OnKeySelected?.Invoke(null);
|
|
};
|
|
|
|
StationRecordsFilterType.OnItemSelected += eventArgs =>
|
|
{
|
|
var type = (StationRecordFilterType)eventArgs.Id;
|
|
|
|
if (_currentFilterType != type)
|
|
{
|
|
_currentFilterType = type;
|
|
FilterListingOfRecords();
|
|
}
|
|
};
|
|
|
|
StationRecordsFiltersValue.OnTextEntered += args =>
|
|
{
|
|
FilterListingOfRecords(args.Text);
|
|
};
|
|
|
|
StationRecordsFilters.OnPressed += _ =>
|
|
{
|
|
FilterListingOfRecords(StationRecordsFiltersValue.Text);
|
|
};
|
|
|
|
StationRecordsFiltersReset.OnPressed += _ =>
|
|
{
|
|
StationRecordsFiltersValue.Text = "";
|
|
FilterListingOfRecords();
|
|
};
|
|
}
|
|
|
|
public void UpdateState(uint? selectedKey,
|
|
GeneralStationRecord? record,
|
|
Dictionary<uint, string>? recordListing,
|
|
StationRecordsFilter? filter,
|
|
bool canDeleteEntries)
|
|
{
|
|
if (filter != null)
|
|
{
|
|
if (filter.Type != _currentFilterType)
|
|
{
|
|
_currentFilterType = filter.Type;
|
|
}
|
|
|
|
if (filter.Value != StationRecordsFiltersValue.Text)
|
|
{
|
|
StationRecordsFiltersValue.Text = filter.Value;
|
|
}
|
|
}
|
|
|
|
StationRecordsFilterType.SelectId((int)_currentFilterType);
|
|
|
|
if (recordListing == null)
|
|
{
|
|
RecordListingStatus.Visible = true;
|
|
RecordListing.Visible = false;
|
|
RecordListingStatus.Text = Loc.GetString("general-station-record-console-empty-state");
|
|
RecordContainer.Visible = false;
|
|
RecordContainerStatus.Visible = false;
|
|
return;
|
|
}
|
|
|
|
RecordListingStatus.Visible = false;
|
|
RecordListing.Visible = true;
|
|
RecordContainer.Visible = true;
|
|
|
|
PopulateRecordListing(recordListing, selectedKey);
|
|
|
|
RecordContainerStatus.Visible = record == null;
|
|
|
|
if (record != null)
|
|
{
|
|
RecordContainerStatus.Visible = selectedKey == null;
|
|
RecordContainerStatus.Text = selectedKey == null
|
|
? Loc.GetString("general-station-record-console-no-record-found")
|
|
: Loc.GetString("general-station-record-console-select-record-info");
|
|
PopulateRecordContainer(record, canDeleteEntries, selectedKey);
|
|
}
|
|
else
|
|
{
|
|
RecordContainer.RemoveAllChildren();
|
|
}
|
|
}
|
|
private void PopulateRecordListing(Dictionary<uint, string> listing, uint? selected)
|
|
{
|
|
RecordListing.Clear();
|
|
RecordListing.ClearSelected();
|
|
|
|
_isPopulating = true;
|
|
|
|
foreach (var (key, name) in listing)
|
|
{
|
|
var item = RecordListing.AddItem(name);
|
|
item.Metadata = key;
|
|
item.Selected = key == selected;
|
|
}
|
|
_isPopulating = false;
|
|
|
|
RecordListing.SortItemsByText();
|
|
}
|
|
|
|
private void PopulateRecordContainer(GeneralStationRecord record, bool enableDelete, uint? id)
|
|
{
|
|
RecordContainer.RemoveAllChildren();
|
|
var newRecord = new GeneralRecord(record, enableDelete, id, _prototypeManager);
|
|
newRecord.OnDeletePressed = OnDeleted;
|
|
|
|
RecordContainer.AddChild(newRecord);
|
|
}
|
|
|
|
private void FilterListingOfRecords(string text = "")
|
|
{
|
|
if (!_isPopulating)
|
|
{
|
|
OnFiltersChanged?.Invoke(_currentFilterType, text);
|
|
}
|
|
}
|
|
|
|
private string GetTypeFilterLocals(StationRecordFilterType type)
|
|
{
|
|
return Loc.GetString($"general-station-record-{type.ToString().ToLower()}-filter");
|
|
}
|
|
|
|
}
|