Unhardcode sound and delay in PlaceBuilding.
This commit is contained in:
@@ -15,19 +15,38 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Allows to execute build orders.", " Attach this to the player actor.")]
|
[Desc("Allows the player to execute build orders.", " Attach this to the player actor.")]
|
||||||
class PlaceBuildingInfo : TraitInfo<PlaceBuilding>
|
public class PlaceBuildingInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Palette to use for rendering the placement sprite.")]
|
[Desc("Palette to use for rendering the placement sprite.")]
|
||||||
public readonly string Palette = "terrain";
|
public readonly string Palette = "terrain";
|
||||||
|
|
||||||
|
[Desc("Play NewOptionsNotification this many ticks after building placement.")]
|
||||||
|
public readonly int NewOptionsNotificationDelay = 10;
|
||||||
|
|
||||||
|
[Desc("Notification to play after building placement if new construction options are available.")]
|
||||||
|
public readonly string NewOptionsNotification = "NewOptions";
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new PlaceBuilding(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlaceBuilding : IResolveOrder
|
public class PlaceBuilding : IResolveOrder
|
||||||
{
|
{
|
||||||
|
readonly PlaceBuildingInfo info;
|
||||||
|
|
||||||
|
public PlaceBuilding(PlaceBuildingInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString == "PlaceBuilding" || order.OrderString == "LineBuild" || order.OrderString == "PlacePlug")
|
var os = order.OrderString;
|
||||||
{
|
if (os != "PlaceBuilding" &&
|
||||||
|
os != "LineBuild" &&
|
||||||
|
os != "PlacePlug")
|
||||||
|
return;
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
var prevItems = GetNumBuildables(self.Owner);
|
var prevItems = GetNumBuildables(self.Owner);
|
||||||
@@ -50,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (buildableInfo != null && buildableInfo.ForceRace != null)
|
if (buildableInfo != null && buildableInfo.ForceRace != null)
|
||||||
race = buildableInfo.ForceRace;
|
race = buildableInfo.ForceRace;
|
||||||
|
|
||||||
if (order.OrderString == "LineBuild")
|
if (os == "LineBuild")
|
||||||
{
|
{
|
||||||
var playSounds = true;
|
var playSounds = true;
|
||||||
foreach (var t in BuildingUtils.GetLineBuildCells(w, order.TargetLocation, order.TargetString, buildingInfo))
|
foreach (var t in BuildingUtils.GetLineBuildCells(w, order.TargetLocation, order.TargetString, buildingInfo))
|
||||||
@@ -69,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
playSounds = false;
|
playSounds = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (order.OrderString == "PlacePlug")
|
else if (os == "PlacePlug")
|
||||||
{
|
{
|
||||||
var host = self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(order.TargetLocation);
|
var host = self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(order.TargetLocation);
|
||||||
if (host == null)
|
if (host == null)
|
||||||
@@ -123,11 +142,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (GetNumBuildables(self.Owner) > prevItems)
|
if (GetNumBuildables(self.Owner) > prevItems)
|
||||||
w.Add(new DelayedAction(10,
|
w.Add(new DelayedAction(info.NewOptionsNotificationDelay,
|
||||||
() => Sound.PlayNotification(self.World.Map.Rules, order.Player, "Speech", "NewOptions", order.Player.Country.Race)));
|
() => Sound.PlayNotification(self.World.Map.Rules, order.Player, "Speech", info.NewOptionsNotification, order.Player.Country.Race)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static int GetNumBuildables(Player p)
|
static int GetNumBuildables(Player p)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user