Skip to content

Commit

Permalink
Finished diagnostics window with translations
Browse files Browse the repository at this point in the history
  • Loading branch information
csutorasa committed May 3, 2018
1 parent 17fb06a commit c323e22
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 42 deletions.
1 change: 1 addition & 0 deletions XOutput/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<Converters:ColorConverter x:Key="ColorConverter"/>
<Converters:BlinkConverter x:Key="BlinkConverter"/>
<Converters:DecimalToStringConverter x:Key="DecimalToStringConverter"/>
<Converters:EqualsToVisibilityConverter x:Key="EqualsToVisibilityConverter"/>
</Application.Resources>
</Application>
12 changes: 12 additions & 0 deletions XOutput/Devices/Input/InputDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public IEnumerable<DiagnosticsResult> GetResults()
GetButtonsResult(),
GetDPadResult(),
GetForceFeedbackResult(),
GetSlidersResult(),
};
}

Expand All @@ -48,6 +49,17 @@ public DiagnosticsResult GetAxesResult()
return result;
}

public DiagnosticsResult GetSlidersResult()
{
int slidersCount = device.Sliders.Count();
return new DiagnosticsResult
{
Value = slidersCount,
Type = InputDiagnosticsTypes.SlidersCount,
State = DiagnosticsResultState.Passed,
};
}

