104 lines
2.7 KiB
C#
104 lines
2.7 KiB
C#
using Godot;
|
|
|
|
namespace KeepersCompound.TMV.UI;
|
|
|
|
public partial class MissionSelector : Control
|
|
{
|
|
public event MissionSelectedEventHandler MissionSelected;
|
|
public delegate void MissionSelectedEventHandler(string campaign, string mission);
|
|
|
|
private FileDialog _FolderSelect;
|
|
private LineEdit _FolderPath;
|
|
private Button _BrowseButton;
|
|
private ItemList _Campaigns;
|
|
private ItemList _Missions;
|
|
private Button _LoadButton;
|
|
private Button _CancelButton;
|
|
|
|
public override void _Ready()
|
|
{
|
|
// TODO: Load initial folderpath from config and prefil everything
|
|
_FolderSelect = GetNode<FileDialog>("%FolderSelect");
|
|
_FolderPath = GetNode<LineEdit>("%FolderPath");
|
|
_BrowseButton = GetNode<Button>("%BrowseButton");
|
|
_Campaigns = GetNode<ItemList>("%Campaigns");
|
|
_Missions = GetNode<ItemList>("%Missions");
|
|
_LoadButton = GetNode<Button>("%LoadButton");
|
|
_CancelButton = GetNode<Button>("%CancelButton");
|
|
|
|
_BrowseButton.Pressed += () => _FolderSelect.Visible = true;
|
|
_FolderSelect.DirSelected += SetInstallPath;
|
|
_FolderPath.TextSubmitted += SetInstallPath;
|
|
_Missions.ItemSelected += (long _) => _LoadButton.Disabled = false;
|
|
_Campaigns.ItemSelected += BuildMissionList;
|
|
_LoadButton.Pressed += EmitLoadMission;
|
|
_CancelButton.Pressed += () => Visible = false;
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
|
{
|
|
if (keyEvent.Keycode == Key.Escape)
|
|
{
|
|
Visible = !Visible;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SetInstallPath(string path)
|
|
{
|
|
_FolderPath.Text = path;
|
|
if (Context.Instance.PathManager.Init(path))
|
|
{
|
|
BuildCampaignList();
|
|
}
|
|
}
|
|
|
|
private void BuildCampaignList()
|
|
{
|
|
_Campaigns.Clear();
|
|
_Missions.Clear();
|
|
_LoadButton.Disabled = true;
|
|
|
|
var pathManager = Context.Instance.PathManager;
|
|
_Campaigns.AddItem("Original Missions");
|
|
foreach (var campaign in pathManager.GetCampaignNames())
|
|
{
|
|
_Campaigns.AddItem(campaign);
|
|
}
|
|
}
|
|
|
|
private void BuildMissionList(long idx)
|
|
{
|
|
_Missions.Clear();
|
|
_LoadButton.Disabled = true;
|
|
|
|
var pathManager = Context.Instance.PathManager;
|
|
var campaignName = _Campaigns.GetItemText((int)idx);
|
|
var missionNames = pathManager.GetMissionNames(idx == 0 ? null : campaignName);
|
|
foreach (var mission in missionNames)
|
|
{
|
|
_Missions.AddItem(mission);
|
|
}
|
|
}
|
|
|
|
private void EmitLoadMission()
|
|
{
|
|
var campaignIdxs = _Campaigns.GetSelectedItems();
|
|
var missionIdxs = _Missions.GetSelectedItems();
|
|
if (campaignIdxs.IsEmpty() || missionIdxs.IsEmpty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
var campaignIdx = campaignIdxs[0];
|
|
var missionIdx = missionIdxs[0];
|
|
var campaignName = campaignIdx == 0 ? null : _Campaigns.GetItemText(campaignIdx);
|
|
var missionName = _Missions.GetItemText(missionIdx);
|
|
MissionSelected(campaignName, missionName);
|
|
|
|
Visible = false;
|
|
}
|
|
}
|