Refactor displaying threshold sliders.
Instead of having the sliders show and hide themselves, create the ones that are active in MainWindow.
This commit is contained in:
parent
ae25ed327a
commit
8620da2405
@ -26,7 +26,7 @@ namespace smx_config
|
|||||||
public struct LoadFromConfigDelegateArgs
|
public struct LoadFromConfigDelegateArgs
|
||||||
{
|
{
|
||||||
// This indicates which fields changed since the last call.
|
// This indicates which fields changed since the last call.
|
||||||
public bool ConfigurationChanged, InputChanged, TestDataChanged;
|
public bool ConnectionsChanged, ConfigurationChanged, InputChanged, TestDataChanged;
|
||||||
|
|
||||||
// Data for each of two controllers:
|
// Data for each of two controllers:
|
||||||
public LoadFromConfigDelegateArgsPerController[] controller;
|
public LoadFromConfigDelegateArgsPerController[] controller;
|
||||||
@ -111,6 +111,7 @@ namespace smx_config
|
|||||||
if(WasConnected[pad] != controller.info.connected)
|
if(WasConnected[pad] != controller.info.connected)
|
||||||
{
|
{
|
||||||
args.ConfigurationChanged = true;
|
args.ConfigurationChanged = true;
|
||||||
|
args.ConnectionsChanged = true;
|
||||||
WasConnected[pad] = controller.info.connected;
|
WasConnected[pad] = controller.info.connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ Use if the platform is too sensitive.</clr:String>
|
|||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="{x:Type controls:ThresholdSlider}">
|
<ControlTemplate TargetType="{x:Type controls:ThresholdSlider}">
|
||||||
<StackPanel Margin="0,0,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
|
<StackPanel Margin="0,0,0,0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
<Image
|
<Image
|
||||||
Margin="0,0,0,0"
|
Margin="0,0,0,0"
|
||||||
Height="28" Width="28"
|
Height="28" Width="28"
|
||||||
@ -840,17 +840,15 @@ Use if the platform is too sensitive.</clr:String>
|
|||||||
xml:space="preserve"
|
xml:space="preserve"
|
||||||
TextAlignment="Center"
|
TextAlignment="Center"
|
||||||
>Set the force required to trigger each arrow.</TextBlock>
|
>Set the force required to trigger each arrow.</TextBlock>
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="up-left" controls:ThresholdSlider.Icon="Resources/pad_up_left.png" Margin="0,8,0,0" />
|
<ScrollViewer
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="up" controls:ThresholdSlider.Icon="Resources/pad_up.png" Margin="0,8,0,0" />
|
Height="350"
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="up-right" controls:ThresholdSlider.Icon="Resources/pad_up_right.png" Margin="0,8,0,0" />
|
HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="left" controls:ThresholdSlider.Icon="Resources/pad_left.png" Margin="0,8,0,0" />
|
DockPanel.Dock="Top"
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="center" controls:ThresholdSlider.Icon="Resources/pad_center.png" Margin="0,8,0,0" />
|
>
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="right" controls:ThresholdSlider.Icon="Resources/pad_right.png" Margin="0,8,0,0" />
|
<DockPanel Margin="0,0,0,0" VerticalAlignment="Top" x:Name="ThresholdSliderContainer">
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="down-left" controls:ThresholdSlider.Icon="Resources/pad_down_left.png" Margin="0,8,0,0" />
|
<!-- CreateThresholdSliders adds ThresholdSliders here. -->
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="down" controls:ThresholdSlider.Icon="Resources/pad_down.png" Margin="0,8,0,0" />
|
</DockPanel>
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="down-right" controls:ThresholdSlider.Icon="Resources/pad_down_right.png" Margin="0,8,0,0" />
|
</ScrollViewer>
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="cardinal" controls:ThresholdSlider.Icon="Resources/pad_cardinal.png" Margin="0,8,0,0" />
|
|
||||||
<controls:ThresholdSlider DockPanel.Dock="Top" controls:ThresholdSlider.Type="corner" controls:ThresholdSlider.Icon="Resources/pad_diagonal.png" Margin="0,8,0,0" />
|
|
||||||
<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0,25,0,0" VerticalAlignment="Top"
|
<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0,25,0,0" VerticalAlignment="Top"
|
||||||
xml:space="preserve"
|
xml:space="preserve"
|
||||||
TextAlignment="Center"
|
TextAlignment="Center"
|
||||||
@ -879,6 +877,8 @@ panel to detect releases more quickly.
|
|||||||
DockPanel.Dock="Right" Content="Advanced view"
|
DockPanel.Dock="Right" Content="Advanced view"
|
||||||
VerticalAlignment="Center" HorizontalAlignment="Right"
|
VerticalAlignment="Center" HorizontalAlignment="Right"
|
||||||
IsChecked="{Binding Path=AdvancedModeEnabled, Mode=TwoWay, RelativeSource={RelativeSource Self}}"
|
IsChecked="{Binding Path=AdvancedModeEnabled, Mode=TwoWay, RelativeSource={RelativeSource Self}}"
|
||||||
|
Checked="AdvancedModeEnabledCheckbox_Changed"
|
||||||
|
Unchecked="AdvancedModeEnabledCheckbox_Changed"
|
||||||
/>
|
/>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
@ -68,6 +68,85 @@ namespace smx_config
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<string> thresholdSliderNames = new List<string>()
|
||||||
|
{
|
||||||
|
"up-left", "up", "up-right", "left", "center", "right", "down-left", "down", "down-right", "cardinal", "corner",
|
||||||
|
};
|
||||||
|
|
||||||
|
Dictionary<string,string> thresholdToIcon = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "up-left", "Resources/pad_up_left.png" },
|
||||||
|
{ "up", "Resources/pad_up.png" },
|
||||||
|
{ "up-right", "Resources/pad_up_right.png" },
|
||||||
|
{ "left", "Resources/pad_left.png" },
|
||||||
|
{ "center", "Resources/pad_center.png" },
|
||||||
|
{ "right", "Resources/pad_right.png" },
|
||||||
|
{ "down-left", "Resources/pad_down_left.png" },
|
||||||
|
{ "down", "Resources/pad_down.png" },
|
||||||
|
{ "down-right","Resources/pad_down_right.png" },
|
||||||
|
{ "cardinal", "Resources/pad_cardinal.png" },
|
||||||
|
{ "corner", "Resources/pad_diagonal.png" },
|
||||||
|
};
|
||||||
|
|
||||||
|
bool IsThresholdSliderShown(string type)
|
||||||
|
{
|
||||||
|
bool AdvancedModeEnabled = (bool) AdvancedModeEnabledCheckbox.IsChecked;
|
||||||
|
SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig();
|
||||||
|
bool[] enabledPanels = config.GetEnabledPanels();
|
||||||
|
|
||||||
|
// Up and center are shown in both modes.
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case "up-left": return AdvancedModeEnabled && enabledPanels[0];
|
||||||
|
case "up": return enabledPanels[1];
|
||||||
|
case "up-right": return AdvancedModeEnabled && enabledPanels[2];
|
||||||
|
case "left": return AdvancedModeEnabled && enabledPanels[3];
|
||||||
|
case "center": return enabledPanels[4];
|
||||||
|
case "right": return AdvancedModeEnabled && enabledPanels[5];
|
||||||
|
case "down-left": return AdvancedModeEnabled && enabledPanels[6];
|
||||||
|
case "down": return AdvancedModeEnabled && enabledPanels[7];
|
||||||
|
case "down-right": return AdvancedModeEnabled && enabledPanels[8];
|
||||||
|
|
||||||
|
// Show cardinal and corner if at least one panel they affect is enabled.
|
||||||
|
case "cardinal": return !AdvancedModeEnabled && (enabledPanels[3] || enabledPanels[5] || enabledPanels[8]);
|
||||||
|
case "corner": return !AdvancedModeEnabled && (enabledPanels[0] || enabledPanels[2] || enabledPanels[6] || enabledPanels[8]);
|
||||||
|
default: return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ThresholdSlider CreateThresholdSlider(string type)
|
||||||
|
{
|
||||||
|
ThresholdSlider slider = new ThresholdSlider();
|
||||||
|
slider.Type = type;
|
||||||
|
string iconPath = "pack://application:,,,/" + thresholdToIcon[type];
|
||||||
|
slider.Icon = (new ImageSourceConverter()).ConvertFromString(iconPath) as ImageSource;
|
||||||
|
return slider;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateThresholdSliders()
|
||||||
|
{
|
||||||
|
SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig();
|
||||||
|
bool[] enabledPanels = config.GetEnabledPanels();
|
||||||
|
|
||||||
|
// remove the threshold sliders from xaml, create them all here
|
||||||
|
//
|
||||||
|
// remove the AdvancedModeEnabled binding and ShouldBeDisplayed, handle that here
|
||||||
|
// by creating the ones we need
|
||||||
|
//
|
||||||
|
// then we can add custom sliders too
|
||||||
|
ThresholdSliderContainer.Children.Clear();
|
||||||
|
foreach(string sliderName in thresholdSliderNames)
|
||||||
|
{
|
||||||
|
if(!IsThresholdSliderShown(sliderName))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ThresholdSlider slider = CreateThresholdSlider(sliderName);
|
||||||
|
DockPanel.SetDock(slider, Dock.Top);
|
||||||
|
slider.Margin = new Thickness(0,8,0,0);
|
||||||
|
ThresholdSliderContainer.Children.Add(slider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnApplyTemplate()
|
public override void OnApplyTemplate()
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate();
|
base.OnApplyTemplate();
|
||||||
@ -83,6 +162,8 @@ namespace smx_config
|
|||||||
AutoLightsColor.StoppedDragging += delegate() { showAutoLightsColor.Stop(); };
|
AutoLightsColor.StoppedDragging += delegate() { showAutoLightsColor.Stop(); };
|
||||||
AutoLightsColor.StoppedDragging += delegate() { showAutoLightsColor.Stop(); };
|
AutoLightsColor.StoppedDragging += delegate() { showAutoLightsColor.Stop(); };
|
||||||
|
|
||||||
|
CreateThresholdSliders();
|
||||||
|
|
||||||
// This doesn't happen at the same time AutoLightsColor is used, since they're on different tabs.
|
// This doesn't happen at the same time AutoLightsColor is used, since they're on different tabs.
|
||||||
Diagnostics.SetShowAllLights += delegate(bool on)
|
Diagnostics.SetShowAllLights += delegate(bool on)
|
||||||
{
|
{
|
||||||
@ -182,6 +263,12 @@ namespace smx_config
|
|||||||
RefreshUploadPadText(args);
|
RefreshUploadPadText(args);
|
||||||
RefreshSelectedColorPicker();
|
RefreshSelectedColorPicker();
|
||||||
|
|
||||||
|
// If a device has connected or disconnected, refresh the displayed threshold
|
||||||
|
// sliders. Don't do this otherwise, or we'll do this when the sliders are
|
||||||
|
// dragged.
|
||||||
|
if(args.ConnectionsChanged)
|
||||||
|
CreateThresholdSliders();
|
||||||
|
|
||||||
// Show the threshold warning explanation if any panels are showing the threshold warning icon.
|
// Show the threshold warning explanation if any panels are showing the threshold warning icon.
|
||||||
bool ShowThresholdWarningText = false;
|
bool ShowThresholdWarningText = false;
|
||||||
foreach(Tuple<int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
|
foreach(Tuple<int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
|
||||||
@ -385,6 +472,11 @@ namespace smx_config
|
|||||||
CurrentSMXDevice.singleton.FireConfigurationChanged(null);
|
CurrentSMXDevice.singleton.FireConfigurationChanged(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AdvancedModeEnabledCheckbox_Changed(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
CreateThresholdSliders();
|
||||||
|
}
|
||||||
|
|
||||||
private void ExportSettings(object sender, RoutedEventArgs e)
|
private void ExportSettings(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// Save the current thresholds on the first available pad as a preset.
|
// Save the current thresholds on the first available pad as a preset.
|
||||||
|
@ -107,19 +107,13 @@ namespace smx_config
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty AdvancedModeEnabledProperty = DependencyProperty.Register("AdvancedModeEnabled",
|
public static readonly DependencyProperty AdvancedModeEnabledProperty = DependencyProperty.Register("AdvancedModeEnabled",
|
||||||
typeof(bool), typeof(ThresholdSlider), new FrameworkPropertyMetadata(false, RefreshAdvancedModeEnabledCallback));
|
typeof(bool), typeof(ThresholdSlider), new FrameworkPropertyMetadata(false));
|
||||||
|
|
||||||
public bool AdvancedModeEnabled {
|
public bool AdvancedModeEnabled {
|
||||||
get { return (bool) GetValue(AdvancedModeEnabledProperty); }
|
get { return (bool) GetValue(AdvancedModeEnabledProperty); }
|
||||||
set { SetValue(AdvancedModeEnabledProperty, value); }
|
set { SetValue(AdvancedModeEnabledProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RefreshAdvancedModeEnabledCallback(DependencyObject target, DependencyPropertyChangedEventArgs args)
|
|
||||||
{
|
|
||||||
ThresholdSlider self = target as ThresholdSlider;
|
|
||||||
self.RefreshVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
DoubleSlider slider;
|
DoubleSlider slider;
|
||||||
Label LowerLabel, UpperLabel;
|
Label LowerLabel, UpperLabel;
|
||||||
Image ThresholdWarning;
|
Image ThresholdWarning;
|
||||||
@ -255,41 +249,8 @@ namespace smx_config
|
|||||||
bool ShowThresholdWarning = config.ShowThresholdWarning(panelIdx);
|
bool ShowThresholdWarning = config.ShowThresholdWarning(panelIdx);
|
||||||
ThresholdWarning.Visibility = ShowThresholdWarning? Visibility.Visible:Visibility.Hidden;
|
ThresholdWarning.Visibility = ShowThresholdWarning? Visibility.Visible:Visibility.Hidden;
|
||||||
|
|
||||||
RefreshVisibility();
|
|
||||||
UpdatingUI = false;
|
UpdatingUI = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefreshVisibility()
|
|
||||||
{
|
|
||||||
SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig();
|
|
||||||
this.Visibility = ShouldBeDisplayed(config)? Visibility.Visible:Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return true if this slider should be displayed. Only display a slider if it affects
|
|
||||||
// at least one panel which is enabled.
|
|
||||||
private bool ShouldBeDisplayed(SMX.SMXConfig config)
|
|
||||||
{
|
|
||||||
bool[] enabledPanels = config.GetEnabledPanels();
|
|
||||||
|
|
||||||
// Up and center are shown in both modes.
|
|
||||||
switch(Type)
|
|
||||||
{
|
|
||||||
case "up-left": return AdvancedModeEnabled && enabledPanels[0];
|
|
||||||
case "up": return enabledPanels[1];
|
|
||||||
case "up-right": return AdvancedModeEnabled && enabledPanels[2];
|
|
||||||
case "left": return AdvancedModeEnabled && enabledPanels[3];
|
|
||||||
case "center": return enabledPanels[4];
|
|
||||||
case "right": return AdvancedModeEnabled && enabledPanels[5];
|
|
||||||
case "down-left": return AdvancedModeEnabled && enabledPanels[6];
|
|
||||||
case "down": return AdvancedModeEnabled && enabledPanels[7];
|
|
||||||
case "down-right": return AdvancedModeEnabled && enabledPanels[8];
|
|
||||||
|
|
||||||
// Show cardinal and corner if at least one panel they affect is enabled.
|
|
||||||
case "cardinal": return !AdvancedModeEnabled && (enabledPanels[3] || enabledPanels[5] || enabledPanels[8]);
|
|
||||||
case "corner": return !AdvancedModeEnabled && (enabledPanels[0] || enabledPanels[2] || enabledPanels[6] || enabledPanels[8]);
|
|
||||||
default: return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A button with a selectable highlight.
|
// A button with a selectable highlight.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user