Add Statistics options hotkeys

This commit is contained in:
rob-v
2017-09-02 08:14:20 +02:00
committed by reaperrr
parent b86d632c8c
commit c9b4568117
11 changed files with 170 additions and 93 deletions

View File

@@ -244,6 +244,11 @@ namespace OpenRA
public Hotkey ObserverCombinedViewKey = new Hotkey(Keycode.MINUS, Modifiers.None); public Hotkey ObserverCombinedViewKey = new Hotkey(Keycode.MINUS, Modifiers.None);
public Hotkey ObserverWorldViewKey = new Hotkey(Keycode.EQUALS, Modifiers.None); public Hotkey ObserverWorldViewKey = new Hotkey(Keycode.EQUALS, Modifiers.None);
public Hotkey StatisticsBasicKey = new Hotkey(Keycode.F1, Modifiers.None);
public Hotkey StatisticsEconomyKey = new Hotkey(Keycode.F2, Modifiers.None);
public Hotkey StatisticsProductionKey = new Hotkey(Keycode.F3, Modifiers.None);
public Hotkey StatisticsCombatKey = new Hotkey(Keycode.F4, Modifiers.None);
public Hotkey StatisticsGraphKey = new Hotkey(Keycode.UNKNOWN, Modifiers.None);
public Hotkey CycleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None); public Hotkey CycleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None);
public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None); public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None);

View File

