Implement new production hotkeys. Fixes #3915, #4142, #4181.

This commit is contained in:
Paul Chote
2014-08-01 20:52:26 +12:00
parent 61b7e63e77
commit 43bd8a361e
7 changed files with 122 additions and 20 deletions

View File

@@ -178,6 +178,42 @@ namespace OpenRA
public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None); public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None);
public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift); public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift);
public Hotkey Production01Key = new Hotkey(Keycode.F1, Modifiers.None);
public Hotkey Production02Key = new Hotkey(Keycode.F2, Modifiers.None);
public Hotkey Production03Key = new Hotkey(Keycode.F3, Modifiers.None);
public Hotkey Production04Key = new Hotkey(Keycode.F4, Modifiers.None);
public Hotkey Production05Key = new Hotkey(Keycode.F5, Modifiers.None);
public Hotkey Production06Key = new Hotkey(Keycode.F6, Modifiers.None);
public Hotkey Production07Key = new Hotkey(Keycode.F7, Modifiers.None);
public Hotkey Production08Key = new Hotkey(Keycode.F8, Modifiers.None);
public Hotkey Production09Key = new Hotkey(Keycode.F9, Modifiers.None);
public Hotkey Production10Key = new Hotkey(Keycode.F10, Modifiers.None);
public Hotkey Production11Key = new Hotkey(Keycode.F11, Modifiers.None);
public Hotkey Production12Key = new Hotkey(Keycode.F12, Modifiers.None);
public Hotkey Production13Key = new Hotkey(Keycode.F1, Modifiers.Ctrl);
public Hotkey Production14Key = new Hotkey(Keycode.F2, Modifiers.Ctrl);
public Hotkey Production15Key = new Hotkey(Keycode.F3, Modifiers.Ctrl);
public Hotkey Production16Key = new Hotkey(Keycode.F4, Modifiers.Ctrl);
public Hotkey Production17Key = new Hotkey(Keycode.F5, Modifiers.Ctrl);
public Hotkey Production18Key = new Hotkey(Keycode.F6, Modifiers.Ctrl);
public Hotkey Production19Key = new Hotkey(Keycode.F7, Modifiers.Ctrl);
public Hotkey Production20Key = new Hotkey(Keycode.F8, Modifiers.Ctrl);
public Hotkey Production21Key = new Hotkey(Keycode.F9, Modifiers.Ctrl);
public Hotkey Production22Key = new Hotkey(Keycode.F10, Modifiers.Ctrl);
public Hotkey Production23Key = new Hotkey(Keycode.F11, Modifiers.Ctrl);
public Hotkey Production24Key = new Hotkey(Keycode.F12, Modifiers.Ctrl);
public Hotkey GetProductionHotkey(int index)
{
var field = GetType().GetField("Production{0:D2}Key".F(index + 1));
if (field == null)
return Hotkey.Invalid;
return (Hotkey)field.GetValue(this);
}
} }
public class IrcSettings public class IrcSettings

View File

