add a Lua controllable flash palette trait
This commit is contained in:
@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
readonly Player firedBy;
|
readonly Player firedBy;
|
||||||
readonly Animation anim;
|
readonly Animation anim;
|
||||||
readonly string weapon;
|
readonly string weapon;
|
||||||
|
readonly string flashType;
|
||||||
|
|
||||||
readonly WPos ascendSource;
|
readonly WPos ascendSource;
|
||||||
readonly WPos ascendTarget;
|
readonly WPos ascendTarget;
|
||||||
@@ -34,12 +35,13 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
WPos pos;
|
WPos pos;
|
||||||
int ticks;
|
int ticks;
|
||||||
|
|
||||||
public NukeLaunch(Player firedBy, string weapon, WPos launchPos, WPos targetPos, WRange velocity, int delay, bool skipAscent)
|
public NukeLaunch(Player firedBy, string weapon, WPos launchPos, WPos targetPos, WRange velocity, int delay, bool skipAscent, string flashType)
|
||||||
{
|
{
|
||||||
this.firedBy = firedBy;
|
this.firedBy = firedBy;
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
this.turn = delay / 2;
|
this.turn = delay / 2;
|
||||||
|
this.flashType = flashType;
|
||||||
|
|
||||||
var offset = new WVec(WRange.Zero, WRange.Zero, velocity * turn);
|
var offset = new WVec(WRange.Zero, WRange.Zero, velocity * turn);
|
||||||
ascendSource = launchPos;
|
ascendSource = launchPos;
|
||||||
@@ -84,8 +86,9 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
weapon.Impact(Target.FromPos(pos), firedBy.PlayerActor, Enumerable.Empty<int>());
|
weapon.Impact(Target.FromPos(pos), firedBy.PlayerActor, Enumerable.Empty<int>());
|
||||||
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
|
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
|
||||||
|
|
||||||
foreach (var a in world.ActorsWithTrait<NukePaletteEffect>())
|
foreach (var flash in world.WorldActor.TraitsImplementing<FlashPaletteEffect>())
|
||||||
a.Trait.Enable();
|
if (flash.Info.Type == flashType)
|
||||||
|
flash.Enable(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
|
|||||||
@@ -215,6 +215,7 @@
|
|||||||
<Compile Include="Scripting\Global\CameraGlobal.cs" />
|
<Compile Include="Scripting\Global\CameraGlobal.cs" />
|
||||||
<Compile Include="Scripting\Global\CoordinateGlobals.cs" />
|
<Compile Include="Scripting\Global\CoordinateGlobals.cs" />
|
||||||
<Compile Include="Scripting\Global\DateTimeGlobal.cs" />
|
<Compile Include="Scripting\Global\DateTimeGlobal.cs" />
|
||||||
|
<Compile Include="Scripting\Global\EffectGlobal.cs" />
|
||||||
<Compile Include="Scripting\Global\FacingGlobal.cs" />
|
<Compile Include="Scripting\Global\FacingGlobal.cs" />
|
||||||
<Compile Include="Scripting\Global\HSLColorGlobal.cs" />
|
<Compile Include="Scripting\Global\HSLColorGlobal.cs" />
|
||||||
<Compile Include="Scripting\Global\MapGlobal.cs" />
|
<Compile Include="Scripting\Global\MapGlobal.cs" />
|
||||||
@@ -357,8 +358,8 @@
|
|||||||
<Compile Include="Traits\Passenger.cs" />
|
<Compile Include="Traits\Passenger.cs" />
|
||||||
<Compile Include="Traits\PaletteEffects\CloakPaletteEffect.cs" />
|
<Compile Include="Traits\PaletteEffects\CloakPaletteEffect.cs" />
|
||||||
<Compile Include="Traits\PaletteEffects\GlobalLightingPaletteEffect.cs" />
|
<Compile Include="Traits\PaletteEffects\GlobalLightingPaletteEffect.cs" />
|
||||||
|
<Compile Include="Traits\PaletteEffects\FlashPaletteEffect.cs" />
|
||||||
<Compile Include="Traits\PaletteEffects\MenuPaletteEffect.cs" />
|
<Compile Include="Traits\PaletteEffects\MenuPaletteEffect.cs" />
|
||||||
<Compile Include="Traits\PaletteEffects\NukePaletteEffect.cs" />
|
|
||||||
<Compile Include="Traits\PaletteEffects\WaterPaletteRotation.cs" />
|
<Compile Include="Traits\PaletteEffects\WaterPaletteRotation.cs" />
|
||||||
<Compile Include="Traits\Player\ActorGroupProxy.cs" />
|
<Compile Include="Traits\Player\ActorGroupProxy.cs" />
|
||||||
<Compile Include="Traits\Player\AllyRepair.cs" />
|
<Compile Include="Traits\Player\AllyRepair.cs" />
|
||||||
|
|||||||
36
OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs
Normal file
36
OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Scripting;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Scripting
|
||||||
|
{
|
||||||
|
[ScriptGlobal("Effect")]
|
||||||
|
public class EffectGlobal : ScriptGlobal
|
||||||
|
{
|
||||||
|
readonly IEnumerable<FlashPaletteEffect> fpes;
|
||||||
|
|
||||||
|
public EffectGlobal(ScriptContext context)
|
||||||
|
: base(context)
|
||||||
|
{
|
||||||
|
fpes = context.World.WorldActor.TraitsImplementing<FlashPaletteEffect>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Desc("Controls the `FlashPaletteEffect` trait.")]
|
||||||
|
public void Flash(string type = null, int ticks = -1)
|
||||||
|
{
|
||||||
|
foreach (var fpe in fpes)
|
||||||
|
if (fpe.Info.Type == type)
|
||||||
|
fpe.Enable(ticks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
using GUtil = OpenRA.Graphics.Util;
|
||||||
|
|
||||||
|
[Desc("Used for bursted one-colored whole screen effects. Add this to the world actor.")]
|
||||||
|
public class FlashPaletteEffectInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "fog", "shroud" };
|
||||||
|
|
||||||
|
[Desc("Measured in ticks.")]
|
||||||
|
public readonly int Length = 20;
|
||||||
|
|
||||||
|
public readonly Color Color = Color.White;
|
||||||
|
|
||||||
|
[Desc("Set this when using multiple independent flash effects.")]
|
||||||
|
public readonly string Type = null;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new FlashPaletteEffect(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FlashPaletteEffect : IPaletteModifier, ITick
|
||||||
|
{
|
||||||
|
public readonly FlashPaletteEffectInfo Info;
|
||||||
|
|
||||||
|
public FlashPaletteEffect(FlashPaletteEffectInfo info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
int remainingFrames;
|
||||||
|
|
||||||
|
public void Enable(int ticks)
|
||||||
|
{
|
||||||
|
if (ticks == -1)
|
||||||
|
remainingFrames = Info.Length;
|
||||||
|
else
|
||||||
|
remainingFrames = ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (remainingFrames > 0)
|
||||||
|
remainingFrames--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
|
||||||
|
{
|
||||||
|
if (remainingFrames == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var frac = (float)remainingFrames / Info.Length;
|
||||||
|
|
||||||
|
foreach (var pal in palettes)
|
||||||
|
{
|
||||||
|
for (var x = 0; x < Palette.Size; x++)
|
||||||
|
{
|
||||||
|
var orig = pal.Value.GetColor(x);
|
||||||
|
var c = Info.Color;
|
||||||
|
var color = Color.FromArgb(orig.A, ((int)c.R).Clamp(0, 255), ((int)c.G).Clamp(0, 255), ((int)c.B).Clamp(0, 255));
|
||||||
|
var final = GUtil.PremultipliedColorLerp(frac, orig, GUtil.PremultiplyAlpha(Color.FromArgb(orig.A, color)));
|
||||||
|
pal.Value.SetColor(x, final);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
|
||||||
* available to you under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation. For more information,
|
|
||||||
* see COPYING.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Graphics;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
|
||||||
{
|
|
||||||
using GUtil = OpenRA.Graphics.Util;
|
|
||||||
|
|
||||||
[Desc("Apply palette full screen rotations during atom bomb explosions. Add this to the world actor.")]
|
|
||||||
class NukePaletteEffectInfo : TraitInfo<NukePaletteEffect> { }
|
|
||||||
|
|
||||||
public class NukePaletteEffect : IPaletteModifier, ITick
|
|
||||||
{
|
|
||||||
const int NukeEffectLength = 20;
|
|
||||||
int remainingFrames;
|
|
||||||
|
|
||||||
public void Enable()
|
|
||||||
{
|
|
||||||
remainingFrames = NukeEffectLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (remainingFrames > 0)
|
|
||||||
remainingFrames--;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
|
|
||||||
{
|
|
||||||
if (remainingFrames == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var frac = (float)remainingFrames / NukeEffectLength;
|
|
||||||
|
|
||||||
foreach (var pal in palettes)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < Palette.Size; x++)
|
|
||||||
{
|
|
||||||
var orig = pal.Value.GetColor(x);
|
|
||||||
var final = GUtil.PremultipliedColorLerp(frac, orig, GUtil.PremultiplyAlpha(Color.FromArgb(orig.A, Color.White)));
|
|
||||||
pal.Value.SetColor(x, final);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -45,6 +45,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Amount of time after detonation to remove the camera")]
|
[Desc("Amount of time after detonation to remove the camera")]
|
||||||
public readonly int CameraRemoveDelay = 25;
|
public readonly int CameraRemoveDelay = 25;
|
||||||
|
|
||||||
|
public readonly string FlashType = null;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new NukePower(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new NukePower(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +78,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var missile = new NukeLaunch(self.Owner, info.MissileWeapon,
|
var missile = new NukeLaunch(self.Owner, info.MissileWeapon,
|
||||||
self.CenterPosition + body.LocalToWorld(info.SpawnOffset),
|
self.CenterPosition + body.LocalToWorld(info.SpawnOffset),
|
||||||
targetPosition,
|
targetPosition,
|
||||||
info.FlightVelocity, info.FlightDelay, info.SkipAscent);
|
info.FlightVelocity, info.FlightDelay, info.SkipAscent,
|
||||||
|
info.FlashType);
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w => w.Add(missile));
|
self.World.AddFrameEndTask(w => w.Add(missile));
|
||||||
|
|
||||||
|
|||||||
@@ -1353,6 +1353,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generalized the flash palette trait
|
||||||
|
if (engineVersion < 20150627)
|
||||||
|
{
|
||||||
|
if (node.Key == "NukePaletteEffect")
|
||||||
|
node.Key = "FlashPaletteEffect";
|
||||||
|
}
|
||||||
|
|
||||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
MenuPaletteEffect:
|
MenuPaletteEffect:
|
||||||
MenuEffect: Desaturated
|
MenuEffect: Desaturated
|
||||||
CloakPaletteEffect:
|
CloakPaletteEffect:
|
||||||
NukePaletteEffect:
|
FlashPaletteEffect:
|
||||||
WaterPaletteRotation:
|
WaterPaletteRotation:
|
||||||
ExcludePalettes: effect
|
ExcludePalettes: effect
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ World:
|
|||||||
PlayerCommands:
|
PlayerCommands:
|
||||||
HelpCommand:
|
HelpCommand:
|
||||||
ScreenShaker:
|
ScreenShaker:
|
||||||
NukePaletteEffect:
|
|
||||||
BuildingInfluence:
|
BuildingInfluence:
|
||||||
BridgeLayer:
|
BridgeLayer:
|
||||||
Bridges: bridge1, bridge2, bridge3, bridge4
|
Bridges: bridge1, bridge2, bridge3, bridge4
|
||||||
|
|||||||
@@ -86,5 +86,5 @@
|
|||||||
Alpha: 0.68
|
Alpha: 0.68
|
||||||
Premultiply: false
|
Premultiply: false
|
||||||
PlayerHighlightPalette:
|
PlayerHighlightPalette:
|
||||||
NukePaletteEffect:
|
FlashPaletteEffect:
|
||||||
|
|
||||||
|
|||||||
@@ -70,5 +70,6 @@
|
|||||||
LightPaletteRotator:
|
LightPaletteRotator:
|
||||||
ExcludePalettes: terrain, effect
|
ExcludePalettes: terrain, effect
|
||||||
ChronoshiftPaletteEffect:
|
ChronoshiftPaletteEffect:
|
||||||
NukePaletteEffect:
|
FlashPaletteEffect@NUKE:
|
||||||
|
Type: Nuke
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ MSLO:
|
|||||||
DisplayRadarPing: True
|
DisplayRadarPing: True
|
||||||
BeaconPoster: atomicon
|
BeaconPoster: atomicon
|
||||||
CameraActor: camera
|
CameraActor: camera
|
||||||
|
FlashType: Nuke
|
||||||
CanPowerDown:
|
CanPowerDown:
|
||||||
RequiresPower:
|
RequiresPower:
|
||||||
DisabledOverlay:
|
DisabledOverlay:
|
||||||
|
|||||||
Reference in New Issue
Block a user