Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into feature/evaluatable-…
Browse files Browse the repository at this point in the history
…debug
  • Loading branch information
Wibble199 committed May 17, 2020
2 parents 07c4734 + d9ed030 commit d7fa8fa
Show file tree
Hide file tree
Showing 139 changed files with 1,298 additions and 1,669 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<BooleanToVisibilityConverter x:Key="BoolToVisConv" />
<DataTemplate x:Key="ListItemTemplate">
<Grid>
<TextBlock Text="{Binding DisplayPath}" Padding="4,1" Margin="0,0,16,0" />
<TextBlock Text="{Binding DisplayName}" Padding="4,1" Margin="0,0,16,0" />
<Image Source="/Aurora;component/Resources/icons8-folder-30.png" Width="16" Height="16" HorizontalAlignment="Right" VerticalAlignment="Center" Visibility="{Binding IsFolder, Converter={StaticResource BoolToVisConv}}" />
</Grid>
</DataTemplate>
Expand All @@ -36,8 +36,8 @@

<!-- Up button and current "directory" -->
<StackPanel Grid.Row="0" Orientation="Vertical">
<Button Content="⬅ Previous" IsEnabled="{Binding WorkingPathStr, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type l:GameStateParameterPicker}}, Converter={StaticResource IsStringNotNullConv}}" Margin="6" Padding="6,2" Click="BackBtn_Click" />
<TextBlock Text="{Binding WorkingPathStr, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type l:GameStateParameterPicker}}}" Margin="6,0,6,6" VerticalAlignment="Center" />
<Button Content="⬅ Previous" IsEnabled="{Binding WorkingPath, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type l:GameStateParameterPicker}}, Converter={StaticResource IsStringNotNullConv}}" Margin="6" Padding="6,2" Click="BackBtn_Click" />
<TextBlock Text="{Binding WorkingPath, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type l:GameStateParameterPicker}}}" Margin="6,0,6,6" VerticalAlignment="Center" />
</StackPanel>

<!-- List boxes (aux is for animation) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,28 @@ public partial class GameStateParameterPicker : UserControl, INotifyPropertyChan
public event EventHandler<SelectedPathChangedEventArgs> SelectedPathChanged;
public event PropertyChangedEventHandler PropertyChanged;

private List<string> parameterList;

public GameStateParameterPicker() {
InitializeComponent();
}

#region UI Properties
/// <summary>
/// The current parts that make up the path. E.G. "LocalPCInfo/RAM" -> "LocalPCInfo", "RAM"
/// </summary>
private Stack<string> WorkingPath { get; set; } = new Stack<string>();

/// <summary>
/// Lazy-evaluated list of parameters for this application and property type.
/// </summary>
public List<string> ParameterList => parameterList ?? (parameterList = Application?.ParameterLookup?.GetParameters(PropertyType).ToList());
public string WorkingPath { get; set; } = "";

/// <summary>
/// Gets a list of items that should be displayed in the parameter list (based on the current "parent" variable).
/// </summary>
public IEnumerable<PathOption> CurrentParameterListItems {
public IEnumerable<GameStateParameterLookupEntry> CurrentParameterListItems {
get {
// If the application or param lookup is null, we don't know the parameters so do nothing
if (Application?.ParameterLookup == null) return null;

// If the given working path is a path to a variable (which it shouldn't be), pop the last item (the variable name) from the path to give just the "directory"
if (Application.ParameterLookup.IsValidParameter(WorkingPathStr))
WorkingPath.Pop();

// Generate the string version of this working path (and cache it)
var _workingPath = WorkingPathStr;
if (_workingPath != "") _workingPath += "/"; // If not at the root directory, add / to the end of the test path. This means it doesn't get confused with things such as `CPU` and `CPUUsage`.
return from path in ParameterList // With all properties in the current param lookup that are of a valid type (e.g. numbers)
where path.StartsWith(_workingPath) // Pick only the ones that start with the same working path
let pathSplit = path.Substring(_workingPath.Length).Split('/') // Get a list of all remaining parts of the path (e.g. if this was A/B/C and current path was A, pathSplit would be 'B', 'C')
let isFolder = pathSplit.Length > 1 // If there is more than one part of the path remaining, this must be a directory
group isFolder by pathSplit[0] into g // Group by the path name so duplicates are removed
orderby !g.First(), g.Key // Order the remaining (distinct) items by folders first, then order by their name
select new PathOption(g.Key, g.First()); // Finally, put them in a POCO so we can bind the UI to these properties.
if (Application.ParameterLookup.IsValidParameter(WorkingPath))
GoUp();

return Application.ParameterLookup.Children(WorkingPath, PropertyType).OrderBy(p => !p.IsFolder).ThenBy(p => p.DisplayName);
}
}

/// <summary>
/// Returns the string representation of the current working path.
/// </summary>
public string WorkingPathStr => string.Join("/", WorkingPath.Reverse());
#endregion

#region IsOpen Dependency Property
Expand Down Expand Up @@ -113,9 +89,9 @@ private static void SelectedPathDPChanged(DependencyObject sender, DependencyPro
} 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 = new Stack<string>(e.NewValue.ToString().Split('/'));
picker.WorkingPath.Pop(); // Remove the last one, since the working path should not include the actual var name
picker.NotifyChanged(nameof(WorkingPath), nameof(WorkingPathStr), nameof(ParameterList), nameof(CurrentParameterListItems)); // All these things will be different now, so trigger an update of anything requiring them
picker.WorkingPath = (string)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
}

