Skip to content

Commit

Permalink
ConfigApp: Allow force disabling ExcludedFromVoting & ShortcutKeycode…
Browse files Browse the repository at this point in the history
… for custom effects
  • Loading branch information
pongo1231 committed Aug 29, 2023
1 parent 406031f commit 709e9bd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 24 deletions.
12 changes: 7 additions & 5 deletions ConfigApp/EffectConfig.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@
HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label x:Name="effectconf_exclude_voting_enable_title" Content="Exclude Effect from Voting" Grid.Row="4" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center" />
<CheckBox x:Name="effectconf_exclude_voting_enable" Grid.Row="4" Grid.Column="2"
HorizontalAlignment="Left" VerticalAlignment="Center"
Click="OnClicked"/>
<ComboBox x:Name="effectconf_exclude_voting_state" Height="25" Width="100" Grid.Row="4" Grid.Column="2"
HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label x:Name="effectconf_effect_shortcut_key_title" Content="Shortcut (ESC to reset)"
Grid.Row="5" Grid.Column="0" Margin="0,5.667,0,10.333" HorizontalAlignment="Right" Width="360" HorizontalContentAlignment="Right" />
<TextBox x:Name="effectconf_effect_shortcut_input" Grid.Row="5" Grid.Column="2" Margin="0,10,0,10" AllowDrop="False" Height="20"
<CheckBox x:Name="effectconf_effect_shortcut_enable" Grid.Row="5" Grid.Column="2"
HorizontalAlignment="Left" VerticalAlignment="Center" VerticalContentAlignment="Center"
Click="OnClicked" />
<TextBox x:Name="effectconf_effect_shortcut_input" Grid.Row="5" Grid.Column="2" Margin="40,10,0,10" AllowDrop="False" Height="20"
IsUndoEnabled="False" IsReadOnly="True" PreviewKeyDown="EffectShortcutTextFieldPreviewKeyDown" HorizontalContentAlignment="Center"
HorizontalAlignment="Left" Text="None" SelectionBrush="{x:Null}" MinWidth="120"/>
HorizontalAlignment="Left" Text="None" SelectionBrush="{x:Null}" MinWidth="120" IsEnabled="False" />
<TextBlock x:Name="effectconf_mp3_label" Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="3" FontSize="10"
HorizontalAlignment="Center" VerticalAlignment="Center" />
<Button Content="Save" Height="40" Width="75" Margin="0,0,5,0" Grid.Row="8" Grid.Column="2"
Expand Down
84 changes: 65 additions & 19 deletions ConfigApp/EffectConfig.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class EffectConfig : Window
private EffectData m_EffectData;
private bool m_IsTimedEffect = false;
private bool m_IsSaved = false;
private int? m_EffectShortcut; // Win32Key + 2^10 (if CTRL) + 2^9 (if Shift) + 2^8 (if Alt)
private int m_EffectShortcut = 0; // Win32Key + 2^10 (if CTRL) + 2^9 (if Shift) + 2^8 (if Alt)

public bool IsSaved
{
Expand All @@ -23,7 +23,7 @@ public bool IsSaved
}
}

