Beispiel #1
0
        private AskSaveResult AskSaving()
        {
            MessageBoxResult res = ShowDialogManager.ShowMessageBox("そのまえに、データを保存しますか?(「いいえ」を押すと変更内容は破棄されます)", "確認", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

            if (res == MessageBoxResult.Cancel)
            {
                return(AskSaveResult.Cancel);
            }

            if (res == MessageBoxResult.No)
            {
                return(AskSaveResult.CanProcess);
            }

            // 一旦フォーカスを外します。
            var prevFocus = FocusManager.GetFocusedElement(_view);

            FocusManager.SetFocusedElement(_view, _view);

            // 溜まってるイベントは全部処理させる
            WPFUtil.DoEvents();


            _writersBattleFieldViewModel.SetTextToModelsComposite();

            if (_fileService.SaveFile() == false)
            {
                return(AskSaving());
            }

            return(AskSaveResult.CanProcess);
        }
Beispiel #2
0
        public IImageData LoadImage(Uri imageUri, MaterialType materialType)
        {
            var image = GetImage(imageUri);
            var brush = new ImageBrush()
            {
                ImageSource = image,
            };

            var mesh = WPFUtil.CreateDefaultMesh(1.0, 1.0, image.Width, image.Height);

            mesh.Freeze();

            var materialWrap = new MaterialWrap
            {
                MaterialType = materialType,
                Brush        = brush,
                Color        = Colors.White,
            };

            GeometryModel3D model = new GeometryModel3D()
            {
                Geometry = mesh,
                Material = materialWrap.Create(),
            };

            return(new WPFImageData
            {
                Model = model,
                Brush = brush,
                Material = model.Material,
            });
        }
Beispiel #3
0
        /// <summary>
        /// ボナンザの設定を行います。
        /// </summary>
        static void ResetBonanza(AbortReason?reason)
        {
            if (reason == AbortReason.Aborted ||
                reason == AbortReason.FatalError)
            {
                Bonanza = null;
                return;
            }

            // 初回起動時とエラー時はボナンザを起動します。
            var bonanza = new Bonanza();

            bonanza.PropertyChanged += (_, __) => WPFUtil.InvalidateCommand();
            bonanza.Aborted         += (_, e) => ResetBonanza(e.Reason);

            Bonanza = bonanza;
            MainViewModel.SetBonanza(bonanza);
            ShogiModel.SetBonanza(bonanza);

            // オブジェクト設定後に初期化します。
            bonanza.Initialize(ClientFileName);

            // UIをすべて更新します。
            WPFUtil.InvalidateCommand();

            // エラー時は自動的に再接続に行きます。
            if (reason == AbortReason.Error)
            {
                Commands.ExecuteConnect();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Update Responsibility in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBoxResponsibility_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (!loadedUI)
                {
                    return;
                }

                UIElement uiElement = e.OriginalSource as UIElement;
                if (uiElement.IsMouseCaptured)
                {
                    DataGridRow row = WPFUtil.FindVisualParent <DataGridRow>(uiElement);
                    if (null != row)
                    {
                        Component component = row.Item as Component;
                        bool      updated   = BCFDBWriter.BCFDBWriter.UpdateComponent(component);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Beispiel #5
0
        /// <summary>
        /// エフェクトを追加します。
        /// </summary>
        private void AddEffect(EffectObject effect, Square square)
        {
            if (effect == null)
            {
                return;
            }

            // 効果音を調整します。
            if (!IsUseEffectSound)
            {
                effect.StartSoundPath   = null;
                effect.StartSoundVolume = 0.0;
            }
            else
            {
                var percent = EffectVolume;

                effect.StartSoundVolume *= MathEx.Between(0, 100, percent) / 100.0;
            }

            WPFUtil.UIProcess(() =>
            {
                effect.DataContext = CreateContext(square);

                Container.AddEffect(effect);
            });
        }
Beispiel #6
0
        /// <summary>
        /// 背景エフェクトを更新します。
        /// </summary>
        public void UpdateBackground()
        {
            if (Container == null)
            {
                return;
            }

            WPFUtil.UIProcess(() =>
            {
                // 必要なら背景エフェクトを無効にします。
                if (!HasEffectFlag(EffectFlag.Background))
                {
                    TrySetBackgroundKey(null);
                    return;
                }

                var Unit = 30;
                if (this.moveCount >= Unit * 3)
                {
                    TrySetBackgroundKey("WinterEffect");
                }
                else if (this.moveCount >= Unit * 2)
                {
                    TrySetBackgroundKey("AutumnEffect");
                }
                else if (this.moveCount >= Unit)
                {
                    TrySetBackgroundKey("SummerEffect");
                }
                else
                {
                    TrySetBackgroundKey("SpringEffect");
                }
            });
        }
Beispiel #7
0
        private void ToggleUIImport()
        {
            WPFUtil.ToggleVisibility(btnImport);
            WPFUtil.ToggleVisibility(btnCancel);

            btnDelete.IsEnabled = !btnDelete.IsEnabled;
        }
Beispiel #8
0
        void client_CommandReceived(object sender, EvaluationEventArgs e)
        {
            if (e.Command != EvaluationCommand.Value)
            {
                return;
            }

            WPFUtil.UIProcess(() => ServerPoint = e.Value);
        }
Beispiel #9
0
 /// <summary>
 /// 使用可能なクッキーのリストをクリアします。
 /// </summary>
 private void ClearAvailableCookieList()
 {
     // ObservableCollectionを使っているため、
     // 処理はUIスレッド上で行います。
     WPFUtil.UIProcess(() =>
     {
         AvailableCookieData = null;
         this.availableCookieList.Clear();
     });
 }
Beispiel #10
0
        private void AssociatedObject_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var o        = Mouse.DirectlyOver as DependencyObject;
            var menuItem = WPFUtil.FindParent <MenuItem>(o);

            if (menuItem != null)
            {
                AssociatedObject.Hide();
            }
        }
Beispiel #11
0
 /// <summary>
 /// コマンドを実行します。
 /// </summary>
 public void Execute()
 {
     try
     {
         this.execute();
     }
     finally
     {
         WPFUtil.InvalidateCommand();
     }
 }
Beispiel #12
0
 private void AssociatedObject_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed)
     {
         var parent = WPFUtil.FindLogicalAncestor(AssociatedObject);
         if (parent != null && parent is MenuItem mi)
         {
             mi.IsSubmenuOpen = false;
         }
     }
 }
Beispiel #13
0
        static void OnEditModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var self = (ShogiUIElement3D)d;

            if (self != null)
            {
                self.UpdateEditMode();

                WPFUtil.InvalidateCommand();
            }
        }
Beispiel #14
0
        /// <summary>
        /// Stoppedイベントを発行します。
        /// </summary>
        private void RaiseStopped()
        {
            var handler = Interlocked.Exchange(ref Stopped, null);

            if (handler != null)
            {
                Util.SafeCall(() =>
                              handler(this, EventArgs.Empty));
            }

            WPFUtil.InvalidateCommand();
        }
Beispiel #15
0
 /// <summary>
 /// コマンドを実行します。
 /// </summary>
 public void Execute(object parameter = null)
 {
     try
     {
         var e = new ExecuteRelayEventArgs(this, parameter);
         this.execute(this, e);
     }
     finally
     {
         WPFUtil.InvalidateCommand();
     }
 }
Beispiel #16
0
        /// <summary>
        /// 移動中の駒を動かします。
        /// </summary>
        private void MovePiece(MouseEventArgs e)
        {
            if (this.movingPiece == null)
            {
                return;
            }

            // 駒とマウスの位置の差を求めておきます。
            var mousePos = InvarseTranslate(e.GetPosition(this));

            this.movingPiece.Coord = WPFUtil.MakeVector3D(mousePos, MovingPieceZ);
        }
        /// <summary>
        /// 新しいログを出力
        /// </summary>
        public void AddLog(string logMessage)
        {
            WPFUtil.UIProcess(() =>
            {
                var control = Log.FindTarget <TextBoxBase>(ControlName);
                if (control == null)
                {
                    return;
                }

                control.AppendText(logMessage + Environment.NewLine);
            });
        }
Beispiel #18
0
        private void CurrentEvaluationValueChanged()
        {
            WPFUtil.UIProcess(() =>
            {
                var shogi = Global.ShogiControl;
                if (shogi == null || shogi.AutoPlayState == AutoPlayState.Playing)
                {
                    return;
                }

                EvaluationValue = CurrentEvaluationValue;
            });
        }
Beispiel #19
0
        /// <summary>
        /// 現局面の指し手を進めます。
        /// </summary>
        public void DoMove(BoardMove bmove, int seconds)
        {
            var prevCurrentBoard = CurrentBoard.Clone();

            // 符号は設定されていないことがあります。
            //csaMove.Side = CurrentBoard.Turn;

            /*var bmove = CurrentBoard.ConvertCsaMove(csaMove);
             * if (bmove == null || !bmove.Validate())
             * {
             *  Log.Error("{0}手目 {1}を変換できませんでした。",
             *      CurrentBoard.MoveCount,
             *      csaMove.ToPersonalString());
             *  return;
             * }*/

            if (!CurrentBoard.DoMove(bmove))
            {
                Log.Error("{0}手目 {1}を指せませんでした。",
                          CurrentBoard.MoveCount, bmove);
                return;
            }

            // 手番側の残り時間を減らしたのち、手番を入れ替えます。
            DecBaseLeaveTime(CurrentTurn, seconds);

            InitBoard(CurrentBoard, false, false);

            WPFUtil.UIProcess(() =>
            {
                // 実際に指した手と一致する変化は残します。
                var list = VariationList
                           .Where(_ => _.MoveList.Count() >= 2)
                           .Where(_ => bmove.Equals(_.MoveList[0]))
                           .Select(_ =>
                                   new VariationInfo
                {
                    IsShowed  = false,
                    MoveList  = _.MoveList.Skip(1).ToList(),
                    Value     = _.Value,
                    NodeCount = _.NodeCount,
                })
                           .ToList();

                VariationList.Clear();
                list.ForEach(_ => VariationList.Add(_));

                // 指し手の再生を行います。
                AddDoMoveAutoPlay(prevCurrentBoard, bmove);
            });
        }
Beispiel #20
0
        /// <summary>
        /// 新しい変化を追加します。
        /// </summary>
        public void AddVariation(VariationInfo variation)
        {
            if (variation == null || variation.MoveList == null)
            {
                return;
            }

            /*if (variation.MoveList.Count() < 9)
             * {
             *  return;
             * }*/

            WPFUtil.UIProcess(() =>
            {
                // 先後の符号は省略されていることがあります。
                SetMoveColor(variation);

                // 同じ変化があれば登録しません。
                var result = VariationList.FirstOrDefault(
                    _ => variation.MoveList.SequenceEqual(_.MoveList));
                if (result != null)
                {
                    result.Value = Math.Max(result.Value, variation.Value);
                    return;
                }

                // 変化はノード数順+評価値順に並べます。
                // ObservableCollectionはソートがやりにくいので、
                // 挿入ソートを使います。
                var comparer = new Func <VariationInfo, VariationInfo, bool>((x, y) =>
                                                                             (x.NodeCount > y.NodeCount) ||
                                                                             (x.NodeCount == y.NodeCount && x.Value > y.Value));
                var inserted = false;
                for (var i = 0; i < VariationList.Count(); ++i)
                {
                    if (comparer(variation, VariationList[i]))
                    {
                        VariationList.Insert(i, variation);
                        inserted = true;
                        break;
                    }
                }

                if (!inserted)
                {
                    VariationList.Add(variation);
                }
            });
        }
Beispiel #21
0
        /// <summary>
        /// ボナンザログに出力します。
        /// </summary>
        public void AppendBonanzaLog(string log, bool?isOutput)
        {
            if (string.IsNullOrEmpty(log))
            {
                return;
            }

            WPFUtil.UIProcess(() =>
            {
                using (LazyLock())
                {
                    var logLine = new LogLine(log, isOutput);

                    this.logList.Add(logLine);
                }
            });
        }
Beispiel #22
0
        /*private List<Tuple<IAnimatable, DependencyProperty>> animatedPropertyList =
         *  new List<Tuple<IAnimatable, DependencyProperty>>();*/

        /// <summary>
        /// アニメーションを開始します。
        /// </summary>
        public void Begin(Animatable target)
        {
            foreach (var anim in Children)
            {
                if (anim == null)
                {
                    continue;
                }

                var animTarget = GetTarget(anim);
                if (animTarget == null)
                {
                    animTarget = target;

                    var targetPath = GetTargetPath(anim);
                    if (!string.IsNullOrEmpty(targetPath))
                    {
                        var targetProperty = WPFUtil.GetDependencyProperty(
                            target.GetType(),
                            targetPath);

                        if (targetProperty != null)
                        {
                            var t = target.GetValue(targetProperty) as Animatable;
                            if (t != null)
                            {
                                animTarget = t;
                            }
                        }
                    }
                }

                var property = WPFUtil.GetDependencyProperty(
                    animTarget.GetType(),
                    GetTargetProperty(anim));

                if (property != null)
                {
                    animTarget.BeginAnimation(property, anim);
                }

                /*this.animatedPropertyList.Add(
                 *  Tuple.Create(animTarget, property));*/
            }
        }
Beispiel #23
0
        /// <summary>
        /// 静的コンストラクタ。
        /// </summary>
        static Global()
        {
            if (WPFUtil.IsInDesignMode)
            {
                return;
            }

            WPFUtil.Init();

            Settings      = Settings.CreateSettings <Settings>();
            MainViewModel = new MainViewModel();
            Updater       = new PresentationUpdater(
                "http://garnet-alice.net/programs/bonako-dfpn/update/versioninfo.xml");

            // 詰将棋用のボナンザを起動します。
            ResetBonanza(null);

            Updater.Start();
        }
        /// <summary>
        /// 色のアルファ値を変更します。
        /// </summary>
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            try
            {
                var alpha = (int)parameter;
                var color = (Color)value;

                return(WPFUtil.MakeColor((byte)alpha, color));
            }
            catch (InvalidCastException ex)
            {
                Log.ErrorException(ex,
                                   "ColorAlphaConverter: " +
                                   "Colorに変換できませんでした。");

                return(Colors.Black);
            }
        }
