Introduce NamedHotkey type.
This commit is contained in:
@@ -273,6 +273,10 @@ namespace OpenRA
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
else if (fieldType == typeof(NamedHotkey))
|
||||
{
|
||||
return new NamedHotkey(value, Game.Settings.Keys);
|
||||
}
|
||||
else if (fieldType == typeof(WDist))
|
||||
{
|
||||
WDist res;
|
||||
|
||||
49
OpenRA.Game/Input/NamedHotkey.cs
Normal file
49
OpenRA.Game/Input/NamedHotkey.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
/// <summary>
|
||||
/// A reference to either a named hotkey (defined in the game settings) or a statically assigned hotkey
|
||||
/// </summary>
|
||||
public class NamedHotkey
|
||||
{
|
||||
static readonly Func<Hotkey> Invalid = () => Hotkey.Invalid;
|
||||
|
||||
readonly Func<Hotkey> getValue;
|
||||
|
||||
public NamedHotkey()
|
||||
{
|
||||
getValue = Invalid;
|
||||
}
|
||||
|
||||
public NamedHotkey(string name, KeySettings settings)
|
||||
{
|
||||
// Try parsing the value as a reference to a named hotkey
|
||||
getValue = settings.GetHotkeyReference(name);
|
||||
|
||||
if (getValue == null)
|
||||
{
|
||||
// Try parsing the value as a normal (static) hotkey
|
||||
var staticKey = Hotkey.Invalid;
|
||||
Hotkey.TryParse(name, out staticKey);
|
||||
getValue = () => staticKey;
|
||||
}
|
||||
}
|
||||
|
||||
public Hotkey GetValue()
|
||||
{
|
||||
return getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,6 +223,7 @@
|
||||
<Compile Include="Input\InputHandler.cs" />
|
||||
<Compile Include="Input\Keycode.cs" />
|
||||
<Compile Include="Input\Hotkey.cs" />
|
||||
<Compile Include="Input\NamedHotkey.cs" />
|
||||
<Compile Include="Graphics\PlatformInterfaces.cs" />
|
||||
<Compile Include="Sound\Sound.cs" />
|
||||
<Compile Include="Sound\SoundDevice.cs" />
|
||||
|
||||
@@ -307,6 +307,15 @@ namespace OpenRA
|
||||
Expression.Field(keySettings, "{0}{1:D2}Key".F(prefix, i + 1)), keySettings).Compile());
|
||||
}
|
||||
|
||||
internal Func<Hotkey> GetHotkeyReference(string name)
|
||||
{
|
||||
var field = typeof(KeySettings).GetField(name + "Key");
|
||||
if (field == null)
|
||||
return null;
|
||||
|
||||
return () => (Hotkey)field.GetValue(this);
|
||||
}
|
||||
|
||||
public Hotkey GetProductionHotkey(int index)
|
||||
{
|
||||
return GetKey(ProductionKeys, index);
|
||||
|
||||
Reference in New Issue
Block a user