예제 #1
0
        public ScreenPictureButton(Screen screen, String Action, TextureData Tex)
            : base(screen)
        {
            this.Action = Action;
            this.Tex = Tex;

            PositionButton();
        }
예제 #2
0
        public ScreenPictureButton(Screen screen, String Action, TextureData Tex, Vector2 Pos, Vector2 Size)
            : base(screen)
        {
            this.Action = Action;
            this.Tex = Tex;

            this.Position = Pos;
            this.Size = Size;
        }
예제 #3
0
        // TODO: Make this data buffered.
        /// <summary>
        /// Constructs a room.
        /// </summary>
        /// <param name="blockSet">The blockset to be used for this room.</param>
        public Room(Engine engine, String blockSetName, int Width, int Depth, int Height)
        {
            // Builds the basic room.
            GridArray = new int[Width, Depth, Height];
            this.Width = Width;
            this.Depth = Depth;
            this.Height = Height;

            this.Background = engine.textureManager.Dic["background_generic"];

            // This is the default room style.
            FillBorders(2);

            // Checks and finds the correct blockset.
            LoadBlockSet(engine, blockSetName);

            // Creates the initial mesh.
            UpdateRoomVertices();
        }
        /// <summary>
        /// Updates the element. This should not happen if the window is minimized.
        /// </summary>
        public override void Update(Engine engine)
        {
            MouseTexture = null;

            int yy = 0;
            int xx = 0;
            foreach (TextureData t in PageList)
            {
                // Changes rows and such.
                if (yy == PrevMaximumRows)
                {
                    yy = 0;
                    xx++;
                    if (xx == PrevMaximumColumns)
                        break;
                }

                // If mouse is within region.
                if (engine.inputManager.mouse.X > Position.X + screen.Position.X + xx * TilePreviewSize && engine.inputManager.mouse.X < Position.X + screen.Position.X + TilePreviewSize + xx * TilePreviewSize
                    && engine.inputManager.mouse.Y > Position.Y + screen.Position.Y + yy * TilePreviewSize && engine.inputManager.mouse.Y < Position.Y + screen.Position.Y + (yy + 1) * TilePreviewSize)
                {
                    // Sets the mouse texture.
                    MouseTexture = t;

                    // Returns the texture clicked.
                    if (engine.inputManager.MouseLeftButtonTapped)
                    {
                        screen.PreformAction(engine, "Click Texture");
                    }
                    // Returns the texture clicked.
                    if (engine.inputManager.MouseRightButtonTapped)
                    {
                        screen.PreformAction(engine, "Cover Texture");
                    }
                }
                yy++;
            }

            base.Update(engine);

            // Updates the filtered list if necessary.
            if (PreviousInput != InputField.InputString)
                FilterTiles(engine);
            PreviousInput = InputField.InputString;
        }
