Skip to content
New issue

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

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

Already on GitHub? # to your account

(minor) fixes #31

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion YAFC/Widgets/ObjectTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ private void BuildRecipe(RecipeOrTechnology recipe, ImGui gui)
gui.BuildText(DataUtils.FormatAmount(ingredient.amount, UnitOfMeasure.None));
}

gui.allocator = RectAllocator.RemainigRow;
gui.allocator = RectAllocator.RemainingRow;
gui.BuildFactorioObjectButtonWithText(technology);
}
}
Expand Down
9 changes: 4 additions & 5 deletions YAFC/Windows/DependencyExplorer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using SDL2;
using YAFC.Model;
using YAFC.UI;
Expand All @@ -11,8 +10,8 @@ public class DependencyExplorer : PseudoScreen
{
private static readonly DependencyExplorer Instance = new DependencyExplorer();

private readonly VerticalScrollCustom dependencies;
private readonly VerticalScrollCustom dependants;
private readonly ScrollArea dependencies;
private readonly ScrollArea dependants;
private static readonly Padding listPad = new Padding(0.5f);

private readonly List<FactorioObject> history = new List<FactorioObject>();
Expand All @@ -34,8 +33,8 @@ public class DependencyExplorer : PseudoScreen

public DependencyExplorer() : base(60f)
{
dependencies = new VerticalScrollCustom(30f, DrawDependencies);
dependants = new VerticalScrollCustom(30f, DrawDependants);
dependencies = new ScrollArea(30f, DrawDependencies);
dependants = new ScrollArea(30f, DrawDependants);
}

public static void Show(FactorioObject target)
Expand Down
4 changes: 2 additions & 2 deletions YAFC/Windows/ErrorListPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class ErrorListPanel : PseudoScreen
{
private static readonly ErrorListPanel Instance = new ErrorListPanel();
private ErrorCollector collector;
private readonly VerticalScrollCustom verticalList;
private readonly ScrollArea verticalList;
private (string error, ErrorSeverity severity)[] errors;

public ErrorListPanel() : base(60f)
{
verticalList = new VerticalScrollCustom(30f, BuildErrorList, default, true);
verticalList = new ScrollArea(30f, BuildErrorList, default, true);
}

private void BuildErrorList(ImGui gui)
Expand Down
10 changes: 5 additions & 5 deletions YAFC/Windows/NeverEnoughItemsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class NeverEnoughItemsPanel : PseudoScreen, IComparer<NeverEnoughItemsPan
private readonly List<Goods> recent = new List<Goods>();
private bool atCurrentMilestones;

private readonly VerticalScrollCustom productionList;
private readonly VerticalScrollCustom usageList;
private readonly ScrollArea productionList;
private readonly ScrollArea usageList;

private enum EntryStatus
{
Expand Down Expand Up @@ -62,8 +62,8 @@ public RecipeEntry(Recipe recipe, bool isProduction, Goods currentItem, bool atC

public NeverEnoughItemsPanel() : base(76f)
{
productionList = new VerticalScrollCustom(40f, BuildItemProduction, new Padding(0.5f));
usageList = new VerticalScrollCustom(40f, BuildItemUsages, new Padding(0.5f));
productionList = new ScrollArea(40f, BuildItemProduction, new Padding(0.5f));
usageList = new ScrollArea(40f, BuildItemUsages, new Padding(0.5f));
}

private void SetItem(Goods current)
Expand Down Expand Up @@ -204,7 +204,7 @@ private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production)
if (recipe.products.Length < 3 && recipe.ingredients.Length < 5)
gui.AllocateSpacing((3 - entry.recipe.products.Length) * 3f);
else if (recipe.products.Length < 3)
gui.allocator = RectAllocator.RemainigRow;
gui.allocator = RectAllocator.RemainingRow;
gui.BuildIcon(Icon.ArrowRight, 3f);
}
}
Expand Down
12 changes: 6 additions & 6 deletions YAFC/Windows/WelcomeScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class WelcomeScreen : WindowUtility, IProgress<(string, string)>
private bool expensive;
private string createText;
private bool canCreate;
private readonly VerticalScrollCustom errorScroll;
private readonly VerticalScrollCustom recentProjectScroll;
private readonly VerticalScrollCustom languageScroll;
private readonly ScrollArea errorScroll;
private readonly ScrollArea recentProjectScroll;
private readonly ScrollArea languageScroll;
private string errorMod;
private string errorMessage;
private string tip;
Expand Down Expand Up @@ -69,9 +69,9 @@ public WelcomeScreen() : base(ImGuiUtils.DefaultScreenPadding)
RenderingUtils.SetColorScheme(Preferences.Instance.darkMode);
var lastProject = Preferences.Instance.recentProjects.FirstOrDefault();
SetProject(lastProject);
errorScroll = new VerticalScrollCustom(20f, BuildError, collapsible:true);
recentProjectScroll = new VerticalScrollCustom(20f, BuildRecentProjectList, collapsible:true);
languageScroll = new VerticalScrollCustom(20f, LanguageSelection, collapsible: true);
errorScroll = new ScrollArea(20f, BuildError, collapsible:true);
recentProjectScroll = new ScrollArea(20f, BuildRecentProjectList, collapsible:true);
languageScroll = new ScrollArea(20f, LanguageSelection, collapsible: true);
Create("Welcome to YAFC CE v"+YafcLib.version.ToString(3), 45, null);
IconCollection.ClearCustomIcons();
if (tips == null)
Expand Down
12 changes: 6 additions & 6 deletions YAFC/Workspace/ProductionTable/ProductionLinkSummaryScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public class ProductionLinkSummaryScreen : PseudoScreen, IComparer<(RecipeRow ro
private readonly List<(RecipeRow row, float flow)> input = new List<(RecipeRow, float)>();
private readonly List<(RecipeRow row, float flow)> output = new List<(RecipeRow, float)>();
private float totalInput, totalOutput;
private readonly VerticalScrollCustom scrollArea;
private readonly ScrollArea scrollArea;

private ProductionLinkSummaryScreen()
{
scrollArea = new VerticalScrollCustom(30, BuildScrollArea);
scrollArea = new ScrollArea(30, BuildScrollArea);
}

private void BuildScrollArea(ImGui gui)
{
gui.BuildText("Production: "+DataUtils.FormatAmount(totalInput, link.goods.flowUnitOfMeasure), Font.subheader);
gui.BuildText("Production: " + DataUtils.FormatAmount(totalInput, link.goods.flowUnitOfMeasure), Font.subheader);
BuildFlow(gui, input, totalInput);
gui.spacing = 0.5f;
gui.BuildText("Consumption: "+DataUtils.FormatAmount(totalOutput, link.goods.flowUnitOfMeasure), Font.subheader);
gui.BuildText("Consumption: " + DataUtils.FormatAmount(totalOutput, link.goods.flowUnitOfMeasure), Font.subheader);
BuildFlow(gui, output, totalOutput);
if (link.flags.HasFlags(ProductionLink.Flags.LinkNotMatched) && totalInput != totalOutput)
gui.BuildText((totalInput > totalOutput ? "Overproduction: " : "Overconsumption: ") + DataUtils.FormatAmount(MathF.Abs(totalInput-totalOutput), link.goods.flowUnitOfMeasure), Font.subheader, color:SchemeColor.Error);
gui.BuildText((totalInput > totalOutput ? "Overproduction: " : "Overconsumption: ") + DataUtils.FormatAmount(MathF.Abs(totalInput - totalOutput), link.goods.flowUnitOfMeasure), Font.subheader, color: SchemeColor.Error);
}

public override void Build(ImGui gui)
Expand Down Expand Up @@ -71,7 +71,7 @@ private void CalculateFlow(ProductionLink link)
{
input.Add((recipe, localFlow));
totalInput += localFlow;
}
}
else if (localFlow < 0)
{
output.Add((recipe, -localFlow));
Expand Down
11 changes: 5 additions & 6 deletions YAFCui/ImGui/ImGui.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
using SDL2;
Expand Down Expand Up @@ -47,7 +46,7 @@ public enum RectAllocator
Center,
LeftRow,
RightRow,
RemainigRow,
RemainingRow,
FixedRect,
HalfRow
}
Expand All @@ -56,17 +55,17 @@ public enum RectAllocator

public sealed partial class ImGui : IDisposable, IPanel
{
public ImGui(GuiBuilder gui, Padding padding, RectAllocator defaultAllocator = RectAllocator.Stretch, bool clip = false)
public ImGui(GuiBuilder guiBuilder, Padding padding, RectAllocator defaultAllocator = RectAllocator.Stretch, bool clip = false)
{
this.gui = gui;
if (gui == null)
this.guiBuilder = guiBuilder;
if (guiBuilder == null)
action = ImGuiAction.Build;
this.defaultAllocator = defaultAllocator;
this.clip = clip;
initialPadding = padding;
}

public readonly GuiBuilder gui;
public readonly GuiBuilder guiBuilder;
public Window window { get; private set; }
public ImGui parent { get; private set; }
IPanel IPanel.Parent => parent;
Expand Down
23 changes: 11 additions & 12 deletions YAFCui/ImGui/ImGuiBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Deconstruct(out Rect rect, out T data, out SchemeColor color)
color = this.color;
}
}

