mirror of
https://github.com/denglihong2007/CRSim
synced 2026-08-11 12:15:35 +08:00
feat: 集成化的窗口管理器
This commit is contained in:
@@ -1,50 +1,63 @@
|
||||
using CRSim.Core.Abstractions;
|
||||
using CRSim.Core.Enums;
|
||||
using CRSim.Core.Models;
|
||||
using CRSim.Core.Models.Plugin;
|
||||
using CRSim.ScreenSimulator.Abstractions;
|
||||
using CRSim.ScreenSimulator.Models;
|
||||
using CRSim.ScreenSimulator.Views;
|
||||
using System.Windows;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows.Controls;
|
||||
using Windows.System;
|
||||
|
||||
namespace CRSim.ScreenSimulator
|
||||
{
|
||||
public class StyleManager
|
||||
{
|
||||
public static List<PluginInfo> StyleInfos => [.. IPluginService.LoadedPlugins.Where(x => x.Manifest.Type == "ScreenStyle" && x.LoadStatus == PluginLoadStatus.Loaded)];
|
||||
public static IServiceProvider ServiceProvider;
|
||||
private static IDatabaseService _databaseService;
|
||||
public StyleManager(IServiceProvider serviceProvider,IDatabaseService databaseService)
|
||||
public List<PluginInfo> StyleInfos => [.. IPluginService.LoadedPlugins.Where(x => x.Manifest.Type == "ScreenStyle" && x.LoadStatus == PluginLoadStatus.Loaded)];
|
||||
|
||||
public static IServiceProvider ServiceProvider { get; set; }
|
||||
|
||||
public ObservableCollection<SimulatorWindow> ActiveWindows { get; set; } = [];
|
||||
|
||||
public DispatcherQueue DispatcherQueue { get; set; } = DispatcherQueue.GetForCurrentThread();
|
||||
|
||||
public StyleManager(IServiceProvider serviceProvider)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
_databaseService = databaseService;
|
||||
}
|
||||
public static void ShowWindow(Type page, Station station, string ticketCheck, string platform,string? text,int location,string? video,DateTime dateTime)
|
||||
public void ShowWindow(Type page, Session session)
|
||||
{
|
||||
Thread thread = new(() =>
|
||||
{
|
||||
Page viewInstance = (Page)ServiceProvider.GetService(page);
|
||||
var viewModel = ((dynamic)viewInstance).ViewModel;
|
||||
if (viewInstance.DataContext is IScreenViewModel viewModel)
|
||||
{
|
||||
var timeService = viewModel.TimeService;
|
||||
timeService.SimulateTime = session.SimulateTime;
|
||||
timeService.Start();
|
||||
|
||||
var timeService = ((ITimeService)viewModel.TimeService);
|
||||
timeService.SimulateTime = dateTime;
|
||||
timeService.Start();
|
||||
|
||||
viewModel.UIDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
|
||||
if (text != null)
|
||||
{
|
||||
viewModel.Text = text;
|
||||
viewModel.UIDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
|
||||
if (session.Text != null)
|
||||
{
|
||||
viewModel.Text = session.Text;
|
||||
}
|
||||
if (session.Loaction != null && session.Loaction != 0)
|
||||
{
|
||||
viewModel.Location = session.Loaction.Value;
|
||||
}
|
||||
if (session.Video != null)
|
||||
{
|
||||
viewModel.Video = session.Video;
|
||||
}
|
||||
viewModel.LoadData(session.Station, session.TicketCheck, session.PlatformName);
|
||||
var win = new SimulatorWindow(viewInstance, timeService, this, session);
|
||||
DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
ActiveWindows.Add(win);
|
||||
});
|
||||
win.Show();
|
||||
System.Windows.Threading.Dispatcher.Run();
|
||||
}
|
||||
if (location != 0)
|
||||
{
|
||||
viewModel.Location = location;
|
||||
}
|
||||
if (video != null)
|
||||
{
|
||||
viewModel.Video = video;
|
||||
}
|
||||
viewModel.LoadData(station, ticketCheck, platform);
|
||||
var win = new SimulatorWindow(viewInstance, timeService);
|
||||
win.Show();
|
||||
System.Windows.Threading.Dispatcher.Run();
|
||||
});
|
||||
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
|
||||
Reference in New Issue
Block a user