示例#1
0
 /// <summary>
 /// Calculate the corner coordinates
 /// </summary>
 /// <param name="map">Map object to get coordinates for</param>
 private void CalculateBorders(Map map)
 {
     Debug.WriteLine("CalculateBorders() for " + map.ToString(), " scale = " + map.Scale.ToString());
     int scale = (int)Math.Pow(2.0, (double)map.Scale);
     int x = map.xCenter;
     int z = map.zCenter;
     int top = x - (scale * map.Height/2);
     int bottom = x + (scale * map.Height/2);
     int left = z - (scale * map.Width/2);
     int right = z + (scale * map.Width/2);
     TopLeftXZ.Text = string.Format("{0},{1}", top.ToString(), left.ToString());
     TopRightXZ.Text = string.Format("{0},{1}", top.ToString(), right.ToString());
     BottomLeftXZ.Text = string.Format("{0},{1}", bottom.ToString(), left.ToString());
     BottomRightXZ.Text = string.Format("{0},{1}", bottom.ToString(), right.ToString());
 }
示例#2
0
        /// <summary>
        /// Read selected map file and convert map data to displayable image
        /// </summary>
        /// <param name="sender">TreeView item</param>
        /// <param name="e">unused</param>
        public void ShowMap(object sender, RoutedEventArgs e)
        {
            var tvi = (TreeViewItem)sender;
            var node = (Node)tvi.Tag;
            var file = node.file;

            Debug.WriteLine("ShowMap() for " + file + "; Event " + e.RoutedEvent.ToString());
            buttonSave.IsEnabled = false;
            try
            {
                var map = new Map(file);
                if (map != null)
                {
                    textMessage.Text = file.Name;
                    MapImage.Source = map.image;
                    textFileName.Text = file.Name;
                    textScale.Text = map.Scale.ToString();
                    textCenterX.Text = map.xCenter.ToString();
                    textCenterZ.Text = map.zCenter.ToString();
                    buttonSave.IsEnabled = true;

                    textCenter.Text = string.Format("{0}  {1},{2}",
                        Path.GetFileNameWithoutExtension(file.Name),
                        map.xCenter.ToString(), map.zCenter.ToString());
                    CalculateBorders(map);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }