Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Yoctillion/NotifyEx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.3.0
Choose a base ref
...
head repository: Yoctillion/NotifyEx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 11 commits
  • 26 files changed
  • 1 contributor

Commits on Jan 18, 2016

  1. 增加补给通知

    Yoctillion committed Jan 18, 2016
    Copy the full SHA
    985f7ce View commit details

Commits on Feb 5, 2016

  1. ITool 改为 ISettings

    Yoctillion committed Feb 5, 2016
    Copy the full SHA
    fc6e377 View commit details
  2. Copy the full SHA
    42fff56 View commit details

Commits on Feb 8, 2016

  1. Copy the full SHA
    1bc8ece View commit details

Commits on Feb 9, 2016

  1. Copy the full SHA
    370d355 View commit details

Commits on Feb 13, 2016

  1. Copy the full SHA
    fde676f View commit details

Commits on Feb 15, 2016

  1. 增加 event 单独设置

    Yoctillion committed Feb 15, 2016
    Copy the full SHA
    f157afc View commit details
  2. Copy the full SHA
    29fcdd8 View commit details
  3. 出击前大破确认

    Yoctillion committed Feb 15, 2016
    Copy the full SHA
    e183fd0 View commit details

Commits on Aug 19, 2016

  1. 增加基地航空队相关通知

    给每次出击都忘了补给的你
    Yoctillion committed Aug 19, 2016
    Copy the full SHA
    136d47a View commit details

Commits on Aug 21, 2016

  1. 基地航空队通知改进

    改正基地航空队状态变更、补给等操作后的通知
    Yoctillion committed Aug 21, 2016
    Copy the full SHA
    b2c655a View commit details
96 changes: 96 additions & 0 deletions NotifyEx/Models/HomeportSpaceProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shell;
using Grabacr07.KanColleViewer.Composition;
using MetroTrilithon.Lifetime;
using MetroTrilithon.Mvvm;
using StatefulModel;

namespace NotifyEx.Models
{
[Export(typeof(IPlugin))]
[Export(typeof(ITaskbarProgress))]
[ExportMetadata("Guid", Guid)]
[ExportMetadata("Title", "HomeportSpaceProcessIndicator")]
[ExportMetadata("Description", "母港剩余空间(舰娘、装备)任务栏进度显示")]
[ExportMetadata("Version", "1.0")]
[ExportMetadata("Author", "@Yoctillion")]
public class HomeportSpaceProcess : IPlugin, ITaskbarProgress, IDisposableHolder
{
private const string Guid = "93B50362-76AA-4F2C-B6BE-8B1C7FEEA2A5";

private readonly MultipleDisposable _compositeDisposable = new MultipleDisposable();

public string Id { get; } = Guid + "-1";

public string DisplayName { get; } = "母港剩余空间";

public TaskbarItemProgressState State { get; private set; }

public double Value { get; private set; }

public event EventHandler Updated;


private readonly List<IWarningCounter> _counters = new List<IWarningCounter>();

public void Initialize()
{
this._counters.Add(ShipNotifier.Current);
this._counters.Add(SlotNotifier.Current);

foreach (var counter in this._counters)
{
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);
}
}

private void Update()
{
// min means most dangerous(?)
var minValue = this._counters.Min(c => GetValue(c));

if (minValue == 0)
{
this.State = TaskbarItemProgressState.Error;
}
else if (minValue < 1)
{
this.State = TaskbarItemProgressState.Paused;
}
else
{
this.State = TaskbarItemProgressState.Normal;
}

this.Value = Math.Max(0, 1 - minValue / 2);

this.Updated?.Invoke(this, EventArgs.Empty);
}

private static double GetValue(IWarningCounter counter)
{
if (!counter.Enabled) return double.MaxValue;

if (counter.WarningCount != 0)
{
return (double)counter.Remain / counter.WarningCount;
}

// WarningCount == 0 && Remain == 0
if (counter.Remain == 0) return 0;

return double.MaxValue;
}

public void Dispose() => this._compositeDisposable.Dispose();

public ICollection<IDisposable> CompositeDisposable => this._compositeDisposable;
}
}
131 changes: 64 additions & 67 deletions NotifyEx/Models/HpNotifier.cs
Original file line number Diff line number Diff line change
@@ -9,82 +9,79 @@
using NotifyEx.Properties;
using System.Reactive.Linq;
using Grabacr07.KanColleWrapper.Models;
using NotifyEx.Models.NotifyType;
using NotifyEx.Models.Settings;

