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,9 @@
using Godot;
public partial class ExitButton : Button
{
public override void _Pressed()
{
GetTree().ChangeSceneToFile("uid://bfstrli64u23y");
}
}

View file

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

View file

@ -0,0 +1,36 @@
using Godot;
namespace Newlon.Components.GUI;
public partial class FastForwardButton : Button
{
[Export] private Texture2D firstSpeed;
[Export] private Texture2D secondSpeed;
[Export] private Texture2D thirdSpeed;
[Export] private AnimationPlayer flashAnimator;
private int speed = 1;
public void OnPressed()
{
speed = Mathf.Wrap(speed+1, 1, 4);
switch (speed)
{
case 1:
Icon = firstSpeed;
break;
case 2:
Icon = secondSpeed;
break;
case 3:
Icon = thirdSpeed;
break;
}
flashAnimator.Play("flash");
Engine.TimeScale = speed;
}
}

View file

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

View file

@ -0,0 +1,11 @@
using Godot;
using System;
public partial class PauseButton : Button
{
public override void _Pressed()
{
PauseMenu.Pause();
}
}

View file

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

31
scripts/gui/PauseMenu.cs Normal file
View file

@ -0,0 +1,31 @@
using Godot;
using System;
public partial class PauseMenu : Control
{
private static PauseMenu Instance;
public override void _Ready()
{
Instance = this;
}
public void Continue()
{
GetParent<Control>().Visible = false;
GetTree().Paused = false;
}
public void Restart()
{
GetTree().Paused = false;
GetTree().ReloadCurrentScene();
}
public void Exit()
{
GetTree().ChangeSceneToFile("uid://bfstrli64u23y");
}
public static void Pause()
{
Instance.GetParent<Control>().Visible = true;
Instance.GetTree().Paused = true;
}
}

View file

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

View file

@ -0,0 +1,12 @@
using Godot;
using System;
public partial class RestartButton : Button
{
public override void _Pressed()
{
GetTree().Paused = false;
GetTree().ReloadCurrentScene();
}
}

View file

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

View file

@ -0,0 +1,41 @@
using Godot;
using Newlon.Components.Plants;
using Newlon.Components.Level;
namespace Newlon.Components.GUI;
public partial class ShovelButton : TextureButton
{
[Export] private PackedScene particles;
private void OnFocusExited()
{
ButtonPressed = false;
}
public override void _Toggled(bool toggledOn)
{
Cursor.Instance.shovel = toggledOn;
Cursor.Instance.UpdateCursor();
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("primary_action") && ButtonPressed)
{
var checkedPosition = (PoolContainer.Instance.Plants.GetGlobalMousePosition() / Utility.Tile).Ceil() * Utility.Tile - new Vector2(20, 14);
for (int i = Utility.LayersCount-1; i >= 0; i--)
{
if (PoolContainer.Instance.EntityField[i].TryGetValue(checkedPosition, out var entity) && entity is RuntimePlantData plantData)
{
plantData.Kill();
PoolContainer.Instance.SpawnParticles(particles, plantData.GlobalPosition + Vector2.Down * Utility.TileHeight/2.0f);
break;
}
}
ButtonPressed = false;
}
}
}

View file

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

12
scripts/gui/SunCounter.cs Normal file
View file

@ -0,0 +1,12 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.GUI;
public partial class SunCounter : Label
{
public override void _Process(double delta)
{
Text = RuntimeLevelData.Instance.SunCount.ToString();
}
}

View file

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

View file

@ -0,0 +1,11 @@
using Godot;
using Newlon;
using System;
public partial class SunCounterImage : Control
{
public override void _Ready()
{
Sun.Counter = this;
}
}

View file

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

View file

@ -0,0 +1,23 @@
using Godot;
using Newlon.Components.GUI.Seedpackets;
namespace Newlon.Components.GUI;
public partial class VeilResizer : TextureProgressBar
{
[Export] private Timer _referenceTimer;
private Seedpacket seedpacket;
public override void _Ready()
{
seedpacket = GetParent<Seedpacket>();
}
public override void _Process(double delta)
{
if (seedpacket.Disabled && _referenceTimer.IsStopped())
Value = 1.0;
else
Value = _referenceTimer.TimeLeft / _referenceTimer.WaitTime;
}
}

