Beispiel #1
0
        private void button12_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog fileDlg = new Microsoft.Win32.OpenFileDialog();

            fileDlg.DefaultExt = ".xml";
            fileDlg.Filter     = "Pliki XML|*.xml";
            try
            {
                if (fileDlg.ShowDialog() == true)
                {
                    using (System.IO.FileStream fs = new System.IO.FileStream(fileDlg.FileName, System.IO.FileMode.Open))
                    {
                        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(SerializableMap));
                        SerializableMap sMap = (SerializableMap)serializer.Deserialize(fs);
                        _map = Map.Deserialize(sMap);
                        DrawMap();
                        listBox3.ItemsSource = _map.AllNamedBlocks;
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }
Beispiel #2
0
        public static Map Deserialize(SerializableMap sMap)
        {
            Map map = new Map(sMap.Width, sMap.Height);

            foreach (SerializableBlock sBlock in sMap.Blocks)
            {
                string [] colorArray = sBlock.Color.Split('.');
                map.BlockMap[sBlock.X, sBlock.Y] = new Block()
                {
                    Color = Color.FromArgb(byte.Parse(colorArray[0]), byte.Parse(colorArray[1]), byte.Parse(colorArray[2]), byte.Parse(colorArray[3])), Name = sBlock.Name, Description = sBlock.Description
                };
            }
            map.TextBlocks = sMap.TextBlocks;
            return(map);
        }
Beispiel #3
0
        public SerializableMap Serialize()
        {
            SerializableMap sMap = new SerializableMap();

            sMap.Width  = Width;
            sMap.Height = Height;
            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    if (BlockMap[i, j] != null)
                    {
                        Block bl = BlockMap[i, j];
                        sMap.Blocks.Add(new SerializableBlock()
                        {
                            Color = string.Format("{0}.{1}.{2}.{3}", bl.Color.A, bl.Color.R, bl.Color.G, bl.Color.B), Description = bl.Description, Name = bl.Name, X = i, Y = j
                        });
                    }
                }
            }
            sMap.TextBlocks = TextBlocks;
            return(sMap);
        }
Beispiel #4
0
 public SerializableMap Serialize()
 {
     SerializableMap sMap = new SerializableMap();
     sMap.Width = Width;
     sMap.Height = Height;
     for (int i = 0; i < Width; i++)
     {
         for (int j = 0; j < Height; j++)
         {
             if (BlockMap[i, j] != null)
             {
                 Block bl = BlockMap[i, j];
                 sMap.Blocks.Add(new SerializableBlock() { Color = string.Format("{0}.{1}.{2}.{3}", bl.Color.A, bl.Color.R, bl.Color.G, bl.Color.B), Description = bl.Description, Name = bl.Name, X = i, Y = j });
             }
         }
     }
     sMap.TextBlocks = TextBlocks;
     return sMap;
 }
Beispiel #5
0
 public static Map Deserialize(SerializableMap sMap)
 {
     Map map = new Map(sMap.Width, sMap.Height);
     foreach (SerializableBlock sBlock in sMap.Blocks)
     {
         string [] colorArray = sBlock.Color.Split('.');
         map.BlockMap[sBlock.X, sBlock.Y] = new Block() { Color = Color.FromArgb(byte.Parse(colorArray[0]), byte.Parse(colorArray[1]), byte.Parse(colorArray[2]), byte.Parse(colorArray[3])), Name = sBlock.Name, Description = sBlock.Description };
     }
     map.TextBlocks = sMap.TextBlocks;
     return map;
 }