Skip to content

Commit

Permalink
Merge pull request #424 from Vivelin/auto-track-hints
Browse files Browse the repository at this point in the history
Auto track hint tiles
  • Loading branch information
MattEqualsCoder authored Nov 26, 2023
2 parents b99b7aa + 4dac57e commit 7d1ac58
Show file tree
Hide file tree
Showing 32 changed files with 877 additions and 71 deletions.
47 changes: 45 additions & 2 deletions src/Randomizer.Abstractions/TrackerBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MSURandomizerLibrary.Configs;
using Randomizer.Data;
using Randomizer.Data.Configuration;
using Randomizer.Data.Configuration.ConfigFiles;
using Randomizer.Data.Configuration.ConfigTypes;
using Randomizer.Data.Tracking;
Expand Down Expand Up @@ -98,6 +99,11 @@ public abstract class TrackerBase
/// </summary>
public event EventHandler<TrackChangedEventArgs>? TrackChanged;

/// <summary>
/// Occurs when a hint tile is viewed that is for a region, dungeon, or group of locations
/// </summary>
public event EventHandler<HintTileUpdatedEventArgs>? HintTileUpdated;

/// <summary>
/// Gets a reference to the <see cref="ItemService"/>.
/// </summary>
Expand Down Expand Up @@ -148,6 +154,11 @@ public abstract class TrackerBase
/// </summary>
public IReadOnlyCollection<BasicVoiceRequest> Requests { get; protected init; } = null!;

/// <summary>
/// Metadata configs
/// </summary>
public Configs Configs { get; protected init; } = null!;

/// <summary>
/// Gets a dictionary containing the rules and the various speech
/// recognition syntaxes.
Expand Down Expand Up @@ -226,6 +237,11 @@ public abstract class TrackerBase
/// </summary>
public bool HasBeatenGame { get; protected set; }

/// <summary>
/// The last viewed hint tile by the player
/// </summary>
public PlayerHintTile? LastViewedHintTile { get; set; }

/// <summary>
/// Attempts to replace a user name with a pronunciation-corrected
/// version of it.
Expand Down Expand Up @@ -317,7 +333,8 @@ public abstract class TrackerBase
/// <param name="dungeon">The dungeon to mark.</param>
/// <param name="medallion">The medallion that is required.</param>
/// <param name="confidence">The speech recognition confidence.</param>
public abstract void SetDungeonRequirement(IDungeon dungeon, ItemType? medallion = null, float? confidence = null);
/// <param name="autoTracked">If the marked dungeon requirement was auto tracked</param>
public abstract void SetDungeonRequirement(IDungeon dungeon, ItemType? medallion = null, float? confidence = null, bool autoTracked = false);

/// <summary>
/// Starts voice recognition.
Expand Down Expand Up @@ -594,6 +611,13 @@ public abstract class TrackerBase
/// <param name="autoTracked">If this was tracked by the auto tracker</param>
public abstract void Clear(Location location, float? confidence = null, bool autoTracked = false);

/// <summary>
/// Clears an item from the specified locations.
/// </summary>
/// <param name="locations">The locations to clear.</param>
/// <param name="confidence">The speech recognition confidence.</param>
public abstract void Clear(List<Location> locations, float? confidence = null);

/// <summary>
/// Marks a dungeon as cleared and, if possible, tracks the boss reward.
/// </summary>
Expand Down Expand Up @@ -637,7 +661,8 @@ public abstract class TrackerBase
/// The item that is found at <paramref name="location"/>.
/// </param>
/// <param name="confidence">The speech recognition confidence.</param>
public abstract void MarkLocation(Location location, Item item, float? confidence = null);
/// <param name="autoTracked">If the marked location was auto tracked</param>
public abstract void MarkLocation(Location location, Item item, float? confidence = null, bool autoTracked = false);

/// <summary>
/// Pegs a Peg World peg.
Expand Down Expand Up @@ -717,6 +742,15 @@ public abstract class TrackerBase
/// <param name="outputText">Formatted output text matching the requested style</param>
public abstract void UpdateTrack(Msu msu, Track track, string outputText);

/// <summary>
/// Marks a hint tile as viewed or cleared
/// </summary>
/// <param name="playerHintTile">Details about the hint for the player</param>
public abstract void UpdateHintTile(PlayerHintTile playerHintTile);

