From eec751f76a8ace8cf92dc59cf8e4720753091dfa Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 22 Oct 2011 10:25:50 +1300 Subject: [PATCH] remove duplicated edgescroll code in cnc --- .../Widgets/ViewportScrollControllerWidget.cs | 8 ++- .../CncWorldInteractionControllerWidget.cs | 56 +------------------ 2 files changed, 7 insertions(+), 57 deletions(-) diff --git a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs index f9021d1738..fd77966a83 100755 --- a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs @@ -55,20 +55,22 @@ namespace OpenRA.Widgets { ScrollDirection.Right, "scroll-r" }, }; - public override string GetCursor(int2 pos) + public static string GetScrollCursor(Widget w, ScrollDirection edge, int2 pos) { - if (!Game.Settings.Game.ViewportEdgeScroll) + if (!Game.Settings.Game.ViewportEdgeScroll || Widget.MouseOverWidget != w) return null; var blockedDirections = Game.viewport.GetBlockedDirections(); foreach( var dir in directions ) - if (Edge.Includes( dir.Key )) + 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; diff --git a/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs b/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs index 64a97148ff..c10c453614 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs @@ -96,60 +96,8 @@ namespace OpenRA.Mods.Cnc.Widgets public override string GetCursor(int2 pos) { - if (!Game.Settings.Game.ViewportEdgeScroll || Widget.MouseOverWidget != this) - return base.GetCursor(pos); - - if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Left)){ - ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); - if(BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Left)) - return "scroll-tl-blocked"; - else - return "scroll-tl"; - } - if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Right)){ - ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); - if (BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Right)) - return "scroll-tr-blocked"; - else - return "scroll-tr"; - } - if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Left)){ - ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); - if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Left)) - return "scroll-bl-blocked"; - else - return "scroll-bl"; - } - if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Right)){ - ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); - if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Right)) - return "scroll-br-blocked"; - else - return "scroll-br"; - } - - if (Edge.Includes(ScrollDirection.Up)) - if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Up)) - return "scroll-t-blocked"; - else - return "scroll-t"; - if (Edge.Includes(ScrollDirection.Down)) - if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Down)) - return "scroll-b-blocked"; - else - return "scroll-b"; - if (Edge.Includes(ScrollDirection.Left)) - if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Left)) - return "scroll-l-blocked"; - else - return "scroll-l"; - if (Edge.Includes(ScrollDirection.Right)) - if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Right)) - return "scroll-r-blocked"; - else - return "scroll-r"; - - return base.GetCursor(pos); + return ViewportScrollControllerWidget.GetScrollCursor(this, Edge, pos) + ?? base.GetCursor(pos); } public override bool LoseFocus(MouseInput mi)