Worked on map viewer
This commit is contained in:
		
							
								
								
									
										20
									
								
								Tools/MapViewer/MapViewer.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Tools/MapViewer/MapViewer.sln
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
 | 
			
		||||
Microsoft Visual Studio Solution File, Format Version 12.00
 | 
			
		||||
# Visual Studio 2012
 | 
			
		||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapViewer", "MapViewer\MapViewer.csproj", "{A6DA2104-18B4-4A9A-BAD7-5AC8C98A5086}"
 | 
			
		||||
EndProject
 | 
			
		||||
Global
 | 
			
		||||
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 | 
			
		||||
		Debug|Any CPU = Debug|Any CPU
 | 
			
		||||
		Release|Any CPU = Release|Any CPU
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 | 
			
		||||
		{A6DA2104-18B4-4A9A-BAD7-5AC8C98A5086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{A6DA2104-18B4-4A9A-BAD7-5AC8C98A5086}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{A6DA2104-18B4-4A9A-BAD7-5AC8C98A5086}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{A6DA2104-18B4-4A9A-BAD7-5AC8C98A5086}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(SolutionProperties) = preSolution
 | 
			
		||||
		HideSolutionNode = FALSE
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
EndGlobal
 | 
			
		||||
							
								
								
									
										6
									
								
								Tools/MapViewer/MapViewer/App.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Tools/MapViewer/MapViewer/App.config
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8" ?>
 | 
			
		||||
<configuration>
 | 
			
		||||
    <startup> 
 | 
			
		||||
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 | 
			
		||||
    </startup>
 | 
			
		||||
</configuration>
 | 
			
		||||
							
								
								
									
										8
									
								
								Tools/MapViewer/MapViewer/App.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Tools/MapViewer/MapViewer/App.xaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
<Application x:Class="TransportGame.MapViewer.App"
 | 
			
		||||
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             StartupUri="MainWindow.xaml">
 | 
			
		||||
    <Application.Resources>
 | 
			
		||||
         
 | 
			
		||||
    </Application.Resources>
 | 
			
		||||
</Application>
 | 
			
		||||
							
								
								
									
										17
									
								
								Tools/MapViewer/MapViewer/App.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Tools/MapViewer/MapViewer/App.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Configuration;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
 | 
			
		||||
namespace TransportGame.MapViewer
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for App.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class App : Application
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										125
									
								
								Tools/MapViewer/MapViewer/Business/MapRenderer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								Tools/MapViewer/MapViewer/Business/MapRenderer.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,125 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using TransportGame.Model;
 | 
			
		||||
 | 
			
		||||
namespace TransportGame.MapViewer
 | 
			
		||||
{
 | 
			
		||||
    public class MapRenderer
 | 
			
		||||
    {
 | 
			
		||||
        [Flags]
 | 
			
		||||
        public enum Layers
 | 
			
		||||
        {
 | 
			
		||||
            None = 0,
 | 
			
		||||
            Elevation = 1,
 | 
			
		||||
            All = Elevation 
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the scale
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        private int _scale;
 | 
			
		||||
        public int Scale
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _scale;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                lock (this)
 | 
			
		||||
                {
 | 
			
		||||
                    _scale = value;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private readonly Color WaterColor = Colors.Navy;
 | 
			
		||||
        private readonly Color ElevationTerrainColor = Colors.White;
 | 
			
		||||
        private readonly Color TerrainColor = Colors.White;
 | 
			
		||||
 | 
			
		||||
        public MapRenderer()
 | 
			
		||||
        {
 | 
			
		||||
            Scale = 4;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ///<summary>
 | 
			
		||||
        ///Renders a map to a file
 | 
			
		||||
        ///</summary>
 | 
			
		||||
        ///<param name="file"></param>
 | 
			
		||||
        ///<param name="map"></param>
 | 
			
		||||
        ///<param name="layers"></param>
 | 
			
		||||
        public Color[,] Render(Map map, Layers layers = Layers.All)
 | 
			
		||||
        {
 | 
			
		||||
            lock (this)
 | 
			
		||||
            {
 | 
			
		||||
                // Create texture on which to draw
 | 
			
		||||
                Color[,] pixels = new Color[map.Width * Scale, map.Height * Scale];
 | 
			
		||||
 | 
			
		||||
                // First layer - cells
 | 
			
		||||
                DrawCells(pixels, map, (layers & Layers.Elevation) > 0);
 | 
			
		||||
 | 
			
		||||
                // Done
 | 
			
		||||
                return pixels;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void DrawCells(Color[,] pixels, Map map, bool elevation)
 | 
			
		||||
        {
 | 
			
		||||
            for (int x = 0; x < pixels.GetLength(0); x++)
 | 
			
		||||
                for (int y = 0; y < pixels.GetLength(1); y++)
 | 
			
		||||
                {
 | 
			
		||||
                    int mapX = x / Scale;
 | 
			
		||||
                    int mapY = y / Scale;
 | 
			
		||||
 | 
			
		||||
                    // Draw water
 | 
			
		||||
                    if (map.IsWater(mapX, mapY))
 | 
			
		||||
                        pixels[x, y] = WaterColor;
 | 
			
		||||
 | 
			
		||||
                    // Draw elevation
 | 
			
		||||
                    else if (elevation)
 | 
			
		||||
                    {
 | 
			
		||||
                        float alpha = (map[mapX, mapY] - map.Biome.HeightRange.Minimum) / (map.Biome.HeightRange.Maximum - map.Biome.HeightRange.Minimum);
 | 
			
		||||
                        pixels[x, y] = Color.Multiply(ElevationTerrainColor, alpha);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // Draw terrain
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        pixels[x, y] = TerrainColor;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<BitmapSource> RenderToImageSource(Map map, Layers layers = Layers.All)
 | 
			
		||||
        {
 | 
			
		||||
            var colors = await Task.Run(() => Render(map, layers));
 | 
			
		||||
            colors[0, 0] = Colors.Red;
 | 
			
		||||
            colors[colors.GetLength(0) - 1, 0] = Colors.Red;
 | 
			
		||||
 | 
			
		||||
            // Convert to raw pixels
 | 
			
		||||
            byte[] raw = new byte[colors.GetLength(0) * colors.GetLength(1) * 3];
 | 
			
		||||
 | 
			
		||||
            for (int x = 0; x < colors.GetLength(0); x++)
 | 
			
		||||
                for (int y = 0; y < colors.GetLength(1); y++)
 | 
			
		||||
                {
 | 
			
		||||
                    int pixelIndex = x + y * colors.GetLength(0);
 | 
			
		||||
 | 
			
		||||
                    raw[3 * pixelIndex] = colors[x, y].R;
 | 
			
		||||
                    raw[3 * pixelIndex + 1] = colors[x, y].G;
 | 
			
		||||
                    raw[3 * pixelIndex + 2] = colors[x, y].B;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            // Create bitmap source
 | 
			
		||||
            BitmapSource bmp = BitmapSource.Create(colors.GetLength(0), colors.GetLength(1), 
 | 
			
		||||
                96, 96, PixelFormats.Rgb24, null, raw, colors.GetLength(0) * 3);
 | 
			
		||||
 | 
			
		||||
            return bmp;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										141
									
								
								Tools/MapViewer/MapViewer/MainWindow.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								Tools/MapViewer/MapViewer/MainWindow.xaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,141 @@
 | 
			
		||||
<Window x:Class="TransportGame.MapViewer.MainWindow"
 | 
			
		||||
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:prop="http://propertytools.org/wpf"
 | 
			
		||||
        Title="MainWindow" Height="500" Width="800">
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.RowDefinitions>
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
            <RowDefinition />
 | 
			
		||||
        </Grid.RowDefinitions>
 | 
			
		||||
        <Grid.ColumnDefinitions>
 | 
			
		||||
            <ColumnDefinition Width="2*"/>
 | 
			
		||||
            <ColumnDefinition Width="3" />
 | 
			
		||||
            <ColumnDefinition Width="200" />
 | 
			
		||||
        </Grid.ColumnDefinitions>
 | 
			
		||||
 | 
			
		||||
        <ToolBar Grid.Row="0" Grid.ColumnSpan="3">
 | 
			
		||||
            <Button Name="buttonOpen" ToolTip="Open map file" Click="buttonOpen_Click">
 | 
			
		||||
                <Image Source="pack://application:,,,/Resources/folder_page.png" />
 | 
			
		||||
            </Button>
 | 
			
		||||
            <Button Name="buttonSave" ToolTip="Saves as image" Click="buttonSave_Click">
 | 
			
		||||
                <Image Source="pack://application:,,,/Resources/picture_save.png" />
 | 
			
		||||
            </Button>
 | 
			
		||||
            <Separator />
 | 
			
		||||
            <TextBlock VerticalAlignment="Center" Margin="4,2,4,2">Zoom:</TextBlock>
 | 
			
		||||
            <Slider Name="zoomSlider" Width="80" 
 | 
			
		||||
                    Minimum="1" Maximum="15" 
 | 
			
		||||
                    SmallChange="1" LargeChange="3" 
 | 
			
		||||
                    TickPlacement="BottomRight"
 | 
			
		||||
                    Ticks="1,2,5,10,15"
 | 
			
		||||
                    Value="{Binding Renderer.Scale}" 
 | 
			
		||||
                    ValueChanged="zoomSlider_ValueChanged">
 | 
			
		||||
                <Slider.ToolTip>
 | 
			
		||||
                    <ToolTip Content="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.Value}" />
 | 
			
		||||
                </Slider.ToolTip>
 | 
			
		||||
            </Slider>
 | 
			
		||||
            <TextBlock VerticalAlignment="Center">
 | 
			
		||||
                <Run Text="{Binding ElementName=zoomSlider, Path=Value}" /><Run>00%</Run>
 | 
			
		||||
            </TextBlock>
 | 
			
		||||
        </ToolBar>
 | 
			
		||||
 | 
			
		||||
        <ScrollViewer Grid.Row="1" 
 | 
			
		||||
                      VerticalScrollBarVisibility="Auto" 
 | 
			
		||||
                      HorizontalScrollBarVisibility="Auto">
 | 
			
		||||
 | 
			
		||||
            <Image Stretch="None" Source="{Binding RenderedMap}"/>
 | 
			
		||||
 | 
			
		||||
        </ScrollViewer>
 | 
			
		||||
 | 
			
		||||
        <StackPanel Grid.Row="1" Name="progress" Visibility="Hidden" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
 | 
			
		||||
            <ProgressBar Width="100" Height="10" IsIndeterminate="True"
 | 
			
		||||
                             Foreground="Tomato" Background="WhiteSmoke" />
 | 
			
		||||
            <TextBlock Name="progressText" HorizontalAlignment="Center">Loading...</TextBlock>
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
        <GridSplitter Grid.Row="1" Grid.Column="1"
 | 
			
		||||
                      HorizontalAlignment="Stretch"
 | 
			
		||||
                      VerticalAlignment="Stretch" />
 | 
			
		||||
 | 
			
		||||
        <StackPanel Grid.Row="1" Grid.Column="2"
 | 
			
		||||
                    Orientation="Vertical">
 | 
			
		||||
 | 
			
		||||
            <Expander IsExpanded="True" Header="Layers">
 | 
			
		||||
                <StackPanel Orientation="Vertical">
 | 
			
		||||
                    <CheckBox>Elevation</CheckBox>
 | 
			
		||||
                    <CheckBox>Roads</CheckBox>
 | 
			
		||||
                    <CheckBox>Buildings</CheckBox>
 | 
			
		||||
                    <CheckBox>Vegetation</CheckBox>
 | 
			
		||||
                    
 | 
			
		||||
                    <Grid>
 | 
			
		||||
                        <Grid.ColumnDefinitions>
 | 
			
		||||
                            <ColumnDefinition />
 | 
			
		||||
                            <ColumnDefinition />
 | 
			
		||||
                        </Grid.ColumnDefinitions>
 | 
			
		||||
                        <Button Grid.Column="0" Content="Select all" />
 | 
			
		||||
                        <Button Grid.Column="1" Content="Render" />
 | 
			
		||||
                    </Grid>
 | 
			
		||||
                </StackPanel>
 | 
			
		||||
            </Expander>
 | 
			
		||||
            <Expander IsExpanded="True" Header="General">
 | 
			
		||||
                <Grid Height="Auto">
 | 
			
		||||
                    <Grid.ColumnDefinitions>
 | 
			
		||||
                        <ColumnDefinition />
 | 
			
		||||
                        <ColumnDefinition />
 | 
			
		||||
                    </Grid.ColumnDefinitions>
 | 
			
		||||
                    <Grid.RowDefinitions>
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                    </Grid.RowDefinitions>
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="0" Grid.Column="0" >Loaded map:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="0" Grid.Column="1" IsReadOnly="True" Text="{Binding LoadedFile,Mode=OneWay}" />
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="1" Grid.Column="0" >Width:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="1" Grid.Column="1" IsReadOnly="True" Text="{Binding Map.Width,Mode=OneWay}" />
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="2" Grid.Column="0" >Height:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="2" Grid.Column="1" IsReadOnly="True" Text="{Binding Map.Height,Mode=OneWay}" />
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="3" Grid.Column="0" >Water level:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="3" Grid.Column="1" IsReadOnly="True" Text="{Binding Map.WaterLevel,Mode=OneWay}" />
 | 
			
		||||
                </Grid>
 | 
			
		||||
 | 
			
		||||
            </Expander>
 | 
			
		||||
 | 
			
		||||
            <Expander IsExpanded="True" Header="Biome">
 | 
			
		||||
                <Grid Height="Auto">
 | 
			
		||||
                    <Grid.ColumnDefinitions>
 | 
			
		||||
                        <ColumnDefinition />
 | 
			
		||||
                        <ColumnDefinition />
 | 
			
		||||
                    </Grid.ColumnDefinitions>
 | 
			
		||||
                    <Grid.RowDefinitions>
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                        <RowDefinition />
 | 
			
		||||
                    </Grid.RowDefinitions>
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="0" Grid.Column="0" >Name:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="0" Grid.Column="1" IsReadOnly="True" Text="{Binding Map.Biome.Name,Mode=OneWay}" />
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="1" Grid.Column="0" >Height range:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="1" Grid.Column="1" IsReadOnly="True" Text="{Binding Map.Biome.HeightRange,Mode=OneWay}" />
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="2" Grid.Column="0" >Moisture:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="2" Grid.Column="1" IsReadOnly="True" Text="{Binding Map.Biome.Moisture,Mode=OneWay}" />
 | 
			
		||||
 | 
			
		||||
                    <TextBlock Grid.Row="3" Grid.Column="0" >Vegetation density:</TextBlock>
 | 
			
		||||
                    <TextBox Grid.Row="3" Grid.Column="1" IsReadOnly="True" Text="{Binding Map.Biome.VegetationDensity,Mode=OneWay}" />
 | 
			
		||||
                </Grid>
 | 
			
		||||
 | 
			
		||||
            </Expander>
 | 
			
		||||
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
    </Grid>
 | 
			
		||||
</Window>
 | 
			
		||||
							
								
								
									
										202
									
								
								Tools/MapViewer/MapViewer/MainWindow.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								Tools/MapViewer/MapViewer/MainWindow.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,202 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using Microsoft.Win32;
 | 
			
		||||
using TransportGame.MapViewer.Storage;
 | 
			
		||||
using TransportGame.Model;
 | 
			
		||||
 | 
			
		||||
namespace TransportGame.MapViewer
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for MainWindow.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class MainWindow : Window, INotifyPropertyChanged
 | 
			
		||||
    {
 | 
			
		||||
        public event PropertyChangedEventHandler PropertyChanged;
 | 
			
		||||
 | 
			
		||||
        #region Map property
 | 
			
		||||
 | 
			
		||||
        private Map _map;
 | 
			
		||||
 | 
			
		||||
        public Map Map
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _map;
 | 
			
		||||
            }
 | 
			
		||||
            private set
 | 
			
		||||
            {
 | 
			
		||||
                _map = value;
 | 
			
		||||
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("Map"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Loaded file property
 | 
			
		||||
        
 | 
			
		||||
        private string _loadedFile;
 | 
			
		||||
 | 
			
		||||
        public string LoadedFile
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _loadedFile;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            private set
 | 
			
		||||
            {
 | 
			
		||||
                _loadedFile = value;
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("LoadedFile"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Rendered map property
 | 
			
		||||
 | 
			
		||||
        private BitmapSource _renderedMap;
 | 
			
		||||
 | 
			
		||||
        public BitmapSource RenderedMap
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _renderedMap;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            private set
 | 
			
		||||
            {
 | 
			
		||||
                _renderedMap = value;
 | 
			
		||||
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("RenderedMap"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        public MapRenderer Renderer { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public MainWindow()
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            Renderer = new MapRenderer();
 | 
			
		||||
            LoadedFile = "N/A";
 | 
			
		||||
            DataContext = this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async Task OpenMapFile(string filename)
 | 
			
		||||
        {
 | 
			
		||||
            await LoadMap(filename);
 | 
			
		||||
            await RenderMap();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static bool ShowOpenMapDialog(out string filename)
 | 
			
		||||
        {
 | 
			
		||||
            OpenFileDialog dialog = new OpenFileDialog();
 | 
			
		||||
            dialog.Filter = "Map files|*.map|All files|*.*";
 | 
			
		||||
            dialog.Title = "Open map file";
 | 
			
		||||
 | 
			
		||||
            bool? result = dialog.ShowDialog();
 | 
			
		||||
 | 
			
		||||
            if (!result.HasValue || !result.Value)
 | 
			
		||||
            {
 | 
			
		||||
                filename = null;
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            filename = dialog.FileName;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static bool ShowSaveMapDialog(out string filename)
 | 
			
		||||
        {
 | 
			
		||||
            SaveFileDialog dialog = new SaveFileDialog();
 | 
			
		||||
            dialog.Filter = "PNG Files|*.png|All files|*.*";
 | 
			
		||||
            dialog.Title = "Save rendered map image";
 | 
			
		||||
 | 
			
		||||
            bool? result = dialog.ShowDialog();
 | 
			
		||||
 | 
			
		||||
            if (!result.HasValue || !result.Value)
 | 
			
		||||
            {
 | 
			
		||||
                filename = null;
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            filename = dialog.FileName;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async Task LoadMap(string filename)
 | 
			
		||||
        {
 | 
			
		||||
            progress.Visibility = System.Windows.Visibility.Visible;
 | 
			
		||||
            progressText.Text = "Loading map...";
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Map = await Task.Run(() => MapStorage.Read(filename));
 | 
			
		||||
                LoadedFile = filename;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                MessageBox.Show(ex.Message, "Error");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            progress.Visibility = System.Windows.Visibility.Hidden;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async Task RenderMap()
 | 
			
		||||
        {
 | 
			
		||||
            progress.Visibility = System.Windows.Visibility.Visible;
 | 
			
		||||
            progressText.Text = "Rendering map...";
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                RenderedMap = await Renderer.RenderToImageSource(Map);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                MessageBox.Show(ex.Message, "Error");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            progress.Visibility = System.Windows.Visibility.Hidden;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async void buttonOpen_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            // Open dialog
 | 
			
		||||
            string filename;
 | 
			
		||||
 | 
			
		||||
            if (!ShowOpenMapDialog(out filename))
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            // Load file and generate image
 | 
			
		||||
            await OpenMapFile(filename);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonSave_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            var encoder = new PngBitmapEncoder();
 | 
			
		||||
            encoder.Frames.Add(BitmapFrame.Create(RenderedMap));
 | 
			
		||||
 | 
			
		||||
            using (var writer = File.OpenWrite(LoadedFile + ".png"))
 | 
			
		||||
            {
 | 
			
		||||
                encoder.Save(writer);
 | 
			
		||||
                writer.Close();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async void zoomSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
 | 
			
		||||
        {
 | 
			
		||||
            if (Map != null)
 | 
			
		||||
                await RenderMap();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										121
									
								
								Tools/MapViewer/MapViewer/MapViewer.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								Tools/MapViewer/MapViewer/MapViewer.csproj
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,121 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 | 
			
		||||
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
 | 
			
		||||
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
 | 
			
		||||
    <ProjectGuid>{A6DA2104-18B4-4A9A-BAD7-5AC8C98A5086}</ProjectGuid>
 | 
			
		||||
    <OutputType>WinExe</OutputType>
 | 
			
		||||
    <AppDesignerFolder>Properties</AppDesignerFolder>
 | 
			
		||||
    <RootNamespace>TransportGame.MapViewer</RootNamespace>
 | 
			
		||||
    <AssemblyName>MapViewer</AssemblyName>
 | 
			
		||||
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
 | 
			
		||||
    <FileAlignment>512</FileAlignment>
 | 
			
		||||
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
 | 
			
		||||
    <WarningLevel>4</WarningLevel>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
 | 
			
		||||
    <PlatformTarget>AnyCPU</PlatformTarget>
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <DebugType>full</DebugType>
 | 
			
		||||
    <Optimize>false</Optimize>
 | 
			
		||||
    <OutputPath>bin\Debug\</OutputPath>
 | 
			
		||||
    <DefineConstants>DEBUG;TRACE</DefineConstants>
 | 
			
		||||
    <ErrorReport>prompt</ErrorReport>
 | 
			
		||||
    <WarningLevel>4</WarningLevel>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
 | 
			
		||||
    <PlatformTarget>AnyCPU</PlatformTarget>
 | 
			
		||||
    <DebugType>pdbonly</DebugType>
 | 
			
		||||
    <Optimize>true</Optimize>
 | 
			
		||||
    <OutputPath>bin\Release\</OutputPath>
 | 
			
		||||
    <DefineConstants>TRACE</DefineConstants>
 | 
			
		||||
    <ErrorReport>prompt</ErrorReport>
 | 
			
		||||
    <WarningLevel>4</WarningLevel>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Reference Include="System" />
 | 
			
		||||
    <Reference Include="System.Data" />
 | 
			
		||||
    <Reference Include="System.Xml" />
 | 
			
		||||
    <Reference Include="Microsoft.CSharp" />
 | 
			
		||||
    <Reference Include="System.Core" />
 | 
			
		||||
    <Reference Include="System.Xml.Linq" />
 | 
			
		||||
    <Reference Include="System.Data.DataSetExtensions" />
 | 
			
		||||
    <Reference Include="System.Xaml">
 | 
			
		||||
      <RequiredTargetFramework>4.0</RequiredTargetFramework>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="WindowsBase" />
 | 
			
		||||
    <Reference Include="PresentationCore" />
 | 
			
		||||
    <Reference Include="PresentationFramework" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <ApplicationDefinition Include="App.xaml">
 | 
			
		||||
      <Generator>MSBuild:Compile</Generator>
 | 
			
		||||
      <SubType>Designer</SubType>
 | 
			
		||||
    </ApplicationDefinition>
 | 
			
		||||
    <Compile Include="..\..\..\Game\Assets\Scripts\Model\Biome.cs">
 | 
			
		||||
      <Link>Model\Biome.cs</Link>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="..\..\..\Game\Assets\Scripts\Model\Map.cs">
 | 
			
		||||
      <Link>Model\Map.cs</Link>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="Storage\MapStorage.cs" />
 | 
			
		||||
    <Page Include="MainWindow.xaml">
 | 
			
		||||
      <Generator>MSBuild:Compile</Generator>
 | 
			
		||||
      <SubType>Designer</SubType>
 | 
			
		||||
    </Page>
 | 
			
		||||
    <Compile Include="..\..\..\Game\Assets\Scripts\Utils\Range.cs">
 | 
			
		||||
      <Link>Utils\Range.cs</Link>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="App.xaml.cs">
 | 
			
		||||
      <DependentUpon>App.xaml</DependentUpon>
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="Business\MapRenderer.cs" />
 | 
			
		||||
    <Compile Include="MainWindow.xaml.cs">
 | 
			
		||||
      <DependentUpon>MainWindow.xaml</DependentUpon>
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Compile Include="Properties\AssemblyInfo.cs">
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="Properties\Resources.Designer.cs">
 | 
			
		||||
      <AutoGen>True</AutoGen>
 | 
			
		||||
      <DesignTime>True</DesignTime>
 | 
			
		||||
      <DependentUpon>Resources.resx</DependentUpon>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="Properties\Settings.Designer.cs">
 | 
			
		||||
      <AutoGen>True</AutoGen>
 | 
			
		||||
      <DependentUpon>Settings.settings</DependentUpon>
 | 
			
		||||
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <EmbeddedResource Include="Properties\Resources.resx">
 | 
			
		||||
      <Generator>ResXFileCodeGenerator</Generator>
 | 
			
		||||
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
 | 
			
		||||
    </EmbeddedResource>
 | 
			
		||||
    <None Include="Properties\Settings.settings">
 | 
			
		||||
      <Generator>SettingsSingleFileGenerator</Generator>
 | 
			
		||||
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
 | 
			
		||||
    </None>
 | 
			
		||||
    <AppDesigner Include="Properties\" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <None Include="App.config" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Resource Include="Resources\picture_save.png" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Resource Include="Resources\folder_page.png" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 | 
			
		||||
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
 | 
			
		||||
       Other similar extension points exist, see Microsoft.Common.targets.
 | 
			
		||||
  <Target Name="BeforeBuild">
 | 
			
		||||
  </Target>
 | 
			
		||||
  <Target Name="AfterBuild">
 | 
			
		||||
  </Target>
 | 
			
		||||
  -->
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										55
									
								
								Tools/MapViewer/MapViewer/Properties/AssemblyInfo.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								Tools/MapViewer/MapViewer/Properties/AssemblyInfo.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using System.Resources;
 | 
			
		||||
using System.Runtime.CompilerServices;
 | 
			
		||||
using System.Runtime.InteropServices;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
 | 
			
		||||
// General Information about an assembly is controlled through the following 
 | 
			
		||||
// set of attributes. Change these attribute values to modify the information
 | 
			
		||||
// associated with an assembly.
 | 
			
		||||
[assembly: AssemblyTitle("MapViewer")]
 | 
			
		||||
[assembly: AssemblyDescription("")]
 | 
			
		||||
[assembly: AssemblyConfiguration("")]
 | 
			
		||||
[assembly: AssemblyCompany("")]
 | 
			
		||||
[assembly: AssemblyProduct("MapViewer")]
 | 
			
		||||
[assembly: AssemblyCopyright("Copyright ©  2015")]
 | 
			
		||||
[assembly: AssemblyTrademark("")]
 | 
			
		||||
[assembly: AssemblyCulture("")]
 | 
			
		||||
 | 
			
		||||
// Setting ComVisible to false makes the types in this assembly not visible 
 | 
			
		||||
// to COM components.  If you need to access a type in this assembly from 
 | 
			
		||||
// COM, set the ComVisible attribute to true on that type.
 | 
			
		||||
[assembly: ComVisible(false)]
 | 
			
		||||
 | 
			
		||||
//In order to begin building localizable applications, set 
 | 
			
		||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
 | 
			
		||||
//inside a <PropertyGroup>.  For example, if you are using US english
 | 
			
		||||
//in your source files, set the <UICulture> to en-US.  Then uncomment
 | 
			
		||||
//the NeutralResourceLanguage attribute below.  Update the "en-US" in
 | 
			
		||||
//the line below to match the UICulture setting in the project file.
 | 
			
		||||
 | 
			
		||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
[assembly: ThemeInfo(
 | 
			
		||||
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
 | 
			
		||||
    //(used if a resource is not found in the page, 
 | 
			
		||||
    // or application resource dictionaries)
 | 
			
		||||
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
 | 
			
		||||
    //(used if a resource is not found in the page, 
 | 
			
		||||
    // app, or any theme specific resource dictionaries)
 | 
			
		||||
)]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Version information for an assembly consists of the following four values:
 | 
			
		||||
//
 | 
			
		||||
//      Major Version
 | 
			
		||||
//      Minor Version 
 | 
			
		||||
//      Build Number
 | 
			
		||||
//      Revision
 | 
			
		||||
//
 | 
			
		||||
// You can specify all the values or you can default the Build and Revision Numbers 
 | 
			
		||||
// by using the '*' as shown below:
 | 
			
		||||
// [assembly: AssemblyVersion("1.0.*")]
 | 
			
		||||
[assembly: AssemblyVersion("1.0.0.0")]
 | 
			
		||||
[assembly: AssemblyFileVersion("1.0.0.0")]
 | 
			
		||||
							
								
								
									
										63
									
								
								Tools/MapViewer/MapViewer/Properties/Resources.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Tools/MapViewer/MapViewer/Properties/Resources.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
// <auto-generated>
 | 
			
		||||
//     This code was generated by a tool.
 | 
			
		||||
//     Runtime Version:4.0.30319.34014
 | 
			
		||||
//
 | 
			
		||||
//     Changes to this file may cause incorrect behavior and will be lost if
 | 
			
		||||
//     the code is regenerated.
 | 
			
		||||
// </auto-generated>
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace TransportGame.MapViewer.Properties {
 | 
			
		||||
    using System;
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///   A strongly-typed resource class, for looking up localized strings, etc.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    // This class was auto-generated by the StronglyTypedResourceBuilder
 | 
			
		||||
    // class via a tool like ResGen or Visual Studio.
 | 
			
		||||
    // To add or remove a member, edit your .ResX file then rerun ResGen
 | 
			
		||||
    // with the /str option, or rebuild your VS project.
 | 
			
		||||
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
 | 
			
		||||
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 | 
			
		||||
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
 | 
			
		||||
    internal class Resources {
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Resources.ResourceManager resourceMan;
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Globalization.CultureInfo resourceCulture;
 | 
			
		||||
        
 | 
			
		||||
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
 | 
			
		||||
        internal Resources() {
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Returns the cached ResourceManager instance used by this class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Resources.ResourceManager ResourceManager {
 | 
			
		||||
            get {
 | 
			
		||||
                if (object.ReferenceEquals(resourceMan, null)) {
 | 
			
		||||
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TransportGame.MapViewer.Properties.Resources", typeof(Resources).Assembly);
 | 
			
		||||
                    resourceMan = temp;
 | 
			
		||||
                }
 | 
			
		||||
                return resourceMan;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Overrides the current thread's CurrentUICulture property for all
 | 
			
		||||
        ///   resource lookups using this strongly typed resource class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Globalization.CultureInfo Culture {
 | 
			
		||||
            get {
 | 
			
		||||
                return resourceCulture;
 | 
			
		||||
            }
 | 
			
		||||
            set {
 | 
			
		||||
                resourceCulture = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										117
									
								
								Tools/MapViewer/MapViewer/Properties/Resources.resx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								Tools/MapViewer/MapViewer/Properties/Resources.resx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,117 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<root>
 | 
			
		||||
  <!-- 
 | 
			
		||||
    Microsoft ResX Schema 
 | 
			
		||||
    
 | 
			
		||||
    Version 2.0
 | 
			
		||||
    
 | 
			
		||||
    The primary goals of this format is to allow a simple XML format 
 | 
			
		||||
    that is mostly human readable. The generation and parsing of the 
 | 
			
		||||
    various data types are done through the TypeConverter classes 
 | 
			
		||||
    associated with the data types.
 | 
			
		||||
    
 | 
			
		||||
    Example:
 | 
			
		||||
    
 | 
			
		||||
    ... ado.net/XML headers & schema ...
 | 
			
		||||
    <resheader name="resmimetype">text/microsoft-resx</resheader>
 | 
			
		||||
    <resheader name="version">2.0</resheader>
 | 
			
		||||
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
 | 
			
		||||
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
 | 
			
		||||
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
 | 
			
		||||
        <value>[base64 mime encoded serialized .NET Framework object]</value>
 | 
			
		||||
    </data>
 | 
			
		||||
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
 | 
			
		||||
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
 | 
			
		||||
        <comment>This is a comment</comment>
 | 
			
		||||
    </data>
 | 
			
		||||
                
 | 
			
		||||
    There are any number of "resheader" rows that contain simple 
 | 
			
		||||
    name/value pairs.
 | 
			
		||||
    
 | 
			
		||||
    Each data row contains a name, and value. The row also contains a 
 | 
			
		||||
    type or mimetype. Type corresponds to a .NET class that support 
 | 
			
		||||
    text/value conversion through the TypeConverter architecture. 
 | 
			
		||||
    Classes that don't support this are serialized and stored with the 
 | 
			
		||||
    mimetype set.
 | 
			
		||||
    
 | 
			
		||||
    The mimetype is used for serialized objects, and tells the 
 | 
			
		||||
    ResXResourceReader how to depersist the object. This is currently not 
 | 
			
		||||
    extensible. For a given mimetype the value must be set accordingly:
 | 
			
		||||
    
 | 
			
		||||
    Note - application/x-microsoft.net.object.binary.base64 is the format 
 | 
			
		||||
    that the ResXResourceWriter will generate, however the reader can 
 | 
			
		||||
    read any of the formats listed below.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.binary.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Serialization.Formatters.Binary.BinaryFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.soap.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.bytearray.base64
 | 
			
		||||
    value   : The object must be serialized into a byte array 
 | 
			
		||||
            : using a System.ComponentModel.TypeConverter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    -->
 | 
			
		||||
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
 | 
			
		||||
    <xsd:element name="root" msdata:IsDataSet="true">
 | 
			
		||||
      <xsd:complexType>
 | 
			
		||||
        <xsd:choice maxOccurs="unbounded">
 | 
			
		||||
          <xsd:element name="metadata">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="assembly">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:attribute name="alias" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="data">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="resheader">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" use="required" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
        </xsd:choice>
 | 
			
		||||
      </xsd:complexType>
 | 
			
		||||
    </xsd:element>
 | 
			
		||||
  </xsd:schema>
 | 
			
		||||
  <resheader name="resmimetype">
 | 
			
		||||
    <value>text/microsoft-resx</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="version">
 | 
			
		||||
    <value>2.0</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="reader">
 | 
			
		||||
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="writer">
 | 
			
		||||
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
</root>
 | 
			
		||||
							
								
								
									
										26
									
								
								Tools/MapViewer/MapViewer/Properties/Settings.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Tools/MapViewer/MapViewer/Properties/Settings.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
// <auto-generated>
 | 
			
		||||
//     This code was generated by a tool.
 | 
			
		||||
//     Runtime Version:4.0.30319.34014
 | 
			
		||||
//
 | 
			
		||||
//     Changes to this file may cause incorrect behavior and will be lost if
 | 
			
		||||
//     the code is regenerated.
 | 
			
		||||
// </auto-generated>
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace TransportGame.MapViewer.Properties {
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
 | 
			
		||||
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
 | 
			
		||||
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
 | 
			
		||||
        
 | 
			
		||||
        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
 | 
			
		||||
        
 | 
			
		||||
        public static Settings Default {
 | 
			
		||||
            get {
 | 
			
		||||
                return defaultInstance;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								Tools/MapViewer/MapViewer/Properties/Settings.settings
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Tools/MapViewer/MapViewer/Properties/Settings.settings
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
<?xml version='1.0' encoding='utf-8'?>
 | 
			
		||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
 | 
			
		||||
  <Profiles>
 | 
			
		||||
    <Profile Name="(Default)" />
 | 
			
		||||
  </Profiles>
 | 
			
		||||
  <Settings />
 | 
			
		||||
</SettingsFile>
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Tools/MapViewer/MapViewer/Resources/folder_page.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tools/MapViewer/MapViewer/Resources/folder_page.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 688 B  | 
							
								
								
									
										
											BIN
										
									
								
								Tools/MapViewer/MapViewer/Resources/picture_save.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tools/MapViewer/MapViewer/Resources/picture_save.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 755 B  | 
							
								
								
									
										28
									
								
								Tools/MapViewer/MapViewer/Storage/MapStorage.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								Tools/MapViewer/MapViewer/Storage/MapStorage.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Xml.Serialization;
 | 
			
		||||
using TransportGame.Model;
 | 
			
		||||
 | 
			
		||||
namespace TransportGame.MapViewer.Storage
 | 
			
		||||
{
 | 
			
		||||
    public static class MapStorage
 | 
			
		||||
    {
 | 
			
		||||
        public static Map Read(string file)
 | 
			
		||||
        {
 | 
			
		||||
            XmlSerializer serializer = new XmlSerializer(typeof(Map));
 | 
			
		||||
            Map map;
 | 
			
		||||
 | 
			
		||||
            using (StreamReader reader = new StreamReader(file))
 | 
			
		||||
            {
 | 
			
		||||
                map = (Map)serializer.Deserialize(reader);
 | 
			
		||||
                reader.Close();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return map;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user