Beispiel #1
0
 private void buttonOK_Click(object sender, EventArgs e)
 {
     TreeNode[] nodes = MainForm.Instance.treeView1.Nodes.Find(textBox1.Text, true);
     if (nodes.Length > 0)
     {
         MessageBox.Show("A layer or item with the name \"" + textBox1.Text + "\" already exists in the level. Please use another name!");
         return;
     }
     Layer l = new Layer(textBox1.Text);
     Editor.Instance.beginCommand("Add Layer \"" + l.Name + "\"");
     Editor.Instance.addLayer(l);
     Editor.Instance.endCommand();
     Editor.Instance.SelectedLayer = l;
     Editor.Instance.updatetreeview();
     this.Close();
 }
Beispiel #2
0
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            if (type == typeof(Level))
            {
                // Create the instance to deserialize into.
                Level level = new Level();

                level.CanvasColor = new Color(
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[1],
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[2],
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[3],
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[0]);
                Constants.Instance.ColorBackground = level.CanvasColor;
                level.Scale = (int)dictionary["Scale"];

                ArrayList spawnList = dictionary["PlayerSpawn"] as ArrayList;
                float spawnX = 0.0f;
                if (spawnList[0] is decimal)
                    spawnX = (float)(decimal)spawnList[0];
                if (spawnList[0] is int)
                    spawnX = (float)(int)spawnList[0];

                float spawnY = 0.0f;
                if (spawnList[1] is decimal)
                    spawnY = (float)(decimal)spawnList[1];
                if (spawnList[1] is int)
                    spawnY = (float)(int)spawnList[1];
                level.PlayerSpawn = new Vector2(spawnX, spawnY);

                level.Music = dictionary["Music"] as String;
                level.ContentRootFolder = dictionary["ContentRootFolder"] as String;

                // Deserialize the ListItemCollection's items.
                Dictionary<int, object> layersDict = new Dictionary<int, object>();
                ArrayList itemsList = (ArrayList)dictionary["Layers"];
                foreach (Dictionary<string, object> layerDict in itemsList)
                {

                    Layer layer = new Layer(layerDict["ID"] as String);
                    float scale = 1.0f;
                    if (layerDict["Scale"] is decimal)
                        scale = (float)(decimal)layerDict["Scale"];
                    if (layerDict["Scale"] is int)
                        scale = (float)(int)layerDict["Scale"];
                    layer.ScrollSpeed = new Microsoft.Xna.Framework.Vector2(1.0f/scale, 1.0f/scale);
                    layer.ZPos = (int)layerDict["Layer"];

                    level.Layers.Add(layer);

                    layersDict.Add((int)layerDict["Layer"], layer);
                //    level.Add(serializer.ConvertToType<ListItem>(itemsList[i]));
                }

                ArrayList objList = (ArrayList)dictionary["Objects"];
                foreach (Dictionary<string, object> groupDict in objList)
                {

                    ArrayList childList = (ArrayList)groupDict["Children"];
                    foreach (Dictionary<string, object> childDict in childList)
                    {

                        Vector2 position = new Vector2( 0.0f, 0.0f);
                        float rotation = 0.0f;

                        if (childDict.ContainsKey("Transform"))
                        {
                            Dictionary<string, object> transDict = childDict["Transform"] as Dictionary<string, object>;
                            ArrayList posList = transDict["Position"] as ArrayList;
                            float posX = 0.0f;
                            if (posList[0] is decimal)
                                posX = (float)(decimal)posList[0];
                            if (posList[0] is int)
                                posX = (float)(int)posList[0];

                            float posY = 0.0f;
                            if (posList[1] is decimal)
                                posY = (float)(decimal)posList[1];
                            if (posList[1] is int)
                                posY = (float)(int)posList[1];

                            position = new Vector2(posX * level.Scale, posY * level.Scale);
                            if (transDict["Rotation"] is decimal)
                                rotation = (float)(decimal)transDict["Rotation"];
                            if (transDict["Rotation"] is int)
                                rotation = (float)(int)transDict["Rotation"];
                        }

                        if (childDict.ContainsKey("Renderable"))
                        {
                            Dictionary<string, object> rendDict = childDict["Renderable"] as Dictionary<string, object>;
                            TextureItem item = new TextureItem(level.ContentRootFolder + '/' + rendDict["Image"] as String, position);
                            item.texture_filename = rendDict["Image"] as String;
                            item.Name = childDict["Name"] as String;
                            item.Rotation = rotation * MathHelper.Pi/180.0f;
                            item.TintColor = new Color(
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[3],
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[0],
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[1],
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[2]);

                            float xscale = 1.0f;
                            if (rendDict["xScale"] is decimal)
                                xscale = (float)(decimal)rendDict["xScale"];
                            if (rendDict["xScale"] is int)
                                xscale = (float)(int)rendDict["xScale"];

                            float yscale = 1.0f;
                            if (rendDict["yScale"] is decimal)
                                yscale = (float)(decimal)rendDict["yScale"];
                            if (rendDict["yScale"] is int)
                                yscale = (float)(int)rendDict["yScale"];

                            item.setScale(new Vector2(xscale, yscale));

                            //Game Specific components
                            if (childDict.ContainsKey("Planet"))
                            {
                                Dictionary<string, object> gravDict = childDict["Planet"] as Dictionary<string, object>;
                                double gravity = 0.0f;
                                if (gravDict["Gravity"] is decimal)
                                    gravity = (double)(decimal)gravDict["Gravity"];
                                if (gravDict["Gravity"] is int)
                                    gravity = (double)(int)gravDict["Gravity"];
                                item.CustomProperties.Add("Gravity", new CustomProperty("Gravity", gravity, typeof(double), ""));
                            }

                            (layersDict[(int)rendDict["Layer"]] as Layer).Items.Add( item );
                        }

                    }
                }

                //Engine draws things in reverse
                foreach (Layer layer in level.Layers)
                {
                    layer.Items.Reverse();
                }

                return level;
            }
            return null;
        }
