Skip to content

Commit

Permalink
Add Trade Alert.
Browse files Browse the repository at this point in the history
  • Loading branch information
C1rdec committed Jan 16, 2020
1 parent 3915cfe commit 7e355a6
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 15 deletions.
Binary file added src/Lurker.UI/Assets/TradeAlert.mp3
Binary file not shown.
4 changes: 4 additions & 0 deletions src/Lurker.UI/Lurker.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\packages\NLog.4.6.8\lib\net45\NLog.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -265,6 +268,7 @@
<Resource Include="Assets\TrayIconUpdate.ico" />
<Resource Include="Assets\Alteration.png" />
<Resource Include="Assets\Jeweller.png" />
<EmbeddedResource Include="Assets\TradeAlert.mp3" />
<Content Include="Svg.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Svg.cs</LastGenOutput>
Expand Down
51 changes: 51 additions & 0 deletions src/Lurker.UI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SettingsViewModel: ScreenBase
private SettingsService _settingService;
private UpdateManager _updateManager;
private bool _needsUpdate;
private int _alertVolume;

#endregion

Expand All @@ -34,6 +35,8 @@ public SettingsViewModel(IWindowManager windowManager, KeyboardHelper keyboardHe
this._settingService = settingsService;
this._updateManager = updateManager;
this.DisplayName = "Settings";

this.PropertyChanged += this.SettingsViewModel_PropertyChanged;
}

#endregion
Expand Down Expand Up @@ -125,6 +128,40 @@ public string StillInterestedMessage
}
}

/// <summary>
/// Gets or sets a value indicating whether [alert enabled].
/// </summary>
public bool AlertEnabled
{
get
{
return this._settingService.AlertEnabled;
}

set
{
this._settingService.AlertEnabled = value;
this.NotifyOfPropertyChange();
}
}

/// <summary>
/// Gets or sets the alert volume.
/// </summary>
public int AlertVolume
{
get
{
return this._alertVolume;
}

set
{
this._alertVolume = value;
this.NotifyOfPropertyChange();
}
}

#endregion

#region Methods
Expand Down Expand Up @@ -180,6 +217,7 @@ protected override void OnDeactivate(bool close)
/// </summary>
protected override void OnActivate()
{
this.AlertVolume = (int)(this._settingService.AlertVolume * 100);
this.CheckForUpdate();
base.OnActivate();
}
Expand All @@ -192,6 +230,19 @@ private async void CheckForUpdate()
this.NeedsUpdate = await this._updateManager.CheckForUpdate();
}

/// <summary>
/// Handles the PropertyChanged event of the SettingsViewModel control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
private void SettingsViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(this.AlertVolume))
{
this._settingService.AlertVolume = (float)this.AlertVolume / 100;
}
}

#endregion
}
}
9 changes: 6 additions & 3 deletions src/Lurker.UI/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,12 @@ private void CurrentLurker_PoeClosed(object sender, System.EventArgs e)
this._container.UnregisterHandler<DockingHelper>();
this._container.UnregisterHandler<PoeKeyboardHelper>();

this._clipboardLurker.Newitem -= this.ClipboardLurker_Newitem;
this._clipboardLurker.Dispose();
this._clipboardLurker = null;
if (this._clipboardLurker != null)
{
this._clipboardLurker.Newitem -= this.ClipboardLurker_Newitem;
this._clipboardLurker.Dispose();
this._clipboardLurker = null;
}

this._currentLurker.PoeClosed -= this.CurrentLurker_PoeClosed;
this._currentLurker.Dispose();
Expand Down
30 changes: 30 additions & 0 deletions src/Lurker.UI/ViewModels/TradebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Lurker.UI.ViewModels
using Lurker.Services;
using Lurker.UI.Helpers;
using Lurker.UI.Models;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -236,12 +237,41 @@ private void Lurker_PoeClosed(object sender, EventArgs e)
/// <param name="e">The trade event.</param>
private void Lurker_NewOffer(object sender, Events.TradeEvent e)
{
if (this._settingsService.AlertEnabled)
{
this.PlayAlert();
}

Execute.OnUIThread(() =>
{
this.TradeOffers.Add(new OfferViewModel(e, this._keyboardHelper, this._context, this._settingsService));
});
}

/// <summary>
/// Plays the alert.
/// </summary>
private void PlayAlert()
{
var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Lurker.UI.Assets.TradeAlert.mp3");
var waveOut = new WaveOutEvent();
var mp3Reader = new Mp3FileReader(stream);
waveOut.Init(mp3Reader);
waveOut.Volume = this._settingsService.AlertVolume;
waveOut.Play();

EventHandler<StoppedEventArgs> handler = default;
handler = (object s, StoppedEventArgs e) =>
{
stream.Dispose();
mp3Reader.Dispose();
waveOut.Dispose();
waveOut.PlaybackStopped -= handler;
};

waveOut.PlaybackStopped += handler;
}

