Skip to content

Commit

Permalink
增加 event 单独设置
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoctillion committed Feb 15, 2016
1 parent fde676f commit f157afc
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 60 deletions.
6 changes: 3 additions & 3 deletions NotifyEx/Models/HomeportSpaceProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public void Initialize()

foreach (var counter in this._counters)
{
counter.Subscribe(nameof(counter.Enabled), this.Update).AddTo(this);
counter.Subscribe(nameof(counter.WarningCount), this.Update).AddTo(this);
counter.Subscribe(nameof(counter.Remain), this.Update).AddTo(this);
counter.Subscribe(nameof(IWarningCounter.Enabled), this.Update).AddTo(this);
counter.Subscribe(nameof(IWarningCounter.WarningCount), this.Update).AddTo(this);
counter.Subscribe(nameof(IWarningCounter.Remain), this.Update).AddTo(this);
}
}

Expand Down
22 changes: 1 addition & 21 deletions NotifyEx/Models/NotifyHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,7 @@ public override int GetHashCode()
///// </summary>
///// <param name="kcapi">监视的API</param>
///// <param name="type">通知类型</param>
///// <param name="notifyProvider">return null => 不进行通知</param>
//public void Register(string kcapi, INotifyType type, Func<Session, string> notifyProvider)
//{
// var key = new NotifyTypeKey(kcapi, type);

// Func<Session, string> action;
// if (this._notifyProviders.TryGetValue(key, out action))
// {
// action += notifyProvider;
// this._notifyProviders[key] = action;
// }
// else
// {
// this._notifyProviders.Add(key, notifyProvider);

// KanColleClient.Current.Proxy.ApiSessionSource
// .Where(s => s.Request.PathAndQuery == kcapi)
// .Subscribe(s => this.Notify(s, key));
// }
//}

///// <param name="notifyProvider">return null or "" => 不进行通知</param>
public static void Register(string kcapi, INotifyType type, Func<Session, string> notifyProvider)
{
if (Current != null)
Expand Down
58 changes: 46 additions & 12 deletions NotifyEx/Models/ShipNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,27 @@ public bool Enabled
}
}

public uint WarningCount
public uint WarningCount =>
this.EnabledEvent && Util.IsInEvent
? this.EventWarningCount
: this.NormalWarningCount;

private uint _remain = uint.MaxValue;

public uint Remain
{
get { return this._remain; }
private set
{
if (this._remain != value)
{
this._remain = value;
this.RaisePropertyChanged();
}
}
}

public uint NormalWarningCount
{
get { return Settings.WarningShipCount; }
set
Expand All @@ -47,34 +67,48 @@ public uint WarningCount
Settings.WarningShipCount = value;
Settings.Save();
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
}
}

private uint _remain = uint.MaxValue;

public uint Remain
public bool EnabledEvent
{
get
get { return Settings.EnabledEventShipNotifier; }
set
{
return this._remain;
if (Settings.EnabledEventShipNotifier != value)
{
Settings.EnabledEventShipNotifier = value;
Settings.Save();
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
}
private set
}

public uint EventWarningCount
{
get { return Settings.EventWarningShipCount; }
set
{
if (this._remain != value)
if (Settings.EventWarningShipCount != value)
{
this._remain = value;
Settings.EventWarningShipCount = value;
Settings.Save();
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
}
}


private ShipNotifier()
{
NotifyHost.Register("/kcsapi/api_get_member/mapinfo", WarningType.Instance, s => CheckReminding());

KanColleClient.Current
.Subscribe(nameof(KanColleClient.Current.IsStarted), this.Initialize, false)
.Subscribe(nameof(KanColleClient.IsStarted), this.Initialize, false)
.AddTo(this);
}

Expand All @@ -90,10 +124,10 @@ private void Initialize()
this._initialized = true;

homeport.Organization
.Subscribe(nameof(homeport.Organization.Ships), this.UpdateRemainCount)
.Subscribe(nameof(Organization.Ships), this.UpdateRemainCount)
.AddTo(this);
homeport
.Subscribe(nameof(homeport.Admiral), this.UpdateRemainCount)
.Subscribe(nameof(Homeport.Admiral), this.UpdateRemainCount)
.AddTo(this);
}
}
Expand Down
58 changes: 46 additions & 12 deletions NotifyEx/Models/SlotNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleWrapper;
using Grabacr07.KanColleWrapper.Models;
using Livet;
using MetroTrilithon.Lifetime;
using MetroTrilithon.Mvvm;
Expand Down Expand Up @@ -34,7 +35,27 @@ public bool Enabled
}
}

