Widget IHandleInputs now
This commit is contained in:
@@ -15,7 +15,7 @@ using OpenRA.Widgets;
|
|||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
class Chrome : IHandleInput
|
class Chrome
|
||||||
{
|
{
|
||||||
public readonly Renderer renderer;
|
public readonly Renderer renderer;
|
||||||
public readonly LineRenderer lineRenderer;
|
public readonly LineRenderer lineRenderer;
|
||||||
@@ -44,37 +44,10 @@ namespace OpenRA
|
|||||||
|
|
||||||
if (!world.GameHasStarted) return;
|
if (!world.GameHasStarted) return;
|
||||||
if (world.LocalPlayer == null) return;
|
if (world.LocalPlayer == null) return;
|
||||||
++ticksSinceLastMove;
|
++Widget.ticksSinceLastMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(World world) { Widget.RootWidget.Draw(world); shpRenderer.Flush(); rgbaRenderer.Flush(); lineRenderer.Flush(); }
|
public void Draw(World world) { Widget.RootWidget.Draw(world); shpRenderer.Flush(); rgbaRenderer.Flush(); lineRenderer.Flush(); }
|
||||||
|
|
||||||
public int ticksSinceLastMove = 0;
|
|
||||||
public int2 lastMousePos;
|
|
||||||
public bool HandleInput(World world, MouseInput mi)
|
|
||||||
{
|
|
||||||
if (Widget.SelectedWidget != null && Widget.SelectedWidget.HandleMouseInputOuter(mi))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (Widget.RootWidget.HandleMouseInputOuter(mi))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
|
||||||
{
|
|
||||||
lastMousePos = mi.Location;
|
|
||||||
ticksSinceLastMove = 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HandleKeyPress(KeyInput e)
|
|
||||||
{
|
|
||||||
if (Widget.SelectedWidget != null)
|
|
||||||
return Widget.SelectedWidget.HandleKeyPressOuter(e);
|
|
||||||
|
|
||||||
if (Widget.RootWidget.HandleKeyPressOuter(e))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
int sync = world.SyncHash();
|
int sync = world.SyncHash();
|
||||||
|
|
||||||
if (chrome.HandleKeyPress(e))
|
if (Widget.HandleKeyPress(e))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (e.KeyName)
|
switch (e.KeyName)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Graphics
|
|||||||
scrollPosition = scrollPosition + delta;
|
scrollPosition = scrollPosition + delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IHandleInput> regions { get { return new IHandleInput[] { Game.chrome, Game.controller }; } }
|
public IEnumerable<IHandleInput> regions { get { return new IHandleInput[] { Widget.RootWidget, Game.controller }; } }
|
||||||
|
|
||||||
public Viewport(float2 screenSize, int2 mapStart, int2 mapEnd, Renderer renderer)
|
public Viewport(float2 screenSize, int2 mapStart, int2 mapEnd, Renderer renderer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ namespace OpenRA.Widgets
|
|||||||
currentTab = produces;
|
currentTab = produces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleKeyPress(KeyInput e)
|
public override bool HandleKeyPressInner(KeyInput e)
|
||||||
{
|
{
|
||||||
if (e.KeyChar == '\t')
|
if (e.KeyChar == '\t')
|
||||||
{
|
{
|
||||||
@@ -148,7 +148,7 @@ namespace OpenRA.Widgets
|
|||||||
return DoBuildingHotkey(Char.ToLowerInvariant(e.KeyChar), Game.world);
|
return DoBuildingHotkey(Char.ToLowerInvariant(e.KeyChar), Game.world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event != MouseInputEvent.Down)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
return false;
|
return false;
|
||||||
@@ -223,7 +223,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
var firstOfThis = queue.AllItems(queueName).FirstOrDefault(a => a.Item == item.Name);
|
var firstOfThis = queue.AllItems(queueName).FirstOrDefault(a => a.Item == item.Name);
|
||||||
|
|
||||||
if (rect.Contains(Game.chrome.lastMousePos.ToPoint()))
|
if (rect.Contains(Widget.lastMousePos.ToPoint()))
|
||||||
tooltipItem = item.Name;
|
tooltipItem = item.Name;
|
||||||
|
|
||||||
var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2);
|
var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2);
|
||||||
@@ -421,7 +421,7 @@ namespace OpenRA.Widgets
|
|||||||
var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight);
|
var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight);
|
||||||
tabs.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(Widget.lastMousePos.ToPoint()))
|
||||||
{
|
{
|
||||||
var text = CategoryNameRemaps.ContainsKey(groupName) ? CategoryNameRemaps[groupName] : groupName;
|
var text = CategoryNameRemaps.ContainsKey(groupName) ? CategoryNameRemaps[groupName] : groupName;
|
||||||
var sz = Game.chrome.renderer.BoldFont.Measure(text);
|
var sz = Game.chrome.renderer.BoldFont.Measure(text);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Widgets
|
|||||||
return base.LoseFocus(mi);
|
return base.LoseFocus(mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ namespace OpenRA.Widgets
|
|||||||
return composing ? false : base.LoseFocus(mi);
|
return composing ? false : base.LoseFocus(mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi) { return false; }
|
public override bool HandleInputInner(MouseInput mi) { return false; }
|
||||||
|
|
||||||
public override bool HandleKeyPress(KeyInput e)
|
public override bool HandleKeyPressInner(KeyInput e)
|
||||||
{
|
{
|
||||||
if (e.KeyChar == '\r')
|
if (e.KeyChar == '\r')
|
||||||
{
|
{
|
||||||
@@ -94,7 +94,7 @@ namespace OpenRA.Widgets
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.HandleKeyPress(e);
|
return base.HandleKeyPressInner(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi) { return true; }
|
public override bool HandleInputInner(MouseInput mi) { return true; }
|
||||||
|
|
||||||
public CheckboxWidget() : base() { }
|
public CheckboxWidget() : base() { }
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace OpenRA.Widgets
|
|||||||
return base.LoseFocus(mi);
|
return base.LoseFocus(mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
2
OpenRA.Game/Widgets/MapPreviewWidget.cs
Executable file → Normal file
2
OpenRA.Game/Widgets/MapPreviewWidget.cs
Executable file → Normal file
@@ -43,7 +43,7 @@ namespace OpenRA.Widgets
|
|||||||
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.TopLeft.X)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.TopLeft.Y)));
|
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.TopLeft.X)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.TopLeft.Y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
var map = Map();
|
var map = Map();
|
||||||
if (map == null)
|
if (map == null)
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Down)
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRA.Widgets
|
|||||||
var image = ChromeProvider.GetImage(Game.chrome.renderer, Image + "-button", GetImage());
|
var image = ChromeProvider.GetImage(Game.chrome.renderer, Image + "-button", GetImage());
|
||||||
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);
|
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);
|
||||||
|
|
||||||
if (rect.Contains(Game.chrome.lastMousePos.ToPoint()))
|
if (rect.Contains(Widget.lastMousePos.ToPoint()))
|
||||||
{
|
{
|
||||||
rect = rect.InflateBy(3, 3, 3, 3);
|
rect = rect.InflateBy(3, 3, 3, 3);
|
||||||
var pos = new int2(rect.Left, rect.Top);
|
var pos = new int2(rect.Left, rect.Top);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Widgets
|
|||||||
return SequenceProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor;
|
return SequenceProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Widgets
|
|||||||
isMoving = other.isMoving;
|
isMoving = other.isMoving;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Widgets
|
|||||||
get { return buttons.Any() ? buttons.Select(b => b.First).Aggregate(Rectangle.Union) : Bounds; }
|
get { return buttons.Any() ? buttons.Select(b => b.First).Aggregate(Rectangle.Union) : Bounds; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Down)
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
@@ -92,7 +92,7 @@ namespace OpenRA.Widgets
|
|||||||
var drawPos = new float2(rectBounds.X + 5, y);
|
var drawPos = new float2(rectBounds.X + 5, y);
|
||||||
var rect = new Rectangle(rectBounds.X + 5, y, 64, 48);
|
var rect = new Rectangle(rectBounds.X + 5, y, 64, 48);
|
||||||
|
|
||||||
if (rect.Contains(Game.chrome.lastMousePos.ToPoint()))
|
if (rect.Contains(Widget.lastMousePos.ToPoint()))
|
||||||
{
|
{
|
||||||
var pos = drawPos.ToInt2();
|
var pos = drawPos.ToInt2();
|
||||||
var tl = new int2(pos.X-3,pos.Y-3);
|
var tl = new int2(pos.X-3,pos.Y-3);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Widgets
|
|||||||
return lose;
|
return lose;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInputInner(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
return false;
|
return false;
|
||||||
@@ -61,7 +61,7 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleKeyPress(KeyInput e)
|
public override bool HandleKeyPressInner(KeyInput e)
|
||||||
{
|
{
|
||||||
// Only take input if we are focused
|
// Only take input if we are focused
|
||||||
if (!Focused)
|
if (!Focused)
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
namespace OpenRA.Widgets
|
namespace OpenRA.Widgets
|
||||||
{
|
{
|
||||||
public abstract class Widget
|
public abstract class Widget : IHandleInput
|
||||||
{
|
{
|
||||||
// Info defined in YAML
|
// Info defined in YAML
|
||||||
public string Id = null;
|
public string Id = null;
|
||||||
@@ -186,7 +187,26 @@ namespace OpenRA.Widgets
|
|||||||
return EventBounds.Contains(pos.ToPoint()) ? GetCursor(pos) : null;
|
return EventBounds.Contains(pos.ToPoint()) ? GetCursor(pos) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool HandleInput(MouseInput mi) { return !ClickThrough; }
|
public virtual bool HandleInputInner(MouseInput mi) { return !ClickThrough; }
|
||||||
|
|
||||||
|
public static int ticksSinceLastMove = 0;
|
||||||
|
public static int2 lastMousePos;
|
||||||
|
public bool HandleInput(World world, MouseInput mi)
|
||||||
|
{
|
||||||
|
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (Widget.RootWidget.HandleMouseInputOuter(mi))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
|
{
|
||||||
|
lastMousePos = mi.Location;
|
||||||
|
ticksSinceLastMove = 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool HandleMouseInputOuter(MouseInput mi)
|
public bool HandleMouseInputOuter(MouseInput mi)
|
||||||
{
|
{
|
||||||
// Are we able to handle this event?
|
// Are we able to handle this event?
|
||||||
@@ -200,7 +220,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
// Do any widgety behavior (button click etc)
|
// Do any widgety behavior (button click etc)
|
||||||
// Return false if it can't handle any user actions
|
// Return false if it can't handle any user actions
|
||||||
if (!HandleInput(mi))
|
if (!HandleInputInner(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Apply any special logic added by delegates; they return true if they caught the input
|
// Apply any special logic added by delegates; they return true if they caught the input
|
||||||
@@ -212,7 +232,7 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual bool HandleKeyPress(KeyInput e) { return false; }
|
public virtual bool HandleKeyPressInner(KeyInput e) { return false; }
|
||||||
public virtual bool HandleKeyPressOuter(KeyInput e)
|
public virtual bool HandleKeyPressOuter(KeyInput e)
|
||||||
{
|
{
|
||||||
if (!IsVisible())
|
if (!IsVisible())
|
||||||
@@ -224,7 +244,7 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Do any widgety behavior (enter text etc)
|
// Do any widgety behavior (enter text etc)
|
||||||
var handled = HandleKeyPress(e);
|
var handled = HandleKeyPressInner(e);
|
||||||
|
|
||||||
// Apply any special logic added by delegates; they return true if they caught the input
|
// Apply any special logic added by delegates; they return true if they caught the input
|
||||||
if (OnKeyPress(e)) return true;
|
if (OnKeyPress(e)) return true;
|
||||||
@@ -232,6 +252,16 @@ namespace OpenRA.Widgets
|
|||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool HandleKeyPress(KeyInput e)
|
||||||
|
{
|
||||||
|
if (SelectedWidget != null)
|
||||||
|
return SelectedWidget.HandleKeyPressOuter(e);
|
||||||
|
|
||||||
|
if (RootWidget.HandleKeyPressOuter(e))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void DrawInner( World world );
|
public abstract void DrawInner( World world );
|
||||||
|
|
||||||
public virtual void Draw(World world)
|
public virtual void Draw(World world)
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null)
|
if (Widget.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var actor = world.FindUnitsAtMouse(Game.chrome.lastMousePos).FirstOrDefault();
|
var actor = world.FindUnitsAtMouse(Widget.lastMousePos).FirstOrDefault();
|
||||||
if (actor == null) return;
|
if (actor == null) return;
|
||||||
|
|
||||||
var text = actor.Info.Traits.Contains<ValuedInfo>()
|
var text = actor.Info.Traits.Contains<ValuedInfo>()
|
||||||
@@ -51,23 +51,23 @@ namespace OpenRA.Widgets
|
|||||||
sz.Y += 24;
|
sz.Y += 24;
|
||||||
|
|
||||||
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
||||||
Game.chrome.lastMousePos.X + 20, Game.chrome.lastMousePos.Y + 20,
|
Widget.lastMousePos.X + 20, Widget.lastMousePos.Y + 20,
|
||||||
Game.chrome.lastMousePos.X + sz.X + 20, Game.chrome.lastMousePos.Y + sz.Y + 20));
|
Widget.lastMousePos.X + sz.X + 20, Widget.lastMousePos.Y + sz.Y + 20));
|
||||||
|
|
||||||
renderer.BoldFont.DrawText(text,
|
renderer.BoldFont.DrawText(text,
|
||||||
new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 30), Color.White);
|
new float2(Widget.lastMousePos.X + 30, Widget.lastMousePos.Y + 30), Color.White);
|
||||||
|
|
||||||
if (text2 != "")
|
if (text2 != "")
|
||||||
{
|
{
|
||||||
renderer.RegularFont.DrawText(text2,
|
renderer.RegularFont.DrawText(text2,
|
||||||
new float2(Game.chrome.lastMousePos.X + 65, Game.chrome.lastMousePos.Y + 50), actor.Owner.Color);
|
new float2(Widget.lastMousePos.X + 65, Widget.lastMousePos.Y + 50), actor.Owner.Color);
|
||||||
|
|
||||||
renderer.RegularFont.DrawText(text3,
|
renderer.RegularFont.DrawText(text3,
|
||||||
new float2(Game.chrome.lastMousePos.X + 65 + sz2.X, Game.chrome.lastMousePos.Y + 50), Color.White);
|
new float2(Widget.lastMousePos.X + 65 + sz2.X, Widget.lastMousePos.Y + 50), Color.White);
|
||||||
|
|
||||||
WidgetUtils.DrawRGBA(
|
WidgetUtils.DrawRGBA(
|
||||||
ChromeProvider.GetImage(Game.chrome.renderer, "flags", actor.Owner.Country.Race),
|
ChromeProvider.GetImage(Game.chrome.renderer, "flags", actor.Owner.Country.Race),
|
||||||
new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 50));
|
new float2(Widget.lastMousePos.X + 30, Widget.lastMousePos.Y + 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.RgbaSpriteRenderer.Flush();
|
renderer.RgbaSpriteRenderer.Flush();
|
||||||
|
|||||||
Reference in New Issue
Block a user