/// <summary>
/// Resets the idle timers when tracker will comment on nothing happening
/// </summary>
public abstract void RestartIdleTimers();

/// <summary>
Expand Down Expand Up @@ -907,4 +941,13 @@ protected virtual void OnTrackChanged(TrackChangedEventArgs args)
{
TrackChanged?.Invoke(this, args);
}

/// <summary>
/// Invokes the HintTileUpdated event
/// </summary>
/// <param name="args"></param>
protected virtual void OnHintTileUpdated(HintTileUpdatedEventArgs args)
{
HintTileUpdated?.Invoke(this, args);
}
}
6 changes: 6 additions & 0 deletions src/Randomizer.App/TrackerLocationSyncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ public TrackerLocationSyncer(TrackerBase tracker, IItemService itemService, IWor
TrackedLocationUpdated?.Invoke(this, new(""));
MarkedLocationUpdated?.Invoke(this, new(""));
};
Tracker.HintTileUpdated += (_, _) =>
{
HintTileUpdated?.Invoke(this, new PropertyChangedEventArgs(""));
};
}

public event PropertyChangedEventHandler? TrackedLocationUpdated;

public event PropertyChangedEventHandler? MarkedLocationUpdated;

public event PropertyChangedEventHandler? HintTileUpdated;

/// <summary>
/// If out of logic locations should be displayed on the tracker
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions src/Randomizer.App/ViewModels/HintTileViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Randomizer.Data.WorldData;
using Randomizer.Shared.Models;

namespace Randomizer.App.ViewModels;

public class HintTileViewModel
{
public HintTileViewModel(PlayerHintTile hintTile)
{
PlayerHintTile = hintTile;
}

public PlayerHintTile PlayerHintTile { get; init; }

public string Name => PlayerHintTile.LocationKey;
public string Quality => PlayerHintTile.Usefulness?.ToString() ?? "";
}
14 changes: 14 additions & 0 deletions src/Randomizer.App/ViewModels/TrackerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public TrackerViewModel(TrackerLocationSyncer syncer, IUIService uiService)
_syncer = syncer;
_syncer.TrackedLocationUpdated += (_, _) => OnPropertyChanged(nameof(TopLocations));
_syncer.MarkedLocationUpdated += (_, _) => OnPropertyChanged(nameof(MarkedLocations));
_syncer.HintTileUpdated += (_, _) => OnPropertyChanged(nameof(HintTiles));
_uiService = uiService;
}

Expand All @@ -55,6 +56,19 @@ public bool ShowOutOfLogicLocations
set => _syncer.ShowOutOfLogicLocations = value;
}

public IEnumerable<HintTileViewModel> HintTiles
{
get
{
if (_isDesign)
return new List<HintTileViewModel>();

return _syncer.WorldService.ViewedHintTiles
.Where(x => x.Locations?.Count() > 1)
.Select(x => new HintTileViewModel(x));
}
}

public IEnumerable<MarkedLocationViewModel> MarkedLocations
{
get
Expand Down
34 changes: 31 additions & 3 deletions src/Randomizer.App/Windows/TrackerLocationsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

<Grid Margin="11">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -80,11 +82,37 @@
</ListView.ItemTemplate>
</ListView>

<TextBlock Text="All locations"
<TextBlock Text="Viewed Hints"
Grid.Row="2"
Style="{StaticResource Heading}" />
<ListView ItemsSource="{Binding HintTiles}"
Grid.Row="3"
BorderThickness="0"
Margin="0,0,0,11">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Focusable"
Value="false" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}"
FontWeight="Bold" />
<TextBlock Margin="0 0 5 0">: </TextBlock>
<TextBlock Text="{Binding Quality}"
Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

<TextBlock Text="All locations"
Grid.Row="4"
Style="{StaticResource Heading}" />
<StackPanel Orientation="Horizontal"
Grid.Row="2"
Grid.Row="4"
HorizontalAlignment="Right"
VerticalAlignment="Center">
<CheckBox Content="Show out-of-logic"
Expand All @@ -110,7 +138,7 @@
</StackPanel>


<ScrollViewer Grid.Row="3">
<ScrollViewer Grid.Row="5">
<ItemsControl ItemsSource="{Binding Source={StaticResource topLocations}}"
BorderThickness="0"
Margin="0,0,0,11">
Expand Down
Loading

0 comments on commit 7d1ac58

Please sign in to comment.