예제 #5
0
        public void LoadTexturesFromFile(String Filename, ContentManager Content)
        {
            // The filename should not have the extension.

            TextReader rawTextureFile = new StreamReader("Content/Texts/" + Filename + ".tin");
            String line;
            do
            {
                line = rawTextureFile.ReadLine();
                if (line != null)
                {
                    // Loads a tileset
                    if (line[0] == '#')
                    {
                        String[] _lineSplit = line.Split('#');

                        Texture2D _texture = Content.Load<Texture2D>("Tilesets/" + _lineSplit[2]);

                        LoadTileset(_lineSplit[2], _texture, int.Parse(_lineSplit[1]));
                    }

                    // Loads an animation.
                    else if (line[0] == '@')
                    {
                        // Splits the data.
                        String[] _lineSplit = line.Split('@');

                        // Loads the texture.
                        Texture2D _texture = Content.Load<Texture2D>("Animations/" + _lineSplit[2]);

                        // Gets the grid width.
                        int gridWidth = int.Parse(_lineSplit[1]);

                        float frameSize = _texture.Width / gridWidth;

                        // Creates a new animation.
                        Animation _ani = new Animation(_texture);

                        for (int i = 3; i < _lineSplit.Length; i++)
                        {
                            // Creates a new list to hold texture data.
                            List<TextureData> _smallAni = new List<TextureData>();

                            // Gets the frames in this smaller animation.
                            int _frames = int.Parse(_lineSplit[i]);

                            // Loads individual frames.
                            for (int f = 0; f < _frames; f++)
                            {
                                TextureData _tex = new TextureData(
                                    _lineSplit[2] + (i-3).ToString() + "_" + f.ToString(),
                                    _texture,
                                    new Vector2((float)f / (float)gridWidth, frameSize * (i-3) / (float)_texture.Height),
                                    new Vector2(1f / (float)gridWidth, frameSize / (float)_texture.Height));

                                _smallAni.Add(_tex);
                            }

                            _ani.AniList.Add(_smallAni);
                        }

                        AniDic.Add(_lineSplit[2], _ani);
                    }

                    // Loads a single image
                    else
                    {
                        Texture2D _texture = Content.Load<Texture2D>("Textures/" + line);
                        AddTexture(new TextureData(line, _texture));
                    }
                }
            }
            while (line != null);

            rawTextureFile.Close();
        }
예제 #6
0
 public void AddTexture(TextureData Tex)
 {
     Dic.Add(Tex.Name, Tex);
 }
예제 #7
0
        private void LoadTileset(String Filename, Texture2D Texture, int GridWidth)
        {
            // The filename should not have the extension.

            Tileset _newTileset = new Tileset(Filename, Texture, Texture.Width / GridWidth);
            TilesetList.Add(_newTileset);

            TextReader tilesetFile = new StreamReader("Content/Texts/" + Filename + ".tlin");
            String line;
            int lineNum = 0;
            do
            {
                line = tilesetFile.ReadLine();
                if (line != null)
                {
                    String[] _lineSplit = line.Split(' ');
                    for (int i = 0; i < _lineSplit.Length; i++)
                    {
                        TextureData _newTexture = new TextureData(_lineSplit[i], Texture, new Vector2((float)i / (float)GridWidth, (float)lineNum / (float)GridWidth), new Vector2(1f / (float)GridWidth, 1f / (float)GridWidth));
                        _newTileset.Tiles.Add(_newTexture);
                    }

                    for (int i = _lineSplit.Length; i < GridWidth; i++)
                    {
                        _newTileset.Tiles.Add(null);
                    }
                }
                lineNum += 1;
            }
            while (line != null);

            tilesetFile.Close();
        }
예제 #8
0
        /// <summary>
        /// Creates a room using a layout.
        /// </summary>
        public Room(Engine engine, String blockSetName, String filename)
        {
            this.Background = engine.textureManager.Dic["background_generic"];

            // Checks and finds the correct blockset.
            LoadBlockSet(engine, blockSetName);

            this.LoadLayout(engine, filename);
            // Creates the initial mesh.
            UpdateRoomVertices();
        }