Beispiel #25
0
        /// <summary>
        /// エフェクトのアニメーション画像の位置などを修正します。
        /// </summary>
        private void UpdateImage()
        {
            var brush = this.brush as ImageBrush;

            if (brush == null || string.IsNullOrEmpty(ImageUri))
            {
                return;
            }

            var imageList = EffectImageCache.GetImageList(
                MakeContentUri(ImageUri),
                AnimationImageCount);

            if (imageList == null)
            {
                return;
            }

            var oldImage = brush.ImageSource;
            var newImage = imageList[AnimationImageIndex % imageList.Count()];

            // 必要ならメッシュの更新を行います。
            if (AutoUpdateMesh)
            {
                if (newImage != null)
                {
                    if (oldImage == null ||
                        oldImage.Width != newImage.Width ||
                        oldImage.Height != newImage.Height)
                    {
                        Mesh = WPFUtil.CreateDefaultMesh(
                            1.0, 1.0, newImage.Width, newImage.Height);
                    }
                }
                else
                {
                    Mesh = null;
                }
            }

            brush.ImageSource = newImage;
        }
Beispiel #26
0
        /// <summary>
        /// 盤などのサイズを設定します。
        /// </summary>
        private void InitializeBounds(Rect3D banBounds, Rect3D komaboxBounds,
                                      Rect3D komadai0Bounds, Rect3D komadai1Bounds)
        {
            // 駒の表示サイズを設定
            CellSize = new Size(
                banBounds.SizeX / (Board.BoardSize + BanBorderRate * 2),
                banBounds.SizeY / (Board.BoardSize + BanBorderRate * 2));

            // 盤サイズの設定
            BanBounds = new Rect(
                banBounds.X + CellSize.Width * BanBorderRate,
                banBounds.Y + CellSize.Height * BanBorderRate,
                CellSize.Width * Board.BoardSize,
                CellSize.Height * Board.BoardSize);

            // index=0が駒箱の駒となります。
            this.capturedPieceBoxBounds[0] = WPFUtil.MakeRectXY(komaboxBounds);
            this.capturedPieceBoxBounds[1] = WPFUtil.MakeRectXY(komadai0Bounds);
            this.capturedPieceBoxBounds[2] = WPFUtil.MakeRectXY(komadai1Bounds);
        }
