git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1332 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -75,7 +75,14 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
if (e.Button == MouseButtons.Left)
|
if (e.Button == MouseButtons.Left)
|
||||||
{
|
{
|
||||||
float2 xy = ( 1 / 24.0f ) * ( new float2( e.Location ) + game.viewport.Location );
|
float2 point = new float2(e.Location) + game.viewport.Location;
|
||||||
|
RectangleF rect = new RectangleF(sidebar.Location.ToPointF(), new SizeF(sidebar.Width, game.viewport.Height));
|
||||||
|
if (rect.Contains(point.ToPointF()))
|
||||||
|
{
|
||||||
|
sidebar.Build(sidebar.FindSpriteAtPoint(point));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
float2 xy = (1 / 24.0f) * point;
|
||||||
IOrder order = game.world.myUnit.Order( new int2( (int)xy.X, (int)xy.Y ) );
|
IOrder order = game.world.myUnit.Order( new int2( (int)xy.X, (int)xy.Y ) );
|
||||||
game.Issue( order );
|
game.Issue( order );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
||||||
Viewport viewport;
|
Viewport viewport;
|
||||||
|
const float spriteWidth = 64, spriteHeight = 48;
|
||||||
|
|
||||||
|
public float Width
|
||||||
|
{
|
||||||
|
get { return spriteWidth * 2; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Sidebar(Race race, Renderer renderer, Viewport viewport)
|
public Sidebar(Race race, Renderer renderer, Viewport viewport)
|
||||||
{
|
{
|
||||||
@@ -31,7 +38,12 @@ namespace OpenRa.Game
|
|||||||
LoadSprites("buildings.txt");
|
LoadSprites("buildings.txt");
|
||||||
LoadSprites("units.txt");
|
LoadSprites("units.txt");
|
||||||
|
|
||||||
blank = SheetBuilder.Add(new Size(64, 48), 16);
|
blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Build(string key)
|
||||||
|
{
|
||||||
|
return techTree.Build(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSprites(string filename)
|
void LoadSprites(string filename)
|
||||||
@@ -46,7 +58,7 @@ namespace OpenRa.Game
|
|||||||
void DrawSprite(Sprite s, ref float2 p)
|
void DrawSprite(Sprite s, ref float2 p)
|
||||||
{
|
{
|
||||||
spriteRenderer.DrawSprite(s, p, 0);
|
spriteRenderer.DrawSprite(s, p, 0);
|
||||||
p.Y += 48;
|
p.Y += spriteHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fill(float height, float2 p)
|
void Fill(float height, float2 p)
|
||||||
@@ -55,10 +67,17 @@ namespace OpenRa.Game
|
|||||||
DrawSprite(blank, ref p);
|
DrawSprite(blank, ref p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float2 location;
|
||||||
|
|
||||||
|
public float2 Location
|
||||||
|
{
|
||||||
|
get { return location; }
|
||||||
|
}
|
||||||
|
|
||||||
public void Paint( Game game )
|
public void Paint( Game game )
|
||||||
{
|
{
|
||||||
float2 buildPos = viewport.Location + new float2(viewport.Size.X - 128, 0);
|
float2 buildPos = location = viewport.Location + new float2(viewport.Size.X - spriteWidth * 2, 0);
|
||||||
float2 unitPos = viewport.Location + new float2(viewport.Size.X - 64, 0);
|
float2 unitPos = viewport.Location + new float2(viewport.Size.X - spriteWidth, 0);
|
||||||
|
|
||||||
foreach (Item i in techTree.BuildableItems)
|
foreach (Item i in techTree.BuildableItems)
|
||||||
{
|
{
|
||||||
@@ -76,5 +95,26 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string FindSpriteAtPoint(float2 point)
|
||||||
|
{
|
||||||
|
float y1 = 0, y2 = 0;
|
||||||
|
foreach (Item i in techTree.BuildableItems)
|
||||||
|
{
|
||||||
|
RectangleF rect;
|
||||||
|
if (i.IsStructure)
|
||||||
|
{
|
||||||
|
rect = new RectangleF(location.X, location.Y + y1, spriteWidth, spriteHeight);
|
||||||
|
y1 += 48;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rect = new RectangleF(location.X + spriteWidth, location.Y + y2, spriteWidth, spriteHeight);
|
||||||
|
y2 += 48;
|
||||||
|
}
|
||||||
|
if (rect.Contains(point.ToPointF())) return i.tag;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ namespace OpenRa.TechTree
|
|||||||
|
|
||||||
public bool Build(string key, bool force)
|
public bool Build(string key, bool force)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(key)) return false;
|
||||||
Item b = objects[key];
|
Item b = objects[key];
|
||||||
if (!force && !b.CanBuild) return false;
|
if (!force && !b.CanBuild) return false;
|
||||||
built.Add(key);
|
built.Add(key);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
OpenRA
|
OpenRA
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
|
[ ] Sidebar
|
||||||
|
[x] Click handling going ~beedee
|
||||||
|
[ ] Building needs to have some sort of timer
|
||||||
|
[ ] Need a better order to sort items in (rather than what the collection chucks at us by default)
|
||||||
|
[ ] Actually make built units appear in the world/allow them to be placed in the world
|
||||||
|
|
||||||
[ ] Multiplayer!
|
[ ] Multiplayer!
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user