예제 #9
0
        /// <summary>
        /// Generates vertices for a cube.
        /// </summary>
        /// <param name="BottomLeftFront"> The bottom left front corner of the cube.</param>
        /// <param name="TopRightBack">The top right back corner of the cube.</param>
        /// <param name="Tex">The texture to cover the cube.</param>
        /// <returns>Returns a VertexIndexData instance containing the information.</returns>
        public static VertexIndexData GenerateCubeVertices(Vector3 BottomLeftFront, Vector3 TopRightBack, TextureData Tex)
        {
            // NOTE: the Front is the side that is facing the camera, which should be in -Y zone, thus the side with lowest Y.
            //       the Left has smaller X value than the Right

            Vector3 topLeftFront     = new Vector3(BottomLeftFront.X, BottomLeftFront.Y, TopRightBack.Z);
            Vector3 bottomLeftFront  = BottomLeftFront;
            Vector3 topRightFront    = new Vector3(TopRightBack.X, BottomLeftFront.Y, TopRightBack.Z);
            Vector3 bottomRightFront = new Vector3(TopRightBack.X, BottomLeftFront.Y, BottomLeftFront.Z);
            Vector3 topLeftBack      = new Vector3(BottomLeftFront.X, TopRightBack.Y, TopRightBack.Z);
            Vector3 bottomLeftBack   = new Vector3(BottomLeftFront.X, TopRightBack.Y, BottomLeftFront.Z);
            Vector3 topRightBack     = TopRightBack;
            Vector3 bottomRightBack  = new Vector3(TopRightBack.X, TopRightBack.Y, BottomLeftFront.Z);

            Vector2 textureTopLeft     = Tex.TopLeftPercent;
            Vector2 textureTopRight    = new Vector2(Tex.BottomRightPercent.X, Tex.TopLeftPercent.Y);
            Vector2 textureBottomLeft  = new Vector2(Tex.TopLeftPercent.X, Tex.BottomRightPercent.Y);
            Vector2 textureBottomRight = Tex.BottomRightPercent;

            Vector3 frontNormal  = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 backNormal   = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 topNormal    = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 bottomNormal = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 leftNormal   = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal  = new Vector3(1.0f, 0.0f, 0.0f);

            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[24];
            short[] indices = new short[36];

            vertices[0] =
                new VertexPositionNormalTexture(
                    topLeftFront, frontNormal, textureTopLeft);
            vertices[1] =
                new VertexPositionNormalTexture(
                    topRightFront, frontNormal, textureTopRight);
            vertices[2] =
                new VertexPositionNormalTexture(
                    bottomLeftFront, frontNormal, textureBottomLeft);
            vertices[3] =
                new VertexPositionNormalTexture(
                    bottomRightFront, frontNormal, textureBottomRight);

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 2;
            indices[4] = 1;
            indices[5] = 3;

            vertices[4] =
                new VertexPositionNormalTexture(
                    topRightBack, backNormal, textureTopLeft);
            vertices[5] =
                new VertexPositionNormalTexture(
                    topLeftBack, backNormal, textureTopRight);
            vertices[6] =
                new VertexPositionNormalTexture(
                    bottomRightBack, backNormal, textureBottomLeft);
            vertices[7] =
                new VertexPositionNormalTexture(
                    bottomLeftBack, backNormal, textureBottomRight);

            indices[6]  = 4;
            indices[7]  = 5;
            indices[8]  = 6;
            indices[9]  = 6;
            indices[10] = 5;
            indices[11] = 7;

            vertices[8] =
                new VertexPositionNormalTexture(
                    topLeftBack, leftNormal, textureTopLeft);
            vertices[9] =
                new VertexPositionNormalTexture(
                    topLeftFront, leftNormal, textureTopRight);
            vertices[10] =
                new VertexPositionNormalTexture(
                    bottomLeftBack, leftNormal, textureBottomLeft);
            vertices[11] =
                new VertexPositionNormalTexture(
                    bottomLeftFront, leftNormal, textureBottomRight);

            indices[12] = 8;
            indices[13] = 9;
            indices[14] = 10;
            indices[15] = 10;
            indices[16] = 9;
            indices[17] = 11;

            vertices[12] =
                new VertexPositionNormalTexture(
                    topRightFront, rightNormal, textureTopLeft);
            vertices[13] =
                new VertexPositionNormalTexture(
                    topRightBack, rightNormal, textureTopRight);
            vertices[14] =
                new VertexPositionNormalTexture(
                    bottomRightFront, rightNormal, textureBottomLeft);
            vertices[15] =
                new VertexPositionNormalTexture(
                    bottomRightBack, rightNormal, textureBottomRight);

            indices[18] = 12;
            indices[19] = 13;
            indices[20] = 14;
            indices[21] = 14;
            indices[22] = 13;
            indices[23] = 15;

            vertices[16] =
                new VertexPositionNormalTexture(
                    topLeftBack, topNormal, textureTopLeft);
            vertices[17] =
                new VertexPositionNormalTexture(
                    topRightBack, topNormal, textureTopRight);
            vertices[18] =
                new VertexPositionNormalTexture(
                    topLeftFront, topNormal, textureBottomLeft);
            vertices[19] =
                new VertexPositionNormalTexture(
                    topRightFront, topNormal, textureBottomRight);

            indices[24] = 16;
            indices[25] = 17;
            indices[26] = 18;
            indices[27] = 18;
            indices[28] = 17;
            indices[29] = 19;

            vertices[20] =
                new VertexPositionNormalTexture(
                    bottomLeftFront, bottomNormal, textureTopLeft);
            vertices[21] =
                new VertexPositionNormalTexture(
                    bottomRightFront, bottomNormal, textureTopRight);
            vertices[22] =
                new VertexPositionNormalTexture(
                    bottomLeftBack, bottomNormal, textureBottomLeft);
            vertices[23] =
                new VertexPositionNormalTexture(
                    bottomRightBack, bottomNormal, textureBottomRight);

            indices[30] = 20;
            indices[31] = 21;
            indices[32] = 22;
            indices[33] = 22;
            indices[34] = 21;
            indices[35] = 23;

            return(new VertexIndexData(vertices, indices));
        }
