Exemple #1
0
        private void ChangeQuizSelection(TreeNode selectedNode)
        {
            try
            {
                var nodeType = selectedNode.Tag.GetType();
                if (nodeType == typeof(OpeningMove))
                {
                    var move = (OpeningMove)selectedNode.Tag;
                    move.Selected = selectedNode.Checked;
                    if (selectedNode.Checked)
                    {
                        //  Select all parent nodes
                        var parentNode = selectedNode.Parent;
                        if (parentNode != null && parentNode.Tag.GetType() == typeof(OpeningMove))
                        {
                            parentNode.Checked = true;
                        }
                    }
                    else
                    {
                        //  Unselect all children nodes
                        if (selectedNode.Nodes.Count > 0)
                        {
                            foreach (TreeNode childNode in selectedNode.Nodes)
                            {
                                childNode.Checked = false;
                            }
                        }
                    }
                }
                else if (nodeType == typeof(OpeningRepertoire))
                {
                    var repertoire = (OpeningRepertoire)selectedNode.Tag;
                    repertoire.Selected = selectedNode.Checked;
                    _updatingSelection  = true;
                    ChangeAllChildNodesSelection(selectedNode, selectedNode.Checked);
                    _updatingSelection = false;
                }
                else if (nodeType == typeof(OpeningBook))
                {
                    var blackRepertoire = (OpeningRepertoire)_blackRepertoireNode.Tag;
                    var whiteRepertoire = (OpeningRepertoire)_whiteRepertoireNode.Tag;
                    blackRepertoire.Selected = selectedNode.Checked;
                    whiteRepertoire.Selected = selectedNode.Checked;

                    _updatingSelection           = true;
                    _whiteRepertoireNode.Checked = selectedNode.Checked;
                    _blackRepertoireNode.Checked = selectedNode.Checked;
                    ChangeAllChildNodesSelection(_whiteRepertoireNode, selectedNode.Checked);
                    ChangeAllChildNodesSelection(_blackRepertoireNode, selectedNode.Checked);
                    _updatingSelection = false;
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            TrvRepertoires.SelectedNode = selectedNode;
            TrvRepertoires.Focus();
        }
Exemple #2
0
        private void NodeSelected(TreeNode clickedNode)
        {
            TrvRepertoires.SelectedNode = clickedNode;
            var nodeType = clickedNode.Tag.GetType();

            if (nodeType == typeof(OpeningBook))
            {
                chessboard1.SetupInitialPosition();
                chessboard1.Enabled = false;
                chessOpeningInfo1.Clear();
                chessOpeningInfo1.Enabled = false;
                SelectedRepertoire        = null;
            }
            else
            if (nodeType == typeof(OpeningRepertoire))
            {
                chessboard1.SetupInitialPosition();
                chessboard1.Enabled = true;
                chessOpeningInfo1.Clear();
                chessOpeningInfo1.Enabled  = false;
                SelectedRepertoire         = (OpeningRepertoire)clickedNode.Tag;
                chessboard1.BoardDirection = SelectedRepertoire.Color == ChessColor.White ? BoardDirection.BlackOnTop : BoardDirection.WhiteOnTop;
            }
            else
            if (nodeType == typeof(OpeningMove))
            {
                SelectedRepertoire  = GetParentRepertoire(TrvRepertoires.SelectedNode);
                chessboard1.Enabled = true;
                var selectedMove = (OpeningMove)clickedNode.Tag;
                chessboard1.LoadFEN(selectedMove.FenPosition);
                ShowOpeningInfo(selectedMove);
                chessOpeningInfo1.Enabled  = true;
                chessboard1.BoardDirection = SelectedRepertoire.Color == ChessColor.White ? BoardDirection.BlackOnTop : BoardDirection.WhiteOnTop;
            }

            TrvRepertoires.Focus();
        }