/* +==== Get information from the XML file ====+ */ #region Get information from the XML file public EditorMapEvent getMap(string xmlContainer) { if (!active) { return(null); } mDoc.Load(mFilename); XmlNode rootNode = mDoc.DocumentElement.GetElementsByTagName(xmlContainer)[0]; if (rootNode == null) { return(null); } EditorMapEvent map; try { string name = rootNode["Name"].InnerXml; string bgSrc = rootNode["Background_Source"].InnerXml; int width = int.Parse(rootNode["Width"].InnerXml); int height = int.Parse(rootNode["Height"].InnerXml); map = new EditorMapEvent(name, bgSrc, width, height); } catch (Exception) { return(null); } return(map); }
public void updateCanvas(EditorMapEvent map) { if (map != null) { map_canvas.Children.Clear(); border_init_container.Visibility = Visibility.Hidden; border_layerHandler.IsEnabled = true; if (map.BackgroundSource != "") { map_canvas.Background = new ImageBrush(new BitmapImage(new Uri(map.BackgroundSource))); } else { map_canvas.Background = new SolidColorBrush(Colors.Black); } map_canvas.Width = map.Width; map_canvas.Height = map.Height; map_canvas.IsEnabled = true; label_mapSize.Content = map.Width + " x " + map.Height; label_mapSize.Visibility = Visibility.Visible; label_xPos.Visibility = Visibility.Visible; label_yPos.Visibility = Visibility.Visible; label_layer.Visibility = Visibility.Visible; btn_file_save.IsEnabled = true; btn_file_saveAss.IsEnabled = true; } }
public void collectMapDetails(object sender, EditorMapEvent e) { currentFilename = ""; updateCanvas(e); mapDetails = e; createWindow.RaiseCreateMapEvent -= new EventHandler <EditorMapEvent>(collectMapDetails); createWindow = null; }
public bool add(EditorMapEvent map, string group) { if (!active || map == null) { return(false); } mDoc.Load(mFilename); XmlNode groupNode = establishGroupNode(group); XmlNode nameNode = newElement <string>("Name", map.Name); XmlNode bgSrcNode = newElement <string>("Background_Source", map.BackgroundSource); XmlNode widthNode = newElement <int>("Width", map.Width); XmlNode heightNode = newElement <int>("Height", map.Height); groupNode.AppendChild(nameNode); groupNode.AppendChild(bgSrcNode); groupNode.AppendChild(widthNode); groupNode.AppendChild(heightNode); return(true); }
private void btn_loadMap_init_Click(object sender, RoutedEventArgs e) { // Configure open file dialog box Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // http://msdn.microsoft.com/en-us/library/microsoft.win32.openfiledialog%28v=vs.110%29.aspx dlg.FileName = ""; // Default file name dlg.DefaultExt = ".xml"; // Default file extension dlg.Filter = "Config Files (.xml)|*.xml"; // Filter files by extension // Show open file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { if (dlg.FileName != "") { currentFilename = dlg.FileName; XMLFileHandler newDocument = new XMLFileHandler(); newDocument.Intialize(dlg.FileName); mapDetails = newDocument.getMap(xmlconfig_storageGroups[0]); updateCanvas(mapDetails); List <Object> objList = newDocument.get(xmlconfig_storageGroups[1]); if (objList != null && objList.Count > 0) { foreach (Object obj in objList) { obj.UpdateSource(); // Get the position of the ellipse relative to the Canvas Canvas.SetLeft(obj, obj.transform.x); Canvas.SetTop(obj, obj.transform.y); AddObjectToMap(obj); } } } } }