2013-08-04 16:47:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2013-10-06 20:45:04 +00:00
|
|
|
|
public partial class HotkeyConfig : Form
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2013-10-06 20:45:04 +00:00
|
|
|
|
public HotkeyConfig()
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-04-26 19:34:52 +00:00
|
|
|
|
|
|
|
|
|
Closing += (o, e) =>
|
|
|
|
|
{
|
|
|
|
|
IDB_SAVE.Focus(); // A very dirty hack to avoid https://code.google.com/p/bizhawk/issues/detail?id=161
|
|
|
|
|
};
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NewHotkeyWindow_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var source = new AutoCompleteStringCollection();
|
2013-10-06 20:45:04 +00:00
|
|
|
|
source.AddRange(Global.Config.HotkeyBindings.Select(x => x.DisplayName).ToArray());
|
2013-08-05 13:23:17 +00:00
|
|
|
|
|
2013-10-06 20:45:04 +00:00
|
|
|
|
SearchBox.AutoCompleteCustomSource = source;
|
|
|
|
|
SearchBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
|
2013-08-05 13:23:17 +00:00
|
|
|
|
|
2013-10-06 20:45:04 +00:00
|
|
|
|
AutoTabCheckBox.Checked = Global.Config.HotkeyConfigAutoTab;
|
2013-08-04 16:47:54 +00:00
|
|
|
|
DoTabs();
|
2013-08-04 20:51:49 +00:00
|
|
|
|
DoFocus();
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IDB_CANCEL_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.OSD.AddMessage("Hotkey config aborted");
|
2013-08-04 16:47:54 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IDB_SAVE_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Save();
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.OSD.AddMessage("Hotkey settings saved");
|
2013-08-04 16:47:54 +00:00
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RestoreDefaults_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Defaults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AutoTabCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SetAutoTab();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Save()
|
|
|
|
|
{
|
|
|
|
|
Global.Config.HotkeyConfigAutoTab = AutoTabCheckBox.Checked;
|
|
|
|
|
|
2013-11-28 01:33:38 +00:00
|
|
|
|
foreach (var w in InputWidgets)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2013-10-25 00:57:23 +00:00
|
|
|
|
var b = Global.Config.HotkeyBindings.FirstOrDefault(x => x.DisplayName == w.WidgetName);
|
2014-04-22 19:38:23 +00:00
|
|
|
|
b.Bindings = w.Bindings;
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-19 21:03:49 +00:00
|
|
|
|
private IEnumerable<InputCompositeWidget> InputWidgets
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-04-19 21:03:49 +00:00
|
|
|
|
var widgets = new List<InputCompositeWidget>();
|
2013-11-28 01:33:38 +00:00
|
|
|
|
for (var x = 0; x < HotkeyTabControl.TabPages.Count; x++)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
for (var y = 0; y < HotkeyTabControl.TabPages[x].Controls.Count; y++)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2014-04-19 21:03:49 +00:00
|
|
|
|
if (HotkeyTabControl.TabPages[x].Controls[y] is InputCompositeWidget)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2014-04-19 21:03:49 +00:00
|
|
|
|
widgets.Add(HotkeyTabControl.TabPages[x].Controls[y] as InputCompositeWidget);
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return widgets;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DoTabs()
|
|
|
|
|
{
|
|
|
|
|
HotkeyTabControl.TabPages.Clear();
|
|
|
|
|
|
|
|
|
|
//Buckets
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var Tabs = Global.Config.HotkeyBindings.Select(x => x.TabGroup).Distinct().ToList();
|
2013-12-22 17:14:22 +00:00
|
|
|
|
|
2013-11-28 01:33:38 +00:00
|
|
|
|
foreach (var tab in Tabs)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2013-12-22 17:14:22 +00:00
|
|
|
|
var _y = 14;
|
|
|
|
|
var _x = 6;
|
|
|
|
|
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var tb = new TabPage {Name = tab, Text = tab};
|
2013-08-04 16:47:54 +00:00
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
var bindings = Global.Config.HotkeyBindings.Where(x => x.TabGroup == tab).OrderBy(x => x.Ordinal).ThenBy(x => x.DisplayName).ToList();
|
2013-08-04 16:47:54 +00:00
|
|
|
|
|
2013-11-28 01:33:38 +00:00
|
|
|
|
const int iwOffsetX = 110;
|
|
|
|
|
const int iwOffsetY = -4;
|
|
|
|
|
const int iwWidth = 120;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
foreach (var b in bindings)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var l = new Label
|
|
|
|
|
{
|
2013-08-04 16:47:54 +00:00
|
|
|
|
Text = b.DisplayName,
|
|
|
|
|
Location = new Point(_x, _y),
|
2013-11-28 01:33:38 +00:00
|
|
|
|
Width = iwOffsetX - 2,
|
2013-08-04 16:47:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-22 19:23:52 +00:00
|
|
|
|
var w = new InputCompositeWidget
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2013-08-04 20:21:58 +00:00
|
|
|
|
Bindings = b.Bindings,
|
2013-11-28 01:33:38 +00:00
|
|
|
|
Location = new Point(_x + iwOffsetX, _y + iwOffsetY),
|
2013-08-04 16:47:54 +00:00
|
|
|
|
AutoTab = AutoTabCheckBox.Checked,
|
2013-11-28 01:33:38 +00:00
|
|
|
|
Width = iwWidth,
|
2013-08-04 16:47:54 +00:00
|
|
|
|
WidgetName = b.DisplayName,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tb.Controls.Add(l);
|
|
|
|
|
tb.Controls.Add(w);
|
|
|
|
|
|
|
|
|
|
_y += 24;
|
|
|
|
|
if (_y > HotkeyTabControl.Height - 35)
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
_x += iwOffsetX + iwWidth + 10;
|
2013-08-04 16:47:54 +00:00
|
|
|
|
_y = 14;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HotkeyTabControl.TabPages.Add(tb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Defaults()
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
foreach (var w in InputWidgets)
|
2013-08-04 17:13:25 +00:00
|
|
|
|
{
|
2013-10-25 00:57:23 +00:00
|
|
|
|
var b = Global.Config.HotkeyBindings.FirstOrDefault(x => x.DisplayName == w.WidgetName);
|
2014-04-22 19:38:23 +00:00
|
|
|
|
if (b != null) w.Bindings = b.DefaultBinding;
|
2013-08-04 17:13:25 +00:00
|
|
|
|
}
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetAutoTab()
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
foreach (var w in InputWidgets)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
|
|
|
|
w.AutoTab = AutoTabCheckBox.Checked;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-04 20:51:49 +00:00
|
|
|
|
|
|
|
|
|
private void HotkeyTabControl_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DoFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DoFocus()
|
|
|
|
|
{
|
|
|
|
|
if (HotkeyTabControl.SelectedTab != null)
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
foreach (var c in HotkeyTabControl.SelectedTab.Controls.OfType<InputWidget>())
|
2013-08-04 20:51:49 +00:00
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
c.Focus();
|
|
|
|
|
return;
|
2013-08-04 20:51:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 20:45:04 +00:00
|
|
|
|
private void SearchBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Tab or Enter
|
|
|
|
|
if (!e.Control && !e.Alt && !e.Shift &&
|
|
|
|
|
(e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab))
|
|
|
|
|
{
|
2013-10-25 00:57:23 +00:00
|
|
|
|
var b = Global.Config.HotkeyBindings.FirstOrDefault(x => x.DisplayName == SearchBox.Text);
|
2013-10-06 20:45:04 +00:00
|
|
|
|
|
|
|
|
|
//Found
|
|
|
|
|
if (b != null)
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var w = InputWidgets.FirstOrDefault(x => x.WidgetName == b.DisplayName);
|
2013-10-06 20:45:04 +00:00
|
|
|
|
if (w != null)
|
|
|
|
|
{
|
|
|
|
|
HotkeyTabControl.SelectTab((w.Parent as TabPage));
|
|
|
|
|
w.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|