예제 #10
0
 public PushCube(Vector3 Position, TextureData Tex)
     : base(Position)
 {
     this.UsesIce = true;
     this.Tex = Tex;
 }
예제 #11
0
        public static VertexIndexData GenerateFloorVertices(Vector3 BottomLeftCorner, Vector3 TopRightCorner, Vector3 Normal, TextureData Tex)
        {
            Vector3 topLeft     = new Vector3(BottomLeftCorner.X, TopRightCorner.Y, BottomLeftCorner.Z);
            Vector3 bottomLeft  = BottomLeftCorner;
            Vector3 topRight    = new Vector3(TopRightCorner.X, TopRightCorner.Y, BottomLeftCorner.Z);
            Vector3 bottomRight = new Vector3(TopRightCorner.X, BottomLeftCorner.Y, BottomLeftCorner.Z);

            Vector2 textureTopLeft     = Tex.TopLeftPercent;
            Vector2 textureTopRight    = new Vector2(Tex.BottomRightPercent.X, Tex.TopLeftPercent.Y);
            Vector2 textureBottomLeft  = new Vector2(Tex.TopLeftPercent.X, Tex.BottomRightPercent.Y);
            Vector2 textureBottomRight = Tex.BottomRightPercent;

            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[4];
            short[] indices = new short[6];

            vertices[0] =
                new VertexPositionNormalTexture(
                    topLeft, Normal, textureTopLeft);
            vertices[1] =
                new VertexPositionNormalTexture(
                    topRight, Normal, textureTopRight);
            vertices[2] =
                new VertexPositionNormalTexture(
                    bottomLeft, Normal, textureBottomLeft);
            vertices[3] =
                new VertexPositionNormalTexture(
                    bottomRight, Normal, textureBottomRight);

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 2;
            indices[4] = 1;
            indices[5] = 3;

            return(new VertexIndexData(vertices, indices));
        }
예제 #12
0
        public static void DrawCube(PrimManager PrimManager, Vector3 BottomLeftFront, Vector3 TopRightBack, TextureData Tex)
        {
            VertexIndexData _cube = PrimHelper.GenerateCubeVertices(BottomLeftFront, TopRightBack, Tex);

            PrimManager.DrawVertices(_cube, Tex.TextureMain);
        }
