421 lines
10 KiB
C#
421 lines
10 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Text;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/UI/LWMenu.cs")]
|
|
public partial class LWMenu : Control
|
|
{
|
|
public enum Menus
|
|
{
|
|
Main,
|
|
Item,
|
|
Mail,
|
|
Settings,
|
|
Stats
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public RichTextLabel mainText;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public RichTextLabel statText;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public RichTextLabel mainOpt;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public RichTextLabel mainText2;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public RichTextLabel[] itemOpt;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Sprite2D soul;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Control bigBox;
|
|
|
|
public static LWMenu instance;
|
|
|
|
public static int lastItem;
|
|
|
|
public Menus currentMenu;
|
|
|
|
private Settings settings;
|
|
|
|
private int option;
|
|
|
|
private int maxOption;
|
|
|
|
private int subOption;
|
|
|
|
private int selected;
|
|
|
|
private static readonly int[] optPos = new int[3] { -40, 10, 68 };
|
|
|
|
private static readonly StringName line = "theme_override_constants/line_separation";
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (!base.Visible)
|
|
{
|
|
return;
|
|
}
|
|
switch (currentMenu)
|
|
{
|
|
case Menus.Main:
|
|
if (Input.IsActionJustPressed(Main.keys[0]))
|
|
{
|
|
option--;
|
|
if (option < 0)
|
|
{
|
|
option = maxOption - 1;
|
|
}
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[1]))
|
|
{
|
|
option++;
|
|
if (option >= maxOption)
|
|
{
|
|
option = 0;
|
|
}
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[4]))
|
|
{
|
|
switch (option)
|
|
{
|
|
case 0:
|
|
if (SaveFile.current.lwItems.Count > 0)
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
currentMenu = Menus.Item;
|
|
StringBuilder stringBuilder2 = new StringBuilder();
|
|
for (int j = 0; j < SaveFile.current.lwItems.Count; j++)
|
|
{
|
|
stringBuilder2.Append(Texts.items[SaveFile.current.lwItems[j]].name + "\n");
|
|
}
|
|
mainText.Text = stringBuilder2.ToString();
|
|
itemOpt[0].Visible = false;
|
|
maxOption = SaveFile.current.lwItems.Count;
|
|
bigBox.Visible = true;
|
|
UpdateMenus();
|
|
}
|
|
else
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[1]);
|
|
}
|
|
break;
|
|
case 1:
|
|
currentMenu = Menus.Stats;
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
break;
|
|
case 2:
|
|
if (SaveFile.current.letters.Count > 0)
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
currentMenu = Menus.Mail;
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
for (int i = 0; i < SaveFile.current.letters.Count; i++)
|
|
{
|
|
if (!SaveFile.current.readLetters.Contains(SaveFile.current.letters[i]))
|
|
{
|
|
stringBuilder.Append("[color=yellow]" + Texts.letters[SaveFile.current.letters[i]].name + "[/color]\n");
|
|
}
|
|
else
|
|
{
|
|
stringBuilder.Append(Texts.letters[SaveFile.current.letters[i]].name + "\n");
|
|
}
|
|
}
|
|
mainText.Text = stringBuilder.ToString();
|
|
maxOption = SaveFile.current.letters.Count;
|
|
bigBox.Visible = true;
|
|
option = 0;
|
|
UpdateMenus();
|
|
}
|
|
else
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[1]);
|
|
}
|
|
break;
|
|
case 3:
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
Exit();
|
|
Talk.DoTalk();
|
|
break;
|
|
case 4:
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
currentMenu = Menus.Settings;
|
|
UpdateMenus();
|
|
break;
|
|
}
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[5]))
|
|
{
|
|
Exit();
|
|
}
|
|
break;
|
|
default:
|
|
if (Input.IsActionJustPressed(Main.keys[5]))
|
|
{
|
|
Return(option);
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
}
|
|
break;
|
|
case Menus.Mail:
|
|
if (Input.IsActionJustPressed(Main.keys[0]) || Input.IsActionJustPressed(Main.keys[2]))
|
|
{
|
|
option--;
|
|
if (option < 0)
|
|
{
|
|
option = maxOption - 1;
|
|
}
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[1]) || Input.IsActionJustPressed(Main.keys[3]))
|
|
{
|
|
option++;
|
|
if (option >= maxOption)
|
|
{
|
|
option = 0;
|
|
}
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[4]))
|
|
{
|
|
Main.inEvent = Coroutine.Start(CommonEvents.ReadLetter(Texts.letters[SaveFile.current.letters[option]], SaveFile.current.letters[option]));
|
|
Exit();
|
|
}
|
|
else if (Input.IsActionJustPressed(Main.keys[5]))
|
|
{
|
|
option = 2;
|
|
Return(option);
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
}
|
|
break;
|
|
case Menus.Item:
|
|
if (Input.IsActionJustPressed(Main.keys[0]) || Input.IsActionJustPressed(Main.keys[2]))
|
|
{
|
|
option--;
|
|
if (option < 0)
|
|
{
|
|
option = maxOption - 1;
|
|
}
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
break;
|
|
}
|
|
if (Input.IsActionJustPressed(Main.keys[1]) || Input.IsActionJustPressed(Main.keys[3]))
|
|
{
|
|
option++;
|
|
if (option >= maxOption)
|
|
{
|
|
option = 0;
|
|
}
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
break;
|
|
}
|
|
if (Input.IsActionJustPressed(Main.keys[4]))
|
|
{
|
|
if (subOption == 0)
|
|
{
|
|
subOption = 1;
|
|
selected = option;
|
|
option = 0;
|
|
maxOption = 3;
|
|
itemOpt[0].Text = "\t\t" + Texts.common[18];
|
|
itemOpt[1].Text = Texts.common[19];
|
|
itemOpt[2].Text = Texts.common[20];
|
|
itemOpt[0].Visible = true;
|
|
UpdateMenus();
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
break;
|
|
}
|
|
lastItem = selected;
|
|
switch (option)
|
|
{
|
|
case 0:
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
Items.UseItem(SaveFile.current.lwItems[selected]);
|
|
Exit();
|
|
break;
|
|
case 1:
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
TextSystem.GetText(Texts.items[SaveFile.current.lwItems[selected]].descriptionLW);
|
|
Player.instance.CallDeferred("StopInput");
|
|
Player.instance.CallDeferred("PartyStop");
|
|
Exit();
|
|
break;
|
|
case 2:
|
|
{
|
|
string tossEvent = Texts.items[SaveFile.current.lwItems[selected]].tossEvent;
|
|
if (tossEvent != null && tossEvent.Length > 0)
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[2]);
|
|
CommonEvents.DoEvent(Texts.items[SaveFile.current.lwItems[selected]].tossEvent);
|
|
Exit();
|
|
}
|
|
else
|
|
{
|
|
Audio.PlaySound(Audio.commonSounds[1]);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
if (subOption == 1 && Input.IsActionJustPressed(Main.keys[5]))
|
|
{
|
|
subOption = 0;
|
|
option = selected;
|
|
maxOption = SaveFile.current.lwItems.Count;
|
|
itemOpt[0].Visible = false;
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
UpdateMenus();
|
|
break;
|
|
}
|
|
if (Input.IsActionJustPressed(Main.keys[5]))
|
|
{
|
|
option = 0;
|
|
}
|
|
goto default;
|
|
case Menus.Settings:
|
|
if (!GodotObject.IsInstanceValid(settings))
|
|
{
|
|
settings = null;
|
|
currentMenu = Menus.Main;
|
|
UpdateMenus();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void Return(int opt = 0)
|
|
{
|
|
currentMenu = Menus.Main;
|
|
option = opt;
|
|
maxOption = 5;
|
|
subOption = 0;
|
|
itemOpt[0].Visible = false;
|
|
bigBox.Visible = false;
|
|
UpdateMenus();
|
|
}
|
|
|
|
public void Open()
|
|
{
|
|
Return();
|
|
Room.current.ProcessMode = ProcessModeEnum.Disabled;
|
|
Player.instance.canInput = false;
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
mainOpt.Text = Texts.common[21] + "\n" + Texts.common[22] + "\n" + Texts.common[23] + "\n" + Texts.common[16] + "\n" + Texts.common[17];
|
|
base.Visible = true;
|
|
CheckItems();
|
|
}
|
|
|
|
private void CheckItems()
|
|
{
|
|
if (!SaveFile.current.lwItems.Contains(Items.IDs.BallOfJunk) && (SaveFile.current.dwWeapon.Count > 0 || SaveFile.current.dwArmor.Count > 0 || SaveFile.current.dwItems.Count > 0))
|
|
{
|
|
SaveFile.current.lwItems.Add(Items.IDs.BallOfJunk);
|
|
}
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
base.Visible = false;
|
|
Player.instance.canInput = true;
|
|
Room.current.ProcessMode = ProcessModeEnum.Inherit;
|
|
Audio.PlaySound(Audio.commonSounds[0]);
|
|
}
|
|
|
|
private string GetEquip(int slot)
|
|
{
|
|
if (Party.party[0].EQUIP[slot] > -1)
|
|
{
|
|
string lwEquip = Texts.items[(Items.IDs)Party.party[0].EQUIP[slot]].lwEquip;
|
|
if (lwEquip != null && lwEquip.Length > 0)
|
|
{
|
|
return Texts.items[(Items.IDs)Party.party[0].EQUIP[slot]].lwEquip;
|
|
}
|
|
}
|
|
if (slot == 1)
|
|
{
|
|
return GetEquip(2);
|
|
}
|
|
if (slot == 1)
|
|
{
|
|
return Texts.common[107];
|
|
}
|
|
return Texts.common[108];
|
|
}
|
|
|
|
private void UpdateMenus()
|
|
{
|
|
soul.Visible = true;
|
|
if (currentMenu != Menus.Stats)
|
|
{
|
|
mainText2.Text = "";
|
|
}
|
|
switch (currentMenu)
|
|
{
|
|
case Menus.Main:
|
|
bigBox.Visible = false;
|
|
soul.Position = new Vector2(-136.5f, -38 + option * 15);
|
|
mainText.Set(line, -1);
|
|
statText.Text = Texts.common[109] + "\n" + Texts.common[91] + "\t" + SaveFile.current.love + "\n" + Texts.common[110] + "\t" + Party.LWHP + "/" + Party.LWMHP + "\n$\t\t" + SaveFile.current.gold;
|
|
break;
|
|
case Menus.Stats:
|
|
mainText.Set(line, -3);
|
|
mainText.Text = Texts.common[109] + "\n\n" + Texts.common[91] + "\t" + SaveFile.current.love + "\n" + Texts.common[110] + "\t" + Party.LWHP + "/" + Party.LWMHP + "\n\n" + Texts.common[112] + "\t" + Party.LWAtk + "\n" + Texts.common[113] + "\t" + Party.LWDef + "\n\n" + Texts.common[115] + " " + GetEquip(0) + "\n" + Texts.common[116] + " " + GetEquip(1) + "\n\n" + Texts.common[117] + " " + SaveFile.current.gold;
|
|
bigBox.Visible = true;
|
|
mainText2.Text = "\n\n\n\n\n" + Texts.common[111] + " " + SaveFile.current.exp + "\n" + Texts.common[114] + " 10";
|
|
break;
|
|
case Menus.Mail:
|
|
mainText.Set(line, 0);
|
|
if (subOption == 0)
|
|
{
|
|
soul.Position = new Vector2(-48f, -87 + option * 16);
|
|
}
|
|
else
|
|
{
|
|
soul.Position = new Vector2(optPos[option], 69f);
|
|
}
|
|
break;
|
|
case Menus.Item:
|
|
mainText.Set(line, 2);
|
|
if (subOption == 0)
|
|
{
|
|
soul.Position = new Vector2(-48f, -87 + option * 18);
|
|
}
|
|
else
|
|
{
|
|
soul.Position = new Vector2(optPos[option], 69f);
|
|
}
|
|
break;
|
|
case Menus.Settings:
|
|
mainText.Text = "";
|
|
soul.Visible = false;
|
|
bigBox.Visible = true;
|
|
bigBox.AddChild(settings = GD.Load<PackedScene>("res://Objects/UI/Settings.tscn").Instantiate<Settings>(PackedScene.GenEditState.Disabled), forceReadableName: false, InternalMode.Disabled);
|
|
settings.Position = new Vector2(33f, 20f);
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|