Merge branch 'master' of github.com:beedee/OpenRA

Conflicts:
	OpenRa.Game/Sidebar.cs
This commit is contained in:
Matthew Bowra-Dean
2009-10-08 01:53:03 +13:00
20 changed files with 633 additions and 720 deletions

View File

@@ -6,6 +6,7 @@ using OpenRa.FileFormats;
using System.Windows.Forms;
using OpenRa.Game.Graphics;
using IjwFramework.Types;
namespace OpenRa.Game
{
@@ -13,9 +14,8 @@ namespace OpenRa.Game
{
public readonly Game game;
public abstract float2 RenderLocation { get; }
public Player owner;
public abstract Sprite[] CurrentImages { get; }
public abstract IEnumerable<Pair<Sprite,float2>> CurrentImages { get; }
public virtual void Tick(Game game, int t) { }
protected Actor(Game game)

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using OpenRa.FileFormats;
using System.Linq;
using OpenRa.Game.Graphics;
@@ -23,7 +24,7 @@ namespace OpenRa.Game
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
// temporary, until we remove all the subclasses of Building
public Dictionary<string, Func<int2, Player, Building>> buildingCreation = new Dictionary<string, Func<int2, Player, Building>>();
public Dictionary<string, Func<int2, Player, Building>> buildingCreation;
public Player LocalPlayer { get { return players[localPlayerIndex]; } }
@@ -48,15 +49,13 @@ namespace OpenRa.Game
network = new Network();
buildingCreation.Add("proc", (location, owner) => new Refinery(location, owner, this));
buildingCreation.Add("weap", (location, owner) => new WarFactory(location, owner, this));
var buildings = new[] { "fact", "powr", "apwr", "barr", "atek", "stek", "dome" };
buildingCreation = buildings.ToDictionary(s => s,
s => (Func<int2, Player, Building>)(
(l, o) => new Building(s, l, o, this)));
string[] buildings = { "fact", "powr", "apwr", "barr", "atek", "stek", "dome" };
foreach (string s in buildings)
{
var t = s;
buildingCreation.Add(t, (location, owner) => new Building(t, location, owner, this));
}
buildingCreation.Add("proc", (location, owner) => new Refinery(location, owner, this));
buildingCreation.Add("weap", (location, owner) => new WarFactory(location, owner, this));
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
worldRenderer = new WorldRenderer(renderer, world);

View File

@@ -15,7 +15,7 @@ namespace OpenRa.Game.Graphics
Play( "idle" );
}
public Sprite[] Images { get { return new Sprite[] { currentSequence.GetSprite( frame ) }; } }
public Sprite Image { get { return currentSequence.GetSprite( frame ); } }
public float2 Center { get { return 0.25f * new float2(currentSequence.GetSprite(0).bounds.Size); } }
public void Play( string sequenceName )

View File

@@ -44,7 +44,7 @@ namespace OpenRa.Game.Graphics
{
Button = mi.Button,
Event = mi.Event,
Location = mi.Location - Location
Location = mi.Location - location
});
return mouseHandler != null;
}

View File

@@ -31,17 +31,19 @@ namespace OpenRa.Game.Graphics
foreach (Actor a in world.Actors)
{
Sprite[] images = a.CurrentImages;
float2 loc = a.RenderLocation;
var images = a.CurrentImages;
if (loc.X > rect.Right || loc.X < rect.Left - images[0].bounds.Width)
continue;
foreach( var image in images )
{
var loc = image.Second;
if (loc.Y > rect.Bottom || loc.Y < rect.Top - images[0].bounds.Height)
continue;
if( loc.X > rect.Right || loc.X < rect.Left - image.First.bounds.Width )
continue;
if( loc.Y > rect.Bottom || loc.Y < rect.Top - image.First.bounds.Height )
continue;
foreach (Sprite image in images)
spriteRenderer.DrawSprite(image, loc, (a.owner != null) ? a.owner.Palette : 0);
spriteRenderer.DrawSprite( image.First, loc, ( a.owner != null ) ? a.owner.Palette : 0 );
}
}
spriteRenderer.Flush();

View File

