Remove OnMouseDown from Widget. Define it on just the widgets that want it.
This commit is contained in:
@@ -24,6 +24,8 @@ namespace OpenRA.Widgets
|
|||||||
public string Font = ChromeMetrics.Get<string>("ButtonFont");
|
public string Font = ChromeMetrics.Get<string>("ButtonFont");
|
||||||
public Func<string> GetText;
|
public Func<string> GetText;
|
||||||
public Func<bool> IsDisabled = () => false;
|
public Func<bool> IsDisabled = () => false;
|
||||||
|
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
||||||
|
|
||||||
public Action OnClick = () => {};
|
public Action OnClick = () => {};
|
||||||
public Action<KeyInput> OnKeyPress = _ => {};
|
public Action<KeyInput> OnKeyPress = _ => {};
|
||||||
|
|
||||||
@@ -43,6 +45,8 @@ namespace OpenRA.Widgets
|
|||||||
Depressed = widget.Depressed;
|
Depressed = widget.Depressed;
|
||||||
VisualHeight = widget.VisualHeight;
|
VisualHeight = widget.VisualHeight;
|
||||||
GetText = widget.GetText;
|
GetText = widget.GetText;
|
||||||
|
OnMouseDown = widget.OnMouseDown;
|
||||||
|
|
||||||
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
|
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
|
||||||
OnKeyPress = _ => OnClick();
|
OnKeyPress = _ => OnClick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRA.Widgets
|
|||||||
public class DropDownButtonWidget : ButtonWidget
|
public class DropDownButtonWidget : ButtonWidget
|
||||||
{
|
{
|
||||||
Widget panel;
|
Widget panel;
|
||||||
Widget fullscreenMask;
|
MaskWidget fullscreenMask;
|
||||||
|
|
||||||
public DropDownButtonWidget()
|
public DropDownButtonWidget()
|
||||||
: base()
|
: base()
|
||||||
@@ -75,17 +75,11 @@ namespace OpenRA.Widgets
|
|||||||
panel = p;
|
panel = p;
|
||||||
|
|
||||||
// Mask to prevent any clicks from being sent to other widgets
|
// Mask to prevent any clicks from being sent to other widgets
|
||||||
fullscreenMask = new ContainerWidget();
|
fullscreenMask = new MaskWidget();
|
||||||
fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height);
|
fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height);
|
||||||
|
fullscreenMask.OnMouseDown = mi => RemovePanel();
|
||||||
Widget.RootWidget.AddChild(fullscreenMask);
|
Widget.RootWidget.AddChild(fullscreenMask);
|
||||||
|
|
||||||
fullscreenMask.OnMouseDown = mi =>
|
|
||||||
{
|
|
||||||
RemovePanel();
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
fullscreenMask.OnMouseUp = mi => true;
|
|
||||||
|
|
||||||
var oldBounds = panel.Bounds;
|
var oldBounds = panel.Bounds;
|
||||||
panel.Bounds = new Rectangle(RenderOrigin.X, RenderOrigin.Y + Bounds.Height, oldBounds.Width, oldBounds.Height);
|
panel.Bounds = new Rectangle(RenderOrigin.X, RenderOrigin.Y + Bounds.Height, oldBounds.Width, oldBounds.Height);
|
||||||
Widget.RootWidget.AddChild(panel);
|
Widget.RootWidget.AddChild(panel);
|
||||||
@@ -114,4 +108,30 @@ namespace OpenRA.Widgets
|
|||||||
AttachPanel(panel);
|
AttachPanel(panel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MaskWidget : Widget
|
||||||
|
{
|
||||||
|
public Action<MouseInput> OnMouseDown = _ => {};
|
||||||
|
public MaskWidget() : base() { }
|
||||||
|
public MaskWidget(MaskWidget other)
|
||||||
|
: base(other)
|
||||||
|
{
|
||||||
|
OnMouseDown = other.OnMouseDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandleMouseInput(MouseInput mi)
|
||||||
|
{
|
||||||
|
if (mi.Event != MouseInputEvent.Down && mi.Event != MouseInputEvent.Up)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
|
OnMouseDown(mi);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawInner() { }
|
||||||
|
public override string GetCursor(int2 pos) { return null; }
|
||||||
|
public override Widget Clone() { return new MaskWidget(this); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,8 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
public Func<Map> Map = () => null;
|
public Func<Map> Map = () => null;
|
||||||
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
||||||
|
public Action<MouseInput> OnMouseDown = _ => {};
|
||||||
|
|
||||||
Cache<Map,Bitmap> PreviewCache = new Cache<Map, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
|
Cache<Map,Bitmap> PreviewCache = new Cache<Map, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
|
||||||
|
|
||||||
public MapPreviewWidget() : base() { }
|
public MapPreviewWidget() : base() { }
|
||||||
@@ -32,6 +34,15 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||||
|
|
||||||
|
public override bool HandleMouseInput(MouseInput mi)
|
||||||
|
{
|
||||||
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
OnMouseDown(mi);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public int2 ConvertToPreview(Map map, int2 point)
|
public int2 ConvertToPreview(Map map, int2 point)
|
||||||
{
|
{
|
||||||
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top)));
|
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top)));
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ namespace OpenRA.Widgets
|
|||||||
static Stack<Widget> WindowList = new Stack<Widget>();
|
static Stack<Widget> WindowList = new Stack<Widget>();
|
||||||
|
|
||||||
// Common Funcs that most widgets will want
|
// Common Funcs that most widgets will want
|
||||||
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
|
||||||
public Func<MouseInput, bool> OnMouseUp = mi => false;
|
public Func<MouseInput, bool> OnMouseUp = mi => false;
|
||||||
|
|
||||||
public Func<bool> IsVisible;
|
public Func<bool> IsVisible;
|
||||||
@@ -65,7 +64,6 @@ namespace OpenRA.Widgets
|
|||||||
Bounds = widget.Bounds;
|
Bounds = widget.Bounds;
|
||||||
Parent = widget.Parent;
|
Parent = widget.Parent;
|
||||||
|
|
||||||
OnMouseDown = widget.OnMouseDown;
|
|
||||||
OnMouseUp = widget.OnMouseUp;
|
OnMouseUp = widget.OnMouseUp;
|
||||||
|
|
||||||
IsVisible = widget.IsVisible;
|
IsVisible = widget.IsVisible;
|
||||||
@@ -226,7 +224,6 @@ namespace OpenRA.Widgets
|
|||||||
public virtual bool HandleMouseInput(MouseInput mi)
|
public virtual bool HandleMouseInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
// Apply any special logic added by event handlers; they return true if they caught the input
|
// Apply any special logic added by event handlers; they return true if they caught the input
|
||||||
if (mi.Event == MouseInputEvent.Down && OnMouseDown(mi)) return true;
|
|
||||||
if (mi.Event == MouseInputEvent.Up && OnMouseUp(mi)) return true;
|
if (mi.Event == MouseInputEvent.Up && OnMouseUp(mi)) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
var map = mapPreview.Map();
|
var map = mapPreview.Map();
|
||||||
if (map == null || mi.Button != MouseButton.Left
|
if (map == null || mi.Button != MouseButton.Left
|
||||||
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
var p = map.SpawnPoints
|
var p = map.SpawnPoints
|
||||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i))
|
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i))
|
||||||
@@ -131,8 +131,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p);
|
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p);
|
||||||
if (p == 0 || !owned)
|
if (p == 0 || !owned)
|
||||||
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p)));
|
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p)));
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var mapTitle = lobby.GetWidget<LabelWidget>("MAP_TITLE");
|
var mapTitle = lobby.GetWidget<LabelWidget>("MAP_TITLE");
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
var map = mapPreview.Map();
|
var map = mapPreview.Map();
|
||||||
if (map == null || mi.Button != MouseButton.Left
|
if (map == null || mi.Button != MouseButton.Left
|
||||||
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
var p = map.SpawnPoints
|
var p = map.SpawnPoints
|
||||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i))
|
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i))
|
||||||
@@ -76,8 +76,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p);
|
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p);
|
||||||
if (p == 0 || !owned)
|
if (p == 0 || !owned)
|
||||||
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p)));
|
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p)));
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mapPreview.SpawnColors = () =>
|
mapPreview.SpawnColors = () =>
|
||||||
|
|||||||
Reference in New Issue
Block a user