예제 #1
0
        //Tree view delete click event
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (componentsTree.SelectedNode.Parent != null)
            {
                int id = int.Parse(componentsTree.SelectedNode.Name);
                switch (componentsTree.SelectedNode.Parent.Text)
                {
                case "Sprites":
                    //Deletes the given sprite
                    Sprites.Delete(id);
                    break;

                case "Objects":
                    //Deletes the given object
                    Objects.Delete(id);
                    break;

                case "UIs":
                    //Deletes the given UI
                    UIs.Delete(id);
                    break;

                case "Rooms":
                    //Deletes the given room
                    Rooms.Delete(id);
                    break;

                case "Scripts":
                    //Deletes the given user-defined function
                    Scripts.Delete(id);
                    break;

                case "Sounds":
                    //Deletes the given sound
                    Sounds.Delete(id);
                    break;
                }
                componentsTree.SelectedNode.Remove();
                FileManager.UnsavedChanges = true;
            }
        }
예제 #2
0
        //A tree node double click event
        private void componentsTree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Parent != null)
            {
                switch (e.Node.Parent.Text)
                {
                case "Sprites":
                    //Opens the Sprite Form and loads it with the given sprite data
                    using (var form = new SpriteForm())
                    {
                        form.Text = "Properties of " + e.Node.Text;
                        form.SetNameBoxText(e.Node.Text);
                        form.id = int.Parse(e.Node.Name);
                        form.SetPathBoxText(Sprites.sprites[int.Parse(e.Node.Name)].path);
                        var result = form.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            //Updates the data of the given sprite
                            Sprites.SetName(int.Parse(e.Node.Name), form.GetNameBoxText());
                            if (!string.IsNullOrWhiteSpace(form.path[0]))
                            {
                                DirectoryInfo _dir = new DirectoryInfo(form.path[0]);
                                if (!string.IsNullOrWhiteSpace(_dir.Parent.ToString()) && _dir.Parent.ToString() != "IMG")
                                {
                                    //Creates a new folder named "spr"+id(of the sprite) inside the resources directory and copies
                                    //every image into it, adding each path to the array of paths of the Sprites.sprites variable.
                                    Directory.CreateDirectory(GameConfig.path + @"\Resources\IMG\spr" + int.Parse(e.Node.Name));
                                    int           i         = 0;
                                    List <string> _tempPath = new List <string>();
                                    foreach (string _p in form.path)
                                    {
                                        string _path = @"Resources\IMG\spr" + int.Parse(e.Node.Name) + @"\" + i + Path.GetExtension(_p);
                                        try
                                        {
                                            File.Copy(_p, GameConfig.path + @"\" + _path, true);
                                        }
                                        catch { }
                                        i++;
                                        _tempPath.Add(_path);
                                    }
                                    Sprites.SetPath(int.Parse(e.Node.Name), _tempPath.ToArray <string>());
                                }
                            }
                            FileManager.UnsavedChanges = true;
                        }
                        form.Close();
                    }
                    break;

                case "Sounds":
                    //Opens the Sound Form and loads it with the given sprite data
                    using (var form = new SoundForm())
                    {
                        form.Text = "Properties of " + e.Node.Text;
                        form.SetNameBoxText(e.Node.Text);
                        form.id = int.Parse(e.Node.Name);
                        form.SetPathBoxText(Sounds.sounds[int.Parse(e.Node.Name)].path);
                        var result = form.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            //Updates the data of the given sound
                            Sounds.SetName(int.Parse(e.Node.Name), form.GetNameBoxText());
                            if (!string.IsNullOrWhiteSpace(form.path))
                            {
                                DirectoryInfo _dir = new DirectoryInfo(form.path);
                                if (!string.IsNullOrWhiteSpace(_dir.Parent.ToString()) && _dir.Parent.ToString() != "SND")
                                {
                                    //Copies the sound to the resources folder
                                    Directory.CreateDirectory(GameConfig.path + @"\Resources\SND");
                                    string _path = @"Resources\SND" + @"\snd" + form.id + Path.GetExtension(form.path);
                                    try
                                    {
                                        if (File.Exists(GameConfig.path + @"\" + _path))
                                        {
                                            File.Delete(GameConfig.path + @"\" + _path);
                                        }
                                        File.Copy(form.path, GameConfig.path + @"\" + _path, true);
                                    }
                                    catch { }
                                    Sounds.SetPath(int.Parse(e.Node.Name), _path);
                                }
                            }
                            FileManager.UnsavedChanges = true;
                        }
                        form.Close();
                    }
                    break;

                case "Rooms":
                    //Opens the Room Form and loads it with the given room data
                    using (var form = new RoomForm())
                    {
                        form.Text = "Properties of " + e.Node.Text;
                        form.SetNameBoxText(e.Node.Text);
                        Room room = Rooms.rooms[int.Parse(e.Node.Name)];
                        form.id = room.id;
                        form.SetFirstBox(int.Parse(e.Node.Name) == Rooms.firstId);
                        form.onCreate      = room.onCreate;
                        form.onUpdate      = room.onUpdate;
                        form.onDraw        = room.onDraw;
                        form.onKeyPressed  = room.onKeyPressed;
                        form.onKeyReleased = room.onKeyReleased;
                        form.editorCreate  = room.editorCreate;
                        var result = form.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            //Updates the data of the given room
                            Rooms.SetName(int.Parse(e.Node.Name), form.GetNameBoxText());
                            if (form.GetFirstBox())
                            {
                                Rooms.firstId = int.Parse(e.Node.Name);
                            }
                            room.onCreate      = form.onCreate;
                            room.onUpdate      = form.onUpdate;
                            room.onDraw        = form.onDraw;
                            room.onKeyPressed  = form.onKeyPressed;
                            room.onKeyReleased = form.onKeyReleased;
                            room.editorCreate  = form.editorCreate;
                            room.gravityX      = form.GravityX;
                            room.gravityY      = form.GravityY;
                            room.allowSleep    = form.AllowSleep;
                            if (!IDEConfig.IsDefaultEditor)
                            {
                                FileManager.ReloadCode();
                            }
                            FileManager.UnsavedChanges = true;
                        }
                        form.Close();
                    }
                    break;

                case "UIs":
                    //Opens the UI Form and loads it with the given UI data
                    using (var form = new UIForm())
                    {
                        form.Text = "Properties of " + e.Node.Text;
                        form.SetNameBoxText(e.Node.Text);
                        UI ui = UIs.uis[int.Parse(e.Node.Name)];
                        form.id = ui.id;
                        form.SetMovableBox(ui.movable);
                        form.onCreate      = ui.onCreate;
                        form.onUpdate      = ui.onUpdate;
                        form.onDraw        = ui.onDraw;
                        form.onKeyPressed  = ui.onKeyPressed;
                        form.onKeyReleased = ui.onKeyReleased;
                        form.onDestroy     = ui.onDestroy;
                        form.Components    = ui.components;
                        var result = form.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            //Updates the data of the given UI
                            UIs.SetName(int.Parse(e.Node.Name), form.GetNameBoxText());
                            ui.onCreate      = form.onCreate;
                            ui.onUpdate      = form.onUpdate;
                            ui.onDraw        = form.onDraw;
                            ui.onKeyPressed  = form.onKeyPressed;
                            ui.onKeyReleased = form.onKeyReleased;
                            ui.onDestroy     = form.onDestroy;
                            ui.components    = form.Components;
                            ui.movable       = form.GetMovableBox();
                            ui.align         = form.Alignment;
                            ui.x             = form.x;
                            ui.y             = form.y;
                            ui.width         = form.width;
                            ui.height        = form.height;
                            if (!IDEConfig.IsDefaultEditor)
                            {
                                FileManager.ReloadCode();
                            }
                            FileManager.UnsavedChanges = true;
                        }
                        form.Close();
                    }
                    break;

                case "Objects":
                    //Opens the Object Form and loads it with the given object data
                    using (var form = new ObjectForm())
                    {
                        form.Text = "Properties of " + e.Node.Text;
                        form.SetNameBoxText(e.Node.Text);
                        Object obj = Objects.objects[int.Parse(e.Node.Name)];
                        form.id = obj.id;
                        form.SetSpriteBox(obj.sprite);
                        form.SetAutoDrawBox(obj.autoDraw);
                        form.onCreate         = obj.onCreate;
                        form.onUpdate         = obj.onUpdate;
                        form.onDraw           = obj.onDraw;
                        form.onKeyPressed     = obj.onKeyPressed;
                        form.onKeyReleased    = obj.onKeyReleased;
                        form.onMousePressed   = obj.onMousePressed;
                        form.onMouseReleased  = obj.onMouseReleased;
                        form.onDestroy        = obj.onDestroy;
                        form.onCollisionEnter = obj.onCollisionEnter;
                        form.onCollisionExit  = obj.onCollisionExit;
                        var result = form.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            //Updates the data of the given object
                            Objects.SetName(int.Parse(e.Node.Name), form.GetNameBoxText());
                            obj.onCreate         = form.onCreate;
                            obj.onUpdate         = form.onUpdate;
                            obj.onDraw           = form.onDraw;
                            obj.onKeyPressed     = form.onKeyPressed;
                            obj.onKeyReleased    = form.onKeyReleased;
                            obj.onMousePressed   = form.onMousePressed;
                            obj.onMouseReleased  = form.onMouseReleased;
                            obj.onDestroy        = form.onDestroy;
                            obj.autoDraw         = form.GetAutoDrawBox();
                            obj.sprite           = form.GetSpriteBox();
                            obj.bodyType         = form.BodyType;
                            obj.usePhysics       = form.UsePhysics;
                            obj.lockRotation     = form.LockRotation;
                            obj.density          = form.Density;
                            obj.friction         = form.Friction;
                            obj.restitution      = form.Restitution;
                            obj.colliderType     = form.ColliderType;
                            obj.onCollisionEnter = form.onCollisionEnter;
                            obj.onCollisionExit  = form.onCollisionExit;
                            if (!IDEConfig.IsDefaultEditor)
                            {
                                FileManager.ReloadCode();
                            }
                            FileManager.UnsavedChanges = true;
                        }
                        form.Close();
                    }
                    break;

                case "Scripts":
                    //Opens the Script Form and loads it with the given script data
                    using (var form = new ScriptForm())
                    {
                        form.Text = "Properties of " + e.Node.Text;
                        form.SetNameBoxText(e.Node.Text);
                        form.id   = Scripts.scripts[int.Parse(e.Node.Name)].id;
                        form.data = Scripts.scripts[int.Parse(e.Node.Name)].data;
                        var result = form.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            //Updates the data of the given script
                            int    id     = int.Parse(e.Node.Name);
                            Script script = Scripts.scripts[id];
                            script.data = form.data;

                            //Updates the code with the new script name
                            string name = form.GetNameBoxText();
                            if (script.name != name)
                            {
                                if (!IDEConfig.IsDefaultEditor)
                                {
                                    string newData = FileManager.ReadSingle(script, null);
                                    if (newData != null)
                                    {
                                        script.data = newData;
                                    }
                                }
                                script.data = script.data.Replace(script.name, name);
                                FileManager.UpdateSingle(script, script.data, null);
                            }

                            Scripts.SetName(id, name);
                            if (!IDEConfig.IsDefaultEditor)
                            {
                                FileManager.ReloadCode();
                            }
                            FileManager.UnsavedChanges = true;
                        }
                        form.Close();
                    }
                    break;
                }
            }
        }