public uint WarningCount
public uint WarningCount =>
this.EnabledEvent && Util.IsInEvent
? this.EventWarningCount
: Settings.WarningSlotCount;

private uint _remain = uint.MaxValue;

public uint Remain
{
get { return this._remain; }
private set
{
if (this._remain != value)
{
this._remain = value;
this.RaisePropertyChanged();
}
}
}

public uint NormalWarningCount
{
get { return Settings.WarningSlotCount; }
set
Expand All @@ -44,24 +65,37 @@ public uint WarningCount
Settings.WarningSlotCount = value;
Settings.Save();
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
}
}

private uint _remain = uint.MaxValue;

public uint Remain
public bool EnabledEvent
{
get
get { return Settings.EnabledEventSlotNotifier; }
set
{
return this._remain;
if (Settings.EnabledEventSlotNotifier != value)
{
Settings.EnabledEventSlotNotifier = value;
Settings.Save();
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
}
private set
}

public uint EventWarningCount
{
get { return Settings.EventWarningSlotCount; }
set
{
if (this._remain != value)
if (Settings.EventWarningSlotCount != value)
{
this._remain = value;
Settings.EventWarningSlotCount = value;
Settings.Save();
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
}
}
Expand All @@ -72,7 +106,7 @@ private SlotNotifier()
NotifyHost.Register("/kcsapi/api_get_member/mapinfo", WarningType.Instance, s => this.CheckReminding());

KanColleClient.Current
.Subscribe(nameof(KanColleClient.Current.IsStarted), this.Initialize, false)
.Subscribe(nameof(KanColleClient.IsStarted), this.Initialize, false)
.AddTo(this);
}

Expand All @@ -88,10 +122,10 @@ private void Initialize()
this._initialized = true;

homeport.Itemyard
.Subscribe(nameof(homeport.Itemyard.SlotItemsCount), this.UpdateRemainCount)
.Subscribe(nameof(Itemyard.SlotItemsCount), this.UpdateRemainCount)
.AddTo(this);
homeport.Admiral
.Subscribe(nameof(homeport.Admiral.MaxSlotItemCount), this.UpdateRemainCount)
.Subscribe(nameof(Admiral.MaxSlotItemCount), this.UpdateRemainCount)
.AddTo(this);
}
}
Expand Down
18 changes: 18 additions & 0 deletions NotifyEx/Models/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleWrapper;
using MetroTrilithon.Mvvm;

namespace NotifyEx.Models
{
public static class Util
{
public static bool IsInEvent
=> KanColleClient.Current.Master?.MapAreas.Values
.Any(area => area.RawData.api_type == 1)
?? false;
}
}
1 change: 1 addition & 0 deletions NotifyEx/NotifyEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<Compile Include="Models\SlotNotifier.cs" />
<Compile Include="Models\SupplyNotifier.cs" />
<Compile Include="Models\IWarningCounter.cs" />
<Compile Include="Models\Util.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="ViewModels\ToolViewModel.cs" />
<Compile Include="Views\ToolView.xaml.cs">
Expand Down
48 changes: 48 additions & 0 deletions NotifyEx/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions NotifyEx/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@
<Setting Name="EnabledSupplyNotifier" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="EnabledEventShipNotifier" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="EventWarningShipCount" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">5</Value>
</Setting>
<Setting Name="EnabledEventSlotNotifier" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="EventWarningSlotCount" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">20</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit f157afc

Please sign in to comment.