2025-05-13 19:22:01 +08:00

201 lines
4.4 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/UI/StorageMenu.cs")]
public partial class StorageMenu : Control
{
[Export(PropertyHint.None, "")]
private RichTextLabel listStore;
[Export(PropertyHint.None, "")]
private RichTextLabel listItem;
[Export(PropertyHint.None, "")]
private RichTextLabel spaceItem;
[Export(PropertyHint.None, "")]
private RichTextLabel spaceStore;
[Export(PropertyHint.None, "")]
private RichTextLabel help;
[Export(PropertyHint.None, "")]
private ScrollBar[] bars;
[Export(PropertyHint.None, "")]
private Node2D soul;
private int[] listLow = new int[2] { 5, 5 };
private int[] option = new int[2];
private string[][] names = new string[2][];
private int selectedList;
private float holdTime;
private float holdDelay = 7f;
private List<Items.IDs>[] listRef = new List<Items.IDs>[2];
private const int maxList = 6;
private const int defaultDelay = 7;
private const int holdFor = 30;
private const string blankSlot = "----------";
private const float listLine = 17f;
public override void _EnterTree()
{
Player.instance.canInput = false;
for (int i = 0; i < 2; i++)
{
bars[i].max = ((i == 0) ? 12 : 48);
}
help.Text = "[center]" + Texts.common[120];
GetNode<RichTextLabel>("Header1").Text = "[center]" + Texts.common[118];
GetNode<RichTextLabel>("Header2").Text = "[center]" + Texts.common[119];
UpdateLists();
}
public override void _Process(double delta)
{
Player.instance.canInput = false;
bool flag = Input.IsActionJustPressed(Main.keys[0]);
bool flag2 = Input.IsActionJustPressed(Main.keys[1]);
if (Input.IsActionPressed(Main.keys[0]))
{
holdTime += Main.deltaTime;
if (holdTime > 30f)
{
holdDelay -= Main.deltaTime;
if (holdDelay <= 0f)
{
flag = true;
holdDelay = 7f;
}
}
}
else if (Input.IsActionPressed(Main.keys[1]))
{
holdTime += Main.deltaTime;
if (holdTime > 30f)
{
holdDelay -= Main.deltaTime;
if (holdDelay <= 0f)
{
flag2 = true;
holdDelay = 7f;
}
}
}
else
{
holdTime = 0f;
holdDelay = 0f;
}
if (flag)
{
Audio.PlaySound(Audio.commonSounds[0]);
if (option[selectedList] > 0)
{
option[selectedList]--;
if (listLow[selectedList] - 6 + 1 > option[selectedList])
{
listLow[selectedList]--;
}
}
UpdateCursor();
}
else if (flag2)
{
Audio.PlaySound(Audio.commonSounds[0]);
if (option[selectedList] < names[selectedList].Length - 1)
{
option[selectedList]++;
if (listLow[selectedList] < option[selectedList])
{
listLow[selectedList]++;
}
}
UpdateCursor();
}
else if (Input.IsActionJustPressed(Main.keys[2]) || Input.IsActionJustPressed(Main.keys[3]))
{
Audio.PlaySound(Audio.commonSounds[0]);
selectedList = ((selectedList == 0) ? 1 : 0);
UpdateCursor();
}
else if (Input.IsActionJustPressed(Main.keys[4]))
{
if (option[selectedList] < listRef[selectedList].Count)
{
Audio.PlaySound(Audio.commonSounds[2]);
Items.IDs item = listRef[selectedList][option[selectedList]];
listRef[selectedList].RemoveAt(option[selectedList]);
listRef[(selectedList == 0) ? 1u : 0u].Add(item);
UpdateLists();
}
else
{
Audio.PlaySound(Audio.commonSounds[1]);
}
}
else if (Input.IsActionJustPressed(Main.keys[5]))
{
Audio.PlaySound(Audio.commonSounds[0]);
QueueFree();
Player.instance.canInput = Main.inEvent == null;
}
}
private void UpdateCursor()
{
soul.Position = new Vector2((selectedList == 0) ? 151 : 15, 44f + 17f * (float)(option[selectedList] - listLow[selectedList] + 6 - 1));
for (int i = 0; i < 2; i++)
{
DWMenu.UpdateEquipListCurrent(ref listLow[i], (i == 0) ? listItem : listStore, ref names[i]);
bars[i].current = option[i];
bars[i].Update();
}
}
private void UpdateLists()
{
for (int i = 0; i < 2; i++)
{
names[i] = new string[(i == 0) ? 12 : 48];
listRef[i] = ((i == 0) ? SaveFile.current.dwItems : SaveFile.current.storage);
for (int j = 0; j < names[i].Length; j++)
{
if (j < listRef[i].Count)
{
names[i][j] = Texts.items[listRef[i][j]].name;
}
else
{
names[i][j] = "----------";
}
}
string text = Texts.common[44].Replace("@", (names[i].Length - listRef[i].Count).ToString());
if (i == 0)
{
spaceItem.Text = text;
}
else
{
spaceStore.Text = text;
}
}
UpdateCursor();
}
}