1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 14:10:45 +00:00
msfs-popout-panel-manager/DomainModel/Profile/UserProfile.cs

136 lines
4.9 KiB
C#
Raw Permalink Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.Shared;
using Newtonsoft.Json;
using PropertyChanged;
using System;
using System.Collections.ObjectModel;
using System.Linq;
namespace MSFSPopoutPanelManager.DomainModel.Profile
{
[SuppressPropertyChangedWarnings]
public class UserProfile : ObservableObject, IComparable<UserProfile>
{
public UserProfile()
{
2024-02-28 02:44:21 +00:00
this.PropertyChanged += (_, e) =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
if (e is PropertyChangedExtendedEventArgs { DisableSave: false })
OnProfileChanged?.Invoke(this, EventArgs.Empty);
if (e.PropertyName == nameof(IsUsedLegacyCameraSystem))
OnPanelConfigChanged();
2023-07-12 22:41:31 +00:00
};
2024-02-28 02:44:21 +00:00
PanelConfigs.CollectionChanged += (_, e) =>
2023-07-12 22:41:31 +00:00
{
switch (e.Action)
{
case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
2024-02-28 02:44:21 +00:00
if (e.NewItems?[0] == null)
2023-07-12 22:41:31 +00:00
return;
2024-02-28 02:44:21 +00:00
((PanelConfig)e.NewItems[0]).PropertyChanged += (_, arg) =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
if (arg is PropertyChangedExtendedEventArgs { DisableSave: false })
OnProfileChanged?.Invoke(this, EventArgs.Empty);
2023-07-12 22:41:31 +00:00
2024-02-29 06:11:56 +00:00
if (arg is PropertyChangedExtendedEventArgs changedArg)
{
if (changedArg.ObjectName == QualifyFullName.Of(nameof(MSFSPopoutPanelManager.DomainModel.Profile.FloatingPanel)) &&
changedArg.PropertyName == nameof(FloatingPanel.IsEnabled))
{
if(PanelConfigs.Any(x => x.FloatingPanel.IsEnabled))
OnUseFloatingPanelChanged?.Invoke(this, true);
else
OnUseFloatingPanelChanged?.Invoke(this, false);
}
}
2024-02-28 02:44:21 +00:00
OnPanelConfigChanged();
2023-07-12 22:41:31 +00:00
};
2024-02-28 02:44:21 +00:00
OnProfileChanged?.Invoke(this, EventArgs.Empty);
OnPanelConfigChanged();
2023-07-12 22:41:31 +00:00
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
2024-02-28 02:44:21 +00:00
OnProfileChanged?.Invoke(this, EventArgs.Empty);
OnPanelConfigChanged();
2023-07-12 22:41:31 +00:00
break;
}
};
InitializeChildPropertyChangeBinding();
}
2024-02-29 06:11:56 +00:00
public event EventHandler<bool> OnUseFloatingPanelChanged;
2024-02-28 02:44:21 +00:00
public event EventHandler OnProfileChanged;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
public Guid Id { get; set; } = Guid.NewGuid();
2023-07-12 22:41:31 +00:00
public string Name { get; set; }
2024-02-28 02:44:21 +00:00
public bool IsLocked { get; set; } = false;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
public ObservableCollection<string> AircraftBindings { get; set; } = new();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
public ObservableCollection<PanelConfig> PanelConfigs { get; set; } = new();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
public ProfileSetting ProfileSetting { get; set; } = new();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
public MsfsGameWindowConfig MsfsGameWindowConfig { get; set; } = new();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
public int PanelSourceCockpitZoomFactor { get; set; } = 50;
public bool IsUsedLegacyCameraSystem { get; set; } = true;
2023-07-12 22:41:31 +00:00
public int CompareTo(UserProfile other)
{
2024-02-28 02:44:21 +00:00
return string.Compare(Name.ToLower(), other.Name.ToLower(), StringComparison.Ordinal);
2023-07-12 22:41:31 +00:00
}
[JsonIgnore]
public bool IsActive { get; set; }
[JsonIgnore]
public bool IsEditingPanelSource { get; set; }
2024-02-28 02:44:21 +00:00
[JsonIgnore]
public bool IsSelectingPanelSource { get; set; }
2023-07-12 22:41:31 +00:00
private bool _isPoppedOut;
[JsonIgnore]
public bool IsPoppedOut
{
2024-02-28 02:44:21 +00:00
get => _isPoppedOut;
2023-07-12 22:41:31 +00:00
set
{
_isPoppedOut = value;
2024-02-28 02:44:21 +00:00
if (value)
return;
foreach (var panelConfig in PanelConfigs)
panelConfig.PanelHandle = IntPtr.MaxValue; // reset panel is popped out status
2023-07-12 22:41:31 +00:00
}
}
[JsonIgnore]
public Guid CurrentMoveResizePanelId { get; set; }
[JsonIgnore]
public bool HasUnidentifiedPanelSource { get; private set; }
[JsonIgnore]
2024-02-28 02:44:21 +00:00
public bool IsDisabledStartPopOut { get; set; }
2023-07-12 22:41:31 +00:00
[JsonIgnore]
2024-02-28 02:44:21 +00:00
public bool HasCustomPanels => PanelConfigs != null && PanelConfigs.Count(p => p.PanelType == PanelType.CustomPopout) > 0;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
private void OnPanelConfigChanged()
2023-07-12 22:41:31 +00:00
{
HasUnidentifiedPanelSource = PanelConfigs.Any(p => p.PanelType == PanelType.CustomPopout && p.PanelSource.X == null);
}
}
}