better cursor handling

This commit is contained in:
Chris Forbes
2009-10-29 22:42:15 +13:00
parent 7a5d75c393
commit 4689a7fd05
4 changed files with 42 additions and 32 deletions

View File

@@ -96,29 +96,36 @@ namespace OpenRa.Game
public Cursor ChooseCursor()
{
var uog = orderGenerator as UnitOrderGenerator;
var c = (orderGenerator != null) ? orderGenerator.Order(dragEnd.ToInt2(), false)
.Select(a => a.Cursor)
.FirstOrDefault(a => a != null) : null;
if (uog != null)
uog.selection.RemoveAll(a => a.IsDead);
return c ?? (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default);
if (uog != null && uog.selection.Count > 0
&& uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
&& uog.selection.All(a => a.Owner == Game.LocalPlayer))
{
var umts = uog.selection.Select(a => a.traits.GetOrDefault<Mobile>())
.Where(m => m != null)
.Select(m => m.GetMovementType())
.Distinct();
//foreach( var o in
//var uog = orderGenerator as UnitOrderGenerator;
if (!umts.Any(umt => Game.IsCellBuildable(dragEnd.ToInt2(), umt)))
return Cursor.MoveBlocked;
return Cursor.Move;
}
//if (uog != null)
// uog.selection.RemoveAll(a => a.IsDead);
if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
return Cursor.Select;
//if (uog != null && uog.selection.Count > 0
// && uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
// && uog.selection.All(a => a.Owner == Game.LocalPlayer))
//{
// var umts = uog.selection.Select(a => a.traits.GetOrDefault<Mobile>())
// .Where(m => m != null)
// .Select(m => m.GetMovementType())
// .Distinct();
return Cursor.Default;
// if (!umts.Any(umt => Game.IsCellBuildable(dragEnd.ToInt2(), umt)))
// return Cursor.MoveBlocked;
// return Cursor.Move;
//}
//if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
// return Cursor.Select;
//return Cursor.Default;
}
}
}

View File

@@ -23,5 +23,6 @@ namespace OpenRa.Game
public static Cursor Select { get { return new Cursor("select"); } }
public static Cursor MoveBlocked { get { return new Cursor("move-blocked"); } }
public static Cursor Attack { get { return new Cursor("attack"); } }
public static Cursor Deploy { get { return new Cursor("deploy"); } }
}
}

View File

@@ -15,8 +15,9 @@ namespace OpenRa.Game
public readonly Actor TargetActor;
public readonly int2 TargetLocation;
public readonly string TargetString;
public readonly Cursor Cursor;
private Order(Player player, string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString)
Order(Player player, string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString, Cursor cursor)
{
this.Player = player;
this.OrderString = orderString;
@@ -24,6 +25,7 @@ namespace OpenRa.Game
this.TargetActor = targetActor;
this.TargetLocation = targetLocation;
this.TargetString = targetString;
this.Cursor = cursor;
}
public byte[] Serialize()
@@ -72,7 +74,7 @@ namespace OpenRa.Game
var targetString = null as string;
if (r.ReadBoolean())
targetString = r.ReadString();
return new Order(player, order, subject, targetActor, targetLocation, targetString);
return new Order(player, order, subject, targetActor, targetLocation, targetString, null);
}
default:
throw new NotImplementedException();
@@ -87,27 +89,27 @@ namespace OpenRa.Game
public static Order Attack(Actor subject, Actor target)
{
return new Order(subject.Owner, "Attack", subject, target, int2.Zero, null);
return new Order(subject.Owner, "Attack", subject, target, int2.Zero, null, Cursor.Attack);
}
public static Order Move(Actor subject, int2 target)
{
return new Order(subject.Owner, "Move", subject, null, target, null);
return new Order(subject.Owner, "Move", subject, null, target, null, Cursor.Move);
}
public static Order DeployMcv(Actor subject)
{
return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, null);
return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, null, Cursor.Deploy);
}
public static Order PlaceBuilding(Player subject, int2 target, string buildingName)
{
return new Order(subject, "PlaceBuilding", null, null, target, buildingName);
return new Order(subject, "PlaceBuilding", null, null, target, buildingName, Cursor.Default);
}
public static Order BuildUnit(Player subject, string unitName)
{
return new Order(subject, "BuildUnit", null, null, int2.Zero, unitName);
return new Order(subject, "BuildUnit", null, null, int2.Zero, unitName, Cursor.Default);
}
}
}

View File

@@ -361,14 +361,14 @@
<sequence name="attack" start="21" length="8" x="12" y="12" />
<sequence name="move-minimap" start="29" length="6" />
<sequence name="repair" start="35" length="24" />
<sequence name="deploy" start="59" length="9" />
<sequence name="deploy" start="59" length="9" x="12" y="12"/>
<sequence name="sell" start="68" length="12" />
<sequence name="default-minimap" start="80" length="1" />
<sequence name="ability" start="82" length="8" />
<sequence name="nuke" start="90" length="7" />
<sequence name="chrono" start="105" length="8" />
<sequence name="enter" start="113" length="3" />
<sequence name="c4" start="116" length="3" />
<sequence name="nuke" start="90" length="7" x="12" y="12" />
<sequence name="chrono" start="105" length="8" x="12" y="12" />
<sequence name="enter" start="113" length="3" x="12" y="12" />
<sequence name="c4" start="116" length="3" x="12" y="12" />
<sequence name="sell-blocked" start="119" length="1" />
<sequence name="repair-blocked" start="120" length="1" />
<sequence name="c4-minimap" start="121" length="3" />
@@ -376,14 +376,14 @@
<sequence name="attack-minimap" start="134" length="8" />
<sequence name="enter-minimap" start="142" length="3" />
<sequence name="guard-minimap" start="146" length="1" />
<sequence name="guard" start="147" length="1" />
<sequence name="guard" start="147" length="1" x="12" y="12" />
<sequence name="sell-vehicle" start="148" length="12" />
<sequence name="heal" start="160" length="4" />
<sequence name="capture" start="164" length="3" />
<sequence name="capture-minimap" start="167" length="3" />
<sequence name="repair2" start="170" length="24" />
<sequence name="heal-minimap" start="194" length="1" />
<sequence name="attack2" start="195" length="8" />
<sequence name="attack2" start="195" length="8" x="12" y="12" />
<sequence name="attack2-minimap" start="203" length="8" />
<sequence name="deploy-blocked" start="211" length="1" />
<sequence name="enter-blocked" start="212" length="1" />