public SkillCountUseCase()
        {
            _skillCountRepository = new SkillCountRepository(Application.Current.GetAppDb());
            _settingRepository    = new SettingRepository(Application.Current.GetAppDb());

            var setting = _settingRepository.GetSetting();

            MapName  = new ReactivePropertySlim <string>(string.Empty);
            WorkName = new ReactivePropertySlim <string>(string.Empty);
            CurrentSkillCollection = new ReactiveCollection <SkillCountDetailEntity>();
            SkillCountHistories    = new ReactiveCollection <SkillCountEntity>();
            SkillUseCollection     = new ReactiveCollection <SkillUseEntity>();
            WarStatus         = new ReactivePropertySlim <WarEvents>(WarEvents.Invalid);
            AverageFps        = new ReactivePropertySlim <double>(0d);
            AttackKeepDamage  = new ReactivePropertySlim <double>(0d);
            DefenceKeepDamage = new ReactivePropertySlim <double>(0d);
            IsBookUsing       = new ReactivePropertySlim <bool>(false);
            Pow                        = new ReactivePropertySlim <int>(0);
            Hp                         = new ReactivePropertySlim <int>(0);
            PowDebuffs                 = new ReactivePropertySlim <string>(string.Empty);
            IsSkillCountFileSave       = setting.ObserveProperty(x => x.IsSkillCountFileSave).ToReactiveProperty();
            IsNotifyBookUses           = setting.ObserveProperty(x => x.IsNotifyBookUses).ToReactiveProperty();
            IsNotifySpellUses          = setting.ObserveProperty(x => x.IsNotifySpellUses).ToReactiveProperty();
            IsNotifyEnchantUses        = setting.ObserveProperty(x => x.IsNotifyEnchantUses).ToReactiveProperty();
            EnchantSpellNotifyTimeSpan = setting.ObserveProperty(x => x.EnchantSpellNotifyTimeSpan).ToReactiveProperty();
            IsAllwaysOnTop             = setting.ObserveProperty(x => x.IsAllwaysOnTop).ToReactiveProperty();
            IsDebugModeEnabled         = setting.ObserveProperty(x => x.IsDebugModeEnabled).ToReactiveProperty();

            IsSkillCountFileSave.Subscribe(async x =>
            {
                setting.IsSkillCountFileSave = x;
                await _settingRepository.UpdateAsync();
            });
            IsNotifyBookUses.Subscribe(async x =>
            {
                if (_bookUseNotificator != null)
                {
                    _bookUseNotificator.IsEnabled = x;
                }

                setting.IsNotifyBookUses = x;
                await _settingRepository.UpdateAsync();
            });
            IsNotifySpellUses.Subscribe(async x =>
            {
                if (_enchantSpellUseNotificator != null)
                {
                    _enchantSpellUseNotificator.IsSpellNotifyEnabled = x;
                }

                setting.IsNotifySpellUses = x;
                await _settingRepository.UpdateAsync();
            });
            IsNotifyEnchantUses.Subscribe(async x =>
            {
                if (_enchantSpellUseNotificator != null)
                {
                    _enchantSpellUseNotificator.IsEnchantNotifyEnabled = x;
                }

                setting.IsNotifyEnchantUses = x;
                await _settingRepository.UpdateAsync();
            });
            EnchantSpellNotifyTimeSpan.Subscribe(async x =>
            {
                if (_enchantSpellUseNotificator != null)
                {
                    _enchantSpellUseNotificator.NotifyTimeSpan = x ?? TimeSpan.Zero;
                }

                setting.EnchantSpellNotifyTimeSpan = x;
                await _settingRepository.UpdateAsync();
            });
            IsAllwaysOnTop.Subscribe(async x =>
            {
                setting.IsAllwaysOnTop = x;
                await _settingRepository.UpdateAsync();
            });
            IsDebugModeEnabled.Subscribe(async x =>
            {
                // ログ出力を切り替え
                Logger.IsLogFileOutEnabled = x;

                setting.IsDebugModeEnabled = x;
                await _settingRepository.UpdateAsync();
            });
        }
Ejemplo n.º 2
0
        public MainWindowViewModel()
        {
            _skillCountUseCase = new SkillCountUseCase();

            IsLoaded = new ReactivePropertySlim <bool>(false);
            MapName  = _skillCountUseCase.MapName
                       .Select(x => string.IsNullOrEmpty(x) ? "" : x)
                       .ToReadOnlyReactivePropertySlim();
            WorkName = _skillCountUseCase.WorkName
                       .Select(x => string.IsNullOrEmpty(x) ? "" : x)
                       .ToReadOnlyReactivePropertySlim();
            WarStatus         = _skillCountUseCase.WarStatus.ToReadOnlyReactivePropertySlim();
            AverageFps        = _skillCountUseCase.AverageFps.ToReadOnlyReactivePropertySlim();
            AttackKeepDamage  = _skillCountUseCase.AttackKeepDamage.ToReadOnlyReactivePropertySlim();
            DefenceKeepDamage = _skillCountUseCase.DefenceKeepDamage.ToReadOnlyReactivePropertySlim();
            IsBookUsing       = _skillCountUseCase.IsBookUsing.ToReadOnlyReactivePropertySlim();
            Pow        = _skillCountUseCase.Pow.ToReadOnlyReactivePropertySlim();
            Hp         = _skillCountUseCase.Hp.ToReadOnlyReactivePropertySlim();
            PowDebuffs = _skillCountUseCase.PowDebuffs
                         .Select(x => string.IsNullOrEmpty(x) ? "" : x)
                         .ToReadOnlyReactivePropertySlim();

            IsSkillCountFileSave = _skillCountUseCase.IsSkillCountFileSave.ToReactiveProperty();
            IsSkillCountFileSave.Subscribe(x =>
            {
                _skillCountUseCase.IsSkillCountFileSave.Value = x;
            });
            IsNotifyBookUses = _skillCountUseCase.IsNotifyBookUses.ToReactiveProperty();
            IsNotifyBookUses.Subscribe(x =>
            {
                _skillCountUseCase.IsNotifyBookUses.Value = x;
            });
            IsNotifyEnchantUses = _skillCountUseCase.IsNotifyEnchantUses.ToReactiveProperty();
            IsNotifyEnchantUses.Subscribe(x =>
            {
                _skillCountUseCase.IsNotifyEnchantUses.Value = x;
            });
            IsNotifySpellUses = _skillCountUseCase.IsNotifySpellUses.ToReactiveProperty();
            IsNotifySpellUses.Subscribe(x =>
            {
                _skillCountUseCase.IsNotifySpellUses.Value = x;
            });
            EnchantSpellNotifySecond = _skillCountUseCase.EnchantSpellNotifyTimeSpan
                                       .Select(x => (int)(x ?? TimeSpan.Zero).TotalSeconds)
                                       .ToReactiveProperty();
            EnchantSpellNotifySecond.Subscribe(x =>
            {
                _skillCountUseCase.EnchantSpellNotifyTimeSpan.Value = TimeSpan.FromSeconds(x);
            });
            IsAllwaysOnTop = _skillCountUseCase.IsAllwaysOnTop.ToReactiveProperty();
            IsAllwaysOnTop.Subscribe(x =>
            {
                _skillCountUseCase.IsAllwaysOnTop.Value = x;
            });
            IsDebugModeEnabled = _skillCountUseCase.IsDebugModeEnabled.ToReactiveProperty();
            IsDebugModeEnabled.Subscribe(x =>
            {
                _skillCountUseCase.IsDebugModeEnabled.Value = x;
            });

            IsWarriorFilter  = new ReactiveProperty <bool>(true);
            IsSorcererFilter = new ReactiveProperty <bool>(true);
            IsScoutFilter    = new ReactiveProperty <bool>(true);
            IsCestusFilter   = new ReactiveProperty <bool>(true);
            IsFencerFilter   = new ReactiveProperty <bool>(true);
            void doFilter(bool _)
            {
                var filterWorks = new List <string>();

                if (IsWarriorFilter.Value)
                {
                    filterWorks.Add("ウォーリアー");
                }
                if (IsSorcererFilter.Value)
                {
                    filterWorks.Add("ソーサラー");
                }
                if (IsScoutFilter.Value)
                {
                    filterWorks.Add("スカウト");
                }
                if (IsCestusFilter.Value)
                {
                    filterWorks.Add("セスタス");
                }
                if (IsFencerFilter.Value)
                {
                    filterWorks.Add("フェンサー");
                }

                SkillCountHistories?.Refresh(entity => filterWorks.Contains(entity.WorkName));
            }

            IsWarriorFilter.Subscribe(doFilter);
            IsSorcererFilter.Subscribe(doFilter);
            IsScoutFilter.Subscribe(doFilter);
            IsCestusFilter.Subscribe(doFilter);
            IsFencerFilter.Subscribe(doFilter);
            CurrentSkillCollection = _skillCountUseCase.CurrentSkillCollection.ToReadOnlyReactiveCollection();
            SkillCountHistories    = _skillCountUseCase.SkillCountHistories.ToFilteredReadOnlyObservableCollection(x =>
            {
                var filterWorks = new List <string>();
                if (IsWarriorFilter.Value)
                {
                    filterWorks.Add("ウォーリアー");
                }
                if (IsSorcererFilter.Value)
                {
                    filterWorks.Add("ソーサラー");
                }
                if (IsScoutFilter.Value)
                {
                    filterWorks.Add("スカウト");
                }
                if (IsCestusFilter.Value)
                {
                    filterWorks.Add("セスタス");
                }
                if (IsFencerFilter.Value)
                {
                    filterWorks.Add("フェンサー");
                }

                return(filterWorks.Contains(x.WorkName));
            });
            SelectedSkillCountHistory = new ReactiveProperty <SkillCountEntity>();
            SelectedSkillCountDatails = SelectedSkillCountHistory
                                        .Select(x => x != null ? x.Details : new List <SkillCountDetailEntity>())
                                        .ToReadOnlyReactivePropertySlim();

            LoadedCommand = new ReactiveCommand();
            LoadedCommand.Subscribe(async() =>
            {
                await _skillCountUseCase.SetUpAsync();
                _skillCountUseCase.StartSkillCounter();

                IsLoaded.Value = true;
            });

            ResetCommand = new ReactiveCommand();
            ResetCommand.Subscribe(async() =>
            {
                await _skillCountUseCase.ResetSkillCountAsync();
            });

            CopySkillCountsCommand = SelectedSkillCountHistory
                                     .Select(x => x != null)
                                     .ToReactiveCommand();
            CopySkillCountsCommand.Subscribe(o =>
            {
                var entities = ((System.Collections.IList)o).Cast <SkillCountEntity>();
                _skillCountUseCase.CopySkillCountToClipboard(entities);

                MessageQueue.Enqueue("クリップボードにコピーしました");
            });
        }