Exemplo n.º 1
0
        /// <summary>
        /// メインの処理。
        ///
        /// 各インスタンスを生成して、イベントのbindを行い、メインダイアログの実行を開始する。
        /// </summary>
        private void Main()
        {
            // -- global configの読み込み

            config = GlobalConfig.CreateInstance();

            // -- 各インスタンスの生成と、それぞれのbind作業

            // -- 画像の読み込み

            {
                imageManager = new ImageManager();
                imageManager.Update(); // ここでconfigに従い、画像が読み込まれる。

                // GlobalConfigのプロパティ変更に対して、このimageManagerが呼び出されるようにbindしておく。

                config.AddPropertyChangedHandler("BoardImageVersion", imageManager.UpdateBoardImage);
                config.AddPropertyChangedHandler("TatamiImageVersion", imageManager.UpdateBoardImage);
                config.AddPropertyChangedHandler("PieceTableImageVersion", imageManager.UpdateBoardImage);

                config.AddPropertyChangedHandler("PieceImageVersion", imageManager.UpdatePieceImage);
                config.AddPropertyChangedHandler("PieceAttackImageVersion", imageManager.UpdatePieceAttackImage);

                config.AddPropertyChangedHandler("LastMoveFromColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("LastMoveToColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("PickedMoveFromColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("PickedMoveToColorType", imageManager.UpdatePieceMoveImage);

                config.AddPropertyChangedHandler("BoardNumberImageVersion", imageManager.UpdateBoardNumberImage);
            }

            // -- メインの対局ウィンドゥ

            var mainDialog = new MainDialog();

            mainForm = mainDialog;

            // -- 対局controllerを1つ生成して、メインの対局ウィンドゥのViewModelに加える

            var gameServer = new LocalGameServer();

            mainDialog.Init(gameServer);

            // 盤・駒が変更されたときにMainDialogのメニューの内容を修正しないといけないので更新がかかるようにしておく。

            config.AddPropertyChangedHandler("BoardImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("TatamiImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PieceImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PromotePieceColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PieceAttackImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("BoardNumberImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("LastMoveFromColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("LastMoveToColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PickedMoveFromColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PickedMoveToColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("TurnDisplay", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PieceSoundInTheGame", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("KifuReadOut", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("ReadOutSenteGoteEverytime", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("MemoryLoggingEnable", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("FileLoggingEnable", mainDialog.UpdateMenuItems, mainDialog);

            // -- ロギング用のハンドラをセット

            var MemoryLoggingEnableHandler = new PropertyChangedEventHandler((args) =>
            {
                if (config.MemoryLoggingEnable)
                {
                    Log.log1 = new MemoryLog();
                }
                else
                {
                    if (Log.log1 != null)
                    {
                        Log.log1.Dispose();
                    }
                    Log.log1 = null;
                }
            });
            var FileLoggingEnable = new PropertyChangedEventHandler((args) =>
            {
                if (config.FileLoggingEnable)
                {
                    var now  = DateTime.Now;
                    Log.log2 = new FileLog($"log{now.ToString("yyyyMMddHHmm")}.txt");
                }
                else
                {
                    if (Log.log2 != null)
                    {
                        Log.log2.Dispose();
                    }
                    Log.log2 = null;
                }
            });

            config.AddPropertyChangedHandler("MemoryLoggingEnable", MemoryLoggingEnableHandler);
            config.AddPropertyChangedHandler("FileLoggingEnable", FileLoggingEnable);

            // 上のハンドラを呼び出して、必要ならばロギングを開始しておいてやる。
            MemoryLoggingEnableHandler(null);
            FileLoggingEnable(null);

            // 初期化が終わったのでgameServerの起動を行う。
            gameServer.Start();

            // サウンド
            soundManager = new SoundManager();
            soundManager.Start();

            // 終了するときに設定ファイルに書き出すコード
            Application.ApplicationExit += new EventHandler((sender, e) =>
            {
                // メインウィンドウと検討ウィンドウに関して、
                // 終了時のウィンドウサイズを記憶しておき、次回起動時にこのサイズでウィンドウを生成する。
                if (mainDialog.ClientSize.Width >= 100 && mainDialog.ClientSize.Height >= 100)
                {
                    config.MainDialogClientSize = mainDialog.ClientSize;
                }
                if (mainDialog.engineConsiderationDialog != null &&
                    mainDialog.engineConsiderationDialog.Width >= 100 && mainDialog.engineConsiderationDialog.Height >= 100)
                {
                    config.ConsiderationDialogClientSize     = mainDialog.engineConsiderationDialog.ClientSize;
                    config.ConsiderationDialogClientLocation =
                        new Point(
                            mainDialog.engineConsiderationDialog.Location.X - mainDialog.Location.X,
                            mainDialog.engineConsiderationDialog.Location.Y - mainDialog.Location.Y
                            );
                }

                config.Save();
                soundManager.Dispose();

                // 起動しているGameServerすべてを終了させる必要がある。(エンジンを停止させるため)
                if (gameServer != null)
                {
                    gameServer.Dispose();
                }
            });

            Application.Run(mainDialog);
        }
Exemplo n.º 2
0
        /// <summary>
        /// メインの処理。
        ///
        /// 各インスタンスを生成して、イベントのbindを行い、メインダイアログの実行を開始する。
        /// </summary>
        private void Main()
        {
            // -- working directoryの変更

            // 拡張子関連付けやショートカットなどで他のフォルダがworking directoryに設定されていることがある。
            {
                try
                {
                    var dirpath = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(Environment.GetCommandLineArgs()[0]));
                    Directory.SetCurrentDirectory(dirpath);
                } catch { }
            }


            // -- global configの読み込み

            Config = GlobalConfig.CreateInstance();

            // -- 各インスタンスの生成と、それぞれのbind作業

            // -- 画像の読み込み

            {
                ImageManager = new ImageManager();
                ImageManager.Update(); // ここでconfigに従い、画像が読み込まれる。

                // GlobalConfigのプロパティ変更に対して、このimageManagerが呼び出されるようにbindしておく。

                Config.AddPropertyChangedHandler("BoardImageVersion", ImageManager.UpdateBoardImage);
                Config.AddPropertyChangedHandler("BoardImageColorVersion", ImageManager.UpdateBoardImage);
                Config.AddPropertyChangedHandler("TatamiImageVersion", ImageManager.UpdateBoardImage);
                Config.AddPropertyChangedHandler("TatamiImageColorVersion", ImageManager.UpdateBoardImage);
                Config.AddPropertyChangedHandler("PieceTableImageVersion", ImageManager.UpdateBoardImage);

                Config.AddPropertyChangedHandler("PieceImageVersion", ImageManager.UpdatePieceImage);
                Config.AddPropertyChangedHandler("PieceImageColorVersion", ImageManager.UpdatePieceImage);

                Config.AddPropertyChangedHandler("PieceAttackImageVersion", ImageManager.UpdatePieceAttackImage);

                Config.AddPropertyChangedHandler("LastMoveFromColorType", ImageManager.UpdatePieceMoveImage);
                Config.AddPropertyChangedHandler("LastMoveToColorType", ImageManager.UpdatePieceMoveImage);
                Config.AddPropertyChangedHandler("PickedMoveFromColorType", ImageManager.UpdatePieceMoveImage);
                Config.AddPropertyChangedHandler("PickedMoveToColorType", ImageManager.UpdatePieceMoveImage);

                Config.AddPropertyChangedHandler("BoardNumberImageVersion", ImageManager.UpdateBoardNumberImage);
            }

            // -- メインの対局ウィンドゥ

            var mainDialog = new MainDialog();

            mainForm = mainDialog;

            // -- 対局controllerを1つ生成して、メインの対局ウィンドゥのViewModelに加える

            var gameServer = new LocalGameServer();

            mainDialog.Init(gameServer);

            // -- 盤・駒が変更されたときにMainDialogのメニューの内容を修正しないといけないので更新がかかるようにしておく。

            // 表示設定

            Config.AddPropertyChangedHandler("BoardImageVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("BoardImageColorVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("TatamiImageVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("TatamiImageColorVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("PieceImageVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("PieceImageColorVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("PromotePieceColorType", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("FlipWhitePromoteDialog", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("PieceAttackImageVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("BoardNumberImageVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("LastMoveFromColorType", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("LastMoveToColorType", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("PickedMoveFromColorType", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("PickedMoveToColorType", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("TurnDisplay", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("MemoryLoggingEnable", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("FileLoggingEnable", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("NegateEvalWhenWhite", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("KifuWindowKifuVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("ConsiderationWindowKifuVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("DisplayNameTurnVersion", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("EnableGameEffect", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("PickedMoveDisplayStyle", mainDialog.ForceRedraw);

            // 棋譜・検討ウインドウの高さ・幅

            Config.AddPropertyChangedHandler("KifuWindowWidthType", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("KifuWindowWidthType", mainDialog.ResizeKifuControl, mainDialog);
            Config.AddPropertyChangedHandler("KifuWindowWidthType", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("ConsiderationWindowHeightType", mainDialog.ForceRedraw);
            Config.AddPropertyChangedHandler("ConsiderationWindowHeightType", mainDialog.ResizeConsiderationControl, mainDialog);
            Config.AddPropertyChangedHandler("ConsiderationWindowHeightType", mainDialog.UpdateMenuItems, mainDialog);

            // 操作設定

            Config.AddPropertyChangedHandler("KifuWindowPrevNextKey", mainDialog.UpdateToolStripShortcut);
            Config.AddPropertyChangedHandler("KifuWindowNextSpecialKey", mainDialog.UpdateToolStripShortcut);
            Config.AddPropertyChangedHandler("KifuWindowFirstLastKey", mainDialog.UpdateToolStripShortcut);
            Config.AddPropertyChangedHandler("ConsiderationWindowPrevNextKey", mainDialog.UpdateToolStripShortcut);

            // DockWindow

            Config.KifuWindowDockManager.AddPropertyChangedHandler("DockState", mainDialog.UpdateMenuItems, mainDialog);
            Config.EngineConsiderationWindowDockManager.AddPropertyChangedHandler("DockState", mainDialog.UpdateMenuItems, mainDialog);
            Config.MiniShogiBoardDockManager.AddPropertyChangedHandler("DockState", mainDialog.UpdateMenuItems, mainDialog);

            // -- ロギング用のハンドラをセット

            // メモリ上でのロギング
            Log.log1 = new MemoryLog();

            var FileLoggingEnable = new PropertyChangedEventHandler((args) =>
            {
                if (Config.FileLoggingEnable)
                {
                    var now  = DateTime.Now;
                    Log.log2 = new FileLog($"log{now.ToString("yyyyMMddHHmm")}.txt");
                }
                else
                {
                    if (Log.log2 != null)
                    {
                        Log.log2.Dispose();
                    }
                    Log.log2 = null;
                }
            });

            Config.AddPropertyChangedHandler("FileLoggingEnable", FileLoggingEnable);

            // 上のハンドラを呼び出して、必要ならばロギングを開始しておいてやる。
            FileLoggingEnable(null);


            // 初期化が終わったのでgameServerの起動を行う。
            gameServer.Start();

            // サウンド
            SoundManager = new SoundManager();
            SoundManager.Start();

            // 終了するときに設定ファイルに書き出すコード
            Application.ApplicationExit += new EventHandler((sender, e) =>
            {
                // メインウィンドウのサイズを保存
                SaveMainDialogSize();

                // 設定ファイルの保存
                SaveConfig();

                // サウンドマネージャーの停止
                SoundManager.Dispose();

                // 起動しているGameServerすべてを明示的に終了させる必要がある。(そこにぶら下がっているエンジンを停止させるため)
                if (gameServer != null)
                {
                    gameServer.Dispose();
                }
            });

            // -- メインダイアログを生成して、アプリの開始

            Application.Run(mainDialog);
        }
Exemplo n.º 3
0
        /// <summary>
        /// メインの処理。
        ///
        /// 各インスタンスを生成して、イベントのbindを行い、メインダイアログの実行を開始する。
        /// </summary>
        private void Main()
        {
            // -- global configの読み込み

            Config = GlobalConfig.CreateInstance();

            // -- 各インスタンスの生成と、それぞれのbind作業

            // -- 画像の読み込み

            {
                ImageManager = new ImageManager();
                ImageManager.Update(); // ここでconfigに従い、画像が読み込まれる。

                // GlobalConfigのプロパティ変更に対して、このimageManagerが呼び出されるようにbindしておく。

                Config.AddPropertyChangedHandler("BoardImageVersion", ImageManager.UpdateBoardImage);
                Config.AddPropertyChangedHandler("TatamiImageVersion", ImageManager.UpdateBoardImage);
                Config.AddPropertyChangedHandler("PieceTableImageVersion", ImageManager.UpdateBoardImage);

                Config.AddPropertyChangedHandler("PieceImageVersion", ImageManager.UpdatePieceImage);
                Config.AddPropertyChangedHandler("PieceAttackImageVersion", ImageManager.UpdatePieceAttackImage);

                Config.AddPropertyChangedHandler("LastMoveFromColorType", ImageManager.UpdatePieceMoveImage);
                Config.AddPropertyChangedHandler("LastMoveToColorType", ImageManager.UpdatePieceMoveImage);
                Config.AddPropertyChangedHandler("PickedMoveFromColorType", ImageManager.UpdatePieceMoveImage);
                Config.AddPropertyChangedHandler("PickedMoveToColorType", ImageManager.UpdatePieceMoveImage);

                Config.AddPropertyChangedHandler("BoardNumberImageVersion", ImageManager.UpdateBoardNumberImage);
            }

            // -- メインの対局ウィンドゥ

            var mainDialog = new MainDialog();

            mainForm = mainDialog;

            // -- 対局controllerを1つ生成して、メインの対局ウィンドゥのViewModelに加える

            var gameServer = new LocalGameServer();

            mainDialog.Init(gameServer);

            // 盤・駒が変更されたときにMainDialogのメニューの内容を修正しないといけないので更新がかかるようにしておく。

            Config.AddPropertyChangedHandler("BoardImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("TatamiImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("PieceImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("PromotePieceColorType", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("PieceAttackImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("BoardNumberImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("LastMoveFromColorType", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("LastMoveToColorType", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("PickedMoveFromColorType", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("PickedMoveToColorType", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("TurnDisplay", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("PieceSoundInTheGame", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("PieceSoundOffTheGame", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("KifuReadOut", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("ReadOutSenteGoteEverytime", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("MemoryLoggingEnable", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("FileLoggingEnable", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("NegateEvalWhenWhite", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("KifuWindowWidthType", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("ConsiderationWindowFollowMainWindow", mainDialog.UpdateMenuItems, mainDialog);
            Config.AddPropertyChangedHandler("ReadOutCancelWhenGameEnd", mainDialog.UpdateMenuItems, mainDialog);

            // -- ロギング用のハンドラをセット

            var MemoryLoggingEnableHandler = new PropertyChangedEventHandler((args) =>
            {
                if (Config.MemoryLoggingEnable)
                {
                    Log.log1 = new MemoryLog();
                }
                else
                {
                    if (Log.log1 != null)
                    {
                        Log.log1.Dispose();
                    }
                    Log.log1 = null;
                }
            });
            var FileLoggingEnable = new PropertyChangedEventHandler((args) =>
            {
                if (Config.FileLoggingEnable)
                {
                    var now  = DateTime.Now;
                    Log.log2 = new FileLog($"log{now.ToString("yyyyMMddHHmm")}.txt");
                }
                else
                {
                    if (Log.log2 != null)
                    {
                        Log.log2.Dispose();
                    }
                    Log.log2 = null;
                }
            });

            Config.AddPropertyChangedHandler("MemoryLoggingEnable", MemoryLoggingEnableHandler);
            Config.AddPropertyChangedHandler("FileLoggingEnable", FileLoggingEnable);

            Config.AddPropertyChangedHandler("KifuWindowWidthType", mainDialog.ResizeKifuControl, mainDialog);

            // 上のハンドラを呼び出して、必要ならばロギングを開始しておいてやる。
            MemoryLoggingEnableHandler(null);
            FileLoggingEnable(null);

            // 初期化が終わったのでgameServerの起動を行う。
            gameServer.Start();

            // サウンド
            SoundManager = new SoundManager();
            SoundManager.Start();

            // 終了するときに設定ファイルに書き出すコード
            Application.ApplicationExit += new EventHandler((sender, e) =>
            {
                // メインウィンドウのサイズを保存
                SaveMainDialogSize();

                // 設定ファイルの保存
                SaveConfig();

                // サウンドマネージャーの停止
                SoundManager.Dispose();

                // 起動しているGameServerすべてを明示的に終了させる必要がある。(そこにぶら下がっているエンジンを停止させるため)
                if (gameServer != null)
                {
                    gameServer.Dispose();
                }
            });

            // -- メインダイアログを生成して、アプリの開始

            Application.Run(mainDialog);
        }