Skip to content

Commit

Permalink
Training plan notifier (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jebzou authored Nov 16, 2023
1 parent fcbe4a1 commit e3a01ba
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 22 deletions.
4 changes: 4 additions & 0 deletions ElectronicObserver/Notifier/NotifierManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class NotifierManager
public NotifierBaseAirCorps BaseAirCorps { get; private set; }
public NotifierBattleEnd BattleEnd { get; private set; }
public NotifierRemodelLevel RemodelLevel { get; private set; }
public NotifierBase TrainingPlan { get; private set; }

private NotifierManager()
{
Expand All @@ -50,6 +51,7 @@ public void Initialize(object parent)
BaseAirCorps = new NotifierBaseAirCorps(c.NotifierBaseAirCorps);
BattleEnd = new NotifierBattleEnd(c.NotifierBattleEnd);
RemodelLevel = new NotifierRemodelLevel(c.NotifierRemodelLevel);
TrainingPlan = new NotifierTrainingPlan(c.NotifierTrainingPlan);
}

public void ApplyToConfiguration()
Expand All @@ -66,6 +68,7 @@ public void ApplyToConfiguration()
BaseAirCorps.ApplyToConfiguration(c.NotifierBaseAirCorps);
BattleEnd.ApplyToConfiguration(c.NotifierBattleEnd);
RemodelLevel.ApplyToConfiguration(c.NotifierRemodelLevel);
TrainingPlan.ApplyToConfiguration(c.NotifierTrainingPlan);
}

public void ShowNotifier(ElectronicObserver.Window.Dialog.DialogNotifier form)
Expand Down Expand Up @@ -102,6 +105,7 @@ public IEnumerable<NotifierBase> GetNotifiers()
yield return BaseAirCorps;
yield return BattleEnd;
yield return RemodelLevel;
yield return TrainingPlan;
}

}
31 changes: 31 additions & 0 deletions ElectronicObserver/Notifier/NotifierTrainingPlan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using ElectronicObserver.Window.Wpf.ShipTrainingPlanner;

namespace ElectronicObserver.Notifier;

public class NotifierTrainingPlan : NotifierBase
{
private ShipTrainingPlanViewerViewModel PlanManager { get; }

public NotifierTrainingPlan(Utility.Configuration.ConfigurationData.ConfigNotifierBase config)
: base(config)
{
PlanManager = Ioc.Default.GetRequiredService<ShipTrainingPlanViewerViewModel>();

DialogData.Title = PlanManager.ShipTrainingPlanner.PlanCompleted;

Initialize();
}

private void Initialize()
{
PlanManager.OnPlanCompleted += Notify;
}

private void Notify(ShipTrainingPlanViewModel plan)
{
DialogData.Message = string.Format(PlanManager.ShipTrainingPlanner.PlanCompletedNotification, plan.Ship.MasterShip.NameEN);

base.Notify();
}
}
4 changes: 4 additions & 0 deletions ElectronicObserver/Utility/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,9 +1813,12 @@ public ConfigNotifierBattleEnd()

[DataMember]
public ConfigNotifierBattleEnd NotifierBattleEnd { get; private set; }

[DataMember]
public ConfigNotifierBase NotifierRemodelLevel { get; private set; }

[DataMember]
public ConfigNotifierBase NotifierTrainingPlan { get; private set; }

/// <summary>
/// SyncBGMPlayer の設定を扱います。
Expand Down Expand Up @@ -1971,6 +1974,7 @@ public override void Initialize()
NotifierBaseAirCorps = new ConfigNotifierBaseAirCorps();
NotifierBattleEnd = new ConfigNotifierBattleEnd();
NotifierRemodelLevel = new ConfigNotifierBase();
NotifierTrainingPlan = new ConfigNotifierBase();

BGMPlayer = new ConfigBGMPlayer();
FleetImageGenerator = new ConfigFleetImageGenerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class FormMainTranslationViewModel : TranslationBaseViewModel
public string StripMenu_View_Log => MainResources.View_Log.Replace("_", "__").Replace("&", "_");
public string StripMenu_View_Json => MainResources.View_Json.Replace("_", "__").Replace("&", "_");
public string StripMenu_View_FleetPreset => MainResources.View_FleetPreset.Replace("_", "__").Replace("&", "_");
public string StripMenu_View_ShipTrainingPlanViewer => ShipTrainingPlannerResources.ViewerTitle;
public string StripMenu_View_ShipTrainingPlanViewer => ShipTrainingPlannerResources.Title;

