Skip to content
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
5 changes: 5 additions & 0 deletions Knossos.NET/AppStyles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<StreamGeometry x:Key="ArrowUpRegular">M4.21157,12.7326 C3.9244,13.0312 3.93361,13.5059 4.23213,13.7931 C4.53064,14.0803 5.00543,14.0711 5.29259,13.7725 L13.2521,5.49831 L13.2521,24.2511 C13.2521,24.6653 13.5879,25.0011 14.0021,25.0011 C14.4163,25.0011 14.7521,24.6653 14.7521,24.2511 L14.7521,5.4993 L22.7106,13.7725 C22.9978,14.0711 23.4726,14.0803 23.7711,13.7931 C24.0696,13.5059 24.0788,13.0312 23.7916,12.7326 L14.7223,3.30466 C14.3289,2.89568 13.6743,2.89568 13.2809,3.30466 L4.21157,12.7326 Z</StreamGeometry>
<StreamGeometry x:Key="DocumentArrowLeftRegular">M10.5 8.25C10.5 7.2835 11.2835 6.5 12.25 6.5H24V15.25C24 17.3211 25.6789 19 27.75 19H37.5V39.75C37.5 40.7165 36.7165 41.5 35.75 41.5H24.2608C23.7353 42.4086 23.1029 43.2476 22.3809 44H35.75C38.0972 44 40 42.0972 40 39.75V18.4142C40 17.8175 39.7629 17.2452 39.341 16.8232L27.1768 4.65901C26.7548 4.23705 26.1825 4 25.5858 4H12.25C9.90279 4 8 5.90279 8 8.25V22.9963C8.79632 22.6642 9.63275 22.4091 10.5 22.2402V8.25ZM35.4822 16.5H27.75C27.0596 16.5 26.5 15.9404 26.5 15.25V7.51777L35.4822 16.5Z M24 35C24 41.0751 19.0751 46 13 46C6.92487 46 2 41.0751 2 35C2 28.9249 6.92487 24 13 24C19.0751 24 24 28.9249 24 35ZM11.7071 29.2929C11.3166 28.9024 10.6834 28.9024 10.2929 29.2929L5.29289 34.2929C4.90237 34.6834 4.90237 35.3166 5.29289 35.7071L10.2929 40.7071C10.6834 41.0976 11.3166 41.0976 11.7071 40.7071C12.0976 40.3166 12.0976 39.6834 11.7071 39.2929L8.41421 36H20C20.5523 36 21 35.5523 21 35C21 34.4477 20.5523 34 20 34H8.41421L11.7071 30.7071C12.0976 30.3166 12.0976 29.6834 11.7071 29.2929Z</StreamGeometry>
<StreamGeometry x:Key="ChevronLeftRegular">M31.8839 8.36612C32.372 8.85427 32.372 9.64573 31.8839 10.1339L18.0178 24L31.8839 37.8661C32.372 38.3543 32.372 39.1457 31.8839 39.6339C31.3957 40.122 30.6043 40.122 30.1161 39.6339L15.3661 24.8839C14.878 24.3957 14.878 23.6043 15.3661 23.1161L30.1161 8.36612C30.6043 7.87796 31.3957 7.87796 31.8839 8.36612Z</StreamGeometry>
<StreamGeometry x:Key="FilterRegular">M17.25,19 C17.6642136,19 18,19.3357864 18,19.75 C18,20.1642136 17.6642136,20.5 17.25,20.5 L10.75,20.5 C10.3357864,20.5 10,20.1642136 10,19.75 C10,19.3357864 10.3357864,19 10.75,19 L17.25,19 Z M21.25,13 C21.6642136,13 22,13.3357864 22,13.75 C22,14.1642136 21.6642136,14.5 21.25,14.5 L6.75,14.5 C6.33578644,14.5 6,14.1642136 6,13.75 C6,13.3357864 6.33578644,13 6.75,13 L21.25,13 Z M24.25,7 C24.6642136,7 25,7.33578644 25,7.75 C25,8.16421356 24.6642136,8.5 24.25,8.5 L3.75,8.5 C3.33578644,8.5 3,8.16421356 3,7.75 C3,7.33578644 3.33578644,7 3.75,7 L24.25,7 Z</StreamGeometry>
</Styles.Resources>

