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

82 lines
2.7 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.Orchestration;
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows;
using System.Windows.Documents;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class MessageWindowViewModel : BaseViewModel
{
private const int WINDOW_WIDTH = 400;
private const int WINDOW_HEIGHT = 225;
private bool _isVisible;
public IntPtr Handle { get; set; }
public event EventHandler<List<Run>> OnMessageUpdated;
public bool IsVisible
{
get { return _isVisible; }
set
{
if (!AppSettingData.ApplicationSetting.PopOutSetting.EnablePopOutMessages)
return;
2023-07-12 22:41:31 +00:00
_isVisible = value;
if (value)
{
CenterDialogToGameWindow();
}
}
}
public int WindowTop { get; set; }
public int WindowLeft { get; set; }
public MessageWindowViewModel(MainOrchestrator orchestrator) : base(orchestrator)
{
IsVisible = false;
Orchestrator.PanelPopOut.OnPopOutStarted += (sender, e) => IsVisible = true;
Orchestrator.PanelPopOut.OnPopOutCompleted += (sender, e) =>
{
Thread.Sleep(1000);
IsVisible = false;
};
StatusMessageWriter.OnStatusMessage += (sender, e) =>
{
Application.Current.Dispatcher.Invoke(() =>
{
if (AppSettingData.ApplicationSetting.PopOutSetting.EnablePopOutMessages)
{
WindowActionManager.ApplyAlwaysOnTop(Handle, PanelType.StatusMessageWindow, true);
2023-08-16 03:41:14 +00:00
OnMessageUpdated?.Invoke(this, FormatStatusMessages(e));
2023-07-12 22:41:31 +00:00
CenterDialogToGameWindow();
}
2023-07-12 22:41:31 +00:00
});
};
}
private void CenterDialogToGameWindow()
{
if (WindowProcessManager.SimulatorProcess == null)
return;
var simulatorRectangle = WindowActionManager.GetWindowRectangle(WindowProcessManager.SimulatorProcess.Handle);
var left = simulatorRectangle.Left + simulatorRectangle.Width / 2 - WINDOW_WIDTH / 2;
var top = simulatorRectangle.Top + simulatorRectangle.Height / 2 - WINDOW_HEIGHT / 2;
WindowActionManager.MoveWindow(Handle, left, top, WINDOW_WIDTH, WINDOW_HEIGHT);
WindowActionManager.ApplyAlwaysOnTop(Handle, PanelType.StatusMessageWindow, true);
}
}
}