Merge pull request #3607 from pchote/widget-focus
Split keyboard/mouse focus and use C&C world tooltips in RA/D2K.
This commit is contained in:
@@ -215,7 +215,8 @@ namespace OpenRA
|
||||
worldRenderer = new WorldRenderer(orderManager.world);
|
||||
|
||||
if (orderManager.GameStarted) return;
|
||||
Ui.SelectedWidget = null;
|
||||
Ui.MouseFocusWidget = null;
|
||||
Ui.KeyboardFocusWidget = null;
|
||||
|
||||
orderManager.LocalFrameNumber = 0;
|
||||
orderManager.LastTickTime = Environment.TickCount;
|
||||
|
||||
@@ -212,7 +212,6 @@
|
||||
<Compile Include="Widgets\SliderWidget.cs" />
|
||||
<Compile Include="Widgets\TextFieldWidget.cs" />
|
||||
<Compile Include="Widgets\TimerWidget.cs" />
|
||||
<Compile Include="Widgets\ViewportScrollControllerWidget.cs" />
|
||||
<Compile Include="Widgets\VqaPlayerWidget.cs" />
|
||||
<Compile Include="Widgets\Widget.cs" />
|
||||
<Compile Include="Widgets\WidgetLoader.cs" />
|
||||
@@ -237,6 +236,7 @@
|
||||
<Compile Include="Graphics\TextRenderable.cs" />
|
||||
<Compile Include="Graphics\BeamRenderable.cs" />
|
||||
<Compile Include="Graphics\ContrailRenderable.cs" />
|
||||
<Compile Include="Widgets\ViewportControllerWidget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Widgets
|
||||
if (ClickThrough || !Bounds.Contains(mi.Location))
|
||||
return false;
|
||||
|
||||
if (!Draggable || moving && (!TakeFocus(mi) || mi.Button != MouseButton.Left))
|
||||
if (!Draggable || moving && (!TakeMouseFocus(mi) || mi.Button != MouseButton.Left))
|
||||
return true;
|
||||
|
||||
if (prevMouseLocation == null)
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
case MouseInputEvent.Up:
|
||||
moving = false;
|
||||
LoseFocus(mi);
|
||||
YieldMouseFocus(mi);
|
||||
break;
|
||||
case MouseInputEvent.Down:
|
||||
moving = true;
|
||||
|
||||
@@ -83,10 +83,10 @@ namespace OpenRA.Widgets
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
public override bool YieldMouseFocus(MouseInput mi)
|
||||
{
|
||||
Depressed = false;
|
||||
return base.LoseFocus(mi);
|
||||
return base.YieldMouseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
@@ -110,25 +110,25 @@ namespace OpenRA.Widgets
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeMouseFocus(mi))
|
||||
return false;
|
||||
|
||||
var disabled = IsDisabled();
|
||||
if (Focused && mi.Event == MouseInputEvent.Up && mi.MultiTapCount == 2)
|
||||
if (HasMouseFocus && mi.Event == MouseInputEvent.Up && mi.MultiTapCount == 2)
|
||||
{
|
||||
if (!disabled)
|
||||
{
|
||||
OnDoubleClick();
|
||||
return LoseFocus(mi);
|
||||
return YieldMouseFocus(mi);
|
||||
}
|
||||
}
|
||||
// Only fire the onMouseUp event if we successfully lost focus, and were pressed
|
||||
else if (Focused && mi.Event == MouseInputEvent.Up)
|
||||
else if (HasMouseFocus && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (Depressed && !disabled)
|
||||
OnMouseUp(mi);
|
||||
|
||||
return LoseFocus(mi);
|
||||
return YieldMouseFocus(mi);
|
||||
}
|
||||
if (mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
@@ -141,11 +141,11 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
else
|
||||
{
|
||||
LoseFocus(mi);
|
||||
YieldMouseFocus(mi);
|
||||
Sound.PlayNotification(null, "Sounds", "ClickDisabledSound", null);
|
||||
}
|
||||
}
|
||||
else if (mi.Event == MouseInputEvent.Move && Focused)
|
||||
else if (mi.Event == MouseInputEvent.Move && HasMouseFocus)
|
||||
Depressed = RenderBounds.Contains(mi.Location);
|
||||
|
||||
return Depressed;
|
||||
|
||||
@@ -64,12 +64,12 @@ namespace OpenRA.Widgets
|
||||
orderManager.IssueOrder(Order.Chat(teamChat, content));
|
||||
content = "";
|
||||
|
||||
LoseFocus();
|
||||
YieldKeyboardFocus();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TakeFocus(new MouseInput());
|
||||
TakeKeyboardFocus();
|
||||
composing = true;
|
||||
teamChat = (Game.Settings.Game.TeamChatToggle && teamChat)
|
||||
^ e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
composing = false;
|
||||
content = "";
|
||||
LoseFocus();
|
||||
YieldKeyboardFocus();
|
||||
return true;
|
||||
}
|
||||
else if (e.KeyName == "backspace")
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace OpenRA.Widgets
|
||||
ButtonWidget.DrawBackground("button", downButtonRect, downDisabled, DownPressed, downHover, false);
|
||||
|
||||
if (thumbHeight > 0)
|
||||
ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, Focused && thumbHover, thumbHover, false);
|
||||
ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, HasMouseFocus && thumbHover, thumbHover, false);
|
||||
|
||||
var upOffset = !UpPressed || upDisabled ? 4 : 4 + ButtonDepth;
|
||||
var downOffset = !DownPressed || downDisabled ? 4 : 4 + ButtonDepth;
|
||||
@@ -170,10 +170,10 @@ namespace OpenRA.Widgets
|
||||
if (DownPressed) Scroll(-1);
|
||||
}
|
||||
|
||||
public override bool LoseFocus (MouseInput mi)
|
||||
public override bool YieldMouseFocus(MouseInput mi)
|
||||
{
|
||||
UpPressed = DownPressed = ThumbPressed = false;
|
||||
return base.LoseFocus(mi);
|
||||
return base.YieldMouseFocus(mi);
|
||||
}
|
||||
|
||||
int2 lastMouseLocation;
|
||||
@@ -194,14 +194,14 @@ namespace OpenRA.Widgets
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeMouseFocus(mi))
|
||||
return false;
|
||||
|
||||
if (!Focused)
|
||||
if (!HasMouseFocus)
|
||||
return false;
|
||||
|
||||
if (Focused && mi.Event == MouseInputEvent.Up)
|
||||
return LoseFocus(mi);
|
||||
if (HasMouseFocus && mi.Event == MouseInputEvent.Up)
|
||||
return YieldMouseFocus(mi);
|
||||
|
||||
if (ThumbPressed && mi.Event == MouseInputEvent.Move)
|
||||
{
|
||||
|
||||
@@ -56,14 +56,14 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
if (mi.Button != MouseButton.Left) return false;
|
||||
if (IsDisabled()) return false;
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi)) return false;
|
||||
if (!Focused) return false;
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeMouseFocus(mi)) return false;
|
||||
if (!HasMouseFocus) return false;
|
||||
|
||||
switch(mi.Event)
|
||||
{
|
||||
case MouseInputEvent.Up:
|
||||
isMoving = false;
|
||||
LoseFocus(mi);
|
||||
YieldMouseFocus(mi);
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Down:
|
||||
|
||||
@@ -52,11 +52,10 @@ namespace OpenRA.Widgets
|
||||
VisualHeight = widget.VisualHeight;
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
public override bool YieldKeyboardFocus()
|
||||
{
|
||||
OnLoseFocus();
|
||||
var lose = base.LoseFocus(mi);
|
||||
return lose;
|
||||
return base.YieldKeyboardFocus();
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
@@ -64,14 +63,11 @@ namespace OpenRA.Widgets
|
||||
if (IsDisabled())
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
if (mi.Event != MouseInputEvent.Down)
|
||||
return false;
|
||||
|
||||
// Lose focus if they click outside the box; return false so the next widget can grab this event
|
||||
if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location) && LoseFocus(mi))
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
// Attempt to take keyboard focus
|
||||
if (!RenderBounds.Contains(mi.Location) || !TakeKeyboardFocus())
|
||||
return false;
|
||||
|
||||
blinkCycle = 10;
|
||||
@@ -89,7 +85,7 @@ namespace OpenRA.Widgets
|
||||
var textSize = font.Measure(apparentText);
|
||||
|
||||
var start = RenderOrigin.X + LeftMargin;
|
||||
if (textSize.X > Bounds.Width - LeftMargin - RightMargin && Focused)
|
||||
if (textSize.X > Bounds.Width - LeftMargin - RightMargin && HasKeyboardFocus)
|
||||
start += Bounds.Width - LeftMargin - RightMargin - textSize.X;
|
||||
|
||||
int minIndex = -1;
|
||||
@@ -107,13 +103,11 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (IsDisabled())
|
||||
if (IsDisabled() || e.Event == KeyInputEvent.Up)
|
||||
return false;
|
||||
|
||||
if (e.Event == KeyInputEvent.Up) return false;
|
||||
|
||||
// Only take input if we are focused
|
||||
if (!Focused)
|
||||
if (!HasKeyboardFocus)
|
||||
return false;
|
||||
|
||||
if ((e.KeyName == "return" || e.KeyName == "enter") && OnEnterKey())
|
||||
@@ -206,7 +200,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
var disabled = IsDisabled();
|
||||
var state = disabled ? "textfield-disabled" :
|
||||
Focused ? "textfield-focused" :
|
||||
HasKeyboardFocus ? "textfield-focused" :
|
||||
Ui.MouseOverWidget == this ? "textfield-hover" :
|
||||
"textfield";
|
||||
|
||||
@@ -219,7 +213,7 @@ namespace OpenRA.Widgets
|
||||
// Right align when editing and scissor when the text overflows
|
||||
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
|
||||
{
|
||||
if (Focused)
|
||||
if (HasKeyboardFocus)
|
||||
textPos += new int2(Bounds.Width - LeftMargin - RightMargin - textSize.X, 0);
|
||||
|
||||
Game.Renderer.EnableScissor(pos.X + LeftMargin, pos.Y,
|
||||
@@ -229,7 +223,7 @@ namespace OpenRA.Widgets
|
||||
var color = disabled ? DisabledColor : TextColor;
|
||||
font.DrawText(apparentText, textPos, color);
|
||||
|
||||
if (showCursor && Focused)
|
||||
if (showCursor && HasKeyboardFocus)
|
||||
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White);
|
||||
|
||||
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
|
||||
|
||||
200
OpenRA.Game/Widgets/ViewportControllerWidget.cs
Executable file
200
OpenRA.Game/Widgets/ViewportControllerWidget.cs
Executable file
@@ -0,0 +1,200 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public enum WorldTooltipType { None, Unexplored, Actor }
|
||||
|
||||
public class ViewportControllerWidget : Widget
|
||||
{
|
||||
public readonly string TooltipTemplate = "WORLD_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public WorldTooltipType TooltipType { get; private set; }
|
||||
public IToolTip ActorTooltip { get; private set; }
|
||||
|
||||
public int EdgeScrollThreshold = 15;
|
||||
public int EdgeCornerScrollThreshold = 35;
|
||||
|
||||
static readonly Dictionary<ScrollDirection, string> ScrollCursors = new Dictionary<ScrollDirection, string>
|
||||
{
|
||||
{ ScrollDirection.Up | ScrollDirection.Left, "scroll-tl" },
|
||||
{ ScrollDirection.Up | ScrollDirection.Right, "scroll-tr" },
|
||||
{ ScrollDirection.Down | ScrollDirection.Left, "scroll-bl" },
|
||||
{ ScrollDirection.Down | ScrollDirection.Right, "scroll-br" },
|
||||
{ ScrollDirection.Up, "scroll-t" },
|
||||
{ ScrollDirection.Down, "scroll-b" },
|
||||
{ ScrollDirection.Left, "scroll-l" },
|
||||
{ ScrollDirection.Right, "scroll-r" },
|
||||
};
|
||||
|
||||
static readonly Dictionary<ScrollDirection, float2> ScrollOffsets = new Dictionary<ScrollDirection, float2>
|
||||
{
|
||||
{ ScrollDirection.Up, new float2(0, -1) },
|
||||
{ ScrollDirection.Down, new float2(0, 1) },
|
||||
{ ScrollDirection.Left, new float2(-1, 0) },
|
||||
{ ScrollDirection.Right, new float2(1, 0) },
|
||||
};
|
||||
|
||||
ScrollDirection keyboardDirections;
|
||||
ScrollDirection edgeDirections;
|
||||
World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ViewportControllerWidget(World world, WorldRenderer worldRenderer)
|
||||
: base()
|
||||
{
|
||||
this.world = world;
|
||||
tooltipContainer = Lazy.New(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||
new WidgetArgs() {{ "world", world }, { "viewport", this }});
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
UpdateMouseover();
|
||||
base.Draw();
|
||||
}
|
||||
|
||||
public void UpdateMouseover()
|
||||
{
|
||||
TooltipType = WorldTooltipType.None;
|
||||
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
if (!world.Map.IsInMap(cell))
|
||||
return;
|
||||
|
||||
if (world.ShroudObscures(cell))
|
||||
{
|
||||
TooltipType = WorldTooltipType.Unexplored;
|
||||
return;
|
||||
}
|
||||
|
||||
var actor = world.FindUnitsAtMouse(Viewport.LastMousePos).FirstOrDefault();
|
||||
if (actor == null)
|
||||
return;
|
||||
|
||||
ActorTooltip = actor.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||
if (ActorTooltip != null)
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
}
|
||||
|
||||
public static string GetScrollCursor(Widget w, ScrollDirection edge, int2 pos)
|
||||
{
|
||||
if (!Game.Settings.Game.ViewportEdgeScroll || Ui.MouseOverWidget != w)
|
||||
return null;
|
||||
|
||||
var blockedDirections = Game.viewport.GetBlockedDirections();
|
||||
foreach (var dir in ScrollCursors)
|
||||
if (edge.Includes(dir.Key))
|
||||
return dir.Value + (blockedDirections.Includes(dir.Key) ? "-blocked" : "");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
var scrolltype = Game.Settings.Game.MouseScroll;
|
||||
if (scrolltype == MouseScrollType.Disabled)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Move &&
|
||||
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
|
||||
{
|
||||
var d = scrolltype == MouseScrollType.Inverted ? -1 : 1;
|
||||
Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * d);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos) { return GetScrollCursor(this, edgeDirections, pos); }
|
||||
|
||||
public override bool YieldKeyboardFocus()
|
||||
{
|
||||
keyboardDirections = ScrollDirection.None;
|
||||
return base.YieldKeyboardFocus();
|
||||
}
|
||||
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
switch (e.KeyName)
|
||||
{
|
||||
case "up": keyboardDirections = keyboardDirections.Set(ScrollDirection.Up, e.Event == KeyInputEvent.Down); return true;
|
||||
case "down": keyboardDirections = keyboardDirections.Set(ScrollDirection.Down, e.Event == KeyInputEvent.Down); return true;
|
||||
case "left": keyboardDirections = keyboardDirections.Set(ScrollDirection.Left, e.Event == KeyInputEvent.Down); return true;
|
||||
case "right": keyboardDirections = keyboardDirections.Set(ScrollDirection.Right, e.Event == KeyInputEvent.Down); return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
edgeDirections = ScrollDirection.None;
|
||||
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
|
||||
edgeDirections = CheckForDirections();
|
||||
|
||||
if (keyboardDirections != ScrollDirection.None || edgeDirections != ScrollDirection.None)
|
||||
{
|
||||
var scroll = float2.Zero;
|
||||
|
||||
foreach (var kv in ScrollOffsets)
|
||||
if (keyboardDirections.Includes(kv.Key) || edgeDirections.Includes(kv.Key))
|
||||
scroll += kv.Value;
|
||||
|
||||
var length = Math.Max(1, scroll.Length);
|
||||
scroll *= (1f / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
|
||||
Game.viewport.Scroll(scroll);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollDirection CheckForDirections()
|
||||
{
|
||||
var directions = ScrollDirection.None;
|
||||
if (Viewport.LastMousePos.X < EdgeScrollThreshold)
|
||||
directions |= ScrollDirection.Left;
|
||||
if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
|
||||
directions |= ScrollDirection.Up;
|
||||
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
|
||||
directions |= ScrollDirection.Right;
|
||||
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
|
||||
directions |= ScrollDirection.Down;
|
||||
|
||||
return directions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class ViewportScrollControllerWidget : Widget
|
||||
{
|
||||
public int EdgeScrollThreshold = 15;
|
||||
public int EdgeCornerScrollThreshold = 35;
|
||||
|
||||
ScrollDirection Keyboard;
|
||||
ScrollDirection Edge;
|
||||
|
||||
public ViewportScrollControllerWidget() : base() { }
|
||||
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget)
|
||||
: base(widget) { }
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
var scrolltype = Game.Settings.Game.MouseScroll;
|
||||
if (scrolltype == MouseScrollType.Disabled)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Move &&
|
||||
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
|
||||
{
|
||||
var d = scrolltype == MouseScrollType.Inverted ? -1 : 1;
|
||||
Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * d);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static readonly Dictionary<ScrollDirection, string> directions = new Dictionary<ScrollDirection, string>
|
||||
{
|
||||
{ ScrollDirection.Up | ScrollDirection.Left, "scroll-tl" },
|
||||
{ ScrollDirection.Up | ScrollDirection.Right, "scroll-tr" },
|
||||
{ ScrollDirection.Down | ScrollDirection.Left, "scroll-bl" },
|
||||
{ ScrollDirection.Down | ScrollDirection.Right, "scroll-br" },
|
||||
|
||||
{ ScrollDirection.Up, "scroll-t" },
|
||||
{ ScrollDirection.Down, "scroll-b" },
|
||||
{ ScrollDirection.Left, "scroll-l" },
|
||||
{ ScrollDirection.Right, "scroll-r" },
|
||||
};
|
||||
|
||||
public static string GetScrollCursor(Widget w, ScrollDirection edge, int2 pos)
|
||||
{
|
||||
if (!Game.Settings.Game.ViewportEdgeScroll || Ui.MouseOverWidget != w)
|
||||
return null;
|
||||
|
||||
var blockedDirections = Game.viewport.GetBlockedDirections();
|
||||
|
||||
foreach (var dir in directions)
|
||||
if (edge.Includes(dir.Key))
|
||||
return dir.Value + (blockedDirections.Includes(dir.Key) ? "-blocked" : "");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos) { return GetScrollCursor(this, Edge, pos); }
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
Keyboard = ScrollDirection.None;
|
||||
return base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
switch (e.KeyName)
|
||||
{
|
||||
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, e.Event == KeyInputEvent.Down); return true;
|
||||
case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, e.Event == KeyInputEvent.Down); return true;
|
||||
case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, e.Event == KeyInputEvent.Down); return true;
|
||||
case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, e.Event == KeyInputEvent.Down); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
Edge = ScrollDirection.None;
|
||||
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
|
||||
{
|
||||
Edge = CheckForDirections();
|
||||
}
|
||||
Scroll();
|
||||
}
|
||||
|
||||
ScrollDirection CheckForDirections()
|
||||
{
|
||||
// First let's check if the mouse is on the corners:
|
||||
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeCornerScrollThreshold &&
|
||||
Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeCornerScrollThreshold) //Bottom Right
|
||||
{
|
||||
return ScrollDirection.Right | ScrollDirection.Down;
|
||||
}
|
||||
else if (Viewport.LastMousePos.X < EdgeCornerScrollThreshold &&
|
||||
Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeCornerScrollThreshold) //Bottom Left
|
||||
{
|
||||
return ScrollDirection.Down | ScrollDirection.Left;
|
||||
}
|
||||
|
||||
else if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeCornerScrollThreshold &&
|
||||
Viewport.LastMousePos.Y < EdgeCornerScrollThreshold) //Top Right
|
||||
{
|
||||
return ScrollDirection.Right | ScrollDirection.Up;
|
||||
}
|
||||
|
||||
else if (Viewport.LastMousePos.X < EdgeCornerScrollThreshold &&
|
||||
Viewport.LastMousePos.Y < EdgeCornerScrollThreshold) //Top Left
|
||||
{
|
||||
return ScrollDirection.Left | ScrollDirection.Up;
|
||||
}
|
||||
|
||||
//Check for corner ends here now let's check the edges:
|
||||
|
||||
// Check for edge-scroll
|
||||
if (Viewport.LastMousePos.X < EdgeScrollThreshold)
|
||||
return ScrollDirection.Left;
|
||||
if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
|
||||
return ScrollDirection.Up;
|
||||
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
|
||||
return ScrollDirection.Right;
|
||||
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
|
||||
return ScrollDirection.Down;
|
||||
|
||||
|
||||
//Check for edge-scroll ends here.If none of above then return none.
|
||||
return ScrollDirection.None;
|
||||
}
|
||||
|
||||
|
||||
void Scroll()
|
||||
{
|
||||
if (Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
|
||||
{
|
||||
var scroll = new float2(0, 0);
|
||||
|
||||
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
|
||||
scroll += new float2(0, -1);
|
||||
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
|
||||
scroll += new float2(1, 0);
|
||||
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
|
||||
scroll += new float2(0, 1);
|
||||
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
|
||||
scroll += new float2(-1, 0);
|
||||
|
||||
float length = Math.Max(1, scroll.Length);
|
||||
scroll.X = (scroll.X / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
scroll.Y = (scroll.Y / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
|
||||
Game.viewport.Scroll(scroll);
|
||||
}
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ViewportScrollControllerWidget(this); }
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
static Stack<Widget> WindowList = new Stack<Widget>();
|
||||
|
||||
public static Widget SelectedWidget;
|
||||
public static Widget MouseFocusWidget;
|
||||
public static Widget KeyboardFocusWidget;
|
||||
public static Widget MouseOverWidget;
|
||||
|
||||
public static void CloseWindow()
|
||||
@@ -74,7 +75,7 @@ namespace OpenRA.Widgets
|
||||
MouseOverWidget = null;
|
||||
|
||||
bool handled = false;
|
||||
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
|
||||
if (MouseFocusWidget != null && MouseFocusWidget.HandleMouseInputOuter(mi))
|
||||
handled = true;
|
||||
|
||||
if (!handled && Root.HandleMouseInputOuter(mi))
|
||||
@@ -100,8 +101,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
public static bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (SelectedWidget != null)
|
||||
return SelectedWidget.HandleKeyPressOuter(e);
|
||||
if (KeyboardFocusWidget != null)
|
||||
return KeyboardFocusWidget.HandleKeyPressOuter(e);
|
||||
|
||||
if (Root.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
@@ -234,31 +235,46 @@ namespace OpenRA.Widgets
|
||||
.Aggregate(EventBounds, Rectangle.Union);
|
||||
}
|
||||
|
||||
public bool Focused { get { return Ui.SelectedWidget == this; } }
|
||||
public bool HasMouseFocus { get { return Ui.MouseFocusWidget == this; } }
|
||||
public bool HasKeyboardFocus { get { return Ui.KeyboardFocusWidget == this; } }
|
||||
|
||||
public virtual bool TakeFocus(MouseInput mi)
|
||||
public virtual bool TakeMouseFocus(MouseInput mi)
|
||||
{
|
||||
if (Focused)
|
||||
if (HasMouseFocus)
|
||||
return true;
|
||||
|
||||
if (Ui.SelectedWidget != null && !Ui.SelectedWidget.LoseFocus(mi))
|
||||
if (Ui.MouseFocusWidget != null && !Ui.MouseFocusWidget.YieldMouseFocus(mi))
|
||||
return false;
|
||||
|
||||
Ui.SelectedWidget = this;
|
||||
Ui.MouseFocusWidget = this;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove focus from this widget; return false if you don't want to give it up
|
||||
public virtual bool LoseFocus(MouseInput mi)
|
||||
public virtual bool YieldMouseFocus(MouseInput mi)
|
||||
{
|
||||
// Some widgets may need to override focus depending on mouse click
|
||||
return LoseFocus();
|
||||
if (Ui.MouseFocusWidget == this)
|
||||
Ui.MouseFocusWidget = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool LoseFocus()
|
||||
public virtual bool TakeKeyboardFocus()
|
||||
{
|
||||
if (Ui.SelectedWidget == this)
|
||||
Ui.SelectedWidget = null;
|
||||
if (HasKeyboardFocus)
|
||||
return true;
|
||||
|
||||
if (Ui.KeyboardFocusWidget != null && !Ui.KeyboardFocusWidget.YieldKeyboardFocus())
|
||||
return false;
|
||||
|
||||
Ui.KeyboardFocusWidget = this;
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool YieldKeyboardFocus()
|
||||
{
|
||||
if (Ui.KeyboardFocusWidget == this)
|
||||
Ui.KeyboardFocusWidget = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -288,7 +304,7 @@ namespace OpenRA.Widgets
|
||||
public bool HandleMouseInputOuter(MouseInput mi)
|
||||
{
|
||||
// Are we able to handle this event?
|
||||
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location))))
|
||||
if (!(HasMouseFocus || (IsVisible() && GetEventBounds().Contains(mi.Location))))
|
||||
return false;
|
||||
|
||||
var oldMouseOver = Ui.MouseOverWidget;
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
if (!TakeFocus(mi))
|
||||
if (!TakeMouseFocus(mi))
|
||||
return false;
|
||||
|
||||
dragStart = dragEnd = xy;
|
||||
@@ -75,13 +75,13 @@ namespace OpenRA.Widgets
|
||||
|
||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (UseClassicMouseStyle && Focused)
|
||||
if (UseClassicMouseStyle && HasMouseFocus)
|
||||
{
|
||||
//order units around
|
||||
if (!HasBox && world.Selection.Actors.Any() && !MultiClick)
|
||||
{
|
||||
ApplyOrders(world, xy, mi);
|
||||
LoseFocus(mi);
|
||||
YieldMouseFocus(mi);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
dragStart = dragEnd = xy;
|
||||
LoseFocus(mi);
|
||||
YieldMouseFocus(mi);
|
||||
}
|
||||
|
||||
if (mi.Button == MouseButton.None && mi.Event == MouseInputEvent.Move)
|
||||
|
||||
@@ -90,7 +90,6 @@
|
||||
<Compile Include="SpawnViceroid.cs" />
|
||||
<Compile Include="TiberiumRefinery.cs" />
|
||||
<Compile Include="Widgets\CncWidgetUtils.cs" />
|
||||
<Compile Include="Widgets\CncWorldInteractionControllerWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncConquestObjectivesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
|
||||
@@ -103,7 +102,6 @@
|
||||
<Compile Include="Widgets\Logic\CncSettingsLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\ProductionPaletteWidget.cs" />
|
||||
<Compile Include="Widgets\ProductionTabsWidget.cs" />
|
||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public enum WorldTooltipType { None, Unexplored, Actor }
|
||||
|
||||
public class CncWorldInteractionControllerWidget : WorldInteractionControllerWidget
|
||||
{
|
||||
public readonly string TooltipTemplate = "WORLD_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public WorldTooltipType TooltipType { get; private set; }
|
||||
public IToolTip ActorTooltip { get; private set; }
|
||||
|
||||
public int EdgeScrollThreshold = 15;
|
||||
ScrollDirection Keyboard;
|
||||
ScrollDirection Edge;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncWorldInteractionControllerWidget(World world, WorldRenderer worldRenderer)
|
||||
: base(world, worldRenderer)
|
||||
{
|
||||
tooltipContainer = Lazy.New(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||
new WidgetArgs() {{ "world", world }, { "wic", this }});
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
UpdateMouseover();
|
||||
base.Draw();
|
||||
}
|
||||
|
||||
public void UpdateMouseover()
|
||||
{
|
||||
TooltipType = WorldTooltipType.None;
|
||||
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
if (!world.Map.IsInMap(cell))
|
||||
return;
|
||||
|
||||
if (world.ShroudObscures(cell))
|
||||
{
|
||||
TooltipType = WorldTooltipType.Unexplored;
|
||||
return;
|
||||
}
|
||||
|
||||
var actor = world.FindUnitsAtMouse(Viewport.LastMousePos).FirstOrDefault();
|
||||
if (actor == null)
|
||||
return;
|
||||
|
||||
ActorTooltip = actor.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||
if (ActorTooltip != null)
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
var scrolltype = Game.Settings.Game.MouseScroll;
|
||||
if (scrolltype != OpenRA.GameRules.MouseScrollType.Disabled && mi.Event == MouseInputEvent.Move &&
|
||||
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
|
||||
{
|
||||
var d = scrolltype == OpenRA.GameRules.MouseScrollType.Inverted ? -1 : 1;
|
||||
Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * d);
|
||||
}
|
||||
|
||||
return base.HandleMouseInput(mi);
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos)
|
||||
{
|
||||
return ViewportScrollControllerWidget.GetScrollCursor(this, Edge, pos)
|
||||
?? base.GetCursor(pos);
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
Keyboard = ScrollDirection.None;
|
||||
return base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
switch (e.KeyName)
|
||||
{
|
||||
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, (e.Event == KeyInputEvent.Down)); return true;
|
||||
case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, (e.Event == KeyInputEvent.Down)); return true;
|
||||
}
|
||||
return base.HandleKeyPress(e);
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
Edge = ScrollDirection.None;
|
||||
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus && Ui.MouseOverWidget == this)
|
||||
{
|
||||
// Check for edge-scroll
|
||||
if (Viewport.LastMousePos.X < EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Left, true);
|
||||
if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Up, true);
|
||||
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Right, true);
|
||||
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
|
||||
Edge = Edge.Set(ScrollDirection.Down, true);
|
||||
}
|
||||
|
||||
if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
|
||||
{
|
||||
var scroll = new float2(0, 0);
|
||||
|
||||
// Modified to use the ViewportEdgeScrollStep setting - Gecko
|
||||
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
|
||||
scroll += new float2(0, -1);
|
||||
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
|
||||
scroll += new float2(1, 0);
|
||||
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
|
||||
scroll += new float2(0, 1);
|
||||
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
|
||||
scroll += new float2(-1, 0);
|
||||
|
||||
float length = Math.Max(1, scroll.Length);
|
||||
scroll.X = (scroll.X / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
scroll.Y = (scroll.Y / length) * Game.Settings.Game.ViewportEdgeScrollStep;
|
||||
|
||||
Game.viewport.Scroll(scroll);
|
||||
}
|
||||
|
||||
base.Tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,10 +208,10 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
if (rightPressed) Scroll(-1);
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
public override bool YieldMouseFocus(MouseInput mi)
|
||||
{
|
||||
leftPressed = rightPressed = false;
|
||||
return base.LoseFocus(mi);
|
||||
return base.YieldMouseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
@@ -231,14 +231,14 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return true;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeMouseFocus(mi))
|
||||
return true;
|
||||
|
||||
if (!Focused)
|
||||
if (!HasMouseFocus)
|
||||
return true;
|
||||
|
||||
if (Focused && mi.Event == MouseInputEvent.Up)
|
||||
return LoseFocus(mi);
|
||||
if (HasMouseFocus && mi.Event == MouseInputEvent.Up)
|
||||
return YieldMouseFocus(mi);
|
||||
|
||||
leftPressed = leftButtonRect.Contains(mi.Location);
|
||||
rightPressed = rightButtonRect.Contains(mi.Location);
|
||||
|
||||
@@ -413,7 +413,6 @@
|
||||
<Compile Include="Widgets\SupportPowerTimerWidget.cs" />
|
||||
<Compile Include="Widgets\SupportPowerBinWidget.cs" />
|
||||
<Compile Include="Widgets\WorldCommandWidget.cs" />
|
||||
<Compile Include="Widgets\WorldTooltipWidget.cs" />
|
||||
<Compile Include="World\ChooseBuildTabOnSelect.cs" />
|
||||
<Compile Include="World\DebugOverlay.cs" />
|
||||
<Compile Include="World\ResourceClaim.cs" />
|
||||
@@ -462,6 +461,7 @@
|
||||
<Compile Include="MPStartUnits.cs" />
|
||||
<Compile Include="Orders\SetChronoTankDestination.cs" />
|
||||
<Compile Include="Effects\FrozenActorProxy.cs" />
|
||||
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -158,8 +158,9 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
// Eat mouse-up events
|
||||
if (mi.Event != MouseInputEvent.Down)
|
||||
return false;
|
||||
return true;
|
||||
|
||||
if (mi.Button == MouseButton.WheelDown)
|
||||
{
|
||||
|
||||
@@ -165,16 +165,16 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeMouseFocus(mi))
|
||||
return false;
|
||||
if (!Focused)
|
||||
if (!HasMouseFocus)
|
||||
return false;
|
||||
|
||||
switch (mi.Event)
|
||||
{
|
||||
case MouseInputEvent.Up:
|
||||
isMoving = false;
|
||||
LoseFocus(mi);
|
||||
YieldMouseFocus(mi);
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Down:
|
||||
|
||||
@@ -104,14 +104,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
ChatText.Text = "";
|
||||
ChatOverlay.Visible = false;
|
||||
ChatChrome.Visible = true;
|
||||
ChatText.TakeFocus(new MouseInput());
|
||||
ChatText.TakeKeyboardFocus();
|
||||
}
|
||||
|
||||
public void CloseChat()
|
||||
{
|
||||
ChatOverlay.Visible = true;
|
||||
ChatChrome.Visible = false;
|
||||
ChatText.LoseFocus();
|
||||
ChatText.YieldKeyboardFocus();
|
||||
}
|
||||
|
||||
public bool IsOpen { get { return ChatChrome.IsVisible(); } }
|
||||
|
||||
@@ -215,23 +215,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
name.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
|
||||
name.Text = c.Name;
|
||||
name.OnEnterKey = () =>
|
||||
name.OnLoseFocus = () =>
|
||||
{
|
||||
name.Text = name.Text.Trim();
|
||||
if (name.Text.Length == 0)
|
||||
name.Text = c.Name;
|
||||
|
||||
name.LoseFocus();
|
||||
if (name.Text == c.Name)
|
||||
return true;
|
||||
return;
|
||||
|
||||
orderManager.IssueOrder(Order.Command("name " + name.Text));
|
||||
Game.Settings.Player.Name = name.Text;
|
||||
Game.Settings.Save();
|
||||
return true;
|
||||
};
|
||||
|
||||
name.OnLoseFocus = () => name.OnEnterKey();
|
||||
name.OnEnterKey = () => { name.YieldKeyboardFocus(); return true; };
|
||||
}
|
||||
|
||||
public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||
|
||||
@@ -43,13 +43,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
name.OnLoseFocus = () =>
|
||||
{
|
||||
name.Text = name.Text.Trim();
|
||||
|
||||
if (name.Text.Length == 0)
|
||||
name.Text = Game.Settings.Player.Name;
|
||||
else
|
||||
Game.Settings.Player.Name = name.Text;
|
||||
};
|
||||
name.OnEnterKey = () => { name.LoseFocus(); return true; };
|
||||
name.OnEnterKey = () => { name.YieldKeyboardFocus(); return true; };
|
||||
|
||||
var edgescrollCheckbox = general.Get<CheckboxWidget>("EDGE_SCROLL");
|
||||
edgescrollCheckbox.IsChecked = () => Game.Settings.Game.ViewportEdgeScroll;
|
||||
@@ -315,7 +314,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
var textBox = keyWidget.Get<TextFieldWidget>("HOTKEY");
|
||||
|
||||
textBox.Text = getValue();
|
||||
|
||||
textBox.OnLoseFocus = () =>
|
||||
{
|
||||
textBox.Text.Trim();
|
||||
@@ -324,8 +322,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
else
|
||||
setValue(textBox.Text);
|
||||
};
|
||||
|
||||
textBox.OnEnterKey = () => { textBox.LoseFocus(); return true; };
|
||||
textBox.OnEnterKey = () => { textBox.YieldKeyboardFocus(); return true; };
|
||||
}
|
||||
|
||||
public static bool ShowRendererDropdown(DropDownButtonWidget dropdown, GraphicSettings s)
|
||||
|
||||
@@ -12,14 +12,14 @@ using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class WorldTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public WorldTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, CncWorldInteractionControllerWidget wic)
|
||||
public WorldTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ViewportControllerWidget viewport)
|
||||
{
|
||||
widget.IsVisible = () => wic.TooltipType != WorldTooltipType.None;
|
||||
widget.IsVisible = () => viewport.TooltipType != WorldTooltipType.None;
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var flag = widget.Get<ImageWidget>("FLAG");
|
||||
var owner = widget.Get<LabelWidget>("OWNER");
|
||||
@@ -32,24 +32,25 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
var flagRace = "";
|
||||
var ownerName = "";
|
||||
var ownerColor = Color.White;
|
||||
var doubleHeight = 45;
|
||||
var singleHeight = 25;
|
||||
|
||||
var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
|
||||
var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;
|
||||
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
if (wic == null || wic.TooltipType == WorldTooltipType.None)
|
||||
if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
|
||||
return;
|
||||
|
||||
labelText = wic.TooltipType == WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
||||
wic.ActorTooltip.Name();
|
||||
labelText = viewport.TooltipType == WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
||||
viewport.ActorTooltip.Name();
|
||||
var textWidth = font.Measure(labelText).X;
|
||||
if (textWidth != cachedWidth)
|
||||
{
|
||||
label.Bounds.Width = textWidth;
|
||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||
}
|
||||
var o = wic.ActorTooltip != null ? wic.ActorTooltip.Owner() : null;
|
||||
showOwner = wic.TooltipType == WorldTooltipType.Actor && o != null && !o.NonCombatant;
|
||||
var o = viewport.ActorTooltip != null ? viewport.ActorTooltip.Owner() : null;
|
||||
showOwner = viewport.TooltipType == WorldTooltipType.Actor && o != null && !o.NonCombatant;
|
||||
|
||||
if (showOwner)
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
ownerColor = o.Color.RGB;
|
||||
widget.Bounds.Height = doubleHeight;
|
||||
widget.Bounds.Width = Math.Max(widget.Bounds.Width,
|
||||
owner.Bounds.X + ownerFont.Measure(ownerName).X + 5);
|
||||
owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X);
|
||||
}
|
||||
else
|
||||
widget.Bounds.Height = singleHeight;
|
||||
@@ -1,94 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class WorldTooltipWidget : Widget
|
||||
{
|
||||
public int TooltipDelay = 10;
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public WorldTooltipWidget(World world) { this.world = world; }
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (Viewport.TicksSinceLastMove < TooltipDelay || world == null)
|
||||
return;
|
||||
|
||||
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
if (!world.Map.IsInMap(cell))
|
||||
return;
|
||||
|
||||
if (world.ShroudObscures(cell))
|
||||
{
|
||||
var utext = "Unexplored Terrain";
|
||||
var usz = Game.Renderer.Fonts["Bold"].Measure(utext) + new int2(20, 24);
|
||||
|
||||
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
||||
Viewport.LastMousePos.X + 20, Viewport.LastMousePos.Y + 20,
|
||||
Viewport.LastMousePos.X + usz.X + 20, Viewport.LastMousePos.Y + usz.Y + 20));
|
||||
|
||||
Game.Renderer.Fonts["Bold"].DrawText(utext,
|
||||
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 30), Color.White);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var actor = world.FindUnitsAtMouse(Viewport.LastMousePos).FirstOrDefault();
|
||||
if (actor == null)
|
||||
return;
|
||||
|
||||
var itt = actor.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||
if (itt == null)
|
||||
return;
|
||||
|
||||
var owner = itt.Owner();
|
||||
var nameText = itt.Name();
|
||||
var ownerText = !owner.NonCombatant ? owner.PlayerName : "";
|
||||
var stanceText = (world.LocalPlayer != null && owner != actor.World.LocalPlayer
|
||||
&& !owner.NonCombatant) ? " ({0})".F(itt.Stance()) : "";
|
||||
|
||||
var nameSize = Game.Renderer.Fonts["Bold"].Measure(nameText);
|
||||
var ownerSize = Game.Renderer.Fonts["Regular"].Measure(ownerText);
|
||||
var stanceSize = Game.Renderer.Fonts["Regular"].Measure(stanceText);
|
||||
var panelSize = new int2(Math.Max(nameSize.X, ownerSize.X + stanceSize.X + 35) + 20, nameSize.Y + 24);
|
||||
|
||||
if (ownerText != "") panelSize.Y += ownerSize.Y + 2;
|
||||
|
||||
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
||||
Viewport.LastMousePos.X + 20, Viewport.LastMousePos.Y + 20,
|
||||
Viewport.LastMousePos.X + panelSize.X + 20, Viewport.LastMousePos.Y + panelSize.Y + 20));
|
||||
|
||||
Game.Renderer.Fonts["Bold"].DrawText(nameText,
|
||||
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 30), Color.White);
|
||||
|
||||
if (ownerText != "")
|
||||
{
|
||||
Game.Renderer.Fonts["Regular"].DrawText(ownerText,
|
||||
new float2(Viewport.LastMousePos.X + 65, Viewport.LastMousePos.Y + 50), actor.Owner.Color.RGB);
|
||||
|
||||
Game.Renderer.Fonts["Regular"].DrawText(stanceText,
|
||||
new float2(Viewport.LastMousePos.X + 65 + ownerSize.X, Viewport.LastMousePos.Y + 50), Color.White);
|
||||
|
||||
WidgetUtils.DrawRGBA(
|
||||
ChromeProvider.GetImage("flags", actor.Owner.Country.Race),
|
||||
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 50));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,10 @@ Container@INGAME_ROOT:
|
||||
Y:WINDOW_BOTTOM-HEIGHT-10
|
||||
Width:200
|
||||
Height:200
|
||||
CncWorldInteractionController@INTERACTION_CONTROLLER:
|
||||
WorldInteractionController@INTERACTION_CONTROLLER:
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
ViewportController:
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
|
||||
@@ -25,8 +25,11 @@ Background@BUTTON_TOOLTIP:
|
||||
Background@WORLD_TOOLTIP:
|
||||
Logic:WorldTooltipLogic
|
||||
Background:panel-black
|
||||
Width:141
|
||||
Children:
|
||||
Container@SINGLE_HEIGHT:
|
||||
Height:25
|
||||
Container@DOUBLE_HEIGHT:
|
||||
Height:45
|
||||
Label@LABEL:
|
||||
X:5
|
||||
Height:23
|
||||
|
||||
@@ -9,6 +9,30 @@ Background@SIMPLE_TOOLTIP:
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@WORLD_TOOLTIP:
|
||||
Logic:WorldTooltipLogic
|
||||
Background:dialog3
|
||||
Children:
|
||||
Container@SINGLE_HEIGHT:
|
||||
Height:31
|
||||
Container@DOUBLE_HEIGHT:
|
||||
Height:56
|
||||
Label@LABEL:
|
||||
X:7
|
||||
Y:2
|
||||
Height:23
|
||||
Font:Bold
|
||||
Image@FLAG:
|
||||
X:7
|
||||
Y:27
|
||||
Width:23
|
||||
Height:23
|
||||
Label@OWNER:
|
||||
X:35
|
||||
Y:25
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic:SpawnSelectorTooltipLogic
|
||||
Background:dialog3
|
||||
|
||||
@@ -6,11 +6,12 @@ Container@INGAME_ROOT:
|
||||
Y:0
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
ViewportScrollController:
|
||||
ViewportController:
|
||||
X:0
|
||||
Y:0
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
WorldCommand:
|
||||
X:0
|
||||
Y:0
|
||||
@@ -31,7 +32,6 @@ Container@INGAME_ROOT:
|
||||
Text:Options (ESC)
|
||||
Font:Bold
|
||||
Key: escape
|
||||
WorldTooltip:
|
||||
Background@PERF_BG:
|
||||
ClickThrough:true
|
||||
Background:dialog4
|
||||
|
||||
@@ -9,6 +9,30 @@ Background@SIMPLE_TOOLTIP:
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@WORLD_TOOLTIP:
|
||||
Logic:WorldTooltipLogic
|
||||
Background:dialog4
|
||||
Children:
|
||||
Container@SINGLE_HEIGHT:
|
||||
Height:29
|
||||
Container@DOUBLE_HEIGHT:
|
||||
Height:50
|
||||
Label@LABEL:
|
||||
X:7
|
||||
Y:2
|
||||
Height:23
|
||||
Font:Bold
|
||||
Image@FLAG:
|
||||
X:7
|
||||
Y:27
|
||||
Width:32
|
||||
Height:16
|
||||
Label@OWNER:
|
||||
X:45
|
||||
Y:22
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic:SpawnSelectorTooltipLogic
|
||||
Background:dialog4
|
||||
|
||||
Reference in New Issue
Block a user