@@ -40,15 +40,18 @@ namespace OpenRa.Game
renderer = new Renderer(this, GetResolution(settings), windowed);
SheetBuilder.Initialize( renderer );
game = new Game( settings.GetValue( "map", "scm12ea.ini" ), renderer, new int2( ClientSize ) );
game = new Game( settings.GetValue( "map", "scg11eb.ini" ), renderer, new int2( ClientSize ) );
SequenceProvider.ForcePrecache();
Unit controlled;
game.world.Add( new Unit( "mcv", new int2( 5, 5 ), game.players[ 3 ], game ) );
game.world.Add( new Unit( "mcv", new int2( 7, 5 ), game.players[ 2 ], game ) );
Unit mcv = new Unit( "mcv", new int2( 9, 5 ), game.players[ 1 ], game );
game.controller.orderGenerator = mcv;
game.world.Add( mcv );
game.world.Add(controlled = new Unit("mcv", new int2(9, 5), game.players[1], game));
game.controller.orderGenerator = controlled;
sidebar = new Sidebar(Race.Soviet, renderer, game);
@@ -83,7 +86,7 @@ namespace OpenRa.Game
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Right)
if (e.Button == MouseButtons.Middle)
{
int2 p = new int2(e.Location);
game.viewport.Scroll(lastPos - p);

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
using OpenRa.Game.Graphics;
using IjwFramework.Types;
namespace OpenRa.Game
{
@@ -17,11 +19,7 @@ namespace OpenRa.Game
this.location = location;
}
public override float2 RenderLocation
{
get { return 24.0f * (float2)location; }
}
public override Sprite[] CurrentImages { get { return animation.Images; } }
public override IEnumerable<Pair<Sprite, float2>> CurrentImages { get { yield return Pair.New( animation.Image, 24 * (float2)location ); } }
}
}

View File

@@ -1,5 +1,7 @@
using OpenRa.Game.Graphics;
using System.Linq;
using System.Collections.Generic;
using IjwFramework.Types;
namespace OpenRa.Game
{
@@ -39,13 +41,14 @@ namespace OpenRa.Game
});
}
public override Sprite[] CurrentImages
public override IEnumerable<Pair<Sprite,float2>> CurrentImages
{
get
{
return (roof == null)
? base.CurrentImages
: (base.CurrentImages.Concat( roof.Images ).ToArray());
: (base.CurrentImages.Concat(
new[] { Pair.New(roof.Image, 24 * (float2)location) }));
}
}

View File

@@ -126,7 +126,7 @@ namespace OpenRa.Game
{
if (kvp.Value != null)
{
clockRenderer.DrawSprite(clockAnimations[kvp.Key].Images[0], region.Location.ToFloat2() + kvp.Value.location, 0);
clockRenderer.DrawSprite(clockAnimations[kvp.Key].Image, region.Location.ToFloat2() + kvp.Value.location, 0);
clockAnimations[kvp.Key].Tick(1);
}
}

View File

@@ -4,6 +4,7 @@ using System.Text;
using OpenRa.FileFormats;
using System.Drawing;
using OpenRa.Game.Graphics;
using IjwFramework.Types;
namespace OpenRa.Game
{
@@ -19,8 +20,13 @@ namespace OpenRa.Game
}
Sprite[] currentImages;
public override Sprite[] CurrentImages { get { return currentImages; } }
public override float2 RenderLocation { get { return 24 * location; } }
public override IEnumerable<Pair<Sprite, float2>> CurrentImages
{
get
{
foreach( var x in currentImages )
yield return Pair.New( x, 24 * (float2)location );
}
}
}
}

View File

@@ -1,5 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.Graphics;
using IjwFramework.Types;
namespace OpenRa.Game
{
@@ -67,14 +71,20 @@ namespace OpenRa.Game
currentOrder( t );
}
public override float2 RenderLocation
public override IEnumerable<Pair<Sprite, float2>> CurrentImages
{
get
{
yield return Centered( animation.Image, CenterLocation );
}
}
public float2 CenterLocation
{
get
{
float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f;
float2 location = 24 * float2.Lerp( fromCell, toCell, fraction );
return ( location - renderOffset ).Round();
return new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction );
}
}
@@ -97,5 +107,34 @@ namespace OpenRa.Game
}
public void PrepareOverlay(Game game, int2 xy) { }
protected static Pair<Sprite, float2> Centered( Sprite s, float2 location )
{
var loc = location - 0.5f * s.size;
return Pair.New( s, loc.Round() );
}
}
class TurretedUnit : Unit
{
Animation turretAnim;
int turretFacing { get { return facing; } }
public TurretedUnit( string name, int2 cell, Player owner, Game game )
: base( name, cell, owner, game )
{
turretAnim = new Animation( name );
turretAnim.PlayFetchIndex( "turret", () => turretFacing );
}
public override IEnumerable<Pair<Sprite, float2>> CurrentImages
{
get
{
foreach( var x in base.CurrentImages )
yield return x;
yield return Centered( turretAnim.Image, CenterLocation );
}
}
}
}