@@ -10,13 +10,15 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common.Lint;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic namespace OpenRA.Mods.Common.Widgets.Logic
{ {
[ChromeLogicArgsHotkeys("StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsCombatKey", "StatisticsGraphKey")]
public class MenuButtonsChromeLogic : ChromeLogic public class MenuButtonsChromeLogic : ChromeLogic
{ {
readonly World world; readonly World world;
@@ -26,13 +28,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Widget currentWidget; Widget currentWidget;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MenuButtonsChromeLogic(Widget widget, World world) public MenuButtonsChromeLogic(Widget widget, World world, Dictionary<string, MiniYaml> logicArgs)
{ {
this.world = world; this.world = world;
worldRoot = Ui.Root.Get("WORLD_ROOT"); worldRoot = Ui.Root.Get("WORLD_ROOT");
menuRoot = Ui.Root.Get("MENU_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 // System buttons
var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON"); var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
if (options != null) if (options != null)
@@ -85,7 +94,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (stats != null) if (stats != null)
{ {
stats.IsDisabled = () => disableSystemButtons || world.Map.Visibility.HasFlag(MapVisibility.MissionSelector); 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;
});
} }
} }

View File

@@ -14,6 +14,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Lint;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Traits; using OpenRA.Traits;
@@ -21,30 +22,40 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic namespace OpenRA.Mods.Common.Widgets.Logic
{ {
public enum ObserverStatsPanel { Basic, Economy, Production, Combat, Graph }
[ChromeLogicArgsHotkeys("StatisticsBasicKey", "StatisticsEconomyKey", "StatisticsProductionKey", "StatisticsCombatKey", "StatisticsGraphKey")]
public class ObserverStatsLogic : ChromeLogic public class ObserverStatsLogic : ChromeLogic
{ {
ContainerWidget basicStatsHeaders; readonly ContainerWidget basicStatsHeaders;
ContainerWidget economyStatsHeaders; readonly ContainerWidget economyStatsHeaders;
ContainerWidget productionStatsHeaders; readonly ContainerWidget productionStatsHeaders;
ContainerWidget combatStatsHeaders; readonly ContainerWidget combatStatsHeaders;
ContainerWidget earnedThisMinuteGraphHeaders; readonly ContainerWidget earnedThisMinuteGraphHeaders;
ScrollPanelWidget playerStatsPanel; readonly ScrollPanelWidget playerStatsPanel;
ScrollItemWidget basicPlayerTemplate; readonly ScrollItemWidget basicPlayerTemplate;
ScrollItemWidget economyPlayerTemplate; readonly ScrollItemWidget economyPlayerTemplate;
ScrollItemWidget productionPlayerTemplate; readonly ScrollItemWidget productionPlayerTemplate;
ScrollItemWidget combatPlayerTemplate; readonly ScrollItemWidget combatPlayerTemplate;
ContainerWidget earnedThisMinuteGraphTemplate; readonly ContainerWidget earnedThisMinuteGraphTemplate;
ScrollItemWidget teamTemplate; readonly ScrollItemWidget teamTemplate;
DropDownButtonWidget statsDropDown; readonly IEnumerable<Player> players;
IEnumerable<Player> players; readonly World world;
World world; readonly WorldRenderer worldRenderer;
WorldRenderer worldRenderer;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ObserverStatsLogic(World world, WorldRenderer worldRenderer, Widget widget, Action onExit) public ObserverStatsLogic(World world, WorldRenderer worldRenderer, Widget widget, Action onExit, ObserverStatsPanel activePanel, Dictionary<string, MiniYaml> logicArgs)
{ {
this.world = world; this.world = world;
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
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();
players = world.Players.Where(p => !p.NonCombatant); players = world.Players.Where(p => !p.NonCombatant);
basicStatsHeaders = widget.Get<ContainerWidget>("BASIC_STATS_HEADERS"); basicStatsHeaders = widget.Get<ContainerWidget>("BASIC_STATS_HEADERS");
@@ -64,79 +75,40 @@ namespace OpenRA.Mods.Common.Widgets.Logic
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE"); teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
statsDropDown = widget.Get<DropDownButtonWidget>("STATS_DROPDOWN"); var statsDropDown = widget.Get<DropDownButtonWidget>("STATS_DROPDOWN");
statsDropDown.GetText = () => "Basic"; Func<string, ContainerWidget, Action, StatsDropDownOption> createStatsOption = (title, headers, a) =>
statsDropDown.OnMouseDown = _ =>
{ {
var options = new List<StatsDropDownOption> return new StatsDropDownOption
{ {
new StatsDropDownOption Title = title,
IsSelected = () => headers.Visible,
OnClick = () =>
{ {
Title = "Basic", ClearStats();
IsSelected = () => basicStatsHeaders.Visible, statsDropDown.GetText = () => title;
OnClick = () => a();
{
ClearStats();
statsDropDown.GetText = () => "Basic";
DisplayStats(BasicStats);
}
},
new StatsDropDownOption
{
Title = "Economy",
IsSelected = () => economyStatsHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Economy";
DisplayStats(EconomyStats);
}
},
new StatsDropDownOption
{
Title = "Production",
IsSelected = () => productionStatsHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Production";
DisplayStats(ProductionStats);
}
},
new StatsDropDownOption
{
Title = "Combat",
IsSelected = () => combatStatsHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Combat";
DisplayStats(CombatStats);
}
},
new StatsDropDownOption
{
Title = "Earnings (graph)",
IsSelected = () => earnedThisMinuteGraphHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Earnings (graph)";
EarnedThisMinuteGraph();
}
} }
}; };
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
return item;
};
statsDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
}; };
ClearStats(); var statsDropDownOptions = new StatsDropDownOption[]
DisplayStats(BasicStats); {
createStatsOption("Basic", basicStatsHeaders, () => DisplayStats(BasicStats)),
createStatsOption("Economy", economyStatsHeaders, () => DisplayStats(EconomyStats)),
createStatsOption("Production", productionStatsHeaders, () => DisplayStats(ProductionStats)),
createStatsOption("Combat", combatStatsHeaders, () => DisplayStats(CombatStats)),
createStatsOption("Earnings (graph)", earnedThisMinuteGraphHeaders, () => EarnedThisMinuteGraph())
};
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
return item;
};
statsDropDown.OnMouseDown = _ => statsDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, statsDropDownOptions, setupItem);
statsDropDownOptions[(int)activePanel].OnClick();
var close = widget.GetOrNull<ButtonWidget>("CLOSE"); var close = widget.GetOrNull<ButtonWidget>("CLOSE");
if (close != null) if (close != null)
@@ -146,6 +118,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Ui.Root.RemoveChild(widget); Ui.Root.RemoveChild(widget);
onExit(); onExit();
}; };
var keyListener = statsDropDown.Get<LogicKeyListenerWidget>("STATS_DROPDOWN_KEYHANDLER");
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())
{
statsDropDownOptions[i].OnClick();
return true;
}
}
}
return false;
});
} }
void ClearStats() void ClearStats()

View File

@@ -502,7 +502,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "ReplaySpeedSlowKey", "Slow speed" }, { "ReplaySpeedSlowKey", "Slow speed" },
{ "ReplaySpeedRegularKey", "Regular speed" }, { "ReplaySpeedRegularKey", "Regular speed" },
{ "ReplaySpeedFastKey", "Fast speed" }, { "ReplaySpeedFastKey", "Fast speed" },
{ "ReplaySpeedMaxKey", "Maximum speed" } { "ReplaySpeedMaxKey", "Maximum speed" },
{ "StatisticsBasicKey", "Basic statistics" },
{ "StatisticsEconomyKey", "Economy statistics" },
{ "StatisticsProductionKey", "Production statistics" },
{ "StatisticsCombatKey", "Combat statistics" },
{ "StatisticsGraphKey", "Statistics graph" }
}; };
var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing); var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing);

