Skip to content

Commit 8653d34

Browse files
Add new profile button
1 parent 41b624a commit 8653d34

6 files changed

Lines changed: 77 additions & 15 deletions

File tree

Source/HedgeModManager.UI/App.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<local:LogStringConverter x:Key="LogStringConverter"/>
2323
<local:StringLocalizeConverter x:Key="StringLocalizeConverter"/>
2424
<local:StringLocalizeIfNotEmptyConverter x:Key="StringLocalizeIfNotEmptyConverter"/>
25+
<local:BoolIfEqualsConverter x:Key="BoolIfEqualsConverter"/>
2526
</Application.Resources>
2627

2728
<Application.DataTemplates>

Source/HedgeModManager.UI/Controls/Modals/ProfileManagerModal.axaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
<local:WindowModal.Buttons>
2020
<Grid>
2121
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Spacing="10">
22+
<cb:Button Text="Modal.Button.NewProfile" Click="OnNewClick" IsEnabled="{Binding ViewModel.CanDuplicate, RelativeSource={RelativeSource AncestorType=local:ProfileManagerModal}}" />
2223
<cb:Button Text="Modal.Button.DuplicateProfile" Click="OnDuplicateClick" IsEnabled="{Binding ViewModel.CanDuplicate, RelativeSource={RelativeSource AncestorType=local:ProfileManagerModal}}" />
2324
<cb:Button Text="Modal.Button.DeleteProfile" Click="OnDeleteClick" IsEnabled="{Binding ViewModel.CanDelete, RelativeSource={RelativeSource AncestorType=local:ProfileManagerModal}}" />
2425
<cb:Button Text="Modal.Button.RenameProfile" Click="OnRenameClick" IsEnabled="{Binding ViewModel.CanRename, RelativeSource={RelativeSource AncestorType=local:ProfileManagerModal}}" />
25-
<cb:Button Text="Modal.Button.SelectProfile" Click="OnSelectClick" IsEnabled="{Binding ViewModel.CanSelect, RelativeSource={RelativeSource AncestorType=local:ProfileManagerModal}}" />
2626
</StackPanel>
2727
<StackPanel HorizontalAlignment="Right">
2828
<cb:Button Text="Common.Button.Close" Click="OnCloseClick" />
@@ -37,11 +37,22 @@
3737
HorizontalAlignment="Stretch"
3838
VerticalAlignment="Stretch"
3939
Background="{DynamicResource BackgroundL0Brush}"
40-
SelectionChanged="OnSelectionChanged">
40+
SelectionChanged="OnSelectionChanged" DoubleTapped="OnDoubleTapped">
4141
<ListBox.ItemTemplate>
4242
<DataTemplate>
4343
<StackPanel Orientation="Vertical" Spacing="4">
44-
<TextBlock Text="{Binding Name}" Foreground="{DynamicResource Text.NormalBrush}" />
44+
<StackPanel Orientation="Horizontal" Spacing="0">
45+
<TextBlock Text="{Binding Name}" Foreground="{DynamicResource Text.NormalBrush}" />
46+
<TextBlock Text="{DynamicResource Modal.Text.SelectedProfile}" Foreground="{DynamicResource Text.SubBrush}">
47+
<TextBlock.IsVisible>
48+
<MultiBinding Converter="{StaticResource BoolIfEqualsConverter}">
49+
<Binding Path="." />
50+
<Binding Path="ViewModel.MainWindowViewModel.SelectedProfile"
51+
RelativeSource="{RelativeSource AncestorType=local:ProfileManagerModal}" />
52+
</MultiBinding>
53+
</TextBlock.IsVisible>
54+
</TextBlock>
55+
</StackPanel>
4556
<TextBlock Text="{Binding FileName}" Foreground="{DynamicResource Text.SubBrush}"/>
4657
</StackPanel>
4758
</DataTemplate>

