예제 #1
0
        public void Initialize()
        {
            if (!OS.IsWin8OrLater)
            {
                InitializeNotifyIcon();
            }
            else
            {
                try
                {
                    InstallShortcut();
                }
                catch
                {
                    r_IsToastNotificationUnavailable = true;
                    InitializeNotifyIcon();
                }
            }

            var rGamePCEL = PropertyChangedEventListener.FromSource(KanColleGame.Current);

            rGamePCEL.Add(nameof(KanColleGame.Current.IsStarted), delegate
            {
                var rPort = KanColleGame.Current.Port;
                rPort.Fleets.FleetsUpdated += rpFleets =>
                {
                    foreach (var rFleet in rpFleets)
                    {
                        rFleet.ExpeditionStatus.Returned += (rpFleetName, rpExpeditionName) =>
                        {
                            if (Preference.Instance.Notification.Expedition)
                            {
                                Show(StringResources.Instance.Main.Notification_Expedition, string.Format(StringResources.Instance.Main.Notification_Expedition_Content, rpFleetName, rpExpeditionName));
                            }
                        };
                        rFleet.ConditionRegeneration.Recovered += rpFleet =>
                        {
                            if (Preference.Instance.Notification.RecoveryFromFatigue)
                            {
                                Show(StringResources.Instance.Main.Notification_RecoveryFromFatigue, string.Format(StringResources.Instance.Main.Notification_RecoveryFromFatigue_Content, rpFleet.Name));
                            }
                        };
                        rFleet.AnchorageRepair.InterruptionNotification += () =>
                        {
                            if (Preference.Instance.Notification.AnchorageRepair)
                            {
                                Show(StringResources.Instance.Main.Notification_AnchorageRepair, StringResources.Instance.Main.Notification_AnchorageRepair_Content);
                            }
                        };
                    }
                };

                var rPortPCEL = PropertyChangedEventListener.FromSource(rPort);
                rPortPCEL.Add(nameof(rPort.ConstructionDocks), delegate
                {
                    foreach (var rConstructionDock in rPort.ConstructionDocks.Values)
                    {
                        rConstructionDock.ConstructionCompleted += rpShipName =>
                        {
                            if (Preference.Instance.Notification.Construction)
                            {
                                Show(StringResources.Instance.Main.Notification_Construction, string.Format(StringResources.Instance.Main.Notification_Construction_Content, rpShipName));
                            }
                        }
                    }
                    ;
                });
        public MaterialsViewModel()
        {
            var rPort = KanColleGame.Current.Port;

            PropertyChangedEventListener.FromSource(rPort).Add(nameof(rPort.Materials), (s, e) => OnPropertyChanged(nameof(Source)));
        }
        internal OverviewViewModel()
        {
            var rPort = KanColleGame.Current.Port;

            var rPortPCEL = PropertyChangedEventListener.FromSource(rPort);

            rPortPCEL.Add(nameof(rPort.Ships), (s, e) => ShipCount                     = rPort.Ships.Count);
            rPortPCEL.Add(nameof(rPort.Equipment), (s, e) => EquipmentCount            = rPort.Equipment.Count);
            rPortPCEL.Add(nameof(rPort.RepairDocks), (s, e) => RepairDocks             = rPort.RepairDocks.Values.Select(r => new RepairDockViewModel(r)).ToList());
            rPortPCEL.Add(nameof(rPort.ConstructionDocks), (s, e) => ConstructionDocks = rPort.ConstructionDocks.Values.Select(r => new ConstructionDockViewModel(r)).ToList());
            rPortPCEL.Add(nameof(rPort.Admiral), delegate
            {
                if (!r_IsAdmiralInitialized)
                {
                    var rAdmiral     = rPort.Admiral;
                    var rAdmiralPCEL = PropertyChangedEventListener.FromSource(rAdmiral);
                    rAdmiralPCEL.Add(nameof(rAdmiral.MaxShipCount), (s, e) => CheckShipCapacity());
                    rAdmiralPCEL.Add(nameof(rAdmiral.MaxEquipmentCount), (s, e) => CheckEquipmentCapacity());

                    r_IsAdmiralInitialized = true;
                }

                CheckCapacity();
            });

            AirBase = new AirBaseViewModel();

            r_AirBasePCEL = PropertyChangedEventListener.FromSource(rPort.AirBase);
            r_AirBasePCEL.Add(nameof(rPort.AirBase.AllGroups), delegate
            {
                if (rPort.AirBase.Table.Count == 0)
                {
                    return;
                }

                DispatcherUtil.UIDispatcher.InvokeAsync(() =>
                {
                    if (RightTabs == null)
                    {
                        RightTabs = new ObservableCollection <ModelBase>();
                        OnPropertyChanged(nameof(RightTabs));
                    }

                    RightTabs.Add(AirBase);
                });

                r_AirBasePCEL.Dispose();
                r_AirBasePCEL = null;
            });

            ApiService.Subscribe("api_req_map/next", delegate
            {
                var rSortie = SortieInfo.Current;
                if (rSortie != null)
                {
                    ShipCount = rPort.Ships.Count + rSortie.PendingShipCount;
                }
            });

            ShowShipOverviewWindowCommand      = new DelegatedCommand(() => WindowService.Instance.Show <ShipOverviewWindow>());
            ShowEquipmentOverviewWindowCommand = new DelegatedCommand(() => WindowService.Instance.Show <EquipmentOverviewWindow>());
        }