Exemplo n.º 1
0
        private void AddItem(ProjectItem parentFolder, ProjectItem folder, string[] existingNames)
        {
            m_treeView.AddChild(parentFolder, folder);

            if (existingNames.Length > 0)
            {
                int index = Array.IndexOf(existingNames.Union(new[] { folder.Name }).OrderBy(n => n).ToArray(), folder.Name);
                if (index > 0)
                {
                    m_treeView.SetNextSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index - 1), folder);
                }
                else
                {
                    m_treeView.SetPrevSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index + 1), folder);
                }
            }

            ProjectItem projectItem = parentFolder;

            Expand(parentFolder);
            m_treeView.ScrollIntoView(folder);
            m_treeView.SelectedItem = folder;

            VirtualizingTreeViewItem treeViewItem = m_treeView.GetTreeViewItem(folder);

            treeViewItem.IsEditing = true;
        }
Exemplo n.º 2
0
        private void CreateBrush(Texture2D texture)
        {
            Texture2D brushTexture = new Texture2D(texture.width + 2, texture.height + 2, TextureFormat.ARGB32, false);

            brushTexture.wrapMode = TextureWrapMode.Clamp;

            Color32[] pixels = brushTexture.GetPixels32();
            Color32   c      = new Color32(255, 255, 255, 0);

            for (int i = 0; i < pixels.Length; ++i)
            {
                pixels[i] = c;
            }
            brushTexture.SetPixels32(pixels);

            Graphics.CopyTexture(texture, 0, 0, 0, 0, texture.width, texture.height, brushTexture, 0, 0, 1, 1);

            pixels = brushTexture.GetPixels32();
            for (int i = 0; i < pixels.Length; ++i)
            {
                byte a = pixels[i].a;
                pixels[i] = new Color32(255, 255, 255, a);
            }
            brushTexture.SetPixels32(pixels);
            brushTexture.Apply();

            Sprite sprite = Sprite.Create(brushTexture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));

            m_source.UserBrushes.Add(sprite);
            m_brushesList.Add(sprite);
            m_brushesList.SelectedItem = sprite;
            m_brushesList.ScrollIntoView(sprite);
        }
        protected virtual void AddItem(ProjectItem parentFolder, ProjectItem folder, string[] existingNames, bool select, bool expand)
        {
            m_treeView.AddChild(parentFolder, folder);

            if (existingNames.Length > 0)
            {
                int index = Array.IndexOf(existingNames.Union(new[] { folder.Name }).OrderBy(n => n).ToArray(), folder.Name);
                if (index > 0)
                {
                    m_treeView.SetNextSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index - 1), folder);
                }
                else
                {
                    m_treeView.SetPrevSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index + 1), folder);
                }
            }

            if (expand)
            {
                ProjectItem projectItem = parentFolder;
                Expand(parentFolder);
            }

            if (select)
            {
                if (m_treeView.GetTreeViewItem(folder) != null)
                {
                    m_treeView.ScrollIntoView(folder);
                }
                m_treeView.SelectedItem = folder;
            }
        }
Exemplo n.º 4
0
        public virtual void InsertItems(ProjectItem[] items, bool selectAndScrollIntoView)
        {
            if (m_folders == null)
            {
                return;
            }

            items = items.Where(item => m_folders.Contains(item.Parent) && CanDisplayItem(item)).ToArray();
            if (items.Length == 0)
            {
                return;
            }

            m_items = m_items.Union(items).ToList();
            List <ProjectItem> sorted     = m_items.Where(item => item.IsFolder).OrderBy(item => item.Name).Union(m_items.Where(item => !item.IsFolder).OrderBy(item => item.Name)).ToList();
            ProjectItem        selectItem = null;

            for (int i = 0; i < sorted.Count; ++i)
            {
                if (items.Contains(sorted[i]))
                {
                    m_listBox.Insert(i, sorted[i]);
                    selectItem = sorted[i];
                }
                else
                {
                    VirtualizingItemContainer itemContainer = m_listBox.GetItemContainer(sorted[i]);
                    if (itemContainer != null)
                    {
                        m_listBox.DataBindItem(sorted[i], itemContainer);
                    }
                }

                if (!m_idToItem.ContainsKey(sorted[i].ItemID))
                {
                    m_idToItem.Add(sorted[i].ItemID, sorted[i]);
                }
            }
            m_items = sorted;

            if (selectItem != null)
            {
                if (selectAndScrollIntoView)
                {
                    m_listBox.SelectedItem = selectItem;
                    m_listBox.ScrollIntoView(selectItem);
                }
            }
        }
Exemplo n.º 5
0
        private void OnCreateProjectClick()
        {
            InputDialog input = Instantiate(m_inputDialogPrefab);

            input.transform.position = Vector3.zero;

            m_windowManager.Dialog(m_localization.GetString("ID_RTEditor_ProjectsDialog_CreateProject", "Create Project"), input.transform,
                                   (sender, args) =>
            {
                string projectName = input.Text;
                if (string.IsNullOrEmpty(projectName))
                {
                    args.Cancel = true;
                    return;
                }

                if (m_treeView.Items != null && m_treeView.Items.OfType <ProjectInfo>().Any(p => p.Name == projectName))
                {
                    m_windowManager.MessageBox(
                        m_localization.GetString("ID_RTEditor_ProjectsDialog_UnableToCreateProject", "Unable to create project"),
                        m_localization.GetString("ID_RTEditor_ProjectsDialog_ProjectWithSameNameExists", "Project with the same name already exists"));
                    args.Cancel = true;
                    return;
                }

                Editor.IsBusy = true;
                m_project.CreateProject(projectName, (error, newProjectInfo) =>
                {
                    Editor.IsBusy = false;
                    if (error.HasError)
                    {
                        m_windowManager.MessageBox(m_localization.GetString("ID_RTEditor_ProjectsDialog_UnableToCreateProject", "Unable to create project"), error.ErrorText);
                        args.Cancel = true;
                        return;
                    }

                    m_treeView.SelectedItem   = null;
                    ProjectInfo[] projectInfo = m_treeView.Items.OfType <ProjectInfo>().Union(new[] { newProjectInfo }).OrderBy(p => p.Name).ToArray();
                    m_treeView.Insert(Array.IndexOf(projectInfo, newProjectInfo), newProjectInfo);
                    m_treeView.SelectedItem = newProjectInfo;
                    m_treeView.ScrollIntoView(newProjectInfo);
                });
            },
                                   (sender, args) => { },
                                   m_localization.GetString("ID_RTEditor_ProjectsDialog_Btn_Create", "Create"),
                                   m_localization.GetString("ID_RTEditor_ProjectsDialog_Btn_Cancel", "Cancel"),
                                   120, 100, 350, 100);
        }