Add Statistics options hotkeys
This commit is contained in:
@@ -10,13 +10,15 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsCombatKey", "StatisticsGraphKey")]
|
||||
public class MenuButtonsChromeLogic : ChromeLogic
|
||||
{
|
||||
readonly World world;
|
||||
@@ -26,13 +28,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Widget currentWidget;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public MenuButtonsChromeLogic(Widget widget, World world)
|
||||
public MenuButtonsChromeLogic(Widget widget, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
{
|
||||
this.world = world;
|
||||
|
||||
worldRoot = Ui.Root.Get("WORLD_ROOT");
|
||||
menuRoot = Ui.Root.Get("MENU_ROOT");
|
||||
|
||||
MiniYaml yaml;
|
||||
var ks = Game.Settings.Keys;
|
||||
string[] keyNames = Enum.GetNames(typeof(ObserverStatsPanel));
|
||||
var statsHotkeys = new NamedHotkey[keyNames.Length];
|
||||
for (var i = 0; i < keyNames.Length; i++)
|
||||
statsHotkeys[i] = logicArgs.TryGetValue("Statistics" + keyNames[i] + "Key", out yaml) ? new NamedHotkey(yaml.Value, ks) : new NamedHotkey();
|
||||
|
||||
// System buttons
|
||||
var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
|
||||
if (options != null)
|
||||
@@ -85,7 +94,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (stats != null)
|
||||
{
|
||||
stats.IsDisabled = () => disableSystemButtons || world.Map.Visibility.HasFlag(MapVisibility.MissionSelector);
|
||||
stats.OnClick = () => OpenMenuPanel(stats);
|
||||
stats.OnClick = () => OpenMenuPanel(stats, new WidgetArgs() { { "activePanel", ObserverStatsPanel.Basic } });
|
||||
}
|
||||
|
||||
var keyListener = widget.GetOrNull<LogicKeyListenerWidget>("OBSERVER_KEY_LISTENER");
|
||||
if (keyListener != null)
|
||||
{
|
||||
keyListener.AddHandler(e =>
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down && !e.IsRepeat)
|
||||
{
|
||||
var key = Hotkey.FromKeyInput(e);
|
||||
for (var i = 0; i < statsHotkeys.Length; i++)
|
||||
{
|
||||
if (key == statsHotkeys[i].GetValue())
|
||||
{
|
||||
OpenMenuPanel(stats, new WidgetArgs() { { "activePanel", i } });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user