View File

@@ -1,5 +1,10 @@
Background@INGAME_OBSERVERSTATS_BG: Background@INGAME_OBSERVERSTATS_BG:
Logic: ObserverStatsLogic Logic: ObserverStatsLogic
StatisticsBasicKey: StatisticsBasic
StatisticsEconomyKey: StatisticsEconomy
StatisticsProductionKey: StatisticsProduction
StatisticsCombatKey: StatisticsCombat
StatisticsGraphKey: StatisticsGraph
X: (WINDOW_RIGHT - WIDTH) / 2 X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2 Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 1005 Width: 1005
@@ -24,6 +29,8 @@ Background@INGAME_OBSERVERSTATS_BG:
Width: 185 Width: 185
Height: 25 Height: 25
Font: Bold Font: Bold
Children:
LogicKeyListener@STATS_DROPDOWN_KEYHANDLER:
Container@BASIC_STATS_HEADERS: Container@BASIC_STATS_HEADERS:
X: 0 X: 0
Y: 0 Y: 0

View File

@@ -106,7 +106,13 @@ Container@PERF_WIDGETS:
Container@OBSERVER_WIDGETS: Container@OBSERVER_WIDGETS:
Logic: MenuButtonsChromeLogic Logic: MenuButtonsChromeLogic
StatisticsBasicKey: StatisticsBasic
StatisticsEconomyKey: StatisticsEconomy
StatisticsProductionKey: StatisticsProduction
StatisticsCombatKey: StatisticsCombat
StatisticsGraphKey: StatisticsGraph
Children: Children:
LogicKeyListener@OBSERVER_KEY_LISTENER:
MenuButton@OPTIONS_BUTTON: MenuButton@OPTIONS_BUTTON:
Key: escape Key: escape
X: WINDOW_RIGHT - 260 - WIDTH X: WINDOW_RIGHT - 260 - WIDTH
@@ -123,7 +129,7 @@ Container@OBSERVER_WIDGETS:
ImageCollection: order-icons ImageCollection: order-icons
ImageName: options ImageName: options
MenuButton@OBSERVER_STATS_BUTTON: MenuButton@OBSERVER_STATS_BUTTON:
Key: F1 Key: StatisticsBasic
X: WINDOW_RIGHT - 260 - WIDTH X: WINDOW_RIGHT - 260 - WIDTH
Y: 35 Y: 35
Width: 30 Width: 30

View File

@@ -1,6 +1,12 @@
Container@OBSERVER_WIDGETS: Container@OBSERVER_WIDGETS:
Logic: MenuButtonsChromeLogic Logic: MenuButtonsChromeLogic
StatisticsBasicKey: StatisticsBasic
StatisticsEconomyKey: StatisticsEconomy
StatisticsProductionKey: StatisticsProduction
StatisticsCombatKey: StatisticsCombat
StatisticsGraphKey: StatisticsGraph
Children: Children:
LogicKeyListener@OBSERVER_KEY_LISTENER:
MenuButton@OPTIONS_BUTTON: MenuButton@OPTIONS_BUTTON:
Width: 160 Width: 160
Height: 25 Height: 25
@@ -9,6 +15,7 @@ Container@OBSERVER_WIDGETS:
Key: escape Key: escape
DisableWorldSounds: true DisableWorldSounds: true
MenuButton@OBSERVER_STATS_BUTTON: MenuButton@OBSERVER_STATS_BUTTON:
Key: StatisticsBasic
MenuContainer: INGAME_OBSERVERSTATS_BG MenuContainer: INGAME_OBSERVERSTATS_BG
HideIngameUI: False HideIngameUI: False
Pause: False Pause: False
@@ -16,9 +23,8 @@ Container@OBSERVER_WIDGETS:
Y: 0 Y: 0
Width: 160 Width: 160
Height: 25 Height: 25
Text: Statistics (F1) Text: Statistics
Font: Bold Font: Bold
Key: f1
Container@GAME_TIMER_BLOCK: Container@GAME_TIMER_BLOCK:
Logic: GameTimerLogic Logic: GameTimerLogic
X: (WINDOW_RIGHT - WIDTH) / 2 X: (WINDOW_RIGHT - WIDTH) / 2

View File

