using System.Collections.Generic; using System.ComponentModel; using Godot; using Godot.Bridge; using Godot.NativeInterop; [ScriptPath("res://Scripts/UI/SavePrompt.cs")] public class SavePrompt : NinePatchRect { public new class MethodName : NinePatchRect.MethodName { public new static readonly StringName _EnterTree = "_EnterTree"; public new static readonly StringName _Process = "_Process"; } public new class PropertyName : NinePatchRect.PropertyName { public static readonly StringName soul = "soul"; public static readonly StringName text = "text"; public static readonly StringName time = "time"; public static readonly StringName cancel = "cancel"; public static readonly StringName saved = "saved"; } public new class SignalName : NinePatchRect.SignalName { } [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("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(); } } } [EditorBrowsable(EditorBrowsableState.Never)] internal static List GetGodotMethodList() { return new List(2) { new MethodInfo(MethodName._EnterTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null), new MethodInfo(MethodName._Process, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List { new PropertyInfo(Variant.Type.Float, "delta", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false) }, null) }; } [EditorBrowsable(EditorBrowsableState.Never)] protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret) { if (method == MethodName._EnterTree && args.Count == 0) { _EnterTree(); ret = default(godot_variant); return true; } if (method == MethodName._Process && args.Count == 1) { _Process(VariantUtils.ConvertTo(in args[0])); ret = default(godot_variant); return true; } return base.InvokeGodotClassMethod(in method, args, out ret); } [EditorBrowsable(EditorBrowsableState.Never)] protected override bool HasGodotClassMethod(in godot_string_name method) { if (method == MethodName._EnterTree) { return true; } if (method == MethodName._Process) { return true; } return base.HasGodotClassMethod(in method); } [EditorBrowsable(EditorBrowsableState.Never)] protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value) { if (name == PropertyName.soul) { soul = VariantUtils.ConvertTo(in value); return true; } if (name == PropertyName.text) { text = VariantUtils.ConvertTo(in value); return true; } if (name == PropertyName.time) { time = VariantUtils.ConvertTo(in value); return true; } if (name == PropertyName.cancel) { cancel = VariantUtils.ConvertTo(in value); return true; } if (name == PropertyName.saved) { saved = VariantUtils.ConvertTo(in value); return true; } return base.SetGodotClassPropertyValue(in name, in value); } [EditorBrowsable(EditorBrowsableState.Never)] protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value) { if (name == PropertyName.soul) { value = VariantUtils.CreateFrom(in soul); return true; } if (name == PropertyName.text) { value = VariantUtils.CreateFrom(in text); return true; } if (name == PropertyName.time) { value = VariantUtils.CreateFrom(in time); return true; } if (name == PropertyName.cancel) { value = VariantUtils.CreateFrom(in cancel); return true; } if (name == PropertyName.saved) { value = VariantUtils.CreateFrom(in saved); return true; } return base.GetGodotClassPropertyValue(in name, out value); } [EditorBrowsable(EditorBrowsableState.Never)] internal static List GetGodotPropertyList() { return new List { new PropertyInfo(Variant.Type.Object, PropertyName.soul, PropertyHint.NodeType, "Sprite2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true), new PropertyInfo(Variant.Type.Object, PropertyName.text, PropertyHint.NodeType, "RichTextLabel", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true), new PropertyInfo(Variant.Type.Object, PropertyName.time, PropertyHint.NodeType, "RichTextLabel", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true), new PropertyInfo(Variant.Type.Bool, PropertyName.cancel, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false), new PropertyInfo(Variant.Type.Bool, PropertyName.saved, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false) }; } [EditorBrowsable(EditorBrowsableState.Never)] protected override void SaveGodotObjectData(GodotSerializationInfo info) { base.SaveGodotObjectData(info); info.AddProperty(PropertyName.soul, Variant.From(in soul)); info.AddProperty(PropertyName.text, Variant.From(in text)); info.AddProperty(PropertyName.time, Variant.From(in time)); info.AddProperty(PropertyName.cancel, Variant.From(in cancel)); info.AddProperty(PropertyName.saved, Variant.From(in saved)); } [EditorBrowsable(EditorBrowsableState.Never)] protected override void RestoreGodotObjectData(GodotSerializationInfo info) { base.RestoreGodotObjectData(info); if (info.TryGetProperty(PropertyName.soul, out var value)) { soul = value.As(); } if (info.TryGetProperty(PropertyName.text, out var value2)) { text = value2.As(); } if (info.TryGetProperty(PropertyName.time, out var value3)) { time = value3.As(); } if (info.TryGetProperty(PropertyName.cancel, out var value4)) { cancel = value4.As(); } if (info.TryGetProperty(PropertyName.saved, out var value5)) { saved = value5.As(); } } }