Exemple #1
0
 public Exporter(object _blocks, object _items, object _entities, object _materials, object _levelinfo)
 {
     try
     {
         this.materials = (List<Material>)_materials;
         this.entities = (List<Entity>)_entities;
         this.items = (List<Item>)_items;
         this.blocks = (List<Block>)_blocks;
         this.levelinfo = (LevelInformation)_levelinfo;
     } catch(Exception ex) {
         MessageBox.Show(MapEditor.Default, "Failed to initialize exporter: " + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
     }
 }
Exemple #2
0
        private void FileOpen()
        {
            bool drCancel = false;
                if (bFileIsChanged)
                {
                    DialogResult dr = MessageBox.Show("File is changed, do you want to save?", "File is changed", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        this.FileSave();
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                        drCancel = true;
                    }
                }
                if (!drCancel)
                {
                    OpenFileDialog dlgOpen = new OpenFileDialog();
                    dlgOpen.Filter = "GPME map file (*.gpm)|*.gpm|All Files (*.*)|*.*";
                    dlgOpen.FilterIndex = 1;
                    dlgOpen.RestoreDirectory = true;
                    if (dlgOpen.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            using (Stream stream = File.Open(dlgOpen.FileName, FileMode.Open))
                            {
                                BinaryFormatter bin = new BinaryFormatter();

                                lstBlocks.Clear();
                                lstItems.Clear();
                                levelInfo.Clear();
                                lstMaterial.Clear();

                                var tlstBlocks = (List<Block>)bin.Deserialize(stream);
                                var tlstItems = (List<Item>)bin.Deserialize(stream);
                                this.levelInfo = (LevelInformation)bin.Deserialize(stream);
                                var tlstMaterial = (List<Material>)bin.Deserialize(stream);

                                foreach (Block b in tlstBlocks)
                                {
                                    lstBlocks.Add(b);
                                }

                                foreach (Item i in tlstItems)
                                {
                                    lstItems.Add(i);
                                }

                                foreach (Material i in tlstMaterial)
                                {
                                    lstMaterial.Add(i);
                                }

                                tlstBlocks.Clear();
                                tlstBlocks = null;
                                tlstItems.Clear();
                                tlstItems = null;
                                tlstMaterial.Clear();
                                tlstMaterial = null;

                                this.sFilePath = dlgOpen.FileName;
                                this.sFileName = Path.GetFileName(dlgOpen.FileName);
                                this.bFileIsSaved = true;
                                this.bFileIsChanged = false;

                                this.RedrawAll();

                            }

                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(this, "The file could not be opened, error: " + Environment.NewLine + ex.Message, "Error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                this.UpdateProperties();
        }