Source/HedgeModManager.UI/Controls/Modals/ProfileManagerModal.axaml.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ public string GenerateProfileName(string baseName)
2828

2929
var profiles = ViewModel.MainWindowViewModel.Profiles;
3030
string name = baseName;
31+
int count = 0;
3132
while (profiles.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
32-
name += " - Copy";
33+
{
34+
++count;
35+
name = $"{baseName} ({count})";
36+
}
37+
3338
return name;
3439
}
3540

@@ -55,6 +60,32 @@ private void OnCloseClick(object? sender, RoutedEventArgs e)
5560
Close();
5661
}
5762

63+
private void OnNewClick(object? sender, RoutedEventArgs e)
64+
{
65+
if (ViewModel.MainWindowViewModel == null)
66+
return;
67+
if (ViewModel.MainWindowViewModel.SelectedGame?.Game is not ModdableGameGeneric game)
68+
return;
69+
70+
// Create profile
71+
var profile = new ModProfile()
72+
{
73+
Name = GenerateProfileName("New Profile")
74+
};
75+
76+
var modal = new ProfileRenameModal(profile, true);
77+
modal.OnProfileRenamed = () =>
78+
{
79+
profile.FileName = profile.GenerateFileNameFromName();
80+
ViewModel.MainWindowViewModel.Profiles.Add(profile);
81+
ViewModel.MainWindowViewModel.SelectedProfile = ViewModel.SelectedProfile = profile;
82+
ProfileListBox.Bind(ListBox.ItemsSourceProperty, new Binding("Profiles"));
83+
Dispatcher.UIThread.Invoke(async () => await ViewModel.MainWindowViewModel.SaveProfilesAsync(game));
84+
ViewModel.Update();
85+
};
86+
modal.Open(ViewModel.MainWindowViewModel);
87+
}
88+
5889
private void OnDuplicateClick(object? sender, RoutedEventArgs e)
5990
{
6091
if (ViewModel.MainWindowViewModel == null || ViewModel.SelectedProfile == null)
@@ -134,7 +165,7 @@ private void OnRenameClick(object? sender, RoutedEventArgs e)
134165
if (ViewModel.MainWindowViewModel == null || ViewModel.SelectedProfile == null)
135166
return;
136167

137-
var modal = new ProfileRenameModal(ViewModel.SelectedProfile);
168+
var modal = new ProfileRenameModal(ViewModel.SelectedProfile, false);
138169
modal.OnProfileRenamed = () =>
139170
{
140171
ProfileListBox.Bind(ListBox.ItemsSourceProperty, new Binding("Profiles"));
@@ -143,17 +174,17 @@ private void OnRenameClick(object? sender, RoutedEventArgs e)
143174
ViewModel.Update();
144175
}
145176

146-
private void OnSelectClick(object? sender, RoutedEventArgs e)
177+
private void OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
147178
{
148-
if (ViewModel.MainWindowViewModel == null || ViewModel.SelectedProfile == null)
149-
return;
150-
151-
ViewModel.MainWindowViewModel.SelectedProfile = ViewModel.SelectedProfile;
152179
ViewModel.Update();
153180
}
154181

155-
private void OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
182+
private void OnDoubleTapped(object? sender, Avalonia.Input.TappedEventArgs e)
156183
{
184+
if (ViewModel.MainWindowViewModel == null || ViewModel.SelectedProfile == null)
185+
return;
186+
187+
ViewModel.MainWindowViewModel.SelectedProfile = ViewModel.SelectedProfile;
157188
ViewModel.Update();
158189
}
159190

Source/HedgeModManager.UI/Controls/Modals/ProfileRenameModal.axaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Avalonia.Interactivity;
22
using Avalonia.Markup.Xaml;
3+
using static HedgeModManager.UI.Languages.Language;
34

45
namespace HedgeModManager.UI.Controls.Modals;
56

@@ -10,12 +11,14 @@ public partial class ProfileRenameModal : WindowModal
1011
public Action? OnProfileRenamed { get; set; }
1112

1213
// Preview
13-
public ProfileRenameModal() : this(new ModProfile("No Profile")) { }
14+
public ProfileRenameModal() : this(new ModProfile("No Profile"), false) { }
1415

15-
public ProfileRenameModal(ModProfile modProfile)
16+
public ProfileRenameModal(ModProfile modProfile, bool newProfile)
1617
{
1718
SelectedProfile = modProfile;
1819
AvaloniaXamlLoader.Load(this);
20+
if (newProfile)
21+
Title = Localize("Modal.Title.NewProfile");
1922
}
2023

2124
private void OnOkClick(object? sender, RoutedEventArgs e)

Source/HedgeModManager.UI/Converters.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,18 @@ public class StringLocalizeIfNotEmptyConverter : StringLocalizeConverter
109109
return BindingNotification.UnsetValue;
110110
return base.Convert(value, targetType, parameter, culture);
111111
}
112-
}
112+
}
113+
114+
public class BoolIfEqualsConverter : IMultiValueConverter
115+
{
116+
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
117+
{
118+
if (values.Count < 2) return false;
119+
return Equals(values[0], values[1]);
120+
}
121+
122+
public object[] ConvertBack(object value, Type[] targetTypes, object? parameter, CultureInfo culture)
123+
{
124+
return [BindingNotification.UnsetValue];
125+
}
126+
}

