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

Color Coded Resolutions #76

Merged
merged 35 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bfd00bb
Initial color code
FaithBeam Sep 18, 2023
e383569
WIP aspect ratio filter
FaithBeam Sep 19, 2023
628f5e6
Add aspect ratio filter
FaithBeam Oct 5, 2023
7b11cfb
wip aspect ratio combobox
FaithBeam Oct 6, 2023
237c0f4
+ Optional resolution coloring
FaithBeam Oct 6, 2023
10d8f0a
Sort resolutions by their aspect ratio
FaithBeam Oct 7, 2023
71f69af
Rearrange aspect ratio checkboxes
FaithBeam Oct 7, 2023
a200c0e
Register mainwindow in dependency injection
FaithBeam Oct 7, 2023
8582f0e
before autofac
FaithBeam Oct 7, 2023
459b6ae
set the selected resolution to the first resolution in the filtered l…
FaithBeam Oct 7, 2023
b1b4dc1
Prevent aspect ratio combo from growing/shrinking
FaithBeam Oct 7, 2023
85ef5e4
Add tooltip for the Add Resolution button
FaithBeam Oct 7, 2023
1ee937d
Add the ability to reset the aspect ratio combo box by holding ctrl a…
FaithBeam Oct 7, 2023
22002f0
Change the aspect ratio label on the new resolution dialog to ??? for…
FaithBeam Oct 7, 2023
e89d789
Improve tool tip text editor readability with <LineBreak />
FaithBeam Oct 7, 2023
8ed9835
remove to none tip
FaithBeam Oct 7, 2023
302bba3
Tooltip text improvements
FaithBeam Oct 7, 2023
78374fa
Use default comboboxitem background color when color code is not sele…
FaithBeam Oct 7, 2023
b07902c
Remove color coding because colors are a pita
FaithBeam Oct 7, 2023
3be40d7
Revert "Remove color coding because colors are a pita"
FaithBeam Oct 7, 2023
25cdd29
Added colors back
FaithBeam Oct 7, 2023
4436e32
Add color coding again
FaithBeam Oct 7, 2023
d2ec6ed
Change green color
FaithBeam Oct 7, 2023
4dac43c
better selected resolution handling
FaithBeam Oct 7, 2023
98fb7c1
remove margin around the wrapper row
FaithBeam Oct 7, 2023
5f1fd1a
remove commented code
FaithBeam Oct 7, 2023
cadd5a6
Up the version
FaithBeam Oct 7, 2023
d526276
Update dotnet.yml
FaithBeam Oct 7, 2023
1853503
Fix coloring resolutions with width that is a multiple of 1600.
FaithBeam Oct 7, 2023
593249a
Forgot these other conditions to fix previous issue
FaithBeam Oct 7, 2023
37c5d47
Update the patcher image
FaithBeam Oct 8, 2023
0c3adec
Revert "Update the patcher image"
FaithBeam Oct 8, 2023
8dfae02
Update the image without messing the other formatting
FaithBeam Oct 8, 2023
254c57e
Add missing icon to the custom resolution dialog.
FaithBeam Oct 9, 2023
0f23059
Fix build warnings
FaithBeam Oct 9, 2023
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: 4 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ name: .NET

env:
PACK_ID: Sims1WidescreenPatcher
PACK_VER: 3.6.0
PACK_VER: 3.7.0

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
workflow_dispatch:

jobs:
linux:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This program patches **The Sims 1** to a custom resolution.