/// <summary>
/// Lurkers the trade accepted.
/// </summary>
Expand Down
53 changes: 41 additions & 12 deletions src/Lurker.UI/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@
<Grid.Resources>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
</Grid.Resources>

<Controls:MetroAnimatedTabControl Controls:TabControlHelper.IsUnderlined="True" Controls:TabControlHelper.Underlined="TabPanel" TabStripPlacement="Left">
<TabItem Header="General">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Content="General" Style="{DynamicResource LabelHeaderStyle}" />
<Label Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20">Coming Soon</Label>
</Grid>
</TabItem>
<TabItem Header="Message">
<StackPanel>
<Label Content="Message" Style="{DynamicResource LabelHeaderStyle}" />
Expand Down Expand Up @@ -109,6 +99,45 @@
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="Notification">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Content="Notification" Style="{DynamicResource LabelHeaderStyle}" />
<Grid Grid.Row="1" VerticalAlignment="Top" Margin="30,0,30,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Controls:ToggleSwitch Grid.Row="1"
Margin="0,30,0,0"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Header="Incoming trade"
IsChecked="{Binding AlertEnabled}"/>
<Label Grid.Column="1" Visibility="{Binding AlertEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Center" Margin="0,-40,0,0" >Volume</Label>
<Slider Height="150"
Grid.Column="1"
Visibility="{Binding AlertEnabled, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="4"
Controls:SliderHelper.ChangeValueBy="SmallChange"
Controls:SliderHelper.EnableMouseWheel="MouseHover"
AutoToolTipPlacement="TopLeft"
LargeChange="10"
Maximum="100"
Minimum="0"
Orientation="Horizontal"
SmallChange="1"
Value="{Binding AlertVolume}" />

</Grid>



</Grid>
</TabItem>
<TabItem Header="Action">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -122,7 +151,7 @@
</Controls:MetroAnimatedTabControl>
<Button x:Name="Update"
Visibility="{Binding NeedsUpdate, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="20,8,8,8"
Margin="36,8,8,8"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Height="10"
Expand Down
1 change: 1 addition & 0 deletions src/Lurker.UI/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<package id="InputSimulator" version="1.0.4.0" targetFramework="net472" />
<package id="MahApps.Metro" version="1.6.5" targetFramework="net472" />
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net472" />
<package id="NAudio" version="1.9.0" targetFramework="net472" />
<package id="NLog" version="4.6.8" targetFramework="net472" />
<package id="SharpCompress" version="0.17.1" targetFramework="net472" />
<package id="Splat" version="1.6.2" targetFramework="net472" />
Expand Down
10 changes: 10 additions & 0 deletions src/Lurker/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public sealed class Settings: SettingsBase<Settings>
/// </summary>
public bool SearchEnabled { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [alert enabled].
/// </summary>
public bool AlertEnabled { get; set; }

/// <summary>
/// Gets or sets the alert volume.
/// </summary>
public float AlertVolume { get; set; }

#endregion
}
}
34 changes: 34 additions & 0 deletions src/Lurker/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SettingsService
private static readonly string DefaultSoldMessage = $"I'm sorry, my {TokenHelper.ItemName} has already been sold.";
private static readonly string DefaultBusyMessage = "I'm busy right now I'll send you a party invite.";
private static readonly string DefaultThankYouMessage = string.Empty;
private static readonly float DefaultAlertVolume = 1;

private Settings _settings;

Expand Down Expand Up @@ -49,6 +50,7 @@ public SettingsService()
this.SoldMessage = DefaultSoldMessage;
this.StillInterestedMessage = DefaultStillInterestedMessage;
this.ThankYouMessage = DefaultThankYouMessage;
this.AlertVolume = DefaultAlertVolume;
this.Save();
}
else
Expand Down Expand Up @@ -182,6 +184,38 @@ public bool SearchEnabled
}
}

/// <summary>
/// Gets or sets a value indicating whether [alert enabled].
/// </summary>
public bool AlertEnabled
{
get
{
return this._settings.AlertEnabled;
}

set
{
this._settings.AlertEnabled = value;
}
}

/// <summary>
/// Gets or sets the alert volume.
/// </summary>
public float AlertVolume
{
get
{
return this._settings.AlertVolume;
}

set
{
this._settings.AlertVolume = value;
}
}

#endregion

#region Methods
Expand Down

0 comments on commit 7e355a6

Please sign in to comment.