2012-11-07 04:31:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-28 21:59:53 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2013-07-14 02:04:55 +00:00
|
|
|
|
// this is a little messy right now because of remnants of the old config system
|
2012-11-07 04:31:29 +00:00
|
|
|
|
public partial class ControllerConfigPanel : UserControl
|
|
|
|
|
{
|
2013-07-14 03:27:54 +00:00
|
|
|
|
// the dictionary that results are saved to
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private Dictionary<string, string> _realConfigObject;
|
|
|
|
|
|
2013-07-14 03:27:54 +00:00
|
|
|
|
// if nonnull, the list of keys to use. used to have the config panel operate on a smaller list than the whole dictionary;
|
|
|
|
|
// for instance, to show only a single player
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private List<string> _realConfigButtons;
|
2012-11-07 04:31:29 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private readonly List<string> _buttons = new List<string>();
|
2012-11-07 04:31:29 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private readonly int _inputMarginLeft = UIHelper.ScaleX(0);
|
|
|
|
|
private readonly int _labelPadding = UIHelper.ScaleX(5);
|
|
|
|
|
private readonly int _marginTop = UIHelper.ScaleY(0);
|
|
|
|
|
private readonly int _spacing = UIHelper.ScaleY(24);
|
|
|
|
|
private readonly int _inputSize = UIHelper.ScaleX(170);
|
|
|
|
|
private readonly int _columnWidth = UIHelper.ScaleX(280);
|
2012-11-07 04:31:29 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
public ToolTip Tooltip { get; set; }
|
2014-11-07 16:58:27 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private readonly List<InputCompositeWidget> _inputs = new List<InputCompositeWidget>();
|
2012-11-07 04:31:29 +00:00
|
|
|
|
|
2013-07-14 21:09:42 +00:00
|
|
|
|
private Size _panelSize = new Size(0, 0);
|
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private bool _autotab;
|
|
|
|
|
|
2012-11-07 04:31:29 +00:00
|
|
|
|
public ControllerConfigPanel()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ControllerConfigPanel_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private void ClearAll()
|
2012-12-03 00:41:05 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
_inputs.ForEach(x => x.Clear());
|
2012-12-03 00:41:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 02:43:06 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// save to config
|
|
|
|
|
/// </summary>
|
2017-05-31 13:10:09 +00:00
|
|
|
|
/// <param name="saveConfigObject">if non-null, save to possibly different config object than originally initialized from</param>
|
|
|
|
|
public void Save(Dictionary<string, string> saveConfigObject = null)
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
var saveto = saveConfigObject ?? _realConfigObject;
|
|
|
|
|
for (int button = 0; button < _buttons.Count; button++)
|
|
|
|
|
{
|
|
|
|
|
saveto[_buttons[button]] = _inputs[button].Bindings;
|
|
|
|
|
}
|
2012-11-07 04:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-28 21:54:42 +00:00
|
|
|
|
public void LoadSettings(Dictionary<string, string> configobj, bool autotab, List<string> configbuttons = null, int? width = null, int? height = null)
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
_autotab = autotab;
|
2013-07-14 21:09:42 +00:00
|
|
|
|
if (width.HasValue && height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_panelSize = new Size(width.Value, height.Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-07-15 01:20:22 +00:00
|
|
|
|
_panelSize = Size;
|
2013-07-14 21:09:42 +00:00
|
|
|
|
}
|
2013-07-15 01:20:22 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
_realConfigObject = configobj;
|
|
|
|
|
_realConfigButtons = configbuttons;
|
2012-11-07 04:31:29 +00:00
|
|
|
|
SetButtonList();
|
|
|
|
|
Startup();
|
|
|
|
|
SetWidgetStrings();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private void SetButtonList()
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
_buttons.Clear();
|
|
|
|
|
IEnumerable<string> bl = _realConfigButtons ?? (IEnumerable<string>)_realConfigObject.Keys;
|
2013-07-14 03:27:54 +00:00
|
|
|
|
foreach (string s in bl)
|
2017-05-31 13:10:09 +00:00
|
|
|
|
{
|
|
|
|
|
_buttons.Add(s);
|
|
|
|
|
}
|
2012-11-07 04:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private void SetWidgetStrings()
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
for (int button = 0; button < _buttons.Count; button++)
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2013-07-14 02:30:57 +00:00
|
|
|
|
string s;
|
2017-05-31 13:10:09 +00:00
|
|
|
|
if (!_realConfigObject.TryGetValue(_buttons[button], out s))
|
|
|
|
|
{
|
2013-07-14 02:30:57 +00:00
|
|
|
|
s = "";
|
2017-05-31 13:10:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_inputs[button].Bindings = s;
|
2012-11-07 04:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private void Startup()
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
int x = _inputMarginLeft;
|
|
|
|
|
int y = _marginTop - _spacing;
|
|
|
|
|
for (int i = 0; i < _buttons.Count; i++)
|
2012-11-07 04:31:29 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
y += _spacing;
|
2015-01-02 23:04:02 +00:00
|
|
|
|
if (y > (_panelSize.Height - UIHelper.ScaleY(62)))
|
2012-11-08 04:09:24 +00:00
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
y = _marginTop;
|
|
|
|
|
x += _columnWidth;
|
2012-11-08 04:09:24 +00:00
|
|
|
|
}
|
2013-10-11 15:41:11 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
var iw = new InputCompositeWidget
|
2013-10-11 15:41:11 +00:00
|
|
|
|
{
|
|
|
|
|
Location = new Point(x, y),
|
2017-05-31 13:10:09 +00:00
|
|
|
|
Size = new Size(_inputSize, UIHelper.ScaleY(23)),
|
2013-10-11 15:41:11 +00:00
|
|
|
|
TabIndex = i,
|
2017-05-31 13:10:09 +00:00
|
|
|
|
AutoTab = _autotab
|
2013-10-11 15:41:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-11-07 16:58:27 +00:00
|
|
|
|
iw.SetupTooltip(Tooltip, null);
|
|
|
|
|
|
2012-11-08 04:09:24 +00:00
|
|
|
|
iw.BringToFront();
|
2012-11-07 04:31:29 +00:00
|
|
|
|
Controls.Add(iw);
|
2017-05-31 13:10:09 +00:00
|
|
|
|
_inputs.Add(iw);
|
|
|
|
|
var label = new Label
|
|
|
|
|
{
|
|
|
|
|
Location = new Point(x + _inputSize + _labelPadding, y + UIHelper.ScaleY(3)),
|
|
|
|
|
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
|
|
|
|
|
Text = _buttons[i].Replace('_', ' ').Trim(),
|
|
|
|
|
};
|
2014-11-07 16:58:27 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
////Tooltip.SetToolTip(label, null); //??? not supported yet
|
2014-11-07 16:58:27 +00:00
|
|
|
|
|
2013-10-11 15:41:11 +00:00
|
|
|
|
Controls.Add(label);
|
2012-11-07 04:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-23 16:14:47 +00:00
|
|
|
|
|
|
|
|
|
public void SetAutoTab(bool value)
|
|
|
|
|
{
|
2017-05-31 13:10:09 +00:00
|
|
|
|
_inputs.ForEach(x => x.AutoTab = value);
|
2012-11-23 16:14:47 +00:00
|
|
|
|
}
|
2012-12-03 00:41:05 +00:00
|
|
|
|
|
2017-05-31 13:10:09 +00:00
|
|
|
|
private void ClearToolStripMenuItem_Click(object sender, EventArgs e)
|
2012-12-03 00:41:05 +00:00
|
|
|
|
{
|
|
|
|
|
ClearAll();
|
|
|
|
|
}
|
2012-11-07 04:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|