Skip to content

Commit 0de9312

Browse files
committed
+ Added skill profiles
+ Fixed select key values
1 parent 3440970 commit 0de9312

File tree

11 files changed

+299
-36
lines changed

11 files changed

+299
-36
lines changed

D2RSO/Classes/Data/SkillDataItem.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public class SkillDataItem: INotifyPropertyChanged
2121
/// </summary>
2222
public int Id { get; set; }
2323

24+
/// <summary>
25+
/// Profile id for this skill item
26+
/// </summary>
27+
public int ProfileId { get; set; }
28+
2429
/// <summary>
2530
/// File path for the image icon
2631
/// </summary>
@@ -43,7 +48,7 @@ public string IconFileName
4348
/// <summary>
4449
/// Stores key to select skill in game
4550
/// </summary>
46-
public string SelectKey { get; set; }
51+
public DataClass.KeyEntry SelectKey { get; set; }
4752
/// <summary>
4853
/// Stores key to activate skill in game
4954
/// </summary>
@@ -55,7 +60,7 @@ public string IconFileName
5560
public bool SkillKeyPressed()
5661
{
5762
//initial state with no select key
58-
if (_state == 0 && string.IsNullOrEmpty(SelectKey))
63+
if (_state == 0 && SelectKey == null)
5964
return true;
6065
//already pressed select
6166
if (_state == 1)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace D2RSO.Classes.Data
2+
{
3+
public class TrackerProfile
4+
{
5+
public int Id { get; set; }
6+
public string Name { get; set; }
7+
}
8+
}

D2RSO/Classes/DataClass.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class KeyEntry
2020
public string Name { get; set; }
2121
public string Code { get; set; }
2222

23+
public KeyEntry() {}
24+
2325
public KeyEntry(string key)
2426
{
2527
Name = Code = key;

D2RSO/Classes/SettingsClass.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.ObjectModel;
22
using System.ComponentModel;
33
using System.IO;
4+
using System.Linq;
45
using System.Runtime.CompilerServices;
56
using D2RSO.Classes.Data;
67
using Newtonsoft.Json;
@@ -36,11 +37,21 @@ public bool IsTrackerVertical
3637
set { _isTrackerVertical = value; OnPropertyChanged(); }
3738
}
3839

40+
/// <summary>
41+
/// Last selected profile Id to load profile when the app starts
42+
/// </summary>
43+
public int LastSelectedProfileId { get; set; }
44+
3945
/// <summary>
4046
/// Skills data collection
4147
/// </summary>
4248
public ObservableCollection<SkillDataItem> SkillItems { get; set; } = new();
4349

50+
/// <summary>
51+
/// Skill profiles collection
52+
/// </summary>
53+
public ObservableCollection<TrackerProfile> Profiles { get; set; } = new();
54+
4455
/// <summary>
4556
/// Tracker window X position coordinate
4657
/// </summary>
@@ -97,16 +108,21 @@ public void Save()
97108
/// <param name="filePath">File path</param>
98109
public static SettingsClass Load(string filePath)
99110
{
111+
SettingsClass result;
100112
try
101113
{
102-
return File.Exists(filePath)
114+
result = File.Exists(filePath)
103115
? JsonConvert.DeserializeObject<SettingsClass>(File.ReadAllText(filePath))
104116
: new SettingsClass();
105117
}
106118
catch
107119
{
108-
return new SettingsClass();
120+
result = new SettingsClass();
109121
}
122+
123+
if (!result.Profiles.Any()) result.Profiles.Add(new TrackerProfile {Id = 0, Name = "Default"});
124+
125+
return result;
110126
}
111127

112128
/// <summary>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using System.Windows.Input;
4+
5+
namespace D2RSO.Classes
6+
{
7+
public sealed class SimpleAsyncCommand : ICommand
8+
{
9+
public Func<object, Task<bool>> CanExecuteDelegate { get; set; }
10+
public Func<object, bool> CanExecuteDelegateEx { get; set; }
11+
public Func<object, Task> ExecuteDelegate { get; set; }
12+
13+
public SimpleAsyncCommand(Func<object, Task<bool>> can, Func<object, Task> ex)
14+
{
15+
CanExecuteDelegate = can;
16+
ExecuteDelegate = ex;
17+
}
18+
19+
public SimpleAsyncCommand(Func<object, bool> can, Func<object, Task> ex)
20+
{
21+
CanExecuteDelegateEx = can;
22+
ExecuteDelegate = ex;
23+
}
24+
25+
#region ICommand Members
26+
27+
public bool CanExecute()
28+
{
29+
return CanExecute(null);
30+
}
31+
32+
public bool CanExecute(object parameter)
33+
{
34+
if(CanExecuteDelegateEx != null)
35+
return CanExecuteDelegateEx(parameter);
36+
37+
return CanExecuteDelegate == null || CanExecuteDelegate(parameter).GetAwaiter().GetResult();
38+
}
39+
40+
public event EventHandler Executed;
41+
42+
public event EventHandler CanExecuteChanged
43+
{
44+
add => CommandManager.RequerySuggested += value;
45+
remove => CommandManager.RequerySuggested -= value;
46+
}
47+
48+
public void Execute()
49+
{
50+
Execute(null);
51+
}
52+
53+
public void Execute(object parameter)
54+
{
55+
if (ExecuteDelegate == null) return;
56+
ExecuteDelegate(parameter).GetAwaiter().GetResult();
57+
if (Executed != null)
58+
Executed(this, null);
59+
}
60+
61+
#endregion
62+
}
63+
}

D2RSO/Classes/SimpleCommand.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Windows.Input;
3+
4+
namespace D2RSO.Classes
5+
{
6+
public sealed class SimpleCommand : ICommand
7+
{
8+
public Predicate<object> CanExecuteDelegate { get; set; }
9+
public Action<object> ExecuteDelegate { get; set; }
10+
11+
public SimpleCommand(Predicate<object> can, Action<object> ex)
12+
{
13+
CanExecuteDelegate = can;
14+
ExecuteDelegate = ex;
15+
}
16+
17+
#region ICommand Members
18+
19+
public bool CanExecute()
20+
{
21+
return CanExecute(null);
22+
}
23+
24+
public bool CanExecute(object parameter)
25+
{
26+
return CanExecuteDelegate == null || CanExecuteDelegate(parameter);
27+
}
28+
29+
public event EventHandler Executed;
30+
31+
public event EventHandler CanExecuteChanged
32+
{
33+
add => CommandManager.RequerySuggested += value;
34+
remove => CommandManager.RequerySuggested -= value;
35+
}
36+
37+
public void Execute()
38+
{
39+
Execute(null);
40+
}
41+
42+
public void Execute(object parameter)
43+
{
44+
if (ExecuteDelegate == null) return;
45+
ExecuteDelegate(parameter);
46+
if (Executed != null)
47+
Executed(this, null);
48+
}
49+
50+
#endregion
51+
}
52+
}

D2RSO/Controls/OptionsDialog.xaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@
2222
<RowDefinition Height="Auto"/>
2323
<RowDefinition Height="Auto"/>
2424
<RowDefinition Height="Auto"/>
25+
<RowDefinition Height="Auto"/>
2526
</Grid.RowDefinitions>
2627
<CheckBox Content="Insert tracker icons on the left" IsChecked="{Binding Source={x:Static d2Rso:App.Settings}, Path=IsTrackerInsertToLeft}" Grid.Row="0" Margin="5" ToolTip="Insert new icons from the left edge instead of adding to the right"/>
2728
<CheckBox Content="Vertical tracker" IsChecked="{Binding Source={x:Static d2Rso:App.Settings}, Path=IsTrackerVertical}" Grid.Row="1" Margin="5" ToolTip="Position icons vertically instead of horizontally"/>
2829
<CheckBox Content="Show digits in tracker" IsChecked="{Binding Source={x:Static d2Rso:App.Settings}, Path=ShowDigitsInTracker}" Grid.Row="2" Margin="5" ToolTip="Show or hide timer digits beside the icon"/>
2930
<CheckBox Content="Start tracking on app launch" IsChecked="{Binding Source={x:Static d2Rso:App.Settings}, Path=StartTrackerOnAppRun}" Grid.Row="3" Margin="5" ToolTip="Show or hide timer digits beside the icon"/>
3031

31-
<StackPanel Orientation="Horizontal" Grid.Row="4">
32+
<StackPanel Orientation="Horizontal" Grid.Row="4">
33+
<Label HorizontalAlignment="Center" Content="Tracker Size"/>
34+
<Slider Minimum="5" Maximum="19" Value="10" Interval="1" Margin="3" ValueChanged="Scaler_OnValueChanged" Width="130" x:Name="TrackerSlider"/>
35+
</StackPanel>
36+
37+
<StackPanel Orientation="Horizontal" Grid.Row="5">
3238
<Label Content="Enable reddish icon (sec)" VerticalAlignment="Center" ToolTip="Icon becomes red when specified number of seconds left on the timer"/>
3339
<TextBox Text="{Binding Source={x:Static d2Rso:App.Settings}, Path=RedTrackerOverlaySec, Mode=TwoWay}" Width="50" Margin="5"/>
3440
</StackPanel>

D2RSO/Controls/OptionsDialog.xaml.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Windows;
22
using System.Windows.Controls;
3-
using MahApps.Metro.Controls;
4-
using MahApps.Metro.Controls.Dialogs;
53

64
namespace D2RSO.Controls
75
{
@@ -13,6 +11,14 @@ public partial class OptionsDialog : UserControl
1311
public OptionsDialog()
1412
{
1513
InitializeComponent();
14+
15+
TrackerSlider.Value = App.Settings.FormScaleX * 10;
16+
}
17+
18+
private void Scaler_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
19+
{
20+
App.Settings.FormScaleX = e.NewValue / 10;
21+
App.Settings.FormScaleY = e.NewValue / 10;
1622
}
1723
}
1824
}

