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

Allow unsetting target technology #115

Merged
merged 1 commit into from
May 9, 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
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