Пример #1
0
 public void RemoveObject(cObject obj)
 {
     objectList.Remove(obj);
 }
Пример #2
0
 public ObjectManager()
 {
     selectedObject = null;
     objectList = new List<cObject>();
 }
Пример #3
0
 public void AddObject(cObject obj)
 {
     objectList.Add(obj);
 }
Пример #4
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Image Files (*.bmp, *.gif, *.jpeg, *.jpg, *.png, *.tiff)|*.bmp;*.gif;*.jpeg;*.jpg;*.png;*.tiff|XML Files (*.xml)|*.xml";
            ofd.Multiselect = true;

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (ofd.FilterIndex == 1)
                {
                    foreach (string s in ofd.FileNames)
                    {
                        string relativePath = MakeRelativePath(Application.ExecutablePath, s);

                        cObject t_object = new cObject(new Bitmap(s), relativePath);

                        objectManager.AddObject(t_object);
                        saved = Saved_State.NOTSAVED;
                    }
                }
                else
                {
                    XmlDocument xmlDoc = new XmlDocument(); // Create an XML document object
                    int objOpend = 0;
                    int wrldOpend = 0;

                    foreach (string s in ofd.FileNames)
                    {
                        xmlDoc.Load(s); // Load the XML document from the specified file
                        bool exportedObject = false;

                        XmlNode versionNode = xmlDoc.SelectSingleNode("/World");
                        if (null == versionNode)
                        {
                            versionNode = xmlDoc.SelectSingleNode("/Exported_Object");
                            if (null == versionNode)
                            {
                                MessageBox.Show("ERROR: Cannot find root \"World\" or \"Exported_Object\".", "ERROR: Bad File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                                exportedObject = true;
                        }

                        if (null == versionNode.Attributes["Version"])
                        {
                            MessageBox.Show("ERROR: XML file is does not contain version number.", "ERROR: Bad Version", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        string worldVersion = versionNode.Attributes["Version"].Value;

                        if (0 != String.Compare(worldVersion, VERSION))
                        {
                            MessageBox.Show("ERROR: XML file is using a version different from the Editor.", "ERROR: Old Version", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        if (!exportedObject)
                        {
                            XmlNode objectsNode = xmlDoc.SelectSingleNode("/World/Objects");
                            int numOfObjects = int.Parse(objectsNode.Attributes["Number_of_Objects"].Value);

                            XmlNodeList objectChildren = objectsNode.ChildNodes;
                            XmlNode objectNode;
                            for (int i = 0; i < numOfObjects; ++i)
                            {
                                objectNode = objectChildren[i];

                                if (null != objectNode.Attributes["Image_Path"])
                                {
                                    string path = objectNode.Attributes["Image_Path"].Value;
                                    path = Path.GetFullPath(path);
                                    string relativePath = MakeRelativePath(Application.ExecutablePath, path);

                                    cObject t_object = new cObject(new Bitmap(path), relativePath);

                                    t_object.LoadXML(objectNode);

                                    objectManager.AddObject(t_object);
                                    ++objOpend;
                                }
                                else
                                    MessageBox.Show("ERROR: XML file has an object with a bad image file path.", "ERROR: Bad File Path", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            ++wrldOpend;
                        }
                        else
                        {
                            XmlNode objectNode = xmlDoc.SelectSingleNode("/Exported_Object/Object");

                            if (null != objectNode.Attributes["Image_Path"])
                            {
                                string path = objectNode.Attributes["Image_Path"].Value;
                                path = Path.GetFullPath(path);
                                string relativePath = MakeRelativePath(Application.ExecutablePath, path);

                                cObject t_object = new cObject(new Bitmap(path), relativePath);

                                t_object.LoadXML(objectNode);

                                objectManager.AddObject(t_object);
                                ++objOpend;

                                saved = Saved_State.NOTSAVED;
                            }
                            else
                                MessageBox.Show("ERROR: XML file has an object with a bad image file path.", "ERROR: Bad File Path", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                    }

                    if (saved == Saved_State.NEVERSAVED && wrldOpend == 1)
                        saved = Saved_State.SAVED;
                    else
                        saved = Saved_State.NOTSAVED;
                }

                FindCanvasSize();
                objectManager.SelectedObject = null;
                ButtonsEnabled(false);
                Invalidate();
            }
        }