Exemple #1
0
        public void SaveLayout(string layoutName, string treeId, SubWindowNode node)
        {
            if (string.IsNullOrEmpty(layoutName))
            {
                return;
            }
            if (string.IsNullOrEmpty(treeId))
            {
                return;
            }
            XmlDocument doc = new XmlDocument();

            XmlElement root = doc.CreateElement("SubWindowTree");

            root.SetAttribute("Layout", layoutName);
            root.SetAttribute("TreeID", treeId.GetHashCode().ToString());

            doc.AppendChild(root);

            if (node != null)
            {
                node.WriteToLayoutCfg(root, doc, 0);
            }
            bool   isCurrent = layoutName == "Current";
            string path      = GetLayoutCfgsPath(isCurrent);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            doc.Save(path + "/" + layoutName + ".xml");
            LoadLayoutCfgs();
        }
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="node"></param>
        /// <param name="index"></param>
        public virtual void Insert(SubWindowNode node, int index)
        {
            if (this.m_Childs.Count == 0)
            {
                node.weight       = 1;
                node.depth        = depth + 1;
                node.isHorizontal = !isHorizontal;
                this.m_Childs.Add(node);
                return;
            }
            float w  = 1.0f / (this.m_Childs.Count + 1);
            float ew = w / this.m_Childs.Count;

            node.weight       = w;
            node.depth        = depth + 1;
            node.isHorizontal = !isHorizontal;
            for (int i = 0; i < this.m_Childs.Count; i++)
            {
                this.m_Childs[i].weight -= ew;
            }
            if (index < 0 || index >= m_Childs.Count)
            {
                m_Childs.Add(node);
            }
            else
            {
                m_Childs.Insert(index, node);
            }
        }
 /// <summary>
 /// 插入子窗口
 /// </summary>
 /// <param name="window"></param>
 private void InsertWindow(SubWindow window)
 {
     window.AddCloseEventListener(this.m_OnSubWindowClose);
     if (this.m_Root == null)
     {
         this.m_Root = new SubWindowNode(true, 0);
     }
     this.m_Root.AddWindow(window, 0);
 }
        public static void CreateWizard(SubWindowLayout layout, string treeId, SubWindowNode rootNode)
        {
            SubWindowTreeLayoutWizard wizard =
                ScriptableWizard.DisplayWizard <SubWindowTreeLayoutWizard>("Save SubWindow Layout", "Save");

            wizard.maxSize    = new Vector2(300, 150);
            wizard.minSize    = new Vector2(300, 150);
            wizard.m_Layout   = layout;
            wizard.m_TreeId   = treeId;
            wizard.m_RootNode = rootNode;
        }
 void OnWizardCreate()
 {
     if (layoutname == "Default")
     {
         if (!EditorUtility.DisplayDialog("警告", "确定覆盖默认布局?", "是", "否"))
         {
             return;
         }
     }
     if (m_Layout != null)
     {
         m_Layout.SaveLayout(layoutname, m_TreeId, m_RootNode);
     }
     m_Layout   = null;
     m_RootNode = null;
     m_TreeId   = null;
 }
Exemple #6
0
 void OnWizardCreate()
 {
     if (layoutname == "Default")
     {
         if (!EditorUtility.DisplayDialog("Warning", "Are you sure to override the default layout?", "Yes", "No"))
         {
             return;
         }
     }
     if (m_Layout != null)
     {
         m_Layout.SaveLayout(layoutname, m_TreeId, m_RootNode);
     }
     m_Layout   = null;
     m_RootNode = null;
     m_TreeId   = null;
 }
        private void DropWindow(SubWindow window, System.Action <SubWindow> preDropAction, System.Action postDropAction,
                                bool betweenChilds, int dropIndex)
        {
            if (window == null)
            {
                return;
            }
            if (preDropAction == null)
            {
                return;
            }
            if (betweenChilds)
            {
                if (preDropAction != null)
                {
                    preDropAction(window);
                    this.AddWindow(window, dropIndex);

                    postDropAction();
                }
            }
            else
            {
                if (preDropAction != null && dropIndex >= 0 && dropIndex < m_Childs.Count)
                {
                    SubWindowNode child = m_Childs[dropIndex];
                    if (child.ContainWindow(window))
                    {
                        return;
                    }
                    preDropAction(window);
                    m_Childs.RemoveAt(dropIndex);
                    SubWindowNode node = new SubWindowNode(!isHorizontal, depth + 1);
                    node.weight        = child.weight;
                    child.isHorizontal = isHorizontal;
                    child.depth        = node.depth + 1;
                    node.Insert(child, 0);

                    this.Insert(node, dropIndex);
                    node.AddWindow(window, -1);
                    postDropAction();
                }
            }
        }
        /// <summary>
        /// 从布局信息构造节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="windowList"></param>
        /// <param name="onWindowClose"></param>
        public virtual void CreateFromLayoutCfg(XmlElement node, List <SubWindow> windowList,
                                                System.Action <SubWindow> onWindowClose)
        {
            string weightStr     = node.GetAttribute("Weight");
            string depthStr      = node.GetAttribute("Depth");
            string horizontalStr = node.GetAttribute("Horizontal");

            weight       = float.Parse(weightStr);
            depth        = int.Parse(depthStr);
            isHorizontal = bool.Parse(horizontalStr);
            XmlNodeList nodes = node.ChildNodes;

            if (nodes.Count == 0)
            {
                return;
            }
            XmlElement[] sortnode = new XmlElement[nodes.Count];
            foreach (var n in nodes)
            {
                XmlElement nd       = (XmlElement)n;
                string     indexstr = nd.GetAttribute("Index");
                int        index    = int.Parse(indexstr);
                sortnode[index] = nd;
            }
            foreach (var n in sortnode)
            {
                if (n.Name == "SubWindowNode")
                {
                    SubWindowNode swnode = new SubWindowNode(true, 0);
                    swnode.CreateFromLayoutCfg(n, windowList, onWindowClose);
                    this.m_Childs.Add(swnode);
                }
                else if (n.Name == "SubWindowLeaf")
                {
                    SubWindowLeaf swleaf = new SubWindowLeaf(null, true, 0);
                    swleaf.CreateFromLayoutCfg(n, windowList, onWindowClose);
                    this.m_Childs.Add(swleaf);
                }
            }
        }
        private bool UseLayout(string layoutName)
        {
            if (string.IsNullOrEmpty(layoutName))
            {
                return(false);
            }
            string treeId = GetTreeIndentifier();

            if (string.IsNullOrEmpty(treeId))
            {
                return(false);
            }
            if (m_Layout == null)
            {
                return(false);
            }
            if (m_Root == null)
            {
                m_Root = new SubWindowNode(true, 0);
            }
            var element = m_Layout.UseLayout(layoutName, treeId);

            if (element == null)
            {
                return(false);
            }
            for (int i = 0; i < m_SubWindowList.Count; i++)
            {
                if (m_SubWindowList[i].IsOpen)
                {
                    m_SubWindowList[i].Close();
                }
            }

            m_Root.CreateFromLayoutCfg(element, m_SubWindowList, m_OnSubWindowClose);
            m_Root.ClearEmptyNode();
            m_Root.Recalculate(0, true);

            return(true);
        }
 public override void Insert(SubWindowNode node, int index)
 {
 }