From 78c9ae53dfa9ed742b509a0f86a0d38509058598 Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 24 Oct 2009 19:42:54 +1300 Subject: [PATCH] On orders, the mouse button is now considered part on issuing the order, not resolving it. --- OpenRa.Game/Actor.cs | 4 +- OpenRa.Game/Controller.cs | 74 +++++++++++++------------- OpenRa.Game/Game.cs | 2 +- OpenRa.Game/IOrderGenerator.cs | 2 +- OpenRa.Game/MoveOrder.cs | 6 +-- OpenRa.Game/PlaceBuilding.cs | 35 +++++++----- OpenRa.Game/PlaceBuildingOrder.cs | 27 +++------- OpenRa.Game/Traits/McvDeploy.cs | 7 +-- OpenRa.Game/Traits/Mobile.cs | 14 ++--- OpenRa.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRa.Game/UnitOrderGenerator.cs | 4 +- 11 files changed, 85 insertions(+), 92 deletions(-) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index f56b68c832..4981014dc8 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -62,13 +62,13 @@ namespace OpenRa.Game return traits.WithInterface().SelectMany( x => x.Render( this ) ); } - public Order Order( int2 xy ) + public Order Order( int2 xy, bool lmb ) { if (Owner != Game.LocalPlayer) return null; return traits.WithInterface() - .Select( x => x.Order( this, xy ) ) + .Select( x => x.Order( this, xy, lmb ) ) .FirstOrDefault( x => x != null ); } diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index 16dccdf954..661c0ec1f4 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -20,11 +20,11 @@ namespace OpenRa.Game if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down) { if (!(orderGenerator is PlaceBuilding)) - dragStart = dragEnd = xy; - - if (orderGenerator != null) - foreach (var order in orderGenerator.Order(xy.ToInt2())) - order.Apply(true); + dragStart = dragEnd = xy; + + if (orderGenerator != null) + foreach (var order in orderGenerator.Order(xy.ToInt2(), true)) + order.Apply(); } if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move) @@ -40,53 +40,53 @@ namespace OpenRa.Game else orderGenerator = new UnitOrderGenerator( Game.SelectUnitOrBuilding( Game.CellSize * xy ) ); - } - + } + dragStart = dragEnd = xy; } if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move) { /* 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( orderGenerator != null ) - foreach( var order in orderGenerator.Order( xy.ToInt2() ) ) - order.Apply( false ); + foreach( var order in orderGenerator.Order( xy.ToInt2(), false ) ) + order.Apply(); } public Pair? SelectionBox - { - get - { - if (dragStart == dragEnd) return null; - return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd); + { + get + { + if (dragStart == dragEnd) return null; + return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd); } - } - - public Cursor ChooseCursor() - { - var uog = orderGenerator as UnitOrderGenerator; - - if (uog != null) - uog.selection.RemoveAll(a => a.IsDead); - - if (uog != null && uog.selection.Count > 0 - && uog.selection.Any(a => a.traits.Contains()) - && uog.selection.All( a => a.Owner == Game.LocalPlayer )) - { - if (!Game.IsCellBuildable(dragEnd.ToInt2(), UnitMovementType.Wheel)) - return Cursor.MoveBlocked; /* todo: handle non-wheel movement behavior */ - return Cursor.Move; - } - - if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any()) - return Cursor.Select; - - return Cursor.Default; + } + + public Cursor ChooseCursor() + { + var uog = orderGenerator as UnitOrderGenerator; + + if (uog != null) + uog.selection.RemoveAll(a => a.IsDead); + + if (uog != null && uog.selection.Count > 0 + && uog.selection.Any(a => a.traits.Contains()) + && uog.selection.All( a => a.Owner == Game.LocalPlayer )) + { + if (!Game.IsCellBuildable(dragEnd.ToInt2(), UnitMovementType.Wheel)) + return Cursor.MoveBlocked; /* todo: handle non-wheel movement behavior */ + return Cursor.Move; + } + + if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any()) + return Cursor.Select; + + return Cursor.Default; } } } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 6d7180ea2f..77fa4f53e0 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -194,7 +194,7 @@ namespace OpenRa.Game var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player); var mobile = unit.traits.Get(); 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)); diff --git a/OpenRa.Game/IOrderGenerator.cs b/OpenRa.Game/IOrderGenerator.cs index f20c10cab6..a53877f95c 100644 --- a/OpenRa.Game/IOrderGenerator.cs +++ b/OpenRa.Game/IOrderGenerator.cs @@ -6,7 +6,7 @@ namespace OpenRa.Game { interface IOrderGenerator { - IEnumerable Order( int2 xy ); + IEnumerable Order( int2 xy, bool lmb ); void PrepareOverlay( int2 xy ); } } diff --git a/OpenRa.Game/MoveOrder.cs b/OpenRa.Game/MoveOrder.cs index 96eef6db20..ea7b2f5b41 100644 --- a/OpenRa.Game/MoveOrder.cs +++ b/OpenRa.Game/MoveOrder.cs @@ -6,7 +6,7 @@ namespace OpenRa.Game { abstract class Order { - public abstract void Apply( bool leftMButton ); + public abstract void Apply(); } class MoveOrder : Order @@ -26,10 +26,8 @@ namespace OpenRa.Game return suffixes[Unit.traits.Get().Voice]; } - public override void Apply( bool leftMouseButton ) + public override void Apply() { - if (leftMouseButton) return; - if (Game.LocalPlayer == Unit.Owner) Game.PlaySound("ackno.r00", false); var mobile = Unit.traits.Get(); diff --git a/OpenRa.Game/PlaceBuilding.cs b/OpenRa.Game/PlaceBuilding.cs index e93dcc052a..02095050f8 100644 --- a/OpenRa.Game/PlaceBuilding.cs +++ b/OpenRa.Game/PlaceBuilding.cs @@ -17,21 +17,32 @@ namespace OpenRa.Game Name = name; } - public IEnumerable Order(int2 xy) + public IEnumerable Order(int2 xy, bool lmb) { - // todo: check that space is free - var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[Name]; - if (Footprint.Tiles(bi, xy).Any( - t => !Game.IsCellBuildable(t, - bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel))) - yield break; + if( lmb ) + { + // todo: check that space is free + var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[ Name ]; + if( Footprint.Tiles( bi, xy ).Any( + 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. */ - if (!Footprint.Tiles(bi, xy).Any( - t => Game.GetDistanceToBase(t, Owner) < maxDistance)) - yield break; + var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ + if( !Footprint.Tiles( bi, xy ).Any( + t => Game.GetDistanceToBase( t, Owner ) < maxDistance ) ) + 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) diff --git a/OpenRa.Game/PlaceBuildingOrder.cs b/OpenRa.Game/PlaceBuildingOrder.cs index 433e661913..931bac5888 100644 --- a/OpenRa.Game/PlaceBuildingOrder.cs +++ b/OpenRa.Game/PlaceBuildingOrder.cs @@ -16,29 +16,18 @@ namespace OpenRa.Game 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 - Game.world.Add( new Actor( building.Name, xy - GameRules.Footprint.AdjustForBuildingSize( building.Name ), building.Owner ) ); + //Adjust placement for cursor to be in middle + Game.world.Add( new Actor( building.Name, xy - GameRules.Footprint.AdjustForBuildingSize( building.Name ), building.Owner ) ); - Game.controller.orderGenerator = null; - Game.worldRenderer.uiOverlay.KillOverlay(); - } ); - } - else - { - Game.world.AddFrameEndTask( _ => - { - Game.controller.orderGenerator = null; - Game.worldRenderer.uiOverlay.KillOverlay(); - } ); - } + Game.controller.orderGenerator = null; + Game.worldRenderer.uiOverlay.KillOverlay(); + } ); } } } diff --git a/OpenRa.Game/Traits/McvDeploy.cs b/OpenRa.Game/Traits/McvDeploy.cs index 1a78ce9db1..2057e3cb5a 100644 --- a/OpenRa.Game/Traits/McvDeploy.cs +++ b/OpenRa.Game/Traits/McvDeploy.cs @@ -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. if( xy == self.Location ) return new DeployMcvOrder( self, xy ); @@ -32,9 +34,8 @@ namespace OpenRa.Game.Traits Location = location; } - public override void Apply( bool leftMouseButton ) + public override void Apply() { - if( leftMouseButton ) return; var mobile = Unit.traits.Get(); mobile.QueueAction( new Mobile.Turn( 96 ) ); mobile.QueueAction( new DeployAction() ); diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index 4a848250ac..953809760c 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -22,14 +22,6 @@ namespace OpenRa.Game.Traits { this.self = self; fromCell = toCell; - } - - public void SetNextAction( CurrentAction nextAction ) - { - if( currentAction == null ) - currentAction = nextAction; - else - currentAction.NextAction = nextAction; } public void QueueAction( CurrentAction nextAction ) @@ -55,8 +47,10 @@ namespace OpenRa.Game.Traits 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) return new MoveOrder(self, xy); diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 0464f5b623..3c0c189c98 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -9,5 +9,5 @@ namespace OpenRa.Game.Traits { interface ITick { void Tick(Actor self); } interface IRender { IEnumerable> Render(Actor self); } - interface IOrder { Order Order(Actor self, int2 xy); } + interface IOrder { Order Order(Actor self, int2 xy, bool lmb); } } diff --git a/OpenRa.Game/UnitOrderGenerator.cs b/OpenRa.Game/UnitOrderGenerator.cs index 06ab76fe6b..7f0eac9b80 100755 --- a/OpenRa.Game/UnitOrderGenerator.cs +++ b/OpenRa.Game/UnitOrderGenerator.cs @@ -14,11 +14,11 @@ namespace OpenRa.Game selection = selected.ToList(); } - public IEnumerable Order( int2 xy ) + public IEnumerable Order( int2 xy, bool lmb ) { foreach( var unit in selection ) { - var ret = unit.Order( xy ); + var ret = unit.Order( xy, lmb ); if( ret != null ) yield return ret; }