Esempio n. 1
0
        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;
                }
            });
        }
        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());

            AirBase = new AirBaseViewModel();

            SessionService.Instance.SubscribeOnce("api_get_member/base_air_corps", delegate
            {
                DispatcherUtil.UIDispatcher.BeginInvoke(new Action(() =>
                {
                    if (RightTabs == null)
                    {
                        RightTabs = new ObservableCollection <ModelBase>();
                        OnPropertyChanged(nameof(RightTabs));
                    }

                    RightTabs.Add(AirBase);
                }));
            });

            SessionService.Instance.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>());
        }