namespace NotifyEx.Models
{
/// <summary>
/// 大破通知
/// </summary>
class HpNotifier : NotificationObject
{
private static readonly Settings Settings = Settings.Default;
/// <summary>
/// 大破通知
/// </summary>
internal class HpNotifier
{
public static HpNotifier Current = new HpNotifier();

private readonly Plugin _plugin;
public bool Enabled
{
get { return NotifierSettings.EnabledLowHpNotifier.Value; }
set
{
if (NotifierSettings.EnabledLowHpNotifier.Value != value)
{
NotifierSettings.EnabledLowHpNotifier.Value = value;
}
}
}

public bool Enabled
{
get { return Settings.EnabledLowHpNotifier; }
set
{
if (Settings.EnabledLowHpNotifier != value)
{
Settings.EnabledLowHpNotifier = value;
Settings.Save();
RaisePropertyChanged();
}
}
}
/// <summary>
/// 是否显示装备损管的舰娘
/// </summary>
public bool EnabledShowDamageControl
{
get { return NotifierSettings.EnabledShowDamageControl.Value; }
set
{
if (NotifierSettings.EnabledShowDamageControl.Value != value)
{
NotifierSettings.EnabledShowDamageControl.Value = value;
}
}
}

/// <summary>
/// 是否显示装备损管的舰娘
/// </summary>
public bool EnabledShowDamageControl
{
get { return Settings.EnabledShowDamageControl; }
set
{
if (Settings.EnabledShowDamageControl != value)
{
Settings.EnabledShowDamageControl = value;
Settings.Save();
RaisePropertyChanged();
}
}
}
private HpNotifier()
{
NotifyHost.Register("/kcsapi/api_get_member/mapinfo", WarningType.Instance, s => this.CheckSituation(false));
NotifyHost.Register("/kcsapi/api_req_map/start", WarningType.Instance, s => this.CheckSituation(true));
NotifyHost.Register("/kcsapi/api_req_map/next", WarningType.Instance, s => this.CheckSituation(true));
}

public HpNotifier(Plugin plugin)
{
_plugin = plugin;
private string CheckSituation(bool isInSortie)
{
if (!Enabled) return null;

var proxy = KanColleClient.Current.Proxy;
var fleets = KanColleClient.Current.Homeport.Organization.Fleets.Values
.Where(f => isInSortie ? f.IsInSortie : !f.Expedition.IsInExecution)
.Select(f => new
{
f.Name,
Ships = f.Ships.Where(this.FilterShip)
.Select(s => s.Info.Name + (s.Situation.HasFlag(ShipSituation.DamageControlled) ? "(损管)" : ""))
.ToArray()
})
.Where(f => f.Ships.Length > 0)
.ToArray();

proxy.api_req_map_start
.Subscribe(x => CheckSituation());
if (fleets.Length == 0) return null;

proxy.ApiSessionSource.Where(x => x.Request.PathAndQuery == "/kcsapi/api_req_map/next")
.Subscribe(x => CheckSituation());
}
return string.Join(", ", fleets.Select(f => $"{f.Name} {string.Join(" ", f.Ships)}")) + " 大破!";
}

private void CheckSituation()
{
if (!Enabled) return;

var fleets = KanColleClient.Current.Homeport.Organization.Fleets.Values.Where(fleet => fleet.IsInSortie);

var lowHpList = (from fleet in fleets
let ships = fleet.Ships
from ship in ships
where !(ship.Situation.HasFlag(ShipSituation.Tow) || ship.Situation.HasFlag(ShipSituation.Evacuation))
&& ship.Situation.HasFlag(ShipSituation.HeavilyDamaged)
&& (EnabledShowDamageControl || !ship.Situation.HasFlag(ShipSituation.DamageControlled))
group ship.Info.Name + (ship.Situation.HasFlag(ShipSituation.DamageControlled) ? "(损管)" : "") by fleet.Name
).ToArray();

if (lowHpList.Any())
{
var info = string.Join(", ", lowHpList.Select(fleet => $"{fleet.Key} {string.Join(" ", fleet)}")) + " 大破!";
_plugin.Notify("HpNotify", "大破警告", info);
}
}
}
private bool FilterShip(Ship ship)
{
var situation = ship.Situation;
return !(situation.HasFlag(ShipSituation.Tow) || situation.HasFlag(ShipSituation.Evacuation))
&& situation.HasFlag(ShipSituation.HeavilyDamaged)
&& (this.EnabledShowDamageControl || !situation.HasFlag(ShipSituation.DamageControlled));
}
}
}
17 changes: 17 additions & 0 deletions NotifyEx/Models/IWarningCounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Livet;

namespace NotifyEx.Models
{
public interface IWarningCounter : INotifyPropertyChanged
{
bool Enabled { get; }
uint WarningCount { get; }
uint Remain { get; }
}
}
Loading