public SunbirdMBWindow(CancellationTokenSource cancelSplashTokenSource, Thread splashThread) { this.cancelSplashTokenSource = cancelSplashTokenSource; splashThreadDispatcher = Dispatcher.FromThread(splashThread); InitializeComponent(); SunbirdMBGame = MainGame; SunbirdMBGame.AfterContentBuild += Game_AfterContentBuild; SunbirdMBGame.Loaded += Game_Loaded; SunbirdMBWindowViewModel = new SunbirdMBWindowViewModel(SunbirdMBGame); DataContext = SunbirdMBWindowViewModel; KeyDown += SunbirdMBWindow_KeyDown; if (File.Exists("Config.xml")) { Config = Serializer.ReadXML <Config>(Config.ConfigSerializer, "Config.xml"); Config.LoadApplicationParameters(this); } else { Config = new Config(); } SunbirdMBWindow.PumpToSplash(() => SunbirdMBSplash.ViewModel.Message = "Loading Game..."); }
private void Game_Loaded(object sender, EventArgs e) { SunbirdMBWindow.PumpToSplash(() => SunbirdMBSplash.ViewModel.Message = "Configurating Settings..."); Config.LoadGameParameters(SunbirdMBGame); ResizeGameWindow(); SizeChanged += Window_SizeChanged; Closed += Window_Closed; SunbirdMBWindowViewModel.CubeDesignerViewModel.OnGameLoaded(); SunbirdMBWindowViewModel.DecoCatalogViewModel.OnGameLoaded(); gameLoaded = true; }
//public event EventHandler Loaded; protected override void Initialize() { // must be initialized. required by Content loading and rendering (will add itself to the Services) // note that MonoGame requires this to be initialized in the constructor, while WpfInterop requires it to // be called inside Initialize (before base.Initialize()) graphicsDeviceManager = new WpfGraphicsDeviceService(this); // wpf and keyboard need reference to the host control in order to receive input // this means every WpfGame control will have it's own keyboard & mouse manager which will only react if the mouse is in the control Keyboard = new Keyboard(this); Mouse = new Mouse(this); services = new ServiceContainer(); services.AddService(typeof(IGraphicsDeviceService), graphicsDeviceManager); Content = new ContentManager(services); Content.RootDirectory = "Content"; Serializer.ExtraTypes = new Type[] { typeof(Cube), typeof(Deco), typeof(DecoReference), typeof(GhostMarker), typeof(Player), }; Camera = new Camera(this); spriteBatch = new SpriteBatch(GraphicsDevice); // must be called after the WpfGraphicsDeviceService instance was created base.Initialize(); // content loading now possible OnBeforeContentBuild(); SunbirdMBWindow.PumpToSplash(() => SunbirdMBSplash.ViewModel.Message = "Building Content..."); // Rebuild the .pngs into .xnb files. ContentBuilder.RebuildContent("Cubes"); ContentBuilder.RebuildContent("Decos"); ContentBuilder.RebuildContent("Temp"); OnAfterContentBuild(); MapBuilder = new MapBuilder(this, "MapBuilderSave.xml"); CurrentState = MapBuilder; }
private void Application_Startup(object sender, StartupEventArgs e) { // Create the token source for closing the splash screen. CancellationTokenSource cancelSplashTokenSource = new CancellationTokenSource(); // Run the splash screen in a new background thread. Thread splashThread = new Thread(new ThreadStart(() => LaunchSplash(cancelSplashTokenSource.Token))); splashThread.SetApartmentState(ApartmentState.STA); splashThread.IsBackground = true; splashThread.Start(); // Run the main window. var mainWindow = new SunbirdMBWindow(cancelSplashTokenSource, splashThread); mainWindow.Show(); }