Tidy more uses of BottomRight/TopLeft, bogus location of FormatTime.

This commit is contained in:
Paul Chote
2010-11-24 11:37:18 +13:00
parent de8603832f
commit b8eda5a152
8 changed files with 29 additions and 34 deletions

View File

@@ -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);
}

View File

@@ -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]

View File

@@ -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<int2> 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<SelectableInfo>() && a.Info.Traits.Get<SelectableInfo>().Voice != null;

View File

@@ -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);

View File

@@ -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<SpawnMapActors>().Actors;
Sound.SoundVolumeModifier = 0.25f;

View File

@@ -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<BuildingInfo>();
if (bi != null)

View File

@@ -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)
{

View File

@@ -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);