Exemplo n.º 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 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()]);
            }
        }
Exemplo n.º 2
0
 //--------------------------------------------------------------------------------------
 // SetScreen - call this to change the visual tree to a screen you have defined in
 // a .vwml file
 //--------------------------------------------------------------------------------------
 public void SetScreen(string screenName, object bindingContext)
 {
     _visualTree = _widgetSpace.FindWidgetByName(screenName);
     _visualTree.BindingContext = bindingContext;
 }