Skip to content

Commit

Permalink
Implement #252
Browse files Browse the repository at this point in the history
  • Loading branch information
iTTou committed Sep 20, 2023
1 parent 15954e5 commit aadfe83
Show file tree
Hide file tree
Showing 7 changed files with 660 additions and 465 deletions.
16 changes: 16 additions & 0 deletions WoWsShipBuilder.Common/Features/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public AppSettings(CultureDetails? selectedLanguage = null)

public bool[] BuildImageLayoutSettings { get; set; } = { true, false, true, true, true, true };

public bool ShipComparisonUseUpgradedModules { get; set; } = true;

public bool ShipComparisonHideShipsWithoutSection { get; set; }

public double ShipComparisonFiringRange { get; set; } = 10;

public string? ShipComparisonHiddenColumns { get; set; }

public void ClearSettings()
{
AutoUpdateEnabled = true;
Expand All @@ -65,6 +73,10 @@ public void ClearSettings()
OpenSecondariesAndAaExpandersByDefault = false;
BetaAccessCodes = new();
BuildImageLayoutSettings = new[] { true, false, true, true, true, true };
ShipComparisonFiringRange = 10;
ShipComparisonUseUpgradedModules = true;
ShipComparisonHideShipsWithoutSection = false;
ShipComparisonHiddenColumns = default;
}

public void UpdateFromSettings(AppSettings settings)
Expand All @@ -85,5 +97,9 @@ public void UpdateFromSettings(AppSettings settings)
OpenSecondariesAndAaExpandersByDefault = settings.OpenSecondariesAndAaExpandersByDefault;
BetaAccessCodes = settings.BetaAccessCodes;
BuildImageLayoutSettings = settings.BuildImageLayoutSettings;
ShipComparisonFiringRange = settings.ShipComparisonFiringRange;
ShipComparisonUseUpgradedModules = settings.ShipComparisonUseUpgradedModules;
ShipComparisonHideShipsWithoutSection = settings.ShipComparisonHideShipsWithoutSection;
ShipComparisonHiddenColumns = settings.ShipComparisonHiddenColumns;
}
}
221 changes: 178 additions & 43 deletions WoWsShipBuilder.Common/Features/ShipComparison/ShipComparison.razor

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public ShipComparisonViewModel(ILocalizer localizer, AppSettings appSettings)
{
this.localizer = localizer;
this.appSettings = appSettings;
LoadSettings();
}

private Dictionary<Guid, GridDataWrapper> FilteredShipList
Expand Down Expand Up @@ -88,7 +89,7 @@ private Dictionary<Guid, GridDataWrapper> FilteredShipList

public Dictionary<Guid, DispersionContainer> DispersionCache { get; } = new();

public double Range { get; private set; } = 10;
public double Range { get; private set; }

public string ResearchedShip
{
Expand All @@ -106,6 +107,13 @@ private static bool ContainsShipIndex(string shipIndex, IEnumerable<KeyValuePair
return list.Select(x => x.Value.ShipIndex).Contains(shipIndex);
}

private void LoadSettings()
{
useUpgradedModules = appSettings.ShipComparisonUseUpgradedModules;
hideShipsWithoutSelectedSection = appSettings.ShipComparisonHideShipsWithoutSection;
Range = appSettings.ShipComparisonFiringRange;
}

public Task ApplyFilters()
{
Dictionary<Guid, GridDataWrapper> dictionary = new();
Expand All @@ -119,10 +127,10 @@ public Task ApplyFilters()

dictionary.AddRange(filteredShips.Where(x => !dictionary.ContainsKey(x.Key)));

Dictionary<Guid, GridDataWrapper> cachedWrappers = wrappersCache.Where(data => SelectedTiers.Contains(data.Value.Ship.Tier) &&
SelectedClasses.Contains(data.Value.Ship.ShipClass) &&
SelectedNations.Contains(data.Value.Ship.ShipNation) &&
SelectedCategories.Contains(data.Value.Ship.ShipCategory)).ToDictionary(x => x.Key, x => x.Value);
var cachedWrappers = wrappersCache.Where(data => SelectedTiers.Contains(data.Value.Ship.Tier) &&
SelectedClasses.Contains(data.Value.Ship.ShipClass) &&
SelectedNations.Contains(data.Value.Ship.ShipNation) &&
SelectedCategories.Contains(data.Value.Ship.ShipCategory)).ToDictionary(x => x.Key, x => x.Value);

dictionary.AddRange(cachedWrappers.Where(x => !dictionary.ContainsKey(x.Key)));

Expand Down Expand Up @@ -291,7 +299,7 @@ public void EditBuilds(IEnumerable<KeyValuePair<Guid, GridDataWrapper>> newWrapp
public Dictionary<Guid, GridDataWrapper> RemoveBuilds(IEnumerable<KeyValuePair<Guid, GridDataWrapper>> wrappers)
{
Dictionary<Guid, GridDataWrapper> warnings = new();
Dictionary<Guid, GridDataWrapper> buildList = wrappers.ToDictionary(x => x.Key, x => x.Value);
var buildList = wrappers.ToDictionary(x => x.Key, x => x.Value);
foreach (var wrapper in buildList)
{
if (FilteredShipList.Count(x => x.Value.Ship.Index.Equals(wrapper.Value.Ship.Index)) > 1)
Expand Down Expand Up @@ -334,7 +342,7 @@ public void ResetAllBuilds()
{
RemoveBuilds(FilteredShipList);
SelectedShipList.Clear();
Dictionary<Guid, GridDataWrapper> list = FilteredShipList.Where(x => x.Value.Build is not null).ToDictionary(x => x.Key, x => ResetBuild(x.Value));
var list = FilteredShipList.Where(x => x.Value.Build is not null).ToDictionary(x => x.Key, x => ResetBuild(x.Value));
EditBuilds(list, true);
SetSelectAndPinAllButtonsStatus();
}
Expand Down Expand Up @@ -463,6 +471,11 @@ public void AddShip(object? obj)
{
newWrapper = new(ShipBuildContainer.CreateNew(ship, null, null) with { ShipDataContainer = GetShipDataContainer(ship) });
}
else if (obj is string shipIndex)
{
var shipFromIndex = fullShipList.First(x => x.Index.Equals(shipIndex, StringComparison.Ordinal));
newWrapper = new(ShipBuildContainer.CreateNew(shipFromIndex, null, null) with { ShipDataContainer = GetShipDataContainer(shipFromIndex) });
}
else
{
return;
Expand Down
Loading

0 comments on commit aadfe83

Please sign in to comment.