Ejemplo n.º 1
0
        private ILayoutControl CreateOptionsScreen(TextureAtlas textureAtlas)
        {
            var dockLayout = new DockLayout();

            var stackLayout = new StackLayout()
            {
                HorizontalAlignment = HorizontalAlignment.Centre,
                VerticalAlignment = VerticalAlignment.Centre
            };

            var toggleButton = new ToggleButton(new VisualStyle(textureAtlas.GetRegion("TickButton")), new VisualStyle(textureAtlas.GetRegion("CrossButton")))
            {
                Text = "Music",
            };
            stackLayout.Controls.Add(toggleButton);

            dockLayout.Controls.Add(new DockItem(stackLayout, DockStyle.Fill));

            var backButton = CreateScalingButton(textureAtlas.GetRegion("BackButton"));
            backButton.HorizontalAlignment = HorizontalAlignment.Left;
            backButton.Clicked += (s, e) => _gui.RootLayout = CreateTitleScreen(textureAtlas);
            dockLayout.Controls.Add(new DockItem(backButton, DockStyle.Bottom));

            return dockLayout;
        }
Ejemplo n.º 2
0
        private ILayoutControl CreateTitleScreen(TextureAtlas textureAtlas)
        {
            var layout = new DockLayout();

            var stackLayout = new StackLayout()
            {
                HorizontalAlignment = HorizontalAlignment.Centre,
                VerticalAlignment = VerticalAlignment.Centre
            };

            var titleImage = new Image(new VisualStyle(textureAtlas.GetRegion("CraftworkGUI")))
            {
                Margin = new Margin(0, 0, 0, 40)
            };
            stackLayout.Controls.Add(titleImage);

            var playButton = CreateScalingButton(textureAtlas.GetRegion("PlayButton"));
            stackLayout.Controls.Add(playButton);

            layout.Controls.Add(new DockItem(stackLayout, DockStyle.Fill));

            var optionsButton = CreateScalingButton(textureAtlas.GetRegion("CogButton"));
            optionsButton.VerticalAlignment = VerticalAlignment.Bottom;
            optionsButton.Clicked += (s, e) => _gui.RootLayout = CreateOptionsScreen(textureAtlas);
            layout.Controls.Add(new DockItem(optionsButton, DockStyle.Left));

            var socialStackLayout = new StackLayout()
            {
                VerticalAlignment = VerticalAlignment.Bottom
            };

            var facebookButton = CreateTiltingButton(textureAtlas.GetRegion("Facebook"), 0.1f);
            facebookButton.Clicked += (s, e) => Process.Start("https://www.facebook.com/CraftworkGames");
            socialStackLayout.Controls.Add(facebookButton);

            var twitterButton = CreateTiltingButton(textureAtlas.GetRegion("Twitter"), -0.1f);
            twitterButton.Clicked += (s, e) => Process.Start("https://twitter.com/craftworkgames");
            socialStackLayout.Controls.Add(twitterButton);

            layout.Controls.Add(new DockItem(socialStackLayout, DockStyle.Right));

            return layout;
        }
Ejemplo n.º 3
0
        public static TextureAtlas Load(GraphicsDevice graphicsDevice, ContentManager contentManager, string filename)
        {
            try
            {
                string path = filename;
                string textureDirectory = Path.GetDirectoryName(filename);

                using (var stream = TitleContainer.OpenStream(path))
                {
                    var xmlReader = XmlReader.Create(stream);

                    if (xmlReader.ReadToFollowing("TextureAtlas"))
                    {
                        var textureName = xmlReader.GetAttribute("imagePath");
                        var texturePath = Path.Combine(textureDirectory, textureName);
                        var texture = LoadTexture(graphicsDevice, contentManager, texturePath);
                        var textureAtlas = new TextureAtlas(textureName, texture);
                        textureAtlas.Filename = filename;
                        textureAtlas.Width = int.Parse(xmlReader.GetAttribute("width"));
                        textureAtlas.Height = int.Parse(xmlReader.GetAttribute("height"));

                        while (xmlReader.ReadToFollowing("sprite"))
                        {
                            var name = xmlReader.GetAttribute("n");
                            var x = int.Parse(xmlReader.GetAttribute("x"));
                            var y = int.Parse(xmlReader.GetAttribute("y"));
                            var w = int.Parse(xmlReader.GetAttribute("w"));
                            var h = int.Parse(xmlReader.GetAttribute("h"));

                            textureAtlas.AddRegion(name, x, y, w, h);
                        }

                        return textureAtlas;
                    }

                    return null;
                }
            }
            catch (Exception ex)
            {
                // TODO: Log an error
                return null;
            }
        }