From 9b8d2f70ab1bbdfcd96e663009f1d502fdc1e1ca Mon Sep 17 00:00:00 2001 From: SuuperW Date: Sun, 22 Mar 2015 16:55:34 +0000 Subject: [PATCH] Various fixes --- .../movie/bk2/Bk2Movie.InputLog.cs | 28 +++ .../movie/bkm/BkmMovie.InputLog.cs | 10 + .../movie/interfaces/IMovie.cs | 7 + .../movie/tasproj/TasLagLog.cs | 29 ++- .../movie/tasproj/TasMovie.cs | 29 --- .../movie/tasproj/TasMovieMarker.cs | 4 + .../tools/Macros/MacroInput.Designer.cs | 1 + .../tools/Macros/MacroInput.cs | 43 ++++- .../tools/Macros/MovieZone.cs | 17 +- .../tools/TAStudio/InputRoll.cs | 7 +- .../tools/TAStudio/TAStudio.IToolForm.cs | 5 +- .../tools/TAStudio/TAStudio.MenuItems.cs | 2 +- .../tools/TAStudio/TAStudio.cs | 173 +++++++----------- BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs | 12 +- .../tools/Watch/RamSearch.Designer.cs | 8 +- .../tools/Watch/RamSearch.cs | 44 +++-- .../tools/Watch/RamWatch.cs | 2 +- .../tools/Watch/WatchEditor.cs | 10 +- .../tools/Watch/WatchValueBox.cs | 2 + 19 files changed, 234 insertions(+), 199 deletions(-) diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs index 8c1defbeb1..2deacda209 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs @@ -22,6 +22,34 @@ namespace BizHawk.Client.Common return sb.ToString(); } + public string GetInputLogEntry(int frame) + { + if (frame < FrameCount && frame >= 0) + { + int getframe; + + if (LoopOffset.HasValue) + { + if (frame < _log.Count) + { + getframe = frame; + } + else + { + getframe = ((frame - LoopOffset.Value) % (_log.Count - LoopOffset.Value)) + LoopOffset.Value; + } + } + else + { + getframe = frame; + } + + return _log[getframe]; + } + + return string.Empty; + } + public virtual bool ExtractInputLog(TextReader reader, out string errorMessage) { errorMessage = string.Empty; diff --git a/BizHawk.Client.Common/movie/bkm/BkmMovie.InputLog.cs b/BizHawk.Client.Common/movie/bkm/BkmMovie.InputLog.cs index c65d22f23d..a508936aca 100644 --- a/BizHawk.Client.Common/movie/bkm/BkmMovie.InputLog.cs +++ b/BizHawk.Client.Common/movie/bkm/BkmMovie.InputLog.cs @@ -26,6 +26,16 @@ namespace BizHawk.Client.Common return sb.ToString(); } + public string GetInputLogEntry(int frame) + { + if (frame < FrameCount && frame >= 0) + { + return _log[frame]; + } + + return string.Empty; + } + public bool ExtractInputLog(TextReader reader, out string errorMessage) { errorMessage = string.Empty; diff --git a/BizHawk.Client.Common/movie/interfaces/IMovie.cs b/BizHawk.Client.Common/movie/interfaces/IMovie.cs index 31fd9eea66..ddba54c898 100644 --- a/BizHawk.Client.Common/movie/interfaces/IMovie.cs +++ b/BizHawk.Client.Common/movie/interfaces/IMovie.cs @@ -110,6 +110,13 @@ namespace BizHawk.Client.Common /// returns a string represntation of the input log in its current state string GetInputLog(); + /// + /// Gets one frame from the input log. + /// + /// The frame to get. + /// + string GetInputLogEntry(int frame); + /// /// Compares the input log inside reader with the movie's current input to see if the reader's input belongs to the same timeline, /// in other words, if reader's input is completely contained in the movie's input, then it is considered in the same timeline diff --git a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs index 534b7b2086..0c923cb565 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs @@ -52,26 +52,23 @@ namespace BizHawk.Client.Common return; // Can this break anything? } - if (frame >= LagLog.Count) - { - LagLog.Add(value.Value); - if (frame >= LagLog.Count) - { - System.Diagnostics.Debugger.Break(); - System.Diagnostics.Debug.Print("Lag Log error. f" + frame); - do - { - LagLog.Add(value.Value); - } while (frame >= LagLog.Count); - } - } + bool wasValue; + if (frame < LagLog.Count) + wasValue = LagLog[frame]; + else if (frame == WasLag.Count) + wasValue = value.Value; else - LagLog[frame] = value.Value; + wasValue = WasLag[frame]; if (frame == WasLag.Count) - WasLag.Add(value.Value); + WasLag.Add(wasValue); else - WasLag[frame] = value.Value; + WasLag[frame] = wasValue; + + if (frame >= LagLog.Count) + LagLog.Add(value.Value); + else + LagLog[frame] = value.Value; } } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 68e4270188..49aef33274 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -225,35 +225,6 @@ namespace BizHawk.Client.Common .GetFloat(buttonName); } - // TODO: try not to need this, or at least use GetInputState and then a log entry generator - public string GetInputLogEntry(int frame) - { - if (frame < FrameCount && frame >= 0) - { - int getframe; - - if (LoopOffset.HasValue) - { - if (frame < _log.Count) - { - getframe = frame; - } - else - { - getframe = ((frame - LoopOffset.Value) % (_log.Count - LoopOffset.Value)) + LoopOffset.Value; - } - } - else - { - getframe = frame; - } - - return _log[getframe]; - } - - return string.Empty; - } - public void ClearGreenzone() { if (StateManager.Any()) diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs index 5b2a1aae43..04a4bd1093 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs @@ -160,6 +160,8 @@ namespace BizHawk.Client.Common public new void Remove(TasMovieMarker item) { + if (item == null) // TODO: Don't do this. + return; _movie.ChangeLog.AddMarkerChange(null, item.Frame, item.Message); base.Remove(item); OnListChanged(NotifyCollectionChangedAction.Remove); @@ -187,6 +189,8 @@ namespace BizHawk.Client.Common public void Move(int fromFrame, int toFrame) { TasMovieMarker m = Get(fromFrame); + if (m == null) // TODO: Don't do this. + return; _movie.ChangeLog.AddMarkerChange(m, m.Frame); Insert(0, new TasMovieMarker(toFrame, m.Message)); Remove(m); diff --git a/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.Designer.cs b/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.Designer.cs index 60e64f5499..a2fd77540a 100644 --- a/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.Designer.cs @@ -285,6 +285,7 @@ this.Name = "MacroInputTool"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Macro Input"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MacroInputTool_FormClosing); this.Load += new System.EventHandler(this.MacroInputTool_Load); this.Resize += new System.EventHandler(this.MacroInputTool_Resize); this.MacroMenu.ResumeLayout(false); diff --git a/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs b/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs index 80c04c2359..e2d7a4539f 100644 --- a/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs +++ b/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs @@ -38,8 +38,9 @@ namespace BizHawk.Client.EmuHawk private void MacroInputTool_Load(object sender, EventArgs e) { - // Movie recording must be active - if (!Global.MovieSession.Movie.IsActive) + // Movie recording must be active (check TAStudio because opening a project re-loads the ROM, + // which resets tools before the movie session becomes active) + if (!Global.MovieSession.Movie.IsActive && !GlobalWin.Tools.IsLoaded()) { MessageBox.Show("In order to use this tool you must be recording a movie."); this.Close(); @@ -63,6 +64,15 @@ namespace BizHawk.Client.EmuHawk _initializing = false; } + private void MacroInputTool_FormClosing(object sender, FormClosingEventArgs e) + { + if (_initializing) + return; + + if (!AskSaveChanges()) + e.Cancel = true; + } + public void Restart() { if (_initializing) @@ -90,6 +100,20 @@ namespace BizHawk.Client.EmuHawk public bool AskSaveChanges() { + if (unsavedZones.Count == 0 || IsDisposed) + return true; + else + { + DialogResult result = MessageBox.Show("You have unsaved macro(s). Do you wish to save them?", "Save?", MessageBoxButtons.YesNoCancel); + if (result == DialogResult.Cancel) + return false; + else if (result == DialogResult.No) + return true; + } + + for (int i = 0; i < unsavedZones.Count; i++) + SaveMacroAs(zones[unsavedZones[i]]); + return true; } @@ -98,6 +122,7 @@ namespace BizHawk.Client.EmuHawk Close(); } + List unsavedZones = new List(); private void SetZoneButton_Click(object sender, EventArgs e) { if (StartNum.Value >= CurrentMovie.InputLogLength || EndNum.Value >= CurrentMovie.InputLogLength) @@ -110,6 +135,8 @@ namespace BizHawk.Client.EmuHawk newZone.Name = "Zone " + zones.Count; zones.Add(newZone); ZonesList.Items.Add(newZone.Name + " - length: " + newZone.Length); + + unsavedZones.Add(ZonesList.Items.Count - 1); } private MovieZone selectedZone @@ -190,7 +217,8 @@ namespace BizHawk.Client.EmuHawk return; } - SaveMacroAs(selectedZone); + if (SaveMacroAs(selectedZone)) + unsavedZones.Remove(ZonesList.SelectedIndex); } private void loadMacroToolStripMenuItem_Click(object sender, EventArgs e) @@ -231,9 +259,10 @@ namespace BizHawk.Client.EmuHawk } #endregion - public static void SaveMacroAs(MovieZone macro) + public static bool SaveMacroAs(MovieZone macro) { SaveFileDialog dialog = new SaveFileDialog(); + // Create directory? bool create = false; if (!Directory.Exists(SuggestedFolder())) { @@ -241,7 +270,7 @@ namespace BizHawk.Client.EmuHawk create = true; } dialog.InitialDirectory = SuggestedFolder(); - // Create directory? + dialog.FileName = macro.Name; dialog.Filter = "Movie Macros (*.bk2m)|*.bk2m|All Files|*.*"; DialogResult result = dialog.ShowHawkDialog(); @@ -249,11 +278,13 @@ namespace BizHawk.Client.EmuHawk { if (create) Directory.Delete(dialog.InitialDirectory); - return; + return false; } macro.Save(dialog.FileName); Global.Config.RecentMacros.Add(dialog.FileName); + + return true; } public static MovieZone LoadMacro() { diff --git a/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs b/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs index 1e7d7aa3c9..3a689eb582 100644 --- a/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs +++ b/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs @@ -65,10 +65,21 @@ namespace BizHawk.Client.EmuHawk Bk2LogEntryGenerator logGenerator = new Bk2LogEntryGenerator(""); logGenerator.SetSource(controller); logGenerator.GenerateLogEntry(); // Reference and create all buttons. - for (int i = 0; i < length; i++) + + string movieKey = logGenerator.GenerateLogKey().Replace("LogKey:", "").Replace("#", ""); + movieKey = movieKey.Substring(0, movieKey.Length - 1); + if (key == movieKey) { - controller.LatchFromSource(movie.GetInputState(i + start)); - _log[i] = logGenerator.GenerateLogEntry(); + for (int i = 0; i < length; i++) + _log[i] = movie.GetInputLogEntry(i + start); + } + else + { + for (int i = 0; i < length; i++) + { + controller.LatchFromSource(movie.GetInputState(i + start)); + _log[i] = logGenerator.GenerateLogEntry(); + } } } private void ReSetLog() diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs index b4687d17da..478c0729f6 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs @@ -2393,7 +2393,12 @@ namespace BizHawk.Client.EmuHawk /// /// Column will be drawn with an emphasized look, if true /// - public bool Emphasis { get; set; } + private bool _emphasis; + public bool Emphasis + { + get { return _emphasis; } + set { _emphasis = value; } + } public RollColumn() { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs index f6d031ff48..cc8905c9f3 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs @@ -18,6 +18,7 @@ namespace BizHawk.Client.EmuHawk public bool UpdateBefore { get { return false; } } + private int lastRefresh = 0; public void UpdateValues() { if (!IsHandleCreated || IsDisposed || CurrentTasMovie == null) @@ -37,7 +38,7 @@ namespace BizHawk.Client.EmuHawk if (TasPlaybackBox.FollowCursor) SetVisibleIndex(); - if (TasView.IsPartiallyVisible(Global.Emulator.Frame) || TasView.IsPartiallyVisible(Global.Emulator.Frame - 1)) + if (TasView.IsPartiallyVisible(Global.Emulator.Frame) || TasView.IsPartiallyVisible(lastRefresh)) refreshNeeded = true; if (refreshNeeded) @@ -79,7 +80,7 @@ namespace BizHawk.Client.EmuHawk { TastudioToStopMovie(); TasView.AllColumns.Clear(); - NewDefaultProject(); + StartNewTasMovie(); SetUpColumns(); RefreshTasView(); } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 7c7ca6a5b0..0c8192fda5 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -988,7 +988,7 @@ namespace BizHawk.Client.EmuHawk (byte[])StatableEmulator.SaveStateBinary().Clone()); GlobalWin.MainForm.PauseEmulator(); - LoadProject(newProject.Filename); + LoadFile(new FileInfo(newProject.Filename)); } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 31a9591abc..1bc1cb7a1e 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -181,18 +181,18 @@ namespace BizHawk.Client.EmuHawk // Start Scenario 3: No movie, but user wants to autload their last project else if (Settings.RecentTas.AutoLoad && !string.IsNullOrEmpty(Settings.RecentTas.MostRecent)) { - var result = LoadProject(Settings.RecentTas.MostRecent); + bool result = LoadFile(new FileInfo(Settings.RecentTas.MostRecent)); if (!result) { TasView.AllColumns.Clear(); - NewDefaultProject(); + StartNewTasMovie(); } } // Start Scenario 4: No movie, default behavior of engaging tastudio with a new default project else { - NewDefaultProject(); + StartNewTasMovie(); } EngageTastudio(); @@ -304,7 +304,7 @@ namespace BizHawk.Client.EmuHawk #endregion - #region "Loading, Saving" + #region "Loading" private void ConvertCurrentMovieToTasproj() { @@ -315,77 +315,85 @@ namespace BizHawk.Client.EmuHawk Settings.RecentTas.Add(Global.MovieSession.Movie.Filename); } - private void NewTasMovie() + private bool LoadFile(FileInfo file) { - Global.MovieSession.Movie = new TasMovie(false, _saveBackgroundWorker); - SetTasMovieCallbacks(); - CurrentTasMovie.PropertyChanged += new PropertyChangedEventHandler(this.TasMovie_OnPropertyChanged); - CurrentTasMovie.Filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename - CurrentTasMovie.PopulateWithDefaultHeaderValues(); - CurrentTasMovie.ClearChanges(); - TasView.RowCount = 1; + if (!file.Exists) + { + Settings.RecentTas.HandleLoadError(file.FullName); + return false; + } + + CurrentTasMovie.Filename = file.FullName; + try + { + CurrentTasMovie.Load(); + } + catch + { + MessageBox.Show( + "Tastudio could not open the file. Due to the loading process, the emulator/Tastudio may be in a unspecified state depending on the error.", + "Tastudio", + MessageBoxButtons.OK); + return false; + } + Settings.RecentTas.Add(CurrentTasMovie.Filename); + + if (!HandleMovieLoadStuff()) + return false; + + RefreshDialog(); + return true; } private void StartNewTasMovie() { if (AskSaveChanges()) { - NewTasMovie(); - WantsToControlStopMovie = false; - StartNewMovieWrapper(record: true); - CurrentTasMovie.ClearChanges(); - WantsToControlStopMovie = true; - SetTextProperty(); + Global.MovieSession.Movie = new TasMovie(false, _saveBackgroundWorker); + CurrentTasMovie.PropertyChanged += new PropertyChangedEventHandler(this.TasMovie_OnPropertyChanged); + CurrentTasMovie.Filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename + CurrentTasMovie.PopulateWithDefaultHeaderValues(); + CurrentTasMovie.ClearChanges(); // Don't ask to save changes here. + HandleMovieLoadStuff(); + RefreshDialog(); } } - public bool LoadProject(string path) + private bool HandleMovieLoadStuff(TasMovie movie = null) { - if (AskSaveChanges()) - { - var movie = new TasMovie(false, _saveBackgroundWorker) - { - Filename = path, - ClientSettingsForSave = ClientSettingsForSave, - GetClientSettingsOnLoad = GetClientSettingsOnLoad - }; + if (movie == null) + movie = CurrentTasMovie; - movie.PropertyChanged += TasMovie_OnPropertyChanged; - movie.Load(); + WantsToControlStopMovie = false; + bool result = StartNewMovieWrapper(movie.InputLogLength == 0, movie); + if (!result) + return false; + WantsToControlStopMovie = true; - var file = new FileInfo(path); - if (!file.Exists) - { - Settings.RecentTas.HandleLoadError(path); - } + CurrentTasMovie.ClearChanges(); - WantsToControlStopMovie = false; + SetTasMovieCallbacks(); + SetTextProperty(); + MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " loaded."; - var shouldRecord = movie.InputLogLength == 0; + return true; + } + private bool StartNewMovieWrapper(bool record, IMovie movie = null) + { + _initializing = true; + if (movie == null) + movie = CurrentTasMovie; + bool result = GlobalWin.MainForm.StartNewMovie(movie, record); + _initializing = false; - var result = StartNewMovieWrapper(movie: movie, record: shouldRecord); - if (!result) - { - return false; - } - - SetTasMovieCallbacks(); - - WantsToControlStopMovie = true; - Settings.RecentTas.Add(path); - Text = "TAStudio - " + CurrentTasMovie.Name; - - RefreshDialog(); - return true; - } - - return false; + return result; } private void DummyLoadProject(string path) { - LoadProject(path); + if (AskSaveChanges()) + LoadFile(new FileInfo(path)); } private void DummyLoadMacro(string path) { @@ -411,54 +419,6 @@ namespace BizHawk.Client.EmuHawk } } - private void NewDefaultProject() - { - NewTasMovie(); - StartNewMovieWrapper(record: true); - CurrentTasMovie.TasStateManager.Capture(); - CurrentTasMovie.SwitchToRecord(); - CurrentTasMovie.ClearChanges(); - } - - private bool StartNewMovieWrapper(bool record, IMovie movie = null) - { - _initializing = true; - var result = GlobalWin.MainForm.StartNewMovie(movie != null ? movie : CurrentTasMovie, record); - _initializing = false; - - return result; - } - - private void LoadFile(FileInfo file) - { - CurrentTasMovie.Filename = file.FullName; - try - { - CurrentTasMovie.Load(); - } - catch - { - MessageBox.Show( - "Tastudio could not open the file. Due to the loading process, the emulator/Tastudio may be in a unspecified state depending on the error.", - "Tastudio", - MessageBoxButtons.OK); - return; - } - Settings.RecentTas.Add(CurrentTasMovie.Filename); - - if (CurrentTasMovie.InputLogLength > 0) // TODO: this is probably reoccuring logic, break off into a function - { - CurrentTasMovie.SwitchToPlay(); - } - else - { - CurrentTasMovie.SwitchToRecord(); - } - - RefreshDialog(); - MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " loaded."; - } - #endregion private void TastudioToStopMovie() @@ -667,13 +627,10 @@ namespace BizHawk.Client.EmuHawk { if (_triggerAutoRestore) { - if (Global.Emulator.Frame < 50) - System.Diagnostics.Debugger.Break(); - int? pauseOn = GlobalWin.MainForm.PauseOnFrame; GoToLastEmulatedFrameIfNecessary(_triggerAutoRestoreFromFrame.Value); - if (pauseOn.HasValue && _autoRestoreFrame.HasValue && _autoRestoreFrame < pauseOn) + if (pauseOn.HasValue && _autoRestoreFrame.HasValue && _autoRestoreFrame < pauseOn) { // If we are already seeking to a later frame don't shorten that journey here _autoRestoreFrame = GlobalWin.MainForm.PauseOnFrame; } @@ -727,10 +684,10 @@ namespace BizHawk.Client.EmuHawk var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); if (Path.GetExtension(filePaths[0]) == "." + TasMovie.Extension) { - var file = new FileInfo(filePaths[0]); + FileInfo file = new FileInfo(filePaths[0]); if (file.Exists) { - LoadProject(file.FullName); + LoadFile(file); } } } diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs index 3d4e8dd13c..a960fb803b 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamPoke.cs @@ -50,9 +50,9 @@ namespace BizHawk.Client.EmuHawk if (_watchList.Count > 1) { - var hasMixedSizes = _watchList.Select(x => x.Size).Distinct().Count() > 1; - var hasMixedTypes = _watchList.Select(x => x.Type).Distinct().Count() > 1; - var hasMixedEndian = _watchList.Select(x => x.BigEndian).Distinct().Count() > 1; + bool hasMixedSizes = _watchList.Select(x => x.Size).Distinct().Count() > 1; + bool hasMixedTypes = _watchList.Select(x => x.Type).Distinct().Count() > 1; + bool hasMixedEndian = _watchList.Select(x => x.BigEndian).Distinct().Count() > 1; if (hasMixedSizes || hasMixedTypes || hasMixedEndian) { @@ -77,6 +77,9 @@ namespace BizHawk.Client.EmuHawk .Aggregate((addrStr, nextStr) => addrStr + ("," + nextStr)); } + ValueBox.ByteSize = _watchList[0].Size; + ValueBox.Type = _watchList[0].Type; + ValueHexLabel.Text = _watchList[0].Type == Watch.DisplayType.Hex ? "0x" : string.Empty; ValueBox.Text = _watchList[0].ValueString.Replace(" ", string.Empty); DomainLabel.Text = _watchList[0].Domain.Name; @@ -84,9 +87,6 @@ namespace BizHawk.Client.EmuHawk DisplayTypeLabel.Text = Watch.DisplayTypeToString(_watchList[0].Type); BigEndianLabel.Text = _watchList[0].BigEndian ? "Big Endian" : "Little Endian"; SetTitle(); - - ValueBox.ByteSize = _watchList[0].Size; - ValueBox.Type = _watchList[0].Type; } private void SetTitle() diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs index 515c1c8c9c..767df2c554 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs @@ -116,7 +116,7 @@ this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.AutoSearchCheckBox = new System.Windows.Forms.CheckBox(); this.CompareToBox = new System.Windows.Forms.GroupBox(); - this.DifferenceBox = new BizHawk.Client.EmuHawk.UnsignedIntegerBox(); + this.DifferenceBox = new BizHawk.Client.EmuHawk.WatchValueBox(); this.DifferenceRadio = new System.Windows.Forms.RadioButton(); this.NumberOfChangesBox = new BizHawk.Client.EmuHawk.UnsignedIntegerBox(); this.SpecificAddressBox = new BizHawk.Client.EmuHawk.HexTextBox(); @@ -144,7 +144,7 @@ this.RebootToolbarButton = new System.Windows.Forms.ToolStripButton(); this.ErrorIconButton = new System.Windows.Forms.ToolStripButton(); this.ComparisonBox = new System.Windows.Forms.GroupBox(); - this.DifferentByBox = new BizHawk.Client.EmuHawk.UnsignedIntegerBox(); + this.DifferentByBox = new BizHawk.Client.EmuHawk.WatchValueBox(); this.DifferentByRadio = new System.Windows.Forms.RadioButton(); this.NotEqualToRadio = new System.Windows.Forms.RadioButton(); this.EqualToRadio = new System.Windows.Forms.RadioButton(); @@ -1506,7 +1506,7 @@ private System.Windows.Forms.ToolStripButton NewSearchToolButton; private System.Windows.Forms.ToolStripSeparator toolStripSeparator15; private System.Windows.Forms.GroupBox ComparisonBox; - private UnsignedIntegerBox DifferentByBox; + private WatchValueBox DifferentByBox; private System.Windows.Forms.RadioButton DifferentByRadio; private System.Windows.Forms.RadioButton NotEqualToRadio; private System.Windows.Forms.RadioButton EqualToRadio; @@ -1522,7 +1522,7 @@ private System.Windows.Forms.ToolStripButton AddToRamWatchToolBarItem; private System.Windows.Forms.ToolStripButton PokeAddressToolBarItem; private System.Windows.Forms.ToolStripButton FreezeAddressToolBarItem; - private UnsignedIntegerBox DifferenceBox; + private WatchValueBox DifferenceBox; private System.Windows.Forms.ToolStripMenuItem AutoSearchMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator9; private System.Windows.Forms.ColumnHeader DiffColumn; diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index de82b9fca7..df0b5bbcc7 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -425,7 +425,7 @@ namespace BizHawk.Client.EmuHawk DoSearchToolButton.Enabled = CopyValueToPrevToolBarItem.Enabled = _searches.Count > 0; - + UpdateUndoToolBarButtons(); OutOfRangeCheck(); @@ -443,22 +443,22 @@ namespace BizHawk.Client.EmuHawk { return null; } - + if (SpecificValueRadio.Checked) { return (long)SpecificValueBox.ToRawInt() & 0x00000000FFFFFFFF; } - + if (SpecificAddressRadio.Checked) { return SpecificAddressBox.ToRawInt(); } - + if (NumberOfChangesRadio.Checked) { return NumberOfChangesBox.ToRawInt(); } - + if (DifferenceRadio.Checked) { return DifferenceBox.ToRawInt(); @@ -484,12 +484,12 @@ namespace BizHawk.Client.EmuHawk { return RamSearchEngine.ComparisonOperator.NotEqual; } - + if (LessThanRadio.Checked) { return RamSearchEngine.ComparisonOperator.LessThan; } - + if (GreaterThanRadio.Checked) { return RamSearchEngine.ComparisonOperator.GreaterThan; @@ -499,7 +499,7 @@ namespace BizHawk.Client.EmuHawk { return RamSearchEngine.ComparisonOperator.LessThanEqual; } - + if (GreaterThanOrEqualToRadio.Checked) { return RamSearchEngine.ComparisonOperator.GreaterThanEqual; @@ -522,7 +522,7 @@ namespace BizHawk.Client.EmuHawk { return RamSearchEngine.Compare.SpecificValue; } - + if (SpecificAddressRadio.Checked) { return RamSearchEngine.Compare.SpecificAddress; @@ -610,7 +610,7 @@ namespace BizHawk.Client.EmuHawk private void DoDomainSizeCheck() { - if (_settings.Domain.Size >= MaxDetailedSize + if (_settings.Domain.Size >= MaxDetailedSize && _settings.Mode == RamSearchEngine.Settings.SearchMode.Detailed) { _settings.Mode = RamSearchEngine.Settings.SearchMode.Fast; @@ -644,18 +644,24 @@ namespace BizHawk.Client.EmuHawk private void DoDisplayTypeClick(Watch.DisplayType type) { - if (_settings.Type != type && !string.IsNullOrEmpty(SpecificValueBox.Text)) + if (_settings.Type != type) { - SpecificValueBox.Text = "0"; + if (!string.IsNullOrEmpty(SpecificValueBox.Text)) + SpecificValueBox.Text = "0"; + if (!string.IsNullOrEmpty(DifferenceBox.Text)) + DifferenceBox.Text = "0"; + if (!string.IsNullOrEmpty(DifferentByBox.Text)) + DifferentByBox.Text = "0"; } SpecificValueBox.Type = _settings.Type = type; + DifferenceBox.Type = type; + DifferentByBox.Type = type; _searches.SetType(type); _dropdownDontfire = true; DisplayTypeDropdown.SelectedItem = Watch.DisplayTypeToString(type); _dropdownDontfire = false; - SpecificValueBox.Type = type; WatchListView.Refresh(); } @@ -1081,10 +1087,10 @@ namespace BizHawk.Client.EmuHawk { var item = new ToolStripMenuItem { - Name = type + "ToolStripMenuItem", - Text = Watch.DisplayTypeToString(type), - Checked = _settings.Type == type, - }; + Name = type + "ToolStripMenuItem", + Text = Watch.DisplayTypeToString(type), + Checked = _settings.Type == type, + }; var type1 = type; item.Click += (o, ev) => DoDisplayTypeClick(type1); @@ -1539,7 +1545,7 @@ namespace BizHawk.Client.EmuHawk { SpecificValueBox.Focus(); } - + SpecificAddressBox.Enabled = false; NumberOfChangesBox.Enabled = false; DifferenceBox.Enabled = false; @@ -1657,7 +1663,7 @@ namespace BizHawk.Client.EmuHawk private void DifferentByRadio_Click(object sender, EventArgs e) { DifferentByBox.Enabled = true; - + if (string.IsNullOrWhiteSpace(DifferentByBox.Text)) { DifferentByBox.ResetText(); diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 761fa1f676..6976cf1d09 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -789,7 +789,7 @@ namespace BizHawk.Client.EmuHawk { if (SelectedWatches.Any()) { - var poke = new RamPoke + RamPoke poke = new RamPoke { InitialLocation = this.ChildPointToScreen(WatchListView) }; diff --git a/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs b/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs index 9a0849aeae..3e3ed84cea 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs @@ -12,7 +12,7 @@ namespace BizHawk.Client.EmuHawk public partial class WatchEditor : Form { public enum Mode { New, Duplicate, Edit }; - + private readonly List _watchList = new List(); public IMemoryDomains MemoryDomains { get; set; } @@ -125,7 +125,7 @@ namespace BizHawk.Client.EmuHawk private void SetTitle() { - switch(_mode) + switch (_mode) { default: case Mode.New: @@ -154,6 +154,7 @@ namespace BizHawk.Client.EmuHawk private void SetDisplayTypes() { + string oldType = DisplayTypeDropDown.Text; DisplayTypeDropDown.Items.Clear(); switch (SizeDropDown.SelectedIndex) { @@ -169,7 +170,10 @@ namespace BizHawk.Client.EmuHawk break; } - DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[0]; + if (DisplayTypeDropDown.Items.Contains(oldType)) + DisplayTypeDropDown.SelectedItem = oldType; + else + DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[0]; } private void SetBigEndianCheckBox() diff --git a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs index bf23acfbc3..7adb703949 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs @@ -617,6 +617,8 @@ namespace BizHawk.Client.EmuHawk case Watch.DisplayType.Signed: if (Text.IsSigned()) { + if (Text == "-") + return 0; return int.Parse(Text); }