fish-station/Content.Client/UserInterface/Systems/Ghost/Controls/GhostTargetWindow.xaml.cs
Rinary 05aeb44b14
[RU] Полный перевод (#236)
* init

* fax translate

* translate

* translate cargo panel

* road map translate

* Fix cargo panel | fix bot craft translate

* fix, steal objectives translate

* do not break my not localized fax!

* fix

* radio guide translate

* Better DefaultRules

* Translate Criminal Records

* Space luw fully translate excluding CrimeList(need to rework)

* Some Guidebook translate

* Перевод глоссария, некоторые термины были переписанны под РУ комьюнити игры, некоторые к сожелению остались прежними

* Fix

* fix, translate

* Обновил структуру SpeakOnUIClosed, пофиксил перевод автоматов

* update and fix

* fully translate

* fix

* not fail but warn

* fix

* fix2

* фикс уже переведённого дерьма от корвахов

* Добавил термин подов в глоссарий

* roles translate fix

* Сикей в глоссарий

* Delete Resources/Locale/ru-RU/_sunrise/info/character-info.ftl

* remove cluster from pool

* new translation

* fully translate borgs

* some fixes

* Mr.Chang moment

* upd

* upd

* upd

* hotfix

* big fix

* fix some hardcode lang

* oh no shitcode language

* some translation

* some actions| admin commands translate start

* some new translation

* fully translate commands | figurines | chat-repo

* upd

* second upd

* upd

* start translating items

* some fixes

* translate wackpack

Из-за игры слов, я не смог нормально интерпритировать это дерьмо, так что пусть будет так, да теряется смысл и смешинка, но извините, я не смог как-то придумать игру слов

* translate

* debug translate

* upd

* Актуализация всего перевода

* fix

* fix

* upd

* some fixes | guns to his folders

* upd

* upd

* upd

* upd

* upd

* upd

* Перевод меток атмоса

* Последние коррективы

* fix

* some hardcode localization fix

* fix

* some fixes

* stats entry fully translate

* upd

* some fixes

* translate server side stats entry

* fix

* fix

* fix2

* fix

* upd

* upd

* fix

* holly shit

* fix

* totaly feed

* upd

* upd

* fix

* upd

* init

* upd

* upd

* access in prototypes

* Sunrise comments on code

* my bad

* я даун
2024-08-14 21:44:32 +03:00

115 lines
4 KiB
C#

using System.Linq;
using System.Numerics;
using Content.Shared.Ghost;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using System.Text.RegularExpressions; //Sunrise-Edit
namespace Content.Client.UserInterface.Systems.Ghost.Controls
{
[GenerateTypedNameReferences]
public sealed partial class GhostTargetWindow : DefaultWindow
{
private List<(string, NetEntity)> _warps = new();
private string _searchText = string.Empty;
public event Action<NetEntity>? WarpClicked;
public event Action? OnGhostnadoClicked;
public GhostTargetWindow()
{
RobustXamlLoader.Load(this);
SearchBar.OnTextChanged += OnSearchTextChanged;
GhostnadoButton.OnPressed += _ => OnGhostnadoClicked?.Invoke();
}
public void UpdateWarps(IEnumerable<GhostWarp> warps)
{
// Server COULD send these sorted but how about we just use the client to do it instead
_warps = warps
.OrderBy(w => w.IsWarpPoint)
.ThenBy(w => w.DisplayName, Comparer<string>.Create(
(x, y) => string.Compare(x, y, StringComparison.Ordinal)))
.Select(w =>
{
var name = w.IsWarpPoint
? Loc.GetString("ghost-target-window-current-button", ("name", GetLocalizedName(w.DisplayName))) //Sunrise-Edit
: GetLocalizedName(w.DisplayName); //Sunrise-Edit
return (name, w.Entity);
})
.ToList();
}
//Sunrise-Start
private string GetLocalizedName(string displayName)
{
var locationKey = $"location-{Regex.Replace(displayName, @"[^\s]", string.Empty).Replace(" ", "-").ToLower()}";
var localizedName = Loc.GetString(locationKey);
if (localizedName == locationKey)
{
if (locationKey != "location--" || locationKey != "location-")
{
Logger.Warning($"Failed to find localization with ID: {locationKey}");
}
localizedName = displayName;
}
return localizedName;
}
//Sunrise-End
public void Populate()
{
ButtonContainer.DisposeAllChildren();
AddButtons();
}
private void AddButtons()
{
foreach (var (name, warpTarget) in _warps)
{
var currentButtonRef = new Button
{
Text = name,
TextAlign = Label.AlignMode.Right,
HorizontalAlignment = HAlignment.Center,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1,
MinSize = new Vector2(340, 20),
ClipText = true,
};
currentButtonRef.OnPressed += _ => WarpClicked?.Invoke(warpTarget);
currentButtonRef.Visible = ButtonIsVisible(currentButtonRef);
ButtonContainer.AddChild(currentButtonRef);
}
}
private bool ButtonIsVisible(Button button)
{
return string.IsNullOrEmpty(_searchText) || button.Text == null || button.Text.Contains(_searchText, StringComparison.OrdinalIgnoreCase);
}
private void UpdateVisibleButtons()
{
foreach (var child in ButtonContainer.Children)
{
if (child is Button button)
button.Visible = ButtonIsVisible(button);
}
}
private void OnSearchTextChanged(LineEdit.LineEditEventArgs args)
{
_searchText = args.Text;
UpdateVisibleButtons();
// Reset scroll bar so they can see the relevant results.
GhostScroll.SetScrollValue(Vector2.Zero);
}
}
}