OptionButton OptionCategories { get; }
bool EraseButtonPressed { get; set; }
+ bool GridViewButtonPressed { get; set; }
bool BuildButtonPressed { get; set; }
ItemList Recipes { get; }
ItemList RecipeStepList { get; }
+
+ ScrollContainer RecipesGridScrollContainer { get; }
+ GridContainer RecipesGrid { get; }
+
event EventHandler<(string search, string catagory)> PopulateRecipes;
event EventHandler<ItemList.Item?> RecipeSelected;
event EventHandler RecipeFavorited;
set => EraseButton.Pressed = value;
}
+ public bool GridViewButtonPressed
+ {
+ get => MenuGridViewButton.Pressed;
+ set => MenuGridViewButton.Pressed = value;
+ }
+
public ConstructionMenu()
{
- SetSize = MinSize = new Vector2(720, 320);
+ SetSize = new Vector2(560, 450);
+ MinSize = new Vector2(560, 320);
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
EraseButton.OnToggled += args => EraseButtonToggled?.Invoke(this, args.Pressed);
FavoriteButton.OnPressed += args => RecipeFavorited?.Invoke(this, EventArgs.Empty);
+
+ MenuGridViewButton.OnPressed += _ =>
+ PopulateRecipes?.Invoke(this, (SearchBar.Text, Categories[OptionCategories.SelectedId]));
}
public event EventHandler? ClearAllGhosts;
using System.Linq;
+using System.Numerics;
+using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Shared.Construction.Prototypes;
-using Content.Shared.Tag;
using Content.Shared.Whitelist;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Enums;
-using Robust.Shared.Graphics;
using Robust.Shared.Prototypes;
using static Robust.Client.UserInterface.Controls.BaseButton;
private readonly IConstructionMenuView _constructionView;
private readonly EntityWhitelistSystem _whitelistSystem;
+ private readonly SpriteSystem _spriteSystem;
private ConstructionSystem? _constructionSystem;
private ConstructionPrototype? _selected;
private List<ConstructionPrototype> _favoritedRecipes = [];
+ private Dictionary<string, TextureButton> _recipeButtons = new();
private string _selectedCategory = string.Empty;
private string _favoriteCatName = "construction-category-favorites";
private string _forAllCategoryName = "construction-category-all";
IoCManager.InjectDependencies(this);
_constructionView = new ConstructionMenu();
_whitelistSystem = _entManager.System<EntityWhitelistSystem>();
+ _spriteSystem = _entManager.System<SpriteSystem>();
// This is required so that if we load after the system is initialized, we can bind to it immediately
if (_systemManager.TryGetEntitySystem<ConstructionSystem>(out var constructionSystem))
PopulateInfo(_selected);
}
+ private void OnGridViewRecipeSelected(object? sender, ConstructionPrototype? recipe)
+ {
+ if (recipe is null)
+ {
+ _selected = null;
+ _constructionView.ClearRecipeInfo();
+ return;
+ }
+
+ _selected = recipe;
+ if (_placementManager.IsActive && !_placementManager.Eraser) UpdateGhostPlacement();
+ PopulateInfo(_selected);
+ }
+
private void OnViewPopulateRecipes(object? sender, (string search, string catagory) args)
{
var (search, category) = args;
- var recipesList = _constructionView.Recipes;
- recipesList.Clear();
var recipes = new List<ConstructionPrototype>();
var isEmptyCategory = string.IsNullOrEmpty(category) || category == _forAllCategoryName;
recipes.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.InvariantCulture));
- foreach (var recipe in recipes)
+ var recipesList = _constructionView.Recipes;
+ recipesList.Clear();
+
+ var recipesGrid = _constructionView.RecipesGrid;
+ recipesGrid.RemoveAllChildren();
+
+ _constructionView.RecipesGridScrollContainer.Visible = _constructionView.GridViewButtonPressed;
+ _constructionView.Recipes.Visible = !_constructionView.GridViewButtonPressed;
+
+ if (_constructionView.GridViewButtonPressed)
+ {
+ foreach (var recipe in recipes)
+ {
+ var itemButton = new TextureButton
+ {
+ TextureNormal = _spriteSystem.Frame0(recipe.Icon),
+ VerticalAlignment = Control.VAlignment.Center,
+ Name = recipe.Name,
+ ToolTip = recipe.Name,
+ Scale = new Vector2(1.35f),
+ ToggleMode = true,
+ };
+ var itemButtonPanelContainer = new PanelContainer
+ {
+ PanelOverride = new StyleBoxFlat { BackgroundColor = StyleNano.ButtonColorDefault },
+ Children = { itemButton },
+ };
+
+ itemButton.OnToggled += buttonToggledEventArgs =>
+ {
+ SelectGridButton(itemButton, buttonToggledEventArgs.Pressed);
+
+ if (buttonToggledEventArgs.Pressed &&
+ _selected != null &&
+ _recipeButtons.TryGetValue(_selected.Name, out var oldButton))
+ {
+ oldButton.Pressed = false;
+ SelectGridButton(oldButton, false);
+ }
+
+ OnGridViewRecipeSelected(this, buttonToggledEventArgs.Pressed ? recipe : null);
+ };
+
+ recipesGrid.AddChild(itemButtonPanelContainer);
+ _recipeButtons[recipe.Name] = itemButton;
+ var isCurrentButtonSelected = _selected == recipe;
+ itemButton.Pressed = isCurrentButtonSelected;
+ SelectGridButton(itemButton, isCurrentButtonSelected);
+ }
+ }
+ else
{
- recipesList.Add(GetItem(recipe, recipesList));
+ foreach (var recipe in recipes)
+ {
+ recipesList.Add(GetItem(recipe, recipesList));
+ }
}
+ }
+
+ private void SelectGridButton(TextureButton button, bool select)
+ {
+ if (button.Parent is not PanelContainer buttonPanel)
+ return;
- // There is apparently no way to set which
+ button.Modulate = select ? Color.Green : Color.White;
+ var buttonColor = select ? StyleNano.ButtonColorDefault : Color.Transparent;
+ buttonPanel.PanelOverride = new StyleBoxFlat { BackgroundColor = buttonColor };
}
private void PopulateCategories(string? selectCategory = null)
private void PopulateInfo(ConstructionPrototype prototype)
{
- var spriteSys = _systemManager.GetEntitySystem<SpriteSystem>();
_constructionView.ClearRecipeInfo();
_constructionView.SetRecipeInfo(
- prototype.Name, prototype.Description, spriteSys.Frame0(prototype.Icon),
+ prototype.Name, prototype.Description, _spriteSystem.Frame0(prototype.Icon),
prototype.Type != ConstructionType.Item,
!_favoritedRecipes.Contains(prototype));
if (_constructionSystem?.GetGuide(prototype) is not { } guide)
return;
- var spriteSys = _systemManager.GetEntitySystem<SpriteSystem>();
foreach (var entry in guide.Entries)
{
// The padding needs to be applied regardless of text length... (See PadLeft documentation)
text = text.PadLeft(text.Length + entry.Padding);
- var icon = entry.Icon != null ? spriteSys.Frame0(entry.Icon) : Texture.Transparent;
+ var icon = entry.Icon != null ? _spriteSystem.Frame0(entry.Icon) : Texture.Transparent;
stepList.AddItem(text, icon, false);
}
}
- private static ItemList.Item GetItem(ConstructionPrototype recipe, ItemList itemList)
+ private ItemList.Item GetItem(ConstructionPrototype recipe, ItemList itemList)
{
return new(itemList)
{
Metadata = recipe,
Text = recipe.Name,
- Icon = recipe.Icon.Frame0(),
+ Icon = _spriteSystem.Frame0(recipe.Icon),
TooltipEnabled = true,
- TooltipText = recipe.Description
+ TooltipText = recipe.Description,
};
}