Exemplo n.º 1
0
        public static TileAnimation LoadFromJson(JToken json, Point2D basePos)
        {
            var ani = new TileAnimation();

            // RPG Maker XP animations are based on one tileset
            var tilesetSource = new TileCellSource(json["graphic"].ToString(), 0, 0, Constants.AnimationTilesetWidth, Constants.AnimationTilesetHeight);
            var tileset       = EngineCore.ContentLoader.GetAnimationTileset(tilesetSource.TextureIndex);
            var tilesPerRow   = tileset.Width / tilesetSource.Width;

            var frames = (JArray)json["frames"];

            foreach (var frame in frames)
            {
                var frameImages = (JArray)frame;
                var tileFrame   = new TileAnimationFrame();
                foreach (var frameImage in frameImages)
                {
                    /*
                     * pattern: 1,		// 1-based tile index
                     * x: 0,			// center-based x-offset
                     * y: 16,			// center-based y-offset
                     * zoom: 30,		// 100-based scale
                     * rotation: 0,		// 360-degree
                     * opacity: 100		// 255 = full visible, 0 = full trans
                     */
                    // Make index 0-based!
                    var patIndex    = (int)(frameImage["pattern"]) - 1;
                    var patX        = (int)(frameImage["x"]);
                    var patY        = (int)(frameImage["y"]);
                    var patZoom     = (int)(frameImage["zoom"]);
                    var patRotation = (int)(frameImage["rotation"]);
                    var patOpacity  = (int)(frameImage["opacity"]);

                    if (patIndex > 0)
                    {
                        tilesetSource.X = (patIndex % tilesPerRow) * tilesetSource.Width;
                        tilesetSource.Y = (patIndex / tilesPerRow) * tilesetSource.Width;
                    }
                    else
                    {
                        tilesetSource.X = 0;
                        tilesetSource.Y = 0;
                    }
                    var scale        = patZoom / 100f;
                    var pos          = new Point2D(patX + basePos.X, patY + basePos.Y);
                    var mirror       = SpriteEffects.None;
                    var col          = new Color(Color.White.R, Color.White.G, Color.White.B, patOpacity);
                    var isBackground = false;                     // TODO: How does RPG Maker handle this?
                    var rot          = (float)patRotation;
                    var pattern      = new TileAnimationFrameImage(tilesetSource.Clone() as TileCellSource, scale, pos, mirror, col, rot, isBackground);
                    tileFrame.Add(pattern);
                }

                ani.Frames.Add(tileFrame);
            }

            return(ani);
        }
Exemplo n.º 2
0
		public FrameImageListItem(int frame, int frameImage, TileAnimationFrameImage image)
			: base(new[] {
				(frameImage + 1).ToString(CultureInfo.InvariantCulture),
				(image.IsBackground ? "Back" : "Front")
				}) {
			FrameIndex = frame;
			FrameImageIndex = frameImage;
			FrameImage = image;
		}
        public object Clone()
        {
            var img = new TileAnimationFrameImage {
                TextureSource = TextureSource,
                Scale         = Scale,
                Offset        = Offset,
                Mirror        = Mirror,
                Rotation      = Rotation,
                Color         = Color,
                IsBackground  = IsBackground
            };

            return(img);
        }