Beispiel #27
0
        /// <summary>
        /// 操作完了時に呼ばれます。
        /// </summary>
        private void TaskCompleted(Task state)
        {
            WPFUtil.UIProcess(
                () =>
            {
                if (this.task.Exception != null)
                {
                    IsFaulted = true;
                    Exception = this.task.Exception;

                    Log.ErrorException(
                        Exception,
                        "Taskが途中で失敗しました。");
                }

                RaiseCompletedEvent();

                // ダイアログは自動で閉じます。
                Close();
            });
        }
Beispiel #28
0
        /// <summary>
        /// 成るか不成りかダイアログによる選択を行います。
        /// </summary>
        private bool CheckToPromote(PieceType pieceType, BWType bwType)
        {
            var dialog = DialogUtil.CreateDialog(
                null,
                "成りますか?",
                "成り/不成り",
                MessageBoxButton.YesNo,
                MessageBoxResult.Yes);

            dialog.Topmost = true;

            dialog.Loaded += (sender, e) =>
            {
                var p         = WPFUtil.GetMousePosition(dialog);
                var screenPos = dialog.PointToScreen(p);

                dialog.WindowStartupLocation = WindowStartupLocation.Manual;
                dialog.Left = screenPos.X - (dialog.ActualWidth / 2);
                dialog.Top  = screenPos.Y + CellSize.Height / 2;
                dialog.AdjustInDisplay();
            };

            try
            {
                ClosePromoteDialog();

                // 成り・不成り選択中に外から局面が設定されることがあります。
                // その場合に備えてダイアログ自体を持っておきます。
                this.promoteDialog = dialog;

                var result = dialog.ShowDialog();
                ClosePromoteDialog();

                return(result != null ? result.Value : false);
            }
            finally
            {
                ClosePromoteDialog();
            }
        }
