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

90 lines
2.1 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/UI/SavePrompt.cs")]
public partial class SavePrompt : NinePatchRect
{
[Export(PropertyHint.None, "")]
private Sprite2D soul;
[Export(PropertyHint.None, "")]
private RichTextLabel text;
[Export(PropertyHint.None, "")]
private RichTextLabel time;
private static readonly Vector2[] pos = new Vector2[2]
{
new Vector2(47f, 70f),
new Vector2(106f, 70f)
};
private bool cancel;
private bool saved;
public override void _EnterTree()
{
text.Text = Texts.common[28].ToUpper() + " - " + Texts.common[91] + " " + Party.party[0].LV + "\n[center]" + SaveFile.GetRoomName(Room.current.id) + "\n\n[center]" + Texts.common[98] + "\t\t\t" + Texts.common[99];
time.Text = "[right]" + SaveFile.current.time[2].ToString().PadLeft(3, '0') + ":" + SaveFile.current.time[1].ToString().PadLeft(2, '0');
if (SaveFile.current.flags.Contains(SaveFile.Flags.IsInDW))
{
base.Texture = GD.Load<Texture2D>("res://Sprites/Menus/dwbox.png");
base.PatchMarginBottom = 13;
base.PatchMarginTop = 13;
base.PatchMarginLeft = 13;
base.PatchMarginRight = 13;
}
}
public override void _Process(double delta)
{
if (saved)
{
if (Input.IsActionJustPressed(Main.keys[4]))
{
QueueFree();
}
}
else if (Input.IsActionJustPressed(Main.keys[3]) || Input.IsActionJustPressed(Main.keys[2]))
{
cancel = !cancel;
soul.Position = pos[cancel ? 1u : 0u];
Audio.PlaySound(Audio.commonSounds[0]);
}
else
{
if (!Input.IsActionJustPressed(Main.keys[4]))
{
return;
}
if (!cancel)
{
soul.Visible = false;
time.Visible = false;
saved = true;
if (SaveFile.Save())
{
Audio.PlaySound(Audio.commonSounds[3]);
base.Modulate = Main.colorYellow;
text.Text = "[center]\n" + Texts.common[96];
}
else
{
Audio.PlaySound("snd_error.wav");
base.Modulate = Main.colorRed;
text.Text = "[center][color=red]\n" + Texts.common[97];
}
}
else
{
QueueFree();
}
}
}
}