public EffectConfig(string effectId, EffectData? effectData, EffectInfo effectInfo)
public EffectConfig(string? effectId, EffectData? effectData, EffectInfo effectInfo)
{
InitializeComponent();

Expand Down Expand Up @@ -75,7 +75,12 @@ public EffectConfig(string effectId, EffectData? effectData, EffectInfo effectIn
};
effectconf_effect_weight_mult.SelectedIndex = m_EffectData.WeightMult.GetValueOrDefault(0);

effectconf_exclude_voting_enable.IsChecked = m_EffectData.ExcludedFromVoting.GetValueOrDefault(false);
effectconf_exclude_voting_state.ItemsSource = new List<string>()
{
"Default", "Disabled", "Enabled"
};
effectconf_exclude_voting_state.SelectedIndex = m_EffectData.ExcludedFromVoting.HasValue
? (m_EffectData.ExcludedFromVoting.Value ? 2 : 1) : 0;

effectconf_effect_custom_name.Text = m_EffectData.CustomName;
effectconf_effect_custom_name.TextChanged += CustomEffectNameTextFieldTextChanged;
Expand All @@ -93,14 +98,38 @@ public EffectConfig(string effectId, EffectData? effectData, EffectInfo effectIn
if (effectInfo.EffectCategory == EffectCategory.Meta)
{
effectconf_exclude_voting_enable_title.Visibility = Visibility.Hidden;
effectconf_exclude_voting_enable.Visibility = Visibility.Hidden;
effectconf_exclude_voting_enable.IsChecked = false;
effectconf_exclude_voting_state.Visibility = Visibility.Hidden;
effectconf_exclude_voting_state.SelectedIndex = 0;
}

/* Shortcut */

// HACK: effectId is set to null for custom effects so make use of that to hide shortcut checkbox for built-in effects
// as those should not have set a shortcut to begin with so 0 == null in that case
// Also hide the custom shortcut toggle for built-in effects as those save shortcut as 0 even if non-existant
if (effectId != null)
{
effectconf_effect_shortcut_enable.IsChecked = true;
effectconf_effect_shortcut_enable.Visibility = Visibility.Collapsed;

effectconf_effect_shortcut_input.IsEnabled = true;
// Another HACK: Move the textbox to the left :)
var margin = effectconf_effect_shortcut_input.Margin;
margin.Left = 0f;
effectconf_effect_shortcut_input.Margin = margin;
}

// Shortcut
if (int.TryParse(m_EffectData.ShortcutKeycode.ToString(), out int savedWin32Key))
if (m_EffectData.ShortcutKeycode.HasValue &&
int.TryParse(m_EffectData.ShortcutKeycode.ToString(), out int savedWin32Key))
{
if (savedWin32Key > 0)
effectconf_effect_shortcut_enable.IsChecked = true;
effectconf_effect_shortcut_input.IsEnabled = true;

if (savedWin32Key <= 0)
{
effectconf_effect_shortcut_input.Text = "None";
}
else
{
Key key = KeyInterop.KeyFromVirtualKey(savedWin32Key % 256);
var modifiers = ModifierKeys.None;
Expand All @@ -119,10 +148,6 @@ public EffectConfig(string effectId, EffectData? effectData, EffectInfo effectIn

SetEffectShortcut(key, modifiers);
}
else if (savedWin32Key == 0)
{
effectconf_effect_shortcut_input.Text = "None";
}
}

CheckEnableConfigurables();
Expand All @@ -144,7 +169,7 @@ private void EffectShortcutTextFieldPreviewKeyDown(object sender, KeyEventArgs e
if (key == Key.Escape || key == Key.Back)
{
effectconf_effect_shortcut_input.Text = "None";
m_EffectShortcut = null;
m_EffectShortcut = 0;
return;
}

Expand Down Expand Up @@ -200,13 +225,22 @@ private void CheckEnableConfigurables()
effectconf_timer_time_enable.IsEnabled = false;
}

effectconf_timer_type.IsEnabled = effectconf_timer_type_enable.IsChecked.Value;
effectconf_timer_time.IsEnabled = effectconf_timer_time_enable.IsChecked.Value;
effectconf_timer_type.IsEnabled = effectconf_timer_type_enable.IsChecked.GetValueOrDefault(false);
effectconf_timer_time.IsEnabled = effectconf_timer_time_enable.IsChecked.GetValueOrDefault(false);
}

private void OnClicked(object sender, RoutedEventArgs e)
{
if (((CheckBox)sender).IsChecked.Value)
var checkBox = (CheckBox)sender;

if (checkBox == effectconf_effect_shortcut_enable)
{
effectconf_effect_shortcut_input.IsEnabled = checkBox.IsChecked.GetValueOrDefault(false);

return;
}

if (checkBox.IsChecked.GetValueOrDefault(false))
{
if (sender == effectconf_timer_type_enable)
{
Expand Down Expand Up @@ -264,10 +298,22 @@ public EffectData GetNewData()
m_EffectData.CustomTime = effectconf_timer_time_enable.IsChecked.HasValue && effectconf_timer_time_enable.IsChecked.Value
? effectconf_timer_time.Text.Length > 0 ? int.Parse(effectconf_timer_time.Text) : null : null;
m_EffectData.WeightMult = effectconf_effect_weight_mult.SelectedIndex > 0 ? effectconf_effect_weight_mult.SelectedIndex : null;
m_EffectData.ExcludedFromVoting = effectconf_exclude_voting_enable.IsChecked.HasValue && effectconf_exclude_voting_enable.IsChecked.Value
? true : null; // Currently the assumption is that every effect is voteable in the mod anyways so don't waste space where unneeded storing this is false

switch (effectconf_exclude_voting_state.SelectedIndex)
{
case 1:
m_EffectData.ExcludedFromVoting = false;
break;
case 2:
m_EffectData.ExcludedFromVoting = true;
break;
default:
m_EffectData.ExcludedFromVoting = null;
break;
}

m_EffectData.CustomName = effectconf_effect_custom_name.Text.Trim().Length > 0 ? effectconf_effect_custom_name.Text.Trim() : null;
m_EffectData.ShortcutKeycode = m_EffectShortcut;
m_EffectData.ShortcutKeycode = effectconf_effect_shortcut_enable.IsChecked.GetValueOrDefault(false) ? m_EffectShortcut : null;

return m_EffectData;
}
Expand Down

0 comments on commit 709e9bd

Please sign in to comment.