select cursor support, better selection
This commit is contained in:
@@ -42,18 +42,21 @@ namespace OpenRa.Game
|
|||||||
if (!(orderGenerator is PlaceBuilding))
|
if (!(orderGenerator is PlaceBuilding))
|
||||||
{
|
{
|
||||||
if (dragStart != xy)
|
if (dragStart != xy)
|
||||||
orderGenerator = new UnitOrderGenerator( game.FindUnits( Game.CellSize * dragStart, Game.CellSize * xy ) ); /* band-box select */
|
orderGenerator = new UnitOrderGenerator(
|
||||||
|
game.SelectUnitsInBox( Game.CellSize * dragStart, Game.CellSize * xy ) );
|
||||||
else
|
else
|
||||||
orderGenerator = new UnitOrderGenerator( game.FindUnits( Game.CellSize * xy, Game.CellSize * xy ) ); /* click select */
|
orderGenerator = new UnitOrderGenerator(
|
||||||
|
game.SelectUnitOrBuilding( Game.CellSize * xy ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart = dragEnd;
|
dragStart = dragEnd = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move)
|
if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move)
|
||||||
{
|
{
|
||||||
/* update the cursor to reflect the thing under us - note this
|
/* update the cursor to reflect the thing under us - note this
|
||||||
* needs to also happen when the *thing* changes, so per-frame hook */
|
* needs to also happen when the *thing* changes, so per-frame hook */
|
||||||
|
dragStart = dragEnd = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
||||||
@@ -69,6 +72,19 @@ namespace OpenRa.Game
|
|||||||
if (dragStart == dragEnd) return null;
|
if (dragStart == dragEnd) return null;
|
||||||
return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd);
|
return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Cursor ChooseCursor()
|
||||||
|
{
|
||||||
|
var uog = orderGenerator as UnitOrderGenerator;
|
||||||
|
|
||||||
|
if (uog != null && uog.selection.Count > 0 && uog.selection.Any(a => a.traits.Contains<Traits.Mobile>()))
|
||||||
|
return Cursor.Move;
|
||||||
|
|
||||||
|
if (game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
||||||
|
return Cursor.Select;
|
||||||
|
|
||||||
|
return Cursor.Default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,8 @@ namespace OpenRa.Game
|
|||||||
public Sprite GetSprite(int frame) { return sequence.GetSprite(frame); }
|
public Sprite GetSprite(int frame) { return sequence.GetSprite(frame); }
|
||||||
public int2 GetHotspot() { return sequence.Hotspot; }
|
public int2 GetHotspot() { return sequence.Hotspot; }
|
||||||
|
|
||||||
public static Cursor Default
|
public static Cursor Default { get { return new Cursor("default"); } }
|
||||||
{
|
public static Cursor Move { get { return new Cursor("move"); } }
|
||||||
get { return new Cursor("default"); }
|
public static Cursor Select { get { return new Cursor("select"); } }
|
||||||
}
|
|
||||||
|
|
||||||
public static Cursor Move
|
|
||||||
{
|
|
||||||
get { return new Cursor("move"); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,17 +131,28 @@ namespace OpenRa.Game
|
|||||||
return map.IsInMap(a.X, a.Y) &&
|
return map.IsInMap(a.X, a.Y) &&
|
||||||
TerrainCosts.Cost(UnitMovementType.Wheel,
|
TerrainCosts.Cost(UnitMovementType.Wheel,
|
||||||
terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<Actor> FindUnits(float2 a, float2 b)
|
||||||
|
{
|
||||||
|
var min = float2.Min(a, b);
|
||||||
|
var max = float2.Max(a, b);
|
||||||
|
|
||||||
|
var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y);
|
||||||
|
|
||||||
|
return world.Actors
|
||||||
|
.Where(x => x.Bounds.IntersectsWith(rect));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Actor> FindUnits(float2 a, float2 b)
|
public IEnumerable<Actor> SelectUnitsInBox(float2 a, float2 b)
|
||||||
{
|
{
|
||||||
var min = float2.Min(a, b);
|
return FindUnits(a, b).Where(x => x.Owner == LocalPlayer && x.traits.Contains<Traits.Mobile>());
|
||||||
var max = float2.Max(a, b);
|
}
|
||||||
|
|
||||||
var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y);
|
public IEnumerable<Actor> SelectUnitOrBuilding(float2 a)
|
||||||
|
{
|
||||||
return world.Actors
|
var q = FindUnits(a, a);
|
||||||
.Where(x => (x.Owner == LocalPlayer) && (x.Bounds.IntersectsWith(rect)));
|
return q.Where(x => x.traits.Contains<Traits.Mobile>()).Concat(q).Take(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
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 game.FindUnits(selbox.Value.First, selbox.Value.Second))
|
foreach (var u in game.SelectUnitsInBox(selbox.Value.First, selbox.Value.Second))
|
||||||
DrawSelectionBox(u, Color.Yellow, false);
|
DrawSelectionBox(u, Color.Yellow, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,9 +80,7 @@ using System.Runtime.InteropServices;
|
|||||||
game.Tick();
|
game.Tick();
|
||||||
|
|
||||||
// rude hack
|
// rude hack
|
||||||
game.viewport.cursor = (game.controller.orderGenerator is UnitOrderGenerator)
|
game.viewport.cursor = game.controller.ChooseCursor();
|
||||||
&& (game.controller.orderGenerator as UnitOrderGenerator).selection.Count > 0
|
|
||||||
? OpenRa.Game.Cursor.Move : OpenRa.Game.Cursor.Default;
|
|
||||||
|
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -332,7 +332,7 @@
|
|||||||
<sequence name="scroll-blocked" start="9" />
|
<sequence name="scroll-blocked" start="9" />
|
||||||
<sequence name="move" start="10" length="4" x="12" y="12"/>
|
<sequence name="move" start="10" length="4" x="12" y="12"/>
|
||||||
<sequence name="move-blocked" start="14" />
|
<sequence name="move-blocked" start="14" />
|
||||||
<sequence name="select" start="15" length="6" />
|
<sequence name="select" start="15" length="6" x="12" y="12"/>
|
||||||
<sequence name="attack" start="21" length="8" />
|
<sequence name="attack" start="21" length="8" />
|
||||||
<sequence name="move-minimap" start="29" length="6" />
|
<sequence name="move-minimap" start="29" length="6" />
|
||||||
<sequence name="repair" start="35" length="24" />
|
<sequence name="repair" start="35" length="24" />
|
||||||
|
|||||||
Reference in New Issue
Block a user