Esempio n. 1
0
        public void onTerrainSelected(HUD invoker, TerrainDescription data)
        {
            selectedTerrain = data;
            SquareSpriteRenderer ssr = new SquareSpriteRenderer(data.TerrainTexture, Color.Blue);

            ssr.size = new Vector2(1, 0);
            if (mapPreview.childRenderers.Count == 0)
            {
                mapPreview.AddChildRenderer(ssr);
            }
            else
            {
                mapPreview.childRenderers[0] = ssr;
                ssr.parentRenderer           = mapPreview;
            }
        }
Esempio n. 2
0
        public void onLevelSelected(HUD invokder, LevelDescription data)
        {
            selectedLevel = data;
            SquareSpriteRenderer ssr = new SquareSpriteRenderer(Game.Content.Load <Texture2D>(@"Terrain\" + data.TerrainName), Color.Blue);

            ssr.size = new Vector2(1, 0);
            if (mapPreview.childRenderers.Count == 0)
            {
                mapPreview.AddChildRenderer(ssr);
            }
            else
            {
                mapPreview.childRenderers[0] = ssr;
                ssr.parentRenderer           = mapPreview;
            }
        }
Esempio n. 3
0
        public MapEditorScreen()
        {
            // background
            _2DRenderer background = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuBackground"));

            AddComponent(background);

            // map preview
            mapPreview          = new _2DRenderer();
            mapPreview.position = new Vector2(0.1f, 0.02f);
            mapPreview.size     = new Vector2(0.4f, 0.4f);
            AddComponent(mapPreview);

            // terrain list
            _2DRenderer terrainListRenderer = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuFrame"));

            terrainListRenderer.position = new Vector2(0.75f, 0.02f);
            terrainListRenderer.size     = new Vector2(0.2f, 0.6f);

            Vector2 terrainListPadding = new Vector2(0.1f, 0.1f);
            float   nVisibleTerrain    = 3.5f;

            terrainList = new VerticalList <TerrainDescription>(terrainListRenderer, terrainListPadding, nVisibleTerrain);
            terrainList.onItemSelected = onTerrainSelected;
            AddComponent(terrainList);

            // fill data to terrain list
            string[]   terrainPathList = Directory.GetFiles(Game.Content.RootDirectory + @"\terrain\", "*.bmp", SearchOption.TopDirectoryOnly);
            SpriteFont terrainItemFont = Game.Content.Load <SpriteFont>(@"Fonts\Arial");

            foreach (string terrainPath in terrainPathList)
            {
                ListItem <TerrainDescription> terrainItem = new ListItem <TerrainDescription>();

                // item data
                string    terrainName    = Path.GetFileNameWithoutExtension(terrainPath);
                Texture2D terrainTexture = Game.Content.Load <Texture2D>(@"Terrain\" + terrainName);
                terrainItem.data                = new TerrainDescription();
                terrainItem.data.TerrainName    = terrainName;
                terrainItem.data.TerrainTexture = terrainTexture;

                // item display
                terrainItem.renderer = new _2DRenderer();

                _2DRenderer terrainThumbnailRenderer = new SquareSpriteRenderer(terrainTexture, Color.Blue);
                terrainThumbnailRenderer.position = new Vector2(0.05f, 0.2f);
                terrainThumbnailRenderer.size     = new Vector2(0, 0.6f);
                terrainItem.renderer.AddChildRenderer(terrainThumbnailRenderer);

                _2DRenderer terrainNameRenderer = new TextRenderer(terrainName);
                terrainNameRenderer.position = new Vector2(0.3f, 0.05f);
                terrainItem.renderer.AddChildRenderer(terrainNameRenderer);

                terrainList.Add(terrainItem);
            }

            // edit map button
            _2DRenderer editMapButtonRenderer = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuButton"));

            editMapButtonRenderer.AddChildRenderer(new TextRenderer("Edit"));
            editMapButtonRenderer.position = terrainListRenderer.position + new Vector2(0, terrainListRenderer.size.Y);
            editMapButtonRenderer.size     = new Vector2(terrainListRenderer.size.X, terrainListRenderer.size.Y / 8);
            editMapButton         = new HUD(editMapButtonRenderer);
            editMapButton.onClick = onEditClicked;
            AddComponent(editMapButton);

            // exit button
            _2DRenderer exitButtonRenderer = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuButton"));

            exitButtonRenderer.AddChildRenderer(new TextRenderer("Exit"));
            exitButtonRenderer.position = editMapButtonRenderer.position + new Vector2(0, editMapButtonRenderer.size.Y + 0.2f);
            exitButtonRenderer.size     = editMapButtonRenderer.size;

            HUD exitButton = new HUD(exitButtonRenderer);

            exitButton.onClick = onExitClicked;
            AddComponent(exitButton);
        }
Esempio n. 4
0
        public SelectLevelScreen()
        {
            // background
            _2DRenderer background = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuBackground"));

            AddComponent(background);

            // map preview
            mapPreview          = new _2DRenderer();
            mapPreview.position = new Vector2(0.1f, 0.02f);
            mapPreview.size     = new Vector2(0.4f, 0.4f);
            AddComponent(mapPreview);

            // level list
            _2DRenderer levelListRenderer = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuFrame"));

            levelListRenderer.position = new Vector2(0.75f, 0.02f);
            levelListRenderer.size     = new Vector2(0.2f, 0.6f);

            Vector2 levelListPadding = new Vector2(0.1f, 0.1f);
            float   nVisibleLevel    = 3.5f;

            levelList = new VerticalList <LevelDescription>(levelListRenderer, levelListPadding, nVisibleLevel);
            levelList.onItemSelected = onLevelSelected;
            AddComponent(levelList);

            // fill data to level list
            string[]   levelPathList = Directory.GetFiles(Game.Content.RootDirectory + @"\Level\", "*.xml", SearchOption.TopDirectoryOnly);
            SpriteFont levelItemFont = Game.Content.Load <SpriteFont>(@"Fonts\Arial");

            foreach (string levelPath in levelPathList)
            {
                ListItem <LevelDescription> levelItem = new ListItem <LevelDescription>();

                // level data
                string           levelName        = Path.GetFileNameWithoutExtension(levelPath);
                LevelDescription levelDescription = LevelDescription.LoadFromXML(levelPath);
                levelItem.data = levelDescription;
                Texture2D levelTerrainTexture = Game.Content.Load <Texture2D>(@"Terrain\" + levelDescription.TerrainName);

                // level display
                levelItem.renderer = new _2DRenderer();

                _2DRenderer terrainThumbnailRenderer = new SquareSpriteRenderer(levelTerrainTexture, Color.Blue);
                terrainThumbnailRenderer.position = new Vector2(0.05f, 0.2f);
                terrainThumbnailRenderer.size     = new Vector2(0, 0.6f);
                levelItem.renderer.AddChildRenderer(terrainThumbnailRenderer);

                _2DRenderer levelNameRenderer = new TextRenderer(levelName);
                levelNameRenderer.position = new Vector2(0.3f, 0.05f);
                levelItem.renderer.AddChildRenderer(levelNameRenderer);

                levelList.Add(levelItem);
            }

            // play button
            _2DRenderer playButtonRenderer = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuButton"));

            playButtonRenderer.AddChildRenderer(new TextRenderer("Play"));
            playButtonRenderer.position = levelListRenderer.position + new Vector2(0, levelListRenderer.size.Y);
            playButtonRenderer.size     = new Vector2(levelListRenderer.size.X, levelListRenderer.size.Y / 8);
            HUD playButton = new HUD(playButtonRenderer);

            playButton.onClick = onPlayClicked;
            AddComponent(playButton);

            // exit button
            _2DRenderer exitButtonRenderer = new SpriteRenderer(Game.Content.Load <Texture2D>(@"Sprites\MainMenuButton"));

            exitButtonRenderer.AddChildRenderer(new TextRenderer("Exit"));
            exitButtonRenderer.position = new Vector2(0.8f, 0.8f);
            exitButtonRenderer.size     = new Vector2(0.1f, 0.1f);

            HUD exitButton = new HUD(exitButtonRenderer);

            exitButton.onClick = onExitClicked;
            AddComponent(exitButton);
        }