Expand All @@ -141,18 +117,17 @@ public Application Application {
/// <summary>
/// The types of properties that will be shown to the user.
/// </summary>
public PropertyType PropertyType {
get => (PropertyType)GetValue(PropertyTypeProperty);
public GSIPropertyType PropertyType {
get => (GSIPropertyType)GetValue(PropertyTypeProperty);
set => SetValue(PropertyTypeProperty, value);
}

public static readonly DependencyProperty PropertyTypeProperty =
DependencyProperty.Register(nameof(PropertyType), typeof(PropertyType), typeof(GameStateParameterPicker), new PropertyMetadata(PropertyType.None, ApplicationOrPropertyTypeChange));
DependencyProperty.Register(nameof(PropertyType), typeof(GSIPropertyType), typeof(GameStateParameterPicker), new PropertyMetadata(GSIPropertyType.None, ApplicationOrPropertyTypeChange));

public static void ApplicationOrPropertyTypeChange(DependencyObject sender, DependencyPropertyChangedEventArgs e) {
var picker = (GameStateParameterPicker)sender;
picker.parameterList = null;
picker.NotifyChanged(nameof(ParameterList), nameof(CurrentParameterListItems));
picker.NotifyChanged(nameof(CurrentParameterListItems));

if (!picker.ValidatePath(picker.SelectedPath))
picker.SelectedPath = "";
Expand All @@ -165,11 +140,11 @@ public static void ApplicationOrPropertyTypeChange(DependencyObject sender, Depe
/// </summary>
private bool ValidatePath(string path) =>
// If application parameter context doesn't exist or there is no set type, assume non loaded and allow the path
Application?.ParameterLookup == null || PropertyType == PropertyType.None
Application?.ParameterLookup == null || PropertyType == GSIPropertyType.None
// An empty path is fine
|| string.IsNullOrEmpty(path)
// If we're in number mode, allow the selected path to be a double
|| (PropertyType == PropertyType.Number && double.TryParse(path, out var _))
|| (PropertyType == GSIPropertyType.Number && double.TryParse(path, out var _))
// If not in number mode, must be a valid path and have the same type as the expected property type
|| Application.ParameterLookup.IsValidParameter(path, PropertyType);

Expand Down Expand Up @@ -215,13 +190,13 @@ private Storyboard CreateStoryboard(int from, int to, UIElement target) {

#region Event Handlers
private void BackBtn_Click(object sender, RoutedEventArgs e) {
if (WorkingPath.Count > 0) {
if (!string.IsNullOrEmpty(WorkingPath)) {
// 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;

Animate(-1);
WorkingPath.Pop(); // Remove the last "directory" off the working path
NotifyChanged(nameof(CurrentParameterListItems), nameof(WorkingPathStr)); // These properties will have changed so any UI stuff that relies on it should update
GoUp(); // Remove the last "directory" off the working path
NotifyChanged(nameof(CurrentParameterListItems), nameof(WorkingPath)); // These properties will have changed so any UI stuff that relies on it should update
}
}

Expand All @@ -237,29 +212,24 @@ private void MainListBox_PreviewMouseLeftButtonDown(object sender, System.Window
// 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) {
if (el is ListBoxItem item) {
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;

// Copy the current list items to the aux list box incase the list box is animated later. This must be done BEFORE the workingpath.push call.
// 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;

// Add the clicked item to the working path (even if it is an end variable, not a "directory")
WorkingPath.Push(((PathOption)item.DataContext).Path);
if (itemContext.IsFolder) {
// If the user selected a directory, animate the box.
WorkingPath = itemContext.Path;
Animate(1);
NotifyChanged(nameof(CurrentParameterListItems), nameof(WorkingPath));

var path = string.Join("/", WorkingPath.Reverse());
if (Application?.ParameterLookup?.IsValidParameter(path) ?? false) {
// If it turns out the user has selected an end variable, we want to update the DependencyObject for the selected path
SelectedPath = path;
NotifyChanged(nameof(SelectedPath));
} else {
// If the user has selected a directory instead (i.e. isn't not a valid parameter) then perform the animation since there will now be new properties to choose from
Animate(1);
// Otherwise if the user selected a parameter, update the SelectedPath Dependency Property (which will fire a change event).
SelectedPath = itemContext.Path;
}

// Regardless of whether it was a variable or a directory, the list and path will have changed
NotifyChanged(nameof(CurrentParameterListItems), nameof(WorkingPathStr));
}
el = (UIElement)VisualTreeHelper.GetParent(el);
}
Expand All @@ -277,24 +247,15 @@ private void NumericEntry_ValueChanged(object sender, RoutedPropertyChangedEvent
}
#endregion

private void NotifyChanged(params string[] propNames) {
foreach (var prop in propNames)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}


/// <summary>
/// Basic POCO for holding a bit of metadata about a path option.
/// Removes the last parameter or folder from the working path.
/// </summary>
public class PathOption {
public PathOption(string path, bool isFolder) {
Path = path;
IsFolder = isFolder;
}
private void GoUp() =>
WorkingPath = WorkingPath.Contains("/") ? WorkingPath.Substring(0, WorkingPath.LastIndexOf("/")) : "";

public string DisplayPath => Path.CamelCaseToSpaceCase();
public string Path { get; }
public bool IsFolder { get; }
private void NotifyChanged(params string[] propNames) {
foreach (var prop in propNames)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}

Expand Down Expand Up @@ -325,10 +286,10 @@ public class IsStringNotNullOrWhitespaceConverter : IValueConverter {

/// <summary>
/// Converter that converts a PropertyType enum value to a GridLength. Used for binding onto one of the row definition properties to hide a row when
/// the property type is anything other than <see cref="PropertyType.Number" />.
/// the property type is anything other than <see cref="GSIPropertyType.Number" />.
/// </summary>
public class PropertyTypeToGridLengthConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => new GridLength(0, (PropertyType)value == PropertyType.Number ? GridUnitType.Auto : GridUnitType.Pixel);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => new GridLength(0, (GSIPropertyType)value == GSIPropertyType.Number ? GridUnitType.Auto : GridUnitType.Pixel);
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => new NotImplementedException();
}

Expand Down
11 changes: 6 additions & 5 deletions Project-Aurora/Project-Aurora/Devices/Uniwill/UniwillDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ private void ChoiceGamingCenter()

private GAMECENTERTYPE CheckGC()
{
try
int? Control = (int?)Registry.GetValue(keyName, "AuroraSwitch", null);

if(Control.HasValue)
{
int Control = (int)Registry.GetValue(keyName, "AuroraSwitch", null);
GamingCenterType = GAMECENTERTYPE.GAMINGTCENTER;
SwitchOn = Control;
SwitchOn = Control.Value;
}
catch
else
{
GamingCenterType = GAMECENTERTYPE.NONE;
SwitchOn = 0;
Expand Down Expand Up @@ -148,7 +149,7 @@ public bool Initialize()
}
catch
{
Debug.WriteLine("Uniwill device error!");
Global.logger.Error("Uniwill device error!");
}
// Mark Initialized = FALSE
isInitialized = false;
Expand Down
Loading

0 comments on commit d7fa8fa

Please sign in to comment.