Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construction menu grid view #32577

Merged
merged 17 commits into from
Nov 20, 2024
Merged
32 changes: 14 additions & 18 deletions Content.Client/Construction/UI/ConstructionMenuPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ private void OnViewPopulateRecipes(object? sender, (string search, string catago
_constructionView.RecipesGridScrollContainer.Visible = _constructionView.GridViewButtonPressed;
_constructionView.Recipes.Visible = !_constructionView.GridViewButtonPressed;

var spriteSystem = _systemManager.GetEntitySystem<SpriteSystem>();
qwerltaz marked this conversation as resolved.
Show resolved Hide resolved

if (_constructionView.GridViewButtonPressed)
{
foreach (var recipe in recipes)
{
var item = GetItem(recipe, recipesList);

var itemButton = new TextureButton
{
TextureNormal = item.Icon,
TextureNormal = spriteSystem.Frame0(recipe.Icon),
VerticalAlignment = Control.VAlignment.Center,
Name = recipe.Name,
ToolTip = recipe.Name,
Expand All @@ -246,28 +246,24 @@ private void OnViewPopulateRecipes(object? sender, (string search, string catago

itemButton.OnToggled += buttonToggledEventArgs =>
{
if (_selected is null)
SelectGridButton(itemButton, buttonToggledEventArgs.Pressed);
else
SelectGridButton(itemButton, buttonToggledEventArgs.Pressed);

if (buttonToggledEventArgs.Pressed &&
_selected != null &&
_recipeButtons.TryGetValue(_selected.Name, out var oldButton))
{
SelectGridButton(itemButton, true);
if (_recipeButtons.TryGetValue(_selected.Name, out var oldButton))
{
oldButton.Pressed = false;
SelectGridButton(oldButton, false);
if (_selected == recipe)
{
OnGridViewRecipeSelected(this, null);
return;
}
}
oldButton.Pressed = false;
SelectGridButton(oldButton, false);
}

OnGridViewRecipeSelected(this, buttonToggledEventArgs.Pressed ? recipe : null);
};

recipesGrid.AddChild(itemButtonPanelContainer);
_recipeButtons[recipe.Name] = itemButton;
SelectGridButton(itemButton, _selected == recipe);
var isCurrentButtonSelected = _selected == recipe;
itemButton.Pressed = isCurrentButtonSelected;
SelectGridButton(itemButton, isCurrentButtonSelected);
}
}
else
Expand Down
Loading