|
| 1 | +using System; |
| 2 | +using FunkEngine; |
| 3 | +using Godot; |
| 4 | + |
| 5 | +public partial class CreditsMenu : Control, IFocusableMenu |
| 6 | +{ |
| 7 | + public static readonly string LoadPath = "res://Scenes/UI/Options/Credits.tscn"; |
| 8 | + |
| 9 | + [Export] |
| 10 | + public Label CreditsText; |
| 11 | + |
| 12 | + [Export] |
| 13 | + public float ScrollSpeed = 50f; |
| 14 | + |
| 15 | + public float FadeStartY = 0; |
| 16 | + public float FadeEndY = -400f; |
| 17 | + |
| 18 | + [Export] |
| 19 | + public float RestartPositionY = 800f; |
| 20 | + |
| 21 | + [Export] |
| 22 | + private Button _returnButton; |
| 23 | + |
| 24 | + public IFocusableMenu Prev { get; set; } |
| 25 | + |
| 26 | + public override void _Ready() |
| 27 | + { |
| 28 | + if (CreditsText != null) |
| 29 | + { |
| 30 | + CreditsText.Position = new Vector2(CreditsText.Position.X, RestartPositionY); |
| 31 | + FadeEndY = -CreditsText.Size.Y; |
| 32 | + } |
| 33 | + _returnButton.Pressed += ReturnToPrev; |
| 34 | + _returnButton.GrabFocus(); |
| 35 | + } |
| 36 | + |
| 37 | + public void ResumeFocus() |
| 38 | + { |
| 39 | + ProcessMode = ProcessModeEnum.Inherit; |
| 40 | + _returnButton.GrabFocus(); |
| 41 | + } |
| 42 | + |
| 43 | + public void PauseFocus() |
| 44 | + { |
| 45 | + ProcessMode = ProcessModeEnum.Disabled; |
| 46 | + } |
| 47 | + |
| 48 | + public void OpenMenu(IFocusableMenu prev) |
| 49 | + { |
| 50 | + Prev = prev; |
| 51 | + Prev.PauseFocus(); |
| 52 | + _returnButton.GrabFocus(); |
| 53 | + } |
| 54 | + |
| 55 | + public void ReturnToPrev() |
| 56 | + { |
| 57 | + Prev.ResumeFocus(); |
| 58 | + QueueFree(); |
| 59 | + } |
| 60 | + |
| 61 | + public override void _Input(InputEvent @event) |
| 62 | + { |
| 63 | + if (@event.IsActionPressed("ui_cancel")) |
| 64 | + { |
| 65 | + ReturnToPrev(); |
| 66 | + GetViewport().SetInputAsHandled(); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + public override void _Process(double delta) |
| 71 | + { |
| 72 | + if (CreditsText == null) |
| 73 | + return; |
| 74 | + |
| 75 | + CreditsText.Position += Vector2.Up * (float)(ScrollSpeed * delta); |
| 76 | + |
| 77 | + float alpha = Mathf.Clamp( |
| 78 | + 1 - (CreditsText.GlobalPosition.Y - FadeStartY) / (FadeEndY - FadeStartY), |
| 79 | + 0, |
| 80 | + 1 |
| 81 | + ); |
| 82 | + CreditsText.Modulate = new Color(1, 1, 1, alpha); |
| 83 | + |
| 84 | + if (CreditsText.GlobalPosition.Y < -CreditsText.Size.Y) |
| 85 | + { |
| 86 | + CreditsText.Position = new Vector2(CreditsText.Position.X, RestartPositionY); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments