1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 13:50:14 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/HudBarViewModel.cs

87 lines
2.6 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.Orchestration;
using Prism.Commands;
using System;
using System.Linq;
using System.Timers;
using System.Windows;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class HudBarViewModel : BaseViewModel
{
2024-02-28 02:44:21 +00:00
private readonly FlightSimOrchestrator _flightSimOrchestrator;
2023-07-12 22:41:31 +00:00
public ICommand IncreaseSimRateCommand { get; }
public ICommand DecreaseSimRateCommand { get; }
public ICommand StartStopTimerCommand { get; }
public ICommand ResetTimerCommand { get; }
public ICommand CloseCommand { get; }
public Guid PanelId { get; set; }
2024-02-28 02:44:21 +00:00
public PanelConfig PanelConfig => ActiveProfile.PanelConfigs.FirstOrDefault(p => p.Id == PanelId);
2023-07-12 22:41:31 +00:00
public bool IsTimerStarted { get; private set; }
public DateTime Timer { get; set; }
2024-02-28 02:44:21 +00:00
public string HudBarTypeText => ActiveProfile.ProfileSetting.HudBarConfig.HudBarType.ToString().Replace("_", " ");
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
private readonly Timer _clock;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
public HudBarViewModel(SharedStorage sharedStorage, FlightSimOrchestrator flightSimOrchestrator) : base(sharedStorage)
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
_flightSimOrchestrator = flightSimOrchestrator;
2023-07-12 22:41:31 +00:00
IncreaseSimRateCommand = new DelegateCommand(OnIncreaseSimRate);
DecreaseSimRateCommand = new DelegateCommand(OnDecreaseSimRate);
StartStopTimerCommand = new DelegateCommand(OnStartStopTimer);
ResetTimerCommand = new DelegateCommand(OnResetTimer);
CloseCommand = new DelegateCommand(OnClose);
Timer = new DateTime();
_clock = new Timer();
_clock.Interval = 1000;
_clock.Enabled = false;
2024-02-28 02:44:21 +00:00
_clock.Elapsed += (_, _) => Application.Current.Dispatcher.Invoke(() => Timer = Timer.AddSeconds(1));
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
_flightSimOrchestrator.SetHudBarConfig();
2023-07-12 22:41:31 +00:00
}
private void OnIncreaseSimRate()
{
2024-02-28 02:44:21 +00:00
_flightSimOrchestrator.IncreaseSimRate();
2023-07-12 22:41:31 +00:00
}
private void OnDecreaseSimRate()
{
2024-02-28 02:44:21 +00:00
_flightSimOrchestrator.DecreaseSimRate();
2023-07-12 22:41:31 +00:00
}
private void OnStartStopTimer()
{
IsTimerStarted = !IsTimerStarted;
_clock.Enabled = IsTimerStarted;
}
private void OnResetTimer()
{
IsTimerStarted = false;
_clock.Enabled = false;
Timer = new DateTime();
}
private void OnClose()
{
2024-02-28 02:44:21 +00:00
_flightSimOrchestrator.StopHudBar();
2023-07-12 22:41:31 +00:00
}
}
}