From c55ced5cbc3f91c9716e952f96de4cc85980097d Mon Sep 17 00:00:00 2001 From: haven1433 Date: Sun, 6 Nov 2022 20:20:11 -0600 Subject: [PATCH] bugfixes --- .../ViewModels/EditorViewModel.cs | 8 ++++- .../ViewModels/Map/BlockMapViewModel.cs | 14 ++++---- .../ViewModels/Map/MapEditorViewModel.cs | 32 ++++++++++--------- src/HexManiac.Core/ViewModels/ViewPort.cs | 5 ++- src/HexManiac.WPF/Controls/MapTab.xaml | 6 ++-- src/HexManiac.WPF/Controls/MapTab.xaml.cs | 5 +++ 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/HexManiac.Core/ViewModels/EditorViewModel.cs b/src/HexManiac.Core/ViewModels/EditorViewModel.cs index 64fc90ea..862a2f87 100644 --- a/src/HexManiac.Core/ViewModels/EditorViewModel.cs +++ b/src/HexManiac.Core/ViewModels/EditorViewModel.cs @@ -659,7 +659,13 @@ namespace HavenSoft.HexManiac.Core.ViewModels { toggleScrollAnimation.Execute = arg => AnimateScroll = !AnimateScroll; resetZoom.CanExecute = CanAlwaysExecute; - resetZoom.Execute = arg => ZoomLevel = 16; + resetZoom.Execute = arg => { + ZoomLevel = 16; + foreach(var tab in this) { + if (tab is not MapEditorViewModel mapTab) continue; + mapTab.ResetZoom(); + } + }; resetTheme.CanExecute = CanAlwaysExecute; resetTheme.Execute = arg => Theme.Reset(); diff --git a/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs b/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs index 065e55d3..40a23069 100644 --- a/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs +++ b/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs @@ -919,16 +919,14 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { var border = GetBorderThickness(layout); var tileX = (int)((x - LeftEdge) / SpriteScale / 16) - border.West; var tileY = (int)((y - TopEdge) / SpriteScale / 16) - border.North; + IEventViewModel last = null; foreach (var e in GetEvents()) { - if (e.X == tileX && e.Y == tileY) { - if (autoSelect) SelectedEvent = e; - pixelData = null; - NotifyPropertyChanged(nameof(PixelData)); - return e; - } + if (e.X == tileX && e.Y == tileY) last = e; } - if (autoSelect) SelectedEvent = null; - return null; + if (autoSelect) SelectedEvent = last; + pixelData = null; + NotifyPropertyChanged(nameof(PixelData)); + return last; } public IPixelViewModel AutoCrop(int warpID) { diff --git a/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs b/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs index 379b643d..63472c3a 100644 --- a/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs +++ b/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs @@ -4,6 +4,7 @@ using HavenSoft.HexManiac.Core.Models.Runs; using HavenSoft.HexManiac.Core.Models.Runs.Sprites; using HavenSoft.HexManiac.Core.ViewModels.DataFormats; using HavenSoft.HexManiac.Core.ViewModels.Images; +using IronPython.Runtime; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -176,19 +177,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { public ICommand Back => StubCommand(ref backCommand, ExecuteBack, CanExecuteBack); public ICommand Forward => StubCommand(ref forwardCommand, ExecuteForward, CanExecuteForward); - private GameReferenceTables RefTable => singletons.GameReferenceTables.TryGetValue(model.GetGameCode(), out var refTable) ? refTable : null; - public ICommand Close => StubCommand(ref close, () => { - if (!history.IsSaved) { - var metadata = model.ExportMetadata(RefTable, singletons.MetadataInfo); - var result = fileSystem.TrySavePrompt(new LoadedFile(viewPort.FileName, model.RawData)); - if (result == null) return; - if (result == true) { - fileSystem.SaveMetadata(viewPort.FileName, metadata?.Serialize()); - history.TagAsSaved(); - } - } - Closed.Raise(this); - }); + public ICommand Close => StubCommand(ref close, () => Closed.Raise(this)); public ICommand Diff => null; public ICommand DiffLeft => null; @@ -615,10 +604,18 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { Tutorials.Complete(Tutorial.DoubleClick_FollowWarp); } } else if (click == PrimaryInteractionStart.DoubleClick && SelectedEvent is ObjectEventViewModel obj) { - viewPort.Goto.Execute(obj.ScriptAddress); + if (0 <= obj.ScriptAddress && obj.ScriptAddress < model.Count) { + viewPort.Goto.Execute(obj.ScriptAddress); + } else { + OnError.Raise(this, "Not a valid script address."); + } Tutorials.Complete(Tutorial.DoubleClickEvent_SeeScript); } else if (click == PrimaryInteractionStart.DoubleClick && SelectedEvent is ScriptEventViewModel script) { - viewPort.Goto.Execute(script.ScriptAddress); + if (0 <= script.ScriptAddress && script.ScriptAddress < model.Count) { + viewPort.Goto.Execute(script.ScriptAddress); + } else { + OnError.Raise(this, "Not a valid script address."); + } Tutorials.Complete(Tutorial.DoubleClickEvent_SeeScript); } else if ( click == PrimaryInteractionStart.DoubleClick && @@ -1120,6 +1117,11 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { Tutorials.Complete(Tutorial.Wheel_ZoomMap); } + public void ResetZoom() { + while (primaryMap.SpriteScale > 1) Zoom(0, 0, false); + while (primaryMap.SpriteScale < 1) Zoom(0, 0, true); + } + private StubCommand panCommand, zoomCommand, deleteCommand, cancelCommand; public ICommand PanCommand => StubCommand(ref panCommand, Pan); public ICommand ZoomCommand => StubCommand(ref zoomCommand, Zoom); diff --git a/src/HexManiac.Core/ViewModels/ViewPort.cs b/src/HexManiac.Core/ViewModels/ViewPort.cs index 5cd537cc..7a1a6288 100644 --- a/src/HexManiac.Core/ViewModels/ViewPort.cs +++ b/src/HexManiac.Core/ViewModels/ViewPort.cs @@ -603,7 +603,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels { } private void CloseExecuted(IFileSystem fileSystem) { - if (!history.IsSaved) { + if (!history.IsSaved && ownsHistory) { var metadata = Model.ExportMetadata(RefTable, Singletons.MetadataInfo); var result = fileSystem.TrySavePrompt(new LoadedFile(FileName, Model.RawData)); if (result == null) return; @@ -877,6 +877,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels { private bool isFocused; public bool IsFocused { get => isFocused; set => Set(ref isFocused, value); } + private bool ownsHistory; // true if this tab is responsible for history ownership. False if this is a 'duplicate' tab, and another tab owns the history. + public ICommand Copy => copy; public ICommand CopyAddress => copyAddress; public ICommand CopyBytes => copyBytes; @@ -937,6 +939,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels { public ViewPort(string fileName, IDataModel model, IWorkDispatcher dispatcher, Singletons singletons = null, MapTutorialsViewModel tutorials = null, IFileSystem fs = null, PythonTool pythonTool = null, ChangeHistory changeHistory = null) { Singletons = singletons ?? new Singletons(); PythonTool = pythonTool; + ownsHistory = changeHistory == null; history = changeHistory ?? new ChangeHistory(RevertChanges); history.PropertyChanged += HistoryPropertyChanged; this.dispatcher = dispatcher ?? InstantDispatch.Instance; diff --git a/src/HexManiac.WPF/Controls/MapTab.xaml b/src/HexManiac.WPF/Controls/MapTab.xaml index 69766a00..08713429 100644 --- a/src/HexManiac.WPF/Controls/MapTab.xaml +++ b/src/HexManiac.WPF/Controls/MapTab.xaml @@ -39,7 +39,7 @@ - + @@ -836,7 +836,7 @@ @@ -921,7 +921,7 @@ diff --git a/src/HexManiac.WPF/Controls/MapTab.xaml.cs b/src/HexManiac.WPF/Controls/MapTab.xaml.cs index c9f08406..587d8440 100644 --- a/src/HexManiac.WPF/Controls/MapTab.xaml.cs +++ b/src/HexManiac.WPF/Controls/MapTab.xaml.cs @@ -238,6 +238,11 @@ namespace HavenSoft.HexManiac.WPF.Controls { e.Handled = true; } + private void EatMouseWheel(object sender, MouseWheelEventArgs e) { + // we have this so that mouse-wheel over certain elements won't get taken by the Wheel method above. + e.Handled = true; + } + private void BlocksDown(object sender, MouseButtonEventArgs e) { var element = (FrameworkElement)sender; if (element.IsMouseCaptured) return;