Пример #1
0
        private void cmsi_AddEntity_Click(object sender, EventArgs e)
        {
            if (sceneTree.Nodes.Count == 0)
            {
                return;
            }
            var parentNode = sceneTree.SelectedNode;

            if (parentNode == null)
            {
                parentNode = sceneTree.Nodes[0];
            }
            AddEntitywindow addEntitywindow = new AddEntitywindow();

            addEntitywindow.Location      = Cursor.Position;
            addEntitywindow.StartPosition = FormStartPosition.Manual;

            var r = addEntitywindow.ShowDialog();

            if (r == DialogResult.OK)
            {
                var parentEnt = (UInt32)parentNode.Tag;
                if (!wrapper.managers.sceneManager.IsRegistered(parentEnt))
                {
                    var conR = MessageBox.Show("Entity must be a scene. Convert to scene?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                    if (conR == DialogResult.No)
                    {
                        return;
                    }
                }

                var ent = wrapper.managers.entityManager.Create();
                wrapper.managers.sceneManager.AddEntityToScene(parentEnt, ent, addEntitywindow.name);
                TreeNode node = new TreeNode();
                node.Text = addEntitywindow.name;
                node.Name = addEntitywindow.name;
                node.Tag  = ent;
                parentNode.Nodes.Add(node);
                parentNode.Expand();

                sceneTree.SelectedNode = node;
            }
        }
Пример #2
0
        private void cmsi_New_Click(object sender, EventArgs e)
        {
            AddEntitywindow addSceneWindow = new AddEntitywindow();

            addSceneWindow.Location      = Cursor.Position;
            addSceneWindow.StartPosition = FormStartPosition.Manual;
            var  parentNode = scenesTree.SelectedNode;
            var  r          = addSceneWindow.ShowDialog();
            var  name       = addSceneWindow.name;
            bool rename     = false;
            bool found      = false;

            if (r == DialogResult.OK)
            {
                TreeNode node   = new TreeNode();
                var      findIn = scenesTree.Nodes.Find(addSceneWindow.name, true);
                if (findIn.Length > 0)
                {
                    var findinR = MessageBox.Show("A scene with this name already exists. Yes, use existing scene. No, rename the scene", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                    if (findinR == DialogResult.Cancel)
                    {
                        return;
                    }
                    if (findinR == DialogResult.No)
                    {
                        int count = 0;

                        while (!rename)
                        {
                            if (scenesTree.Nodes.Find(name + "_" + count.ToString(), true).Length == 0)
                            {
                                name  += "_" + count.ToString();
                                rename = true;
                            }
                            count++;
                        }
                    }
                    else if (findinR == DialogResult.Yes)
                    {
                        node  = findIn[0];
                        found = true;
                    }
                }
                if (!found)
                {
                    var ent = wrapper.managers.entityManager.Create();
                    wrapper.managers.sceneManager.Create(ent, name);
                    wrapper.managers.sceneManager.WriteComponent(wrapper.binaryLoader, ent, name);
                    LoaderFile newFile;
                    wrapper.managers.entityManager.DestroyNow(ent);
                    var rr = wrapper.binaryLoader.GetFile(out newFile, name, "Scene");
                    if (rr.IsError())
                    {
                        rr.ShowError(MessageBoxButtons.OK, MessageBoxIcon.Warning, "File: " + name);
                        return;
                    }

                    node.Tag  = newFile;
                    node.Text = name;
                    node.Name = name;

                    for (int i = 0; i < deletedScenes.Count; i++)
                    {
                        if (deletedScenes[i].guid_str == node.Name)
                        {
                            deletedScenes.RemoveAt(i);
                            break;
                        }
                    }
                }


                if (parentNode == null)
                {
                    scenesTree.Nodes.Add(node);
                }
                else
                {
                    node = AddSceneNodeToScene(parentNode, node);
                }

                scenesTree.SelectedNode = node;
                if (parentNode != null)
                {
                    parentNode.Expand();
                }
                if (rename)
                {
                    scenesTree.LabelEdit = true;
                    scenesTree.SelectedNode.BeginEdit();
                }
                else
                {
                    wrapper.Changed(Utilities.ChangeType.ENTITY | Utilities.ChangeType.FILE);
                }
            }
        }