예제 #13
0
        /// <summary>
        /// Generates vertices for a cube.
        /// </summary>
        /// <param name="BottomLeftFront"> The bottom left front corner of the cube.</param>
        /// <param name="TopRightBack">The top right back corner of the cube.</param>
        /// <param name="Tex">The texture to cover the cube.</param>
        /// <returns>Returns a VertexIndexData instance containing the information.</returns>
        public static VertexIndexData GenerateCubeVertices(Vector3 BottomLeftFront, Vector3 TopRightBack, TextureData Tex)
        {
            // NOTE: the Front is the side that is facing the camera, which should be in -Y zone, thus the side with lowest Y.
            //       the Left has smaller X value than the Right

            Vector3 topLeftFront = new Vector3(BottomLeftFront.X, BottomLeftFront.Y, TopRightBack.Z);
            Vector3 bottomLeftFront = BottomLeftFront;
            Vector3 topRightFront = new Vector3(TopRightBack.X, BottomLeftFront.Y, TopRightBack.Z);
            Vector3 bottomRightFront = new Vector3(TopRightBack.X, BottomLeftFront.Y, BottomLeftFront.Z);
            Vector3 topLeftBack = new Vector3(BottomLeftFront.X, TopRightBack.Y, TopRightBack.Z);
            Vector3 bottomLeftBack = new Vector3(BottomLeftFront.X, TopRightBack.Y, BottomLeftFront.Z);
            Vector3 topRightBack = TopRightBack;
            Vector3 bottomRightBack = new Vector3(TopRightBack.X, TopRightBack.Y, BottomLeftFront.Z);

            Vector2 textureTopLeft = Tex.TopLeftPercent;
            Vector2 textureTopRight = new Vector2(Tex.BottomRightPercent.X, Tex.TopLeftPercent.Y);
            Vector2 textureBottomLeft = new Vector2(Tex.TopLeftPercent.X, Tex.BottomRightPercent.Y);
            Vector2 textureBottomRight = Tex.BottomRightPercent;

            Vector3 frontNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 backNormal = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 topNormal = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 bottomNormal = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f);

            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[24];
            short[] indices = new short[36];

            vertices[0] =
                new VertexPositionNormalTexture(
                topLeftFront, frontNormal, textureTopLeft);
            vertices[1] =
                new VertexPositionNormalTexture(
                topRightFront, frontNormal, textureTopRight);
            vertices[2] =
                new VertexPositionNormalTexture(
                bottomLeftFront, frontNormal, textureBottomLeft);
            vertices[3] =
                new VertexPositionNormalTexture(
                bottomRightFront, frontNormal, textureBottomRight);

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 2;
            indices[4] = 1;
            indices[5] = 3;

            vertices[4] =
                new VertexPositionNormalTexture(
                topRightBack, backNormal, textureTopLeft);
            vertices[5] =
                new VertexPositionNormalTexture(
                topLeftBack, backNormal, textureTopRight);
            vertices[6] =
                new VertexPositionNormalTexture(
                bottomRightBack, backNormal, textureBottomLeft);
            vertices[7] =
                new VertexPositionNormalTexture(
                bottomLeftBack, backNormal, textureBottomRight);

            indices[6] = 4;
            indices[7] = 5;
            indices[8] = 6;
            indices[9] = 6;
            indices[10] = 5;
            indices[11] = 7;

            vertices[8] =
                new VertexPositionNormalTexture(
                topLeftBack, leftNormal, textureTopLeft);
            vertices[9] =
                new VertexPositionNormalTexture(
                topLeftFront, leftNormal, textureTopRight);
            vertices[10] =
                new VertexPositionNormalTexture(
                bottomLeftBack, leftNormal, textureBottomLeft);
            vertices[11] =
                new VertexPositionNormalTexture(
                bottomLeftFront, leftNormal, textureBottomRight);

            indices[12] = 8;
            indices[13] = 9;
            indices[14] = 10;
            indices[15] = 10;
            indices[16] = 9;
            indices[17] = 11;

            vertices[12] =
                new VertexPositionNormalTexture(
                topRightFront, rightNormal, textureTopLeft);
            vertices[13] =
                new VertexPositionNormalTexture(
                topRightBack, rightNormal, textureTopRight);
            vertices[14] =
                new VertexPositionNormalTexture(
                bottomRightFront, rightNormal, textureBottomLeft);
            vertices[15] =
                new VertexPositionNormalTexture(
                bottomRightBack, rightNormal, textureBottomRight);

            indices[18] = 12;
            indices[19] = 13;
            indices[20] = 14;
            indices[21] = 14;
            indices[22] = 13;
            indices[23] = 15;

            vertices[16] =
                new VertexPositionNormalTexture(
                topLeftBack, topNormal, textureTopLeft);
            vertices[17] =
                new VertexPositionNormalTexture(
                topRightBack, topNormal, textureTopRight);
            vertices[18] =
                new VertexPositionNormalTexture(
                topLeftFront, topNormal, textureBottomLeft);
            vertices[19] =
                new VertexPositionNormalTexture(
                topRightFront, topNormal, textureBottomRight);

            indices[24] = 16;
            indices[25] = 17;
            indices[26] = 18;
            indices[27] = 18;
            indices[28] = 17;
            indices[29] = 19;

            vertices[20] =
                new VertexPositionNormalTexture(
                bottomLeftFront, bottomNormal, textureTopLeft);
            vertices[21] =
                new VertexPositionNormalTexture(
                bottomRightFront, bottomNormal, textureTopRight);
            vertices[22] =
                new VertexPositionNormalTexture(
                bottomLeftBack, bottomNormal, textureBottomLeft);
            vertices[23] =
                new VertexPositionNormalTexture(
                bottomRightBack, bottomNormal, textureBottomRight);

            indices[30] = 20;
            indices[31] = 21;
            indices[32] = 22;
            indices[33] = 22;
            indices[34] = 21;
            indices[35] = 23;

            return new VertexIndexData(vertices, indices);
        }
