Audio system and rich text

This commit is contained in:
Rendo 2025-06-29 14:28:51 +05:00
commit 68cafff083
161 changed files with 1605 additions and 255 deletions

View file

@ -8,7 +8,7 @@ public partial class Previewport : SubViewport
private RuntimePlantData current_display;
[Export] private Label title;
[Export] private Label description;
[Export] private RichTextLabel description;
public override void _Ready()
{

View file

@ -8,7 +8,7 @@ public class ChoosableHandler : SeedpacketHandler, ISeedpacketPress
public void Pressed()
{
if(LevelGUIElements.Instance.SeedpacketsHotbar.GetChildCount() > 9) return;
if (LevelGUIElements.Instance.SeedpacketsHotbar.GetChildCount() > 9) return;
_owner.disablePacket = true;
var hotbarSeedpacket = Seedpacket.Prefab.Instantiate<Seedpacket>();
@ -18,6 +18,8 @@ public class ChoosableHandler : SeedpacketHandler, ISeedpacketPress
var pregameHandler = new HotbarPregameHandler(hotbarSeedpacket);
hotbarSeedpacket.SetHandler(pregameHandler);
pregameHandler.Clicked += OnHotbarClicked;
AudioSequencer.Play("tap", Seedpacket.TapStream);
}
public void OnHotbarClicked()

View file

@ -10,7 +10,8 @@ public class HotbarHandler : SeedpacketHandler, ISeedpacketPress, ISeedpacketPro
public void Pressed()
{
PlantField.Instance.SetPlant(_owner,_owner.GetPlantResource());
PlantField.Instance.SetPlant(_owner, _owner.GetPlantResource());
AudioSequencer.Play("lift_seed", Seedpacket.LiftStream);
}
public void Process()

View file

@ -16,6 +16,7 @@ public class HotbarPregameHandler : SeedpacketHandler, ISeedpacketPress
{
if (Clicked != null) Clicked();
_owner.QueueFree();
AudioSequencer.Play("tap", Seedpacket.UntapStream);
}
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)

View file

