diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs
index bb73cfa2b2..a29a7b9ee3 100644
--- a/OpenRA.Game/Game.cs
+++ b/OpenRA.Game/Game.cs
@@ -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;
diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index 492a7640cc..33fa3179dd 100644
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -212,7 +212,6 @@
-
@@ -237,6 +236,7 @@
+
diff --git a/OpenRA.Game/Widgets/BackgroundWidget.cs b/OpenRA.Game/Widgets/BackgroundWidget.cs
index 936e568c4b..d7e9589437 100644
--- a/OpenRA.Game/Widgets/BackgroundWidget.cs
+++ b/OpenRA.Game/Widgets/BackgroundWidget.cs
@@ -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;
diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs
index 0773bc8534..f80c9958f3 100644
--- a/OpenRA.Game/Widgets/ButtonWidget.cs
+++ b/OpenRA.Game/Widgets/ButtonWidget.cs
@@ -83,10 +83,10 @@ namespace OpenRA.Widgets
Ui.Root.Get(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;
diff --git a/OpenRA.Game/Widgets/ChatEntryWidget.cs b/OpenRA.Game/Widgets/ChatEntryWidget.cs
index b06d82175d..0d1ce7bdf8 100755
--- a/OpenRA.Game/Widgets/ChatEntryWidget.cs
+++ b/OpenRA.Game/Widgets/ChatEntryWidget.cs
@@ -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")
diff --git a/OpenRA.Game/Widgets/ScrollPanelWidget.cs b/OpenRA.Game/Widgets/ScrollPanelWidget.cs
index b88c15b112..4572b18273 100644
--- a/OpenRA.Game/Widgets/ScrollPanelWidget.cs
+++ b/OpenRA.Game/Widgets/ScrollPanelWidget.cs
@@ -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)
{
diff --git a/OpenRA.Game/Widgets/SliderWidget.cs b/OpenRA.Game/Widgets/SliderWidget.cs
index d172914f8f..563785b506 100755
--- a/OpenRA.Game/Widgets/SliderWidget.cs
+++ b/OpenRA.Game/Widgets/SliderWidget.cs
@@ -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:
diff --git a/OpenRA.Game/Widgets/TextFieldWidget.cs b/OpenRA.Game/Widgets/TextFieldWidget.cs
index fcb1cf5a1b..a4cfe4086f 100644
--- a/OpenRA.Game/Widgets/TextFieldWidget.cs
+++ b/OpenRA.Game/Widgets/TextFieldWidget.cs
@@ -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)
diff --git a/OpenRA.Game/Widgets/ViewportControllerWidget.cs b/OpenRA.Game/Widgets/ViewportControllerWidget.cs
new file mode 100755
index 0000000000..23a1a597ca
--- /dev/null
+++ b/OpenRA.Game/Widgets/ViewportControllerWidget.cs
@@ -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 tooltipContainer;
+
+ public WorldTooltipType TooltipType { get; private set; }
+ public IToolTip ActorTooltip { get; private set; }
+
+ public int EdgeScrollThreshold = 15;
+ public int EdgeCornerScrollThreshold = 35;
+
+ static readonly Dictionary ScrollCursors = new Dictionary
+ {
+ { 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 ScrollOffsets = new Dictionary
+ {
+ { 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(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().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;
+ }
+ }
+}
diff --git a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs
deleted file mode 100755
index 86fa5a39b0..0000000000
--- a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs
+++ /dev/null
@@ -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 directions = new Dictionary
- {
- { 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); }
- }
-}
diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs
index 6e3264adf8..0e066ec0e0 100644
--- a/OpenRA.Game/Widgets/Widget.cs
+++ b/OpenRA.Game/Widgets/Widget.cs
@@ -23,7 +23,8 @@ namespace OpenRA.Widgets
static Stack WindowList = new Stack();
- 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;
diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs
index e0689c669d..80d981b50a 100644
--- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs
+++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs
@@ -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)
diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
index 67d44f1880..c76ff2c534 100644
--- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
+++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
@@ -90,7 +90,6 @@
-
@@ -103,7 +102,6 @@
-
diff --git a/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs b/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs
deleted file mode 100644
index 107d1768c5..0000000000
--- a/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs
+++ /dev/null
@@ -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 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(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().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();
- }
- }
-}
\ No newline at end of file
diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs
index d83f3bd5b7..b618409176 100755
--- a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs
+++ b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs
@@ -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);
diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
index c488da4824..bdc1ec10cf 100644
--- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
+++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
@@ -413,7 +413,6 @@
-
@@ -462,6 +461,7 @@
+
diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs
index dfecd5fb36..8b2b49eb94 100755
--- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs
+++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs
@@ -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)
{
diff --git a/OpenRA.Mods.RA/Widgets/ColorMixerWidget.cs b/OpenRA.Mods.RA/Widgets/ColorMixerWidget.cs
index 8d767ca3f1..96e1ac9e50 100755
--- a/OpenRA.Mods.RA/Widgets/ColorMixerWidget.cs
+++ b/OpenRA.Mods.RA/Widgets/ColorMixerWidget.cs
@@ -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:
diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs
index 9dfbf91184..8587827343 100644
--- a/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs
+++ b/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs
@@ -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(); } }
diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs
index 23fe2e70a9..5f1e18ae9a 100644
--- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs
+++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs
@@ -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)
diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs
index d149a2ef6e..17d13e4465 100644
--- a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs
+++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs
@@ -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("EDGE_SCROLL");
edgescrollCheckbox.IsChecked = () => Game.Settings.Game.ViewportEdgeScroll;
@@ -315,7 +314,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var textBox = keyWidget.Get("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)
diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/WorldTooltipLogic.cs
similarity index 69%
rename from OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs
rename to OpenRA.Mods.RA/Widgets/Logic/WorldTooltipLogic.cs
index 922e081c9f..e34eb34ead 100644
--- a/OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs
+++ b/OpenRA.Mods.RA/Widgets/Logic/WorldTooltipLogic.cs
@@ -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("LABEL");
var flag = widget.Get("FLAG");
var owner = widget.Get("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;
diff --git a/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs b/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs
deleted file mode 100755
index f11b638a42..0000000000
--- a/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs
+++ /dev/null
@@ -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().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));
- }
- }
- }
-}
diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml
index 8298ca1156..fea02f8732 100644
--- a/mods/cnc/chrome/ingame.yaml
+++ b/mods/cnc/chrome/ingame.yaml
@@ -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
diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml
index 7393067200..5edbf1862b 100644
--- a/mods/cnc/chrome/tooltips.yaml
+++ b/mods/cnc/chrome/tooltips.yaml
@@ -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
diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml
index 71b8d45f20..8513117197 100644
--- a/mods/d2k/chrome/tooltips.yaml
+++ b/mods/d2k/chrome/tooltips.yaml
@@ -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
diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml
index 52a556b481..8baa8f51a6 100644
--- a/mods/ra/chrome/ingame.yaml
+++ b/mods/ra/chrome/ingame.yaml
@@ -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
diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml
index 8553b7313b..762d84914f 100644
--- a/mods/ra/chrome/tooltips.yaml
+++ b/mods/ra/chrome/tooltips.yaml
@@ -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