file refactor
This commit is contained in:
parent
da5a3e874b
commit
bffb012a26
175 changed files with 1086 additions and 1107 deletions
10
scripts/gui/seedpackets/AlmanachHandler.cs
Normal file
10
scripts/gui/seedpackets/AlmanachHandler.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
public class AlmanachHandler : SeedpacketHandler
|
||||
{
|
||||
public AlmanachHandler(Seedpacket owner) : base(owner)
|
||||
{
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/AlmanachHandler.cs.uid
Normal file
1
scripts/gui/seedpackets/AlmanachHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://pse018r220mt
|
||||
29
scripts/gui/seedpackets/ChoosableHandler.cs
Normal file
29
scripts/gui/seedpackets/ChoosableHandler.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/ChoosableHandler.cs.uid
Normal file
1
scripts/gui/seedpackets/ChoosableHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b3sut12n56w1y
|
||||
9
scripts/gui/seedpackets/CustomSeedpacketFrame.cs
Normal file
9
scripts/gui/seedpackets/CustomSeedpacketFrame.cs
Normal 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;
|
||||
}
|
||||
1
scripts/gui/seedpackets/CustomSeedpacketFrame.cs.uid
Normal file
1
scripts/gui/seedpackets/CustomSeedpacketFrame.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://3m7xks3xq3hl
|
||||
25
scripts/gui/seedpackets/HotbarHandler.cs
Normal file
25
scripts/gui/seedpackets/HotbarHandler.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/HotbarHandler.cs.uid
Normal file
1
scripts/gui/seedpackets/HotbarHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://gvgt14v1hndn
|
||||
33
scripts/gui/seedpackets/HotbarPregameHandler.cs
Normal file
33
scripts/gui/seedpackets/HotbarPregameHandler.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/HotbarPregameHandler.cs.uid
Normal file
1
scripts/gui/seedpackets/HotbarPregameHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bnygd8pcmoewp
|
||||
6
scripts/gui/seedpackets/ISeedpacketPress.cs
Normal file
6
scripts/gui/seedpackets/ISeedpacketPress.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
public interface ISeedpacketPress
|
||||
{
|
||||
public void Pressed();
|
||||
}
|
||||
1
scripts/gui/seedpackets/ISeedpacketPress.cs.uid
Normal file
1
scripts/gui/seedpackets/ISeedpacketPress.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://o0ly38oqcuwu
|
||||
6
scripts/gui/seedpackets/ISeedpacketProcess.cs
Normal file
6
scripts/gui/seedpackets/ISeedpacketProcess.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
public interface ISeedpacketProcess
|
||||
{
|
||||
public void Process();
|
||||
}
|
||||
1
scripts/gui/seedpackets/ISeedpacketProcess.cs.uid
Normal file
1
scripts/gui/seedpackets/ISeedpacketProcess.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://q2r43hym7s82
|
||||
6
scripts/gui/seedpackets/ISeedpacketUnfocus.cs
Normal file
6
scripts/gui/seedpackets/ISeedpacketUnfocus.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
public interface ISeedpacketUnfocus
|
||||
{
|
||||
public void OnUnfocused();
|
||||
}
|
||||
1
scripts/gui/seedpackets/ISeedpacketUnfocus.cs.uid
Normal file
1
scripts/gui/seedpackets/ISeedpacketUnfocus.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://mdm8cepvvo4t
|
||||
99
scripts/gui/seedpackets/Seedpacket.cs
Normal file
99
scripts/gui/seedpackets/Seedpacket.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/Seedpacket.cs.uid
Normal file
1
scripts/gui/seedpackets/Seedpacket.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cn6ddajdtf4ep
|
||||
11
scripts/gui/seedpackets/SeedpacketHandler.cs
Normal file
11
scripts/gui/seedpackets/SeedpacketHandler.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
public class SeedpacketHandler
|
||||
{
|
||||
protected Seedpacket _owner;
|
||||
|
||||
public SeedpacketHandler(Seedpacket owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/SeedpacketHandler.cs.uid
Normal file
1
scripts/gui/seedpackets/SeedpacketHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cr774updc04fu
|
||||
Loading…
Add table
Add a link
Reference in a new issue