feat: add map levels
This commit is contained in:
		| @@ -13,6 +13,10 @@ | ||||
|         MouseLeave="ContentControl_MouseLeave" | ||||
|         MouseMove="ContentControl_MouseMove" | ||||
|         > | ||||
|     <ContentControl.Resources> | ||||
|         <BitmapImage x:Key="FallbackImage" UriSource="../../Assets/maps/fallback.jpg" /> | ||||
|         <Int32Collection x:Key="mapLevels">0,1,2,3,4,5</Int32Collection> | ||||
|     </ContentControl.Resources> | ||||
|     <Grid Background="Transparent"> | ||||
|         <Grid.InputBindings> | ||||
|             <MouseBinding Gesture="LeftClick" Command="{Binding MouseLeftClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Grid}}" /> | ||||
| @@ -29,7 +33,7 @@ | ||||
|             <ItemsControl.ItemTemplate> | ||||
|                 <DataTemplate> | ||||
|                     <Image | ||||
|                         Source="{Binding ImageSource,Mode=OneWay}" | ||||
|                         Source="{Binding ImageSource,Mode=OneWay,FallbackValue={StaticResource FallbackImage},TargetNullValue={StaticResource FallbackImage}}" | ||||
|                         Width="{Binding Size,Mode=OneWay}" | ||||
|                         Height="{Binding Size,Mode=OneWay}" | ||||
|                         Visibility="{Binding Visible,Converter={StaticResource BooleanToVisibilityConverter}}" | ||||
| @@ -286,10 +290,17 @@ | ||||
|         <StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Right" Background="#66ffffff"> | ||||
|             <Grid Margin="10 5"> | ||||
|                 <Grid.ColumnDefinitions> | ||||
|                     <ColumnDefinition Width="Auto"></ColumnDefinition> | ||||
|                     <ColumnDefinition Width="90"></ColumnDefinition> | ||||
|                     <ColumnDefinition Width="30"></ColumnDefinition> | ||||
|                 </Grid.ColumnDefinitions> | ||||
|                 <TextBlock Padding="0 0 0 3"> | ||||
|                 <StackPanel Orientation="Horizontal"> | ||||
|                     <Label>Map level:</Label> | ||||
|                     <ComboBox | ||||
|                         SelectedValue="{Binding MapLevel}" | ||||
|                         ItemsSource="{StaticResource mapLevels}" Margin="0,0,10,0"/> | ||||
|                 </StackPanel> | ||||
|                 <TextBlock Grid.Column="1" Padding="0 0 0 3" VerticalAlignment="Center"> | ||||
|                     <TextBlock.Text> | ||||
|                         <MultiBinding StringFormat="{}{0:F0}, {1:F0}"> | ||||
|                             <Binding Path="MousePosition.X" Mode="OneWay"/> | ||||
| @@ -297,7 +308,7 @@ | ||||
|                         </MultiBinding> | ||||
|                     </TextBlock.Text> | ||||
|                 </TextBlock> | ||||
|                 <TextBlock Grid.Column="1" Text="{Binding Scale,Mode=OneWay,StringFormat='{}1:{0}'}" HorizontalAlignment="Right" /> | ||||
|                 <Label Grid.Column="2" Content="{Binding Scale,Mode=OneWay,StringFormat='{}1:{0}'}" HorizontalAlignment="Right" /> | ||||
|             </Grid> | ||||
|         </StackPanel> | ||||
|     </Grid> | ||||
|   | ||||
| @@ -11,7 +11,7 @@ namespace Client.Application.ViewModels | ||||
| { | ||||
|     public class MapBlockViewModel : ObservableObject | ||||
|     { | ||||
|         public string ImageSource => "/Assets/maps/" + mapBlock.BlockX + "_" + mapBlock.BlockY + ".jpg"; | ||||
|         public string ImageSource => "/Assets/maps/" + mapBlock.BlockX + "_" + mapBlock.BlockY + (mapBlock.Level > 0 ? "_" + mapBlock.Level : "") + ".jpg"; | ||||
|         public float DeltaX => mapBlock.DeltaX; | ||||
|         public float DeltaY => mapBlock.DeltaY; | ||||
|         public float Size => mapBlock.Size; | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Client.Application.Commands; | ||||
| using Client.Application.Components; | ||||
| using Client.Domain.Common; | ||||
| using Client.Domain.DTO; | ||||
| using Client.Domain.Entities; | ||||
| @@ -83,6 +84,19 @@ namespace Client.Application.ViewModels | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public int MapLevel | ||||
|         { | ||||
|             get => mapLevel; | ||||
|             set | ||||
|             { | ||||
|                 if (mapLevel != value) | ||||
|                 { | ||||
|                     mapLevel = value; | ||||
|                     UpdateMap(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public Vector3 MousePosition | ||||
|         { | ||||
|             get => mousePosition; | ||||
| @@ -107,7 +121,7 @@ namespace Client.Application.ViewModels | ||||
|  | ||||
|             if (hero != null) | ||||
|             { | ||||
|                 var blocks = selector.SelectImages((float)ViewportWidth, (float)ViewportHeight, hero.Transform.Position, Scale); | ||||
|                 var blocks = selector.SelectImages((float)ViewportWidth, (float)ViewportHeight, hero.Transform.Position, Scale, MapLevel); | ||||
|  | ||||
|                 foreach (var block in blocks) | ||||
|                 { | ||||
| @@ -328,7 +342,7 @@ namespace Client.Application.ViewModels | ||||
|         public readonly static float MAX_SCALE = 128; | ||||
|         private readonly AsyncPathMoverInterface pathMover; | ||||
|         private MapImageSelector selector = new MapImageSelector(); | ||||
|         private Dictionary<uint, MapBlockViewModel> blocks = new Dictionary<uint, MapBlockViewModel>(); | ||||
|         private Dictionary<int, MapBlockViewModel> blocks = new Dictionary<int, MapBlockViewModel>(); | ||||
|         private Hero? hero; | ||||
|         private float scale = 8; | ||||
|         private double viewportWidth = 0; | ||||
| @@ -336,5 +350,6 @@ namespace Client.Application.ViewModels | ||||
|         private Vector3 mousePosition = new Vector3(0, 0, 0); | ||||
|         private object pathCollectionLock = new object(); | ||||
|         private AICombatZoneMapViewModel? combatZone = null; | ||||
|         private int mapLevel = 0; | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								Client/Assets/maps/fallback.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Client/Assets/maps/fallback.jpg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 17 KiB | 
| @@ -14,7 +14,7 @@ namespace Client.Domain.Service | ||||
|         private static readonly uint DELTA_X = 20; | ||||
|         private static readonly uint DELTA_Y = 18; | ||||
|  | ||||
|         public List<MapBlock> SelectImages(float viewportWidth, float viewportHeight, Vector3 heroPosition, float scale) | ||||
|         public List<MapBlock> SelectImages(float viewportWidth, float viewportHeight, Vector3 heroPosition, float scale, int level) | ||||
|         { | ||||
|             var viewportCenter = new Tuple<float, float>(viewportWidth / 2, viewportHeight / 2); | ||||
|  | ||||
| @@ -46,7 +46,7 @@ namespace Client.Domain.Service | ||||
|                         (blockTopLeft.Item2 - topLeft.Item2) / scale | ||||
|                     ); | ||||
|  | ||||
|                     result.Add(new MapBlock(x, y, delta.Item1, delta.Item2, BLOCK_SIZE / scale)); | ||||
|                     result.Add(new MapBlock(x, y, delta.Item1, delta.Item2, BLOCK_SIZE / scale, level)); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|   | ||||
| @@ -13,20 +13,24 @@ namespace Client.Domain.ValueObjects | ||||
|         private float deltaY; | ||||
|         private float size; | ||||
|  | ||||
|         public uint Id => (BlockX + BlockY) * (BlockX + BlockY + 1) / 2 + BlockX; | ||||
|         public int Id => (IdWithOutLevel + Level) * (IdWithOutLevel + Level + 1) / 2 + IdWithOutLevel; | ||||
|         public uint BlockX { get; set; } | ||||
|         public uint BlockY { get; set; } | ||||
|         public float DeltaX { get => deltaX; set { if (value != deltaX) { deltaX = value; OnPropertyChanged(); } } } | ||||
|         public float DeltaY { get => deltaY; set { if (value != deltaY) { deltaY = value; OnPropertyChanged(); } } } | ||||
|         public float Size { get => size; set { if (value != size) { size = value; OnPropertyChanged(); } } } | ||||
|         public int Level { get; set; } | ||||
|  | ||||
|         public MapBlock(uint blockX, uint blockY, float deltaX, float deltaY, float size) | ||||
|         private int IdWithOutLevel => (int) ((BlockX + BlockY) * (BlockX + BlockY + 1) / 2 + BlockX); | ||||
|  | ||||
|         public MapBlock(uint blockX, uint blockY, float deltaX, float deltaY, float size, int level) | ||||
|         { | ||||
|             BlockX = blockX; | ||||
|             BlockY = blockY; | ||||
|             DeltaX = deltaX; | ||||
|             DeltaY = deltaY; | ||||
|             Size = size; | ||||
|             Level = level; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Иванов Иван
					Иванов Иван