diff --git a/OpenRA.Game/Widgets/ViewportControllerWidget.cs b/OpenRA.Game/Widgets/ViewportControllerWidget.cs index 8df15746ed..0f8801de55 100755 --- a/OpenRA.Game/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportControllerWidget.cs @@ -10,13 +10,25 @@ 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; @@ -42,6 +54,61 @@ namespace OpenRA.Widgets 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 }, { "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 static string GetScrollCursor(Widget w, ScrollDirection edge, int2 pos) { diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 67d44f1880..485b365be9 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -90,7 +90,6 @@ - diff --git a/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs b/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs deleted file mode 100644 index 67e787bc26..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 ViewportControllerWidget.GetScrollCursor(this, Edge, pos) - ?? base.GetCursor(pos); - } - - public override bool YieldKeyboardFocus() - { - Keyboard = ScrollDirection.None; - return base.YieldKeyboardFocus(); - } - - 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/Logic/WorldTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs index 922e081c9f..177572c369 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public class WorldTooltipLogic { [ObjectCreator.UseCtor] - public WorldTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, CncWorldInteractionControllerWidget wic) + public WorldTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ViewportControllerWidget wic) { widget.IsVisible = () => wic.TooltipType != WorldTooltipType.None; var label = widget.Get("LABEL"); 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