Пример #1
0
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Do some visual setup to get the normalize the coordinate system, load default
        /// content, and then call out for any user-assigned work using the OnLoaded event.
        /// </summary>
        //-----------------------------------------------------------------------------------------------
        protected override void LoadContent()
        {
            Content = new EmbeddedContentManager(_graphics.GraphicsDevice)
            {
                RootDirectory = "Content"
            };
            // Set up a back buffer to render to
            _backBufferWidth  = GraphicsDevice.PresentationParameters.BackBufferWidth;
            _backBufferHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;
            if ((float)_backBufferHeight / _backBufferWidth < 1.6)
            {
                _backBufferWidth   = (int)(_backBufferHeight / 1.6);
                _backBufferXOffset = (GraphicsDevice.PresentationParameters.BackBufferWidth - _backBufferWidth) / 2;
            }

            var scaleFactor = _backBufferWidth / 1000.0f;

            _scaleToNativeResolution = Matrix.CreateScale(new Vector3(scaleFactor, scaleFactor, 1));

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _utilityBlockTexture = Content.Load <Texture2D>("_utility_block");
            _circleTexture       = Content.Load <Texture2D>("_utility_circle");
            _defaultFont         = Content.Load <SpriteFont>("_utility_SegoeUI");

            _fontsByName.Add("_utility_SegoeUI", _defaultFont);
            SelectFont();

            // Widgets
            _widgetSpace = new VarmintWidgetSpace(this, _bindingContext);

            _visualTree = _widgetSpace.GetScreen("_default_screen_", null);
            OnLoaded?.Invoke();
        }
Пример #2
0
 //-----------------------------------------------------------------------------------------------
 /// <summary>
 /// Call this first if you want to reload content
 /// </summary>
 //-----------------------------------------------------------------------------------------------
 public void ClearContent()
 {
     _fontsByName.Clear();
     _glyphsByName.Clear();
     _spritesByName.Clear();
     _songsByName.Clear();
     _soundEffectsByName.Clear();
     _widgetSpace = new VarmintWidgetSpace(this, _bindingContext);
 }
Пример #3
0
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Do some visual setup to get the normalize the coordinate system, load default
        /// content, and then call out for any user-assigned work using the OnLoaded event.
        /// </summary>
        //-----------------------------------------------------------------------------------------------
        protected override void LoadContent()
        {
            Content = new EmbeddedContentManager(_graphics.GraphicsDevice)
            {
                RootDirectory = "Content"
            };

            // Set up buffer size to be a portrait mode of at least 1x1.6 ratio
            _backBufferWidth  = GraphicsDevice.PresentationParameters.BackBufferWidth;
            _backBufferHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;
            if ((float)_backBufferHeight / _backBufferWidth < 1.6)
            {
                _backBufferWidth   = (int)(_backBufferHeight / 1.6);
                _backBufferXOffset = (GraphicsDevice.PresentationParameters.BackBufferWidth - _backBufferWidth) / 2;
            }

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _utilityBlockTexture = Content.Load <Texture2D>("_utility_block");
            _circleTexture       = Content.Load <Texture2D>("_utility_circle");
            _defaultFont         = Content.Load <SpriteFont>("_utility_SegoeUI");

            _fontsByName.Add("_utility_SegoeUI", _defaultFont);
            SelectFont();

            // Widgets
            _widgetSpace = new VarmintWidgetSpace(this);

            _debugContext.ScreenSize    = ScreenSize;
            _debugScreen                = _widgetSpace.FindWidgetByName("_debug_screen_");
            _debugScreen.BindingContext = _debugContext;
            _debugScreen.Prepare(null);
            _debugWidget        = _debugScreen.Children.First();
            _debugContentHolder = _debugScreen.FindWidgetByName("_debug_contentslot_");
            SetScreen("_default_screen_", null);
            OnGameLoaded?.Invoke();

            foreach (var sliceItem in _widgetSpace.NineSlices)
            {
                sliceItem.Prepare(null);
                if (sliceItem.Content == null || !_glyphsByName.ContainsKey(sliceItem.Content.ToString()))
                {
                    throw new ApplicationException($"NineSlice item '{sliceItem.Name}' did not specify a valid glyph name ({sliceItem.Content}) in the Content property. ");
                }
                _slicedGlyphsByName[sliceItem.Name] = sliceItem.GetSlicedTexture(_glyphsByName[sliceItem.Content.ToString()]);
            }
        }