private ICommand CreateChangeFontCommand(
     Func <FontInfo> getCurrentoFont,
     Action <FontInfo> changeFont)
 => new DelegateCommand(() =>
 {
     var result = FontDialogWrapper.ShowDialog(getCurrentoFont());
     if (result.Result)
     {
         changeFont.Invoke(result.Font);
     }
 });
        public void Execute(object parameter)
        {
            var font = (FontInfo)parameter;

            var result = FontDialogWrapper.ShowDialog(font);

            if (result.Result)
            {
                this.ChangeFontDelegate?.Invoke(result.Font);
                this.refreshViewAction?.Invoke();
            }
        }
        private void VisualSettingControl_Load(object sender, EventArgs e)
        {
            var colorSetDirectory = this.GetColorSetDirectory;

            if (Directory.Exists(colorSetDirectory))
            {
                this.OpenFileDialog.InitialDirectory = colorSetDirectory;
                this.SaveFileDialog.InitialDirectory = colorSetDirectory;
            }

            this.WidthNumericUpDown.Value  = this.BarSize.Width;
            this.HeightNumericUpDown.Value = this.BarSize.Height;

            this.RefreshSampleImage();

            this.ChangeFontItem.Click += (s1, e1) =>
            {
                var result = FontDialogWrapper.ShowDialog(this.GetFontInfo());
                if (result.Result)
                {
                    this.SetFontInfo(result.Font);
                    this.RefreshSampleImage();
                }
            };

            this.ChangeFontColorItem.Click += (s1, e1) =>
            {
                var result = ColorDialogWrapper.ShowDialog(this.FontColor, true);
                if (result.Result)
                {
                    this.FontColor = result.LegacyColor;
                    this.RefreshSampleImage();
                }
            };

            this.ChangeFontOutlineColorItem.Click += (s1, e1) =>
            {
                var result = ColorDialogWrapper.ShowDialog(this.FontOutlineColor, true);
                if (result.Result)
                {
                    this.FontOutlineColor = result.LegacyColor;
                    this.RefreshSampleImage();
                }
            };

            this.ChangeWarningFontColorItem.Click += (s1, e1) =>
            {
                var result = ColorDialogWrapper.ShowDialog(this.WarningFontColor, true);
                if (result.Result)
                {
                    this.WarningFontColor = result.LegacyColor;
                    this.RefreshSampleImage();
                }
            };

            this.ChangeWarningFontOutlineColorItem.Click += (s1, e1) =>
            {
                var result = ColorDialogWrapper.ShowDialog(this.WarningFontOutlineColor, true);
                if (result.Result)
                {
                    this.WarningFontOutlineColor = result.LegacyColor;
                    this.RefreshSampleImage();
                }
            };

            this.ChangeBarColorItem.Click += (s1, e1) =>
            {
                var result = ColorDialogWrapper.ShowDialog(this.BarColor, true);
                if (result.Result)
                {
                    this.BarColor = result.LegacyColor;
                    this.RefreshSampleImage();
                }
            };

            this.ChangeBarOutlineColorItem.Click += (s1, e1) =>
            {
                var result = ColorDialogWrapper.ShowDialog(this.BarOutlineColor, true);
                if (result.Result)
                {
                    this.BarOutlineColor = result.LegacyColor;
                    this.RefreshSampleImage();
                }
            };

            this.ChangeBackgoundColorItem.Click += (s1, e1) =>
            {
                var result = ColorDialogWrapper.ShowDialog(this.backgroundColor, true);
                if (result.Result)
                {
                    this.backgroundColor = Color.FromArgb(
                        this.alphaDialog.Alpha,
                        result.LegacyColor);;
                    this.RefreshSampleImage();
                }
            };

            this.ChangeBackgroundAlphaItem.Click += async(s1, e1) =>
            {
                this.alphaDialog.Alpha = this.backgroundColor.A;
                if (await Task.Run(() => this.alphaDialog.ShowDialog(this)) !=
                    DialogResult.Cancel)
                {
                    this.backgroundColor = Color.FromArgb(
                        this.alphaDialog.Alpha,
                        this.backgroundColor);
                    this.RefreshSampleImage();
                }
            };

            this.LoadColorSetItem.Click += async(s1, e1) =>
            {
                if (await Task.Run(() => this.OpenFileDialog.ShowDialog(this)) !=
                    DialogResult.Cancel)
                {
                    using (var sr = new StreamReader(this.OpenFileDialog.FileName, new UTF8Encoding(false)))
                    {
                        var xs       = new XmlSerializer(typeof(ColorSet));
                        var colorSet = xs.Deserialize(sr) as ColorSet;
                        if (colorSet != null)
                        {
                            this.FontColor               = colorSet.FontColor.FromHTML();
                            this.FontOutlineColor        = colorSet.FontOutlineColor.FromHTML();
                            this.WarningFontColor        = colorSet.WarningFontColor.FromHTML();
                            this.WarningFontOutlineColor = colorSet.WarningFontOutlineColor.FromHTML();
                            this.BarColor        = colorSet.BarColor.FromHTML();
                            this.BarOutlineColor = colorSet.BarOutlineColor.FromHTML();
                            this.backgroundColor = string.IsNullOrWhiteSpace(colorSet.BackgroundColor) ?
                                                   Color.Transparent :
                                                   Color.FromArgb(colorSet.BackgroundAlpha, colorSet.BackgroundColor.FromHTML());

                            this.RefreshSampleImage();
                        }
                    }
                }
            };

            this.SaveColorSetItem.Click += async(s1, e1) =>
            {
                if (string.IsNullOrWhiteSpace(this.SaveFileDialog.FileName))
                {
                    this.SaveFileDialog.FileName = "スペスペ配色セット.xml";
                }

                if (await Task.Run(() => this.SaveFileDialog.ShowDialog(this)) !=
                    DialogResult.Cancel)
                {
                    var colorSet = new ColorSet()
                    {
                        FontColor               = this.FontColor.ToHTML(),
                        FontOutlineColor        = this.FontOutlineColor.ToHTML(),
                        WarningFontColor        = this.WarningFontColor.ToHTML(),
                        WarningFontOutlineColor = this.WarningFontOutlineColor.ToHTML(),
                        BarColor        = this.BarColor.ToHTML(),
                        BarOutlineColor = this.BarOutlineColor.ToHTML(),
                        BackgroundColor = this.backgroundColor.ToHTML(),
                        BackgroundAlpha = this.backgroundColor.A,
                    };

                    using (var sw = new StreamWriter(this.SaveFileDialog.FileName, false, new UTF8Encoding(false)))
                    {
                        var xs = new XmlSerializer(typeof(ColorSet));
                        xs.Serialize(sw, colorSet);
                    }
                }
            };

            this.WidthNumericUpDown.ValueChanged += (s1, e1) =>
            {
                this.RefreshSampleImage();
            };

            this.HeightNumericUpDown.ValueChanged += (s1, e1) =>
            {
                this.RefreshSampleImage();
            };

            this.ResetSpellFontItem.Click += (s1, e1) =>
            {
                foreach (var s in SpellTable.Instance.Table)
                {
                    s.Font = this.GetFontInfo();
                }

                SpellsController.Instance.ClosePanels();
                SpellTable.Instance.Save(true);
            };

            this.ResetSpellBarSizeItem.Click += (s1, e1) =>
            {
                foreach (var s in SpellTable.Instance.Table)
                {
                    s.BarWidth  = this.BarSize.Width;
                    s.BarHeight = this.BarSize.Height;
                }

                SpellsController.Instance.ClosePanels();
                SpellTable.Instance.Save(true);
            };

            this.ResetSpellColorItem.Click += (s1, e1) =>
            {
                foreach (var s in SpellTable.Instance.Table)
                {
                    s.FontColor               = this.FontColor.ToHTML();
                    s.FontOutlineColor        = this.FontOutlineColor.ToHTML();
                    s.WarningFontColor        = this.WarningFontColor.ToHTML();
                    s.WarningFontOutlineColor = this.WarningFontOutlineColor.ToHTML();
                    s.BarColor        = this.BarColor.ToHTML();
                    s.BarOutlineColor = this.BarOutlineColor.ToHTML();
                    s.BackgroundColor = this.backgroundColor.ToHTML();
                    s.BackgroundAlpha = this.backgroundColor.A;
                }

                SpellsController.Instance.ClosePanels();
                SpellTable.Instance.Save(true);
            };

            this.ResetTelopFontItem.Click += (s1, e1) =>
            {
                foreach (var s in TickerTable.Instance.Table)
                {
                    s.Font = this.GetFontInfo();
                }

                TickersController.Instance.CloseTelops();
                TickerTable.Instance.Save(true);
            };

            this.ResetTelopColorItem.Click += (s1, e1) =>
            {
                foreach (var s in TickerTable.Instance.Table)
                {
                    s.FontColor        = this.FontColor.ToHTML();
                    s.FontOutlineColor = this.FontOutlineColor.ToHTML();
                    s.BackgroundColor  = this.backgroundColor.ToHTML();
                    s.BackgroundAlpha  = this.backgroundColor.A;
                }

                TickersController.Instance.CloseTelops();
                TickerTable.Instance.Save(true);
            };
        }