Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
.vs/
# Output
XOutput/bin/
XOutput/obj/

# Visual Studio
.vs/

# NuGet
packages/

# User settings
*.csproj.user
52 changes: 31 additions & 21 deletions XOutput/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:XOutput"
xmlns:Converters="clr-namespace:XOutput.UI.Converters"
StartupUri="UI/Windows/MainWindow.xaml">
Startup="Application_Startup">
<Application.Resources>
<ItemsPanelTemplate x:Key="VerticalStackPanel">
<StackPanel Orientation="Vertical" Focusable="False"/>
</ItemsPanelTemplate>

<Converters:BoolToBrushConverter x:Key="BoolToBrushConverter"></Converters:BoolToBrushConverter>
<Converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<Converters:BoolInverterConverter x:Key="BoolInverterConverter"/>
<Converters:MultiConverter x:Key="InvertAndVisibilityConverter">
<Converters:BoolInverterConverter/>
<Converters:BoolToVisibilityConverter/>
</Converters:MultiConverter>
<Converters:NotNullToBoolConverter x:Key="NotNullToBoolConverter"/>
<Converters:DynamicLanguageConverter x:Key="DynamicLanguageConverter"/>
<Converters:EnumerableNotEmptyToVisibilityConverter x:Key="EnumerableNotEmptyToVisibilityConverter"/>
<Converters:EnumerableCountToVisibilityConverter x:Key="EnumerableCountToVisibilityConverter"/>
<Converters:LanguageConverter x:Key="LanguageConverter"/>
<Converters:ColorConverter x:Key="ColorConverter"/>
<Converters:BlinkConverter x:Key="BlinkConverter"/>
<Converters:DecimalToStringConverter x:Key="DecimalToStringConverter"/>
<Converters:EqualsToVisibilityConverter x:Key="EqualsToVisibilityConverter"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
<ItemsPanelTemplate x:Key="VerticalStackPanel">
<StackPanel Orientation="Vertical" Focusable="False"/>
</ItemsPanelTemplate>
<Converters:BoolToBrushConverter x:Key="BoolToBrushConverter"></Converters:BoolToBrushConverter>
<Converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<Converters:BoolInverterConverter x:Key="BoolInverterConverter"/>
<Converters:MultiConverter x:Key="InvertAndVisibilityConverter">
<Converters:BoolInverterConverter/>
<Converters:BoolToVisibilityConverter/>
</Converters:MultiConverter>
<Converters:NotNullToBoolConverter x:Key="NotNullToBoolConverter"/>
<Converters:DynamicLanguageConverter x:Key="DynamicLanguageConverter"/>
<Converters:EnumerableNotEmptyToVisibilityConverter x:Key="EnumerableNotEmptyToVisibilityConverter"/>
<Converters:EnumerableCountToVisibilityConverter x:Key="EnumerableCountToVisibilityConverter"/>
<Converters:LanguageConverter x:Key="LanguageConverter"/>
<Converters:ColorConverter x:Key="ColorConverter"/>
<Converters:BlinkConverter x:Key="BlinkConverter"/>
<Converters:DecimalToStringConverter x:Key="DecimalToStringConverter"/>
<Converters:EqualsToVisibilityConverter x:Key="EqualsToVisibilityConverter"/>
</ResourceDictionary>
</Application.Resources>
</Application>
11 changes: 11 additions & 0 deletions XOutput/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using XOutput.Tools;
using XOutput.UI.Windows;

namespace XOutput
{
Expand Down Expand Up @@ -49,5 +51,14 @@ public static void Main()
}
}
}