Beispiel #3
0
 public void selectlayer(Layer l)
 {
     if (SelectedItems.Count > 0) selectitem(null);
     SelectedLayer = l;
     updatetreeviewselection();
     MainForm.Instance.propertyGrid1.SelectedObject = l;
 }
Beispiel #4
0
 public void selectitem(Item i)
 {
     if (AdesExtensions.allowSelect(i))
     {
         SelectedItems.Clear();
         if (i != null)
         {
             SelectedItems.Add(i);
             SelectedLayer = i.layer;
             updatetreeviewselection();
             MainForm.Instance.propertyGrid1.SelectedObject = i;
         }
         else
         {
             selectlayer(SelectedLayer);
         }
     }
 }
Beispiel #5
0
 public void moveSelectedItemsToLayer(Layer chosenlayer)
 {
     if (chosenlayer == SelectedLayer) return;
     beginCommand("Move Item(s) To Layer \"" + chosenlayer.Name + "\"");
     List<Item> selecteditemscopy = new List<Item>(SelectedItems);
     foreach (Item i in selecteditemscopy)
     {
         moveItemToLayer(i, chosenlayer, null);
     }
     endCommand();
     SelectedItems.Clear();
     updatetreeview();
 }
Beispiel #6
0
 public void moveLayerUp(Layer l)
 {
     int index = level.Layers.IndexOf(l);
     level.Layers[index] = level.Layers[index - 1];
     level.Layers[index - 1] = l;
     selectlayer(l);
 }
Beispiel #7
0
 public void moveItemToLayer(Item i1, Layer l2, Item i2)
 {
     int index2 = i2 == null ? 0 : l2.Items.IndexOf(i2);
     i1.layer.Items.Remove(i1);
     l2.Items.Insert(index2, i1);
     i1.layer = l2;
 }
Beispiel #8
0
        public void loadLevel(Level l)
        {
            AdesExtensions.dummyReference();
            /* DISABLED LEVEL-SPECIFIC CONTENT ROOT.
            if (l.ContentRootFolder == null)
            {
                l.ContentRootFolder = Constants.Instance.DefaultContentRootFolder;
                if (!Directory.Exists(l.ContentRootFolder))
                {
                    Forms.DialogResult dr = Forms.MessageBox.Show(
                        "The DefaultContentRootFolder \"" + l.ContentRootFolder + "\" (as set in the Settings Dialog) doesn't exist!\n"
                        + "The ContentRootFolder of the new level will be set to the Editor's work directory (" + Forms.Application.StartupPath + ").\n"
                        + "Please adjust the DefaultContentRootFolder in the Settings Dialog.\n"
                        + "Do you want to open the Settings Dialog now?", "Error",
                        Forms.MessageBoxButtons.YesNo, Forms.MessageBoxIcon.Exclamation);
                    if (dr == Forms.DialogResult.Yes) new SettingsForm().ShowDialog();
                    l.ContentRootFolder = Forms.Application.StartupPath;
                }
            }
            else
            {
                if (!Directory.Exists(l.ContentRootFolder))
                {
                    Forms.MessageBox.Show("The directory \"" + l.ContentRootFolder + "\" doesn't exist! "
                        + "Please adjust the XML file before trying again.");
                    return;
                }
            }
             */

            AdesExtensions.loadContentRoot(Constants.Instance.DefaultContentRootFolder);
            l.ContentRootFolder = Constants.Instance.DefaultContentRootFolder;

            AdesExtensions.addCustomPropertiesToLevel(l);

            TextureLoader.Instance.Clear();

            foreach (Layer layer in l.Layers)
            {
                layer.level = l;
                foreach (Item item in layer.Items)
                {
                    item.layer = layer;
                    if (!item.loadIntoEditor()) return;
                }
            }

            level = l;

            AdesExtensions.dummyReference();  //MainForm.Instance.loadfolder(level.ContentRootFolder);
            MainForm.Instance.loadfolder(Constants.Instance.DefaultContentRootFolder);

            if (level.Name == null) level.Name = "Level_01";

            SelectedLayer = null;
            if (level.Layers.Count > 0) SelectedLayer = level.Layers[0];
            SelectedItems.Clear();

            camera = new Camera(MainForm.Instance.pictureBox1.Width, MainForm.Instance.pictureBox1.Height);
            camera.Position = level.EditorRelated.CameraPosition;
            MainForm.Instance.zoomcombo.Text = "100%";
            undoBuffer.Clear();
            redoBuffer.Clear();
            MainForm.Instance.undoButton.DropDownItems.Clear();
            MainForm.Instance.redoButton.DropDownItems.Clear();
            MainForm.Instance.undoButton.Enabled = MainForm.Instance.undoMenuItem.Enabled = undoBuffer.Count > 0;
            MainForm.Instance.redoButton.Enabled = MainForm.Instance.redoMenuItem.Enabled = redoBuffer.Count > 0;
            commandInProgress = false;

            updatetreeview();
        }
