On orders, the mouse button is now considered part on issuing the order, not resolving it.
This commit is contained in:
@@ -62,13 +62,13 @@ namespace OpenRa.Game
|
|||||||
return traits.WithInterface<Traits.IRender>().SelectMany( x => x.Render( this ) );
|
return traits.WithInterface<Traits.IRender>().SelectMany( x => x.Render( this ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order Order( int2 xy )
|
public Order Order( int2 xy, bool lmb )
|
||||||
{
|
{
|
||||||
if (Owner != Game.LocalPlayer)
|
if (Owner != Game.LocalPlayer)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return traits.WithInterface<Traits.IOrder>()
|
return traits.WithInterface<Traits.IOrder>()
|
||||||
.Select( x => x.Order( this, xy ) )
|
.Select( x => x.Order( this, xy, lmb ) )
|
||||||
.FirstOrDefault( x => x != null );
|
.FirstOrDefault( x => x != null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ namespace OpenRa.Game
|
|||||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
if (!(orderGenerator is PlaceBuilding))
|
if (!(orderGenerator is PlaceBuilding))
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
|
|
||||||
if (orderGenerator != null)
|
if (orderGenerator != null)
|
||||||
foreach (var order in orderGenerator.Order(xy.ToInt2()))
|
foreach (var order in orderGenerator.Order(xy.ToInt2(), true))
|
||||||
order.Apply(true);
|
order.Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
||||||
@@ -40,53 +40,53 @@ namespace OpenRa.Game
|
|||||||
else
|
else
|
||||||
orderGenerator = new UnitOrderGenerator(
|
orderGenerator = new UnitOrderGenerator(
|
||||||
Game.SelectUnitOrBuilding( Game.CellSize * xy ) );
|
Game.SelectUnitOrBuilding( Game.CellSize * xy ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart = dragEnd = xy;
|
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;
|
dragStart = dragEnd = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
||||||
if( orderGenerator != null )
|
if( orderGenerator != null )
|
||||||
foreach( var order in orderGenerator.Order( xy.ToInt2() ) )
|
foreach( var order in orderGenerator.Order( xy.ToInt2(), false ) )
|
||||||
order.Apply( false );
|
order.Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<float2, float2>? SelectionBox
|
public Pair<float2, float2>? SelectionBox
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
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()
|
public Cursor ChooseCursor()
|
||||||
{
|
{
|
||||||
var uog = orderGenerator as UnitOrderGenerator;
|
var uog = orderGenerator as UnitOrderGenerator;
|
||||||
|
|
||||||
if (uog != null)
|
if (uog != null)
|
||||||
uog.selection.RemoveAll(a => a.IsDead);
|
uog.selection.RemoveAll(a => a.IsDead);
|
||||||
|
|
||||||
if (uog != null && uog.selection.Count > 0
|
if (uog != null && uog.selection.Count > 0
|
||||||
&& uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
|
&& uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
|
||||||
&& uog.selection.All( a => a.Owner == Game.LocalPlayer ))
|
&& uog.selection.All( a => a.Owner == Game.LocalPlayer ))
|
||||||
{
|
{
|
||||||
if (!Game.IsCellBuildable(dragEnd.ToInt2(), UnitMovementType.Wheel))
|
if (!Game.IsCellBuildable(dragEnd.ToInt2(), UnitMovementType.Wheel))
|
||||||
return Cursor.MoveBlocked; /* todo: handle non-wheel movement behavior */
|
return Cursor.MoveBlocked; /* todo: handle non-wheel movement behavior */
|
||||||
return Cursor.Move;
|
return Cursor.Move;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
||||||
return Cursor.Select;
|
return Cursor.Select;
|
||||||
|
|
||||||
return Cursor.Default;
|
return Cursor.Default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ namespace OpenRa.Game
|
|||||||
var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player);
|
var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player);
|
||||||
var mobile = unit.traits.Get<Mobile>();
|
var mobile = unit.traits.Get<Mobile>();
|
||||||
mobile.facing = 128;
|
mobile.facing = 128;
|
||||||
mobile.SetNextAction( new Traits.Mobile.MoveTo( unit.Location + new int2( 0, 3 ) ) );
|
mobile.QueueAction( new Traits.Mobile.MoveTo( unit.Location + new int2( 0, 3 ) ) );
|
||||||
|
|
||||||
world.AddFrameEndTask(_ => world.Add(unit));
|
world.AddFrameEndTask(_ => world.Add(unit));
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
interface IOrderGenerator
|
interface IOrderGenerator
|
||||||
{
|
{
|
||||||
IEnumerable<Order> Order( int2 xy );
|
IEnumerable<Order> Order( int2 xy, bool lmb );
|
||||||
void PrepareOverlay( int2 xy );
|
void PrepareOverlay( int2 xy );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
abstract class Order
|
abstract class Order
|
||||||
{
|
{
|
||||||
public abstract void Apply( bool leftMButton );
|
public abstract void Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
class MoveOrder : Order
|
class MoveOrder : Order
|
||||||
@@ -26,10 +26,8 @@ namespace OpenRa.Game
|
|||||||
return suffixes[Unit.traits.Get<Traits.Mobile>().Voice];
|
return suffixes[Unit.traits.Get<Traits.Mobile>().Voice];
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply( bool leftMouseButton )
|
public override void Apply()
|
||||||
{
|
{
|
||||||
if (leftMouseButton) return;
|
|
||||||
|
|
||||||
if (Game.LocalPlayer == Unit.Owner)
|
if (Game.LocalPlayer == Unit.Owner)
|
||||||
Game.PlaySound("ackno.r00", false);
|
Game.PlaySound("ackno.r00", false);
|
||||||
var mobile = Unit.traits.Get<Traits.Mobile>();
|
var mobile = Unit.traits.Get<Traits.Mobile>();
|
||||||
|
|||||||
@@ -17,21 +17,32 @@ namespace OpenRa.Game
|
|||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(int2 xy)
|
public IEnumerable<Order> Order(int2 xy, bool lmb)
|
||||||
{
|
{
|
||||||
// todo: check that space is free
|
if( lmb )
|
||||||
var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[Name];
|
{
|
||||||
if (Footprint.Tiles(bi, xy).Any(
|
// todo: check that space is free
|
||||||
t => !Game.IsCellBuildable(t,
|
var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[ Name ];
|
||||||
bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel)))
|
if( Footprint.Tiles( bi, xy ).Any(
|
||||||
yield break;
|
t => !Game.IsCellBuildable( t,
|
||||||
|
bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel ) ) )
|
||||||
|
yield break;
|
||||||
|
|
||||||
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
||||||
if (!Footprint.Tiles(bi, xy).Any(
|
if( !Footprint.Tiles( bi, xy ).Any(
|
||||||
t => Game.GetDistanceToBase(t, Owner) < maxDistance))
|
t => Game.GetDistanceToBase( t, Owner ) < maxDistance ) )
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
yield return new PlaceBuildingOrder(this, xy);
|
yield return new PlaceBuildingOrder( this, xy );
|
||||||
|
}
|
||||||
|
else // rmb
|
||||||
|
{
|
||||||
|
Game.world.AddFrameEndTask( _ =>
|
||||||
|
{
|
||||||
|
Game.controller.orderGenerator = null;
|
||||||
|
Game.worldRenderer.uiOverlay.KillOverlay();
|
||||||
|
} );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PrepareOverlay(int2 xy)
|
public void PrepareOverlay(int2 xy)
|
||||||
|
|||||||
@@ -16,29 +16,18 @@ namespace OpenRa.Game
|
|||||||
this.xy = xy;
|
this.xy = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply( bool leftMouseButton )
|
public override void Apply()
|
||||||
{
|
{
|
||||||
if( leftMouseButton )
|
Game.world.AddFrameEndTask( _ =>
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask( _ =>
|
Log.Write( "Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name );
|
||||||
{
|
|
||||||
Log.Write( "Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name );
|
|
||||||
|
|
||||||
//Adjust placement for cursor to be in middle
|
//Adjust placement for cursor to be in middle
|
||||||
Game.world.Add( new Actor( building.Name, xy - GameRules.Footprint.AdjustForBuildingSize( building.Name ), building.Owner ) );
|
Game.world.Add( new Actor( building.Name, xy - GameRules.Footprint.AdjustForBuildingSize( building.Name ), building.Owner ) );
|
||||||
|
|
||||||
Game.controller.orderGenerator = null;
|
Game.controller.orderGenerator = null;
|
||||||
Game.worldRenderer.uiOverlay.KillOverlay();
|
Game.worldRenderer.uiOverlay.KillOverlay();
|
||||||
} );
|
} );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Game.world.AddFrameEndTask( _ =>
|
|
||||||
{
|
|
||||||
Game.controller.orderGenerator = null;
|
|
||||||
Game.worldRenderer.uiOverlay.KillOverlay();
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order Order(Actor self, int2 xy)
|
public Order Order(Actor self, int2 xy, bool lmb)
|
||||||
{
|
{
|
||||||
|
if( lmb ) return null;
|
||||||
|
|
||||||
// TODO: check that there's enough space at the destination.
|
// TODO: check that there's enough space at the destination.
|
||||||
if( xy == self.Location )
|
if( xy == self.Location )
|
||||||
return new DeployMcvOrder( self, xy );
|
return new DeployMcvOrder( self, xy );
|
||||||
@@ -32,9 +34,8 @@ namespace OpenRa.Game.Traits
|
|||||||
Location = location;
|
Location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply( bool leftMouseButton )
|
public override void Apply()
|
||||||
{
|
{
|
||||||
if( leftMouseButton ) return;
|
|
||||||
var mobile = Unit.traits.Get<Mobile>();
|
var mobile = Unit.traits.Get<Mobile>();
|
||||||
mobile.QueueAction( new Mobile.Turn( 96 ) );
|
mobile.QueueAction( new Mobile.Turn( 96 ) );
|
||||||
mobile.QueueAction( new DeployAction() );
|
mobile.QueueAction( new DeployAction() );
|
||||||
|
|||||||
@@ -22,14 +22,6 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
fromCell = toCell;
|
fromCell = toCell;
|
||||||
}
|
|
||||||
|
|
||||||
public void SetNextAction( CurrentAction nextAction )
|
|
||||||
{
|
|
||||||
if( currentAction == null )
|
|
||||||
currentAction = nextAction;
|
|
||||||
else
|
|
||||||
currentAction.NextAction = nextAction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueueAction( CurrentAction nextAction )
|
public void QueueAction( CurrentAction nextAction )
|
||||||
@@ -55,8 +47,10 @@ namespace OpenRa.Game.Traits
|
|||||||
fromCell = toCell;
|
fromCell = toCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order Order(Actor self, int2 xy)
|
public Order Order(Actor self, int2 xy, bool lmb)
|
||||||
{
|
{
|
||||||
|
if( lmb ) return null;
|
||||||
|
|
||||||
if (xy != toCell)
|
if (xy != toCell)
|
||||||
return new MoveOrder(self, xy);
|
return new MoveOrder(self, xy);
|
||||||
|
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
interface ITick { void Tick(Actor self); }
|
interface ITick { void Tick(Actor self); }
|
||||||
interface IRender { IEnumerable<Pair<Sprite, float2>> Render(Actor self); }
|
interface IRender { IEnumerable<Pair<Sprite, float2>> Render(Actor self); }
|
||||||
interface IOrder { Order Order(Actor self, int2 xy); }
|
interface IOrder { Order Order(Actor self, int2 xy, bool lmb); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ namespace OpenRa.Game
|
|||||||
selection = selected.ToList();
|
selection = selected.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order( int2 xy )
|
public IEnumerable<Order> Order( int2 xy, bool lmb )
|
||||||
{
|
{
|
||||||
foreach( var unit in selection )
|
foreach( var unit in selection )
|
||||||
{
|
{
|
||||||
var ret = unit.Order( xy );
|
var ret = unit.Order( xy, lmb );
|
||||||
if( ret != null )
|
if( ret != null )
|
||||||
yield return ret;
|
yield return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user