private readonly List<DrawCommand<RectangleBorder>> rects = new List<DrawCommand<RectangleBorder>>();
private readonly List<DrawCommand<Icon>> icons = new List<DrawCommand<Icon>>();
private readonly List<DrawCommand<IRenderable>> renderables = new List<DrawCommand<IRenderable>>();
Expand Down Expand Up @@ -75,10 +75,10 @@ private void ClearDrawCommandList()

public void ManualDrawingClear()
{
if (gui == null)
if (guiBuilder == null)
ClearDrawCommandList();
}

public readonly ImGuiCache<TextCache, (FontFile.FontSize size, string text, uint wrapWidth)>.Cache textCache = new ImGuiCache<TextCache, (FontFile.FontSize size, string text, uint wrapWidth)>.Cache();

public FontFile.FontSize GetFontSize(Font font = null) => (font ?? Font.text).GetFontSize(pixelsPerUnit);
Expand Down Expand Up @@ -108,7 +108,7 @@ public Rect AllocateTextRect(out TextCache cache, string text, Font font = null,
}
else
{
cache = textCache.GetCached((fontSize, text, wrap ? (uint) UnitsToPixels(MathF.Max(width, 5f)) : uint.MaxValue));
cache = textCache.GetCached((fontSize, text, wrap ? (uint)UnitsToPixels(MathF.Max(width, 5f)) : uint.MaxValue));
rect = AllocateRect(cache.texRect.w / pixelsPerUnit, topOffset + cache.texRect.h / pixelsPerUnit, align);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public bool BuildTextInput(string text, out string newText, string placeholder,
textInputHelper = new ImGuiTextInputHelper(this);
return textInputHelper.BuildTextInput(text, out newText, placeholder, GetFontSize(), delayed, icon, padding, alignment, color);
}

public void BuildIcon(Icon icon, float size = 1.5f, SchemeColor color = SchemeColor.None)
{
if (color == SchemeColor.None)
Expand All @@ -162,15 +162,15 @@ public void BuildIcon(Icon icon, float size = 1.5f, SchemeColor color = SchemeCo

private bool DoGui(ImGuiAction action)
{
if (gui == null)
if (guiBuilder == null)
return false;
this.action = action;
ResetLayout();
buildingWidth = buildWidth;
buildGroupsIndex = -1;
using (EnterGroup(initialPadding, defaultAllocator, initialTextColor))
{
gui(this);
guiBuilder(this);
}
actionParameter = 0;
if (action == ImGuiAction.Build)
Expand All @@ -184,14 +184,14 @@ private bool DoGui(ImGuiAction action)

private void BuildGui(float width)
{
if (gui == null)
if (guiBuilder == null)
return;
buildWidth = width;
nextRebuildTimer = long.MaxValue;
rebuildRequested = false;
ClearDrawCommandList();
DoGui(ImGuiAction.Build);
contentSize = new Vector2(buildingWidth, lastRect.Bottom);
contentSize = new Vector2(lastRect.Right, lastRect.Bottom);
if (boxColor != SchemeColor.None)
{
var rect = new Rect(default, contentSize);
Expand Down Expand Up @@ -252,7 +252,7 @@ public void MouseUp(int button)
SDL.SDL_SetCursor(RenderingUtils.cursorHand);
cursorSetByMouseDown = false;
}

actionParameter = button;
DoGui(ImGuiAction.MouseUp);
}
Expand Down Expand Up @@ -354,7 +354,7 @@ public void SetFocus(Rect rect)
mouseDownRect = rect;
Rebuild();
}

public void SetTextInputFocus(Rect rect, string text)
{
if (textInputHelper != null && InputSystem.Instance.currentKeyboardFocus != textInputHelper)
Expand All @@ -366,7 +366,6 @@ public void SetTextInputFocus(Rect rect, string text)

public void SaveToImage()
{

}
}
}
Loading