Beispiel #9
0
 public void getSelectionFromLevel()
 {
     SelectedItems.Clear();
     SelectedLayer = null;
     string[] itemnames = level.selecteditems.Split(';');
     foreach (string itemname in itemnames)
     {
         if (itemname.Length>0) SelectedItems.Add(level.getItemByName(itemname));
     }
     SelectedLayer = level.getLayerByName(level.selectedlayers);
 }
Beispiel #10
0
 public void deleteLayer(Layer l)
 {
     if (level.Layers.Count > 0)
     {
         Editor.Instance.beginCommand("Delete Layer \"" + l.Name + "\"");
         level.Layers.Remove(l);
         Editor.Instance.endCommand();
     }
     if (level.Layers.Count > 0) SelectedLayer = level.Layers.Last();
     else SelectedLayer = null;
     selectitem(null);
     updatetreeview();
 }
Beispiel #11
0
 public void copySelectedItemsToLayer(Layer chosenlayer)
 {
     //if (chosenlayer == SelectedLayer) return;
     beginCommand("Copy Item(s) To Layer \"" + chosenlayer.Name + "\"");
     List<Item> selecteditemscopy = new List<Item>(SelectedItems);
     foreach (Item i in selecteditemscopy)
     {
         Item copy = i.clone();
         copy.layer = chosenlayer;
         copy.Name = MainForm.Instance.getUniqueNameBasedOn(copy.Name);
         addItem(copy);
     }
     endCommand();
     SelectedItems.Clear();
     updatetreeview();
 }
Beispiel #12
0
 public void addLayer(Layer l)
 {
     l.level = level;
     if (!l.level.Layers.Contains(l)) l.level.Layers.Add(l);
 }
 public void selectitem(Item i)
 {
     isLevelSelected = false;
     SelectedItems.Clear();
     if (i != null)
     {
         SelectedItems.Add(i);
         SelectedLayer = i.layer;
         updatetreeviewselection();
         MainForm.Instance.propertyGrid1.SelectedObject = i;
     }
     else
     {
         selectlayer(SelectedLayer);
     }
 }
Beispiel #14
0
 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (Editor.Instance.SelectedItems.Count == 0)
     {
         MessageBox.Show("select some items first");
         return;
     }
     Level l = new Level();
     l.ContentRootFolder = Editor.Instance.level.ContentRootFolder;
     l.Name = "exportLevel";
     Layer la = new Layer("exportLayer");
     l.Layers.Add(la);
     foreach (Item selitem in Editor.Instance.SelectedItems)
         la.Items.Add(selitem.clone());
     
     System.Windows.Forms.Clipboard.SetText(l.exportToString());
 }
Beispiel #15
0
 public void moveItemToLayer(MapObject i1, Layer l2, MapObject i2)
 {
     int index2 = i2 == null ? 0 : l2.MapObjects.IndexOf(i2);
     i1.layer.MapObjects.Remove(i1);
     l2.MapObjects.Insert(index2, i1);
     i1.layer = l2;
 }
Beispiel #16
0
        public void copySelectedItemsToLayer(Layer chosenlayer)
        {
            //if (chosenlayer == SelectedLayer) return;
            beginCommand("Copy MapObject(s) To Layer \"" + chosenlayer.Name + "\"");
            List<MapObject> selecteditemscopy = new List<MapObject>(SelectedItems);
            foreach (MapObject i in selecteditemscopy)
            {
                MapObject copy = i.clone();
                copy.layer = chosenlayer;
                copy.Name = MainForm.Instance.getUniqueNameBasedOn(copy.Name);

                addItem(copy);
                copy.Id = generateID(level.getNextItemNumber());
            }
            endCommand();
            SelectedItems.Clear();
            updatetreeview();
        }