mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-11-24 06:40:09 +00:00
43caff1ca9
commit 2bbda3c4e4969fdf05566908fde01f1c9e4e23f7 Author: Stanley <hawkeyesk@outlook.com> Date: Mon Sep 5 23:54:39 2022 -0400 Added in-game panel support commit ec29b0ec2612b10e45ab9a73c10b88a98fcf6eaf Author: Stanley <hawkeyesk@outlook.com> Date: Sun Sep 4 21:21:37 2022 -0400 Added in-game panel support commit 97edc184f349e1fde74a15a643fb90fb9bd90395 Author: Stanley <hawkeyesk@outlook.com> Date: Thu Sep 1 18:08:44 2022 -0400 Update touch panel commit da48ca0a272290466952c5c1bd1ca035d56f930c Author: Stanley <hawkeyesk@outlook.com> Date: Mon Aug 29 22:19:38 2022 -0400 Added pop out panel temporary display commit 701346193804f93616b0e6e2222d9d55223f516f Author: Stanley <hawkeyesk@outlook.com> Date: Wed Aug 24 10:33:59 2022 -0400 Added auto resize window display mode commit 98cbcd949f1555b44db22267ce5c54858bef47cd Author: Stanley <hawkeyesk@outlook.com> Date: Wed Aug 24 09:39:38 2022 -0400 Added auto resize window display mode
221 lines
7.5 KiB
C#
221 lines
7.5 KiB
C#
using MSFSPopoutPanelManager.Shared;
|
|
using MSFSPopoutPanelManager.UserDataAgent;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
|
|
namespace MSFSPopoutPanelManager.Orchestration
|
|
{
|
|
public class ProfileData : ObservableObject
|
|
{
|
|
public event PropertyChangedEventHandler ActiveProfileChanged;
|
|
|
|
public ProfileData()
|
|
{
|
|
Profiles = new ObservableCollection<Profile>();
|
|
}
|
|
|
|
public ObservableCollection<Profile> Profiles { get; private set; }
|
|
|
|
public FlightSimData FlightSimData { private get; set; }
|
|
|
|
public AppSettingData AppSettingData { private get; set; }
|
|
|
|
public int AddProfile(string profileName)
|
|
{
|
|
var newProfileId = ProfileManager.AddProfile(profileName, Profiles);
|
|
UpdateActiveProfile(newProfileId);
|
|
AppSettingData.AppSetting.LastUsedProfileId = newProfileId;
|
|
return newProfileId;
|
|
}
|
|
|
|
public int AddProfile(string profileName, int copyFromProfileId)
|
|
{
|
|
var newProfileId = ProfileManager.AddProfile(profileName, copyFromProfileId, Profiles);
|
|
UpdateActiveProfile(newProfileId);
|
|
AppSettingData.AppSetting.LastUsedProfileId = newProfileId;
|
|
return newProfileId;
|
|
}
|
|
|
|
public bool DeleteProfile(int profileId)
|
|
{
|
|
if (ActiveProfile == null)
|
|
return false;
|
|
|
|
var success = ProfileManager.DeleteProfile(profileId, Profiles);
|
|
UpdateActiveProfile(-1);
|
|
return true;
|
|
}
|
|
|
|
public void AddProfileBinding(string aircraft, int activeProfileId)
|
|
{
|
|
if (ActiveProfile == null)
|
|
return;
|
|
|
|
ProfileManager.AddProfileBinding(aircraft, activeProfileId, Profiles);
|
|
RefreshProfile();
|
|
}
|
|
|
|
public void DeleteProfileBinding(string aircraft, int activeProfileId)
|
|
{
|
|
if (ActiveProfile == null)
|
|
return;
|
|
|
|
ProfileManager.DeleteProfileBinding(aircraft, activeProfileId, Profiles);
|
|
RefreshProfile();
|
|
}
|
|
|
|
public void ReadProfiles()
|
|
{
|
|
Profiles = new ObservableCollection<Profile>(ProfileManager.ReadProfiles());
|
|
}
|
|
|
|
public void WriteProfiles()
|
|
{
|
|
ProfileManager.WriteProfiles(Profiles);
|
|
}
|
|
|
|
public void UpdateActiveProfile(int profileId)
|
|
{
|
|
if (profileId == -1 && Profiles.Count > 0)
|
|
ActiveProfile = Profiles.FirstOrDefault(p => p.ProfileId == Profiles[0].ProfileId);
|
|
else if (profileId == -1 || Profiles.Count == 0)
|
|
ActiveProfile = null;
|
|
else
|
|
ActiveProfile = Profiles.FirstOrDefault(p => p.ProfileId == profileId);
|
|
|
|
// Set active profile flag, this is used only for MVVM binding
|
|
Profiles.ToList().ForEach(p => p.IsActive = false);
|
|
|
|
if (ActiveProfile != null)
|
|
{
|
|
ActiveProfile.IsActive = true;
|
|
AppSettingData.AppSetting.LastUsedProfileId = ActiveProfile.ProfileId;
|
|
}
|
|
else
|
|
{
|
|
AppSettingData.AppSetting.LastUsedProfileId = -1;
|
|
}
|
|
|
|
ActiveProfileChanged?.Invoke(this, null);
|
|
}
|
|
|
|
public Profile ActiveProfile { get; private set; }
|
|
|
|
public bool HasActiveProfile { get { return ActiveProfile != null; } }
|
|
|
|
public bool IsAircraftBoundToProfile
|
|
{
|
|
get
|
|
{
|
|
if (ActiveProfile == null)
|
|
return false;
|
|
|
|
return ActiveProfile.BindingAircrafts.Any(p => p == FlightSimData.CurrentMsfsAircraft);
|
|
}
|
|
}
|
|
|
|
public bool IsAllowedDeleteAircraftBinding
|
|
{
|
|
get
|
|
{
|
|
if (ActiveProfile == null || !FlightSimData.HasCurrentMsfsAircraft)
|
|
return false;
|
|
|
|
var uProfile = Profiles.FirstOrDefault(u => u.BindingAircrafts.Any(p => p == FlightSimData.CurrentMsfsAircraft));
|
|
if (uProfile != null && uProfile.ProfileId != ActiveProfile.ProfileId)
|
|
return false;
|
|
|
|
return ActiveProfile.BindingAircrafts.Any(p => p == FlightSimData.CurrentMsfsAircraft);
|
|
}
|
|
}
|
|
|
|
public bool IsAllowedAddAircraftBinding
|
|
{
|
|
get
|
|
{
|
|
if (ActiveProfile == null || !FlightSimData.HasCurrentMsfsAircraft)
|
|
return false;
|
|
|
|
var uProfile = Profiles.FirstOrDefault(u => u.BindingAircrafts.Any(p => p == FlightSimData.CurrentMsfsAircraft));
|
|
if (uProfile != null && uProfile.ProfileId != ActiveProfile.ProfileId)
|
|
return false;
|
|
|
|
if (FlightSimData == null || ActiveProfile.BindingAircrafts == null)
|
|
return false;
|
|
|
|
return ActiveProfile == null ? false : !ActiveProfile.BindingAircrafts.Any(p => p == FlightSimData.CurrentMsfsAircraft);
|
|
}
|
|
}
|
|
|
|
public void RefreshProfile()
|
|
{
|
|
int currentProfileId;
|
|
if (ActiveProfile == null)
|
|
currentProfileId = -1;
|
|
else
|
|
currentProfileId = ActiveProfile.ProfileId;
|
|
|
|
ActiveProfile = null;
|
|
UpdateActiveProfile(currentProfileId);
|
|
}
|
|
|
|
public void AutoSwitchProfile()
|
|
{
|
|
// Automatic switching of active profile when SimConnect active aircraft changes
|
|
if (Profiles != null && !string.IsNullOrEmpty(FlightSimData.CurrentMsfsAircraft))
|
|
{
|
|
var matchedProfile = Profiles.FirstOrDefault(p => p.BindingAircrafts.Any(t => t == FlightSimData.CurrentMsfsAircraft));
|
|
if (matchedProfile != null)
|
|
UpdateActiveProfile(matchedProfile.ProfileId);
|
|
}
|
|
}
|
|
|
|
// This is to migrate profile binding from aircraft livery to aircraft name
|
|
// Started in v3.4.2
|
|
public void MigrateLiveryToAircraftBinding(string liveryName, string aircraftName)
|
|
{
|
|
bool hasChanges = false;
|
|
if (Profiles != null && !string.IsNullOrEmpty(liveryName) && !string.IsNullOrEmpty(aircraftName))
|
|
{
|
|
var matchedProfile = Profiles.FirstOrDefault(p => p.BindingAircraftLiveries.Any(t => t == liveryName));
|
|
|
|
if (matchedProfile != null && !matchedProfile.BindingAircrafts.Any(a => a == aircraftName))
|
|
{
|
|
matchedProfile.BindingAircrafts.Add(aircraftName);
|
|
hasChanges = true;
|
|
}
|
|
|
|
if (matchedProfile != null)
|
|
{
|
|
matchedProfile.BindingAircraftLiveries.Remove(liveryName);
|
|
hasChanges = true;
|
|
}
|
|
|
|
if (hasChanges)
|
|
{
|
|
WriteProfiles();
|
|
RefreshProfile();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void MigrateLiveryToAircraftBinding()
|
|
{
|
|
MigrateLiveryToAircraftBinding(FlightSimData.CurrentMsfsLiveryTitle, FlightSimData.CurrentMsfsAircraft);
|
|
}
|
|
|
|
public void SaveMsfsGameWindowConfig()
|
|
{
|
|
if (ActiveProfile == null)
|
|
return;
|
|
|
|
var msfsGameWindowConfig = WindowsAgent.WindowActionManager.GetMsfsGameWindowLocation();
|
|
if (msfsGameWindowConfig.IsValid)
|
|
{
|
|
ActiveProfile.MsfsGameWindowConfig = msfsGameWindowConfig;
|
|
WriteProfiles();
|
|
}
|
|
}
|
|
}
|
|
}
|