Skip to content

Commit

Permalink
fix node value preview for override controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Sep 13, 2024
1 parent 55f7f7a commit 6a9a113
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</UserControl.Resources>
<Grid>
<TextBlock Text="{Binding DisplayName}" Padding="4,1" Margin="0,0,16,0" />
<TextBlock Name="ValueText" Width="60" Height="16" HorizontalAlignment="Right" VerticalAlignment="Center" />
<TextBlock Name="ValueText" MinWidth="160" Height="16" HorizontalAlignment="Right" VerticalAlignment="Center" />
<Image Source="/AuroraRgb;component/Resources/icons8-folder-30.png" Width="16" Height="16" HorizontalAlignment="Right" VerticalAlignment="Center"
Visibility="{Binding IsFolder, Converter={StaticResource BoolToVisConv}}" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ namespace AuroraRgb.Controls;

public partial class GameStateParameterItem
{
private DispatcherTimer _timer;
private DispatcherTimer? _timer;

public GameStateParameterItem()
{
InitializeComponent();
}

public PropertyEntryToValueConverter Converter { get; set; }
public PropertyEntryToValueConverter Converter { get; set; } = new();

private void GameStateParameterItem_OnLoaded(object sender, RoutedEventArgs e)
{
_timer = new DispatcherTimer(TimeSpan.FromMilliseconds(200), DispatcherPriority.Background, TimerTick, Dispatcher);
_timer = new DispatcherTimer(TimeSpan.FromMilliseconds(50), DispatcherPriority.Background, TimerTick, Dispatcher);
_timer.Start();
}

Expand All @@ -29,6 +29,6 @@ private void TimerTick(object? sender, EventArgs e)

private void GameStateParameterItem_OnUnloaded(object sender, RoutedEventArgs e)
{
_timer.Stop();
_timer?.Stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:controls="clr-namespace:AuroraRgb.Controls"
Loaded="GameStateParameterPicker_OnLoaded"
mc:Ignorable="d"
Height="22" MinWidth="60">

Expand All @@ -25,7 +26,7 @@

<!-- Dropdown content -->
<Popup StaysOpen="False" IsOpen="{Binding IsOpen, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:GameStateParameterPicker}}}">
<Grid x:Name="popupContent" Background="#1A1A1A" Height="280" Width="450">
<Grid x:Name="PopupContent" Background="#1A1A1A" Height="280" Width="450">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
Expand All @@ -40,21 +41,21 @@
</StackPanel>

<!-- List boxes (aux is for animation) -->
<ListBox x:Name="mainListBox" Grid.Row="1"
<ListBox x:Name="MainListBox" Grid.Row="1"
ItemsSource="{Binding CurrentParameterListItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:GameStateParameterPicker}}}"
ItemTemplate="{StaticResource ListItemTemplate}" SelectedValuePath="Path" Width="{Binding ActualWidth, ElementName=popupContent}" HorizontalAlignment="Left"
ItemTemplate="{StaticResource ListItemTemplate}" SelectedValuePath="Path" Width="{Binding ActualWidth, ElementName=PopupContent}" HorizontalAlignment="Left"
controls:GameStateParameterPicker.TransformRelativeOffset="0" RenderTransform="{controls:DoubleToRelativeTransformOffset}" PreviewMouseLeftButtonDown="MainListBox_PreviewMouseLeftButtonDown" />
<ListBox x:Name="auxillaryListbox" Grid.Row="1" ItemTemplate="{StaticResource ListItemTemplate}" Width="{Binding ActualWidth, ElementName=popupContent}"
<ListBox x:Name="AuxillaryListbox" Grid.Row="1" ItemTemplate="{StaticResource ListItemTemplate}" Width="{Binding ActualWidth, ElementName=PopupContent}"
SelectedValuePath="Path" HorizontalAlignment="Left" controls:GameStateParameterPicker.TransformRelativeOffset="-1" RenderTransform="{controls:DoubleToRelativeTransformOffset}" />

<!-- Numeric input for numeric types -->
<DockPanel Grid.Row="2" LastChildFill="True">
<TextBlock Text="Or enter number:" VerticalAlignment="Center" Margin="6,4,0,6" DockPanel.Dock="Left" />
<xctk:DoubleUpDown x:Name="numericEntry" Margin="6" ValueChanged="NumericEntry_ValueChanged" />
<xctk:DoubleUpDown x:Name="NumericEntry" Margin="6" ValueChanged="NumericEntry_ValueChanged" />
</DockPanel>

<!-- Border around all popup content -->
<Border BorderBrush="#454545" BorderThickness="1" Grid.RowSpan="999" />
<Border Grid.Row="0" BorderBrush="#454545" BorderThickness="1" Grid.RowSpan="2" />
</Grid>
</Popup>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace AuroraRgb.Controls;

public partial class GameStateParameterPicker : INotifyPropertyChanged {

public event EventHandler<SelectedPathChangedEventArgs> SelectedPathChanged;
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler<SelectedPathChangedEventArgs>? SelectedPathChanged;
public event PropertyChangedEventHandler? PropertyChanged;

public GameStateParameterPicker() {
InitializeComponent();
Expand Down Expand Up @@ -100,14 +100,14 @@ private static void SelectedPathDPChanged(DependencyObject sender, DependencyPro

if (double.TryParse(e.NewValue.ToString(), CultureInfo.InvariantCulture, out var val)) {
// If a raw number has been entered, fill in the numeric stepper
picker.numericEntry.Value = val;
picker.NumericEntry.Value = val;
} else {
// Else if an actual path has been given, split it up into it's ""directories""
// For the path to be valid (and to be passed as a param to this method) it will be a path to a variable, not a "directory". We use this assumption.
picker.WorkingPath = (VariablePath)e.NewValue;
picker.GoUp(); // Remove the last one, since the working path should not include the actual var name
picker.NotifyChanged(nameof(WorkingPath), nameof(CurrentParameterListItems)); // All these things will be different now, so trigger an update of anything requiring them
picker.mainListBox.SelectedValue = e.NewValue.ToString().Split('/').Last(); // The selected item in the list will be the last part of the path
picker.MainListBox.SelectedValue = e.NewValue.ToString().Split('/').Last(); // The selected item in the list will be the last part of the path
}

// Raise an event informing subscribers
Expand All @@ -125,11 +125,16 @@ public Application Application
set
{
SetValue(ApplicationProperty, value);
var propertyEntryToValueConverter = (PropertyEntryToValueConverter)Resources["EntryToValueConverter"];
propertyEntryToValueConverter.App = value;
UpdateConverterApp();
}
}

private void UpdateConverterApp()
{
var propertyEntryToValueConverter = (PropertyEntryToValueConverter)Resources["EntryToValueConverter"];
propertyEntryToValueConverter.App = Application;
}

public static readonly DependencyProperty ApplicationProperty =
DependencyProperty.Register(nameof(Application), typeof(Application), typeof(GameStateParameterPicker), new PropertyMetadata(null, ApplicationOrPropertyTypeChange));
#endregion
Expand Down Expand Up @@ -173,17 +178,17 @@ private bool ValidatePath(VariablePath path) =>
/// <summary>Animates the list boxes.</summary>
/// <param name="dx">Direction of animation. -1 for previous, 1 for next.</param>
private void Animate(int dx) {
var auxillaryScrollViewer = auxillaryListbox.FindChildOfType<ScrollViewer>();
var mainScrollViewer = mainListBox.FindChildOfType<ScrollViewer>();
var auxillaryScrollViewer = AuxillaryListbox.FindChildOfType<ScrollViewer>();
var mainScrollViewer = MainListBox.FindChildOfType<ScrollViewer>();
auxillaryScrollViewer.ScrollToVerticalOffset(mainScrollViewer.VerticalOffset);

// Move the aux to the centre and move the main to the side of it
SetTransformRelativeOffset(mainListBox, dx);
SetTransformRelativeOffset(mainListBox, 0);
SetTransformRelativeOffset(MainListBox, dx);
SetTransformRelativeOffset(MainListBox, 0);

// Animate the aux moving away and the main moving in
CreateStoryboard(dx, 0, mainListBox).Begin();
CreateStoryboard(0, -dx, auxillaryListbox).Begin();
CreateStoryboard(dx, 0, MainListBox).Begin();
CreateStoryboard(0, -dx, AuxillaryListbox).Begin();
}

/// <summary>Creates a storyboard animation that changes the TransformRelativeOffsetProperty property from `fromX` to `toX` for the given target.</summary>
Expand Down Expand Up @@ -213,7 +218,7 @@ private Storyboard CreateStoryboard(int from, int to, UIElement target) {
private void BackBtn_Click(object? sender, RoutedEventArgs e) {
if (!string.IsNullOrEmpty(WorkingPath.GsiPath)) {
// Make the aux list box take on the same items as the current one so that when animated (since the aux is moved to the middle first) it looks natural
auxillaryListbox.ItemsSource = CurrentParameterListItems;
AuxillaryListbox.ItemsSource = CurrentParameterListItems;

Animate(-1);
GoUp(); // Remove the last "directory" off the working path
Expand All @@ -231,15 +236,15 @@ private void MainListBox_PreviewMouseLeftButtonDown(object? sender, MouseButtonE
* Side note: THIS PICKER HAS TAKEN ME SO DAMN LONG TO MAKE. Probably longer than the actual GSI plugin system itself.... But hey, I'm proud of it. */

// Element selection code is adapted from http://kevin-berridge.blogspot.com/2008/06/wpf-listboxitem-double-click.html
var el = (UIElement)mainListBox.InputHitTest(e.GetPosition(mainListBox));
while (el != null && el != mainListBox) {
var el = (UIElement)MainListBox.InputHitTest(e.GetPosition(MainListBox));
while (el != null && el != MainListBox) {
if (el is ListBoxItem item && item.DataContext is GameStateParameterLookupEntry itemContext) {

// Since the user has picked an item on the list, we want to clear the numeric box so it is obvious to the user that the number is having no effect.
numericEntry.Value = null;
NumericEntry.Value = null;

// Copy the current list items to the aux list box incase the list box is animated later. This must be done BEFORE changing workingpath
auxillaryListbox.ItemsSource = CurrentParameterListItems;
AuxillaryListbox.ItemsSource = CurrentParameterListItems;

if (itemContext.IsFolder) {
// If the user selected a directory, animate the box.
Expand All @@ -262,7 +267,7 @@ private void NumericEntry_ValueChanged(object? sender, RoutedPropertyChangedEven
// If there is no value, then this will have been set programmatically, so do nothing since we don't want to end up in a change event handler loop
if (!v.HasValue) return;

mainListBox.SelectedItem = null; // Clear the selection on the list box (to emphasise to the user it is now irrelevant)
MainListBox.SelectedItem = null; // Clear the selection on the list box (to emphasise to the user it is now irrelevant)
SelectedPath = new VariablePath(v.ToString()); // Set the selectedpath to be the value of this numeric stepper
NotifyChanged(nameof(SelectedPath));
}
Expand All @@ -285,9 +290,9 @@ private void NotifyChanged(params string[] propNames) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}

private void FrameworkElement_OnSourceUpdated(object? sender, DataTransferEventArgs e)
private void GameStateParameterPicker_OnLoaded(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
UpdateConverterApp();
}
}

Expand Down Expand Up @@ -329,6 +334,10 @@ public class PropertyEntryToValueConverter : IValueConverter
{
public Application? App { get; set; }

public PropertyEntryToValueConverter()
{
}

public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not GameStateParameterLookupEntry entry)
Expand Down

0 comments on commit 6a9a113

Please sign in to comment.