//============================================================ // <T>加载设置信息。</T> // // @param xconfig 设置节点 //============================================================ public void LoadConfig(FXmlNode xconfig) { // 读取属性 _isReversed = xconfig.GetBoolean("is_reversed", _isReversed); if (xconfig.Contains("reverse_direction")) { int reverseDirection = xconfig.GetInteger("reverse_direction"); _reverseDirection = IntToDirction(reverseDirection); } _frameDelay = xconfig.GetInteger("frame_delay", _frameDelay); // 读取剪辑集合 FXmlNode xframes = xconfig.Find("Frames"); if (xframes != null) { foreach (FXmlNode xnode in xframes.Nodes) { if (xnode.IsName("Frame")) { int index = xnode.GetInteger("index"); FRsResourceFrame frame = _frames.Get(index, null); if (frame != null) { frame.LoadConfig(xnode); } } } } }
//============================================================ // <T>增加帧。</T> // // @param frame 帧 //============================================================ public void PushFrame(FRsResourceFrame frame) { frame.Animation = _animation; frame.Clip = this; frame.Index = _frames.Count; _frames.Push(frame); }
//============================================================ // <T>扫描资源。</T> //============================================================ public override void Scan() { base.Scan(); // 扫描所有文件 _optionValid = true; FStrings fileNames = RDirectory.ListFiles(_directory); fileNames.Sort(); foreach (string fileName in fileNames) { // 文件是否图片 string name = fileName.Substring(fileName.LastIndexOf("\\") + 1); if (name.EndsWith(".png")) { name = name.Substring(0, name.Length - 4); // 是否符合命名标准 if (5 == name.Length) { int direction = RInt.Parse(name.Substring(0, 1)); int frameIndex = RInt.Parse(name.Substring(1)) - 1; // 同步剪辑 FRsResourceClip clip = SyncClip(direction); FRsResourceFrame frame = new FRsResourceFrame(); frame.FileName = fileName; clip.PushFrame(frame); // 设置有效 _optionValid = true; } else { RMoCore.TrackConsole.Write(this, "Scan", "Invalid picture define. (file_name={0})", fileName); } } } // 检查剪辑帧数相等 FRsResourceClip firstClip = FristClip; if (null != firstClip) { foreach (FRsResourceClip clip in _clips) { if (clip != null) { if (firstClip.FrameCount != clip.FrameCount) { RMoCore.TrackConsole.Write(this, "Scan", "Animation clip frame is differenty. (first_frames={0}, clip_frames={1})", firstClip.FrameCount, clip.FrameCount); } } } } string _configName = _directory + "\\config.xml"; if (RFile.Exists(_configName)) { FXmlDocument xdoc = new FXmlDocument(); xdoc.LoadFile(_configName); LoadConfig(xdoc.Root); } }
//============================================================ // <T>导出资源。</T> //============================================================ public void Merge() { // 计算范围 int clipCount = ClipNotEmptyCount; FRsResourceClip firstClip = FristClip; int frameCount = 0; if (null != firstClip) { frameCount = firstClip.FrameCount; } else { RMoCore.TrackConsole.Write(this, "Merge", "Animatioin is valid, first clip is empty. (code={0})", Code); return; } int width = _size.Width * frameCount; int height = _size.Height * clipCount; // 计算是否合并 using (Bitmap bitmap = new Bitmap(width, height)) { // 合并图片 int y = 0; foreach (FRsResourceClip clip in _clips) { if (clip != null) { if (!clip.Frames.IsEmpty()) { for (int x = 0; x < frameCount; x++) { FRsResourceFrame frame = clip.Frames[x]; int cx = _size.Width * x; int cy = _size.Height * y; if (frame.ValidBitmap != null) { frame.MergeLocation.Set(cx, cy); RBitmap.Copy(frame.ValidBitmap, new SIntRectangle(0, 0, frame.ValidBitmap.Width, frame.ValidBitmap.Height), bitmap, frame.MergeLocation); } } y++; } } } // 存储图片 _mergeFileName = RContent2dManager.ResourceConsole.MergeDirectory + "\\" + Code + ".png"; RDirectory.MakeDirectoriesForFile(_mergeFileName); bitmap.Save(_mergeFileName); _mergeSize.Set(bitmap.Width, bitmap.Height); } }