2023-07-12 22:41:31 +00:00
|
|
|
|
using MSFSPopoutPanelManager.DomainModel.Profile;
|
2022-08-02 15:51:28 +00:00
|
|
|
|
using System.Linq;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.Orchestration
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
public class ProfileOrchestrator : BaseOrchestrator
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
public ProfileOrchestrator(SharedStorage sharedStorage) : base(sharedStorage)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2022-08-02 15:51:28 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public void AddProfile(string profileName, UserProfile copiedProfile)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Reset current profile
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.ResetActiveProfile();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
|
|
|
|
if (copiedProfile == null)
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.AddProfile(profileName);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
else
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.AddProfile(profileName, copiedProfile);
|
2022-08-02 15:51:28 +00:00
|
|
|
|
|
|
|
|
|
// Automatically bind aircraft
|
2024-02-28 02:44:21 +00:00
|
|
|
|
var boundProfile = ProfileData.Profiles.FirstOrDefault(p => p.AircraftBindings.Any(a => a == FlightSimData.AircraftName));
|
|
|
|
|
if (boundProfile == null && FlightSimData.HasAircraftName)
|
2022-08-02 15:51:28 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.ActiveProfile.AircraftBindings.Add(FlightSimData.AircraftName);
|
|
|
|
|
ProfileData.WriteProfiles();
|
|
|
|
|
ProfileData.RefreshProfile();
|
2022-08-02 15:51:28 +00:00
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteActiveProfile()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.DeleteActiveProfile();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveToNextProfile()
|
|
|
|
|
{
|
|
|
|
|
// Reset current profile
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.ResetActiveProfile();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
var newProfileIndex = ProfileData.Profiles.IndexOf(ProfileData.ActiveProfile) + 1;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (newProfileIndex >= ProfileData.Profiles.Count)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
newProfileIndex = 0;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.SetActiveProfile(newProfileIndex);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveToPreviousProfile()
|
|
|
|
|
{
|
|
|
|
|
// Reset current profile
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.ResetActiveProfile();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
var newProfileIndex = ProfileData.Profiles.IndexOf(ProfileData.ActiveProfile) - 1;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
|
|
|
|
if (newProfileIndex < 0)
|
2024-02-28 02:44:21 +00:00
|
|
|
|
newProfileIndex = ProfileData.Profiles.Count - 1;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ProfileData.SetActiveProfile(newProfileIndex);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public void ChangeProfile(UserProfile profile)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ProfileData != null)
|
|
|
|
|
ProfileData.SetActiveProfile(profile.Id);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 23:21:42 +00:00
|
|
|
|
public void AddProfileBinding(string bindingAircraft)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ProfileData.ActiveProfile != null && bindingAircraft != null)
|
|
|
|
|
ProfileData.AddProfileBinding(bindingAircraft);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 23:21:42 +00:00
|
|
|
|
public void DeleteProfileBinding(string bindingAircraft)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ProfileData.ActiveProfile != null && bindingAircraft != null)
|
|
|
|
|
ProfileData.DeleteProfileBinding(bindingAircraft);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddPanel()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
var panelConfig = new PanelConfig
|
|
|
|
|
{
|
|
|
|
|
PanelType = PanelType.CustomPopout,
|
|
|
|
|
PanelSource =
|
|
|
|
|
{
|
|
|
|
|
Color = PanelConfigColors.GetNextAvailableColor(ProfileData.ActiveProfile.PanelConfigs.ToList())
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
ProfileData.ActiveProfile.PanelConfigs.Add(panelConfig);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|