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/MainApp/ViewModel/MessageWindowViewModel.cs

104 lines
3.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
{
2023-11-05 02:10:03 +00:00
private const int WINDOW_WIDTH_POPOUT_MESSAGE = 400;
private const int WINDOW_HEIGHT_POPOUT_MESSAGE = 225;
private const int WINDOW_WIDTH_REGULAR_MESSAGE = 300;
private const int WINDOW_HEIGHT_REGULAR_MESSAGE = 75;
2023-07-12 22:41:31 +00:00
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();
}
}
}
2023-11-05 02:10:03 +00:00
public int WindowWidth { get; set; }
2023-07-12 22:41:31 +00:00
2023-11-05 02:10:03 +00:00
public int WindowHeight { get; set; }
2023-07-12 22:41:31 +00:00
public MessageWindowViewModel(MainOrchestrator orchestrator) : base(orchestrator)
{
IsVisible = false;
2023-11-05 02:10:03 +00:00
Orchestrator.PanelPopOut.OnPopOutStarted += (sender, e) =>
{
IsVisible = true;
WindowWidth = WINDOW_WIDTH_POPOUT_MESSAGE;
WindowHeight = WINDOW_HEIGHT_POPOUT_MESSAGE;
};
2023-07-12 22:41:31 +00:00
Orchestrator.PanelPopOut.OnPopOutCompleted += (sender, e) =>
{
Thread.Sleep(1000);
IsVisible = false;
2023-11-05 02:10:03 +00:00
WindowWidth = WINDOW_WIDTH_POPOUT_MESSAGE;
WindowHeight = WINDOW_HEIGHT_POPOUT_MESSAGE;
};
Orchestrator.PanelSource.OnStatusMessageStarted += (sender, e) =>
{
IsVisible = true;
WindowWidth = WINDOW_WIDTH_REGULAR_MESSAGE;
WindowHeight = WINDOW_HEIGHT_REGULAR_MESSAGE;
};
Orchestrator.PanelSource.OnStatusMessageEnded += (sender, e) =>
{
IsVisible = false;
WindowWidth = WINDOW_WIDTH_REGULAR_MESSAGE;
WindowHeight = WINDOW_HEIGHT_REGULAR_MESSAGE;
2023-07-12 22:41:31 +00:00
};
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);
2023-11-05 02:10:03 +00:00
var left = simulatorRectangle.Left + simulatorRectangle.Width / 2 - WindowWidth / 2;
var top = simulatorRectangle.Top + simulatorRectangle.Height / 2 - WindowHeight / 2;
WindowActionManager.MoveWindow(Handle, left, top, WindowWidth, WindowHeight);
2023-07-12 22:41:31 +00:00
WindowActionManager.ApplyAlwaysOnTop(Handle, PanelType.StatusMessageWindow, true);
}
}
}