Skip to content

Commit

Permalink
增加基地航空队相关通知
Browse files Browse the repository at this point in the history
给每次出击都忘了补给的你
  • Loading branch information
Yoctillion committed Aug 19, 2016
1 parent e183fd0 commit 136d47a
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 2 deletions.
153 changes: 153 additions & 0 deletions NotifyEx/Models/LandBaseNotifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleWrapper.Models;
using Livet;
using NotifyEx.Models.NotifyType;
using NotifyEx.Models.Settings;

namespace NotifyEx.Models
{
public class LandBaseNotifier : NotificationObject
{
public static LandBaseNotifier Current { get; } = new LandBaseNotifier();

public bool Enabled
{
get { return NotifierSettings.EnabledLandBaseNotifier.Value; }
set
{
if (NotifierSettings.EnabledLandBaseNotifier.Value != value)
{
NotifierSettings.EnabledLandBaseNotifier.Value = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowNotificationBeforeSelectMap
{
get { return NotifierSettings.ShowLandBaseNotificationBeforeSelectMap.Value; }
set
{
if (NotifierSettings.ShowLandBaseNotificationBeforeSelectMap.Value != value)
{
NotifierSettings.ShowLandBaseNotificationBeforeSelectMap.Value = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowUncompletedAirCorps
{
get { return NotifierSettings.ShowUncompletedAirCorps.Value; }
set
{
if (NotifierSettings.ShowUncompletedAirCorps.Value != value)
{
NotifierSettings.ShowUncompletedAirCorps.Value = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowNotReadyAirCorps
{
get { return NotifierSettings.ShowNotReadyAirCorps.Value; }
set
{
if (NotifierSettings.ShowNotReadyAirCorps.Value != value)
{
NotifierSettings.ShowNotReadyAirCorps.Value = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowNeedSupplyAirCorps
{
get { return NotifierSettings.ShowNeedSupplyAirCorps.Value; }
set
{
if (NotifierSettings.ShowNeedSupplyAirCorps.Value != value)
{
NotifierSettings.ShowNeedSupplyAirCorps.Value = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowTiredAirCorps
{
get { return NotifierSettings.ShowTiredAirCorps.Value; }
set
{
if (NotifierSettings.ShowTiredAirCorps.Value != value)
{
NotifierSettings.ShowTiredAirCorps.Value = value;
this.RaisePropertyChanged();
}
}
}

private LandBaseNotifier()
{
NotifyHost.Register("/kcsapi/api_get_member/base_air_corps", LandBaseType.Instance, s =>
{
SvData<base_air_corps[]> svData;
SvData.TryParse(s, out svData);
this._data = svData?.Data;
return this.CheckSituation(true);
});
NotifyHost.Register("/kcsapi/api_get_member/sortie_conditions", LandBaseType.Instance, s => this.CheckSituation());
}

private base_air_corps[] _data;

private string CheckSituation(bool beforeSelectMap = false)
{
if (!this.Enabled) return "";

if (this._data == null) return "";

if (beforeSelectMap && !this.ShowNotificationBeforeSelectMap) return "";

var notificationContent = new List<string>();

if (this.ShowUncompletedAirCorps)
{
var uncompleted = this._data.Where(s => s.api_plane_info.Any(p => p.api_state == 0));
notificationContent.Add(this.FormatInfo(uncompleted, "有空位未配置"));
}

if (this.ShowNotReadyAirCorps)
{
var notReady = this._data.Where(s => s.api_action_kind != 1 && s.api_action_kind != 2);
notificationContent.Add(this.FormatInfo(notReady, "未在出击/防空状态"));
}

if (this.ShowNeedSupplyAirCorps)
{
var needSupply = this._data.Where(s => s.api_plane_info.Any(p => p.api_count < p.api_max_count));
notificationContent.Add(this.FormatInfo(needSupply, "需要补给"));
}

if (this.ShowTiredAirCorps)
{
var tired = this._data.Where(s => s.api_plane_info.Any(p => p.api_state > 1));
notificationContent.Add(this.FormatInfo(tired, "疲劳"));
}

return string.Join(Environment.NewLine, notificationContent);
}

private string FormatInfo(IEnumerable<base_air_corps> airCorps, string info)
{
return airCorps.Any()
? $"{string.Join(", ", airCorps.Select(s => s.api_name))} {info}"
: "";
}
}
}
17 changes: 17 additions & 0 deletions NotifyEx/Models/NotifyType/LandBaseType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NotifyEx.Models.NotifyType
{
public class LandBaseType : INotifyType
{
public static LandBaseType Instance { get; } = new LandBaseType();

public string Name => "基地航空队";

private LandBaseType() { }
}
}
22 changes: 22 additions & 0 deletions NotifyEx/Models/Settings/NotifierSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ public static class NotifierSettings

#endregion

#region Land base

public static SerializableProperty<bool> EnabledLandBaseNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, true) { AutoSave = true };

public static SerializableProperty<bool> ShowLandBaseNotificationBeforeSelectMap { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, false) { AutoSave = true };

public static SerializableProperty<bool> ShowUncompletedAirCorps { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, true) { AutoSave = true };

public static SerializableProperty<bool> ShowNotReadyAirCorps { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, true) { AutoSave = true };

public static SerializableProperty<bool> ShowNeedSupplyAirCorps { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, true) { AutoSave = true };

public static SerializableProperty<bool> ShowTiredAirCorps { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, true) { AutoSave = true };

#endregion

private static string GetKey([CallerMemberName] string propertyName = "")
{
return $"{nameof(NotifierSettings)}.{propertyName}";
Expand Down
27 changes: 27 additions & 0 deletions NotifyEx/Models/base_air_corps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NotifyEx.Models
{
public class base_air_corps
{
public int api_rid { get; set; }
public string api_name { get; set; }
public int api_distance { get; set; }
public int api_action_kind { get; set; }
public api_plane_info[] api_plane_info { get; set; }
}

public class api_plane_info
{
public int api_squadron_id { get; set; }
public int api_state { get; set; }
public int api_slotid { get; set; }
public int api_count { get; set; }
public int api_max_count { get; set; }
public int api_cond { get; set; }
}
}
3 changes: 3 additions & 0 deletions NotifyEx/NotifyEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="Models\LandBaseNotifier.cs" />
<Compile Include="Models\base_air_corps.cs" />
<Compile Include="Models\HomeportSpaceProcess.cs" />
<Compile Include="Models\HpNotifier.cs" />
<Compile Include="Models\NotifyHost.cs" />
<Compile Include="Models\NotifyType\INotifyType.cs" />
<Compile Include="Models\NotifyType\LandBaseType.cs" />
<Compile Include="Models\NotifyType\WarningType.cs" />
<Compile Include="Models\Settings\NotifierSettings.cs" />
<Compile Include="Models\Settings\Provider.cs" />
Expand Down
2 changes: 1 addition & 1 deletion NotifyEx/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace NotifyEx
[ExportMetadata("Guid", "3190E362-3833-4953-87C3-B2C22C058EE8")]
[ExportMetadata("Title", "NotifyEx")]
[ExportMetadata("Description", "通知内容扩展")]
[ExportMetadata("Version", "0.7.0")]
[ExportMetadata("Version", "0.8.0")]
[ExportMetadata("Author", "@Yoctillion")]
public class Plugin : IPlugin, ISettings, IRequestNotify
{
Expand Down
2 changes: 1 addition & 1 deletion NotifyEx/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.0")]
[assembly: AssemblyVersion("0.8.0")]
78 changes: 78 additions & 0 deletions NotifyEx/ViewModels/ToolViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ToolViewModel : ViewModel
private readonly SlotNotifier _slotNotifier = SlotNotifier.Current;
private readonly HpNotifier _hpNotifier = HpNotifier.Current;
private readonly SupplyNotifier _supplyNotifier = SupplyNotifier.Current;
private readonly LandBaseNotifier _landBaseNotifier = LandBaseNotifier.Current;

public bool EnabledShipNotifier
{
Expand Down Expand Up @@ -197,5 +198,82 @@ public bool EnabledExpenditionSupplyNotifier
}
}

public bool EnabledLandBaseNotifier
{
get { return this._landBaseNotifier.Enabled; }
set
{
if (this._landBaseNotifier.Enabled != value)
{
this._landBaseNotifier.Enabled = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowNotReadyAirCorps
{
get { return this._landBaseNotifier.ShowNotReadyAirCorps; }
set
{
if (this._landBaseNotifier.ShowNotReadyAirCorps != value)
{
this._landBaseNotifier.ShowNotReadyAirCorps = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowLandBaseNotificationBeforeSelectMap
{
get { return this._landBaseNotifier.ShowNotificationBeforeSelectMap; }
set
{
if (this._landBaseNotifier.ShowNotificationBeforeSelectMap != value)
{
this._landBaseNotifier.ShowNotificationBeforeSelectMap = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowUncompletedAirCorps
{
get { return this._landBaseNotifier.ShowUncompletedAirCorps; }
set
{
if (this._landBaseNotifier.ShowUncompletedAirCorps != value)
{
this._landBaseNotifier.ShowUncompletedAirCorps = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowNeedSupplyAirCorps
{
get { return this._landBaseNotifier.ShowNeedSupplyAirCorps; }
set
{
if (this._landBaseNotifier.ShowNeedSupplyAirCorps != value)
{
this._landBaseNotifier.ShowNeedSupplyAirCorps = value;
this.RaisePropertyChanged();
}
}
}

public bool ShowTiredAirCorps
{
get { return this._landBaseNotifier.ShowTiredAirCorps; }
set
{
if (this._landBaseNotifier.ShowTiredAirCorps != value)
{
this._landBaseNotifier.ShowTiredAirCorps = value;
this.RaisePropertyChanged();
}
}
}
}
}
Loading

0 comments on commit 136d47a

Please sign in to comment.