public string StripMenu_WindowCapture => MainResources.WindowCapture.Replace("_", "__").Replace("&", "_");
public string StripMenu_WindowCapture_SubWindow => MainResources.WindowCapture_SubWindow.Replace("_", "__").Replace("&", "_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
x:Class="ElectronicObserver.Window.Settings.Notification.ConfigurationNotificationUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:ElectronicObserver.Window.Settings.Notification.Base"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ElectronicObserver.Window.Settings.Notification"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:base="clr-namespace:ElectronicObserver.Window.Settings.Notification.Base"
d:DataContext="{d:DesignInstance local:ConfigurationNotificationViewModel}"
d:DesignHeight="450"
d:DesignWidth="800"
Expand Down Expand Up @@ -80,5 +80,12 @@
CommandParameter="{Binding RemodelLevel}"
Content="{Binding Translation.Notification_RemodelLevel}"
/>

<Button
Margin="2"
Command="{Binding OpenNotificationConfigDialogCommand}"
CommandParameter="{Binding Training}"
Content="{Binding Translation.Notification_RemodelLevel}"
/>
</WrapPanel>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public partial class ConfigurationNotificationViewModel : ConfigurationViewModel
public ConfigurationNotificationBaseAirCorpsViewModel BaseAirCorps { get; }
public ConfigurationNotificationBattleEndViewModel BattleEnd { get; }
public ConfigurationNotificationBaseViewModel RemodelLevel { get; }
public ConfigurationNotificationBaseViewModel Training { get; }

public ConfigurationNotificationViewModel(Configuration.ConfigurationData config)
{
Expand All @@ -42,6 +43,7 @@ public ConfigurationNotificationViewModel(Configuration.ConfigurationData config
BaseAirCorps = new(Config.NotifierBaseAirCorps, NotifierManager.Instance.BaseAirCorps);
BattleEnd = new(Config.NotifierBattleEnd, NotifierManager.Instance.BattleEnd);
RemodelLevel = new(Config.NotifierRemodelLevel, NotifierManager.Instance.RemodelLevel);
Training = new(Config.NotifierTrainingPlan, NotifierManager.Instance.TrainingPlan);
}

public override void Save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:local="clr-namespace:ElectronicObserver.Window.Wpf.ShipTrainingPlanner"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
Title="{Binding ShipTrainingPlanner.ViewTitle}"
Title="{Binding ShipTrainingPlanner.Title}"
Width="800"
Height="450"
d:DataContext="{d:DesignInstance local:ShipTrainingPlanViewModel}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
using ElectronicObserverTypes.Mocks;

namespace ElectronicObserver.Window.Wpf.ShipTrainingPlanner;
public partial class ShipTrainingPlanViewModel : WindowViewModelBase

public class ShipTrainingPlanViewModel : WindowViewModelBase
{
public ShipTrainingPlanModel Model { get; }

public IShipData Ship => KCDatabase.Instance.Ships[Model.ShipId] switch
{
IShipData => KCDatabase.Instance.Ships[Model.ShipId],
not null => KCDatabase.Instance.Ships[Model.ShipId],
_ => new ShipDataMock(new ShipDataMasterMock())
};

Expand All @@ -26,9 +27,9 @@ public partial class ShipTrainingPlanViewModel : WindowViewModelBase
public ShipTrainingPlannerTranslationViewModel ShipTrainingPlanner { get; }

public bool ShipRemodelLevelReached =>
TargetRemodel?.Ship is IShipDataMaster remodel
TargetRemodel?.Ship is { } remodel
&& Ship.MasterShip.ShipId != remodel.ShipId
&& remodel.RemodelBeforeShip is IShipDataMaster shipBefore
&& remodel.RemodelBeforeShip is { } shipBefore
&& Ship.Level >= shipBefore.RemodelAfterLevel;

public bool ShipAnyRemodelLevelReached => Ship.Level >= Ship.MasterShip.RemodelAfterLevel && Ship.MasterShip.RemodelAfterLevel > 0;
Expand Down Expand Up @@ -119,9 +120,10 @@ private void UpdatePlanFinished()
&& Ship.HPMax >= TargetHP
&& Ship.ASWBase >= TargetASW
&& Ship.LuckBase >= TargetLuck
&& (Ship.MasterShip.ShipId == TargetRemodel?.Ship.ShipId);
}
&& (TargetRemodel is null || Ship.MasterShip.ShipId == TargetRemodel?.Ship.ShipId);

OnPropertyChanged(nameof(PlanFinished));
}

public void UpdateFromModel()
{
Expand All @@ -134,7 +136,7 @@ public void UpdateFromModel()

NotifyOnAnyRemodelReady = Model.NotifyOnAnyRemodelReady;

if (Model.TargetRemodel is ShipId shipId)
if (Model.TargetRemodel is { } shipId)
TargetRemodel = new(KCDatabase.Instance.MasterShips[(int)shipId]);

PossibleRemodels.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using ElectronicObserver.Common.Datagrid;
using ElectronicObserver.Data;
Expand Down Expand Up @@ -35,18 +34,21 @@ public partial class ShipTrainingPlanViewerViewModel : AnchorableViewModel

private Tracker Tracker { get; }

public ShipTrainingPlanViewerViewModel() : base("ShipTrainingPlanViewer", "ShipTrainingPlanViewer", IconContent.ItemActionReport)
public delegate void OnPlanCompletedArgs(ShipTrainingPlanViewModel plan);
public event OnPlanCompletedArgs? OnPlanCompleted;

public ShipTrainingPlanViewerViewModel(ShipTrainingPlannerTranslationViewModel translations, Tracker tracker) : base("ShipTrainingPlanViewer", "ShipTrainingPlanViewer", IconContent.ItemActionReport)
{
Tracker = Ioc.Default.GetService<Tracker>()!;
ShipTrainingPlanner = Ioc.Default.GetRequiredService<ShipTrainingPlannerTranslationViewModel>();
Tracker = tracker;
ShipTrainingPlanner = translations;

DataGridViewModel = new(Plans)
{
FilterValue = plan => DisplayFinished || !plan.PlanFinished
};

Title = ShipTrainingPlanner.ViewTitle;
ShipTrainingPlanner.PropertyChanged += (_, _) => Title = ShipTrainingPlanner.ViewTitle;
Title = ShipTrainingPlanner.Title;
ShipTrainingPlanner.PropertyChanged += (_, _) => Title = ShipTrainingPlanner.Title;
PropertyChanged += ShipTrainingPlanViewerViewModel_PropertyChanged;

SubscribeToApi();
Expand Down Expand Up @@ -98,7 +100,14 @@ private void Initialize(string apiname, dynamic data)

private void OnPlanViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(ShipTrainingPlanViewModel.PlanFinished)) UpdatePlanList();
if (e.PropertyName is not nameof(ShipTrainingPlanViewModel.PlanFinished)) return;

UpdatePlanList();

if (sender is ShipTrainingPlanViewModel { PlanFinished: true } plan)
{
OnPlanCompleted?.Invoke(plan);
}
}

private void UpdatePlanList() => DataGridViewModel.Items.Refresh();
Expand All @@ -121,7 +130,7 @@ private ShipTrainingPlanViewModel NewPlan(IShipData ship)
{
newPlan.TargetRemodel = lastRemodel.ShipId;

if (lastRemodel.RemodelBeforeShip is IShipDataMaster shipBefore)
if (lastRemodel.RemodelBeforeShip is { } shipBefore)
{
newPlan.TargetLevel = shipBefore.RemodelAfterLevel;
}
Expand All @@ -136,6 +145,7 @@ private ShipTrainingPlanViewModel NewPlan(IShipData ship)
private void RemovePlan(ShipTrainingPlanViewModel plan)
{
Plans.Remove(plan);
plan.PropertyChanged -= OnPlanViewModelPropertyChanged;
DatabaseContext.ShipTrainingPlans.Remove(plan.Model);
DatabaseContext.SaveChanges();
}
Expand Down Expand Up @@ -189,7 +199,7 @@ private void OpenShipPickerToAddNewPlan()

pickerView.ShowDialog();

if (PickerViewModel.PickedShip is IShipData ship)
if (PickerViewModel.PickedShip is { } ship)
{
AddNewPlan(ship);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<data name="RemovePlan" xml:space="preserve">
<value>Remove plan</value>
</data>
<data name="ViewerTitle" xml:space="preserve">
<data name="Title" xml:space="preserve">
<value>Ship Training</value>
</data>
<data name="NotifyAnyRemodelReadyToolTip" xml:space="preserve">
Expand Down Expand Up @@ -212,4 +212,10 @@ When enabled, you'll be notified when you can remodel Kamikaze to Kamikaze Kai a
<data name="LuckRemaining" xml:space="preserve">
<value>Luck (Remaining)</value>
</data>
<data name="PlanCompletedNotification" xml:space="preserve">
<value>{0}'s training has been completed</value>
</data>
<data name="PlanCompleted" xml:space="preserve">
<value>Ship training completed</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<data name="RemovePlan" xml:space="preserve">
<value>除去</value>
</data>
<data name="ViewerTitle" xml:space="preserve">
<data name="Title" xml:space="preserve">
<value>艦娘訓練</value>
</data>
<data name="NotifyAnyRemodelReadyToolTip" xml:space="preserve">
Expand Down Expand Up @@ -212,4 +212,10 @@
<data name="LuckRemaining" xml:space="preserve">
<value>運残</value>
</data>
<data name="PlanCompletedNotification" xml:space="preserve">
<value>{0}の艦娘訓練終了</value>
</data>
<data name="PlanCompleted" xml:space="preserve">
<value>艦娘訓練終了</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace ElectronicObserver.Window.Wpf.ShipTrainingPlanner;
public class ShipTrainingPlannerTranslationViewModel : TranslationBaseViewModel
{
public string ViewTitle => ShipTrainingPlannerResources.ViewerTitle;
public string Title => ShipTrainingPlannerResources.Title;
public string PlanCompletedNotification => ShipTrainingPlannerResources.PlanCompletedNotification;
public string PlanCompleted => ShipTrainingPlannerResources.PlanCompleted;
public string AddShip => ShipTrainingPlannerResources.AddShip;
public string RemovePlan => ShipTrainingPlannerResources.RemovePlan;
public string ShipName => EncycloRes.ShipName;
Expand Down

0 comments on commit e3a01ba

Please sign in to comment.