Exemple #1
0
        /// <summary>
        /// On form loading
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DungeonForm_Load(object sender, EventArgs e)
        {
            glControl.MakeCurrent();
            Display.Init();

            SpriteBatch = new SpriteBatch();


            // Preload background texture resource
            CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png"));
            CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat;
            CheckerBoard.VerticalWrap   = TextureWrapFilter.Repeat;

            // Preload texture resources
            Icons         = new TileSet();
            Icons.Texture = new Texture2D(ResourceManager.GetInternalResource("DungeonEye.Forms.data.editor.png"));
            int id = 0;

            for (int y = 0; y < Icons.Texture.Size.Height - 50; y += 25)
            {
                for (int x = 0; x < Icons.Texture.Size.Width; x += 25)
                {
                    Tile tile = Icons.AddTile(id++);
                    tile.Rectangle = new Rectangle(x, y, 25, 25);
                }
            }
            Icons.AddTile(100).Rectangle = new Rectangle(0, 245, 6, 11);             // alcoves
            Icons.AddTile(101).Rectangle = new Rectangle(6, 248, 11, 6);             // alcoves
            Icons.AddTile(102).Rectangle = new Rectangle(17, 243, 10, 13);           // wall switch
            Icons.AddTile(103).Rectangle = new Rectangle(27, 246, 13, 10);           // wall switch


            RebuildMazeList();

            if (Dungeon.StartLocation != null && !string.IsNullOrEmpty(Dungeon.StartLocation.Maze) && MazeListBox.Items.Contains(Dungeon.StartLocation.Maze))
            {
                MazeListBox.SelectedItem = Dungeon.StartLocation.Maze;
            }
            else if (MazeListBox.Items.Count > 0)
            {
                MazeListBox.SelectedIndex = 0;
            }

            DrawTimer.Start();
        }
Exemple #2
0
        /// <summary>
        /// Form loading
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GlControlBox_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            GlControlBox.MakeCurrent();
            Display.Init();

            // Spritebatch
            Batch = new SpriteBatch();

            // Preload background texture resource
            CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png"));
            CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat;
            CheckerBoard.VerticalWrap   = TextureWrapFilter.Repeat;


            // Preload texture resources
            Icons         = new TileSet();
            Icons.Texture = new Texture2D(ResourceManager.GetInternalResource("DungeonEye.Forms.data.editor.png"));

            int id = 0;

            for (int y = 0; y < Icons.Texture.Size.Height - 50; y += 25)
            {
                for (int x = 0; x < Icons.Texture.Size.Width; x += 25)
                {
                    Tile tile = Icons.AddTile(id++);
                    tile.Rectangle = new Rectangle(x, y, 25, 25);
                }
            }
            Icons.AddTile(100).Rectangle = new Rectangle(0, 245, 6, 11);             // alcoves
            Icons.AddTile(101).Rectangle = new Rectangle(6, 248, 11, 6);             // alcoves


            ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);
            DrawTimer.Start();
        }
