ConstructionGL2 Part 2: Better guided steps and recipes. (#5103)

This commit is contained in:
Vera Aguilera Puerto
2021-11-02 11:24:32 +01:00
committed by GitHub
parent 5be8271907
commit 5a5006e4cf
45 changed files with 725 additions and 210 deletions

View File

@@ -65,6 +65,9 @@ namespace Content.Client.Construction.UI
_constructionView.MoveToFront();
else
_constructionView.OpenCentered();
if(_selected != null)
PopulateInfo(_selected);
}
else
_constructionView.Close();
@@ -224,95 +227,23 @@ namespace Content.Client.Construction.UI
private void GenerateStepList(ConstructionPrototype prototype, ItemList stepList)
{
if (!_prototypeManager.TryIndex(prototype.Graph, out ConstructionGraphPrototype? graph))
if (_constructionSystem?.GetGuide(prototype) is not { } guide)
return;
var startNode = graph.Nodes[prototype.StartNode];
var targetNode = graph.Nodes[prototype.TargetNode];
if (!graph.TryPath(startNode.Name, targetNode.Name, out var path))
foreach (var entry in guide.Entries)
{
return;
var text = entry.Arguments != null
? Loc.GetString(entry.Localization, entry.Arguments) : Loc.GetString(entry.Localization);
if (entry.EntryNumber is {} number)
text = Loc.GetString("construction-presenter-step-wrapper",
("step-number", number), ("text", text));
// The padding needs to be applied regardless of text length... (See PadLeft documentation)
text = text.PadLeft(text.Length + entry.Padding);
stepList.AddItem(text, entry.Icon?.Frame0(), false);
}
var current = startNode;
var stepNumber = 1;
foreach (var node in path)
{
if (!current.TryGetEdge(node.Name, out var edge))
{
continue;
}
var firstNode = current == startNode;
if (firstNode)
{
stepList.AddItem(prototype.Type == ConstructionType.Item
? Loc.GetString($"construction-presenter-to-craft", ("step-number", stepNumber++))
: Loc.GetString($"construction-presenter-to-build", ("step-number", stepNumber++)));
}
foreach (var step in edge.Steps)
{
var icon = GetTextureForStep(_resourceCache, step);
switch (step)
{
case MaterialConstructionGraphStep materialStep:
stepList.AddItem(
!firstNode
? Loc.GetString(
"construction-presenter-material-step",
("step-number", stepNumber++),
("amount", materialStep.Amount),
("material", materialStep.MaterialPrototype.Name))
: Loc.GetString(
"construction-presenter-material-first-step",
("amount", materialStep.Amount),
("material", materialStep.MaterialPrototype.Name)),
icon);
break;
case ToolConstructionGraphStep toolStep:
stepList.AddItem(Loc.GetString(
"construction-presenter-tool-step",
("step-number", stepNumber++),
("tool", Loc.GetString(_prototypeManager.Index<ToolQualityPrototype>(toolStep.Tool).ToolName))),
icon);
break;
case ArbitraryInsertConstructionGraphStep arbitraryStep:
stepList.AddItem(Loc.GetString(
"construction-presenter-arbitrary-step",
("step-number", stepNumber++),
("name", arbitraryStep.Name)),
icon);
break;
}
}
current = node;
}
}
private Texture? GetTextureForStep(IResourceCache resourceCache, ConstructionGraphStep step)
{
switch (step)
{
case MaterialConstructionGraphStep materialStep:
return materialStep.MaterialPrototype.Icon?.Frame0();
case ToolConstructionGraphStep toolStep:
return _prototypeManager.Index<ToolQualityPrototype>(toolStep.Tool).Icon?.Frame0();
case ArbitraryInsertConstructionGraphStep arbitraryStep:
return arbitraryStep.Icon?.Frame0();
}
return null;
}
private static ItemList.Item GetItem(ConstructionPrototype recipe, ItemList itemList)
@@ -413,6 +344,7 @@ namespace Content.Client.Construction.UI
_constructionSystem = system;
system.ToggleCraftingWindow += SystemOnToggleMenu;
system.CraftingAvailabilityChanged += SystemCraftingAvailabilityChanged;
system.ConstructionGuideAvailable += SystemGuideAvailable;
CraftingAvailable = system.CraftingEnabled;
}
@@ -425,6 +357,7 @@ namespace Content.Client.Construction.UI
system.ToggleCraftingWindow -= SystemOnToggleMenu;
system.CraftingAvailabilityChanged -= SystemCraftingAvailabilityChanged;
system.ConstructionGuideAvailable -= SystemGuideAvailable;
_constructionSystem = null;
}
@@ -454,5 +387,19 @@ namespace Content.Client.Construction.UI
_gameHud.CraftingButtonDown = true; // This does not call CraftingButtonToggled
}
}
private void SystemGuideAvailable(object? sender, string e)
{
if (!CraftingAvailable)
return;
if (!WindowOpen)
return;
if (_selected == null)
return;
PopulateInfo(_selected);
}
}
}