diff --git a/OpenRA.Game/Widgets/TimerWidget.cs b/OpenRA.Game/Widgets/TimerWidget.cs index ac6ef0de9f..a56c8c090a 100644 --- a/OpenRA.Game/Widgets/TimerWidget.cs +++ b/OpenRA.Game/Widgets/TimerWidget.cs @@ -25,7 +25,7 @@ namespace OpenRA.Widgets public override void DrawInner( WorldRenderer wr ) { - var s = WorldUtils.FormatTime(Game.LocalTick); + var s = WidgetUtils.FormatTime(Game.LocalTick); var size = Game.Renderer.TitleFont.Measure(s); Game.Renderer.TitleFont.DrawText(s, new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20), Color.White); } diff --git a/OpenRA.Game/Widgets/WidgetUtils.cs b/OpenRA.Game/Widgets/WidgetUtils.cs index 39337065c9..fa27880549 100644 --- a/OpenRA.Game/Widgets/WidgetUtils.cs +++ b/OpenRA.Game/Widgets/WidgetUtils.cs @@ -128,6 +128,18 @@ namespace OpenRA.Widgets if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom)) DrawRGBA(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y)); } + + + public static string FormatTime(int ticks) + { + var seconds = ticks / 25; + var minutes = seconds / 60; + + if (minutes >= 60) + return "{0:D}:{1:D2}:{2:D2}".F(minutes / 60, minutes % 60, seconds % 60); + else + return "{0:D2}:{1:D2}".F(minutes, seconds % 60); + } } [Flags] diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 16615809a1..4b769a9b6e 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -15,6 +15,7 @@ using OpenRA.FileFormats; using OpenRA.GameRules; using OpenRA.Support; using OpenRA.Traits; +using System; namespace OpenRA { @@ -52,13 +53,8 @@ namespace OpenRA public static IEnumerable FindTilesInCircle(this World world, int2 a, int r) { - var min = a - new int2(r, r); - var max = a + new int2(r, r); - if (min.X < world.Map.Bounds.Left) min.X = world.Map.Bounds.Left; - if (min.Y < world.Map.Bounds.Top) min.Y = world.Map.Bounds.Top; - if (max.X > world.Map.Bounds.Right - 1) max.X = world.Map.Bounds.Right - 1; - if (max.Y > world.Map.Bounds.Bottom - 1) max.Y = world.Map.Bounds.Bottom - 1; - + var min = world.ClampToWorld(a - new int2(r, r)); + var max = world.ClampToWorld(a + new int2(r, r)); for (var j = min.Y; j <= max.Y; j++) for (var i = min.X; i <= max.X; i++) if (r * r >= (new int2(i, j) - a).LengthSquared) @@ -94,7 +90,9 @@ namespace OpenRA public static int2 ClampToWorld( this World world, int2 xy ) { - return int2.Min(world.Map.BottomRight, int2.Max(world.Map.TopLeft, xy)); + var b = world.Map.Bounds; + return new int2(Math.Min(b.Right, Math.Max(xy.X, b.Left)), + Math.Min(b.Bottom, Math.Max(xy.Y, b.Top))); } public static int2 ChooseRandomEdgeCell(this World w) @@ -134,17 +132,6 @@ namespace OpenRA return new float2(Gauss1D(r, samples), Gauss1D(r, samples)); } - public static string FormatTime(int ticks) - { - var seconds = ticks / 25; - var minutes = seconds / 60; - - if (minutes >= 60) - return "{0:D}:{1:D2}:{2:D2}".F(minutes / 60, minutes % 60, seconds % 60); - else - return "{0:D2}:{1:D2}".F(minutes, seconds % 60); - } - public static bool HasVoice(this Actor a) { return a.Info.Traits.Contains() && a.Info.Traits.Get().Voice != null; diff --git a/OpenRA.Mods.RA/BridgeLayer.cs b/OpenRA.Mods.RA/BridgeLayer.cs index 841678cba8..1c630335e1 100644 --- a/OpenRA.Mods.RA/BridgeLayer.cs +++ b/OpenRA.Mods.RA/BridgeLayer.cs @@ -49,11 +49,8 @@ namespace OpenRA.Mods.RA } // Loop through the map looking for templates to overlay - var tl = w.Map.TopLeft; - var br = w.Map.BottomRight; - - for (int i = tl.X; i < br.X; i++) - for (int j = tl.Y; j < br.Y; j++) + for (int i = w.Map.Bounds.Left; i < w.Map.Bounds.Right; i++) + for (int j = w.Map.Bounds.Top; j < w.Map.Bounds.Bottom; j++) if (BridgeTypes.Keys.Contains(w.Map.MapTiles[i, j].type)) ConvertBridgeToActor(w, i, j); diff --git a/OpenRA.Mods.RA/DefaultShellmapScript.cs b/OpenRA.Mods.RA/DefaultShellmapScript.cs index 706de03498..ab9d6be428 100755 --- a/OpenRA.Mods.RA/DefaultShellmapScript.cs +++ b/OpenRA.Mods.RA/DefaultShellmapScript.cs @@ -25,10 +25,9 @@ namespace OpenRA.Mods.RA public void WorldLoaded(World w) { - int2 loc = (.5f * (w.Map.TopLeft + w.Map.BottomRight).ToFloat2()).ToInt2(); - Game.MoveViewport(loc); - - ViewportOrigin = loc; + var b = w.Map.Bounds; + ViewportOrigin = new int2(b.Left + b.Width/2, b.Top + b.Height/2); + Game.MoveViewport(ViewportOrigin); Actors = w.WorldActor.Trait().Actors; Sound.SoundVolumeModifier = 0.25f; diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index 7c8ad2ee4e..9202afbdfe 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -465,7 +465,7 @@ namespace OpenRA.Mods.RA.Widgets var lowpower = power.PowerState != PowerState.Normal; var time = CurrentQueue.GetBuildTime(info.Name) * ((lowpower)? CurrentQueue.Info.LowPowerSlowdown : 1); - DrawRightAligned(WorldUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red: Color.White); + DrawRightAligned(WidgetUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red: Color.White); var bi = info.Traits.GetOrDefault(); if (bi != null) diff --git a/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs b/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs index 3a8e2e3d2b..5bb8de2277 100755 --- a/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs +++ b/OpenRA.Mods.RA/Widgets/SpecialPowerBinWidget.cs @@ -121,8 +121,8 @@ namespace OpenRA.Mods.RA.Widgets Game.Renderer.BoldFont.DrawText(sp.Info.Description, pos, Color.White); pos += new int2(0,20); - Game.Renderer.BoldFont.DrawText(WorldUtils.FormatTime(sp.RemainingTime).ToString(), pos, Color.White); - Game.Renderer.BoldFont.DrawText("/ {0}".F(WorldUtils.FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White); + Game.Renderer.BoldFont.DrawText(WidgetUtils.FormatTime(sp.RemainingTime).ToString(), pos, Color.White); + Game.Renderer.BoldFont.DrawText("/ {0}".F(WidgetUtils.FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White); if (sp.Info.LongDesc != null) { diff --git a/OpenRA.Mods.RA/Widgets/StrategicProgressWidget.cs b/OpenRA.Mods.RA/Widgets/StrategicProgressWidget.cs index 5a5d1981e4..4f8db27ed5 100644 --- a/OpenRA.Mods.RA/Widgets/StrategicProgressWidget.cs +++ b/OpenRA.Mods.RA/Widgets/StrategicProgressWidget.cs @@ -66,12 +66,12 @@ namespace OpenRA.Mods.RA.Widgets { // losing tc = "Strategic defeat in " + - ((svc.CriticalTicksLeft > svc.TicksLeft) ? WorldUtils.FormatTime(svc.CriticalTicksLeft) : WorldUtils.FormatTime(svc.TicksLeft)); + ((svc.CriticalTicksLeft > svc.TicksLeft) ? WidgetUtils.FormatTime(svc.CriticalTicksLeft) : WidgetUtils.FormatTime(svc.TicksLeft)); }else { // winning tc = "Strategic victory in " + - ((svc.CriticalTicksLeft > svc.TicksLeft) ? WorldUtils.FormatTime(svc.CriticalTicksLeft) : WorldUtils.FormatTime(svc.TicksLeft)); + ((svc.CriticalTicksLeft > svc.TicksLeft) ? WidgetUtils.FormatTime(svc.CriticalTicksLeft) : WidgetUtils.FormatTime(svc.TicksLeft)); } var size = Game.Renderer.BoldFont.Measure(tc);