Beispiel #29
0
        /// <summary>
        /// パスなどを初期化します。
        /// </summary>
        public static void Initialize(Assembly asm, string dataDir)
        {
            WPFUtil.Init();

            // パーティクルシステムの想定画面サイズを設定。
            FlintSharp.Utils.ScreenSize = new Size(640, 360);

            // 画像のローダーを設定。
            FlintSharp.Utils.ImageLoader = new WPFImageLoader();

            var uri = new Uri(
                new Uri(asm.Location),
                dataDir + "/xxx");

            EffectInfo.BaseDir = uri;

            var sm = EffectObject.SoundManager;

            sm.DefaultPath  = Path.GetDirectoryName(uri.LocalPath);
            sm.PlayInterval = TimeSpan.FromSeconds(0.5);
            sm.Volume       = 50;
        }
Beispiel #30
0
        private void OnTrySave(object sender, TrySaveOccuredEventArgs e)
        {
            // 一旦フォーカスを外します。
            var prevFocus = FocusManager.GetFocusedElement(_view);

            FocusManager.SetFocusedElement(_view, _view);

            // 溜まってるイベントは全部処理させる
            WPFUtil.DoEvents();

            _writersBattleFieldViewModel.SetTextToModelsComposite();
            if (e.SaveKind == SaveKind.SaveWithName)
            {
                _fileService.SaveFileWithName();
            }
            else
            {
                _fileService.SaveFile();
            }

            FocusManager.SetFocusedElement(_view, prevFocus);
        }