예제 #14
0
        public static VertexIndexData GenerateWallVertices(Vector3 BottomLeftCorner, Vector3 TopRightCorner, Vector3 Normal, TextureData Tex)
        {
            Vector3 topLeft = new Vector3(BottomLeftCorner.X, BottomLeftCorner.Y, TopRightCorner.Z);
            Vector3 bottomLeft = BottomLeftCorner;
            Vector3 topRight = TopRightCorner;
            Vector3 bottomRight = new Vector3(TopRightCorner.X, TopRightCorner.Y, BottomLeftCorner.Z);

            Vector2 textureTopLeft = Tex.TopLeftPercent;
            Vector2 textureTopRight = new Vector2(Tex.BottomRightPercent.X, Tex.TopLeftPercent.Y);
            Vector2 textureBottomLeft = new Vector2(Tex.TopLeftPercent.X, Tex.BottomRightPercent.Y);
            Vector2 textureBottomRight = Tex.BottomRightPercent;

            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[4];
            short[] indices = new short[6];

            vertices[0] =
                new VertexPositionNormalTexture(
                topLeft, Normal, textureTopLeft);
            vertices[1] =
                new VertexPositionNormalTexture(
                topRight, Normal, textureTopRight);
            vertices[2] =
                new VertexPositionNormalTexture(
                bottomLeft, Normal, textureBottomLeft);
            vertices[3] =
                new VertexPositionNormalTexture(
                bottomRight, Normal, textureBottomRight);

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 2;
            indices[4] = 1;
            indices[5] = 3;

            return new VertexIndexData(vertices, indices);
        }
예제 #15
0
 public static void DrawCube(PrimManager PrimManager, Vector3 BottomLeftFront, Vector3 TopRightBack, TextureData Tex)
 {
     VertexIndexData _cube = PrimHelper.GenerateCubeVertices(BottomLeftFront, TopRightBack, Tex);
     PrimManager.DrawVertices(_cube, Tex.TextureMain);
 }