Exemplo n.º 4
0
		public static TileAnimation LoadFromJson(JToken json, Point2D basePos) {
			var ani = new TileAnimation();

			// RPG Maker XP animations are based on one tileset
			var tilesetSource = new TileCellSource(json["graphic"].ToString(), 0, 0, Constants.AnimationTilesetWidth, Constants.AnimationTilesetHeight);
			var tileset = EngineCore.ContentLoader.GetAnimationTileset(tilesetSource.TextureIndex);
			var tilesPerRow = tileset.Width / tilesetSource.Width;

			var frames = (JArray)json["frames"];
			foreach (var frame in frames) {
				var frameImages = (JArray)frame;
				var tileFrame = new TileAnimationFrame();
				foreach (var frameImage in frameImages) {
					/*
					 * pattern: 1,		// 1-based tile index
					 * x: 0,			// center-based x-offset
					 * y: 16,			// center-based y-offset
					 * zoom: 30,		// 100-based scale
					 * rotation: 0,		// 360-degree
					 * opacity: 100		// 255 = full visible, 0 = full trans
					 */
					// Make index 0-based!
					var patIndex = (int)(frameImage["pattern"]) - 1;
					var patX = (int)(frameImage["x"]);
					var patY = (int)(frameImage["y"]);
					var patZoom = (int)(frameImage["zoom"]);
					var patRotation = (int)(frameImage["rotation"]);
					var patOpacity = (int)(frameImage["opacity"]);

					if (patIndex > 0) {
						tilesetSource.X = (patIndex % tilesPerRow) * tilesetSource.Width;
						tilesetSource.Y = (patIndex / tilesPerRow) * tilesetSource.Width;
					} else {
						tilesetSource.X = 0;
						tilesetSource.Y = 0;
					}
					var scale = patZoom / 100f;
					var pos = new Point2D(patX + basePos.X, patY + basePos.Y);
					var mirror = SpriteEffects.None;
					var col = new Color(Color.White.R, Color.White.G, Color.White.B, patOpacity);
					var isBackground = false; // TODO: How does RPG Maker handle this?
					var rot = (float)patRotation;
					var pattern = new TileAnimationFrameImage(tilesetSource.Clone() as TileCellSource, scale, pos, mirror, col, rot, isBackground);
					tileFrame.Add(pattern);
				}

				ani.Frames.Add(tileFrame);
			}

			return ani;
		}
Exemplo n.º 5
0
		public object Clone() {
			var img = new TileAnimationFrameImage {
				TextureSource = TextureSource,
				Scale = Scale,
				Offset = Offset,
				Mirror = Mirror,
				Rotation = Rotation,
				Color = Color,
				IsBackground = IsBackground
			};
			return img;
		}
Exemplo n.º 6
0
		/// <exception cref="Exception"></exception>
		private void RenderDisplayAnimation_MouseUp(object sender, MouseEventArgs e) {
			RenderDisplayAnimation.Focus();

			if (mSelectedFrame == -1) {
				return;
			}
			if (AnimationTimerRunning) {
				return;
			}

			// Place a new Image
			if (mSelectedAnimation != -1 && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)) {
				var imagePos = CalculateNewImagePosition();

				var img = new TileAnimationFrameImage {
					TextureSource = GetTextureSource(pnlTilesetThumbs.Controls[mSelectedAnimation].Name),
					Scale = 0.5f,
					Offset = imagePos,
					IsBackground = (e.Button == MouseButtons.Left)
				};
				img.Scale = (Constants.AnimationWidth / (float)Constants.AnimationTilesetWidth);
				// Add to animation object
				mAnimation.Frames[mSelectedFrame].Add(img);

				// Add to frame image list
				var item = new FrameImageListItem(mSelectedFrame, mAnimation.Frames[mSelectedFrame].Count - 1, img);
				var listViewItem = listFrameImages.Items.Add(item);
				// Select frame image
				listFrameImages.SelectedItems.Clear();
				listFrameImages.SelectedIndices.Add(listFrameImages.Items.IndexOf(listViewItem));

				return;
			}

			// Select a Image from the frame
			var frame = mAnimation.Frames[mSelectedFrame];
			var intersectionPosition = mMousePosition;
			int i;
			for (i = frame.Count - 1; i >= 0; i--) {
				if (intersectionPosition.Contains(frame[i].GetDestinationRectangle(RenderDisplayCenterPosition)))
					break;
			}
			if (i == -1) { // no collision
				listFrameImages.SelectedIndices.Clear();
				return;
			}

			// Search the listImages Index
			for (var l = 0; l < listFrameImages.Items.Count; l++) {
				var item = listFrameImages.Items[l] as FrameImageListItem;
				if (item == null) {
					throw new Exception("Invalid item data in frame image list at index " + i);
				}

				if (item.FrameIndex != mSelectedFrame || item.FrameImageIndex != i) {
					continue;
				}

				listFrameImages.SelectedIndices.Clear();
				listFrameImages.SelectedIndices.Add(l);
				break;
			}
		}