BuildPaletteWidget: don't click on buttons if the palette isn't open. Don't allow hotkeys unless palette is open. Move key handling into widget.
This commit is contained in:
@@ -514,13 +514,6 @@ namespace OpenRA
|
|||||||
if (c == 08)
|
if (c == 08)
|
||||||
Game.controller.GotoNextBase();
|
Game.controller.GotoNextBase();
|
||||||
|
|
||||||
if (c == 09)
|
|
||||||
BuildPaletteWidget.TabChange((Control.ModifierKeys & Keys.Shift) == Keys.Shift ? true : false);
|
|
||||||
|
|
||||||
// Todo: move this into the widget
|
|
||||||
BuildPaletteWidget.DoBuildingHotkey(c, world);
|
|
||||||
|
|
||||||
|
|
||||||
if (sync != Game.world.SyncHash())
|
if (sync != Game.world.SyncHash())
|
||||||
throw new InvalidOperationException("Desync in OnKeyPress");
|
throw new InvalidOperationException("Desync in OnKeyPress");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ namespace OpenRA.Traits
|
|||||||
public class EvaAlertsInfo : TraitInfo<EvaAlerts>
|
public class EvaAlertsInfo : TraitInfo<EvaAlerts>
|
||||||
{
|
{
|
||||||
// Sound effects
|
// Sound effects
|
||||||
public readonly string TabClick = "ramenu1.aud";
|
|
||||||
public readonly string RadarUp = "radaron2.aud";
|
public readonly string RadarUp = "radaron2.aud";
|
||||||
public readonly string RadarDown = "radardn1.aud";
|
public readonly string RadarDown = "radardn1.aud";
|
||||||
|
|
||||||
@@ -32,8 +31,6 @@ namespace OpenRA.Traits
|
|||||||
public readonly string CashTickDown = "cashdn1.aud";
|
public readonly string CashTickDown = "cashdn1.aud";
|
||||||
|
|
||||||
// Build Palette
|
// Build Palette
|
||||||
public readonly string BuildPaletteOpen = "bleep13.aud";
|
|
||||||
public readonly string BuildPaletteClose = "bleep13.aud";
|
|
||||||
public readonly string BuildingSelectAudio = "abldgin1.aud";
|
public readonly string BuildingSelectAudio = "abldgin1.aud";
|
||||||
public readonly string BuildingReadyAudio = "conscmp1.aud";
|
public readonly string BuildingReadyAudio = "conscmp1.aud";
|
||||||
public readonly string BuildingCannotPlaceAudio = "nodeply1.aud";
|
public readonly string BuildingCannotPlaceAudio = "nodeply1.aud";
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ using OpenRA.FileFormats;
|
|||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Orders;
|
using OpenRA.Orders;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,7 @@ namespace OpenRA.Widgets
|
|||||||
public int Columns = 3;
|
public int Columns = 3;
|
||||||
public int Rows = 5;
|
public int Rows = 5;
|
||||||
|
|
||||||
string currentTab = "Building";
|
string currentTab = null;
|
||||||
bool paletteOpen = false;
|
bool paletteOpen = false;
|
||||||
Dictionary<string, string[]> tabImageNames;
|
Dictionary<string, string[]> tabImageNames;
|
||||||
Dictionary<string, Sprite> tabSprites;
|
Dictionary<string, Sprite> tabSprites;
|
||||||
@@ -45,9 +46,13 @@ namespace OpenRA.Widgets
|
|||||||
int paletteAnimationFrame = 0;
|
int paletteAnimationFrame = 0;
|
||||||
bool paletteAnimating = false;
|
bool paletteAnimating = false;
|
||||||
List<Pair<Rectangle, Action<MouseInput>>> buttons = new List<Pair<Rectangle,Action<MouseInput>>>();
|
List<Pair<Rectangle, Action<MouseInput>>> buttons = new List<Pair<Rectangle,Action<MouseInput>>>();
|
||||||
|
List<Pair<Rectangle, Action<MouseInput>>> tabs = new List<Pair<Rectangle, Action<MouseInput>>>();
|
||||||
Animation cantBuild;
|
Animation cantBuild;
|
||||||
Animation ready;
|
Animation ready;
|
||||||
Animation clock;
|
Animation clock;
|
||||||
|
public readonly string BuildPaletteOpen = "bleep13.aud";
|
||||||
|
public readonly string BuildPaletteClose = "bleep13.aud";
|
||||||
|
public readonly string TabClick = "ramenu1.aud";
|
||||||
List<string> visibleTabs = new List<string>();
|
List<string> visibleTabs = new List<string>();
|
||||||
|
|
||||||
public BuildPaletteWidget() : base() { }
|
public BuildPaletteWidget() : base() { }
|
||||||
@@ -76,6 +81,7 @@ namespace OpenRA.Widgets
|
|||||||
n => i.ToString())))
|
n => i.ToString())))
|
||||||
.ToDictionary(a => a.First, a => a.Second);
|
.ToDictionary(a => a.First, a => a.Second);
|
||||||
|
|
||||||
|
IsVisible = () => { return currentTab != null || (currentTab == null && !paletteOpen); };
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick(World world)
|
public override void Tick(World world)
|
||||||
@@ -112,16 +118,14 @@ namespace OpenRA.Widgets
|
|||||||
// Calculate palette position
|
// Calculate palette position
|
||||||
if (paletteAnimationFrame <= paletteAnimationLength)
|
if (paletteAnimationFrame <= paletteAnimationLength)
|
||||||
paletteOrigin = float2.Lerp(paletteClosedOrigin, paletteOpenOrigin, paletteAnimationFrame * 1.0f / paletteAnimationLength);
|
paletteOrigin = float2.Lerp(paletteClosedOrigin, paletteOpenOrigin, paletteAnimationFrame * 1.0f / paletteAnimationLength);
|
||||||
|
|
||||||
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
|
||||||
|
|
||||||
// Play palette-open sound at the start of the activate anim (open)
|
// Play palette-open sound at the start of the activate anim (open)
|
||||||
if (paletteAnimationFrame == 1 && paletteOpen)
|
if (paletteAnimationFrame == 1 && paletteOpen)
|
||||||
Sound.Play(eva.BuildPaletteOpen);
|
Sound.Play(BuildPaletteOpen);
|
||||||
|
|
||||||
// Play palette-close sound at the start of the activate anim (close)
|
// Play palette-close sound at the start of the activate anim (close)
|
||||||
if (paletteAnimationFrame == paletteAnimationLength + -1 && !paletteOpen)
|
if (paletteAnimationFrame == paletteAnimationLength + -1 && !paletteOpen)
|
||||||
Sound.Play(eva.BuildPaletteClose);
|
Sound.Play(BuildPaletteClose);
|
||||||
|
|
||||||
// Animation is complete
|
// Animation is complete
|
||||||
if ((paletteAnimationFrame == 0 && !paletteOpen)
|
if ((paletteAnimationFrame == 0 && !paletteOpen)
|
||||||
@@ -139,13 +143,26 @@ namespace OpenRA.Widgets
|
|||||||
currentTab = produces;
|
currentTab = produces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool HandleKeyPress (KeyPressEventArgs e, Modifiers modifiers)
|
||||||
|
{
|
||||||
|
if (e.KeyChar == 09)
|
||||||
|
TabChange((Control.ModifierKeys & Keys.Shift) == Keys.Shift);
|
||||||
|
|
||||||
|
DoBuildingHotkey(Char.ToLowerInvariant(e.KeyChar), Game.world);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event != MouseInputEvent.Down)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
var action = tabs.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
||||||
.Select(a => a.Second).FirstOrDefault();
|
.Select(a => a.Second).FirstOrDefault();
|
||||||
|
if (action == null && paletteOpen)
|
||||||
|
action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
||||||
|
.Select(a => a.Second).FirstOrDefault();
|
||||||
|
|
||||||
if (action == null)
|
if (action == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -155,6 +172,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
|
if (!IsVisible()) return;
|
||||||
int paletteHeight = DrawPalette(world, currentTab);
|
int paletteHeight = DrawPalette(world, currentTab);
|
||||||
DrawBuildTabs(world, paletteHeight);
|
DrawBuildTabs(world, paletteHeight);
|
||||||
}
|
}
|
||||||
@@ -285,22 +303,12 @@ namespace OpenRA.Widgets
|
|||||||
Action<MouseInput> HandleClick(string name, World world)
|
Action<MouseInput> HandleClick(string name, World world)
|
||||||
{
|
{
|
||||||
return mi => {
|
return mi => {
|
||||||
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
Sound.Play(TabClick);
|
||||||
Sound.Play(eva.TabClick);
|
|
||||||
|
|
||||||
if (name != null)
|
if (name != null)
|
||||||
HandleBuildPalette(world, name, (mi.Button == MouseButton.Left));
|
HandleBuildPalette(world, name, (mi.Button == MouseButton.Left));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Hotkey(World world, String name)
|
|
||||||
{
|
|
||||||
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
|
||||||
Sound.Play(eva.TabClick);
|
|
||||||
|
|
||||||
if (name != null)
|
|
||||||
HandleBuildPalette(world, name, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Action<MouseInput> HandleTabClick(string button, World world)
|
Action<MouseInput> HandleTabClick(string button, World world)
|
||||||
{
|
{
|
||||||
@@ -308,8 +316,7 @@ namespace OpenRA.Widgets
|
|||||||
if (mi.Button != MouseButton.Left)
|
if (mi.Button != MouseButton.Left)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
Sound.Play(TabClick);
|
||||||
Sound.Play(eva.TabClick);
|
|
||||||
var wasOpen = paletteOpen;
|
var wasOpen = paletteOpen;
|
||||||
paletteOpen = (currentTab == button && wasOpen) ? false : true;
|
paletteOpen = (currentTab == button && wasOpen) ? false : true;
|
||||||
currentTab = button;
|
currentTab = button;
|
||||||
@@ -326,7 +333,7 @@ namespace OpenRA.Widgets
|
|||||||
return Rules.Info[ a.ToLowerInvariant() ].Traits.Get<ValuedInfo>().Description;
|
return Rules.Info[ a.ToLowerInvariant() ].Traits.Get<ValuedInfo>().Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleBuildPalette( World world, string item, bool isLmb )
|
void HandleBuildPalette( World world, string item, bool isLmb )
|
||||||
{
|
{
|
||||||
var player = world.LocalPlayer;
|
var player = world.LocalPlayer;
|
||||||
var unit = Rules.Info[item];
|
var unit = Rules.Info[item];
|
||||||
@@ -373,7 +380,7 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StartProduction( World world, string item )
|
void StartProduction( World world, string item )
|
||||||
{
|
{
|
||||||
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
||||||
var unit = Rules.Info[item];
|
var unit = Rules.Info[item];
|
||||||
@@ -399,6 +406,7 @@ namespace OpenRA.Widgets
|
|||||||
var x = paletteOrigin.X - tabWidth;
|
var x = paletteOrigin.X - tabWidth;
|
||||||
var y = paletteOrigin.Y + 9;
|
var y = paletteOrigin.Y + 9;
|
||||||
|
|
||||||
|
tabs.Clear();
|
||||||
var queue = world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
var queue = world.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
|
||||||
foreach (var q in tabImageNames)
|
foreach (var q in tabImageNames)
|
||||||
@@ -414,7 +422,7 @@ namespace OpenRA.Widgets
|
|||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer,"tabs-"+tabKeys[index], race+"-"+q.Key), new float2(x, y));
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer,"tabs-"+tabKeys[index], race+"-"+q.Key), new float2(x, y));
|
||||||
|
|
||||||
var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight);
|
var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight);
|
||||||
buttons.Add(Pair.New(rect, HandleTabClick(groupName, world)));
|
tabs.Add(Pair.New(rect, HandleTabClick(groupName, world)));
|
||||||
|
|
||||||
if (rect.Contains(Game.chrome.lastMousePos.ToPoint()))
|
if (rect.Contains(Game.chrome.lastMousePos.ToPoint()))
|
||||||
{
|
{
|
||||||
@@ -497,37 +505,42 @@ namespace OpenRA.Widgets
|
|||||||
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DoBuildingHotkey(char c, World world)
|
bool DoBuildingHotkey(char c, World world)
|
||||||
{
|
{
|
||||||
if (Game.world.LocalPlayer == null) return;
|
if (!paletteOpen) return true;
|
||||||
|
|
||||||
var buildable = Rules.TechTree.BuildableItems(Game.world.LocalPlayer, Chrome.rootWidget.GetWidget<BuildPaletteWidget>("INGAME_BUILD_PALETTE").currentTab);
|
var buildable = Rules.TechTree.BuildableItems(world.LocalPlayer, currentTab);
|
||||||
|
|
||||||
var toBuild = buildable.FirstOrDefault(b => Rules.Info[b.ToLowerInvariant()].Traits.Get<BuildableInfo>().Hotkey == c.ToString());
|
var toBuild = buildable.FirstOrDefault(b => Rules.Info[b.ToLowerInvariant()].Traits.Get<BuildableInfo>().Hotkey == c.ToString());
|
||||||
|
|
||||||
if (toBuild != null) Hotkey(world, toBuild);
|
if ( toBuild != null )
|
||||||
|
{
|
||||||
|
Sound.Play(TabClick);
|
||||||
|
HandleBuildPalette(world, toBuild, true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void TabChange(bool shift)
|
|
||||||
|
void TabChange(bool shift)
|
||||||
{
|
{
|
||||||
var p = Chrome.rootWidget.GetWidget<BuildPaletteWidget>("INGAME_BUILD_PALETTE");
|
int size = visibleTabs.Count();
|
||||||
int size = p.visibleTabs.Count();
|
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
int current = p.visibleTabs.IndexOf(p.currentTab);
|
int current = visibleTabs.IndexOf(currentTab);
|
||||||
if (!shift)
|
if (!shift)
|
||||||
{
|
{
|
||||||
if (current + 1 >= size)
|
if (current + 1 >= size)
|
||||||
p.SetCurrentTab(p.visibleTabs.FirstOrDefault());
|
SetCurrentTab(visibleTabs.FirstOrDefault());
|
||||||
else
|
else
|
||||||
p.SetCurrentTab(p.visibleTabs[current + 1]);
|
SetCurrentTab(visibleTabs[current + 1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (current - 1 < 0)
|
if (current - 1 < 0)
|
||||||
p.SetCurrentTab(p.visibleTabs.LastOrDefault());
|
SetCurrentTab(visibleTabs.LastOrDefault());
|
||||||
else
|
else
|
||||||
p.SetCurrentTab(p.visibleTabs[current - 1]);
|
SetCurrentTab(visibleTabs[current - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user