unhacking a hack
This commit is contained in:
@@ -19,6 +19,12 @@ namespace OpenRa.Game
|
|||||||
public Controller(Func<Modifiers> getModifierKeys)
|
public Controller(Func<Modifiers> getModifierKeys)
|
||||||
{
|
{
|
||||||
GetModifierKeys = getModifierKeys;
|
GetModifierKeys = getModifierKeys;
|
||||||
|
CancelInputMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CancelInputMode()
|
||||||
|
{
|
||||||
|
orderGenerator = new UnitOrderGenerator(new Actor[] { });
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Order> recentOrders = new List<Order>();
|
List<Order> recentOrders = new List<Order>();
|
||||||
@@ -128,13 +134,22 @@ namespace OpenRa.Game
|
|||||||
public Cursor ChooseCursor()
|
public Cursor ChooseCursor()
|
||||||
{
|
{
|
||||||
var mods = GetModifierKeys();
|
var mods = GetModifierKeys();
|
||||||
var c = (orderGenerator is UnitOrderGenerator) ? orderGenerator.Order(dragEnd.ToInt2(),
|
|
||||||
new MouseInput { Location = (Game.CellSize * dragEnd - Game.viewport.Location).ToInt2(), Button = MouseButton.Right, Modifiers = mods })
|
var mi = new MouseInput {
|
||||||
|
Location = (Game.CellSize * dragEnd - Game.viewport.Location).ToInt2(),
|
||||||
|
Button = MouseButton.Right,
|
||||||
|
Modifiers = mods,
|
||||||
|
IsFake = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
var c = orderGenerator.Order(dragEnd.ToInt2(), mi)
|
||||||
.Where(o => o.Validate())
|
.Where(o => o.Validate())
|
||||||
.Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
|
.Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
|
||||||
.FirstOrDefault(a => a != null) : null;
|
.FirstOrDefault(a => a != null);
|
||||||
|
|
||||||
return c ?? (Game.SelectActorsInBox(Game.CellSize * dragEnd, Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default);
|
return c ??
|
||||||
|
(Game.SelectActorsInBox(Game.CellSize * dragEnd, Game.CellSize * dragEnd).Any()
|
||||||
|
? Cursor.Select : Cursor.Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor CursorForOrderString( string s, Actor a, int2 location )
|
Cursor CursorForOrderString( string s, Actor a, int2 location )
|
||||||
@@ -166,6 +181,7 @@ namespace OpenRa.Game
|
|||||||
case "Infiltrate": return Cursor.Enter;
|
case "Infiltrate": return Cursor.Enter;
|
||||||
case "Capture": return Cursor.Capture;
|
case "Capture": return Cursor.Capture;
|
||||||
case "Harvest": return Cursor.Attack; // TODO: special harvest cursor?
|
case "Harvest": return Cursor.Attack; // TODO: special harvest cursor?
|
||||||
|
case "PlaceBuilding": return Cursor.Default;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ namespace OpenRa.Game
|
|||||||
public int2 Location;
|
public int2 Location;
|
||||||
public MouseButton Button;
|
public MouseButton Button;
|
||||||
public Modifiers Modifiers;
|
public Modifiers Modifiers;
|
||||||
|
public bool IsFake;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MouseInputEvent { Down, Move, Up };
|
enum MouseInputEvent { Down, Move, Up };
|
||||||
|
|||||||
@@ -16,33 +16,38 @@ namespace OpenRa.Game.Orders
|
|||||||
|
|
||||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if( mi.Button == MouseButton.Left )
|
if (mi.IsFake)
|
||||||
{
|
{
|
||||||
if (!Game.CanPlaceBuilding(Building, xy, null, true))
|
// this order is never actually issued, but it's used for choosing a cursor
|
||||||
{
|
yield return new Order("PlaceBuilding", Producer.Owner.PlayerActor, null, xy, Building.Name);
|
||||||
Sound.Play("nodeply1.aud");
|
yield break;
|
||||||
yield break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!Game.IsCloseEnoughToBase(Producer.Owner, Building, xy))
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
Sound.Play("nodeply1.aud");
|
if (!Game.CanPlaceBuilding(Building, xy, null, true))
|
||||||
yield break;
|
{
|
||||||
}
|
Sound.Play("nodeply1.aud");
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Game.IsCloseEnoughToBase(Producer.Owner, Building, xy))
|
||||||
|
{
|
||||||
|
Sound.Play("nodeply1.aud");
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
yield return new Order("PlaceBuilding", Producer.Owner.PlayerActor, null, xy, Building.Name);
|
yield return new Order("PlaceBuilding", Producer.Owner.PlayerActor, null, xy, Building.Name);
|
||||||
}
|
}
|
||||||
else // rmb
|
else
|
||||||
{
|
Game.controller.CancelInputMode();
|
||||||
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.UnitCategory[ Building.Name ] );
|
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.UnitCategory[ Building.Name ] );
|
||||||
if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 )
|
if (producing == null || producing.Item != Building.Name || producing.RemainingTime != 0)
|
||||||
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
Game.controller.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render()
|
public void Render()
|
||||||
|
|||||||
Reference in New Issue
Block a user