public static void RSDKvU_Import_Frame(EditorAnimation.EditorFrame frame, string filepath) { RSDKv5.Reader readerv5 = new RSDKv5.Reader(filepath); RSDKv5.Animation.AnimationEntry.Frame framev5 = new RSDKv5.Animation.AnimationEntry.Frame(readerv5); readerv5.Close(); RSDKv5_Load_Frame(frame, framev5); }
public static void RSDKvU_Export_Frame(EditorAnimation.EditorFrame frame, string filepath) { RSDKv5.Animation.AnimationEntry.Frame framev5 = new RSDKv5.Animation.AnimationEntry.Frame(); RSDKv5_Save_Frame(frame, framev5); RSDKv5.Writer writerv5 = new RSDKv5.Writer(filepath); framev5.Write(writerv5); writerv5.Close(); }
public void Invalidate(int texture, EditorAnimation.EditorFrame frame) { if (texture < 0 || texture >= _animationData.SpriteSheets.Count) { return; } var name = _animationData.SpriteSheets[texture]; _frames.Remove(new Tuple <string, int>(name, frame.GetHashCode())); }
public static void RSDKv1_Save_Frame(EditorAnimation.EditorFrame frame, RSDKv1.Animation.AnimationEntry.Frame framev1) { framev1.CollisionBox = frame.CollisionBox; framev1.Height = (byte)frame.Height; framev1.PivotX = (sbyte)frame.PivotX; framev1.PivotY = (sbyte)frame.PivotY; framev1.SpriteSheet = frame.SpriteSheet; framev1.Width = (byte)frame.Width; framev1.X = (byte)frame.X; framev1.Y = (byte)frame.Y; }
public void InvalidateCroppedFrame(int texture, EditorAnimation.EditorFrame frame) { if (texture < 0 || texture >= LoadedAnimationFile.SpriteSheets.Count) { return; } var name = LoadedAnimationFile.SpriteSheets[texture]; CroppedFrames.Remove(new Tuple <string, int>(name, frame.GetHashCode())); CroppedTransparentFrames.Remove(new Tuple <string, int>(name, frame.GetHashCode())); }
public static void RSDKv1_Load_Frame(EditorAnimation.EditorFrame frame, RSDKv1.Animation.AnimationEntry.Frame framev1) { frame.engineType = EngineType.RSDKv1; frame.Delay = framev1.Delay; frame.CollisionBox = framev1.CollisionBox; frame.Height = framev1.Height; frame.PivotX = framev1.PivotX; frame.PivotY = framev1.PivotY; frame.SpriteSheet = framev1.SpriteSheet; frame.Width = framev1.Width; frame.X = framev1.X; frame.Y = framev1.Y; }
public static void RSDKvRS_Save_Frame(EditorAnimation.EditorFrame frame, RSDKvRS.Animation.AnimationEntry.Frame framevRS) { framevRS.Height = (byte)frame.Height; framevRS.PivotX = (sbyte)frame.PivotX; framevRS.PivotY = (sbyte)frame.PivotY; framevRS.SpriteSheet = frame.SpriteSheet; framevRS.Width = (byte)frame.Width; framevRS.X = (byte)frame.X; framevRS.Y = (byte)frame.Y; RSDKvRS.Animation.AnimationEntry.Frame.HitBox hb = new RSDKvRS.Animation.AnimationEntry.Frame.HitBox(); RSDKvRS_Save_Hitbox(frame.HitBoxes[0], hb); framevRS.CollisionBox = hb; }
public static void RSDKvB_Load_AnimEntry(EditorAnimation.EditorAnimationInfo animEntry, RSDKvB.Animation.AnimationEntry animvB) { animEntry.AnimName = animvB.AnimName; animEntry.LoopIndex = animvB.LoopIndex; animEntry.SpeedMultiplyer = animvB.SpeedMultiplyer; animEntry.RotationFlags = animvB.RotationFlags; for (int i = 0; i < animvB.Frames.Count; i++) { EditorAnimation.EditorFrame frame = new EditorAnimation.EditorFrame(EngineType.RSDKvB, animEntry); RSDKvB_Load_Frame(frame, animvB.Frames[i]); animEntry.Frames.Add(frame); } }
public static void RSDKvRS_Load_Frame(EditorAnimation.EditorFrame frame, RSDKvRS.Animation.AnimationEntry.Frame framevRS) { frame.engineType = EngineType.RSDKvRS; frame.Delay = framevRS.Delay; frame.Height = framevRS.Height; frame.PivotX = framevRS.PivotX; frame.PivotY = framevRS.PivotY; frame.SpriteSheet = framevRS.SpriteSheet; frame.Width = framevRS.Width; frame.X = framevRS.X; frame.Y = framevRS.Y; EditorAnimation.EditorHitbox hb = new EditorAnimation.EditorHitbox(); RSDKvRS_Load_Hitbox(hb, framevRS.CollisionBox); frame.HitBoxes.Add(hb); }
public void ImportFrame() { if (Instance.ViewModel.LoadedAnimationFile == null || Instance.ViewModel.SelectedAnimation == null) { return; } var fd = new OpenFileDialog(); fd.DefaultExt = "*.frame"; fd.Filter = "RSDK Frame Files|*.frame"; if (fd.ShowDialog() == true) { var importFrame = new EditorAnimation.EditorFrame(EngineType.RSDKv5, Instance.ViewModel.SelectedAnimation); importFrame.ImportFrom(EngineType.RSDKv5, fd.FileName); Instance.ViewModel.LoadedAnimationFile.Animations[Instance.ViewModel.SelectedAnimationIndex].Frames.Add(importFrame); } }
public BitmapSource this[int texture, EditorAnimation.EditorFrame frame] { get { if (texture < 0 || texture >= _animationData.SpriteSheets.Count || frame == null) { return(null); } var name = _animationData.SpriteSheets[texture]; var tuple = new Tuple <string, int>(name, frame.GetHashCode()); if (_frames.TryGetValue(tuple, out BitmapSource bitmap)) { return(bitmap); } //if (!frame.IsEmpty) if (frame.Width > 0 && frame.Height > 0) { var textureBitmap = GetTexture(texture); try { bitmap = new CroppedBitmap(textureBitmap, new System.Windows.Int32Rect() { X = frame.X, Y = frame.Y, Width = frame.Width, Height = frame.Height }); } catch (ArgumentException) { } } else { bitmap = BitmapSource.Create(1, 1, 96, 96, PixelFormats.Bgr24, null, new byte[3] { 0, 0, 0 }, 3); } return(_frames[tuple] = bitmap); } }
public static void RSDKv5_Save_Frame(EditorAnimation.EditorFrame frame, RSDKv5.Animation.AnimationEntry.Frame framev5) { framev5.CollisionBox = frame.CollisionBox; framev5.Delay = frame.Delay; framev5.Height = frame.Height; framev5.ID = (short)frame.ID; framev5.PivotX = frame.PivotX; framev5.PivotY = frame.PivotY; framev5.SpriteSheet = frame.SpriteSheet; framev5.Width = frame.Width; framev5.X = frame.X; framev5.Y = frame.Y; for (int i = 0; i < frame.HitBoxes.Count; i++) { RSDKv5.Animation.AnimationEntry.Frame.HitBox hb = new RSDKv5.Animation.AnimationEntry.Frame.HitBox(); RSDKv5_Save_Hitbox(frame.HitBoxes[i], hb); framev5.HitBoxes.Add(hb); } }
public static void RSDKv5_Load_Frame(EditorAnimation.EditorFrame frame, RSDKv5.Animation.AnimationEntry.Frame framev5) { frame.engineType = EngineType.RSDKv5; frame.CollisionBox = framev5.CollisionBox; frame.Delay = framev5.Delay; frame.Height = framev5.Height; frame.ID = (ushort)framev5.ID; frame.PivotX = framev5.PivotX; frame.PivotY = framev5.PivotY; frame.SpriteSheet = framev5.SpriteSheet; frame.Width = framev5.Width; frame.X = framev5.X; frame.Y = framev5.Y; frame.HitBoxes = new List <EditorAnimation.EditorHitbox>(); for (int i = 0; i < framev5.HitBoxes.Count; i++) { EditorAnimation.EditorHitbox hb = new EditorAnimation.EditorHitbox(); RSDKv5_Load_Hitbox(hb, framev5.HitBoxes[i]); frame.HitBoxes.Add(hb); } }
/// <summary> /// Loads / Gets the Sprite Animation /// NOTE: /// </summary> /// <param name="name">The Name of the object</param> /// <param name="d">The DevicePanel</param> /// <param name="AnimId">The Animation ID (-1 to Load Normal)</param> /// <param name="frameId">The Frame ID for the specified Animation (-1 to load all frames)</param> /// <param name="fliph">Flip the Texture Horizontally</param> /// <param name="flipv">Flip the Texture Vertically</param> /// <returns>The fully loaded Animation</returns> public EditorAnimation LoadAnimation(string name, DevicePanel d, int AnimId, int frameId, bool fliph, bool flipv, bool rotate, bool loadImageToDX = true) { string key = $"{name}-{AnimId}-{frameId}-{fliph}-{flipv}-{rotate}"; var anim = new EditorAnimation(); if (Animations.ContainsKey(key)) { if (Animations[key].Ready) { // Use the already loaded Amination return(Animations[key]); } else { return(null); } } Animations.Add(key, anim); string path, path2; if (name == "EditorAssets" || name == "SuperSpecialRing" || name == "EditorIcons2" || name == "TransportTubes") { if (name == "EditorAssets") { path2 = Path.Combine(Environment.CurrentDirectory, "EditorAssets.bin"); if (!File.Exists(path2)) { return(null); } } else if (name == "EditorIcons2") { path2 = Path.Combine(Environment.CurrentDirectory, "EditorIcons2.bin"); if (!File.Exists(path2)) { return(null); } } else if (name == "TransportTubes") { path2 = Path.Combine(Environment.CurrentDirectory, "Global\\", "TransportTubes.bin"); if (!File.Exists(path2)) { return(null); } } else { path2 = Path.Combine(Environment.CurrentDirectory, "Global\\", "SuperSpecialRing.bin"); Debug.Print(path2); if (!File.Exists(path2)) { return(null); } } } else { if (DataDirectoryList == null) { DataDirectoryList = Directory.GetFiles(Path.Combine(Editor.DataDirectory, "Sprites"), $"*.bin", SearchOption.AllDirectories); } // Checks Global frist path = Editor.Instance.SelectedZone + "\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; if (!File.Exists(path2)) { // Checks without last character path = path = Editor.Instance.SelectedZone.Substring(0, Editor.Instance.SelectedZone.Length - 1) + "\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; } /*if (!File.Exists(path2)) * { * // Checks Editor Global * path2 = Environment.CurrentDirectory + "\\Global\\" + name + ".bin"; * }*/ if (!File.Exists(path2)) { // Checks Global path = "Global\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; } if (!File.Exists(path2)) { // Checks the Stage folder foreach (string dir in Directory.GetDirectories(Path.Combine(Editor.DataDirectory, "Sprites"), $"*", SearchOption.TopDirectoryOnly)) { path = Path.GetFileName(dir) + "\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; if (File.Exists(path2)) { break; } } } if (!File.Exists(path2)) { // Seaches all around the Data directory var list = DataDirectoryList; if (list.Any(t => Path.GetFileName(t.ToLower()).Contains(name.ToLower()))) { list = list.Where(t => Path.GetFileName(t.ToLower()).Contains(name.ToLower())).ToArray(); if (list.Any(t => t.ToLower().Contains(Editor.Instance.SelectedZone))) { path2 = list.Where(t => t.ToLower().Contains(Editor.Instance.SelectedZone)).First(); } else { path2 = list.First(); } } } if (!File.Exists(path2)) { // No animation found return(null); } } using (var stream = File.OpenRead(path2)) { rsdkAnim = new Animation(); rsdkAnim.Load(new BinaryReader(stream)); } if (AnimId == -1) { if (rsdkAnim.Animations.Any(t => t.AnimName.Contains("Normal"))) { AnimId = rsdkAnim.Animations.FindIndex(t => t.AnimName.Contains("Normal")); } else { AnimId = 0; } // Use Vertical Amination if one exists if (rotate && rsdkAnim.Animations.Any(t => t.AnimName.EndsWith(" V"))) { AnimId = rsdkAnim.Animations.FindIndex(t => t.AnimName.EndsWith(" V")); } } if (AnimId >= rsdkAnim.Animations.Count) { AnimId = rsdkAnim.Animations.Count - 1; } for (int i = 0; i < rsdkAnim.Animations[AnimId].Frames.Count; ++i) { // check we don't stray outside our loaded animations/frames // if user enters a value that would take us there, just show // a valid frame instead var animiation = rsdkAnim.Animations[AnimId]; var frame = animiation.Frames[i]; if (frameId >= 0 && frameId < animiation.Frames.Count) { frame = animiation.Frames[frameId]; } Bitmap map; if (!Sheets.ContainsKey(rsdkAnim.SpriteSheets[frame.SpriteSheet])) { string targetFile; if (name == "EditorAssets" || name == "SuperSpecialRing" || name == "EditorIcons2" || name == "TransportTubes") { if (name == "EditorAssets") { targetFile = Path.Combine(Environment.CurrentDirectory, "EditorAssets.gif"); } else if (name == "EditorIcons2") { targetFile = Path.Combine(Environment.CurrentDirectory, "EditorIcons2.gif"); } else if (name == "TransportTubes") { targetFile = Path.Combine(Environment.CurrentDirectory, "Global\\", "TransportTubes.gif"); } else { targetFile = Path.Combine(Environment.CurrentDirectory, "Global\\", "SuperSpecialRing.gif"); } } else { targetFile = Path.Combine(Editor.DataDirectory, "sprites", rsdkAnim.SpriteSheets[frame.SpriteSheet].Replace('/', '\\')); } if (!File.Exists(targetFile)) { map = null; // add a Null to our lookup, so we can avoid looking again in the future Sheets.Add(rsdkAnim.SpriteSheets[frame.SpriteSheet], map); } else { map = new Bitmap(targetFile); Sheets.Add(rsdkAnim.SpriteSheets[frame.SpriteSheet], map); } } else { map = Sheets[rsdkAnim.SpriteSheets[frame.SpriteSheet]]; } if (frame.Width == 0 || frame.Height == 0) { continue; } // can't load the animation, it probably doesn't exist in the User's Sprites folder if (map == null) { return(null); } // We are storing the first colour from the palette so we can use it to make sprites transparent var colour = map.Palette.Entries[0]; // Slow map = CropImage(map, new Rectangle(frame.X, frame.Y, frame.Width, frame.Height), fliph, flipv); RemoveColourImage(map, colour, frame.Width, frame.Height); Texture texture = null; if (loadImageToDX) { texture = TextureCreator.FromBitmap(d._device, map); } var editorFrame = new EditorAnimation.EditorFrame() { Texture = texture, Frame = frame, Entry = rsdkAnim.Animations[AnimId] }; if (!loadImageToDX) { editorFrame._Bitmap = map; } anim.Frames.Add(editorFrame); if (frameId != -1) { break; } } anim.ImageLoaded = true; if (loadImageToDX) { anim.Ready = true; } Working = false; return(anim); }
public BitmapSource GetCroppedFrame(int texture, EditorAnimation.EditorFrame frame, bool isTransparent = false) { if (!isAnimationFileLoaded) { return(null); } if (texture < 0 || texture >= LoadedAnimationFile.SpriteSheets.Count || frame == null) { return(null); } var name = LoadedAnimationFile.SpriteSheets[texture]; var tuple = new Tuple <string, int>(name, frame.GetHashCode()); if (GetCroppedFrames(isTransparent).TryGetValue(tuple, out BitmapSource bitmap)) { return(bitmap); } var textureBitmap = SpriteSheets[texture]; if (NullSpriteSheetList.Contains(name)) { bitmap = BitmapSource.Create(1, 1, 96, 96, PixelFormats.Bgr24, null, new byte[3] { 0, 0, 0 }, 3); return(SetCroppedFrames(isTransparent, tuple, bitmap)); } if (frame.Width > 0 && frame.Height > 0 && textureBitmap != null && textureBitmap.isReady) { try { var desiredType = (isTransparent ? textureBitmap.TransparentImage : textureBitmap.Image); int max_width = desiredType.PixelWidth; int max_height = desiredType.PixelHeight; int ofb_width = max_width - frame.X + frame.Width; int ofb_height = max_height - frame.Y + frame.Height; int image_width = (frame.X + frame.Width > max_width ? frame.Width + ofb_width : frame.Width); int image_height = (frame.Y + frame.Height > max_height ? frame.Height + ofb_height : frame.Height); bool oversized_X = frame.X + frame.Width > max_width; bool oversized_Y = frame.Y + frame.Height > max_height; if (oversized_X || oversized_Y) { bitmap = BitmapSource.Create(1, 1, frame.Height, frame.Width, PixelFormats.Bgr24, null, new byte[3] { 0, 0, 0 }, 3); } else { bitmap = new CroppedBitmap(desiredType, new System.Windows.Int32Rect() { X = frame.X, Y = frame.Y, Width = frame.Width, Height = frame.Height }); } } catch (ArgumentException) { bitmap = BitmapSource.Create(1, 1, frame.Height, frame.Width, PixelFormats.Bgr24, null, new byte[3] { 0, 0, 0 }, 3); } } else { bitmap = BitmapSource.Create(1, 1, 96, 96, PixelFormats.Bgr24, null, new byte[3] { 0, 0, 0 }, 3); } return(SetCroppedFrames(isTransparent, tuple, bitmap)); }
public FrameViewModel(SpriteService spriteService, EditorAnimation.EditorFrame frame) { _spriteService = spriteService; Frame = frame; }