@@ -233,6 +233,8 @@ namespace OpenRA.Mods.D2k.Widgets
// Icons // Icons
string tooltipItem = null; string tooltipItem = null;
var tooltipHotkey = Hotkey.Invalid;
var i = 0;
foreach (var item in allBuildables) foreach (var item in allBuildables)
{ {
var rect = new RectangleF(origin.X + x * IconWidth, origin.Y + IconHeight * y, IconWidth, IconHeight); var rect = new RectangleF(origin.X + x * IconWidth, origin.Y + IconHeight * y, IconWidth, IconHeight);
@@ -244,7 +246,10 @@ namespace OpenRA.Mods.D2k.Widgets
var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name); var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);
if (rect.Contains(Viewport.LastMousePos)) if (rect.Contains(Viewport.LastMousePos))
{
tooltipItem = item.Name; tooltipItem = item.Name;
tooltipHotkey = Game.Settings.Keys.GetProductionHotkey(i);
}
var overlayPos = drawPos + new float2(32, 16); var overlayPos = drawPos + new float2(32, 16);
@@ -271,6 +276,7 @@ namespace OpenRA.Mods.D2k.Widgets
buttons.Add(Pair.New(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), HandleClick(closureName, world))); buttons.Add(Pair.New(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), HandleClick(closureName, world)));
if (++x == Columns) { x = 0; y++; } if (++x == Columns) { x = 0; y++; }
i++;
} }
if (x != 0) y++; if (x != 0) y++;
@@ -291,7 +297,7 @@ namespace OpenRA.Mods.D2k.Widgets
// Tooltip // Tooltip
if (tooltipItem != null && !paletteAnimating && paletteOpen) if (tooltipItem != null && !paletteAnimating && paletteOpen)
DrawProductionTooltip(world, tooltipItem, DrawProductionTooltip(world, tooltipItem, tooltipHotkey,
new float2(Game.Renderer.Resolution.Width, origin.Y + numActualRows * IconHeight + 9).ToInt2()); new float2(Game.Renderer.Resolution.Width, origin.Y + numActualRows * IconHeight + 9).ToInt2());
} }
@@ -466,7 +472,7 @@ namespace OpenRA.Mods.D2k.Widgets
font.DrawText(text, pos - new int2(font.Measure(text).X, 0), c); font.DrawText(text, pos - new int2(font.Measure(text).X, 0), c);
} }
void DrawProductionTooltip(World world, string unit, int2 pos) void DrawProductionTooltip(World world, string unit, Hotkey hotkey, int2 pos)
{ {
pos.Y += 15; pos.Y += 15;
@@ -485,7 +491,7 @@ namespace OpenRA.Mods.D2k.Widgets
WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.Renderer.Resolution.Width - 300, pos.Y, 300, longDescSize + 65)); WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.Renderer.Resolution.Width - 300, pos.Y, 300, longDescSize + 65));
Game.Renderer.Fonts["Bold"].DrawText( Game.Renderer.Fonts["Bold"].DrawText(
tooltip.Name + (buildable.Hotkey.IsValid() ? " ({0})".F(buildable.Hotkey.DisplayString()) : ""), tooltip.Name + (hotkey.IsValid() ? " ({0})".F(hotkey.DisplayString()) : ""),
p.ToInt2() + new int2(5, 5), Color.White); p.ToInt2() + new int2(5, 5), Color.White);
var resources = pl.PlayerActor.Trait<PlayerResources>(); var resources = pl.PlayerActor.Trait<PlayerResources>();
@@ -526,8 +532,20 @@ namespace OpenRA.Mods.D2k.Widgets
if (!paletteOpen) return false; if (!paletteOpen) return false;
if (CurrentQueue == null) return false; if (CurrentQueue == null) return false;
var toBuild = CurrentQueue.BuildableItems().FirstOrDefault(b => b.Traits.Get<BuildableInfo>().Hotkey == Hotkey.FromKeyInput(e)); var key = Hotkey.FromKeyInput(e);
var ks = Game.Settings.Keys;
var slot = -1;
for (var i = 0; i < 24; i++)
{
if (ks.GetProductionHotkey(i) == key)
{
slot = i;
break;
}
}
var allBuildables = CurrentQueue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder).ToArray();
var toBuild = allBuildables.ElementAtOrDefault(slot);
if (toBuild != null) if (toBuild != null)
{ {
Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null); Sound.PlayNotification(world.Map.Rules, null, "Sounds", "TabClick", null);

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var pm = palette.World.LocalPlayer.PlayerActor.Trait<PowerManager>(); var pm = palette.World.LocalPlayer.PlayerActor.Trait<PowerManager>();
var pr = palette.World.LocalPlayer.PlayerActor.Trait<PlayerResources>(); var pr = palette.World.LocalPlayer.PlayerActor.Trait<PlayerResources>();
widget.IsVisible = () => palette.TooltipActor != null; widget.IsVisible = () => palette.TooltipIcon != null;
var nameLabel = widget.Get<LabelWidget>("NAME"); var nameLabel = widget.Get<LabelWidget>("NAME");
var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY"); var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY");
var requiresLabel = widget.Get<LabelWidget>("REQUIRES"); var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
@@ -44,29 +44,31 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var font = Game.Renderer.Fonts[nameLabel.Font]; var font = Game.Renderer.Fonts[nameLabel.Font];
var descFont = Game.Renderer.Fonts[descLabel.Font]; var descFont = Game.Renderer.Fonts[descLabel.Font];
var requiresFont = Game.Renderer.Fonts[requiresLabel.Font]; var requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
string lastActor = null; ActorInfo lastActor = null;
tooltipContainer.BeforeRender = () => tooltipContainer.BeforeRender = () =>
{ {
var actor = palette.TooltipActor; if (palette.TooltipIcon == null)
return;
var actor = palette.TooltipIcon.Actor;
if (actor == null || actor == lastActor) if (actor == null || actor == lastActor)
return; return;
var info = mapRules.Actors[actor]; var tooltip = actor.Traits.Get<TooltipInfo>();
var tooltip = info.Traits.Get<TooltipInfo>(); var buildable = actor.Traits.Get<BuildableInfo>();
var buildable = info.Traits.Get<BuildableInfo>(); var cost = actor.Traits.Get<ValuedInfo>().Cost;
var cost = info.Traits.Get<ValuedInfo>().Cost; var pi = actor.Traits.GetOrDefault<PowerInfo>();
var pi = info.Traits.GetOrDefault<PowerInfo>();
nameLabel.GetText = () => tooltip.Name; nameLabel.GetText = () => tooltip.Name;
var hotkey = palette.TooltipIcon.Hotkey;
var nameWidth = font.Measure(tooltip.Name).X; var nameWidth = font.Measure(tooltip.Name).X;
var hotkeyText = "({0})".F(buildable.Hotkey.DisplayString()); var hotkeyText = "({0})".F(hotkey.DisplayString());
var hotkeyWidth = buildable.Hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0; var hotkeyWidth = hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
hotkeyLabel.GetText = () => hotkeyText; hotkeyLabel.GetText = () => hotkeyText;
hotkeyLabel.Bounds.X = nameWidth + 2 * nameLabel.Bounds.X; hotkeyLabel.Bounds.X = nameWidth + 2 * nameLabel.Bounds.X;
hotkeyLabel.Visible = buildable.Hotkey.IsValid(); hotkeyLabel.Visible = hotkey.IsValid();
var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a)).Where(s => !s.StartsWith("~")); var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a)).Where(s => !s.StartsWith("~"));
var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : ""; var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
@@ -81,7 +83,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
powerIcon.IsVisible = () => power != 0; powerIcon.IsVisible = () => power != 0;
var lowpower = pm.PowerState != PowerState.Normal; var lowpower = pm.PowerState != PowerState.Normal;
var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor) var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor.Name)
* (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1); * (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
var timeString = WidgetUtils.FormatTime(time); var timeString = WidgetUtils.FormatTime(time);
timeLabel.GetText = () => timeString; timeLabel.GetText = () => timeString;

View File

@@ -305,6 +305,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var hotkeyHeader = hotkeyList.Get<ScrollItemWidget>("HEADER"); var hotkeyHeader = hotkeyList.Get<ScrollItemWidget>("HEADER");
var globalTemplate = hotkeyList.Get("GLOBAL_TEMPLATE"); var globalTemplate = hotkeyList.Get("GLOBAL_TEMPLATE");
var unitTemplate = hotkeyList.Get("UNIT_TEMPLATE"); var unitTemplate = hotkeyList.Get("UNIT_TEMPLATE");
var productionTemplate = hotkeyList.Get("PRODUCTION_TEMPLATE");
hotkeyList.RemoveChildren(); hotkeyList.RemoveChildren();
// Game // Game
@@ -376,6 +377,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
BindHotkeyPref(kv, ks, unitTemplate, hotkeyList); BindHotkeyPref(kv, ks, unitTemplate, hotkeyList);
} }
// Production
{
var hotkeys = new Dictionary<string, string>();
for (var i = 1; i <= 24; i++)
hotkeys.Add("Production{0:D2}Key".F(i), "Slot {0}".F(i));
var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
header.Get<LabelWidget>("LABEL").GetText = () => "Production Commands";
hotkeyList.AddChild(header);
foreach (var kv in hotkeys)
BindHotkeyPref(kv, ks, productionTemplate, hotkeyList);
}
// Developer // Developer
{ {
var hotkeys = new Dictionary<string, string>() var hotkeys = new Dictionary<string, string>()

View File

@@ -25,6 +25,7 @@ namespace OpenRA.Mods.RA.Widgets
{ {
public class ProductionIcon public class ProductionIcon
{ {
public ActorInfo Actor;
public string Name; public string Name;
public Hotkey Hotkey; public Hotkey Hotkey;
public Sprite Sprite; public Sprite Sprite;
@@ -53,7 +54,7 @@ namespace OpenRA.Mods.RA.Widgets
public int IconCount { get; private set; } public int IconCount { get; private set; }
public event Action<int, int> OnIconCountChanged = (a, b) => {}; public event Action<int, int> OnIconCountChanged = (a, b) => {};
public string TooltipActor { get; private set; } public ProductionIcon TooltipIcon { get; private set; }
public readonly World World; public readonly World World;
readonly OrderManager orderManager; readonly OrderManager orderManager;
@@ -116,7 +117,7 @@ namespace OpenRA.Mods.RA.Widgets
.Select(i => i.Value).FirstOrDefault(); .Select(i => i.Value).FirstOrDefault();
if (mi.Event == MouseInputEvent.Move) if (mi.Event == MouseInputEvent.Move)
TooltipActor = icon != null ? icon.Name : null; TooltipIcon = icon;
if (icon == null) if (icon == null)
return false; return false;
@@ -218,6 +219,7 @@ namespace OpenRA.Mods.RA.Widgets
var oldIconCount = IconCount; var oldIconCount = IconCount;
IconCount = 0; IconCount = 0;
var ks = Game.Settings.Keys;
var rb = RenderBounds; var rb = RenderBounds;
foreach (var item in allBuildables) foreach (var item in allBuildables)
{ {
@@ -229,8 +231,9 @@ namespace OpenRA.Mods.RA.Widgets
var pi = new ProductionIcon() var pi = new ProductionIcon()
{ {
Actor = item,
Name = item.Name, Name = item.Name,
Hotkey = item.Traits.Get<BuildableInfo>().Hotkey, Hotkey = ks.GetProductionHotkey(IconCount),
Sprite = icon.Image, Sprite = icon.Image,
Pos = new float2(rect.Location), Pos = new float2(rect.Location),
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(), Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),

View File

@@ -399,6 +399,20 @@ Container@SETTINGS_PANEL:
X: PARENT_RIGHT-WIDTH+1 X: PARENT_RIGHT-WIDTH+1
Width: 80 Width: 80
Height: 25 Height: 25
Container@PRODUCTION_TEMPLATE:
Width: 173
Height: 25
Visible: false
Children:
Label@FUNCTION:
Y: 0-1
Width: PARENT_RIGHT - 84
Height: 25
Align: Right
HotkeyEntry@HOTKEY:
X: PARENT_RIGHT-WIDTH+1
Width: 80
Height: 25
Container@ADVANCED_PANEL: Container@ADVANCED_PANEL:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM Height: PARENT_BOTTOM

View File

@@ -404,6 +404,20 @@ Background@SETTINGS_PANEL:
X: PARENT_RIGHT-WIDTH+1 X: PARENT_RIGHT-WIDTH+1
Width: 80 Width: 80
Height: 25 Height: 25
Container@PRODUCTION_TEMPLATE:
Width: 173
Height: 25
Visible: false
Children:
Label@FUNCTION:
Y: 0-1
Width: PARENT_RIGHT - 84
Height: 25
Align: Right
HotkeyEntry@HOTKEY:
X: PARENT_RIGHT-WIDTH+1
Width: 80
Height: 25
Container@ADVANCED_PANEL: Container@ADVANCED_PANEL:
X: 5 X: 5
Y: 50 Y: 50