Implemented layers for MapViewer, fixed some issues.
This commit is contained in:
parent
c96de53ec8
commit
8f9f935796
@ -23,7 +23,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Assembly-CSharp.csproj
|
||||
Policies = $0
|
||||
$0.TextStylePolicy = $1
|
||||
|
@ -29,7 +29,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Assembly-CSharp.csproj
|
||||
Policies = $0
|
||||
$0.TextStylePolicy = $1
|
||||
|
Binary file not shown.
Binary file not shown.
@ -7,14 +7,16 @@
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{02576F1D-BE9C-CFA7-763D-1EBF63B36977}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace></RootNamespace>
|
||||
<RootNamespace>
|
||||
</RootNamespace>
|
||||
<AssemblyName>Assembly-CSharp</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
|
||||
<CompilerResponseFile></CompilerResponseFile>
|
||||
<CompilerResponseFile>
|
||||
</CompilerResponseFile>
|
||||
<UnityProjectType>Game:1</UnityProjectType>
|
||||
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
|
||||
<UnityVersion>5.0.0f4</UnityVersion>
|
||||
@ -86,7 +88,9 @@
|
||||
<ItemGroup>
|
||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.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" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2012\UnityVS.CSharp.targets" />
|
||||
|
Binary file not shown.
@ -41,7 +41,7 @@ namespace TransportGame.MapViewer
|
||||
|
||||
private readonly Color WaterColor = Colors.Navy;
|
||||
private readonly Color ElevationTerrainColor = Colors.White;
|
||||
private readonly Color TerrainColor = Colors.White;
|
||||
private readonly Color TerrainColor = Colors.Gray;
|
||||
|
||||
public MapRenderer()
|
||||
{
|
||||
|
@ -22,20 +22,16 @@
|
||||
<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>
|
||||
|
||||
<Button Name="buttonZoomIn" ToolTip="Zoom in" Click="buttonZoomIn_Click">
|
||||
<Image Source="pack://application:,,,/Resources/zoom_in.png" />
|
||||
</Button>
|
||||
<Button Name="buttonZoomOut" ToolTip="Zoom out" Click="buttonZoomOut_Click">
|
||||
<Image Source="pack://application:,,,/Resources/zoom_out.png" />
|
||||
</Button>
|
||||
|
||||
<TextBlock VerticalAlignment="Center">
|
||||
<Run Text="{Binding ElementName=zoomSlider, Path=Value}" /><Run>00%</Run>
|
||||
<Run Text="{Binding ZoomLevel}" /><Run>00%</Run>
|
||||
</TextBlock>
|
||||
</ToolBar>
|
||||
|
||||
@ -62,19 +58,14 @@
|
||||
|
||||
<Expander IsExpanded="True" Header="Layers">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<CheckBox>Elevation</CheckBox>
|
||||
<CheckBox IsChecked="{Binding LayersAll}">(All)</CheckBox>
|
||||
<CheckBox IsChecked="{Binding LayerElevation}">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>
|
||||
<Button Name="buttonRender" Grid.Column="1" Content="Render" Click="buttonRender_Click" />
|
||||
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
<Expander IsExpanded="True" Header="General">
|
||||
|
@ -15,12 +15,19 @@ namespace TransportGame.MapViewer
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window, INotifyPropertyChanged
|
||||
{
|
||||
private MapRenderer.Layers _layers = MapRenderer.Layers.All;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
#region Public properties
|
||||
|
||||
#region Map property
|
||||
|
||||
private Map _map;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the map displayed by the map viewer.
|
||||
/// </summary>
|
||||
public Map Map
|
||||
{
|
||||
get
|
||||
@ -42,6 +49,9 @@ namespace TransportGame.MapViewer
|
||||
|
||||
private string _loadedFile;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the currently loaded map file.
|
||||
/// </summary>
|
||||
public string LoadedFile
|
||||
{
|
||||
get
|
||||
@ -63,6 +73,9 @@ namespace TransportGame.MapViewer
|
||||
|
||||
private BitmapSource _renderedMap;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendered map bitmap
|
||||
/// </summary>
|
||||
public BitmapSource RenderedMap
|
||||
{
|
||||
get
|
||||
@ -81,8 +94,85 @@ namespace TransportGame.MapViewer
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the map renderer
|
||||
/// </summary>
|
||||
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()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -92,12 +182,121 @@ namespace TransportGame.MapViewer
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private async Task OpenMapFile(string filename)
|
||||
{
|
||||
await LoadMap(filename);
|
||||
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)
|
||||
{
|
||||
OpenFileDialog dialog = new OpenFileDialog();
|
||||
@ -134,69 +333,7 @@ namespace TransportGame.MapViewer
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task LoadMap(string filename)
|
||||
{
|
||||
progress.Visibility = System.Windows.Visibility.Visible;
|
||||
progressText.Text = "Loading map...";
|
||||
#endregion
|
||||
|
||||
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>
|
||||
<Resource Include="Resources\folder_page.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\zoom_in.png" />
|
||||
<Resource Include="Resources\zoom_out.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.
|
||||
|
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