diff --git a/OpenRA.FileFormats/Primitives/float2.cs b/OpenRA.FileFormats/Primitives/float2.cs index d535824902..0b030bc3b7 100644 --- a/OpenRA.FileFormats/Primitives/float2.cs +++ b/OpenRA.FileFormats/Primitives/float2.cs @@ -62,7 +62,8 @@ namespace OpenRA Constrain(Y, min.Y, max.Y)); } - public static float2 operator *(float a, float2 b) { return new float2(a * b.X, a * b.Y); } + public static float2 operator *(float a, float2 b) { return new float2(a * b.X, a * b.Y); } + public static float2 operator *(float2 b, float a) { return new float2(a * b.X, a * b.Y); } public static float2 operator *( float2 a, float2 b ) { return new float2( a.X * b.X, a.Y * b.Y ); } public static float2 operator /( float2 a, float2 b ) { return new float2( a.X / b.X, a.Y / b.Y ); } diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 7193c3f270..785e3a997f 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -61,8 +61,8 @@ namespace OpenRA // auto size from render var firstSprite = TraitsImplementing().SelectMany(x => x.Render(this)).FirstOrDefault(); - if (firstSprite.Sprite == null) return float2.Zero; - return firstSprite.Sprite.size; + if (firstSprite.Sprite == null) return float2.Zero; + return firstSprite.Sprite.size * firstSprite.Scale; }); } @@ -110,7 +110,13 @@ namespace OpenRA { var si = Info.Traits.GetOrDefault(); - var size = Size.Value; + var size = Size.Value; + + /* apply scaling */ + var scale = this.TraitOrDefault(); + if (scale != null && scale.Info.Value != 1) + size = size*scale.Info.Value; + var loc = CenterLocation - 0.5f * size; if (si != null && si.Bounds != null && si.Bounds.Length > 2) diff --git a/OpenRA.Game/Graphics/Sprite.cs b/OpenRA.Game/Graphics/Sprite.cs index 0ef880cad7..af568d3959 100644 --- a/OpenRA.Game/Graphics/Sprite.cs +++ b/OpenRA.Game/Graphics/Sprite.cs @@ -60,6 +60,11 @@ namespace OpenRA.Graphics Game.Renderer.SpriteRenderer.DrawSprite( this, location, paletteIndex, this.size ); } + public void DrawAt(float2 location, int paletteIndex, float scale) + { + Game.Renderer.SpriteRenderer.DrawSprite(this, location, paletteIndex, this.size * scale); + } + public void DrawAt( float2 location, int paletteIndex, float2 size ) { Game.Renderer.SpriteRenderer.DrawSprite( this, location, paletteIndex, size ); diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 195886a08e..419f62584e 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -99,10 +99,10 @@ namespace OpenRA.Graphics if (world.OrderGenerator != null) world.OrderGenerator.RenderBeforeWorld(this, world); - - foreach( var image in SpritesToRender() ) - image.Sprite.DrawAt( image.Pos, this.GetPaletteIndex( image.Palette ) ); - uiOverlay.Draw(this, world); + + foreach (var image in SpritesToRender() ) + image.Sprite.DrawAt(image.Pos, this.GetPaletteIndex(image.Palette), image.Scale); + uiOverlay.Draw(this, world); // added for contrails foreach (var a in world.Actors) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 503d4c103f..903659b412 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -222,6 +222,7 @@ + diff --git a/OpenRA.Game/Server/MasterServerQuery.cs b/OpenRA.Game/Server/MasterServerQuery.cs index 812f68e31b..afdfbd3ac7 100755 --- a/OpenRA.Game/Server/MasterServerQuery.cs +++ b/OpenRA.Game/Server/MasterServerQuery.cs @@ -18,7 +18,7 @@ using OpenRA.Widgets; namespace OpenRA.Server { - static class MasterServerQuery + public static class MasterServerQuery { public static event Action OnComplete = _ => { }; public static event Action OnVersion = _ => { }; @@ -114,7 +114,7 @@ namespace OpenRA.Server } } - class GameServer + public class GameServer { public readonly int Id = 0; public readonly string Name = null; diff --git a/OpenRA.Game/Traits/Scale.cs b/OpenRA.Game/Traits/Scale.cs new file mode 100644 index 0000000000..b6d22a0fb4 --- /dev/null +++ b/OpenRA.Game/Traits/Scale.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; + +namespace OpenRA.Traits +{ + public class ScaleInfo : ITraitInfo + { + public readonly float Value = 1f; /* default */ + + public ScaleInfo() { } /* only because we have other ctors */ + + public object Create(ActorInitializer init) { return new Scale(init.self, this); } + } + + public class Scale : IRenderModifier + { + Actor self; + public ScaleInfo Info { get; protected set; } + + public Scale(Actor self, ScaleInfo info) + { + this.Info = info; + this.self = self; + } + + public IEnumerable ModifyRender(Actor self, IEnumerable r) + { + var r2 = new List(r); + var r3 = new List(); + + for (int i = 0; i < r2.Count;i++) + { + var renderable = r2[i]; + + renderable.Scale = Info.Value; + r3.Add(renderable); + // yield return renderable; + } + + return r3; + } + } +} diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 930c4bdfe9..a1bf8600dd 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -145,22 +145,33 @@ namespace OpenRA.Traits public readonly string Palette; public readonly int Z; public readonly int ZOffset; + public float Scale; - public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset) - { - Sprite = sprite; - Pos = pos; - Palette = palette; - Z = z; - ZOffset = zOffset; - } + public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset) + { + Sprite = sprite; + Pos = pos; + Palette = palette; + Z = z; + ZOffset = zOffset; + Scale = 1f; /* default */ + } + public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset, float scale) + { + Sprite = sprite; + Pos = pos; + Palette = palette; + Z = z; + ZOffset = zOffset; + Scale = scale; /* default */ + } public Renderable(Sprite sprite, float2 pos, string palette, int z) : this(sprite, pos, palette, z, 0) { } - public Renderable WithPalette(string newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset); } - public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset); } - public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset); } + public Renderable WithPalette(string newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } + public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); } + public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); } } public interface ITraitInfo { object Create(ActorInitializer init); } diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index adfac5b5bb..b39367255d 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -99,7 +99,13 @@ namespace OpenRA.Traits public static Renderable Centered(Actor self, Sprite s, float2 location) { var pal = self.Owner == null ? "player0" : self.Owner.Palette; - var loc = location - 0.5f * s.size; + var scale = self.TraitOrDefault(); + var scaleModifier = 1f; + if (scale != null) + scaleModifier = scale.Info.Value; + + var loc = location - 0.5f * s.size * scaleModifier; + return new Renderable(s, loc.Round(), pal, (int)self.CenterLocation.Y); } diff --git a/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs b/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs index 23a9c4785d..c6f63affe8 100755 --- a/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs +++ b/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs @@ -6,7 +6,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Orders { - class DeployOrderTargeter : IOrderTargeter + public class DeployOrderTargeter : IOrderTargeter { readonly Func useDeployCursor; diff --git a/OpenRA.Mods.RA/Orders/EnterBuildingOrderTargeter.cs b/OpenRA.Mods.RA/Orders/EnterBuildingOrderTargeter.cs index c61c332f5c..b76691614f 100755 --- a/OpenRA.Mods.RA/Orders/EnterBuildingOrderTargeter.cs +++ b/OpenRA.Mods.RA/Orders/EnterBuildingOrderTargeter.cs @@ -12,7 +12,7 @@ using System; namespace OpenRA.Mods.RA.Orders { - class EnterOrderTargeter : UnitTraitOrderTargeter + public class EnterOrderTargeter : UnitTraitOrderTargeter { readonly Func canTarget; readonly Func useEnterCursor; diff --git a/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs b/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs index f74ef5143a..b03075182d 100755 --- a/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs +++ b/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs @@ -14,7 +14,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Orders { - class UnitOrderTargeter : IOrderTargeter + public class UnitOrderTargeter : IOrderTargeter { readonly string cursor; readonly bool targetEnemyUnits, targetAllyUnits; @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Orders } } - class UnitTraitOrderTargeter : UnitOrderTargeter + public class UnitTraitOrderTargeter : UnitOrderTargeter { public UnitTraitOrderTargeter( string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits ) : base( order, priority, cursor, targetEnemyUnits, targetAllyUnits ) diff --git a/OpenRA.Mods.RA/Passenger.cs b/OpenRA.Mods.RA/Passenger.cs index b91b989353..a72cf07c21 100644 --- a/OpenRA.Mods.RA/Passenger.cs +++ b/OpenRA.Mods.RA/Passenger.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA public object Create( ActorInitializer init ) { return new Passenger( init.self ); } } - class Passenger : IIssueOrder, IResolveOrder, IOrderVoice + public class Passenger : IIssueOrder, IResolveOrder, IOrderVoice { readonly Actor self; public Passenger( Actor self ) { this.self = self; }