D2RSO/MainWindow.xaml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
mc:Ignorable="d"
1010
d:DataContext="{d:DesignInstance local:MainWindow}"
1111
WindowStartupLocation="CenterScreen"
12-
ResizeMode="NoResize"
12+
ResizeMode="CanResize"
1313
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
14-
Title="D2R Skill Overlay" Height="450" Width="440">
14+
Title="D2R Skill Overlay" Height="450" Width="450" MinWidth="450" MinHeight="400">
1515
<mah:MetroWindow.RightWindowCommands>
1616
<mah:WindowCommands>
1717
<Button Content="Get help" Click="SupportButton_OnClick"/>
@@ -35,6 +35,8 @@
3535

3636
<Grid>
3737
<Grid.RowDefinitions>
38+
<RowDefinition Height="Auto"/>
39+
<RowDefinition Height="Auto"/>
3840
<RowDefinition Height="Auto"/>
3941
<RowDefinition Height="*"/>
4042
<RowDefinition Height="Auto"/>
@@ -50,12 +52,12 @@
5052

5153

5254
<StackPanel Orientation="Horizontal">
53-
<Button Margin="5" Height="35" Width="35" Background="{StaticResource MahApps.Brushes.Window.Background}"
54-
Padding="3" Click="AddSkillButton_OnClick" IsEnabled="{Binding IsNotPlaying, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
55-
ToolTip="Add new skill">
55+
<!--<Button Margin="5" Height="35" Width="35" Background="{StaticResource MahApps.Brushes.Window.Background}"
56+
Padding="3" IsEnabled="{Binding IsNotPlaying, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
57+
ToolTip="Add new skill" Command="{Binding AddSkillCommand}">
5658
<Path Data="M19,6H22V8H19V11H17V8H14V6H17V3H19V6M17,17V14H19V19H3V6H11V8H5V17H17Z" Fill="{StaticResource MahApps.Brushes.IdealForeground}"
5759
Stretch="Uniform"/>
58-
</Button>
60+
</Button>-->
5961
<Button Margin="5" Height="35" Width="35" Background="{StaticResource MahApps.Brushes.Window.Background}"
6062
Padding="3" Click="EyeButton_OnClick" IsEnabled="{Binding IsNotPlaying, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
6163
ToolTip="Show/Hide overlay preview">
@@ -95,10 +97,10 @@
9597
</Path.Style>
9698
</Path>
9799
</Button>
98-
<StackPanel Orientation="Vertical">
100+
<!--<StackPanel Orientation="Vertical">
99101
<Label HorizontalAlignment="Center" Content="Tracker Size"/>
100102
<Slider Minimum="5" Maximum="19" Value="10" Interval="1" Margin="3" ValueChanged="Scaler_OnValueChanged" Width="130" x:Name="TrackerSlider"/>
101-
</StackPanel>
103+
</StackPanel>-->
102104
</StackPanel>
103105

