Skip to content

Commit

Permalink
Suppress recs checkbox for export modpack
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 6, 2024
1 parent 851b3fb commit f8785f9
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 23 deletions.
47 changes: 31 additions & 16 deletions GUI/Controls/EditModpack.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 40 additions & 5 deletions GUI/Controls/EditModpack.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -32,6 +33,7 @@ public EditModpack()
ToolTip.SetToolTip(GameVersionMaxComboBox, Properties.Resources.EditModpackTooltipGameVersionMax);
ToolTip.SetToolTip(LicenseComboBox, Properties.Resources.EditModpackTooltipLicense);
ToolTip.SetToolTip(IncludeVersionsCheckbox, Properties.Resources.EditModpackTooltipIncludeVersions);
ToolTip.SetToolTip(IncludeOptRelsCheckbox, Properties.Resources.EditModpackTooltipIncludeOptRels);
ToolTip.SetToolTip(DependsRadioButton, Properties.Resources.EditModpackTooltipDepends);
ToolTip.SetToolTip(RecommendsRadioButton, Properties.Resources.EditModpackTooltipRecommends);
ToolTip.SetToolTip(SuggestsRadioButton, Properties.Resources.EditModpackTooltipSuggests);
Expand Down Expand Up @@ -322,7 +324,7 @@ private void ExportModpackButton_Click(object sender, EventArgs e)
badField.Focus();
user.RaiseError(error);
}
else if (TrySavePrompt(modpackExportOptions, out _, out string filename))
else if (TrySavePrompt(modpackExportOptions, out string filename))
{
if (module.depends.Count == 0)
{
Expand All @@ -336,11 +338,15 @@ private void ExportModpackButton_Click(object sender, EventArgs e)
{
module.suggests = null;
}
CkanModule.ToFile(ApplyVersionsCheckbox(module), filename);
CkanModule.ToFile(ApplyCheckboxes(module), filename);
OpenFileBrowser(filename);
task?.SetResult(true);
}
}

private CkanModule ApplyCheckboxes(CkanModule input)
=> ApplyIncludeOptRelsCheckbox(ApplyVersionsCheckbox(input));

private CkanModule ApplyVersionsCheckbox(CkanModule input)
{
if (IncludeVersionsCheckbox.Checked)
Expand Down Expand Up @@ -375,7 +381,38 @@ private CkanModule ApplyVersionsCheckbox(CkanModule input)
}
}

private bool TrySavePrompt(List<ExportOption> exportOptions, out ExportOption selectedOption, out string filename)
private CkanModule ApplyIncludeOptRelsCheckbox(CkanModule input)
{
if (IncludeOptRelsCheckbox.Checked)
{
return input;
}
else
{
var newMod = CkanModule.FromJson(CkanModule.ToJson(input));
foreach (var rel in newMod.depends)
{
rel.suppress_recommendations = true;
}
return newMod;
}
}

private void OpenFileBrowser(string location)
{
if (File.Exists(location))
{
// We need the folder of the file
// Otherwise the OS would try to open the file in its default application
location = Path.GetDirectoryName(location);
}
if (Directory.Exists(location))
{
Utilities.ProcessStartURL(location);
}
}

private bool TrySavePrompt(List<ExportOption> exportOptions, out string filename)
{
var dlg = new SaveFileDialog()
{
Expand All @@ -384,13 +421,11 @@ private bool TrySavePrompt(List<ExportOption> exportOptions, out ExportOption se
};
if (dlg.ShowDialog(ParentForm) == DialogResult.OK)
{
selectedOption = exportOptions[dlg.FilterIndex - 1];
filename = dlg.FileName;
return true;
}
else
{
selectedOption = null;
filename = null;
return false;
}
Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/EditModpack.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<data name="GameVersionLabel.Text" xml:space="preserve"><value>Game versions:</value></data>
<data name="LicenseLabel.Text" xml:space="preserve"><value>Licence:</value></data>
<data name="IncludeVersionsCheckbox.Text" xml:space="preserve"><value>Save mod versions</value></data>
<data name="IncludeOptRelsCheckbox.Text" xml:space="preserve"><value>Include optional relationships</value></data>
<data name="ModNameColumn.Text" xml:space="preserve"><value>Mod</value></data>
<data name="ModVersionColumn.Text" xml:space="preserve"><value>Version</value></data>
<data name="ModAbstractColumn.Text" xml:space="preserve"><value>Description</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Controls/ModInfoTabs/Contents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void OpenFileBrowser(TreeNode node)
if (!Directory.Exists(location))
{
// User either selected the parent node
// or he clicked on the tree node of a cached, but not installed mod
// or clicked on the tree node of a cached, but not installed mod
return;
}

Expand Down
2 changes: 1 addition & 1 deletion GUI/Controls/UnmanagedFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void OpenFileBrowser(TreeNode node)
if (!Directory.Exists(location))
{
// User either selected the parent node
// or he clicked on the tree node of a cached, but not installed mod
// or clicked on the tree node of a cached, but not installed mod
return;
}

Expand Down
2 changes: 2 additions & 0 deletions GUI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ Are you sure you want to skip this change?</value></data>
<data name="EditModpackTooltipGameVersionMax" xml:space="preserve"><value>Latest compatible game version, blank for all</value></data>
<data name="EditModpackTooltipLicense" xml:space="preserve"><value>The licence for this modpack</value></data>
<data name="EditModpackTooltipIncludeVersions" xml:space="preserve"><value>If checked, the modpack will include the specific versions of the mods shown, otherwise any version will do</value></data>
<data name="EditModpackTooltipIncludeOptRels" xml:space="preserve"><value>If checked, users installing this modpack will be shown recommendations and suggestions from mods in the pack.
If unchecked, only mods in the pack will be installed.</value></data>
<data name="EditModpackTooltipDepends" xml:space="preserve"><value>Move selected mods to the Depends group. These mods will definitely be installed.</value></data>
<data name="EditModpackTooltipRecommends" xml:space="preserve"><value>Move selected mods to the Recommends group. A user can drop these mods on installation.</value></data>
<data name="EditModpackTooltipSuggests" xml:space="preserve"><value>Move selected mods to the Suggests group. These mods will be available for installation, but you have to explicitly select them.</value></data>
Expand Down

0 comments on commit f8785f9

Please sign in to comment.