Skip to content

Commit

Permalink
Allow unsetting target technology
Browse files Browse the repository at this point in the history
Target technology sets the objective for the CostAnalysis solver
in terms of the required number of science packs.
Setting it to null means to aim for all finite technologies
  • Loading branch information
exyi committed May 9, 2024
1 parent 3e8e02e commit b1a1d6c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions Yafc.Model/Model/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public ProjectPreferences(Project owner) : base(owner) { }
public int inserterCapacity { get; set; } = 1;
public HashSet<FactorioObject> sourceResources { get; } = new HashSet<FactorioObject>();
public HashSet<FactorioObject> favorites { get; } = new HashSet<FactorioObject>();
/// <summary> Target technology for cost analysis - required item counts are estimated for researching this. If null, the is to research all finite technologies. </summary>
public Technology targetTechnology { get; set; }

protected internal override void AfterDeserialize() {
Expand Down
1 change: 1 addition & 0 deletions Yafc/Widgets/ImmediateWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public static void ShowPrecisionValueTooltip(ImGui gui, float amount, UnitOfMeas
/// <summary>Shows a dropdown containing the (partial) <paramref name="list"/> of elements, with an action for when an element is selected.</summary>
/// <param name="count">Maximum number of elements in the list. If there are more another popup can be opened by the user to show the full list.</param>
/// <param name="width">Width of the popup. Make sure the header text fits!</param>
/// <param name="allowNone">Whether to show a "Clear" option which sets the value to <c>null</c>.</param>
public static void BuildObjectSelectDropDown<T>(this ImGui gui, ICollection<T> list, IComparer<T> ordering, Action<T> select, string header, float width = 20f, int count = 6, bool multiple = false, Predicate<T> checkMark = null, bool allowNone = false, Func<T, string> extra = null) where T : FactorioObject {
gui.ShowDropDown(imGui => imGui.BuildInlineObjectListAndButton(list, ordering, select, header, count, multiple, checkMark, allowNone, extra), width);
}
Expand Down
7 changes: 4 additions & 3 deletions Yafc/Windows/PreferencesScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override void Build(ImGui gui) {
ChoiceObject(gui, "Target technology for cost analysis: ", Database.technologies.all, prefs.targetTechnology, x => {
prefs.RecordUndo().targetTechnology = x;
gui.Rebuild();
}, width: 25f);
}, width: 25f, allowNone: true);

if (gui.BuildButton("Done")) {
Close();
Expand All @@ -89,11 +89,12 @@ public override void Build(ImGui gui) {
/// <summary>Add a GUI element that opens a popup to allow the user to choose from the <paramref name="list"/>, which triggers <paramref name="select"/>.</summary>
/// <param name="text">Label to show.</param>
/// <param name="width">Width of the popup. Make sure it is wide enough to fit text!</param>
private void ChoiceObject<T>(ImGui gui, string text, T[] list, T current, Action<T> select, float width = 20f) where T : FactorioObject {
/// <param name="allowNone">Whether to show a "Clear" option which sets the value to <c>null</c>.</param>
private void ChoiceObject<T>(ImGui gui, string text, T[] list, T current, Action<T> select, float width = 20f, bool allowNone = false) where T : FactorioObject {
using (gui.EnterRow()) {
gui.BuildText(text, topOffset: 0.5f);
if (gui.BuildFactorioObjectButtonWithText(current)) {
gui.BuildObjectSelectDropDown(list, DataUtils.DefaultOrdering, select, text, width: width);
gui.BuildObjectSelectDropDown(list, DataUtils.DefaultOrdering, select, text, width: width, allowNone: allowNone);
}
}
}
Expand Down

0 comments on commit b1a1d6c

Please sign in to comment.