104106
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
@@ -117,8 +119,31 @@
117119
</Button>
118120
</StackPanel>
119121

120-
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
121-
<ItemsControl Margin="5" ItemsSource="{Binding Source={x:Static local:App.Settings}, Path=SkillItems , UpdateSourceTrigger=PropertyChanged, Mode=TwoWay }" Background="Transparent"
122+
<DockPanel Grid.Row="1" IsEnabled="{Binding IsNotPlaying, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}">
123+
<Label HorizontalAlignment="Center" Content="Profile" DockPanel.Dock="Left"/>
124+
<Button Margin="3" Height="25" Width="25" Background="{StaticResource MahApps.Brushes.Window.Background}"
125+
Padding="3" ToolTip="Remove profile" Command="{Binding RemoveProfileCommand}" DockPanel.Dock="Right">
126+
<Path Data="M14.12,10.47L12,12.59L9.87,10.47L8.46,11.88L10.59,14L8.47,16.12L9.88,17.53L12,15.41L14.12,17.53L15.53,16.12L13.41,14L15.53,11.88L14.12,10.47M15.5,4L14.5,3H9.5L8.5,4H5V6H19V4H15.5M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19M8,9H16V19H8V9Z" Fill="{StaticResource MahApps.Brushes.IdealForeground}"
127+
Stretch="Uniform"/>
128+
</Button>
129+
130+
<Button Margin="3" Height="25" Width="25" Background="{StaticResource MahApps.Brushes.Window.Background}"
131+
Padding="3" ToolTip="Add new profile" Command="{Binding AddProfileCommand}" DockPanel.Dock="Right">
132+
<Path Data="M12 12H14V10H16V12H18V14H16V16H14V14H12V12M22 8V18C22 19.11 21.11 20 20 20H4C2.89 20 2 19.11 2 18V6C2 4.89 2.89 4 4 4H10L12 6H20C21.11 6 22 6.89 22 8M20 8H4V18H20V8Z" Fill="{StaticResource MahApps.Brushes.IdealForeground}"
133+
Stretch="Uniform"/>
134+
</Button>
135+
<ComboBox Margin="3" DisplayMemberPath="Name" SelectedValuePath="Id" IsEditable="False"
136+
SelectedItem="{Binding Profile, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
137+
ItemsSource="{Binding Source={x:Static local:App.Settings}, Path=Profiles , UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
138+
</DockPanel>
139+
140+
<Button Content="Add new Skill" Grid.Row="2" Width="150" Height="25"
141+
Margin="3" Background="{StaticResource MahApps.Brushes.Window.Background}"
142+
Padding="3" IsEnabled="{Binding IsNotPlaying, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
143+
ToolTip="Add new skill" Command="{Binding AddSkillCommand}"></Button>
144+
145+
<ScrollViewer Grid.Row="3" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
146+
<ItemsControl Margin="5" ItemsSource="{Binding SelectedSkillItems, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay }" Background="Transparent"
122147
IsEnabled="{Binding IsNotPlaying, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}">
123148
<ItemsControl.ItemTemplate>
124149
<DataTemplate>
@@ -158,7 +183,7 @@
158183
<RowDefinition Height="Auto"/>
159184
</Grid.RowDefinitions>
160185
<Label Content="Select Key" Margin="5"/>
161-
<ComboBox Grid.Row="1" SelectedItem="{Binding SelectKey, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ItemsSource="{Binding Source={x:Static local:App.Data}, Path=AvailableKeys}" />
186+
<ComboBox Grid.Row="1" SelectedItem="{Binding SelectKey, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ItemsSource="{Binding Source={x:Static local:App.Data}, Path=AvailableKeys}" DisplayMemberPath="Name" SelectedValuePath="Code" />
162187
</Grid>
163188
<Grid>
164189
<Grid.RowDefinitions>
@@ -194,7 +219,7 @@
194219
</ItemsControl>
195220
</ScrollViewer>
196221

197-
<Border Grid.Row="2" BorderBrush="{StaticResource MahApps.Brushes.AccentBase}" BorderThickness="0,1,0,0">
222+
<Border Grid.Row="4" BorderBrush="{StaticResource MahApps.Brushes.AccentBase}" BorderThickness="0,1,0,0">
198223
<StackPanel Orientation="Vertical">
199224
<TextBlock HorizontalAlignment="Center" Padding="0">Open-source project by <Hyperlink NavigateUri="https://github.com/panthernet" Click="Hyperlink_OnClick">panthernet software</Hyperlink></TextBlock>
200225
<Label Padding="1,0,1,1" HorizontalAlignment="Center" Content="Diablo II: Resurrected is a registred trademark of © BLIZZARD ENTERTAINMENT, INC." FontSize="8"/>

0 commit comments

Comments
 (0)