Skip to content

Commit

Permalink
Added tags for recipe rows
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowTheAge committed Jan 5, 2021
1 parent 97bf104 commit 3502ff0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
51 changes: 50 additions & 1 deletion YAFC/Workspace/ProductionTable/ProductionTableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,36 @@ private void BuildRecipeIngredients(ImGui gui, RecipeRow recipe)
grid.Dispose();
}

private void DrawRecipeTagSelect(ImGui gui, RecipeRow recipe)
{
using (gui.EnterRow())
{
for (var i = 0; i < tagIcons.Length; i++)
{
var (icon, color) = tagIcons[i];
var selected = i == recipe.tag;
gui.BuildIcon(icon, color:selected ? SchemeColor.Background : color);
if (selected)
gui.DrawRectangle(gui.lastRect, color);
else
{
var evt = gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.BackgroundAlt, SchemeColor.BackgroundAlt);
if (evt == ImGuiUtils.Event.Click)
recipe.RecordUndo(true).tag = i;
}
}
}
}

private void BuildRecipeName(ImGui gui, RecipeRow recipe)
{
gui.spacing = 0.5f;
if (gui.BuildFactorioObjectButton(recipe.recipe, 3f))
{
gui.ShowDropDown(delegate(ImGui imgui, ref bool closed)
{
DrawRecipeTagSelect(imgui, recipe);

if (recipe.subgroup == null && imgui.BuildButton("Create nested table"))
{
recipe.RecordUndo().subgroup = new ProductionTable(recipe);
Expand Down Expand Up @@ -871,7 +894,33 @@ private void BuildRecipePad(ImGui gui, RecipeRow row)
}
else
{
//gui.BuildText((index+1).ToString()); TODO
if (row.tag != 0)
BuildRowMarker(gui, row);
}
}

private static readonly (Icon icon, SchemeColor color)[] tagIcons = {
(Icon.Empty, SchemeColor.BackgroundTextFaint),
(Icon.Check, SchemeColor.Green),
(Icon.Warning, SchemeColor.Secondary),
(Icon.Error, SchemeColor.Error),
(Icon.Edit, SchemeColor.Primary),
(Icon.Help, SchemeColor.BackgroundText),
(Icon.Time, SchemeColor.BackgroundText),
(Icon.DarkMode, SchemeColor.BackgroundText),
(Icon.Plus, SchemeColor.BackgroundText),
};

private void BuildRowMarker(ImGui gui, RecipeRow row)
{
var markerId = row.tag;
if (markerId < 0 || markerId >= tagIcons.Length)
markerId = 0;
var (icon, color) = tagIcons[markerId];
gui.BuildIcon(icon, color:color);
if (gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.BackgroundAlt) == ImGuiUtils.Event.Click)
{
gui.ShowDropDown((ImGui imGui, ref bool closed) => DrawRecipeTagSelect(imGui, row));
}
}

Expand Down
3 changes: 2 additions & 1 deletion YAFCmodel/Model/ProductionTableContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public struct RecipeLinks
public ProductionLink fuel;
public ProductionLink spentFuel;
}

public class RecipeRow : ModelObject<ProductionTable>, IModuleFiller
{
public Recipe recipe { get; }
Expand All @@ -135,6 +135,7 @@ public class RecipeRow : ModelObject<ProductionTable>, IModuleFiller
public float fixedBuildings { get; set; }
public bool enabled { get; set; } = true;
public bool hierarchyEnabled { get; internal set; }
public int tag { get; set; }

[Obsolete("Deprecated", true)]
public Item module
Expand Down

0 comments on commit 3502ff0

Please sign in to comment.