Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NoesisWrapper" /> class.
        /// </summary>
        public NoesisWrapper(NoesisConfig config)
        {
            config.Validate();
            this.config     = config;
            this.gameWindow = config.GameWindow;

            // not implemented in NoesisGUI yet
            // setup Noesis Debug callbacks
            //Debug.ExceptionThrown = this.NoesisExceptionThrownHandler;
            //Debug.ErrorMessageReceived = this.NoesisErrorMessageReceivedHandler;

            this.graphicsDevice = config.Graphics.GraphicsDevice;
            this.FixAntiAliasingMode(ref this.antiAliasingMode);
            this.deviceD3D11 = (Device)this.graphicsDevice.Handle;

            this.deviceState = new DeviceStateHelperD3D11((Device)this.graphicsDevice.Handle);

            // setup resource providerManager
            if (config.NoesisFileSystemProviderRootFolderPath != null)
            {
                GUI.SetResourceProvider(config.NoesisFileSystemProviderRootFolderPath);
            }
            else
            {
                this.providerManager = config.CreateNoesisProviderManagerDelegate();
                GUI.SetResourceProvider(this.providerManager.Provider);
            }

            // setup theme
            if (config.ThemeXamlFilePath != null)
            {
                var themeResourceDictionary = (ResourceDictionary)GUI.LoadXaml(config.ThemeXamlFilePath);
                if (themeResourceDictionary == null)
                {
                    throw new Exception(
                              $"Theme is not found or was not able to load by NoesisGUI: {config.ThemeXamlFilePath}");
                }

                GUI.SetTheme(themeResourceDictionary);
                this.Theme = themeResourceDictionary;
            }

            // create and prepare view
            this.view         = this.CreateView(config.RootXamlFilePath);
            this.viewRenderer = this.view.Renderer;
            this.UpdateSize();

            // prepare input
            this.inputManager = new InputManager(
                this.view,
                this.ControlTreeRoot,
                config);

            // subscribe to XNA events
            this.EventsSubscribe();

            // call update with zero delta time to prepare the view for rendering
            this.startupTotalGameTime = config.CurrentTotalGameTime;
            this.Update(new GameTime(this.startupTotalGameTime, elapsedGameTime: TimeSpan.Zero), isWindowActive: true);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NoesisWrapper" /> class.
        /// </summary>
        public NoesisWrapper(NoesisConfig config)
        {
            config.Validate();
            this.config     = config;
            this.gameWindow = config.GameWindow;

            // setup Noesis Debug callbacks
            Log.LogCallback = this.NoesisLogCallbackHandler;

            this.graphicsDevice  = config.Graphics.GraphicsDevice;
            this.providerManager = config.NoesisProviderManager;
            var provider = this.providerManager.Provider;

            GUI.SetFontProvider(provider.FontProvider);
            GUI.SetTextureProvider(provider.TextureProvider);
            GUI.SetXamlProvider(provider.XamlProvider);

            // setup theme
            if (config.ThemeXamlFilePath != null)
            {
                var themeResourceDictionary = (ResourceDictionary)GUI.LoadXaml(config.ThemeXamlFilePath);
                if (themeResourceDictionary == null)
                {
                    throw new Exception(
                              $"Theme is not found or was not able to load by NoesisGUI: {config.ThemeXamlFilePath}");
                }

                GUI.SetApplicationResources(themeResourceDictionary);
                this.Theme = themeResourceDictionary;
            }

            // create and prepare view
            var controlTreeRoot = (FrameworkElement)GUI.LoadXaml(config.RootXamlFilePath);

            this.ControlTreeRoot = controlTreeRoot
                                   ?? throw new Exception(
                                             $"UI file \"{config.RootXamlFilePath}\" is not found - cannot initialize UI");

            this.view = new NoesisViewWrapper(
                controlTreeRoot,
                this.graphicsDevice,
                this.config.CurrentTotalGameTime);
            this.RefreshSize();

            this.inputManager = this.view.CreateInputManager(config);

            // subscribe to MonoGame events
            this.EventsSubscribe();
        }