public DiagnosticsResult GetButtonsResult()
{
int buttonsCount = device.Buttons.Count();
Expand Down
2 changes: 1 addition & 1 deletion XOutput/Devices/Input/InputDiagnosticsTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace XOutput.Devices.Input
{
public enum InputDiagnosticsTypes
{

AxesCount,
ButtonsCount,
DPadCount,
SlidersCount,
ForceFeedbackCount,
}
}
24 changes: 24 additions & 0 deletions XOutput/Resources/languages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ WaitingForInputFor=Waiting for input for
Keyboard=Keyboard
Warning=Warning
Error=Error
True=true
False=false
Test=Test
System=System
DiagnosticsMenu=Diagnostics
InputDiagnosticsTypes.AxesCount=Axes count
InputDiagnosticsTypes.ButtonsCount=Buttons count
InputDiagnosticsTypes.DPadCount=DPad count
InputDiagnosticsTypes.SlidersCount=Sliders count
InputDiagnosticsTypes.ForceFeedbackCount=Force feedback motors count
XInputDiagnosticsTypes.XDevice=Virtualization software is installed
XInputDiagnosticsTypes.ScpDevice=SCPToolkit is installed
XInputDiagnosticsTypes.VigemDevice=ViGEm is installed
VersionCheckError=There was an error while checking for updates.
VersionCheckNewRelease=This is a development release.
VersionCheckUpToDate=The software is up to date.
Expand Down Expand Up @@ -269,6 +281,18 @@ Keyboard=Billentyűzet
Warning=Figyelmeztetés
Error=Hiba
Test=Teszt
True=igaz
False=hamis
System=Rendszer
DiagnosticsMenu=Diagnosztika
InputDiagnosticsTypes.AxesCount=Tengelyek száma
InputDiagnosticsTypes.ButtonsCount=Gombok száma
InputDiagnosticsTypes.DPadCount=DPadok száma
InputDiagnosticsTypes.SlidersCount=Csúszkák száma
InputDiagnosticsTypes.ForceFeedbackCount=Rezgő motorok száma
XInputDiagnosticsTypes.XDevice=Virtualizációs szoftver telepítve
XInputDiagnosticsTypes.ScpDevice=SCPToolkit telepítve
XInputDiagnosticsTypes.VigemDevice=ViGEm telepítve
VersionCheckError=Hiba történt a frissítés keresése közben.
VersionCheckNewRelease=Ez egy fejlesztői verzió.
VersionCheckUpToDate=Az alkalmazás legfrissebb verzióját használja.
Expand Down
81 changes: 55 additions & 26 deletions XOutput/UI/Component/DiagnosticsItemView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,68 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:XOutput.UI.Component"
xmlns:diagnostics="clr-namespace:XOutput.Diagnostics"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:DiagnosticsItemViewModel, IsDesignTimeCreatable=False}"
d:DesignHeight="30" d:DesignWidth="490">
<UserControl.Resources>
<DataTemplate x:Key="ResultTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0">
<Label.Content>
<MultiBinding Converter="{StaticResource DynamicLanguageConverter}">
<Binding Path="Model.Path" RelativeSource="{RelativeSource AncestorType={x:Type local:DiagnosticsItemView}}" />
<Binding Path="Type" />
</MultiBinding>
</Label.Content>
</Label>
<Label Grid.Column="1" Content="{Binding Value}"/>
<Label Grid.Column="2">
<Label.Content>
<MultiBinding Converter="{StaticResource DynamicLanguageConverter}">
<Binding Path="Model.Path" RelativeSource="{RelativeSource AncestorType={x:Type local:DiagnosticsItemView}}" />
<Binding Path="State" />
</MultiBinding>
</Label.Content>
</Label>
</Grid>
<Border BorderThickness="0 0 0 1" BorderBrush="LightGray">
<Grid Height="30">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0">
<Label.Content>
<MultiBinding Converter="{StaticResource DynamicLanguageConverter}">
<Binding Path="DataContext.LanguageModel.Data" RelativeSource="{RelativeSource AncestorType={x:Type local:DiagnosticsItemView}}" />
<Binding Path="Type" />
</MultiBinding>
</Label.Content>
</Label>
<Label Grid.Column="1">
<Label.Content>
<MultiBinding Converter="{StaticResource DynamicLanguageConverter}">
<Binding Path="DataContext.LanguageModel.Data" RelativeSource="{RelativeSource AncestorType={x:Type local:DiagnosticsItemView}}" />
<Binding Path="Value" />
</MultiBinding>
</Label.Content>
</Label>
<Label Grid.Column="2" Visibility="{Binding State, Converter={StaticResource EqualsToVisibilityConverter}, ConverterParameter={x:Static diagnostics:DiagnosticsResultState.Passed}}">
<Canvas>
<Ellipse Fill="Green" Width="20" Height="20"/>
<Polygon Fill="White" Points="4,11 5,10 8,13 15,4 16,5 9,16 7,16"/>
</Canvas>
</Label>
<Label Grid.Column="2" Visibility="{Binding State, Converter={StaticResource EqualsToVisibilityConverter}, ConverterParameter={x:Static diagnostics:DiagnosticsResultState.Warning}}">
<Canvas>
<Polygon Fill="Yellow" Points="0,20 10,0 20,20" Stroke="Orange"/>
<Polygon Fill="Orange" Points="8,6 12,6 11,13 9,13"/>
<Ellipse Fill="Orange" Width="4" Height="4">
<Ellipse.RenderTransform>
<TranslateTransform X="8" Y="15"/>
</Ellipse.RenderTransform>
</Ellipse>
</Canvas>
</Label>
<Label Grid.Column="2" Visibility="{Binding State, Converter={StaticResource EqualsToVisibilityConverter}, ConverterParameter={x:Static diagnostics:DiagnosticsResultState.Failed}}">
<Canvas>
<Ellipse Fill="Red" Width="20" Height="20"/>
<Rectangle Fill="White" Width="20" Height="20">
<Rectangle.RenderTransform>
<ScaleTransform CenterX="10" CenterY="10" ScaleX="0.5" ScaleY="0.2"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Label>
</Grid>
</Border>
</DataTemplate>
</UserControl.Resources>
<StackPanel>
<Label Content="{Binding Model.Source}"/>
<StackPanel Margin="0 0 0 15">
<Label Content="{Binding Model.Source}" FontSize="16"/>
<ItemsControl ItemTemplate="{StaticResource ResultTemplate}" ItemsSource="{Binding Model.Results}" />
</StackPanel>
</UserControl>
2 changes: 1 addition & 1 deletion XOutput/UI/Component/DiagnosticsItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DiagnosticsItemViewModel(DiagnosticsItemModel model, IDiagnostics diagnos
protected string SourceToString(object source)
{
if (source == null)
return "System";
return LanguageModel.Instance.Translate("System");
if (source is IInputDevice)
return (source as IInputDevice).DisplayName;
return null;
Expand Down
29 changes: 18 additions & 11 deletions XOutput/UI/Converters/DynamicLanguageConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,33 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
key = values[1].GetType().Name + "." + values[1].ToString();
return getTranslation(translations, key) ?? values[1].ToString();
}
key = values[1] as string;
else if (values[1] is string)
key = values[1] as string;
else if (values[1] is bool)
key = (bool)values[1] ? "True" : "False";
else if (values[1] is sbyte || values[1] is byte || values[1] is char || values[1] is short || values[1] is ushort || values[1] is int || values[1] is uint || values[1] is long || values[1] is ulong || values[1] is decimal)
return values[1].ToString();
else
throw new ArgumentException(values[1] + " cannot be translated");
return getTranslation(translations, key) ?? key;
}

