83 lines
1.5 KiB
C#
83 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/UI/GenericList.cs")]
|
|
public partial class GenericList : RichTextLabel
|
|
{
|
|
[Signal]
|
|
public delegate void SelectedEventHandler();
|
|
|
|
[Signal]
|
|
public delegate void ScrolledEventHandler();
|
|
|
|
public string[] options;
|
|
|
|
public int maxItems = 6;
|
|
|
|
public int current;
|
|
|
|
private float hold;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Sprite2D soul;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public ScrollBar scrollBar;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public RichTextLabel label;
|
|
|
|
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
CallDeferred(MethodName.Populate);
|
|
}
|
|
|
|
public void Populate()
|
|
{
|
|
base.Text = "";
|
|
for (int i = 0; i < options.Length; i++)
|
|
{
|
|
base.Text = base.Text + options[i] + "\n";
|
|
}
|
|
scrollBar.Visible = options.Length >= maxItems;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (Input.IsActionJustPressed(Main.keys[0]))
|
|
{
|
|
Scroll(-1);
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[1]))
|
|
{
|
|
Scroll(1);
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[4]))
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
EmitSignal(SignalName.Selected);
|
|
}
|
|
}
|
|
|
|
private void Scroll(in int amt)
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
current = Mathf.Clamp(current + amt, 0, options.Length - 1);
|
|
UpdateCursor();
|
|
EmitSignal(SignalName.Scrolled);
|
|
}
|
|
|
|
private void UpdateCursor()
|
|
{
|
|
soul.Position = new Vector2(-8f, 8 + current * 15);
|
|
}
|
|
|
|
|
|
}
|