// 定期的にスクリーンショットを取得し、そこに起因する処理を行う private void HelperTaskF() { if (!SaveScreenshotFlg.Value) { return; } using (var screenShot = ScreenShotProvider.GetScreenshot()) { // スクショが取得できるとscreenShotがnullにならない if (screenShot != null) { // シーン文字列を取得し、表示する string judgedScene = SceneRecognition.JudgeGameScene(screenShot); JudgedScene.Value = $"シーン判定 : {judgedScene}"; // 資材量を取得する // (戦闘中なら各種ボムの分量と残り秒数を読み取る) if (SupplyStore.SupplyListEachScene.ContainsKey(judgedScene)) { foreach (string supplyName in SupplyStore.SupplyListEachScene[judgedScene]) { if (SupplyStore.UpdateSupplyValue(screenShot, supplyName, AutoSupplyScreenShotFlg.Value, PutCharacterRecognitionFlg.Value)) { PutLog($"資材量追記:{supplyName}"); } } } // 戦闘中でなくなった場合、速やかにボムタイマーをリセットする if (judgedScene != "戦闘中" && judgedScene != "不明") { SettingsStore.BombChageTime1 = null; SettingsStore.BombChageTime2 = null; SettingsStore.BombChageTime3 = null; } } else { // スクショが取得できなくなったのでその旨を通知する PutLog("エラー:スクショが取得できなくなりました"); SaveScreenshotFlg.Value = false; } } }
// 資材のインポート機能(index=0~3、0から順にキューブ・ドリル・勲章・家具コイン) private async Task ImportSubSupplyAsync(int index) { // インスタンスを作成 var ofd = new OpenFileDialog { // ファイルの種類を設定 Filter = "設定ファイル(*.csv)|*.csv|全てのファイル (*.*)|*.*", FileName = $"SubSupply{(index + 1)}.csv" }; // ダイアログを表示 if ((bool)ofd.ShowDialog()) { // 資材をインポート PutLog("資材データを読み込み開始..."); if (await SupplyStore.ImportOldSubSupplyDataAsync(ofd.FileName, index)) { PutLog("資材データを読み込みました"); } else { PutLog("エラー:資材データを読み込めませんでした"); } } }
// コンストラクタ public MainViewModel() { // picフォルダが存在しない場合は作成する if (!Directory.Exists(@"pic\")) { Directory.CreateDirectory(@"pic\"); } // debugフォルダが存在しない場合は作成する if (!Directory.Exists(@"debug\")) { Directory.CreateDirectory(@"debug\"); } // 設定項目を初期化する if (!SettingsStore.Initialize()) { MessageBox.Show("設定を読み込めませんでした。\nデフォルトの設定で起動します。", Utility.SoftwareName, MessageBoxButton.OK, MessageBoxImage.Exclamation); } // 資材データベースを初期化する SupplyStore.Initialize(); // 設定内容を画面に反映する SetSettings(); // プロパティを設定 ForTwitterFlg.Subscribe(x => { SettingsStore.ForTwitterFlg = x; }); MainWindowPositionLeft.Subscribe(x => { SettingsStore.MainWindowRect[0] = x; SettingsStore.ChangeSettingFlg = true; }); MainWindowPositionTop.Subscribe(x => { SettingsStore.MainWindowRect[1] = x; SettingsStore.ChangeSettingFlg = true; }); MainWindowPositionWidth.Subscribe(x => { SettingsStore.MainWindowRect[2] = x; SettingsStore.ChangeSettingFlg = true; }); MainWindowPositionHeight.Subscribe(x => { SettingsStore.MainWindowRect[3] = x; SettingsStore.ChangeSettingFlg = true; }); MemoryWindowPositionFlg.Subscribe(x => { SettingsStore.MemoryWindowPositionFlg = x; }); AutoSearchPositionFlg.Subscribe(x => { SettingsStore.AutoSearchPositionFlg = x; }); AutoSupplyScreenShotFlg.Subscribe(x => { SettingsStore.AutoSupplyScreenShotFlg = x; }); PutCharacterRecognitionFlg.Subscribe(x => { SettingsStore.PutCharacterRecognitionFlg = x; }); DragAndDropPictureFlg.Subscribe(x => { SettingsStore.DragAndDropPictureFlg = x; }); // コマンドを設定 GetGameWindowPositionCommand.Subscribe(_ => GetGameWindowPosition()); SaveScreenshotCommand.Subscribe(_ => { try { string fileName = $"{Utility.GetTimeStrLong()}.png"; ScreenShotProvider.GetScreenshot(ForTwitterFlg.Value).Save($"pic\\{fileName}"); PutLog($"スクリーンショット : 成功"); PutLog($"ファイル名 : {fileName}"); } catch (Exception) { PutLog($"スクリーンショット : 失敗"); } }); CloseCommand.Subscribe(_ => { CloseWindow.Value = true; }); SoftwareInfoCommand.Subscribe(_ => { // ソフトの情報を返す // 参考→http://dobon.net/vb/dotnet/file/myversioninfo.html var assembly = Assembly.GetExecutingAssembly(); // AssemblyTitle string asmttl = ((AssemblyTitleAttribute) Attribute.GetCustomAttribute(assembly, typeof(AssemblyTitleAttribute))).Title; // AssemblyCopyright string asmcpy = ((AssemblyCopyrightAttribute) Attribute.GetCustomAttribute(assembly, typeof(AssemblyCopyrightAttribute))).Copyright; // AssemblyProduct string asmprd = ((AssemblyProductAttribute) Attribute.GetCustomAttribute(assembly, typeof(AssemblyProductAttribute))).Product; // AssemblyVersion var asmver = assembly.GetName().Version; MessageBox.Show( $"{asmttl} Ver.{asmver}\n{asmcpy}\n{asmprd}", Utility.SoftwareName, MessageBoxButton.OK, MessageBoxImage.Information); }); ImportSettingsCommand.Subscribe(_ => { // インスタンスを作成 var ofd = new OpenFileDialog { // ファイルの種類を設定 Filter = "設定ファイル(*.json)|*.json|全てのファイル (*.*)|*.*" }; // ダイアログを表示 if ((bool)ofd.ShowDialog()) { // 設定をインポート if (!SettingsStore.LoadSettings(ofd.FileName)) { PutLog("エラー:設定を読み込めませんでした"); } else { PutLog("設定を読み込みました"); } SetSettings(); } }); ExportSettingsCommand.Subscribe(_ => { // インスタンスを作成 var sfd = new SaveFileDialog { // ファイルの種類を設定 Filter = "設定ファイル(*.json)|*.json|全てのファイル (*.*)|*.*" }; // ダイアログを表示 if ((bool)sfd.ShowDialog()) { // 設定をエクスポート if (!SettingsStore.SaveSettings(sfd.FileName)) { PutLog("エラー:設定を保存できませんでした"); } else { PutLog("設定を保存しました"); } } }); OpenPicFolderCommand.Subscribe(_ => System.Diagnostics.Process.Start(@"pic\")); OpenSupplyViewCommand.Subscribe(_ => { if (SettingsStore.ShowSupplyWindowFlg) { return; } var vm = new SupplyViewModel(); var view = new Views.SupplyView { DataContext = vm }; view.Show(); SettingsStore.ShowSupplyWindowFlg = true; }).AddTo(Disposable); OpenTimerViewCommand.Subscribe(_ => { if (SettingsStore.ShowTimerWindowFlg) { return; } var vm = new TimerViewModel(); var view = new Views.TimerView { DataContext = vm }; view.Show(); SettingsStore.ShowTimerWindowFlg = true; }).AddTo(Disposable); ImportMainSupplyCommand.Subscribe(async _ => { // 資材のインポート機能(燃料・資金・ダイヤ) // インスタンスを作成 var ofd = new OpenFileDialog { // ファイルの種類を設定 Filter = "設定ファイル(*.csv)|*.csv|全てのファイル (*.*)|*.*", FileName = "MainSupply.csv" }; // ダイアログを表示 if ((bool)ofd.ShowDialog()) { // 資材をインポート PutLog("資材データを読み込み開始..."); if (await SupplyStore.ImportOldMainSupplyDataAsync(ofd.FileName)) { PutLog("資材データを読み込みました"); } else { PutLog("エラー:資材データを読み込めませんでした"); } } }); ImportSubSupply1Command.Subscribe(async _ => await ImportSubSupplyAsync(0)); ImportSubSupply2Command.Subscribe(async _ => await ImportSubSupplyAsync(1)); ImportSubSupply3Command.Subscribe(async _ => await ImportSubSupplyAsync(2)); ImportSubSupply4Command.Subscribe(async _ => await ImportSubSupplyAsync(3)); // タイマーを初期化し、定時タスクを登録して実行する // http://takachan.hatenablog.com/entry/2017/09/09/225342 var timer = new Timer(200); timer.Elapsed += (sender, e) => { try{ timer.Stop(); HelperTaskF(); } finally{ timer.Start(); } }; timer.Start(); var timer2 = new Timer(1000); timer2.Elapsed += (sender, e) => { try { timer2.Stop(); HelperTaskS(); } finally { timer2.Start(); } }; timer2.Start(); // ウィンドウ表示関係 if (SettingsStore.AutoSupplyWindowFlg) { OpenSupplyViewCommand.Execute(); } if (SettingsStore.AutoTimerWindowFlg) { OpenTimerViewCommand.Execute(); } // 最新版をチェックする CheckSoftwareVer(); }