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
|
|
|
|
|
};
|
2014-06-22 23:20:36 +00:00
|
|
|
|
|
2014-11-07 16:58:27 +00:00
|
|
|
|
tabPage1.Focus();
|
2014-06-22 23:20:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnActivated(e);
|
|
|
|
|
Input.Instance.ControlInputFocus(this, Input.InputFocus.Mouse, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivate(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnDeactivate(e);
|
|
|
|
|
Input.Instance.ControlInputFocus(this, Input.InputFocus.Mouse, false);
|
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 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
|
|
|
|
{
|
2019-10-13 20:34:55 +00:00
|
|
|
|
var b = Global.Config.HotkeyBindings.First(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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 20:34:55 +00:00
|
|
|
|
private IEnumerable<InputCompositeWidget> InputWidgets =>
|
|
|
|
|
HotkeyTabControl.TabPages.Cast<TabPage>().SelectMany(tp => tp.Controls.OfType<InputCompositeWidget>());
|
2013-08-04 16:47:54 +00:00
|
|
|
|
|
|
|
|
|
private void DoTabs()
|
|
|
|
|
{
|
2019-10-13 20:34:55 +00:00
|
|
|
|
HotkeyTabControl.SuspendLayout();
|
2013-08-04 16:47:54 +00:00
|
|
|
|
HotkeyTabControl.TabPages.Clear();
|
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
// Buckets
|
2019-10-13 15:50:57 +00:00
|
|
|
|
var tabs = Global.Config.HotkeyBindings.Select(x => x.TabGroup).Distinct();
|
2013-12-22 17:14:22 +00:00
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
foreach (var tab in tabs)
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2019-10-13 20:34:55 +00:00
|
|
|
|
var tb = new TabPage { Name = tab, Text = tab };
|
|
|
|
|
var bindings = Global.Config.HotkeyBindings.Where(n => n.TabGroup == tab).OrderBy(n => n.Ordinal).ThenBy(n => n.DisplayName);
|
|
|
|
|
int x = UIHelper.ScaleX(6);
|
|
|
|
|
int y = UIHelper.ScaleY(14);
|
2014-12-28 21:59:53 +00:00
|
|
|
|
int iwOffsetX = UIHelper.ScaleX(110);
|
|
|
|
|
int iwOffsetY = UIHelper.ScaleY(-4);
|
|
|
|
|
int iwWidth = UIHelper.ScaleX(120);
|
2019-10-13 20:34:55 +00:00
|
|
|
|
|
|
|
|
|
tb.SuspendLayout();
|
|
|
|
|
|
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
|
2015-12-05 11:47:28 +00:00
|
|
|
|
{
|
2013-08-04 16:47:54 +00:00
|
|
|
|
Text = b.DisplayName,
|
2019-10-13 20:34:55 +00:00
|
|
|
|
Location = new Point(x, y),
|
|
|
|
|
Size = new Size(iwOffsetX - UIHelper.ScaleX(2), UIHelper.ScaleY(15))
|
2013-08-04 16:47:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-22 19:23:52 +00:00
|
|
|
|
var w = new InputCompositeWidget
|
2014-11-07 16:58:27 +00:00
|
|
|
|
{
|
2019-10-13 20:34:55 +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,
|
2019-10-13 20:34:55 +00:00
|
|
|
|
WidgetName = b.DisplayName
|
2013-08-04 16:47:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-11-07 16:58:27 +00:00
|
|
|
|
w.SetupTooltip(toolTip1, b.ToolTip);
|
|
|
|
|
toolTip1.SetToolTip(l, b.ToolTip);
|
|
|
|
|
|
|
|
|
|
w.Bindings = b.Bindings;
|
|
|
|
|
|
2013-08-04 16:47:54 +00:00
|
|
|
|
tb.Controls.Add(l);
|
|
|
|
|
tb.Controls.Add(w);
|
|
|
|
|
|
2019-10-13 20:34:55 +00:00
|
|
|
|
y += UIHelper.ScaleY(24);
|
|
|
|
|
if (y > HotkeyTabControl.Height - UIHelper.ScaleY(35))
|
2013-08-04 16:47:54 +00:00
|
|
|
|
{
|
2019-10-13 20:34:55 +00:00
|
|
|
|
x += iwOffsetX + iwWidth + UIHelper.ScaleX(10);
|
|
|
|
|
y = UIHelper.ScaleY(14);
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-05 11:47:28 +00:00
|
|
|
|
if (tab == "TAStudio")
|
|
|
|
|
{
|
|
|
|
|
tb.Controls.Add(new Label
|
|
|
|
|
{
|
|
|
|
|
Text = "Save States hotkeys operate with branches when TAStudio is engaged.",
|
2019-10-13 20:34:55 +00:00
|
|
|
|
Location = new Point(x, y),
|
|
|
|
|
Size = new Size(iwWidth + iwOffsetX, HotkeyTabControl.Height - y)
|
2015-12-05 11:47:28 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-04 16:47:54 +00:00
|
|
|
|
HotkeyTabControl.TabPages.Add(tb);
|
2019-10-13 20:34:55 +00:00
|
|
|
|
tb.ResumeLayout();
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
2019-10-13 20:34:55 +00:00
|
|
|
|
|
|
|
|
|
HotkeyTabControl.ResumeLayout();
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2017-05-31 15:28:06 +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
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 19:58:38 +00:00
|
|
|
|
private void ClearAll(bool currentTabOnly)
|
|
|
|
|
{
|
|
|
|
|
if (currentTabOnly)
|
|
|
|
|
{
|
|
|
|
|
foreach (var w in InputWidgets)
|
|
|
|
|
{
|
|
|
|
|
w.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var w in HotkeyTabControl.SelectedTab.Controls.OfType<InputCompositeWidget>())
|
|
|
|
|
{
|
|
|
|
|
w.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2017-05-31 15:28:06 +00:00
|
|
|
|
// Tab or Enter
|
2013-10-06 20:45:04 +00:00
|
|
|
|
if (!e.Control && !e.Alt && !e.Shift &&
|
|
|
|
|
(e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab))
|
|
|
|
|
{
|
2017-05-31 15:28:06 +00:00
|
|
|
|
var b = Global.Config.HotkeyBindings.FirstOrDefault(x => string.Compare(x.DisplayName, SearchBox.Text, true) == 0);
|
2013-10-06 20:45:04 +00:00
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
// Found
|
2013-10-06 20:45:04 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2017-05-31 15:28:06 +00:00
|
|
|
|
HotkeyTabControl.SelectTab((TabPage)w.Parent);
|
2013-10-06 20:45:04 +00:00
|
|
|
|
w.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-19 19:58:38 +00:00
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
private void ClearAllToolStripMenuItem_Click(object sender, EventArgs e)
|
2015-07-19 19:58:38 +00:00
|
|
|
|
{
|
|
|
|
|
ClearAll(true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
private void ClearCurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
|
2015-07-19 19:58:38 +00:00
|
|
|
|
{
|
|
|
|
|
ClearAll(false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
private void RestoreDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
|
2015-07-19 19:58:38 +00:00
|
|
|
|
{
|
|
|
|
|
Defaults();
|
|
|
|
|
}
|
2013-08-04 16:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|