Exemple #3
0
        private TileSet LoadTileSet(XElement root, string fileId)
        {
            TileSet ts         = null;
            string  name       = (string)root.Attribute("name");
            int?    tileWidth  = (int?)root.Attribute("tileWidth");
            int?    tileHeight = (int?)root.Attribute("tileHeight");
            string  image      = (string)root.Attribute("image");

            if (name != null && tileWidth != null && tileHeight != null && image != null)
            {
                Texture tex = engine.GetTexture(image);
                if (tex != null)
                {
                    ts = new TileSet(name);
                    ts.AddImage(tex);
                    ts.TileWidth  = (int)tileWidth;
                    ts.TileHeight = (int)tileHeight;
                    foreach (var node in from item in root.Descendants("tile") select item)
                    {
                        int?id  = (int?)node.Attribute("id");
                        var img = node.Descendants().FirstOrDefault();
                        if (id != null && img != null)
                        {
                            int?   x        = (int?)img.Attribute("x");
                            int?   y        = (int?)img.Attribute("y");
                            int?   width    = (int?)img.Attribute("width");
                            int?   height   = (int?)img.Attribute("height");
                            int?   offsetX  = (int?)img.Attribute("offsetX");
                            int?   offsetY  = (int?)img.Attribute("offsetY");
                            string tileName = (string)img.Attribute("name");
                            if (x != null && y != null && width != null && height != null && offsetX != null && offsetY != null)
                            {
                                ts.AddTile((int)id, (int)x, (int)y, (int)width, (int)height, (int)offsetX, (int)offsetY, tileName);
                                foreach (var frameNode in from item in node.Descendants("frame") select item)
                                {
                                    x = (int?)frameNode.Attribute("x");
                                    y = (int?)frameNode.Attribute("y");
                                    int?duration = (int?)frameNode.Attribute("duration");
                                    if (duration != null)
                                    {
                                        ts.AddAnim((int)id, (int)x, (int)y, (int)duration);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(ts);
        }
Exemple #4
0
    // Start is called before the first frame update
    void Awake()
    {
        tileSet = new TileSet(Name, Description, 10, 10);
        int id = 0;

        foreach (var data in Tiles)
        {
            GameObject prefab = data.physicalTile;
            UnityTile  tile   = new UnityTile(prefab.name, id++, prefab, data.leftColor, data.topColor, data.rightColor, data.bottomColor);
            tileSet.AddTile(tile);
        }
        DefaultTile = new UnityTile(DefaultTileInfo.physicalTile.name, id, DefaultTileInfo.physicalTile, DefaultTileInfo.leftColor, DefaultTileInfo.topColor, DefaultTileInfo.rightColor, DefaultTileInfo.bottomColor);
        tileSet.SetDefaultTile(DefaultTile);
        UnityTileSet = tileSet;
    }
Exemple #5
0
        /// <summary>
        /// Process GIF to animation
        /// </summary>
        void Process()
        {
            if (Image == null)
            {
                MessageBox.Show("Load an image first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (string.IsNullOrEmpty(TileSetNameBox.Text))
            {
                MessageBox.Show("Invalid TileSet name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (string.IsNullOrEmpty(AnimationNameBox.Text))
            {
                MessageBox.Show("Invalid Animation name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (string.IsNullOrEmpty(TextureNameBox.Text))
            {
                MessageBox.Show("Invalid Texture name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }


            // The texture
            Texture2D texture = new Texture2D(ComputeTextureSize());

            // The tileset
            TileSet tileset = new TileSet();

            tileset.Name        = TileSetNameBox.Text;
            tileset.TextureName = TextureNameBox.Text + ".png";
            tileset.Texture     = texture;

            // The animation
            Animation animation = new Animation();

            animation.Name = AnimationNameBox.Text;
            animation.SetTileSet(TileSetNameBox.Text);
            SetFrame(0);
            //Bitmap bm = new Bitmap(Image);
            animation.FrameRate = TimeSpan.FromMilliseconds(BitConverter.ToInt32(Image.GetPropertyItem(20736).Value, 0) * 10);
            if (animation.FrameRate < TimeSpan.FromMilliseconds(100))
            {
                animation.FrameRate = TimeSpan.FromMilliseconds(100);
            }
            if (BitConverter.ToInt16(Image.GetPropertyItem(20737).Value, 0) != 1)
            {
                animation.Type = AnimationType.Loop;
            }



            Point location = Point.Empty;
            int   id       = 0;

            for (int f = int.Parse(FirstFrameBox.Value.ToString()); f < int.Parse(LastFrameBox.Value.ToString()); f++)
            {
                // Select the frame
                SetFrame(f);
                Bitmap bm = new Bitmap(Image);

                if (location.X + bm.Width > texture.Size.Width)
                {
                    location.X  = 0;
                    location.Y += bm.Height;
                }

                //
                // Blit the frame to the texture
                texture.SetData(bm, location);

                // Add in the tileset
                tileset.AddTile(id, new Rectangle(location, bm.Size));

                // Move to the next free location
                location.Offset(bm.Width, 0);

                animation.AddFrame(id);

                // Next id
                id++;
            }



            //
            // Save assets to the manager
            //texture.SaveToBank("", TextureNameBox.Text + ".png");
            ResourceManager.AddAsset <TileSet>(TileSetNameBox.Text, tileset);
            ResourceManager.AddAsset <Animation>(AnimationNameBox.Text, animation);

            texture.Dispose();

            Close();
        }
        /// <summary>
        /// MouseDown event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GLTextureControl_MouseDown(object sender, MouseEventArgs e)
        {
            int   zoomvalue = int.Parse((string)ZoomBox.SelectedItem);
            Point position  = new Point((e.Location.X - TextureOffset.X) / zoomvalue, (e.Location.Y - TextureOffset.Y) / zoomvalue);

            #region Left
            if (e.Button == MouseButtons.Left)
            {
                // Select a tile by left click + ctrl
                if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                {
                    // Get the tile under the cursor
                    foreach (int id in TileSet.Tiles)
                    {
                        Tile tile = TileSet.GetTile(id);
                        if (tile != null && tile.Rectangle.Contains(position))
                        {
                            TileIDBox.Value = id;
                            //SetCurrentTile(tile);
                            return;
                        }
                    }
                }

                // Change tile selection
                else if (SelectionBox.Checked)
                {
                    // Size the selection box
                    if (SelectionTool.MouseTool == MouseTools.NoTool)
                    {
                        // No tile, so create one
                        if (CurrentTile == null)
                        {
                            SetCurrentTile(TileSet.AddTile((int)TileIDBox.Value));
                        }

                        SelectionTool.Rectangle = new Rectangle(position, Size.Empty);
                        SelectionTool.MouseTool = MouseTools.SizeDownRight;
                    }
                }
                else if (HotSpotBox.Checked)
                {
                }
                else if (ColisionBox.Checked)
                {
                }
            }
            #endregion

            #region Right

            // Auto detect tile border
            else if ((e.Button == MouseButtons.Right))
            {
                // Auto detect edges
                if (SelectionBox.Checked)
                {
                    // No texture
                    if (TileSet.Texture == null)
                    {
                        return;
                    }

                    // No tile, so create one
                    if (CurrentTile == null)
                    {
                        SetCurrentTile(TileSet.AddTile((int)TileIDBox.Value));
                    }

                    Point start = new Point(
                        (int)((e.Location.X - TextureOffset.X) / zoomvalue),
                        (int)((e.Location.Y - TextureOffset.Y) / zoomvalue));

                    SelectionTool.Rectangle = DetectTileEdges(start);
                }
                else
                {
                    // Pan the texture
                    LastMousePos = e.Location;
                }
            }

            #endregion

            #region Middle
            // Pan the texture
            else if (e.Button == MouseButtons.Middle)
            {
                LastMousePos = e.Location;
            }
            #endregion


            // Transmit event to the selection box
            if (SelectionTool != null && (SelectionBox.Checked || HotSpotBox.Checked || ColisionBox.Checked))
            {
                SelectionTool.OnMouseDown(e);
            }
        }
		/// <summary>
		/// Form loading
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void GlControlBox_Load(object sender, EventArgs e)
		{
			if (DesignMode)
				return;

			GlControlBox.MakeCurrent();
			Display.Init();

			// Spritebatch
            Batch = new SpriteBatch();

			// Preload background texture resource
			CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png"));
			CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat;
			CheckerBoard.VerticalWrap = TextureWrapFilter.Repeat;


			// Preload texture resources
			Icons = new TileSet();
			Icons.Texture = new Texture2D(ResourceManager.GetInternalResource("DungeonEye.Forms.data.editor.png"));

			int id = 0;
			for (int y = 0; y < Icons.Texture.Size.Height - 50; y += 25)
			{
				for (int x = 0; x < Icons.Texture.Size.Width; x += 25)
				{
					Tile tile = Icons.AddTile(id++);
					tile.Rectangle = new Rectangle(x, y, 25, 25);
				}
			}
			Icons.AddTile(100).Rectangle = new Rectangle(0, 245, 6, 11); // alcoves
			Icons.AddTile(101).Rectangle = new Rectangle(6, 248, 11, 6); // alcoves


			ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);
			DrawTimer.Start();
	
		}
		/// <summary>
		/// On form loading
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void DungeonForm_Load(object sender, EventArgs e)
		{

			glControl.MakeCurrent();
			Display.Init();

			SpriteBatch = new SpriteBatch();


			// Preload background texture resource
			CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png"));
			CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat;
			CheckerBoard.VerticalWrap = TextureWrapFilter.Repeat;

			// Preload texture resources
			Icons = new TileSet();
			Icons.Texture = new Texture2D(ResourceManager.GetInternalResource("DungeonEye.Forms.data.editor.png"));
			int id = 0;
			for (int y = 0 ; y < Icons.Texture.Size.Height - 50 ; y += 25)
			{
				for (int x = 0 ; x < Icons.Texture.Size.Width ; x += 25)
				{
					Tile tile = Icons.AddTile(id++);
					tile.Rectangle = new Rectangle(x, y, 25, 25);
				}
			}
			Icons.AddTile(100).Rectangle = new Rectangle(0, 245, 6, 11); // alcoves
			Icons.AddTile(101).Rectangle = new Rectangle(6, 248, 11, 6); // alcoves
			Icons.AddTile(102).Rectangle = new Rectangle(17, 243, 10, 13); // wall switch
			Icons.AddTile(103).Rectangle = new Rectangle(27, 246, 13, 10); // wall switch


			RebuildMazeList();

			if (Dungeon.StartLocation != null && !string.IsNullOrEmpty(Dungeon.StartLocation.Maze) && MazeListBox.Items.Contains(Dungeon.StartLocation.Maze))
				MazeListBox.SelectedItem = Dungeon.StartLocation.Maze;
			else if (MazeListBox.Items.Count > 0)
				MazeListBox.SelectedIndex = 0;

			DrawTimer.Start();

		}
Exemple #9
0
        private TileSet InternalLoadTileSet(IniFile ini, string fileId)
        {
            TileSet ts  = null;
            string  img = ini.ReadString("", "img");

            if (!string.IsNullOrEmpty(img))
            {
                Texture tex = engine.GetTexture(img);
                if (tex != null)
                {
                    ts = new TileSet(fileId);
                    var   sec    = ini.Sections.FirstOrDefault(sn => sn.Name.Equals(""));
                    int[] values = null;
                    if (sec != null)
                    {
                        foreach (var k in sec.KeyList)
                        {
                            switch (k.Ident)
                            {
                            case "tile":
                                values = k.Value.ToIntValues();
                                if (values.Length >= 6)
                                {
                                    int index   = values[0];
                                    int clipX   = values[1];
                                    int clipY   = values[2];
                                    int clipW   = values[3];
                                    int clipH   = values[4];
                                    int offsetX = values[5];
                                    int offsetY = values[6];
                                    ts.AddTile(index, clipX, clipY, clipW, clipH, offsetX, offsetY);
                                }
                                break;

                            case "animation":
                                var sValues = k.Value.ToStrValues(';');
                                var tileId  = sValues[0].ToIntValue();
                                for (int i = 1; i < sValues.Length; i++)
                                {
                                    var subValue = sValues[i];
                                    if (subValue.EndsWith("ms"))
                                    {
                                        subValue = subValue.Replace("ms", "");
                                    }
                                    values = subValue.ToIntValues();
                                    if (values.Length >= 3)
                                    {
                                        ts.AddAnim(tileId, values[0], values[1], values[2]);
                                    }
                                }
                                break;

                            case "img":
                                tex = engine.GetTexture(k.Value);
                                ts.AddImage(tex);
                                break;
                            }
                        }
                    }
                }
            }
            return(ts);
        }