Skip to content

Commit

Permalink
Merge #3939 Search by supports relationship and other search improvem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
HebaruSan committed Dec 11, 2023
2 parents 296f7cc + 01d5177 commit 8dc8643
Show file tree
Hide file tree
Showing 23 changed files with 305 additions and 109 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
- [Multiple] Modernize administrator and Mono version checks (#3933 by: HebaruSan; reviewed: techman83)
- [Multiple] Improve file deletion error while the game is running (#3938 by: HebaruSan; reviewed: techman83)
- [GUI] New Crowdin updates (#3940 by: Olympic1; reviewed: HebaruSan)
- [GUI] Search by supports relationship and other search improvements (#3939 by: HebaruSan)

### Bugfixes

Expand Down
5 changes: 3 additions & 2 deletions Core/Games/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public interface IGame
string[] BuildIDFiles { get; }

// How to get metadata
Uri DefaultRepositoryURL { get; }
Uri RepositoryListURL { get; }
Uri DefaultRepositoryURL { get; }
Uri RepositoryListURL { get; }
Uri MetadataBugtrackerURL { get; }
}
}
2 changes: 2 additions & 0 deletions Core/Games/KerbalSpaceProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ public GameVersion DetectVersion(DirectoryInfo where)

public Uri RepositoryListURL => new Uri("https://raw.githubusercontent.com/KSP-CKAN/CKAN-meta/master/repositories.json");

public Uri MetadataBugtrackerURL => new Uri("https://github.com/KSP-CKAN/NetKAN/issues/new/choose");

private string Missions(GameInstance inst)
=> CKANPathUtils.NormalizePath(Path.Combine(inst.GameDir(), "Missions"));

Expand Down
2 changes: 2 additions & 0 deletions Core/Games/KerbalSpaceProgram2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ private GameVersion VersionFromFile(string path)

public Uri RepositoryListURL => new Uri("https://raw.githubusercontent.com/KSP-CKAN/KSP2-CKAN-meta/main/repositories.json");

public Uri MetadataBugtrackerURL => new Uri("https://github.com/KSP-CKAN/KSP2-NetKAN/issues/new/choose");

// Key: Allowed value of install_to
// Value: Relative path
// (PrimaryModDirectoryRelative is allowed implicitly)
Expand Down
98 changes: 28 additions & 70 deletions GUI/Controls/EditModSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ public bool ShowLabel
}
}

public void CloseSearch(Point screenCoords)
{
// Treat the entire main window as an uncheck button, and let
// the actual checkbox handle unchecking itself
var bounds = new Rectangle(ExpandButton.PointToScreen(new Point(0, 0)),
ExpandButton.Size);
if (!bounds.Contains(screenCoords))
{
ExpandButton.Checked = false;
}
}

public void ParentMoved()
{
FormGeometryChanged();
}

protected override void OnResize(EventArgs e)
{
base.OnResize(e);
FormGeometryChanged();
}

private bool suppressSearch = false;
private ModSearch currentSearch = null;

Expand Down Expand Up @@ -174,25 +197,15 @@ private void ExpandButton_CheckedChanged(object sender, EventArgs e)

private void DoLayout(bool expanded)
{
FormGeometryChanged(null, null);
FormGeometryChanged();
SearchDetails.Visible = expanded;
if (SearchDetails.Visible)
{
SearchDetails.FilterByNameTextBox.Focus();
if (Main.Instance != null)
{
Main.Instance.Move += FormGeometryChanged;
Resize += FormGeometryChanged;
}
}
else if (Main.Instance != null)
{
Main.Instance.Move -= FormGeometryChanged;
Resize -= FormGeometryChanged;
SearchDetails.SetFocus();
}
}

private void FormGeometryChanged(object sender, EventArgs e)
private void FormGeometryChanged()
{
SearchDetails.Location = PointToScreen(new Point(
FilterCombinedTextBox.Left,
Expand All @@ -207,73 +220,18 @@ private void FormGeometryChanged(object sender, EventArgs e)
private void SearchToEditor()
{
suppressSearch = true;
SearchDetails.FilterByNameTextBox.Text = currentSearch?.Name
?? "";
SearchDetails.FilterByAuthorTextBox.Text = currentSearch?.Authors.Aggregate("", CombinePieces)
?? "";
SearchDetails.FilterByDescriptionTextBox.Text = currentSearch?.Description
?? "";
SearchDetails.FilterByLanguageTextBox.Text = currentSearch?.Localizations.Aggregate("", CombinePieces)
?? "";
SearchDetails.FilterByDependsTextBox.Text = currentSearch?.DependsOn.Aggregate("", CombinePieces)
?? "";
SearchDetails.FilterByRecommendsTextBox.Text = currentSearch?.Recommends.Aggregate("", CombinePieces)
?? "";
SearchDetails.FilterByConflictsTextBox.Text = currentSearch?.ConflictsWith.Aggregate("", CombinePieces)
?? "";
SearchDetails.FilterBySuggestsTextBox.Text = currentSearch?.Suggests.Aggregate("", CombinePieces)
?? "";
SearchDetails.FilterByTagsTextBox.Text = currentSearch?.TagNames.Aggregate("", CombinePieces)
?? "";
SearchDetails.FilterByLabelsTextBox.Text = currentSearch?.Labels
.Select(lb => lb.Name)
.Aggregate("", CombinePieces)
?? "";

SearchDetails.CompatibleToggle.Value = currentSearch?.Compatible;
SearchDetails.InstalledToggle.Value = currentSearch?.Installed;
SearchDetails.CachedToggle.Value = currentSearch?.Cached;
SearchDetails.NewlyCompatibleToggle.Value = currentSearch?.NewlyCompatible;
SearchDetails.UpgradeableToggle.Value = currentSearch?.Upgradeable;
SearchDetails.ReplaceableToggle.Value = currentSearch?.Replaceable;
SearchDetails.PopulateSearch(currentSearch);
suppressSearch = false;
}

private static string CombinePieces(string joined, string piece)
{
return string.IsNullOrEmpty(joined) ? piece : $"{joined} {piece}";
}

private void SearchDetails_ApplySearch(object sender, EventArgs e)
{
if (suppressSearch)
{
return;
}

var knownLabels = Main.Instance.ManageMods.mainModList.ModuleLabels.LabelsFor(Main.Instance.CurrentInstance.Name).ToList();

currentSearch = new ModSearch(
SearchDetails.FilterByNameTextBox.Text,
SearchDetails.FilterByAuthorTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByDescriptionTextBox.Text,
SearchDetails.FilterByLanguageTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByDependsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByRecommendsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterBySuggestsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByConflictsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByTagsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
SearchDetails.FilterByLabelsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries)
.Select(ln => knownLabels.FirstOrDefault(lb => lb.Name == ln))
.Where(lb => lb != null)
.ToList(),
SearchDetails.CompatibleToggle.Value,
SearchDetails.InstalledToggle.Value,
SearchDetails.CachedToggle.Value,
SearchDetails.NewlyCompatibleToggle.Value,
SearchDetails.UpgradeableToggle.Value,
SearchDetails.ReplaceableToggle.Value
);
currentSearch = SearchDetails.CurrentSearch();
suppressSearch = true;
FilterCombinedTextBox.Text = currentSearch?.Combined ?? "";
suppressSearch = false;
Expand Down
Loading

0 comments on commit 8dc8643

Please sign in to comment.