add audio feedback to stop/scatter/deploy junk

This commit is contained in:
Chris Forbes
2011-03-06 10:22:40 +13:00
parent 1a6ff61836
commit 65a54ba13a
3 changed files with 36 additions and 18 deletions

View File

@@ -99,17 +99,9 @@ namespace OpenRA.Widgets
if (world.OrderGenerator == null) return;
var orders = world.OrderGenerator.Order(world, xy.ToInt2(), mi).ToArray();
orders.Do( o => world.IssueOrder( o ) );
// Find an actor with a phrase to say
foreach (var o in orders)
{
if (o.Subject.Destroyed) continue;
foreach (var v in o.Subject.TraitsImplementing<IOrderVoice>())
if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o),
o.Subject, o.Subject.Owner.Country.Race))
return;
}
orders.Do( o => world.IssueOrder( o ) );
world.PlayVoiceForOrders(orders);
}
public override string GetCursor(int2 pos)

View File

@@ -124,6 +124,19 @@ namespace OpenRA
if (!a.Info.Traits.Contains<SelectableInfo>()) return null;
var v = a.Info.Traits.Get<SelectableInfo>().Voice;
return (v == null) ? null : Rules.Voices[v];
}
public static void PlayVoiceForOrders(this World w, Order[] orders)
{
// Find an actor with a phrase to say
foreach (var o in orders)
{
if (o.Subject.Destroyed) continue;
foreach (var v in o.Subject.TraitsImplementing<IOrderVoice>())
if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o),
o.Subject, o.Subject.Owner.Country.Race))
return;
}
}
}
}

View File

@@ -15,6 +15,7 @@ namespace OpenRA.Mods.RA.Widgets
public char AttackMoveKey = 'a';
public char StopKey = 's';
public char ScatterKey = 'x';
public char DeployKey = 'f';
public readonly OrderManager OrderManager;
[ObjectCreator.UseCtor]
@@ -50,11 +51,16 @@ namespace OpenRA.Mods.RA.Widgets
if (e.KeyChar == ScatterKey)
return PerformScatter();
if (e.KeyChar == DeployKey)
return PerformDeploy();
}
return false;
}
// todo: take ALL this garbage and route it through the OrderTargeter stuff.
bool PerformAttackMove()
{
World.OrderGenerator = new GenericSelectTarget(World.Selection.Actors, "AttackMove",
@@ -63,21 +69,28 @@ namespace OpenRA.Mods.RA.Widgets
return true;
}
void PerformKeyboardOrderOnSelection(Func<Actor, Order> f)
{
var orders = World.Selection.Actors.Select(f).ToArray();
foreach (var o in orders) World.IssueOrder(o);
World.PlayVoiceForOrders(orders);
}
bool PerformStop()
{
/* issue a stop order to everyone. */
foreach (var a in World.Selection.Actors)
World.IssueOrder(new Order("Stop", a, false));
PerformKeyboardOrderOnSelection(a => new Order("Stop", a, false));
return true;
}
bool PerformScatter()
{
/* issue a stop order to everyone. */
foreach (var a in World.Selection.Actors)
World.IssueOrder(new Order("Scatter", a, false));
PerformKeyboardOrderOnSelection(a => new Order("Scatter", a, false));
return true;
}
bool PerformDeploy()
{
PerformKeyboardOrderOnSelection(a => new Order("Deploy", a, false));
return true;
}
}