2022-06-30 23:53:08 +00:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using MSFSPopoutPanelManager.Model;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.WpfApp.ViewModel
|
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public class DataStore : ObservableObject
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
private int _activeProfileId;
|
2022-06-30 23:53:08 +00:00
|
|
|
|
private AppSetting _appSetting;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
|
|
|
|
public event EventHandler OnActiveUserProfileChanged;
|
|
|
|
|
public event EventHandler OnAllowEditChanged;
|
|
|
|
|
|
|
|
|
|
public DataStore()
|
|
|
|
|
{
|
|
|
|
|
_activeProfileId = -1;
|
|
|
|
|
_allowEdit = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public AppSetting AppSetting
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _appSetting;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_appSetting = value;
|
|
|
|
|
|
|
|
|
|
if (_appSetting != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
IsEnableAutoPopOutPanel = _appSetting.AutoPopOutPanels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bubble event up to this 'DataStore' level
|
|
|
|
|
_appSetting.AutoPopOutPanelsChanged += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
IsEnableAutoPopOutPanel = e.Value;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
|
|
|
|
public ObservableCollection<UserProfile> UserProfiles { get; set; }
|
|
|
|
|
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public ObservableCollection<PanelSourceCoordinate> ActiveProfilePanelCoordinates
|
|
|
|
|
{
|
|
|
|
|
get
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (ActiveUserProfile == null)
|
|
|
|
|
return new ObservableCollection<PanelSourceCoordinate>();
|
|
|
|
|
else
|
2022-06-30 23:53:08 +00:00
|
|
|
|
return ActiveUserProfile.PanelSourceCoordinates;
|
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
2022-06-30 23:53:08 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public ObservableCollection<PanelConfig> ActiveProfilePanelConfigs
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ActiveUserProfile == null)
|
|
|
|
|
return new ObservableCollection<PanelConfig>();
|
|
|
|
|
else
|
|
|
|
|
return ActiveUserProfile.PanelConfigs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserProfile ActiveUserProfile
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ActiveUserProfileId == -1)
|
|
|
|
|
return null;
|
|
|
|
|
else
|
|
|
|
|
return UserProfiles.ToList().Find(x => x.ProfileId == ActiveUserProfileId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _allowEdit;
|
|
|
|
|
public bool AllowEdit
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _allowEdit;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
if (value != _allowEdit)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
_allowEdit = value;
|
2022-06-30 23:53:08 +00:00
|
|
|
|
OnAllowEditChanged?.Invoke(this, null);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IntPtr ApplicationHandle { get; set; }
|
|
|
|
|
|
|
|
|
|
public Window ApplicationWindow { get; set; }
|
|
|
|
|
|
|
|
|
|
public int ActiveUserProfileId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _activeProfileId;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_activeProfileId = value;
|
|
|
|
|
|
|
|
|
|
// Set active profile flag
|
|
|
|
|
UserProfiles.ToList().ForEach(p => p.IsActive = false);
|
|
|
|
|
var profile = UserProfiles.ToList().Find(p => p.ProfileId == value);
|
2022-06-30 23:53:08 +00:00
|
|
|
|
if (profile != null)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
profile.IsActive = true;
|
|
|
|
|
|
|
|
|
|
OnActiveUserProfileChanged?.Invoke(this, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasActiveUserProfileId
|
|
|
|
|
{
|
|
|
|
|
get { return ActiveUserProfileId != -1; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CurrentMsfsPlaneTitle { get; set; }
|
|
|
|
|
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public bool HasCurrentMsfsPlaneTitle
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
get { return !String.IsNullOrEmpty(CurrentMsfsPlaneTitle); }
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 22:07:30 +00:00
|
|
|
|
public bool IsAircraftBoundToProfile
|
2022-04-18 03:38:33 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ActiveUserProfile == null)
|
|
|
|
|
return false;
|
2022-06-30 23:53:08 +00:00
|
|
|
|
|
2022-04-18 16:24:00 +00:00
|
|
|
|
return ActiveUserProfile.BindingAircraftLiveries.ToList().Exists(p => p == CurrentMsfsPlaneTitle);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsAllowedDeleteAircraftBinding
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ActiveUserProfile == null || !HasCurrentMsfsPlaneTitle)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-04-18 16:24:00 +00:00
|
|
|
|
var uProfile = UserProfiles.ToList().Find(u => u.BindingAircraftLiveries.ToList().Exists(p => p == CurrentMsfsPlaneTitle));
|
2022-04-18 03:38:33 +00:00
|
|
|
|
if (uProfile != null && uProfile.ProfileId != ActiveUserProfileId)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-04-18 16:24:00 +00:00
|
|
|
|
return ActiveUserProfile.BindingAircraftLiveries.ToList().Exists(p => p == CurrentMsfsPlaneTitle);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsAllowedAddAircraftBinding
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ActiveUserProfile == null || !HasCurrentMsfsPlaneTitle)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-04-18 16:24:00 +00:00
|
|
|
|
var uProfile = UserProfiles.ToList().Find(u => u.BindingAircraftLiveries.ToList().Exists(p => p == CurrentMsfsPlaneTitle));
|
2022-04-18 03:38:33 +00:00
|
|
|
|
if (uProfile != null && uProfile.ProfileId != ActiveUserProfileId)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-04-18 16:24:00 +00:00
|
|
|
|
return !ActiveUserProfile.BindingAircraftLiveries.ToList().Exists(p => p == CurrentMsfsPlaneTitle);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public bool ElectricalMasterBatteryStatus { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsSimulatorStarted { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsEnteredFlight { get; set; }
|
|
|
|
|
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public bool IsEnableAutoPopOutPanel { get; set; }
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
2022-06-30 23:53:08 +00:00
|
|
|
|
}
|