file refactor

This commit is contained in:
Rendo 2025-07-11 22:35:36 +05:00
commit bffb012a26
175 changed files with 1086 additions and 1107 deletions

View file

@ -0,0 +1,10 @@
using Godot;
namespace Newlon.Components.GUI.Seedpackets;
public class AlmanachHandler : SeedpacketHandler
{
public AlmanachHandler(Seedpacket owner) : base(owner)
{
}
}

View file

@ -0,0 +1 @@
uid://pse018r220mt

View file

@ -0,0 +1,29 @@
namespace Newlon.Components.GUI.Seedpackets;
public class ChoosableHandler : SeedpacketHandler, ISeedpacketPress
{
public ChoosableHandler(Seedpacket owner) : base(owner)
{
}
public void Pressed()
{
if (LevelGUIElements.Instance.SeedpacketsHotbar.GetChildCount() > 9) return;
_owner.disablePacket = true;
var hotbarSeedpacket = Seedpacket.Prefab.Instantiate<Seedpacket>();
LevelGUIElements.Instance.SeedpacketsHotbar.AddChild(hotbarSeedpacket);
hotbarSeedpacket.SetResource(_owner.GetResource());
var pregameHandler = new HotbarPregameHandler(hotbarSeedpacket);
hotbarSeedpacket.SetHandler(pregameHandler);
pregameHandler.Clicked += OnHotbarClicked;
AudioSequencer.Play("tap", Seedpacket.TapStream);
}
public void OnHotbarClicked()
{
_owner.disablePacket = false;
}
}

View file

@ -0,0 +1 @@
uid://b3sut12n56w1y

View file

@ -0,0 +1,9 @@
using Godot;
[GlobalClass]
public partial class CustomSeedpacketFrame : Resource
{
[Export] public Texture2D frame;
[Export] public LabelSettings font;
[Export] public Texture2D almanachField;
}

View file

@ -0,0 +1 @@
uid://3m7xks3xq3hl

View file

@ -0,0 +1,25 @@
using Newlon.Components.Level;
namespace Newlon.Components.GUI.Seedpackets;
public class HotbarHandler : SeedpacketHandler, ISeedpacketPress, ISeedpacketProcess, ISeedpacketUnfocus
{
public HotbarHandler(Seedpacket owner) : base(owner)
{
}
public void Pressed()
{
PlantField.Instance.SetPlant(_owner, _owner.GetResource());
AudioSequencer.Play("lift_seed", Seedpacket.LiftStream);
}
public void Process()
{
_owner.disablePacket = RuntimeLevelData.Instance.SunCount < _owner.GetResource().Cost;
}
public void OnUnfocused()
{
PlantField.Instance.ResetPlant();
}
}

View file

@ -0,0 +1 @@
uid://gvgt14v1hndn

View file

@ -0,0 +1,33 @@
using System;
using Newlon.Components.Level;
namespace Newlon.Components.GUI.Seedpackets;
public class HotbarPregameHandler : SeedpacketHandler, ISeedpacketPress
{
public HotbarPregameHandler(Seedpacket owner) : base(owner)
{
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
}
public event Action Clicked;
public void Pressed()
{
if (Clicked != null) Clicked();
_owner.QueueFree();
AudioSequencer.Play("tap", Seedpacket.UntapStream);
}
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
if (state == RuntimeLevelData.LevelStates.Game)
{
_owner.SetHandler(new HotbarHandler(_owner));
}
else if (state != RuntimeLevelData.LevelStates.ChooseYourSeeds)
{
_owner.disablePacket = true;
}
}
}

View file

@ -0,0 +1 @@
uid://bnygd8pcmoewp

View file

@ -0,0 +1,6 @@
namespace Newlon.Components.GUI.Seedpackets;
public interface ISeedpacketPress
{
public void Pressed();
}

View file

@ -0,0 +1 @@
uid://o0ly38oqcuwu

View file

@ -0,0 +1,6 @@
namespace Newlon.Components.GUI.Seedpackets;
public interface ISeedpacketProcess
{
public void Process();
}

View file

@ -0,0 +1 @@
uid://q2r43hym7s82

View file

@ -0,0 +1,6 @@
namespace Newlon.Components.GUI.Seedpackets;
public interface ISeedpacketUnfocus
{
public void OnUnfocused();
}

View file

@ -0,0 +1 @@
uid://mdm8cepvvo4t

View file

@ -0,0 +1,99 @@
using Godot;
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 DisplayResource _resource;
private Label _cost;
private TextureRect _icon;
private Timer _timer;
private SeedpacketHandler _handler;
public bool disablePacket = false;
public static PackedScene Prefab { get; private set; }
// 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();
if (Prefab == null)
{
Prefab = ResourceLoader.Load<PackedScene>(PATH_TO_PACKED_SCENE);
}
_cost = GetNode<Label>("Cost");
_icon = GetNode<TextureRect>("PlantPreviewContainer/Preview");
_timer = GetNode<Timer>("RechargeTimer");
}
public override void _Process(double delta)
{
Disabled = disablePacket || _timer.TimeLeft > 0;
if (Disabled)
{
FocusMode = FocusModeEnum.None;
}
else
{
FocusMode = FocusModeEnum.All;
}
if (_handler is ISeedpacketProcess processHandler) processHandler.Process();
}
public void SetResource(DisplayResource resource )
{
_resource = resource;
UpdateContents();
}
public DisplayResource GetResource()
{
return _resource;
}
public void SetHandler(SeedpacketHandler newHandler)
{
disablePacket = false;
_handler = newHandler;
}
protected virtual void UpdateContents()
{
_cost.Text = _resource.Cost.ToString();
_icon.Texture = _resource.Preview;
_timer.WaitTime = _resource.ReloadTime;
if (_resource.customFrame != null)
{
TextureNormal = _resource.customFrame.frame;
_cost.LabelSettings = _resource.customFrame.font;
}
}
public override void _Pressed()
{
if (_handler is ISeedpacketPress pressHandler)
pressHandler.Pressed();
}
public void Recharge()
{
_timer.Start();
ReleaseFocus();
}
public void OnUnfocused()
{
if (_handler is ISeedpacketUnfocus unfocusHandler) unfocusHandler.OnUnfocused();
}
}

View file

@ -0,0 +1 @@
uid://cn6ddajdtf4ep

View file

@ -0,0 +1,11 @@
namespace Newlon.Components.GUI.Seedpackets;
public class SeedpacketHandler
{
protected Seedpacket _owner;
public SeedpacketHandler(Seedpacket owner)
{
_owner = owner;
}
}

View file

@ -0,0 +1 @@
uid://cr774updc04fu