![The Sims 1 Widescreen Patcher](https://i.imgur.com/PdKHV0k.png)
![The Sims 1 Widescreen Patcher](https://i.imgur.com/b8BU9lG.png)

## Requirements

Expand Down
84 changes: 84 additions & 0 deletions Sims1WidescreenPatcher.Core/Models/AspectRatio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Numerics;

namespace Sims1WidescreenPatcher.Core.Models;

public class AspectRatio : IEqualityComparer<AspectRatio>, IComparable<AspectRatio>
{
protected bool Equals(AspectRatio other)
{
return Numerator == other.Numerator && Denominator == other.Denominator;
}

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((AspectRatio) obj);
}

public override int GetHashCode()
{
unchecked
{
return (Numerator * 397) ^ Denominator;
}
}

public int Numerator;
public int Denominator;

public AspectRatio(int width, int height)
{
CalculateAspectRatio(width, height);
}

public override string ToString()
{
return $"{Numerator}:{Denominator}";
}

public static bool operator ==(AspectRatio obj1, AspectRatio obj2)
{
return (obj1.Numerator == obj2.Numerator
&& obj1.Denominator == obj2.Denominator);
}

public static bool operator !=(AspectRatio obj1, AspectRatio obj2)
{
return !(obj1 == obj2);
}

private void CalculateAspectRatio(int width, int height)
{
var gcd = BigInteger.GreatestCommonDivisor(width, height);
Numerator = width / (int)gcd;
Denominator = height / (int)gcd;
}

public bool Equals(AspectRatio x, AspectRatio y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return x.Numerator == y.Numerator && x.Denominator == y.Denominator;
}

public int GetHashCode(AspectRatio obj)
{
unchecked
{
return (obj.Numerator * 397) ^ obj.Denominator;
}
}

public int CompareTo(AspectRatio? other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
var numeratorComparison = Numerator.CompareTo(other.Numerator);
if (numeratorComparison != 0) return numeratorComparison;
return Denominator.CompareTo(other.Denominator);
}
}
24 changes: 16 additions & 8 deletions Sims1WidescreenPatcher.Core/Models/Resolution.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Sims1WidescreenPatcher.Core.Models;
using System.Numerics;

public class Resolution
namespace Sims1WidescreenPatcher.Core.Models;

public class Resolution : IComparable<Resolution>
{
private sealed class WidthHeightEqualityComparer : IEqualityComparer<Resolution>
{
Expand All @@ -25,21 +27,27 @@ public int GetHashCode(Resolution obj)
public static IEqualityComparer<Resolution>? WidthHeightComparer { get; } = new WidthHeightEqualityComparer();

public int Width { get; }

public int Height { get; }
public AspectRatio AspectRatio { get; }

public Resolution(int width, int height)
{
Width = width;
Height = height;
AspectRatio = new AspectRatio(width, height);
}

public override string ToString()
{
if (Width == -1 && Height == -1)
{
return @"<Custom Resolution>";
}
return $"{Width}x{Height}";
return $"{Width}x{Height} ({AspectRatio})";
}

public int CompareTo(Resolution? other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
var widthComparison = Width.CompareTo(other.Width);
if (widthComparison != 0) return widthComparison;
return Height.CompareTo(other.Height);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0" />
<PackageReference Include="ReactiveUI" Version="19.2.1" />
<PackageReference Include="Avalonia" Version="11.0.4" />
<PackageReference Include="DynamicData" Version="7.14.2" />
<PackageReference Include="ReactiveUI" Version="19.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using System.Reactive;
using System.Reactive.Linq;
using ReactiveUI;
using Sims1WidescreenPatcher.Core.Models;

namespace Sims1WidescreenPatcher.Core.ViewModels;

public class CustomResolutionDialogViewModel : ViewModelBase
public class CustomResolutionDialogViewModel : ViewModelBase, ICustomResolutionDialogViewModel
{
#region Fields

private string _width = "";
private string _height = "";
private readonly ObservableAsPropertyHelper<AspectRatio?> _aspectRatio;

#endregion

Expand All @@ -18,6 +20,17 @@ public class CustomResolutionDialogViewModel : ViewModelBase
public CustomResolutionDialogViewModel()
{
OkCommand = ReactiveCommand.Create(() => new Resolution(int.Parse(Width), int.Parse(Height)));
_aspectRatio = this
.WhenAnyValue(x => x.Width, x => x.Height, (w, h) =>
{
if (!int.TryParse(w, out var width) || !int.TryParse(h, out var height))
{
return null;
}
return new AspectRatio(width, height);
})
.Throttle(TimeSpan.FromMilliseconds(100))
.ToProperty(this, x => x.AspectRatio);
}

#endregion
Expand All @@ -42,5 +55,7 @@ public string Height
set => this.RaiseAndSetIfChanged(ref _height, value);
}

public AspectRatio? AspectRatio => _aspectRatio.Value;

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel;
using System.Reactive;
using ReactiveUI;
using Sims1WidescreenPatcher.Core.Models;

namespace Sims1WidescreenPatcher.Core.ViewModels;

public interface ICustomResolutionDialogViewModel
{
ReactiveCommand<Unit, Resolution> OkCommand { get; }
string Width { get; set; }
string Height { get; set; }
AspectRatio? AspectRatio { get; }
IObservable<IReactivePropertyChangedEventArgs<IReactiveObject>> Changing { get; }
IObservable<IReactivePropertyChangedEventArgs<IReactiveObject>> Changed { get; }
IObservable<Exception> ThrownExceptions { get; }
IDisposable SuppressChangeNotifications();
bool AreChangeNotificationsEnabled();
IDisposable DelayChangeNotifications();
event PropertyChangingEventHandler? PropertyChanging;
event PropertyChangedEventHandler? PropertyChanged;
}
41 changes: 41 additions & 0 deletions Sims1WidescreenPatcher.Core/ViewModels/IMainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Reactive;
using System.Windows.Input;
using Avalonia.Collections;
using Avalonia.Platform.Storage;
using ReactiveUI;
using Sims1WidescreenPatcher.Core.Models;
using Sims1WidescreenPatcher.Utilities.Models;

namespace Sims1WidescreenPatcher.Core.ViewModels;

public interface IMainWindowViewModel
{
ICommand PatchCommand { get; }
ICommand UninstallCommand { get; }
ICommand OpenFile { get; }
Interaction<Unit, IStorageFile?> ShowOpenFileDialog { get; }
ICommand CustomResolutionCommand { get; }
Interaction<ICustomResolutionDialogViewModel, Resolution?> ShowCustomResolutionDialog { get; }
Interaction<CustomYesNoDialogViewModel, YesNoDialogResponse?> ShowCustomYesNoDialog { get; }
Interaction<CustomInformationDialogViewModel, Unit> ShowCustomInformationDialog { get; }
string Path { get; set; }
AspectRatio? SelectedAspectRatio { get; set; }
bool SortByAspectRatio { get; set; }
bool IsResolutionsColored { get; set; }
ReadOnlyObservableCollection<AspectRatio> AspectRatios { get; }
ReadOnlyObservableCollection<Resolution> FilteredResolutions { get; }
Resolution? SelectedResolution { get; set; }
AvaloniaList<IWrapper> Wrappers { get; }
int SelectedWrapperIndex { get; set; }
double Progress { get; }
IObservable<IReactivePropertyChangedEventArgs<IReactiveObject>> Changing { get; }
IObservable<IReactivePropertyChangedEventArgs<IReactiveObject>> Changed { get; }
IObservable<Exception> ThrownExceptions { get; }
IDisposable SuppressChangeNotifications();
bool AreChangeNotificationsEnabled();
IDisposable DelayChangeNotifications();
event PropertyChangingEventHandler? PropertyChanging;
event PropertyChangedEventHandler? PropertyChanged;
}
Loading