示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                // create Predefined Object Dir, if it does not exists
                string objDir = string.Format(@"{0}\PredefinedObjects", Editor.EditorPath);
                if (!Directory.Exists(objDir))
                {
                    Directory.CreateDirectory(objDir);
                }

                // if object exists, try to save it as an xml predefined object

                if (listBoxObjectsToCreate.SelectedItem != null)
                {
                    string            name = ((EditorDescription)listBoxObjectsToCreate.SelectedItem).ObjectName;
                    EditorDescription desc = (EditorDescription)listBoxObjectsToCreate.SelectedItem;
                    XmlSerializer     x    = new XmlSerializer(typeof(EditorDescription));

                    s = File.Create(string.Format(@"{0}\PredefinedObjects\{1}.xml", Editor.EditorPath, name));
                    x.Serialize(s, desc as EditorDescription);
                    s.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error while saving Predefined Object:");
            }
            finally
            {
                s.Close();
            }
            ReloadPredefinedObjectList();
        }
示例#2
0
 /// <summary>
 /// Resets the distance check.
 /// </summary>
 /// <param name="desc">The desc.</param>
 private void ResetDistanceCheck(EditorDescription desc)
 {
     if (objectDistance.ContainsKey(desc.ObjectName))
     {
         objectDistance[desc.ObjectName] = desc.MinDistance;
     }
 }
示例#3
0
        private void objectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditorDescription[] oldo = Level.Blocks[(int)ActiveBlock.Value - 1].Objects;
            EditorDescription[] newo;
            if (oldo != null)
            {
                newo = new EditorDescription[oldo.Length + 1];
                for (int i = 0; i < oldo.Length; i++)
                {
                    newo[i] = oldo[i];
                }
            }
            else
            {
                newo = new EditorDescription[1];
            }

            bool ready = false;

            if (sender.ToString() == "Enemy")
            {
                newo[newo.Length - 1] = new EnemyDescription();
                ready = true;
            }

            if (!ready)
            {
                throw new Exception("Objekt unbekannt");
            }

            Level.Blocks[(int)ActiveBlock.Value - 1].Objects = newo;
            InvalidateCanyonShape();
        }
示例#4
0
 private void listPredefinedObjects_DoubleClick(object sender, EventArgs e)
 {
     if (listPredefinedObjects.SelectedItem != null)
     {
         EditorDescription desc = DeepClone(listPredefinedObjects.SelectedItem) as EditorDescription;
         if (desc != null)
         {
             listBoxObjectsToCreate.Items.Add(desc);
         }
     }
 }
示例#5
0
        private bool IsObjectCountOk(EditorDescription desc)
        {
            if (!objectCount.ContainsKey(desc.ObjectName))
            {
                objectCount.Add(desc.ObjectName, 1);
                return(true);
            }

            if (objectCount[desc.ObjectName] < desc.MaximumAmount)
            {
                objectCount[desc.ObjectName]++;
                return(true);
            }
            return(false);
        }
示例#6
0
 /// <summary>
 /// Determines whether [is distance ok] [the specified desc].
 /// Distance in canyon segments, to place this item again
 /// </summary>
 /// <param name="desc">The desc.</param>
 /// <returns>
 ///     <c>true</c> if [is distance ok] [the specified desc]; otherwise, <c>false</c>.
 /// </returns>
 private bool IsDistanceOk(EditorDescription desc)
 {
     if (!objectDistance.ContainsKey(desc.ObjectName))
     {
         objectDistance.Add(desc.ObjectName, desc.MinDistance);
         return(true);
     }
     else if (objectDistance[desc.ObjectName] <= 0)
     {
         return(true);
     }
     else
     {
         objectDistance[desc.ObjectName]--;
     }
     return(false);
 }
示例#7
0
        private void buttonObjRemove_Click(object sender, EventArgs e)
        {
            EditorDescription[] oldo = Level.Blocks[(int)ActiveBlock.Value - 1].Objects;
            EditorDescription[] newo;
            if (oldo == null)
            {
                return;
            }
            int sel = ObjectBox.SelectedIndex - 1;

            if (sel < 0 || sel >= oldo.Length)
            {
                MessageBox.Show("Bitte zuerst ein Objekt auswählen");
                return;
            }

            if (oldo[sel] == propertyGrid.SelectedObject)
            {
                propertyGrid.SelectedObject = null;
            }

            newo = new EditorDescription[oldo.Length - 1];
            for (int i = 0; i < newo.Length; i++)
            {
                if (i >= sel)
                {
                    newo[i] = oldo[i + 1];
                }
                else
                {
                    newo[i] = oldo[i];
                }
            }
            Level.Blocks[(int)ActiveBlock.Value - 1].Objects = newo;
            InvalidateCanyonShape();
        }