View file

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

View file

@ -0,0 +1,36 @@
using Godot;
using Newlon.Components.GUI.Seedpackets;
public partial class AlmanachGrid : GridContainer
{
private PackedScene _plantCard;
[Export]
private bool _zombies;
public override void _Ready()
{
_plantCard = ResourceLoader.Load<PackedScene>("res://scenes/gui/seedpacket.tscn");
if (_zombies)
{
foreach (var resource in GameRegistry.GetZombies())
{
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
AddChild(slot);
slot.SetResource(resource);
slot.SetHandler(new AlmanachHandler(slot));
}
}
else
{
foreach (var resource in GameRegistry.GetPlants())
{
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
AddChild(slot);
slot.SetResource(resource);
slot.SetHandler(new AlmanachHandler(slot));
}
}
}
}

View file

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

View file

@ -0,0 +1,24 @@
using Godot;
using Newlon.Components.GUI.Seedpackets;
namespace Newlon.Components.GUI;
public partial class GridLoader : GridContainer
{
private const string PLANT_RESOURCE_PATH = "res://resources/plants/";
private PackedScene _plantCard;
public override void _Ready()
{
_plantCard = ResourceLoader.Load<PackedScene>("res://scenes/gui/seedpacket.tscn");
foreach(var resource in GameRegistry.GetPlants())
{
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
AddChild(slot);
slot.SetResource(resource);
slot.SetHandler(new ChoosableHandler(slot));
}
}
}

View file

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

View file

@ -0,0 +1,16 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.GUI;
public partial class LevelRunButton : Button
{
[Export] private AnimationPlayer _player;
public override void _Pressed()
{
RuntimeLevelData.Instance.SetLevelState(RuntimeLevelData.LevelStates.Game);
GetTree().Paused = false;
_player.Play("Hide");
}
}

View file

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

View file

@ -0,0 +1,51 @@
using Godot;
using Newlon;
using Newlon.Components;
using Newlon.Components.GUI.Seedpackets;
using Newlon.Components.Plants;
public partial class Previewport : SubViewport
{
private Node current_display;
private Texture2D start_Field;
[Export] private Label title;
[Export] private RichTextLabel description;
public override void _Ready()
{
GetParent().GetViewport().GuiFocusChanged += OnFocusChanged;
start_Field = GetNode<Sprite2D>("FrameField").Texture;
}
public void OnFocusChanged(Control node)
{
if (GetParent<Control>().IsVisibleInTree() == false) return;
if (node is Seedpacket packet)
{
ChangeDisplay(packet.GetResource());
}
}
private void ChangeDisplay(DisplayResource resource)
{
// Expand with updates
if (current_display != null)
{
current_display.QueueFree();
}
if (resource.customFrame != null && resource.customFrame.almanachField != null)
{
GetNode<Sprite2D>("FrameField").Texture = resource.customFrame.almanachField;
}
else
GetNode<Sprite2D>("FrameField").Texture = start_Field;
current_display = resource.Scene.Instantiate();
title.Text = Tr(resource.name_key);
description.Text = Tr(resource.description_key);
AddChild(current_display);
if (current_display is Entity entity)
entity.DisableBrain();
}
}

View file

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

View file

@ -0,0 +1,4 @@
extends RichTextLabel
func _on_meta_clicked(meta: Variant) -> void:
OS.shell_open(meta)

View file

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

View file

@ -0,0 +1,21 @@
extends Node
func _on_play_button_pressed() -> void:
get_tree().change_scene_to_file("res://scenes/prototype_survival.tscn")
$ChannelPlayer.call("Play")
func _on_exit_button_pressed() -> void:
get_tree().quit()
$ChannelPlayer.call("Play")
func _on_button_pressed() -> void:
$"../AboutWindow".popup_centered()
$ChannelPlayer.call("Play")
func _on_almanach_button_pressed() -> void:
$"../Almanach".visible = true
$ChannelPlayer.call("Play")

View file

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

View file

@ -0,0 +1,9 @@
extends AcceptDialog
static var seen = false
func _ready() -> void:
if seen:
return
seen = true
popup_centered()

View file

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

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