fish-station/Content.Client/Construction/UI/ConstructionMenu.xaml.cs
Rinary 0bd0a4537c
Перевод меню строительства (#179)
* init

* upd.

* more furniture entries

* furniture fully added entries

* lightning.ftl

* machines.ftl

* Merge branch 'ConstructionLocalization' of https://github.com/Rinary1/space-sunrise into pr/179

* materials.ftl

* modular.ftl

* Create utilities.ftl

* Create tools.ftl

* Create structures.ftl

* storage.ftl

* upd storage.ftl

* translate storage.ftl

* translate modular.ftl

* translate materials.ftl

* translate machines.ftl

* translate lighting.ftl

* furniture.ftl translate

* add tiles.ftl

* bots, tools translate

* misc add, translate

* Translate some missing weapons

* some translations

* clothing description

* fun.ftl description

* Steps Translation

* Revert something

* New Steps translatings, Web items translate

* and some new Web translatings

* door staps translate

* NameLocalization

* ooops

* Всё по новой, перевод шагов был дерьмо, теперь materials.ftl

* some new reverts

* фикс?

* apc icon

* some clears

* steps fully translate

* translate

* Locale Search fix

* пу-пу-пу

* ой

* Revert "apc icon"

This reverts commit 65a3eab80453ab758b6a1e1c155d34938f481644.

---------

Co-authored-by: Babaev <babaevyt210@gmail.com>
2024-07-12 04:26:24 +03:00

143 lines
5.4 KiB
C#

using System;
using System.Numerics;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Graphics;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Client.Construction.UI
{
/// <summary>
/// This is the interface for a UI View of the construction window. The point of it is to abstract away the actual
/// UI controls and just provide higher level operations on the entire window. This View is completely passive and
/// just raises events to the outside world. This class is controlled by the <see cref="ConstructionMenuPresenter"/>.
/// </summary>
public interface IConstructionMenuView : IDisposable
{
// It isn't optimal to expose UI controls like this, but the UI control design is
// questionable so it can't be helped.
string[] Categories { get; set; }
OptionButton OptionCategories { get; }
bool EraseButtonPressed { get; set; }
bool BuildButtonPressed { get; set; }
ItemList Recipes { get; }
ItemList RecipeStepList { get; }
event EventHandler<(string search, string catagory)> PopulateRecipes;
event EventHandler<ItemList.Item?> RecipeSelected;
event EventHandler RecipeFavorited;
event EventHandler<bool> BuildButtonToggled;
event EventHandler<bool> EraseButtonToggled;
event EventHandler ClearAllGhosts;
void ClearRecipeInfo();
void SetRecipeInfo(string Id, Texture iconTexture, bool isItem, bool isFavorite);
void ResetPlacement();
#region Window Control
event Action? OnClose;
bool IsOpen { get; }
void OpenCentered();
void MoveToFront();
bool IsAtFront();
void Close();
#endregion
}
[GenerateTypedNameReferences]
public sealed partial class ConstructionMenu : DefaultWindow, IConstructionMenuView
{
public bool BuildButtonPressed
{
get => BuildButton.Pressed;
set => BuildButton.Pressed = value;
}
public string[] Categories { get; set; } = Array.Empty<string>();
public bool EraseButtonPressed
{
get => EraseButton.Pressed;
set => EraseButton.Pressed = value;
}
public ConstructionMenu()
{
SetSize = MinSize = new Vector2(720, 320);
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
Title = Loc.GetString("construction-menu-title");
BuildButton.Text = Loc.GetString("construction-menu-place-ghost");
Recipes.OnItemSelected += obj => RecipeSelected?.Invoke(this, obj.ItemList[obj.ItemIndex]);
Recipes.OnItemDeselected += _ => RecipeSelected?.Invoke(this, null);
SearchBar.OnTextChanged += _ =>
PopulateRecipes?.Invoke(this, (SearchBar.Text, Categories[OptionCategories.SelectedId]));
OptionCategories.OnItemSelected += obj =>
{
OptionCategories.SelectId(obj.Id);
SearchBar.SetText(string.Empty);
PopulateRecipes?.Invoke(this, (SearchBar.Text, Categories[obj.Id]));
};
BuildButton.Text = Loc.GetString("construction-menu-place-ghost");
BuildButton.OnToggled += args => BuildButtonToggled?.Invoke(this, args.Pressed);
ClearButton.Text = Loc.GetString("construction-menu-clear-all");
ClearButton.OnPressed += _ => ClearAllGhosts?.Invoke(this, EventArgs.Empty);
EraseButton.Text = Loc.GetString("construction-menu-eraser-mode");
EraseButton.OnToggled += args => EraseButtonToggled?.Invoke(this, args.Pressed);
FavoriteButton.OnPressed += args => RecipeFavorited?.Invoke(this, EventArgs.Empty);
}
public event EventHandler? ClearAllGhosts;
public event EventHandler<(string search, string catagory)>? PopulateRecipes;
public event EventHandler<ItemList.Item?>? RecipeSelected;
public event EventHandler? RecipeFavorited;
public event EventHandler<bool>? BuildButtonToggled;
public event EventHandler<bool>? EraseButtonToggled;
public void ResetPlacement()
{
BuildButton.Pressed = false;
EraseButton.Pressed = false;
}
public void SetRecipeInfo(
string Id, Texture iconTexture, bool isItem, bool isFavorite)
{
BuildButton.Disabled = false;
BuildButton.Text = Loc.GetString(isItem ? "construction-menu-place-ghost" : "construction-menu-craft");
TargetName.SetMessage(Loc.GetString($"recipe-{Id}-name"));
TargetDesc.SetMessage(Loc.GetString($"recipe-{Id}-description"));
TargetTexture.Texture = iconTexture;
FavoriteButton.Visible = true;
FavoriteButton.Text = Loc.GetString(
isFavorite ? "construction-add-favorite-button" : "construction-remove-from-favorite-button");
}
public void ClearRecipeInfo()
{
BuildButton.Disabled = true;
TargetName.SetMessage(string.Empty);
TargetDesc.SetMessage(string.Empty);
TargetTexture.Texture = null;
FavoriteButton.Visible = false;
RecipeStepList.Clear();
}
}
}