diff --git a/src/TrackerCouncil.Smz3.Abstractions/ITrackerGameStateService.cs b/src/TrackerCouncil.Smz3.Abstractions/ITrackerGameStateService.cs index b80350a4d..5d8a00735 100644 --- a/src/TrackerCouncil.Smz3.Abstractions/ITrackerGameStateService.cs +++ b/src/TrackerCouncil.Smz3.Abstractions/ITrackerGameStateService.cs @@ -1,4 +1,5 @@ using MSURandomizerLibrary.Configs; +using TrackerCouncil.Smz3.Data.Options; using TrackerCouncil.Smz3.Data.Tracking; using TrackerCouncil.Smz3.Data.WorldData; using TrackerCouncil.Smz3.Data.WorldData.Regions; @@ -67,9 +68,9 @@ public interface ITrackerGameStateService /// Updates the region that the player is in /// /// The region the player is in - /// Set to true to update the map for the player to match the region + /// Behavior for updating the map for the player to match the region /// If the time should be reset if this is the first region update - public void UpdateRegion(Region region, bool updateMap = false, bool resetTime = false); + public void UpdateRegion(Region region, AutoMapUpdateBehavior updateMap = AutoMapUpdateBehavior.Disabled, bool resetTime = false); /// /// Updates the map to display for the user diff --git a/src/TrackerCouncil.Smz3.Data/Options/AutoMapUpdateBehavior.cs b/src/TrackerCouncil.Smz3.Data/Options/AutoMapUpdateBehavior.cs new file mode 100644 index 000000000..5f393f6eb --- /dev/null +++ b/src/TrackerCouncil.Smz3.Data/Options/AutoMapUpdateBehavior.cs @@ -0,0 +1,21 @@ +using System.ComponentModel; + +namespace TrackerCouncil.Smz3.Data.Options; + +public enum AutoMapUpdateBehavior +{ + [Description("Disabled")] + Disabled, + + [Description("Update Map When Changing Games")] + UpdateOnGameChange, + + [Description("Update Map When Changing Regions")] + UpdateOnRegionChange, + + [Description("Update Map When Changing Games or Zelda Regions")] + UpdateOnZeldaRegionChange, + + [Description("Update Map When Changing Games or Metroid Regions")] + UpdateOnMetroidRegionChange, +} diff --git a/src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs b/src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs index 63108cae4..de4e8bbb9 100644 --- a/src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs +++ b/src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs @@ -77,6 +77,8 @@ public class GeneralOptions : INotifyPropertyChanged public SnesConnectorSettings SnesConnectorSettings { get; set; } = new(); public bool AutoTrackerChangeMap { get; set; } + public AutoMapUpdateBehavior? AutoMapUpdateBehavior { get; set; } = Options.AutoMapUpdateBehavior.Disabled; + public int UndoExpirationTime { get; set; } = 3; public double UIScaleFactor { get; set; } = 1; @@ -256,7 +258,7 @@ public bool Validate() ChatGreetingEnabled = EnableChatGreeting, ChatGreetingTimeLimit = ChatGreetingTimeLimit, PollCreationEnabled = EnablePollCreation, - AutoTrackerChangeMap = AutoTrackerChangeMap, + AutoMapUpdateBehavior = AutoMapUpdateBehavior ?? Options.AutoMapUpdateBehavior.Disabled, VoiceFrequency = TrackerVoiceFrequency, TrackerProfiles = SelectedProfiles, UndoExpirationTime = UndoExpirationTime, diff --git a/src/TrackerCouncil.Smz3.Data/Options/RandomizerOptions.cs b/src/TrackerCouncil.Smz3.Data/Options/RandomizerOptions.cs index e042d02bf..5792067dd 100644 --- a/src/TrackerCouncil.Smz3.Data/Options/RandomizerOptions.cs +++ b/src/TrackerCouncil.Smz3.Data/Options/RandomizerOptions.cs @@ -122,6 +122,14 @@ public static RandomizerOptions Load(string loadPath, string savePath, bool isYa options.GeneralOptions.MsuTrackDisplayStyle = null; } + // Update AutoTrackerChangeMap to AutoMapUpdateBehavior + if (options.GeneralOptions.AutoMapUpdateBehavior == null) + { + options.GeneralOptions.AutoMapUpdateBehavior = options.GeneralOptions.AutoTrackerChangeMap + ? AutoMapUpdateBehavior.UpdateOnRegionChange + : AutoMapUpdateBehavior.Disabled; + } + return options; } else diff --git a/src/TrackerCouncil.Smz3.Data/Options/TrackerOptions.cs b/src/TrackerCouncil.Smz3.Data/Options/TrackerOptions.cs index f0f11e726..1a91ea75a 100644 --- a/src/TrackerCouncil.Smz3.Data/Options/TrackerOptions.cs +++ b/src/TrackerCouncil.Smz3.Data/Options/TrackerOptions.cs @@ -83,7 +83,7 @@ public record TrackerOptions /// /// If auto tracker should change maps when changing locations /// - public bool AutoTrackerChangeMap { get; set; } + public AutoMapUpdateBehavior AutoMapUpdateBehavior { get; set; } /// /// The frequency in which tracker will say things diff --git a/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowTrackerOptions.cs b/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowTrackerOptions.cs index 2a7544639..e1c4a9f15 100644 --- a/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowTrackerOptions.cs +++ b/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowTrackerOptions.cs @@ -66,8 +66,8 @@ public class OptionsWindowTrackerOptions [DynamicFormFieldFilePicker(FilePickerType.OpenFile, label: "Current song output path:", dialogText: "Select song output file")] public string? MsuTrackOutputPath { get; set; } = ""; - [DynamicFormFieldCheckBox(checkBoxText: "Auto tracker updates map automatically", groupName: "Bottom")] - public bool AutoTrackerChangeMap { get; set; } + [DynamicFormFieldComboBox(label: "Auto tracker map update behavior")] + public AutoMapUpdateBehavior AutoMapUpdateBehavior { get; set; } [DynamicFormFieldCheckBox(checkBoxText: "Auto track viewed events", groupName: "Bottom")] public bool AutoSaveLookAtEvents { get; set; } = true; diff --git a/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowViewModel.cs b/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowViewModel.cs index 5c82b8943..ba49c9db6 100644 --- a/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowViewModel.cs +++ b/src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowViewModel.cs @@ -50,7 +50,7 @@ public OptionsWindowViewModel(GeneralOptions options, Dictionary TrackerOptions.SniAddress = options.SnesConnectorSettings.SniAddress; TrackerOptions.TrackDisplayFormat = options.TrackDisplayFormat; TrackerOptions.MsuTrackOutputPath = options.MsuTrackOutputPath; - TrackerOptions.AutoTrackerChangeMap = options.AutoTrackerChangeMap; + TrackerOptions.AutoMapUpdateBehavior = options.AutoMapUpdateBehavior ?? AutoMapUpdateBehavior.Disabled; TrackerOptions.AutoSaveLookAtEvents = options.AutoSaveLookAtEvents; TrackerOptions.TrackerHintsEnabled = options.TrackerHintsEnabled; TrackerOptions.TrackerSpoilersEnabled = options.TrackerSpoilersEnabled; @@ -103,7 +103,7 @@ public void UpdateOptions(GeneralOptions options) options.SnesConnectorSettings.SniAddress = TrackerOptions.SniAddress; options.TrackDisplayFormat = TrackerOptions.TrackDisplayFormat; options.MsuTrackOutputPath = TrackerOptions.MsuTrackOutputPath; - options.AutoTrackerChangeMap = TrackerOptions.AutoTrackerChangeMap; + options.AutoMapUpdateBehavior = TrackerOptions.AutoMapUpdateBehavior; options.AutoSaveLookAtEvents = TrackerOptions.AutoSaveLookAtEvents; options.TrackerHintsEnabled = TrackerOptions.TrackerHintsEnabled; options.TrackerSpoilersEnabled = TrackerOptions.TrackerSpoilersEnabled; diff --git a/src/TrackerCouncil.Smz3.Tracking/AutoTracking/MetroidStateChecks/ChangedMetroidRegion.cs b/src/TrackerCouncil.Smz3.Tracking/AutoTracking/MetroidStateChecks/ChangedMetroidRegion.cs index 0b82a1c70..e565db04e 100644 --- a/src/TrackerCouncil.Smz3.Tracking/AutoTracking/MetroidStateChecks/ChangedMetroidRegion.cs +++ b/src/TrackerCouncil.Smz3.Tracking/AutoTracking/MetroidStateChecks/ChangedMetroidRegion.cs @@ -32,7 +32,7 @@ public bool ExecuteCheck(TrackerBase tracker, AutoTrackerMetroidState currentSta var newRegion = tracker.World.Regions.OfType().FirstOrDefault(x => x.MemoryRegionId == currentState.CurrentRegion); if (newRegion != null) { - tracker.GameStateTracker.UpdateRegion(newRegion, tracker.Options.AutoTrackerChangeMap, startedAtShip); + tracker.GameStateTracker.UpdateRegion(newRegion, tracker.Options.AutoMapUpdateBehavior, startedAtShip); } _previousMetroidRegionValue = currentState.CurrentRegion.Value; return true; diff --git a/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/ChangedOverworld.cs b/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/ChangedOverworld.cs index d98459d4b..91ea0d24e 100644 --- a/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/ChangedOverworld.cs +++ b/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/ChangedOverworld.cs @@ -32,7 +32,7 @@ public bool ExecuteCheck(TrackerBase trackerBase, AutoTrackerZeldaState currentS .FirstOrDefault(x => x.StartingRooms.Count != 0 && x.StartingRooms.Contains(currentState.OverworldScreen.Value) && x.IsOverworld); if (region == null) return false; - trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoTrackerChangeMap); + trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoMapUpdateBehavior); return true; } } diff --git a/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/EnteredDungeon.cs b/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/EnteredDungeon.cs index c36789845..0cf244cd5 100644 --- a/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/EnteredDungeon.cs +++ b/src/TrackerCouncil.Smz3.Tracking/AutoTracking/ZeldaStateChecks/EnteredDungeon.cs @@ -71,7 +71,7 @@ public bool ExecuteCheck(TrackerBase trackerBase, AutoTrackerZeldaState currentS } } - trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoTrackerChangeMap); + trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoMapUpdateBehavior); _enteredDungeons.Add(region); return true; diff --git a/src/TrackerCouncil.Smz3.Tracking/TrackingServices/TrackerGameStateService.cs b/src/TrackerCouncil.Smz3.Tracking/TrackingServices/TrackerGameStateService.cs index 3b3fd8d05..0fbba69c9 100644 --- a/src/TrackerCouncil.Smz3.Tracking/TrackingServices/TrackerGameStateService.cs +++ b/src/TrackerCouncil.Smz3.Tracking/TrackingServices/TrackerGameStateService.cs @@ -3,6 +3,7 @@ using System.Linq; using MSURandomizerLibrary.Configs; using TrackerCouncil.Smz3.Abstractions; +using TrackerCouncil.Smz3.Data.Options; using TrackerCouncil.Smz3.Data.Tracking; using TrackerCouncil.Smz3.Data.WorldData; using TrackerCouncil.Smz3.Data.WorldData.Regions; @@ -32,7 +33,7 @@ internal class TrackerGameStateService : TrackerService, ITrackerGameStateServic /// The region the player is in /// Set to true to update the map for the player to match the region /// If the time should be reset if this is the first region update - public void UpdateRegion(Region region, bool updateMap = false, bool resetTime = false) + public void UpdateRegion(Region region, AutoMapUpdateBehavior updateMap = AutoMapUpdateBehavior.Disabled, bool resetTime = false) { if (region != CurrentRegion) { @@ -46,13 +47,50 @@ public void UpdateRegion(Region region, bool updateMap = false, bool resetTime = true, region.Name ); + + if (updateMap != AutoMapUpdateBehavior.Disabled && !string.IsNullOrEmpty(region?.MapName)) + { + if (updateMap == AutoMapUpdateBehavior.UpdateOnGameChange) + { + if (region is SMRegion && CurrentRegion is not SMRegion) + { + UpdateMap("Metroid Combined"); + } + else if (region is Z3Region && CurrentRegion is not Z3Region) + { + UpdateMap("Zelda Combined"); + } + } + else if (updateMap == AutoMapUpdateBehavior.UpdateOnRegionChange) + { + UpdateMap(region.MapName); + } + else if (updateMap == AutoMapUpdateBehavior.UpdateOnMetroidRegionChange) + { + if (region is Z3Region && CurrentRegion is not Z3Region) + { + UpdateMap("Zelda Combined"); + } + else if (region is SMRegion) + { + UpdateMap(region.MapName); + } + } + else if (updateMap == AutoMapUpdateBehavior.UpdateOnZeldaRegionChange) + { + if (region is SMRegion && CurrentRegion is not SMRegion) + { + UpdateMap("Metroid Combined"); + } + else if (region is Z3Region) + { + UpdateMap(region.MapName); + } + } + } } CurrentRegion = region; - if (updateMap && !string.IsNullOrEmpty(region?.MapName)) - { - UpdateMap(region.MapName); - } } ///