@@ -1,5 +1,10 @@
Background@INGAME_OBSERVERSTATS_BG: Background@INGAME_OBSERVERSTATS_BG:
Logic: ObserverStatsLogic Logic: ObserverStatsLogic
StatisticsBasicKey: StatisticsBasic
StatisticsEconomyKey: StatisticsEconomy
StatisticsProductionKey: StatisticsProduction
StatisticsCombatKey: StatisticsCombat
StatisticsGraphKey: StatisticsGraph
X: 25 X: 25
Y: 50 Y: 50
Width: 1025 Width: 1025
@@ -24,6 +29,8 @@ Background@INGAME_OBSERVERSTATS_BG:
Width: 185 Width: 185
Height: 25 Height: 25
Font: Bold Font: Bold
Children:
LogicKeyListener@STATS_DROPDOWN_KEYHANDLER:
Container@BASIC_STATS_HEADERS: Container@BASIC_STATS_HEADERS:
X: 0 X: 0
Y: 0 Y: 0

View File

@@ -31,14 +31,20 @@ Container@OBSERVER_WIDGETS:
TooltipTemplate: SIMPLE_TOOLTIP TooltipTemplate: SIMPLE_TOOLTIP
Container@TOP_BUTTONS: Container@TOP_BUTTONS:
Logic: MenuButtonsChromeLogic Logic: MenuButtonsChromeLogic
StatisticsBasicKey: StatisticsBasic
StatisticsEconomyKey: StatisticsEconomy
StatisticsProductionKey: StatisticsProduction
StatisticsCombatKey: StatisticsCombat
StatisticsGraphKey: StatisticsGraph
X: 9 X: 9
Y: 7 Y: 7
Children: Children:
LogicKeyListener@OBSERVER_KEY_LISTENER:
MenuButton@OBSERVER_STATS_BUTTON: MenuButton@OBSERVER_STATS_BUTTON:
Key: StatisticsBasic
MenuContainer: INGAME_OBSERVERSTATS_BG MenuContainer: INGAME_OBSERVERSTATS_BG
HideIngameUI: false HideIngameUI: false
Pause: false Pause: false
Key: F1
X: 160 X: 160
Width: 28 Width: 28
Height: 28 Height: 28

View File

@@ -1,6 +1,12 @@
Container@OBSERVER_WIDGETS: Container@OBSERVER_WIDGETS:
Logic: MenuButtonsChromeLogic Logic: MenuButtonsChromeLogic
StatisticsBasicKey: StatisticsBasic
StatisticsEconomyKey: StatisticsEconomy
StatisticsProductionKey: StatisticsProduction
StatisticsCombatKey: StatisticsCombat
StatisticsGraphKey: StatisticsGraph
Children: Children:
LogicKeyListener@OBSERVER_KEY_LISTENER:
MenuButton@OPTIONS_BUTTON: MenuButton@OPTIONS_BUTTON:
Width: 160 Width: 160
Height: 25 Height: 25
@@ -9,6 +15,7 @@ Container@OBSERVER_WIDGETS:
Key: escape Key: escape
DisableWorldSounds: true DisableWorldSounds: true
MenuButton@OBSERVER_STATS_BUTTON: MenuButton@OBSERVER_STATS_BUTTON:
Key: StatisticsBasic
MenuContainer: INGAME_OBSERVERSTATS_BG MenuContainer: INGAME_OBSERVERSTATS_BG
HideIngameUI: False HideIngameUI: False
Pause: False Pause: False
@@ -16,9 +23,8 @@ Container@OBSERVER_WIDGETS:
Y: 0 Y: 0
Width: 160 Width: 160
Height: 25 Height: 25
Text: Statistics (F1) Text: Statistics
Font: Bold Font: Bold
Key: f1
Container@GAME_TIMER_BLOCK: Container@GAME_TIMER_BLOCK:
Logic: GameTimerLogic Logic: GameTimerLogic
X: (WINDOW_RIGHT - WIDTH) / 2 X: (WINDOW_RIGHT - WIDTH) / 2

View File

@@ -1,5 +1,10 @@
Background@INGAME_OBSERVERSTATS_BG: Background@INGAME_OBSERVERSTATS_BG:
Logic: ObserverStatsLogic Logic: ObserverStatsLogic
StatisticsBasicKey: StatisticsBasic
StatisticsEconomyKey: StatisticsEconomy
StatisticsProductionKey: StatisticsProduction
StatisticsCombatKey: StatisticsCombat
StatisticsGraphKey: StatisticsGraph
X: 25 X: 25
Y: 50 Y: 50
Width: 1025 Width: 1025
@@ -24,6 +29,8 @@ Background@INGAME_OBSERVERSTATS_BG:
Width: 185 Width: 185
Height: 25 Height: 25
Font: Bold Font: Bold
Children:
LogicKeyListener@STATS_DROPDOWN_KEYHANDLER:
Container@BASIC_STATS_HEADERS: Container@BASIC_STATS_HEADERS:
X: 0 X: 0
Y: 0 Y: 0