* fix workbench icons * workbench search * fix 1 * UI finalize * fix material localization * restore shard sprite * Update sewing_table.yml
134 lines
4.0 KiB
C#
134 lines
4.0 KiB
C#
/*
|
|
* This file is sublicensed under MIT License
|
|
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
|
|
*/
|
|
|
|
using Content.Shared._CP14.Workbench;
|
|
using Content.Shared._CP14.Workbench.Prototypes;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client._CP14.Workbench;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class CP14WorkbenchWindow : DefaultWindow
|
|
{
|
|
[Dependency] private readonly IEntityManager _entity = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
|
|
private CP14WorkbenchUiRecipesState? _cachedState;
|
|
|
|
public event Action<CP14WorkbenchUiRecipesEntry>? OnCraft;
|
|
public event Action<string>? OnTextUpdated;
|
|
|
|
private CP14WorkbenchUiRecipesEntry? _selectedEntry;
|
|
|
|
public CP14WorkbenchWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
SearchBar.OnTextChanged += _ =>
|
|
{
|
|
OnTextUpdated?.Invoke(SearchBar.Text);
|
|
};
|
|
CraftButton.OnPressed += _ =>
|
|
{
|
|
if (_selectedEntry is null)
|
|
return;
|
|
|
|
OnCraft?.Invoke(_selectedEntry.Value);
|
|
};
|
|
}
|
|
|
|
public void UpdateFilter(string? search)
|
|
{
|
|
if (_cachedState is null)
|
|
return;
|
|
|
|
UpdateRecipes(_cachedState, search);
|
|
}
|
|
|
|
public void UpdateRecipes(CP14WorkbenchUiRecipesState recipesState, string? search = null)
|
|
{
|
|
_cachedState = recipesState;
|
|
CraftsContainer.RemoveAllChildren();
|
|
|
|
List<CP14WorkbenchUiRecipesEntry> uncraftableList = new();
|
|
foreach (var entry in recipesState.Recipes)
|
|
{
|
|
if (search is not null && search != "")
|
|
{
|
|
if (!_prototype.TryIndex(entry.ProtoId, out var indexedEntry))
|
|
continue;
|
|
|
|
if (!_prototype.TryIndex(indexedEntry.Result, out var indexedResult))
|
|
continue;
|
|
|
|
if (!indexedResult.Name.Contains(search))
|
|
continue;
|
|
}
|
|
|
|
if (entry.Craftable)
|
|
{
|
|
var control = new CP14WorkbenchRequirementControl(entry);
|
|
control.OnSelect += RecipeSelect;
|
|
CraftsContainer.AddChild(control);
|
|
}
|
|
else
|
|
uncraftableList.Add(entry);
|
|
}
|
|
|
|
foreach (var entry in uncraftableList)
|
|
{
|
|
var control = new CP14WorkbenchRequirementControl(entry);
|
|
control.OnSelect += RecipeSelect;
|
|
CraftsContainer.AddChild(control);
|
|
}
|
|
|
|
if (_selectedEntry is not null && recipesState.Recipes.Contains(_selectedEntry.Value))
|
|
{
|
|
RecipeSelect(_selectedEntry.Value, _prototype.Index(_selectedEntry.Value.ProtoId));
|
|
return;
|
|
}
|
|
|
|
RecipeSelect(recipesState);
|
|
}
|
|
|
|
private void RecipeSelect(CP14WorkbenchUiRecipesState recipesState)
|
|
{
|
|
foreach (var entry in recipesState.Recipes)
|
|
{
|
|
RecipeSelect(entry, _prototype.Index(entry.ProtoId));
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void RecipeSelect(CP14WorkbenchUiRecipesEntry entry, CP14WorkbenchRecipePrototype recipe)
|
|
{
|
|
_selectedEntry = entry;
|
|
|
|
var result = _prototype.Index(recipe.Result);
|
|
|
|
ItemView.SetPrototype(recipe.Result);
|
|
ItemName.Text = result.Name;
|
|
ItemDescription.Text = result.Description;
|
|
|
|
ItemRequirements.RemoveAllChildren();
|
|
foreach (var (entProtoId, count) in recipe.Entities)
|
|
{
|
|
ItemRequirements.AddChild(new CP14WorkbenchRecipeControl(_prototype.Index(entProtoId), count));
|
|
}
|
|
|
|
foreach (var (stackProtoId, count) in recipe.Stacks)
|
|
{
|
|
ItemRequirements.AddChild(new CP14WorkbenchRecipeControl(_prototype.Index(stackProtoId), count));
|
|
}
|
|
|
|
CraftButton.Disabled = !entry.Craftable;
|
|
}
|
|
}
|