3074/Windows/ConfigWindow.xaml.cs

74 lines
1.7 KiB
C#

using System;
using System.Windows;
using System.Windows.Input;
using tsf_3074.Windows.Dialog;
namespace tsf_3074.Windows
{
public partial class ConfigWindow : System.Windows.Window
{
// dont use this ctor,
// use #ShowConfigDialog instead!
public ConfigWindow()
{
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
if (!(e.Source is System.Windows.Controls.Button button)) return;
switch (button.Content)
{
case "3074":
SetHotkeyFor(Tsf.F3074);
break;
case "3074 UL":
SetHotkeyFor(Tsf.F3074UL);
break;
case "7500":
SetHotkeyFor(Tsf.F7500);
break;
case "27k":
SetHotkeyFor(Tsf.F27K);
break;
case "30k":
SetHotkeyFor(Tsf.F30K);
break;
case "FG":
SetHotkeyFor(Tsf.FFullGame);
break;
}
}
/**
* Use KeybindingDialog to receive a keybinding,
* and set the value to TsfFilter.
* When the Config window exits, the hotkeys should be reloaded.
*/
private static void SetHotkeyFor(TsfFilter filter)
{
KeybindingDialog.OpenKeybindingDialog(out var key, out var fs,
KeyInterop.KeyFromVirtualKey((int)filter.VK), filter.FS);
// don't change if escape is pressed
if (key == Key.Escape) return;
filter.SetHotkey((uint)KeyInterop.VirtualKeyFromKey(key), fs);
}
private static bool _showing;
/**
* Use this static method to ensure there is only 1 instance of Config window.
*/
public static void ShowConfigDialog()
{
if (_showing) return;
_showing = true;
var window = new ConfigWindow();
window.Closed += (sender, e) => { _showing = false; };
window.ShowDialog();
}
}
}