Source/HedgeModManager.UI/Languages/en-AU.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,16 @@
137137
<system:String x:Key="Modal.Button.DeleteProfile" >Delete</system:String>
138138
<system:String x:Key="Modal.Button.DuplicateProfile" >Duplicate</system:String>
139139
<system:String x:Key="Modal.Button.ExportLog" >Save Log File</system:String>
140+
<system:String x:Key="Modal.Button.NewProfile" >New</system:String>
140141
<system:String x:Key="Modal.Button.RenameProfile" >Rename</system:String>
141-
<system:String x:Key="Modal.Button.SelectProfile" >Select</system:String>
142142
<system:String x:Key="Modal.Header.Credits" >Credits</system:String>
143143
<system:String x:Key="Modal.Header.Description" >Description</system:String>
144144
<system:String x:Key="Modal.Header.AboutMod" >{0} v{1}</system:String>
145145
<system:String x:Key="Modal.Header.AboutModAuthor" >Authored by {0} on {1}</system:String>
146146
<system:String x:Key="Modal.Text.GameMissing" >Missing Unleashed Recompiled?</system:String>
147147
<system:String x:Key="Modal.Text.NewProfileName" >New Name:</system:String>
148148
<system:String x:Key="Modal.Text.TargetGame" >For {0}</system:String>
149+
<system:String x:Key="Modal.Text.SelectedProfile" > (Selected)</system:String>
149150
<system:String x:Key="Modal.Title.AboutMod" >About {0}</system:String>
150151
<system:String x:Key="Modal.Title.CodeCompileError" >Code Compilation Error</system:String>
151152
<system:String x:Key="Modal.Title.Confirm" >Confirmation</system:String>
@@ -158,6 +159,7 @@
158159
<system:String x:Key="Modal.Title.InstallError" >Install Error</system:String>
159160
<system:String x:Key="Modal.Title.LoadError" >Load Error</system:String>
160161
<system:String x:Key="Modal.Title.MissingDependency" >Missing Dependencies</system:String>
162+
<system:String x:Key="Modal.Title.NewProfile" >New Profile</system:String>
161163
<system:String x:Key="Modal.Title.ProfileManager" >Manage Profiles</system:String>
162164
<system:String x:Key="Modal.Title.SaveError" >Save Error</system:String>
163165
<system:String x:Key="Modal.Title.SelectMods" >Select Mods Directory...</system:String>

0 commit comments

Comments
 (0)