private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow mainWindow = new MainWindow(new MainWindowViewModel(new MainWindowModel(), Dispatcher));
if (!ArgumentParser.Instance.Minimized)
{
mainWindow.Show();
}
}
}
}
81 changes: 0 additions & 81 deletions XOutput/Devices/AbstractInputHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace XOutput.Devices.Input
namespace XOutput.Devices
{
/// <summary>
/// Event delegate for DeviceDisconnected event.
Expand Down
8 changes: 4 additions & 4 deletions XOutput/Devices/DeviceInputChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public class DeviceInputChangedEventArgs : EventArgs
/// <summary>
/// Gets the changed values.
/// </summary>
public IEnumerable<Enum> ChangedValues => changedValues.ToArray();
public IEnumerable<InputType> ChangedValues => changedValues.ToArray();
/// <summary>
/// Gets the changed DPad values.
/// </summary>
public IEnumerable<int> ChangedDPads => changedDPads.ToArray();

protected IEnumerable<Enum> changedValues;
protected IEnumerable<InputType> changedValues;
protected IEnumerable<int> changedDPads;

public DeviceInputChangedEventArgs(IEnumerable<Enum> changedValues, IEnumerable<int> changedDPads)
public DeviceInputChangedEventArgs(IEnumerable<InputType> changedValues, IEnumerable<int> changedDPads)
{
this.changedDPads = changedDPads;
this.changedValues = changedValues;
Expand All @@ -41,7 +41,7 @@ public DeviceInputChangedEventArgs(IEnumerable<Enum> changedValues, IEnumerable<
/// </summary>
/// <param name="type">input type</param>
/// <returns></returns>
public bool HasValueChanged(Enum type)
public bool HasValueChanged(InputType type)
{
return changedValues.Contains(type);
}
Expand Down
57 changes: 34 additions & 23 deletions XOutput/Devices/DeviceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,72 @@ public class DeviceState
/// <summary>
/// Gets the current values.
/// </summary>
public Dictionary<Enum, double> Values => values;
public Dictionary<InputType, double> Values => values;
/// <summary>
/// Gets the current DPad values.
/// </summary>
public IEnumerable<DPadDirection> DPads => dPads;
protected Dictionary<Enum, double> values = new Dictionary<Enum, double>();
protected DPadDirection[] dPads;
protected readonly InputType[] valueTypes;
protected readonly KeyValuePair<InputType, double>[] valueData;
protected readonly Dictionary<InputType, double> values = new Dictionary<InputType, double>();
protected readonly DPadDirection[] dPads;
protected readonly Func<InputType, double> typeGetter;
protected readonly Func<int, DPadDirection> dPadGetter;
protected readonly ICollection<int> changedDPads = new HashSet<int>();
protected readonly ICollection<InputType> changedValues = new HashSet<InputType>();

public DeviceState(IEnumerable<Enum> types, int dPadCount)
public DeviceState(IEnumerable<InputType> types, int dPadCount, Func<InputType, double> typeGetter, Func<int, DPadDirection> dPadGetter)
{
foreach (Enum type in types)
foreach (InputType type in types)
{
values.Add(type, 0);
}
valueData = values.ToArray();
dPads = new DPadDirection[dPadCount];
this.typeGetter = typeGetter;
this.dPadGetter = dPadGetter;
valueTypes = values.Keys.ToArray();
}

/// <summary>
/// Sets new DPad values.
/// </summary>
/// <param name="newDPads">new values</param>
/// <returns>changed DPad indices</returns>
public IEnumerable<int> SetDPads(IEnumerable<DPadDirection> newDPads)
public IEnumerable<int> SetDPads()
{
if (newDPads.Count() != dPads.Length)
throw new ArgumentException();
ICollection<int> changed = new HashSet<int>();
foreach (var x in newDPads.Select((d, i) => new { New = d, Old = dPads[i], Index = i }).ToArray())
changedDPads.Clear();
for (int i = 0; i < dPads.Length; i++)
{
if (x.New != x.Old)
DPadDirection newValue = dPadGetter(i);
if (dPads[i] != newValue)
{
dPads[x.Index] = x.New;
changed.Add(x.Index);
dPads[i] = newValue;
changedDPads.Add(i);
}
}
return changed;
return changedDPads;
}

/// <summary>
/// Sets new values.
/// </summary>
/// <param name="newValues">new values</param>
/// <returns>changed value types</returns>
public IEnumerable<Enum> SetValues(Dictionary<Enum, double> newValues)
public IEnumerable<InputType> SetValues()
{
ICollection<Enum> changed = new HashSet<Enum>();
foreach (var x in newValues.Select((d, i) => new { New = d.Value, Old = values[d.Key], Type = d.Key }).ToArray())
changedValues.Clear();
for (int i = 0; i < valueData.Length; i++)
{
if (x.New != x.Old)
var key = valueData[i].Key;
double newValue = typeGetter(key);
double oldValue = valueData[i].Value;
if (oldValue != newValue)
{
values[x.Type] = x.New;
changed.Add(x.Type);
values[key] = newValue;
valueData[i] = new KeyValuePair<InputType, double>(key, newValue);
changedValues.Add(key);
}
}
return changed;
return changedValues;
}
}
}
Loading