Implemented layers for MapViewer, fixed some issues.
This commit is contained in:
parent
c96de53ec8
commit
8f9f935796
@ -23,7 +23,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(MonoDevelopProperties) = preSolution
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
StartupItem = Assembly-CSharp.csproj
|
StartupItem = Assembly-CSharp.csproj
|
||||||
Policies = $0
|
Policies = $0
|
||||||
$0.TextStylePolicy = $1
|
$0.TextStylePolicy = $1
|
||||||
|
@ -29,7 +29,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(MonoDevelopProperties) = preSolution
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
StartupItem = Assembly-CSharp.csproj
|
StartupItem = Assembly-CSharp.csproj
|
||||||
Policies = $0
|
Policies = $0
|
||||||
$0.TextStylePolicy = $1
|
$0.TextStylePolicy = $1
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -7,14 +7,16 @@
|
|||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{02576F1D-BE9C-CFA7-763D-1EBF63B36977}</ProjectGuid>
|
<ProjectGuid>{02576F1D-BE9C-CFA7-763D-1EBF63B36977}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<RootNamespace></RootNamespace>
|
<RootNamespace>
|
||||||
|
</RootNamespace>
|
||||||
<AssemblyName>Assembly-CSharp</AssemblyName>
|
<AssemblyName>Assembly-CSharp</AssemblyName>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
|
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
|
||||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
|
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
|
||||||
<CompilerResponseFile></CompilerResponseFile>
|
<CompilerResponseFile>
|
||||||
|
</CompilerResponseFile>
|
||||||
<UnityProjectType>Game:1</UnityProjectType>
|
<UnityProjectType>Game:1</UnityProjectType>
|
||||||
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
|
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
|
||||||
<UnityVersion>5.0.0f4</UnityVersion>
|
<UnityVersion>5.0.0f4</UnityVersion>
|
||||||
@ -86,8 +88,10 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
||||||
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
||||||
<None Include="Assets\Data\Config\tergen.xml" />
|
<None Include="Assets\Data\Config\tergen.xml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</None>
|
||||||
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
<None Include="Assets\Standard Assets\Environment\Water (Basic)\Shaders\FXWaterBasic.shader" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2012\UnityVS.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2012\UnityVS.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
Binary file not shown.
@ -41,7 +41,7 @@ namespace TransportGame.MapViewer
|
|||||||
|
|
||||||
private readonly Color WaterColor = Colors.Navy;
|
private readonly Color WaterColor = Colors.Navy;
|
||||||
private readonly Color ElevationTerrainColor = Colors.White;
|
private readonly Color ElevationTerrainColor = Colors.White;
|
||||||
private readonly Color TerrainColor = Colors.White;
|
private readonly Color TerrainColor = Colors.Gray;
|
||||||
|
|
||||||
public MapRenderer()
|
public MapRenderer()
|
||||||
{
|
{
|
||||||
|
@ -22,20 +22,16 @@
|
|||||||
<Image Source="pack://application:,,,/Resources/picture_save.png" />
|
<Image Source="pack://application:,,,/Resources/picture_save.png" />
|
||||||
</Button>
|
</Button>
|
||||||
<Separator />
|
<Separator />
|
||||||
<TextBlock VerticalAlignment="Center" Margin="4,2,4,2">Zoom:</TextBlock>
|
|
||||||
<Slider Name="zoomSlider" Width="80"
|
<Button Name="buttonZoomIn" ToolTip="Zoom in" Click="buttonZoomIn_Click">
|
||||||
Minimum="1" Maximum="15"
|
<Image Source="pack://application:,,,/Resources/zoom_in.png" />
|
||||||
SmallChange="1" LargeChange="3"
|
</Button>
|
||||||
TickPlacement="BottomRight"
|
<Button Name="buttonZoomOut" ToolTip="Zoom out" Click="buttonZoomOut_Click">
|
||||||
Ticks="1,2,5,10,15"
|
<Image Source="pack://application:,,,/Resources/zoom_out.png" />
|
||||||
Value="{Binding Renderer.Scale}"
|
</Button>
|
||||||
ValueChanged="zoomSlider_ValueChanged">
|
|
||||||
<Slider.ToolTip>
|
|
||||||
<ToolTip Content="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.Value}" />
|
|
||||||
</Slider.ToolTip>
|
|
||||||
</Slider>
|
|
||||||
<TextBlock VerticalAlignment="Center">
|
<TextBlock VerticalAlignment="Center">
|
||||||
<Run Text="{Binding ElementName=zoomSlider, Path=Value}" /><Run>00%</Run>
|
<Run Text="{Binding ZoomLevel}" /><Run>00%</Run>
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
|
|
||||||
@ -62,19 +58,14 @@
|
|||||||
|
|
||||||
<Expander IsExpanded="True" Header="Layers">
|
<Expander IsExpanded="True" Header="Layers">
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<CheckBox>Elevation</CheckBox>
|
<CheckBox IsChecked="{Binding LayersAll}">(All)</CheckBox>
|
||||||
|
<CheckBox IsChecked="{Binding LayerElevation}">Elevation</CheckBox>
|
||||||
<CheckBox>Roads</CheckBox>
|
<CheckBox>Roads</CheckBox>
|
||||||
<CheckBox>Buildings</CheckBox>
|
<CheckBox>Buildings</CheckBox>
|
||||||
<CheckBox>Vegetation</CheckBox>
|
<CheckBox>Vegetation</CheckBox>
|
||||||
|
|
||||||
<Grid>
|
<Button Name="buttonRender" Grid.Column="1" Content="Render" Click="buttonRender_Click" />
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition />
|
|
||||||
<ColumnDefinition />
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
<Button Grid.Column="0" Content="Select all" />
|
|
||||||
<Button Grid.Column="1" Content="Render" />
|
|
||||||
</Grid>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Expander>
|
</Expander>
|
||||||
<Expander IsExpanded="True" Header="General">
|
<Expander IsExpanded="True" Header="General">
|
||||||
|
@ -15,12 +15,19 @@ namespace TransportGame.MapViewer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window, INotifyPropertyChanged
|
public partial class MainWindow : Window, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
private MapRenderer.Layers _layers = MapRenderer.Layers.All;
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
#region Public properties
|
||||||
|
|
||||||
#region Map property
|
#region Map property
|
||||||
|
|
||||||
private Map _map;
|
private Map _map;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the map displayed by the map viewer.
|
||||||
|
/// </summary>
|
||||||
public Map Map
|
public Map Map
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -42,6 +49,9 @@ namespace TransportGame.MapViewer
|
|||||||
|
|
||||||
private string _loadedFile;
|
private string _loadedFile;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path of the currently loaded map file.
|
||||||
|
/// </summary>
|
||||||
public string LoadedFile
|
public string LoadedFile
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -63,6 +73,9 @@ namespace TransportGame.MapViewer
|
|||||||
|
|
||||||
private BitmapSource _renderedMap;
|
private BitmapSource _renderedMap;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the rendered map bitmap
|
||||||
|
/// </summary>
|
||||||
public BitmapSource RenderedMap
|
public BitmapSource RenderedMap
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -81,8 +94,85 @@ namespace TransportGame.MapViewer
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the map renderer
|
||||||
|
/// </summary>
|
||||||
public MapRenderer Renderer { get; private set; }
|
public MapRenderer Renderer { get; private set; }
|
||||||
|
|
||||||
|
#region Renderer layers
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets all the layers
|
||||||
|
/// </summary>
|
||||||
|
public bool? LayersAll
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (LayerElevation)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!LayerElevation)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
LayerElevation = value.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the layer elevation layer flag
|
||||||
|
/// </summary>
|
||||||
|
public bool LayerElevation
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _layers.HasFlag(MapRenderer.Layers.Elevation);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value) _layers |= MapRenderer.Layers.Elevation;
|
||||||
|
else _layers &= ~MapRenderer.Layers.Elevation;
|
||||||
|
|
||||||
|
if (PropertyChanged != null)
|
||||||
|
{
|
||||||
|
PropertyChanged(this, new PropertyChangedEventArgs("LayerElevation"));
|
||||||
|
PropertyChanged(this, new PropertyChangedEventArgs("LayersAll"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the zoom level
|
||||||
|
/// </summary>
|
||||||
|
public int ZoomLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Renderer.Scale;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Renderer.Scale = value;
|
||||||
|
if (PropertyChanged != null)
|
||||||
|
PropertyChanged(this, new PropertyChangedEventArgs("ZoomLevel"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructor
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the main window
|
||||||
|
/// </summary>
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -92,12 +182,121 @@ namespace TransportGame.MapViewer
|
|||||||
DataContext = this;
|
DataContext = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
private async Task OpenMapFile(string filename)
|
private async Task OpenMapFile(string filename)
|
||||||
{
|
{
|
||||||
await LoadMap(filename);
|
await LoadMap(filename);
|
||||||
await RenderMap();
|
await RenderMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, _layers);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
progress.Visibility = System.Windows.Visibility.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region UI Event handlers
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// Show save dialog
|
||||||
|
string filename;
|
||||||
|
if (!ShowSaveMapDialog(out filename))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Save to filename
|
||||||
|
var encoder = new PngBitmapEncoder();
|
||||||
|
encoder.Frames.Add(BitmapFrame.Create(RenderedMap));
|
||||||
|
|
||||||
|
using (var writer = File.OpenWrite(filename))
|
||||||
|
{
|
||||||
|
encoder.Save(writer);
|
||||||
|
writer.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void buttonZoomIn_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// Zoom
|
||||||
|
ZoomLevel++;
|
||||||
|
|
||||||
|
// Update IsEnabled
|
||||||
|
if (ZoomLevel >= 10)
|
||||||
|
buttonZoomIn.IsEnabled = false;
|
||||||
|
buttonZoomOut.IsEnabled = true;
|
||||||
|
|
||||||
|
// Render
|
||||||
|
if (Map != null)
|
||||||
|
await RenderMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void buttonZoomOut_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// Zoom
|
||||||
|
ZoomLevel--;
|
||||||
|
|
||||||
|
// Update IsEnabled
|
||||||
|
if (ZoomLevel <= 1)
|
||||||
|
buttonZoomOut.IsEnabled = false;
|
||||||
|
buttonZoomIn.IsEnabled = true;
|
||||||
|
|
||||||
|
// Render
|
||||||
|
if (Map != null)
|
||||||
|
await RenderMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void buttonRender_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (Map != null)
|
||||||
|
await RenderMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helper static functions
|
||||||
|
|
||||||
private static bool ShowOpenMapDialog(out string filename)
|
private static bool ShowOpenMapDialog(out string filename)
|
||||||
{
|
{
|
||||||
OpenFileDialog dialog = new OpenFileDialog();
|
OpenFileDialog dialog = new OpenFileDialog();
|
||||||
@ -134,69 +333,7 @@ namespace TransportGame.MapViewer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadMap(string filename)
|
#endregion
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,10 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="Resources\folder_page.png" />
|
<Resource Include="Resources\folder_page.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Resource Include="Resources\zoom_in.png" />
|
||||||
|
<Resource Include="Resources\zoom_out.png" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
BIN
Tools/MapViewer/MapViewer/Resources/zoom_in.png
Normal file
BIN
Tools/MapViewer/MapViewer/Resources/zoom_in.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 725 B |
BIN
Tools/MapViewer/MapViewer/Resources/zoom_out.png
Normal file
BIN
Tools/MapViewer/MapViewer/Resources/zoom_out.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 708 B |
Loading…
Reference in New Issue
Block a user