public CreateAction(int charIndex, ActiveChar character, CharSprite.ActionType action) { this.charIndex = charIndex; this.Action = action; this.charData = character.CharData; this.dir = character.CharDir; }
public CreateAction(int charIndex, ActiveChar character, CharSprite.ActionType action) { CharIndex = charIndex; Action = action; charData = character.CharData; dir = character.CharDir; }
public CreateAction(int charIndex, ActiveChar character, CharSprite.ActionType action, bool looping, bool inPlace) { CharIndex = charIndex; Action = action; charData = character.CharData; dir = character.CharDir; Looping = looping; InPlace = inPlace; }
public BeamMoveAnimation(Loc2D startLoc, int animIndex, RenderTime animTime, Maps.Direction8 dir, int distance, RenderTime lastingTime) { StartLoc = startLoc; AnimationIndex = animIndex; FrameLength = animTime; Direction = dir; TotalDistance = distance; LastingTime = lastingTime; }
public CreateAction(int charIndex, ActiveChar character, CharSprite.ActionType action, bool looping, bool inPlace) { this.charIndex = charIndex; this.Action = action; this.charData = character.CharData; this.dir = character.CharDir; this.Looping = looping; this.InPlace = inPlace; }
public ArrowMoveAnimation(Loc2D startLoc, int animIndex, RenderTime animTime, Maps.Direction8 dir, int distance, int speed) { StartLoc = startLoc; AnimationIndex = animIndex; FrameLength = animTime; Direction = dir; TotalWaves = distance; TotalDistance = distance * TextureManager.TILE_SIZE; TravelSpeed = speed; }
public int GetFrameCount(FrameType type, Maps.Direction8 dir) { if (frameCount.TryGetValue(type, out Dictionary <Maps.Direction8, int> dirs)) { if (dirs.TryGetValue(dir, out int value)) { return(value); } } return(0); }
public Rectangle GetFrameBounds(FrameType frameType, Maps.Direction8 direction, int frameNum) { Rectangle rec = new Rectangle { X = frameNum * FrameData.FrameWidth, Y = 0, Width = FrameData.FrameWidth, Height = FrameData.FrameHeight }; return(rec); }
public TileMoveAnimation(Loc2D startLoc, int animIndex, RenderTime animTime, int loops, Enums.RangeType rangeType, Maps.Direction8 dir, int range, RenderTime stallTime) { AnimationIndex = animIndex; FrameLength = animTime; TotalLoops = loops; StartLoc = startLoc; RangeType = rangeType; Direction = dir; TotalDistance = range; StallTime = stallTime; FrameTime = StallTime; }
public MapResizeWindow(int width, int height) { InitializeComponent(); Width = width; Height = height; nudWidth.Value = width; nudHeight.Value = height; ResizeDir = Maps.Direction8.None; RefreshResizeDir(); }
public void SetFrameCount(FrameType type, Maps.Direction8 dir, int count) { if (frameCount.ContainsKey(type) == false) { frameCount.Add(type, new Dictionary <Maps.Direction8, int>()); } if (frameCount[type].ContainsKey(dir) == false) { frameCount[type].Add(dir, count); } else { frameCount[type][dir] = count; } }
public void AddSheet(FrameType type, Maps.Direction8 dir, TileSheet surface) { if (!animations.ContainsKey(type)) { animations.Add(type, new Dictionary <Maps.Direction8, TileSheet>()); } if (animations[type].ContainsKey(dir) == false) { animations[type].Add(dir, surface); } else { animations[type][dir] = surface; } }
public TileSheet GetSheet(FrameType type, Maps.Direction8 dir) { if (IsFrameTypeDirectionless(type)) { dir = Maps.Direction8.Down; } if (animations.ContainsKey(type)) { if (animations[type].ContainsKey(dir)) { return(animations[type][dir]); } } return(TextureManager.ErrorTexture); }
public virtual void Resize(int width, int height, Maps.Direction8 dir) { Loc2D diff = Operations.GetResizeOffset(MapArray.GetLength(0), MapArray.GetLength(1), width, height, dir); Operations.ResizeArray <Tile>(ref MapArray, width, height, dir, true); for (int i = 0; i < GroundLayers.Count; i++) { Game.UpdateLoadMsg("Resizing Map... (Layer " + GroundLayers[i].Name + ")"); GroundLayers[i].Resize(width, height, dir); } for (int i = 0; i < PropBackLayers.Count; i++) { Game.UpdateLoadMsg("Resizing Map... (Layer " + PropBackLayers[i].Name + ")"); PropBackLayers[i].Resize(width, height, dir); } for (int i = 0; i < PropFrontLayers.Count; i++) { Game.UpdateLoadMsg("Resizing Map... (Layer " + PropFrontLayers[i].Name + ")"); PropFrontLayers[i].Resize(width, height, dir); } for (int i = 0; i < FringeLayers.Count; i++) { Game.UpdateLoadMsg("Resizing Map... (Layer " + FringeLayers[i].Name + ")"); FringeLayers[i].Resize(width, height, dir); } for (int i = 0; i < NpcSpawns.Count; i++) { if (NpcSpawns[i].Loc.X > -1 && NpcSpawns[i].Loc.Y > -1) { NpcSpawns[i].Loc += diff; if (NpcSpawns[i].Loc.X < 0) { NpcSpawns[i].Loc.X = 0; } if (NpcSpawns[i].Loc.Y < 0) { NpcSpawns[i].Loc.Y = 0; } } } }
private void BtnCenter_Click(object sender, EventArgs e) { ResizeDir = Maps.Direction8.None; RefreshResizeDir(); }
private static SpriteSheet CompileSpriteInternal(string spriteRootDirectory) { Dictionary <FrameType, Dictionary <Maps.Direction8, List <Bitmap> > > frameCollection = new Dictionary <FrameType, Dictionary <Maps.Direction8, List <Bitmap> > >(); Dictionary <FrameType, List <Bitmap> > miscFrameCollection = new Dictionary <FrameType, List <Bitmap> >(); List <string> usedFrames = new List <string>(); //get all frames foreach (FrameType frameType in Enum.GetValues(typeof(FrameType))) { if (!SpriteSheet.IsFrameTypeDirectionless(frameType)) { Dictionary <Maps.Direction8, List <Bitmap> > frameTypeDirectionCollection = new Dictionary <Maps.Direction8, List <Bitmap> >(); for (int j = 0; j < 8; j++) { Maps.Direction8 direction = (Maps.Direction8)j; List <Bitmap> frameTypeCollection = new List <Bitmap>(); frameTypeDirectionCollection.Add(direction, frameTypeCollection); foreach (Tuple <string, Bitmap> frameSurface in GetAllFrames(spriteRootDirectory, frameType + "-" + direction + "-")) { frameTypeCollection.Add(frameSurface.Item2); usedFrames.Add(frameSurface.Item1); } //conversionNotes.Text += "Found " + frameTypeCollection.Count + " frames for " + frameType.ToString() + " (" + direction.ToString() + ") animation.\r\n"; } frameCollection.Add(frameType, frameTypeDirectionCollection); } else { List <Bitmap> frameTypeCollection = new List <Bitmap>(); miscFrameCollection.Add(frameType, frameTypeCollection); foreach (Tuple <string, Bitmap> frameSurface in GetAllFrames(spriteRootDirectory, frameType.ToString() + "-")) { frameTypeCollection.Add(frameSurface.Item2); usedFrames.Add(frameSurface.Item1); } //conversionNotes.Text += "Found " + frameTypeCollection.Count + " frames for " + frameType.ToString() + " (Directionless) animation.\r\n"; } } if (usedFrames.Count < 1) { throw new Exception("No frames"); } List <string> pngs = new List <string>(Directory.GetFiles(spriteRootDirectory, "*.png", SearchOption.TopDirectoryOnly)); if (pngs.Count > usedFrames.Count) { foreach (Dictionary <Maps.Direction8, List <Bitmap> > dict in frameCollection.Values) { foreach (List <Bitmap> list in dict.Values) { foreach (Bitmap bitmap in list) { bitmap.Dispose(); } } } foreach (List <Bitmap> list in miscFrameCollection.Values) { foreach (Bitmap bitmap in list) { bitmap.Dispose(); } } foreach (string path in usedFrames) { for (int i = pngs.Count - 1; i >= 0; i--) { if (pngs[i] == path) { pngs.RemoveAt(i); } } } string errorMsg = spriteRootDirectory + ": The following files do not match the naming pattern, or a preceding file is missing:"; for (int i = 0; i < pngs.Count; i++) { errorMsg += "\n" + pngs[i].Substring(pngs[i].LastIndexOf('\\')); } throw new Exception(errorMsg); } SpriteSheet sprite = BuildSpriteSurface(frameCollection, miscFrameCollection, spriteRootDirectory); return(sprite); }
public void Resize(int width, int height, Maps.Direction8 dir) { Operations.ResizeArray <TileAnim>(ref Tiles, width, height, dir, true); }
public virtual void Resize(int width, int height, Maps.Direction8 dir) { base.Resize(width, height, dir); }
public Defeated(int charIndex, ActiveChar character) { this.charIndex = charIndex; this.charData = character.CharData; this.dir = character.CharDir; }
public void LoadFromData(BinaryReader reader, int totalByteSize) { foreach (FrameType frameType in Enum.GetValues(typeof(FrameType))) { if (IsFrameTypeDirectionless(frameType) == false) { for (int i = 0; i < 8; i++) { Maps.Direction8 dir = (Maps.Direction8)i; int frameCount = reader.ReadInt32(); frameData.SetFrameCount(frameType, dir, frameCount); int size = reader.ReadInt32(); if (size > 0) { byte[] imgData = reader.ReadBytes(size); TileSheet sheetSurface = new TileSheet(); using (MemoryStream stream = new MemoryStream(imgData)) { try { sheetSurface.LoadPixelsFromBytes(stream); sheetSurface.LoadTextureFromPixels32(); sheetSurface.GenerateDataBuffer(sheetSurface.ImageWidth / frameCount, sheetSurface.ImageHeight); } catch (Exception ex) { sheetSurface.Dispose(); throw new Exception("Error reading image data for " + frameType.ToString() + " " + dir.ToString() + "\n", ex); } } AddSheet(frameType, dir, sheetSurface); frameData.SetFrameSize(sheetSurface.ImageWidth, sheetSurface.ImageHeight, frameCount); } } } else { int frameCount = reader.ReadInt32(); frameData.SetFrameCount(frameType, PMDToolkit.Maps.Direction8.Down, frameCount); int size = reader.ReadInt32(); if (size > 0) { byte[] imgData = reader.ReadBytes(size); TileSheet sheetSurface = new TileSheet(); using (MemoryStream stream = new MemoryStream(imgData)) { try { sheetSurface.LoadPixelsFromBytes(stream); sheetSurface.LoadTextureFromPixels32(); } catch (Exception ex) { sheetSurface.Dispose(); throw new Exception("Error reading image data for " + frameType.ToString() + "\n", ex); } } sheetSurface.GenerateDataBuffer(sheetSurface.ImageWidth / frameCount, sheetSurface.ImageHeight); AddSheet(frameType, PMDToolkit.Maps.Direction8.Down, sheetSurface); frameData.SetFrameSize(sheetSurface.ImageWidth, sheetSurface.ImageHeight, frameCount); } } } this.sizeInBytes = totalByteSize; }
private void BtnBottomRight_Click(object sender, EventArgs e) { ResizeDir = Maps.Direction8.DownRight; RefreshResizeDir(); }
private static SpriteSheet BuildSpriteSurface(Dictionary <FrameType, Dictionary <Maps.Direction8, List <Bitmap> > > frameCollection, Dictionary <FrameType, List <Bitmap> > miscFrameCollection, string spriteRootDirectory) { int frameHeight = 0; int frameWidth = 0; SpriteSheet sprite = new SpriteSheet(); //set frame count and frame size for (int i = 0; i < frameCollection.Keys.Count; i++) { Dictionary <Maps.Direction8, List <Bitmap> > frameDirectionCollection = frameCollection.Values.ElementAt(i); for (int j = 0; j < 8; j++) { Maps.Direction8 direction = (Maps.Direction8)j; int totalSurfaceWidth = 0; int lastX = 0; List <Bitmap> frameList = frameDirectionCollection[direction]; sprite.FrameData.SetFrameCount(frameCollection.Keys.ElementAt(i), direction, frameList.Count); foreach (Bitmap frame in frameList) { if (frameHeight == 0) { frameHeight = frame.Height; } else if (frameHeight != frame.Height) { throw new Exception("Frameheight mismatch: " + frameCollection.Keys.ElementAt(i).ToString() + " " + direction.ToString() + " (" + frameHeight + " vs. " + frame.Height + ")"); } if (frameWidth == 0) { frameWidth = frame.Width; } else if (frameWidth != frame.Width) { throw new Exception("Framewidth mismatch: " + frameCollection.Keys.ElementAt(i).ToString() + " " + direction.ToString() + " (" + frameWidth + " vs. " + frame.Width + ")"); } totalSurfaceWidth += frame.Width; } TileSheet animSheet = null; if (totalSurfaceWidth > 0) { animSheet = new TileSheet(); animSheet.CreatePixels32(totalSurfaceWidth, frameHeight); } foreach (Bitmap frame in frameList) { BitmapData frameData = frame.LockBits(new Rectangle(0, 0, frame.Width, frame.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); animSheet.Blit(frameData, 0, 0, frame.Width, frame.Height, lastX, 0); frame.UnlockBits(frameData); lastX += frame.Width; frame.Dispose(); } sprite.AddSheet(frameCollection.Keys.ElementAt(i), direction, animSheet); } } //set frame count and frame size for (int i = 0; i < miscFrameCollection.Count; i++) { int totalSurfaceWidth = 0; int lastX = 0; List <Bitmap> frameList = miscFrameCollection.Values.ElementAt(i); sprite.FrameData.SetFrameCount(miscFrameCollection.Keys.ElementAt(i), Maps.Direction8.Down, frameList.Count); foreach (Bitmap frame in frameList) { if (frameHeight == 0) { frameHeight = frame.Height; } else if (frameHeight != frame.Height) { throw new Exception("Frameheight mismatch: " + frameCollection.Keys.ElementAt(i).ToString() + " (" + frameHeight + " vs. " + frame.Height + ")"); } if (frameWidth == 0) { frameWidth = frame.Width; } else if (frameWidth != frame.Width) { throw new Exception("Framewidth mismatch: " + frameCollection.Keys.ElementAt(i).ToString() + " (" + frameWidth + " vs. " + frame.Width + ")"); } totalSurfaceWidth += frame.Width; } TileSheet animSheet = null; if (totalSurfaceWidth > 0) { animSheet = new TileSheet(); animSheet.CreatePixels32(totalSurfaceWidth, frameHeight); } foreach (Bitmap frame in frameList) { BitmapData frameData = frame.LockBits(new Rectangle(0, 0, frame.Width, frame.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); animSheet.Blit(frameData, 0, 0, frame.Width, frame.Height, lastX, 0); frame.UnlockBits(frameData); lastX += frame.Width; frame.Dispose(); } sprite.AddSheet(miscFrameCollection.Keys.ElementAt(i), Maps.Direction8.Down, animSheet); } return(sprite); }
private void btnBottomLeft_Click(object sender, EventArgs e) { ResizeDir = Maps.Direction8.DownLeft; RefreshResizeDir(); }
private void BtnTopLeft_Click(object sender, EventArgs e) { ResizeDir = Maps.Direction8.UpLeft; RefreshResizeDir(); }
private static void CompileSpriteToFile(string spriteDir, Dictionary <string, byte[]> spriteData, int num, int form, int shiny, int gender) { //check to see if files exist string[] pngs = Directory.GetFiles(spriteDir, "*.png", SearchOption.TopDirectoryOnly); if (pngs.Length < 1) { return; } string outForm = "r"; if (form >= 0) { outForm += "-" + form; if (shiny >= 0) { outForm += "-" + shiny; if (gender >= 0) { outForm += "-" + gender; } } } try { SpriteSheet sprite = CompileSpriteInternal(spriteDir); using (MemoryStream spriteStream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(spriteStream)) { //Go through each frame type, get metadata, sprite data foreach (FrameType frameType in Enum.GetValues(typeof(FrameType))) { if (!SpriteSheet.IsFrameTypeDirectionless(frameType)) { for (int j = 0; j < 8; j++) { Maps.Direction8 dir = (Maps.Direction8)j; int frameCountSize = sprite.FrameData.GetFrameCount(frameType, dir); TileSheet anim = sprite.GetSheet(frameType, dir); // Add frame count size writer.Write(frameCountSize); int sheetSize = 0; byte[] memStreamArray = new byte[0]; if (anim != null) { using (MemoryStream memoryStream = new MemoryStream()) { anim.Save(memoryStream, ImageFormat.Png); memStreamArray = memoryStream.ToArray(); sheetSize = memStreamArray.Length; } anim.Dispose(); } // Add the animation size writer.Write(sheetSize); //add the animation itself if (sheetSize > 0) { spriteStream.Write(memStreamArray, 0, memStreamArray.Length); } } } else { int frameCountSize = sprite.FrameData.GetFrameCount(frameType, Maps.Direction8.Down); TileSheet anim = sprite.GetSheet(frameType, Maps.Direction8.Down); // Add frame count size writer.Write(frameCountSize); int sheetSize = 0; byte[] memStreamArray = new byte[0]; if (anim != null) { using (MemoryStream memoryStream = new MemoryStream()) { anim.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); memStreamArray = memoryStream.ToArray(); sheetSize = memStreamArray.Length; } anim.Dispose(); } // Add the animation size writer.Write(sheetSize); //add the animation itself if (sheetSize > 0) { spriteStream.Write(memStreamArray, 0, memStreamArray.Length); } } } } byte[] writingBytes = spriteStream.ToArray(); spriteData.Add(outForm, writingBytes); } } catch (Exception ex) { throw new Exception("Error compiling sprite" + spriteDir + "\n", ex); } }
private void btnRight_Click(object sender, EventArgs e) { ResizeDir = Maps.Direction8.Right; RefreshResizeDir(); }