show potential selections in band-box; FindUnits is still wrong.
This commit is contained in:
@@ -58,17 +58,20 @@ namespace OpenRa.Game
|
|||||||
orderGenerator.Order(game, new int2((int)xy.X, (int)xy.Y)).Apply(game);
|
orderGenerator.Order(game, new int2((int)xy.X, (int)xy.Y)).Apply(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrderGenerator FindUnit(float2 a, float2 b)
|
public Unit FindUnit(float2 a, float2 b)
|
||||||
|
{
|
||||||
|
return FindUnits(game, 24 * a, 24 * b).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<Unit> FindUnits(Game game, float2 a, float2 b)
|
||||||
{
|
{
|
||||||
a = 24 * a; b = 24 * b;
|
|
||||||
var min = new float2(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y));
|
var min = new float2(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y));
|
||||||
var max = new float2(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y));
|
var max = new float2(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y));
|
||||||
|
|
||||||
var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y);
|
var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y);
|
||||||
|
|
||||||
return game.world.Actors.OfType<Unit>()
|
return game.world.Actors.OfType<Unit>()
|
||||||
.Where(x => (x.owner == game.LocalPlayer) && (x.Bounds.IntersectsWith(rect)))
|
.Where(x => (x.owner == game.LocalPlayer) && (x.Bounds.IntersectsWith(rect)));
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<float2, float2>? SelectionBox()
|
public Pair<float2, float2>? SelectionBox()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRa.Game
|
|||||||
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||||
|
|
||||||
// temporary, until we remove all the subclasses of Building
|
// temporary, until we remove all the subclasses of Building
|
||||||
public Dictionary<string, Func<int2, Player, Building>> buildingCreation;
|
public Dictionary<string, Func<int2, Player, PlayerOwned>> buildingCreation;
|
||||||
|
|
||||||
public Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
public Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
||||||
|
|
||||||
@@ -51,11 +51,12 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
var buildings = new[] { "fact", "powr", "apwr", "barr", "atek", "stek", "dome" };
|
var buildings = new[] { "fact", "powr", "apwr", "barr", "atek", "stek", "dome" };
|
||||||
buildingCreation = buildings.ToDictionary(s => s,
|
buildingCreation = buildings.ToDictionary(s => s,
|
||||||
s => (Func<int2, Player, Building>)(
|
s => (Func<int2, Player, PlayerOwned>)(
|
||||||
(l, o) => new Building(s, l, o, this)));
|
(l, o) => new Building(s, l, o, this)));
|
||||||
|
|
||||||
buildingCreation.Add("proc", (location, owner) => new Refinery(location, owner, this));
|
buildingCreation.Add("proc", (location, owner) => new Refinery(location, owner, this));
|
||||||
buildingCreation.Add("weap", (location, owner) => new WarFactory(location, owner, this));
|
buildingCreation.Add("weap", (location, owner) => new WarFactory(location, owner, this));
|
||||||
|
buildingCreation.Add("3tnk", (location, owner) => new TurretedUnit("3tnk", location, owner, this));
|
||||||
|
|
||||||
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
|
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
|
||||||
worldRenderer = new WorldRenderer(renderer, world);
|
worldRenderer = new WorldRenderer(renderer, world);
|
||||||
|
|||||||
@@ -53,28 +53,6 @@ namespace OpenRa.Game.Graphics
|
|||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
|
|
||||||
var selectedUnit = world.game.controller.orderGenerator as Unit;
|
|
||||||
if (selectedUnit != null)
|
|
||||||
{
|
|
||||||
var center = selectedUnit.CenterLocation;
|
|
||||||
var size = selectedUnit.SelectedSize;
|
|
||||||
|
|
||||||
var xy = center - 0.5f * size;
|
|
||||||
var XY = center + 0.5f * size;
|
|
||||||
var Xy = new float2( XY.X, xy.Y );
|
|
||||||
var xY = new float2( xy.X, XY.Y );
|
|
||||||
|
|
||||||
lineRenderer.DrawLine(xy, xy + new float2(4, 0), Color.White, Color.White);
|
|
||||||
lineRenderer.DrawLine(xy, xy + new float2(0, 4), Color.White, Color.White);
|
|
||||||
lineRenderer.DrawLine(Xy, Xy + new float2(-4, 0), Color.White, Color.White);
|
|
||||||
lineRenderer.DrawLine(Xy, Xy + new float2(0, 4), Color.White, Color.White);
|
|
||||||
|
|
||||||
lineRenderer.DrawLine(xY, xY + new float2(4, 0), Color.White, Color.White);
|
|
||||||
lineRenderer.DrawLine(xY, xY + new float2(0, -4), Color.White, Color.White);
|
|
||||||
lineRenderer.DrawLine(XY, XY + new float2(-4, 0), Color.White, Color.White);
|
|
||||||
lineRenderer.DrawLine(XY, XY + new float2(0, -4), Color.White, Color.White);
|
|
||||||
}
|
|
||||||
|
|
||||||
var selbox = world.game.controller.SelectionBox();
|
var selbox = world.game.controller.SelectionBox();
|
||||||
if (selbox != null)
|
if (selbox != null)
|
||||||
{
|
{
|
||||||
@@ -86,9 +64,38 @@ namespace OpenRa.Game.Graphics
|
|||||||
lineRenderer.DrawLine(a + b, a + b + c, Color.White, Color.White);
|
lineRenderer.DrawLine(a + b, a + b + c, Color.White, Color.White);
|
||||||
lineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White);
|
lineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White);
|
||||||
lineRenderer.DrawLine(a, a + c, Color.White, Color.White);
|
lineRenderer.DrawLine(a, a + c, Color.White, Color.White);
|
||||||
|
|
||||||
|
foreach (var u in Controller.FindUnits(world.game, selbox.Value.First, selbox.Value.Second))
|
||||||
|
DrawSelectionBox(u, Color.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selectedUnit = world.game.controller.orderGenerator as Unit;
|
||||||
|
if (selectedUnit != null)
|
||||||
|
DrawSelectionBox(selectedUnit, Color.White);
|
||||||
|
|
||||||
|
|
||||||
lineRenderer.Flush();
|
lineRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawSelectionBox(Unit selectedUnit, Color c)
|
||||||
|
{
|
||||||
|
var center = selectedUnit.CenterLocation;
|
||||||
|
var size = selectedUnit.SelectedSize;
|
||||||
|
|
||||||
|
var xy = center - 0.5f * size;
|
||||||
|
var XY = center + 0.5f * size;
|
||||||
|
var Xy = new float2(XY.X, xy.Y);
|
||||||
|
var xY = new float2(xy.X, XY.Y);
|
||||||
|
|
||||||
|
lineRenderer.DrawLine(xy, xy + new float2(4, 0), c, c);
|
||||||
|
lineRenderer.DrawLine(xy, xy + new float2(0, 4), c, c);
|
||||||
|
lineRenderer.DrawLine(Xy, Xy + new float2(-4, 0), c, c);
|
||||||
|
lineRenderer.DrawLine(Xy, Xy + new float2(0, 4), c, c);
|
||||||
|
|
||||||
|
lineRenderer.DrawLine(xY, xY + new float2(4, 0), c, c);
|
||||||
|
lineRenderer.DrawLine(xY, xY + new float2(0, -4), c, c);
|
||||||
|
lineRenderer.DrawLine(XY, XY + new float2(-4, 0), c, c);
|
||||||
|
lineRenderer.DrawLine(XY, XY + new float2(0, -4), c, c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
game.world.AddFrameEndTask(_ =>
|
game.world.AddFrameEndTask(_ =>
|
||||||
{
|
{
|
||||||
Func<int2, Player, Building> newBuilding;
|
Func<int2, Player, PlayerOwned> newBuilding;
|
||||||
if (game.buildingCreation.TryGetValue(building.Name, out newBuilding))
|
if (game.buildingCreation.TryGetValue(building.Name, out newBuilding))
|
||||||
{
|
{
|
||||||
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
||||||
|
|||||||
7
line.fx
7
line.fx
@@ -27,20 +27,19 @@ VertexOut Simple_vp(VertexIn v) {
|
|||||||
o.Position = float4(p.x,p.y,0,1);
|
o.Position = float4(p.x,p.y,0,1);
|
||||||
o.Color.rg = v.RG.xy;
|
o.Color.rg = v.RG.xy;
|
||||||
o.Color.ba = v.BA.xy;
|
o.Color.ba = v.BA.xy;
|
||||||
o.Color.a = 1.0f;
|
// o.Color.a = 1.0f;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float2 texelOffset = float2( 0, 1.0f/32.0f );
|
const float2 texelOffset = float2( 0, 1.0f/32.0f );
|
||||||
|
|
||||||
float4 Simple_fp(FragmentIn f) : COLOR0 {
|
float4 Simple_fp(FragmentIn f) : COLOR0 {
|
||||||
return float4(1,1,1,1);
|
return f.Color;
|
||||||
//return f.Color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
technique high_quality {
|
technique high_quality {
|
||||||
pass p0 {
|
pass p0 {
|
||||||
AlphaBlendEnable = false;
|
AlphaBlendEnable = true;
|
||||||
ZWriteEnable = false;
|
ZWriteEnable = false;
|
||||||
ZEnable = false;
|
ZEnable = false;
|
||||||
CullMode = None;
|
CullMode = None;
|
||||||
|
|||||||
Reference in New Issue
Block a user