diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index c3b0a313d1..d878c4d5ef 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -35,7 +35,8 @@ namespace OpenRA.Graphics public static int TicksSinceLastMove = 0; public static int2 LastMousePos; - public void Scroll(float2 delta){ + public void Scroll(float2 delta) + { this.Scroll(delta, false); } @@ -43,22 +44,29 @@ namespace OpenRA.Graphics { float2 newScrollPosition = scrollPosition + delta; - if(!ignoreBorders){ - float2 topLeftBorder = (Game.CellSize* mapStart).ToFloat2(); - float2 bottomRightBorder = (Game.CellSize* mapEnd).ToFloat2(); - - if(newScrollPosition.Y < topLeftBorder.Y) - newScrollPosition.Y = topLeftBorder.Y; - if(newScrollPosition.X < topLeftBorder.X) - newScrollPosition.X = topLeftBorder.X; - if(newScrollPosition.Y > bottomRightBorder.Y-screenSize.Y) - newScrollPosition.Y = bottomRightBorder.Y-screenSize.Y; - if(newScrollPosition.X > bottomRightBorder.X-screenSize.X) - newScrollPosition.X = bottomRightBorder.X-screenSize.X; - } + if(!ignoreBorders) + newScrollPosition = this.NormalizeScrollPosition(newScrollPosition); + scrollPosition = newScrollPosition; } + private float2 NormalizeScrollPosition(float2 newScrollPosition) + { + float2 topLeftBorder = (Game.CellSize* mapStart).ToFloat2(); + float2 bottomRightBorder = (Game.CellSize* mapEnd).ToFloat2(); + + if(newScrollPosition.Y < topLeftBorder.Y) + newScrollPosition.Y = topLeftBorder.Y; + if(newScrollPosition.X < topLeftBorder.X) + newScrollPosition.X = topLeftBorder.X; + if(newScrollPosition.Y > bottomRightBorder.Y-screenSize.Y) + newScrollPosition.Y = bottomRightBorder.Y-screenSize.Y; + if(newScrollPosition.X > bottomRightBorder.X-screenSize.X) + newScrollPosition.X = bottomRightBorder.X-screenSize.X; + + return newScrollPosition; + } + public ScrollDirection GetBlockedDirections() { int2 topLeftBorder = (Game.CellSize* mapStart); @@ -129,7 +137,7 @@ namespace OpenRA.Graphics public void Center(int2 loc) { - scrollPosition = (Game.CellSize*loc - .5f * new float2(Width, Height)); + scrollPosition = this.NormalizeScrollPosition(Game.CellSize*loc - .5f * new float2(Width, Height)); } public void Center(IEnumerable actors) @@ -140,7 +148,7 @@ namespace OpenRA.Graphics .Select(a => a.CenterLocation) .Aggregate((a, b) => a + b); - scrollPosition = (avgPos - .5f * new float2(Width, Height)); + scrollPosition = this.NormalizeScrollPosition((avgPos - .5f * new float2(Width, Height))); } public Rectangle? ShroudBounds() diff --git a/OpenRA.Game/Traits/World/ScreenShaker.cs b/OpenRA.Game/Traits/World/ScreenShaker.cs index d9f200ed99..2ccf33a4b9 100644 --- a/OpenRA.Game/Traits/World/ScreenShaker.cs +++ b/OpenRA.Game/Traits/World/ScreenShaker.cs @@ -23,7 +23,8 @@ namespace OpenRA.Traits public void Tick (Actor self) { - if(shakeEffects.Any()){ + if(shakeEffects.Any()) + { Game.viewport.Scroll(GetScrollOffset(), true); shakeEffects.RemoveAll(t => t.ExpiryTime == ticks); } diff --git a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs index e56eb36856..07f2f3c7a8 100644 --- a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs @@ -137,17 +137,20 @@ namespace OpenRA.Widgets if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold) Edge = Edge.Set(ScrollDirection.Down, true); } - var scroll = new float2(0,0); - if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up)) - scroll += new float2(0, -10); - if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right)) - scroll += new float2(10, 0); - if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down)) - scroll += new float2(0, 10); - if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left)) - scroll += new float2(-10, 0); + 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, -10); + if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right)) + scroll += new float2(10, 0); + if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down)) + scroll += new float2(0, 10); + if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left)) + scroll += new float2(-10, 0); - Game.viewport.Scroll(scroll); + Game.viewport.Scroll(scroll); + } } public override Widget Clone() { return new ViewportScrollControllerWidget(this); }