From 053c4cc6d44621370dfd448744dd1c017aa8ae19 Mon Sep 17 00:00:00 2001 From: Maximilian Goldschmidt Date: Tue, 27 May 2025 22:48:00 +0200 Subject: [PATCH 01/39] First additions: Zooming, hide labels, transparent fixed islands --- .../MapTemplates/Models/MapTemplate.cs | 30 ++++++++ .../FixedIslandProperties.xaml | 18 +++++ .../UI/Controls/MapTemplateProperties.xaml | 60 +++++++++++++++- .../UI/Controls/MapTemplateProperties.xaml.cs | 7 ++ .../MapTemplatePropertiesViewModel.cs | 71 +++++++++++++++++++ .../Controls/MapTemplates/IslandControl.xaml | 5 +- .../Controls/MapTemplates/IslandViewModel.cs | 20 ++++++ AnnoMapEditor/UI/Controls/MapView.xaml | 28 +++++--- AnnoMapEditor/UI/Controls/MapView.xaml.cs | 32 +++++++-- AnnoMapEditor/UI/Windows/Main/MainWindow.xaml | 14 ++-- .../UI/Windows/Main/MainWindow.xaml.cs | 5 ++ 11 files changed, 269 insertions(+), 21 deletions(-) diff --git a/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs b/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs index 3f9f092..a2599e5 100644 --- a/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs +++ b/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs @@ -47,8 +47,16 @@ public bool ResizingInProgress public event EventHandler? MapSizeConfigCommitted; + public event EventHandler? MapZoomConfigChanged; + public string MapSizeText => $"Size: {Size.X}, Playable: {PlayableArea.Width}"; + public bool ShowLabels + { + get => _showLabels; + set => SetProperty(ref _showLabels, value); + } + private bool _showLabels = true; public MapTemplate(SessionAsset session) { @@ -100,6 +108,7 @@ public MapTemplate(int mapSize, int playableSize, SessionAsset session) // create starting spots in the default location Elements.AddRange(CreateNewStartingSpots(mapSize)); + } @@ -148,6 +157,13 @@ public void ResizeMapTemplate(int mapSize, (int x1, int y1, int x2, int y2) play MapSizeConfigChanged?.Invoke(this, new MapTemplateResizeEventArgs(oldMapSize, oldPlayableSize)); } + // public float mapZoomFactor = 1.0f; + + public void UpdateMapZoomConfig(float zoomFactor, float xTransFactor, float yTransFactor) + { + MapZoomConfigChanged?.Invoke(this, new MapZoomConfigEventArgs(zoomFactor, xTransFactor, yTransFactor)); + } + public void ResizeAndCommitMapTemplate(int mapSize, (int x1, int y1, int x2, int y2) playableAreaMargins) { if (_templateDocument.MapTemplate == null) @@ -202,5 +218,19 @@ public MapTemplateResizeEventArgs(Vector2 oldMapSize, Vector2 oldPlayableSize) public Vector2 OldMapSize { get; } public Vector2 OldPlayableSize { get; } } + + public class MapZoomConfigEventArgs : EventArgs + { + public MapZoomConfigEventArgs(float zoomFactor, float xTransFactor, float yTransFactor) + { + ZoomFactor = zoomFactor; + XTransFactor = xTransFactor; + YTransFactor = yTransFactor; + } + + public float ZoomFactor { get; } + public float XTransFactor { get; } + public float YTransFactor { get; } + } } } diff --git a/AnnoMapEditor/UI/Controls/IslandProperties/FixedIslandProperties.xaml b/AnnoMapEditor/UI/Controls/IslandProperties/FixedIslandProperties.xaml index dd562ff..018a954 100644 --- a/AnnoMapEditor/UI/Controls/IslandProperties/FixedIslandProperties.xaml +++ b/AnnoMapEditor/UI/Controls/IslandProperties/FixedIslandProperties.xaml @@ -42,6 +42,24 @@ + + + + + + + + + + + + + + + + + diff --git a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml index 1edb85f..f86a6c4 100644 --- a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml +++ b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml @@ -20,7 +20,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs index 70e0943..52e865d 100644 --- a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs +++ b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs @@ -17,6 +17,13 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA } + private void ZoomResetButtonClicked(object sender, RoutedEventArgs e) + { + if (DataContext is MapTemplatePropertiesViewModel viewModel) + { + viewModel.ResetZoom(); + } + } private void Slider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) { diff --git a/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs b/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs index 2f93919..730313a 100644 --- a/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs +++ b/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs @@ -20,6 +20,15 @@ public string MapSizeText } private string _mapSizeText = ""; + public bool ShowLabels + { + get => _mapTemplate.ShowLabels; + set + { + _mapTemplate.ShowLabels = value; + } + } + public SessionAsset SelectedSession { get => _selectedSession; @@ -46,6 +55,7 @@ private void OnSelectedRegionChanged() private void ResizeMapTemplateValues() { + if (allowMapTemplateUpdate) { if (DragInProgress) @@ -57,6 +67,11 @@ private void ResizeMapTemplateValues() } } + private void ZoomUpdate() + { + _mapTemplate.UpdateMapZoomConfig(_zoomFactor, _xTransFactor, _yTransFactor); + } + private (int x1, int y1, int x2, int y2) PlayableAreaAsTuple() { return (_mapTemplate.PlayableArea.X, _mapTemplate.PlayableArea.Y, @@ -66,6 +81,51 @@ private void ResizeMapTemplateValues() public IEnumerable SupportedSessions { get; } = SessionAsset.SupportedSessions; + public int ZoomFactor + { + get => (int)(_zoomFactor * 100f); + set + { + SetProperty(ref _zoomFactor, (float)value / 100); + ZoomFactorPercent = ((int)(_zoomFactor * 100f)).ToString() + "%"; + + + ZoomUpdate(); + } + } + private float _zoomFactor = 1.0f; + + public string ZoomFactorPercent + { + get => _zoomFactorPercent; + set + { + SetProperty(ref _zoomFactorPercent, value); + } + } + private string _zoomFactorPercent = "100%"; + + public float XTransFactor + { + get => _xTransFactor; + set + { + SetProperty(ref _xTransFactor, value); + ZoomUpdate(); + } + } + private float _xTransFactor = 0.0f; + public float YTransFactor + { + get => _yTransFactor; + set + { + SetProperty(ref _yTransFactor, value); + ZoomUpdate(); + } + } + private float _yTransFactor = 0.0f; + public int MapSize { get => _mapSize; @@ -101,6 +161,15 @@ public bool ShowPlayableAreaMargins public int MaxMapSize { get => 4096; } //Arbitrary Maximum, but larger would be absolutely useless public int MinMapSize { get => 704; } //Smallest playable Size with 4 reliable medium starter islands + public int MaxMapZoom { get => 500; } + + public void ResetZoom() + { + ZoomFactor = 100; + XTransFactor = 0f; + YTransFactor = 0f; + ZoomUpdate(); + } public bool DragInProgress { @@ -127,6 +196,8 @@ public MapTemplatePropertiesViewModel(MapTemplate mapTemplate) ResizeMapTemplateValues(); UpdateMapSizeText(); + + ZoomUpdate(); } diff --git a/AnnoMapEditor/UI/Controls/MapTemplates/IslandControl.xaml b/AnnoMapEditor/UI/Controls/MapTemplates/IslandControl.xaml index 2ced345..bea25fd 100644 --- a/AnnoMapEditor/UI/Controls/MapTemplates/IslandControl.xaml +++ b/AnnoMapEditor/UI/Controls/MapTemplates/IslandControl.xaml @@ -37,7 +37,8 @@ + Height="{Binding Island.SizeInTiles}" + Opacity="0.5"> @@ -48,7 +49,7 @@ - _showLabel; + set => SetProperty(ref _showLabel, value); + } + public bool _showLabel; + public abstract string? Label { get; } public virtual BitmapImage? Thumbnail { get; } @@ -73,9 +80,11 @@ public IslandViewModel(MapTemplate mapTemplate, IslandElement island) Island = island; UpdateBackground(); + UpdateLabelVisibility(); PropertyChanged += This_PropertyChanged; Island.PropertyChanged += Island_PropertyChanged; + _mapTemplate.PropertyChanged += MapTemplate_ConfigChanged; } @@ -97,6 +106,12 @@ private void Island_PropertyChanged(object? sender, PropertyChangedEventArgs e) BoundsCheck(); } + private void MapTemplate_ConfigChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(MapTemplate.ShowLabels)) + UpdateLabelVisibility(); + } + private void UpdateBackground() { if (IsSelected) @@ -137,5 +152,10 @@ public void BoundsCheck() Vector2 position = Element.Position; IsOutOfBounds = !position.Within(mapArea); } + + public void UpdateLabelVisibility() + { + ShowLabel = _mapTemplate.ShowLabels; + } } } diff --git a/AnnoMapEditor/UI/Controls/MapView.xaml b/AnnoMapEditor/UI/Controls/MapView.xaml index e6a97e9..7db2991 100644 --- a/AnnoMapEditor/UI/Controls/MapView.xaml +++ b/AnnoMapEditor/UI/Controls/MapView.xaml @@ -7,17 +7,29 @@ xmlns:local="clr-namespace:AnnoMapEditor.UI.Controls" mc:Ignorable="d"> - - - - - - + + + + + + + + + + + + + - - + + + + + diff --git a/AnnoMapEditor/UI/Controls/MapView.xaml.cs b/AnnoMapEditor/UI/Controls/MapView.xaml.cs index fc61c58..18c3bae 100644 --- a/AnnoMapEditor/UI/Controls/MapView.xaml.cs +++ b/AnnoMapEditor/UI/Controls/MapView.xaml.cs @@ -139,6 +139,9 @@ private static void ShowPlayableAreaMarginsPropertyChangedCallback(DependencyObj #endregion playable area + private float _zoomFactor = 1f; + private float _xTransFactor = 0.0f; + private float _yTransFactor = 0.0f; public MapView() { @@ -578,15 +581,25 @@ void UpdateSize() { if (_mapTemplate is null) return; - - double size = Math.Min(ActualWidth, ActualHeight); + + double size = Math.Min(canvasGrid.ActualWidth, canvasGrid.ActualHeight); size = Math.Sqrt((size * size) / 2); double requiredScaleX = size / _mapTemplate.Size.X; double requiredScaleY = size / _mapTemplate.Size.Y; - float scale = (float)Math.Min(requiredScaleX, requiredScaleY); + float scale = (float)(Math.Min(requiredScaleX, requiredScaleY)); + + TransformGroup mapRenderTransform = new(); + + double defaultTransform = size * ((_zoomFactor - 1) / -2); + + double actualXTransform = defaultTransform + (_xTransFactor / 2 * (_zoomFactor - 1) * size) + (_yTransFactor / 2 * (_zoomFactor - 1) * size); + double actualYTransform = defaultTransform + (_yTransFactor / 2 * (_zoomFactor - 1) * size) - (_xTransFactor / 2 * (_zoomFactor - 1) * size); + + mapRenderTransform.Children.Add(new ScaleTransform(scale * _zoomFactor, scale * _zoomFactor)); + mapRenderTransform.Children.Add(new TranslateTransform(actualXTransform, actualYTransform)); - mapTemplateCanvas.RenderTransform = new ScaleTransform(scale, scale); + mapTemplateCanvas.RenderTransform = mapRenderTransform; rotationCanvas.Width = scale * _mapTemplate.Size.X; rotationCanvas.Height = scale * _mapTemplate.Size.Y; } @@ -596,12 +609,23 @@ private void LinkMapTemplateEventHandlers(MapTemplate mapTemplate) mapTemplate.MapSizeConfigChanged += MapElement_MapSizeConfigChanged; mapTemplate.MapSizeConfigCommitted += MapElement_MapSizeConfigCommitted; mapTemplate.Elements.CollectionChanged += MapElement_ElementsChanged; + mapTemplate.MapZoomConfigChanged += MapElement_MapZoomConfigChanged; } private void UnlinkMapTemplateEventHandlers(MapTemplate mapTemplate) { mapTemplate.MapSizeConfigCommitted -= MapElement_MapSizeConfigCommitted; mapTemplate.MapSizeConfigChanged -= MapElement_MapSizeConfigChanged; mapTemplate.Elements.CollectionChanged -= MapElement_ElementsChanged; + mapTemplate.MapZoomConfigChanged -= MapElement_MapZoomConfigChanged; + } + + private void MapElement_MapZoomConfigChanged(object? sender, MapTemplate.MapZoomConfigEventArgs args) + { + _zoomFactor = args.ZoomFactor; + _xTransFactor = args.XTransFactor; + _yTransFactor = args.YTransFactor; + + UpdateSize(); } private void MapElement_ElementsChanged(object? sender, NotifyCollectionChangedEventArgs e) diff --git a/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml b/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml index 353c4eb..6eba66e 100644 --- a/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml +++ b/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml @@ -50,12 +50,13 @@ + Background="#7f000000"> - + @@ -73,17 +74,18 @@ - + - + HorizontalAlignment="Stretch" /> + - + diff --git a/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml.cs b/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml.cs index fb74418..c82393d 100644 --- a/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml.cs +++ b/AnnoMapEditor/UI/Windows/Main/MainWindow.xaml.cs @@ -79,5 +79,10 @@ private void ExportMod_Click(object sender, RoutedEventArgs e) OverlayService.Instance.Show(new ExportAsModViewModel(_viewModel.MapTemplate)); } + + private void OverlayContainer_Loaded(object sender, RoutedEventArgs e) + { + + } } } From 60632f4ed8c1e22571118be44cd2d37d28b1bea9 Mon Sep 17 00:00:00 2001 From: Maximilian Goldschmidt Date: Tue, 27 May 2025 23:01:09 +0200 Subject: [PATCH 02/39] Update workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d60b60c..e0d9076 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,7 +41,7 @@ jobs: # run: tar --exclude='*.pdb' -caf AnnoMapEditor.zip -C ./Build/ * - name: Upload - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: AnnoMapEditor path: Build/AnnoMapEditor.exe From 6a5c13dceccec3f17922e49a3d4fabc5251a18b3 Mon Sep 17 00:00:00 2001 From: Maximilian Goldschmidt Date: Wed, 28 May 2025 22:39:04 +0200 Subject: [PATCH 03/39] Implemented Zoom with Scroll Wheel and Map Dragging with Right Click --- .../UI/Controls/MapTemplateProperties.xaml | 65 +---------- .../UI/Controls/MapTemplateProperties.xaml.cs | 8 -- .../MapTemplatePropertiesViewModel.cs | 70 ------------ AnnoMapEditor/UI/Controls/MapView.xaml | 13 ++- AnnoMapEditor/UI/Controls/MapView.xaml.cs | 107 +++++++++++++++--- 5 files changed, 107 insertions(+), 156 deletions(-) diff --git a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml index f86a6c4..fe482e2 100644 --- a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml +++ b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml @@ -57,7 +57,7 @@ - + @@ -86,72 +86,11 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs index 52e865d..8332b6a 100644 --- a/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs +++ b/AnnoMapEditor/UI/Controls/MapTemplateProperties.xaml.cs @@ -16,14 +16,6 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA { } - - private void ZoomResetButtonClicked(object sender, RoutedEventArgs e) - { - if (DataContext is MapTemplatePropertiesViewModel viewModel) - { - viewModel.ResetZoom(); - } - } private void Slider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) { diff --git a/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs b/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs index 730313a..5272816 100644 --- a/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs +++ b/AnnoMapEditor/UI/Controls/MapTemplatePropertiesViewModel.cs @@ -20,15 +20,6 @@ public string MapSizeText } private string _mapSizeText = ""; - public bool ShowLabels - { - get => _mapTemplate.ShowLabels; - set - { - _mapTemplate.ShowLabels = value; - } - } - public SessionAsset SelectedSession { get => _selectedSession; @@ -67,11 +58,6 @@ private void ResizeMapTemplateValues() } } - private void ZoomUpdate() - { - _mapTemplate.UpdateMapZoomConfig(_zoomFactor, _xTransFactor, _yTransFactor); - } - private (int x1, int y1, int x2, int y2) PlayableAreaAsTuple() { return (_mapTemplate.PlayableArea.X, _mapTemplate.PlayableArea.Y, @@ -81,51 +67,6 @@ private void ZoomUpdate() public IEnumerable SupportedSessions { get; } = SessionAsset.SupportedSessions; - public int ZoomFactor - { - get => (int)(_zoomFactor * 100f); - set - { - SetProperty(ref _zoomFactor, (float)value / 100); - ZoomFactorPercent = ((int)(_zoomFactor * 100f)).ToString() + "%"; - - - ZoomUpdate(); - } - } - private float _zoomFactor = 1.0f; - - public string ZoomFactorPercent - { - get => _zoomFactorPercent; - set - { - SetProperty(ref _zoomFactorPercent, value); - } - } - private string _zoomFactorPercent = "100%"; - - public float XTransFactor - { - get => _xTransFactor; - set - { - SetProperty(ref _xTransFactor, value); - ZoomUpdate(); - } - } - private float _xTransFactor = 0.0f; - public float YTransFactor - { - get => _yTransFactor; - set - { - SetProperty(ref _yTransFactor, value); - ZoomUpdate(); - } - } - private float _yTransFactor = 0.0f; - public int MapSize { get => _mapSize; @@ -161,15 +102,6 @@ public bool ShowPlayableAreaMargins public int MaxMapSize { get => 4096; } //Arbitrary Maximum, but larger would be absolutely useless public int MinMapSize { get => 704; } //Smallest playable Size with 4 reliable medium starter islands - public int MaxMapZoom { get => 500; } - - public void ResetZoom() - { - ZoomFactor = 100; - XTransFactor = 0f; - YTransFactor = 0f; - ZoomUpdate(); - } public bool DragInProgress { @@ -196,8 +128,6 @@ public MapTemplatePropertiesViewModel(MapTemplate mapTemplate) ResizeMapTemplateValues(); UpdateMapSizeText(); - - ZoomUpdate(); } diff --git a/AnnoMapEditor/UI/Controls/MapView.xaml b/AnnoMapEditor/UI/Controls/MapView.xaml index 7db2991..a2ef303 100644 --- a/AnnoMapEditor/UI/Controls/MapView.xaml +++ b/AnnoMapEditor/UI/Controls/MapView.xaml @@ -6,13 +6,20 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:AnnoMapEditor.UI.Controls" mc:Ignorable="d"> + + + + + + + - + @@ -29,7 +36,9 @@ - + + + - + - - + + + - -