2017-11-19 23:08:23 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Config;
|
|
|
|
|
using Mesen.GUI.Controls;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms.Config
|
|
|
|
|
{
|
|
|
|
|
public class BaseInputConfigControl : BaseControl
|
|
|
|
|
{
|
|
|
|
|
public event EventHandler Change;
|
|
|
|
|
protected HashSet<Button> _buttons = new HashSet<Button>();
|
|
|
|
|
|
|
|
|
|
public enum MappedKeyType
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
Keyboard,
|
|
|
|
|
Controller
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-16 14:06:00 -05:00
|
|
|
|
public BaseInputConfigControl()
|
2017-11-19 23:08:23 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Initialize(KeyMappings mappings) { }
|
2017-12-16 14:06:00 -05:00
|
|
|
|
public virtual void UpdateKeyMappings(KeyMappings mappings) { }
|
2017-11-19 23:08:23 -05:00
|
|
|
|
|
|
|
|
|
protected void InitButton(Button btn, UInt32 scanCode)
|
|
|
|
|
{
|
|
|
|
|
if(!_buttons.Contains(btn)) {
|
|
|
|
|
_buttons.Add(btn);
|
|
|
|
|
btn.Click += btnMapping_Click;
|
2017-12-16 14:06:00 -05:00
|
|
|
|
btn.AutoEllipsis = true;
|
2017-11-19 23:08:23 -05:00
|
|
|
|
}
|
|
|
|
|
btn.Text = InteropEmu.GetKeyName(scanCode);
|
|
|
|
|
btn.Tag = scanCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnChange()
|
|
|
|
|
{
|
|
|
|
|
this.Change?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MappedKeyType GetKeyType()
|
|
|
|
|
{
|
|
|
|
|
MappedKeyType keyType = MappedKeyType.None;
|
|
|
|
|
foreach(Button btn in _buttons) {
|
2017-12-16 14:06:00 -05:00
|
|
|
|
if((UInt32)btn.Tag > 0xFFFF) {
|
2017-11-19 23:08:23 -05:00
|
|
|
|
return MappedKeyType.Controller;
|
2017-12-16 14:06:00 -05:00
|
|
|
|
} else if((UInt32)btn.Tag > 0) {
|
2017-11-19 23:08:23 -05:00
|
|
|
|
keyType = MappedKeyType.Keyboard;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return keyType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearKeys()
|
|
|
|
|
{
|
|
|
|
|
foreach(Button btn in _buttons) {
|
|
|
|
|
InitButton(btn, 0);
|
|
|
|
|
}
|
|
|
|
|
this.OnChange();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void btnMapping_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using(frmGetKey frm = new frmGetKey(true)) {
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
((Button)sender).Text = frm.ShortcutKey.ToString();
|
|
|
|
|
((Button)sender).Tag = frm.ShortcutKey.Key1;
|
|
|
|
|
}
|
|
|
|
|
this.OnChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|