Skip to content

Commit

Permalink
Add dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
C1rdec committed Mar 24, 2020
1 parent 394997e commit 7ca77dd
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/Lurker.UI/ViewModels/BulbViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void OnClick()
{
if (this._action == null)
{
this.DefaultAction();
this.DefaultAction?.Invoke();
return;
}

Expand Down
112 changes: 77 additions & 35 deletions src/Lurker.UI/ViewModels/ManaBulbViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Lurker.UI.ViewModels
{
using Caliburn.Micro;
using Lurker.Helpers;
using Lurker.Services;
using Lurker.UI.Helpers;
using Lurker.UI.Models;
Expand All @@ -19,7 +18,6 @@ public class ManaBulbViewModel : BulbViewModel, IHandle<ManaBulbMessage>
#region Fields

private IEventAggregator _eventAggregator;
private SettingsViewModel _settingsViewModel;

#endregion

Expand All @@ -32,56 +30,37 @@ public class ManaBulbViewModel : BulbViewModel, IHandle<ManaBulbMessage>
/// <param name="dockingHelper">The docking helper.</param>
/// <param name="lurker"></param>
/// <param name="settingsService"></param>H
public ManaBulbViewModel(IEventAggregator eventAggregator, IWindowManager windowManager, DockingHelper dockingHelper, ClientLurker lurker, SettingsService settingsService, PoeKeyboardHelper keyboard, SettingsViewModel settingsViewModel)
public ManaBulbViewModel(IEventAggregator eventAggregator, IWindowManager windowManager, DockingHelper dockingHelper, ClientLurker lurker, SettingsService settingsService)
: base(windowManager, dockingHelper, lurker, settingsService)
{
this._settingsViewModel = settingsViewModel;
this._eventAggregator = eventAggregator;
this._eventAggregator.Subscribe(this);

lurker.LocationChanged += this.Lurker_LocationChanged;
lurker.RemainingMonsters += this.Lurker_RemainingMonsters;
this._lurker.LocationChanged += this.Lurker_LocationChanged;
this._lurker.RemainingMonsters += this.Lurker_RemainingMonsters;
this._settingsService.OnSave += this.SettingsService_OnSave;
}

/// <summary>
/// Lurkers the remaining monsters.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void Lurker_RemainingMonsters(object sender, Patreon.Events.MonstersRemainEvent e)
{
this.SetAction(new ManaBulbMessage() { View = new RemainingMonsterViewModel(e), DisplayTime = TimeSpan.FromSeconds(3)});
}
#endregion

#region Properties

/// <summary>
/// Lurkers the location changed.
/// Defaults the action.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void Lurker_LocationChanged(object sender, Patreon.Events.LocationChangedEvent e)
protected override System.Action DefaultAction
{
if (e.Location.EndsWith("Hideout"))
{
if (!this.HasAction)
{
var message = new ManaBulbMessage()
{
Action = this.DefaultAction
};
this.SetAction(message);
}
}
else
get
{
if (this.IsDefaultAction)
if (!this._settingsService.DashboardEnabled)
{
this.SetAction(new ManaBulbMessage());
return null;
}

return () => this._eventAggregator.PublishOnUIThread(IoC.Get<DashboardViewModel>());
}
}

protected override System.Action DefaultAction => () => this._eventAggregator.PublishOnUIThread(IoC.Get<DashboardViewModel>());

#endregion

#region Methods
Expand Down Expand Up @@ -112,6 +91,69 @@ protected override void SetWindowPosition(PoeWindowInformation windowInformation
});
}

/// <summary>
/// Called when deactivating.
/// </summary>
/// <param name="close">Inidicates whether this instance will be closed.</param>
protected override void OnDeactivate(bool close)
{
if (close)
{
this._lurker.LocationChanged -= this.Lurker_LocationChanged;
this._lurker.RemainingMonsters -= this.Lurker_RemainingMonsters;
this._settingsService.OnSave -= this.SettingsService_OnSave;
}

base.OnDeactivate(close);
}

/// <summary>
/// Handles the OnSave event of the SettingsService control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void SettingsService_OnSave(object sender, EventArgs e)
{
this.SetDefaultAction();
}

/// <summary>
/// Lurkers the remaining monsters.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void Lurker_RemainingMonsters(object sender, Patreon.Events.MonstersRemainEvent e)
{
this.SetAction(new ManaBulbMessage() { View = new RemainingMonsterViewModel(e), DisplayTime = TimeSpan.FromSeconds(3) });
}

/// <summary>
/// Lurkers the location changed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void Lurker_LocationChanged(object sender, Patreon.Events.LocationChangedEvent e)
{
if (e.Location.EndsWith("Hideout"))
{
if (!this.HasAction)
{
var message = new ManaBulbMessage()
{
Action = this.DefaultAction
};
this.SetAction(message);
}
}
else
{
if (this.IsDefaultAction)
{
this.SetAction(new ManaBulbMessage());
}
}
}

#endregion
}
}
2 changes: 1 addition & 1 deletion src/Lurker.UI/ViewModels/PoeOverlayBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public abstract class PoeOverlayBase : ScreenBase, IViewAware

protected Window _view;
protected SettingsService _settingsService;
protected ClientLurker _lurker;
private DockingHelper _dockingHelper;
private ClientLurker _lurker;

#endregion

Expand Down
19 changes: 19 additions & 0 deletions src/Lurker.UI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ public bool RemainingMonsterEnabled
}
}

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

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

/// <summary>
/// Gets or sets the sold message.
/// </summary>
Expand Down Expand Up @@ -412,6 +429,7 @@ public async void LoginToPatreon()
if (this.Pledging)
{
this.SearchEnabled = true;
this.DashboardEnabled = true;
}

this.NotifyOfPropertyChange("NotConnected");
Expand Down Expand Up @@ -476,6 +494,7 @@ protected async override void OnActivate()
if (!this.Pledging)
{
this.SearchEnabled = false;
this.DashboardEnabled = false;
}

this.AlertVolume = (int)(this._settingService.AlertVolume * 100);
Expand Down
8 changes: 5 additions & 3 deletions src/Lurker.UI/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@
</StackPanel>
<Grid Grid.Row="2" Height="70" Visibility="{Binding Pledging, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel Margin="30,0,0,0" Orientation="Horizontal">
<Controls:ToggleSwitch Grid.Row="1"
Header="Item Lurker"
IsChecked="{Binding SearchEnabled}"/>
<Controls:ToggleSwitch Header="Item Lurker"
IsChecked="{Binding SearchEnabled}"/>
<Controls:ToggleSwitch Margin="30,0,0,0"
Header="Dashboard"
IsChecked="{Binding DashboardEnabled}"/>
</StackPanel>
</Grid>
</Grid>
Expand Down
5 changes: 5 additions & 0 deletions src/Lurker/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public sealed class Settings: SettingsBase<Settings>
/// </summary>
public bool RemainingMonsterEnabled { get; set; }

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

/// <summary>
/// Gets or sets the tooltip delay.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/Lurker/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ public bool RemainingMonsterEnabled
}
}

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

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

/// <summary>
/// Gets or sets the alert volume.
/// </summary>
Expand Down

0 comments on commit 7ca77dd

Please sign in to comment.