<!--Color Resource Definition-->
Expand Down Expand Up @@ -317,4 +318,8 @@
<Style Selector="TabItem:pointerover /template/ ContentPresenter">
<Setter Property="Cursor" Value="Hand"/>
</Style>

<Style Selector="FlyoutPresenter.filterFlyout">
<Setter Property="MaxWidth" Value="1000"/>
</Style>
</Styles>
Binary file removed Knossos.NET/Assets/general/sort-icon.png
Binary file not shown.
13 changes: 12 additions & 1 deletion Knossos.NET/Classes/Knossos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,16 @@ public async static void LoadBasePath(bool isQuickLaunch = false)
{
if (globalSettings.basePath != null)
{
//Clear Mod Tags
ModTags.Clear();
MainWindowViewModel.Instance?.tagFilter.Clear();

await FolderSearchRecursive(globalSettings.basePath, isQuickLaunch).ConfigureAwait(false);

if (!isQuickLaunch)
{
//Sort/Re-sort installed mods
MainWindowViewModel.Instance?.InstalledModsView?.ChangeSort(MainWindowViewModel.Instance?.sharedSortType!);
MainWindowViewModel.Instance?.InstalledModsView?.ChangeSort(globalSettings.sortType);

//Red border for mod with missing deps
Dispatcher.UIThread.Invoke(() =>
Expand All @@ -733,6 +737,13 @@ await Task.Run(async () => {
{
await QuickLaunch();
}

//generate mod tag buttons
Dispatcher.UIThread.Invoke(() =>
{
NebulaModListView.Instance?.GenerateFilterButtons();
ModListView.Instance?.GenerateFilterButtons();
});
}
}

Expand Down
267 changes: 267 additions & 0 deletions Knossos.NET/Classes/ModTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
using Knossos.NET.Models;
using System.Collections.Generic;
using System.Linq;

namespace Knossos.NET.Classes
{
public class ModTag
{
public ModTag(string modID, string? filter = null, string? tag = null)
{
ModID = modID;
if(filter != null)
Filters.Add(filter.ToLower());
if(tag != null)
Tags.Add(tag.ToLower());
}

public void AddFilter(string filter)
{
//special cases:
//do not add FS2_MOD filter if FS1_MOD exist
//Remove FS2_MOD if FS1_MOD mod is added
if (filter.ToLower() == "fs1_mod")
Filters.Remove("fs2_mod");
if (filter.ToLower() == "fs2_mod" && FilterExist("fs1_mod"))
return;
Filters.Add(filter);
}

/// <summary>
/// Check if a filter exist in this modid filterlist
/// Case insensitive
/// </summary>
/// <param name="filter"></param>
/// <returns>true/false</returns>
public bool FilterExist(string filter)
{
for (int i = 0; i < Filters.Count(); i++)
{
if(string.Compare(Filters[i], filter, true) == 0)
{
return true;
}
}
return false;
}

public List<string> GetFilters()
{
return Filters;
}

public void AddTag(string tag)
{
Tags.Add(tag);
}

/// <summary>
/// Check if a tag exist in this modid taglist
/// Case insensitive
/// </summary>
/// <param name="tag"></param>
/// <returns>true/false</returns>
public bool TagExist(string tag)
{
for (int i = 0; i < Tags.Count(); i++)
{
if (string.Compare(Tags[i], tag, true) == 0)
{
return true;
}
}
return false;
}

public string ModID { get; private set; } = string.Empty;
private List<string> Filters { get; set; } = new List<string>();
private List<string> Tags { get; set; } = new List<string>();
}

/// <summary>
/// Handlers for the mod tag system
/// Each mod id can contain any number of tags
/// Tags are loaded from nebula and local locals at start
/// Then we can check here if a mod ID contains a tag
/// Note:
/// tags are case insensitive, but ModIDs arent!
/// </summary>
public static class ModTags
{
private static List<ModTag> modTags = new List<ModTag>();

/// <summary>
/// Use _ for spaces and remember these are checked with string.compare so no tags that can contain another
/// </summary>
public enum Filters
{
Total_Conversion,
Retail_FS2,
FS2_MOD,
FS1_MOD,
TC_MOD,
Utility,
Dependency,
VR_MOD,
Asset_Pack,
Demo,
Multiplayer,
Test
}

/// <summary>
/// Clear the all loaded tags and filters
/// </summary>
public static void Clear()
{
modTags.Clear();
}

/// <summary>
/// Get a list of all filters loaded, without the mod id
/// </summary>
/// <returns>List<string></returns>
public static List<string> GetListAllFilters()
{
List<string> list = new List<string>();
for (int i = 0; i < modTags.Count(); i++)
{
var filters = modTags[i].GetFilters();
for (int j = 0; j < filters.Count(); j++)
{
if (!list.Contains(filters[j]))
list.Add(filters[j]);
}
}
return list;
}

/// <summary>
/// Checks if a mod id contains a filter
/// </summary>
/// <param name="modid"></param>
/// <param name="filter"></param>
/// <returns>true/false</returns>
public static bool IsFilterPresentInModID(string modid, string filter)
{
for (int i = 0; i < modTags.Count(); i++)
{
if (modTags[i].ModID == modid)
{
return modTags[i].FilterExist(filter);
}
}
return false;
}

/// <summary>
/// Checks if a mod id contains a tag
/// </summary>
/// <param name="modid"></param>
/// <param name="tag"></param>
/// <returns>true/false</returns>
public static bool IsTagPresentInModID(string modid, string tag)
{
for (int i = 0; i < modTags.Count(); i++)
{
if (modTags[i].ModID == modid)
{
return modTags[i].TagExist(tag);
}
}
return false;
}

/// <summary>
/// Adds a mod filter to the list
/// If the id and filter dosent exist already
/// </summary>
/// <param name="id"></param>
/// <param name="filter"></param>
public static void AddModFilter(string id, string filter)
{
bool found = false;
for (int i = 0; i < modTags.Count(); i++)
{
if (modTags[i].ModID == id)
{
if(!modTags[i].FilterExist(filter))
{
modTags[i].AddFilter(filter);
found = true;
break;
}
}
}
if(!found)
{
modTags.Add(new ModTag(id, filter));
}
}

/// <summary>
/// Adds a mod tag to the list
/// If the id and tag dosent exist already
/// </summary>
/// <param name="id"></param>
/// <param name="filter"></param>
public static void AddModTag(string id, string tag)
{
bool found = false;
for (int i = 0; i < modTags.Count(); i++)
{
if (modTags[i].ModID == id)
{
if (!modTags[i].TagExist(tag))
{
modTags[i].AddTag(tag);
found = true;
break;
}
}
}
if (!found)
{
modTags.Add(new ModTag(id, null, tag));
}
}

/// <summary>
/// Generate runtime mod tags for this mod
/// Tags will be determined based on avalible mod information
/// </summary>
/// <param name="mod"></param>
public static void AddModFiltersRuntime(Mod? mod)
{
if(mod == null) return;
if(mod.id.ToLower() == "fs2")
{
AddModFilter(mod.id, Filters.Retail_FS2.ToString());
return;
}
if(mod.parent == null)
{
AddModFilter(mod.id,Filters.Total_Conversion.ToString());
}
else
{
if (mod.parent.ToLower() == "fs2")
{
if(mod.GetDependency("fsport", true) != null)
{
AddModFilter(mod.id, Filters.FS1_MOD.ToString()); // only going to work for installed mods
}
else
{
AddModFilter(mod.id, Filters.FS2_MOD.ToString());
}
}
else
{
AddModFilter(mod.id, Filters.TC_MOD.ToString());
}
}
}

}
}
1 change: 1 addition & 0 deletions Knossos.NET/Knossos.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="ObservableCollections" Version="3.3.3" />
<PackageReference Include="SharpCompress" Version="0.33.0" />
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Knossos.NET/Models/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public bool hideBuildNightly
}

[JsonIgnore]
private MainWindowViewModel.SortType _sortType = MainWindowViewModel.SortType.name;
private ModSortType _sortType = ModSortType.name;
[JsonPropertyName("last_sort_type"), JsonConverter(typeof(JsonStringEnumConverter))]
public MainWindowViewModel.SortType sortType
public ModSortType sortType
{
get { return _sortType; }
set { if (_sortType != value) { _sortType = value; pendingChangesOnAppClose = true; } }
Expand Down Expand Up @@ -915,7 +915,7 @@ public void Save(bool writeIni = true)
{
// Quickly update the sort type which is managed elsewhere
if (MainWindowViewModel.Instance != null){
sortType = MainWindowViewModel.Instance.sharedSortType;
sortType = Knossos.globalSettings.sortType;
}

var options = new JsonSerializerOptions
Expand Down
Loading