Skip to content

Commit

Permalink
split EGames
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed May 19, 2024
1 parent d7dac03 commit e94f558
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
17 changes: 15 additions & 2 deletions FModel/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ public static string GetDescription(this Enum value)
{
var fi = value.GetType().GetField(value.ToString());
if (fi == null) return $"{value} ({value:D})";

var attributes = (DescriptionAttribute[]) fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return attributes.Length > 0 ? attributes[0].Description : $"{value} ({value:D})";
if (attributes.Length > 0) return attributes[0].Description;


var suffix = $"{value:D}";
var current = Convert.ToInt32(suffix);
var target = current & ~0xF;
if (current != target)
{
var values = Enum.GetValues(value.GetType());
var index = Array.IndexOf(values, value);
suffix = values.GetValue(index - (current - target))?.ToString();
}
return $"{value} ({suffix})";
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -43,4 +56,4 @@ public static T Previous<T>(this Enum value)
var i = Array.IndexOf(values, value) - 1;
return i == -1 ? (T) values.GetValue(values.Length - 1) : (T) values.GetValue(i);
}
}
}
18 changes: 15 additions & 3 deletions FModel/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public bool UseCustomOutputFolders
set => SetProperty(ref _useCustomOutputFolders, value);
}

private bool _useCustomEGames;
public bool UseCustomEGames
{
get => _useCustomEGames;
set => SetProperty(ref _useCustomEGames, value);
}

private EUpdateMode _selectedUpdateMode;
public EUpdateMode SelectedUpdateMode
{
Expand Down Expand Up @@ -170,6 +177,7 @@ public ETextureFormat SelectedTextureExportFormat

public ReadOnlyObservableCollection<EUpdateMode> UpdateModes { get; private set; }
public ReadOnlyObservableCollection<EGame> UeGames { get; private set; }
public ReadOnlyObservableCollection<EGame> CustomUeGames { get; private set; }
public ReadOnlyObservableCollection<ELanguage> AssetLanguages { get; private set; }
public ReadOnlyObservableCollection<EAesReload> AesReloads { get; private set; }
public ReadOnlyObservableCollection<EDiscordRpc> DiscordRpcs { get; private set; }
Expand Down Expand Up @@ -265,8 +273,12 @@ public void Initialize()
SelectedAesReload = UserSettings.Default.AesReload;
SelectedDiscordRpc = UserSettings.Default.DiscordRpc;

var ueGames = EnumerateUeGames().ToArray();
UseCustomEGames = ueGames[1].Contains(SelectedUeGame);

UpdateModes = new ReadOnlyObservableCollection<EUpdateMode>(new ObservableCollection<EUpdateMode>(EnumerateUpdateModes()));
UeGames = new ReadOnlyObservableCollection<EGame>(new ObservableCollection<EGame>(EnumerateUeGames()));
UeGames = new ReadOnlyObservableCollection<EGame>(new ObservableCollection<EGame>(ueGames[0]));
CustomUeGames = new ReadOnlyObservableCollection<EGame>(new ObservableCollection<EGame>(ueGames[1]));
AssetLanguages = new ReadOnlyObservableCollection<ELanguage>(new ObservableCollection<ELanguage>(EnumerateAssetLanguages()));
AesReloads = new ReadOnlyObservableCollection<EAesReload>(new ObservableCollection<EAesReload>(EnumerateAesReloads()));
DiscordRpcs = new ReadOnlyObservableCollection<EDiscordRpc>(new ObservableCollection<EDiscordRpc>(EnumerateDiscordRpcs()));
Expand Down Expand Up @@ -331,11 +343,11 @@ public bool Save(out List<SettingsOut> whatShouldIDo)
}

private IEnumerable<EUpdateMode> EnumerateUpdateModes() => Enum.GetValues<EUpdateMode>();
private IEnumerable<EGame> EnumerateUeGames()
private IEnumerable<IGrouping<bool, EGame>> EnumerateUeGames()
=> Enum.GetValues<EGame>()
.GroupBy(value => (int)value)
.Select(group => group.First())
.OrderBy(value => (int)value == ((int)value & ~0xF));
.GroupBy(value => (int)value == ((int)value & ~0xF));
private IEnumerable<ELanguage> EnumerateAssetLanguages() => Enum.GetValues<ELanguage>();
private IEnumerable<EAesReload> EnumerateAesReloads() => Enum.GetValues<EAesReload>();
private IEnumerable<EDiscordRpc> EnumerateDiscordRpcs() => Enum.GetValues<EDiscordRpc>();
Expand Down
15 changes: 14 additions & 1 deletion FModel/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,28 @@
<Button Grid.Row="5" Grid.Column="6" Content="..." HorizontalAlignment="Right" Click="OnBrowseDirectories" Margin="0 0 0 5" />

<TextBlock Grid.Row="6" Grid.Column="0" Text="UE Versions *" VerticalAlignment="Center" Margin="0 0 0 5" ToolTip="Override the UE version to use when parsing packages" />
<ComboBox Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="5" ItemsSource="{Binding SettingsView.UeGames}" SelectedItem="{Binding SettingsView.SelectedUeGame, Mode=TwoWay}"
<ComboBox Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="3" SelectedItem="{Binding SettingsView.SelectedUeGame, Mode=TwoWay}"
DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Views.SettingsView}}}"
Margin="0 0 0 5">
<ComboBox.Style>
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
<Setter Property="ItemsSource" Value="{Binding SettingsView.UeGames}" />
<Style.Triggers>
<DataTrigger Binding="{Binding SettingsView.UseCustomEGames}" Value="True">
<Setter Property="ItemsSource" Value="{Binding SettingsView.CustomUeGames}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={x:Static converters:EnumToStringConverter.Instance}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Grid.Row="6" Grid.Column="6" Margin="5 0 0 5" ToolTip="Enable custom UE versions"
DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Views.SettingsView}}}"
IsChecked="{Binding SettingsView.UseCustomEGames, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

<TextBlock Grid.Row="7" Grid.Column="0" Text="Texture Platform *" VerticalAlignment="Center" Margin="0 0 0 5" ToolTip="Override the game's platform to ensure texture compatibility" />
<ComboBox Grid.Row="7" Grid.Column="2" Grid.ColumnSpan="5" ItemsSource="{Binding SettingsView.Platforms}" SelectedItem="{Binding SettingsView.SelectedUePlatform, Mode=TwoWay}"
Expand Down

0 comments on commit e94f558

Please sign in to comment.