@ -4,6 +4,9 @@ namespace Newlon.Components.GUI.Seedpackets;
public partial class Seedpacket : TextureButton
{
public static AudioStream TapStream;
public static AudioStream UntapStream;
public static AudioStream LiftStream;
private const string PATH_TO_PACKED_SCENE = "res://scenes/gui/seedpacket.tscn";
private PlantResource _resource;
private Label _cost;
@ -18,8 +21,14 @@ public partial class Seedpacket : TextureButton
// Node overrides
public override void _Ready()
{
if (TapStream == null)
{
TapStream = ResourceLoader.Load<AudioStream>("res://assets/audio/gui/tap.mp3");
UntapStream = ResourceLoader.Load<AudioStream>("res://assets/audio/gui/tap2.mp3");
LiftStream = ResourceLoader.Load<AudioStream>("res://assets/audio/gui/seedlift.mp3");
}
if (_resource != null)
UpdateContents();
UpdateContents();
if (Prefab == null)
{
Prefab = ResourceLoader.Load<PackedScene>(PATH_TO_PACKED_SCENE);

View file

@ -10,6 +10,7 @@ public partial class PlantField : Node2D
private PlantResource _resource;
private Seedpacket _slot;
private bool _previousCanPlace;
private ChannelPlayer player;
[Export] private PackedScene particles;
public static PlantField Instance {get; private set;}
@ -17,6 +18,7 @@ public partial class PlantField : Node2D
{
Instance = this;
_plantSetter = GetChild<Node2D>(0);
player = GetNode<ChannelPlayer>("PlantPlayer");
}
public void SetPlant(Seedpacket slot, PlantResource plant)
@ -99,6 +101,8 @@ public partial class PlantField : Node2D
PoolContainer.Instance.SpawnParticles(particles, plant.GlobalPosition + Vector2.Down * Utility.TileHeight/2.0f);
player.Play();
// Unfocusing and recharging slot
_slot.Recharge();
}

View file

@ -5,11 +5,10 @@ using Newlon.Components.Zombies;
public partial class FallParticle : RigidBody2D
{
[Export] private RuntimeZombieData data;
[Export] private Timer deathTimer;
[Export] private Vector2 falloffImpulseMin = Vector2.Zero;
[Export] private Vector2 falloffImpulseMax = Vector2.Zero;
[Export] private Vector2 falloffOffsetMin = Vector2.Zero;
[Export] private Vector2 falloffOffsetMax = Vector2.Zero;
[Export] private float minAngle;
[Export] private float maxAngle;
[Export] private float minTorque;
[Export] private float maxTorque;
[Export] private float Impulse;
public void FallOff()
{
@ -21,14 +20,14 @@ public partial class FallParticle : RigidBody2D
Callable.From(() =>
{
Reparent(PoolContainer.Instance.Zombies);
ApplyImpulse(RandomVector(falloffImpulseMin, falloffImpulseMax).Normalized() * Impulse, RandomVector(falloffOffsetMin, falloffOffsetMax));
float rng_angle = Mathf.DegToRad((float)GD.RandRange(minAngle, maxAngle));
float rng_torque = Mathf.DegToRad((float)GD.RandRange(minTorque, maxTorque));
ApplyImpulse(new Vector2(Mathf.Sin(rng_angle) * Impulse, Mathf.Cos(rng_angle) * Impulse));
ApplyTorqueImpulse(rng_torque);
}).CallDeferred();
deathTimer.Start();
}
private Vector2 RandomVector(Vector2 min, Vector2 max)
{
return new Vector2((float)GD.RandRange(min.X,max.X),(float)GD.RandRange(min.Y,max.Y));
var tween = CreateTween();
tween.TweenInterval(4.0);
tween.TweenProperty(this, "modulate", new Color(Modulate.R, Modulate.G, Modulate.B, 0f), 1.0);
tween.TweenCallback(Callable.From(QueueFree));
}
}

View file

@ -19,6 +19,7 @@ public partial class ExplosionComponent : Area2D
PoolContainer.Instance.SpawnParticles(particles, GetParent<RuntimePlantData>().GlobalPosition);
GetNode<ChannelPlayer>("ExplosionPlayer").Play();
GetParent<RuntimePlantData>().Kill();
}

View file

@ -17,12 +17,15 @@ public partial class RuntimePlantData : Node2D, IEntity
public int Line { get; set; }
public PlantResource Resource;
private AudioStream eatenSound;
[Signal]
public delegate void OnHPChangedEventHandler(int amount, Node origin);
public override void _Ready()
{
_hp = _maxHP;
eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");
}
public virtual void Heal(int amount, Node origin)
@ -46,6 +49,7 @@ public partial class RuntimePlantData : Node2D, IEntity
if (_hp <= 0)
{
Kill();
AudioSequencer.Play("plant_eaten", eatenSound);
}
}
public virtual void Kill()

View file

@ -8,6 +8,8 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
{
[Signal]
public delegate void OnHPChangedEventHandler(int deltaHP, Node origin);
[Signal]
public delegate void OnDamagedEventHandler();
[Signal]
public delegate void OnLocalTimescaleChangedEventHandler(int currentTimescale);
@ -18,6 +20,11 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
private int _maxHP;
[Export]
private Armor _armor;
[Export]
private AudioStream garlicSound;
[Export]
private AudioStream freezeSound;
private float _localTimescale = 1.0f;
@ -61,7 +68,6 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
else
_hp += amount;
EmitSignal(SignalName.OnHPChanged,amount,origin);
if (MaxHp > 0)
{
@ -78,6 +84,7 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
else
_hp -= amount;
EmitSignal(SignalName.OnHPChanged,-amount, origin);
EmitSignal(SignalName.OnDamaged);
if (_hp <= 0)
{
@ -94,11 +101,27 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
public void GiveEffect(Effect what)
{
int slot = (int)what.Slot;
if(_activeEffectSlots[slot] != null)
if (_activeEffectSlots[slot] == null)
{
_effectSlotTimers[slot].Stop();
_activeEffectSlots[slot].Exit(this);
switch (what.Slot)
{
case Utility.EffectSlots.FREEZE:
AudioSequencer.Play("zombie_freeze", freezeSound);
var settings = new ChannelSettings();
settings.restartTreshold = -1;
AudioSequencer.ChangeSettings("zombie_freeze",settings);
break;
case Utility.EffectSlots.GARLIC:
AudioSequencer.Play("zombie_garlic", garlicSound);
break;
}
}
if (_activeEffectSlots[slot] != null)
{
_effectSlotTimers[slot].Stop();
_activeEffectSlots[slot].Exit(this);
}
_effectSlotTimers[slot].WaitTime = what.Duration;
_effectSlotTimers[slot].Start();