/// <summary>
/// Intentionally not implemented.
/// </summary>
/// <param name="value">Ignored</param>
/// <param name="targetTypes">Ignored</param>
/// <param name="parameter">Ignored</param>
/// <param name="culture">Ignored</param>
/// <returns></returns>
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
/// <summary>
/// Intentionally not implemented.
/// </summary>
/// <param name="value">Ignored</param>
/// <param name="targetTypes">Ignored</param>
/// <param name="parameter">Ignored</param>
/// <param name="culture">Ignored</param>
/// <returns></returns>
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

protected string getTranslation(Dictionary<string, string> translations, string key)
{
if(translations == null || key == null || !translations.ContainsKey(key))
if (translations == null || key == null || !translations.ContainsKey(key))
{
return null;
}
Expand Down
45 changes: 45 additions & 0 deletions XOutput/UI/Converters/EqualsToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace XOutput.UI.Converters
{
/// <summary>
/// Compares enum value and converts to visibility.
/// Cannot be used backwards.
/// </summary>
public class EqualsToVisibilityConverter : IValueConverter
{
/// <summary>
/// Compares enum value and converts to visibility.
/// </summary>
/// <param name="value">Value to convert</param>
/// <param name="targetType">Ignored</param>
/// <param name="parameter">Ignored</param>
/// <param name="culture">Ignored</param>
/// <returns>If the value is not null</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.Equals(parameter) ? Visibility.Visible : Visibility.Collapsed;
}

/// <summary>
/// Intentionally not implemented.
/// </summary>
/// <param name="value">Ignored</param>
/// <param name="targetType">Ignored</param>
/// <param name="parameter">Ignored</param>
/// <param name="culture">Ignored</param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion XOutput/UI/Windows/DiagnosticsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Loaded="WindowLoaded"
Closed="WindowClosed"
d:DataContext="{d:DesignInstance Type=local:DiagnosticsViewModel, IsDesignTimeCreatable=False}"
Title="Diagnostics" Height="550" Width="550">
Title="{Binding LanguageModel.Data, Converter={StaticResource LanguageConverter}, ConverterParameter='DiagnosticsMenu'}" Height="750" Width="550">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsControl Margin="5" ItemsPanel="{StaticResource VerticalStackPanel}" ItemsSource="{Binding Model.Diagnostics}"/>
</ScrollViewer>
Expand Down
4 changes: 2 additions & 2 deletions XOutput/UI/Windows/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ public void OpenSettings()

public void OpenDiagnostics()
{
ICollection<IDiagnostics> elements = Model.Controllers.Select(c => c.ViewModel.Model.Controller.InputDevice)
IList<IDiagnostics> elements = Model.Controllers.Select(c => c.ViewModel.Model.Controller.InputDevice)
.Select(d => new InputDiagnostics(d)).OfType<IDiagnostics>().ToList();
elements.Add(new Devices.XInput.XInputDiagnostics());
elements.Insert(0, new Devices.XInput.XInputDiagnostics());

new DiagnosticsWindow(new DiagnosticsViewModel(new DiagnosticsModel(), elements)).ShowDialog();
}
Expand Down
1 change: 1 addition & 0 deletions XOutput/XOutput.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<Compile Include="UI\Converters\ColorConverter.cs" />
<Compile Include="UI\Converters\EnumerableCountToVisibilityConverter.cs" />
<Compile Include="UI\Converters\MultiConverter.cs" />
<Compile Include="UI\Converters\EqualsToVisibilityConverter.cs" />
<Compile Include="UI\Converters\NotNullToBoolConverter.cs" />
<Compile Include="UI\LanguageModel.cs" />
<Compile Include="Tools\LanguageManager.cs" />
Expand Down

0 comments on commit c323e22

Please sign in to comment.