Exemple #1
0
        protected override void LoadContent()
        {
            base.LoadContent();

            MyraEnvironment.Game = this;

            // Create resource asset resolver
            var assetResolver = new ResourceAssetResolver(GetType().Assembly, "Myra.Samples.CustomUIStylesheet.Resources.");

            // Load image containing font & ui spritesheet
            Texture2D texture;

            using (var stream = assetResolver.Open("ui_stylesheet_atlas.png"))
            {
                texture = Texture2D.FromStream(GraphicsDevice, stream);
            }

            // Load ui text atlas
            var textureAtlas = TextureRegionAtlas.FromXml(assetResolver.ReadAsString("ui_stylesheet_atlas.xml"), texture);

            // Load ui font(s)
            var region = textureAtlas["commodore-64"];
            var fonts  = new Dictionary <string, SpriteFont>
            {
                ["commodore-64"] =
                    BMFontLoader.LoadText(
                        assetResolver.ReadAsString("commodore-64.fnt"),
                        s => new TextureWithOffset(region.Texture, region.Bounds.Location)
                        )
            };

            // Load stylesheet
            var stylesheet = Stylesheet.LoadFromSource(
                assetResolver.ReadAsString("ui_stylesheet.xml"),
                s => textureAtlas[s],
                s => fonts[s]);

            Stylesheet.Current = stylesheet;

            _desktop = new Desktop();

            _allWidgets = new AllWidgets();
            _allWidgets._button.Image      = textureAtlas["music-off"];
            _allWidgets._imageButton.Image = textureAtlas["sound-off"];

            _desktop.Widgets.Add(_allWidgets);
        }
        protected override void LoadContent()
        {
            base.LoadContent();

            MyraEnvironment.Game = this;

            // Create asset manager
            var assetManager = new AssetManager(GraphicsDevice, new ResourceAssetResolver(typeof(CustomUIStylesheetGame).Assembly, "Resources"));

            // Load stylesheet
            Stylesheet.Current = assetManager.Load <Stylesheet>("ui_stylesheet.xml");

            _allWidgets = new AllWidgets();
            var textureAtlas = assetManager.Load <TextureRegionAtlas>("ui_stylesheet_atlas.xml");

            _allWidgets._button.Image      = textureAtlas["music-off"];
            _allWidgets._imageButton.Image = textureAtlas["sound-off"];

            Desktop.Widgets.Add(_allWidgets);
        }
Exemple #3
0
        protected override void LoadContent()
        {
            base.LoadContent();

            MyraEnvironment.Game = this;

            // Load image containing font & ui spritesheet
            var texture = Content.Load <Texture2D>("ui_stylesheet_atlas");

            // Create resource asset resolver
            var assetResolver = new ResourceAssetResolver(GetType().Assembly, "Myra.Samples.CustomUIStylesheet.Resources.");

            // Load ui text atlas
            var textureAtlas = TextureRegionAtlas.FromJson(assetResolver.ReadAsString("ui_stylesheet_atlas.json"), texture);

            // Load ui font(s)
            var fonts = new Dictionary <string, SpriteFont>
            {
                ["commodore-64"] = SpriteFontHelper.LoadFromFnt(assetResolver.ReadAsString("commodore-64.fnt"), textureAtlas["commodore-64"]),
            };

            // Load stylesheet
            var stylesheet = Stylesheet.CreateFromSource(assetResolver.ReadAsString("ui_stylesheet.json"),
                                                         s => textureAtlas[s],
                                                         s => fonts[s]);

            Stylesheet.Current = stylesheet;

            // Widget.DrawFrames = true;
            _host = new Desktop();

            _allWidgets = new AllWidgets
            {
                Background = new Drawable(textureAtlas["blue"])
            };

            _allWidgets._button.Image      = new Drawable(textureAtlas["music-off"]);
            _allWidgets._imageButton.Image = new Drawable(textureAtlas["sound-off"]);

            _host.Widgets.Add(_allWidgets);
        }