Esempio n. 1
0
        //============================================================
        // <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);
            }
        }
Esempio n. 2
0
        //============================================================
        // <T>加载设置信息。</T>
        //
        // @param xconfig 设置节点
        //============================================================
        public override void LoadConfig(FXmlNode xconfig)
        {
            base.LoadConfig(xconfig);
            // 读取属性
            _optionAlpha    = xconfig.GetBoolean("option_alpha", _optionAlpha);
            _optionPadding  = xconfig.GetBoolean("option_padding", _optionPadding);
            _qualityCd      = xconfig.Get("quality_cd", _qualityCd);
            _qualityPalette = xconfig.GetInteger("quality_palette", _qualityPalette);
            _qualityAlpha   = xconfig.GetInteger("quality_alpha", _qualityAlpha);
            _frameDelay     = xconfig.GetInteger("frame_delay", _frameDelay);
            // 读取剪辑集合
            FXmlNode xclips = xconfig.Find("Clips");

            if (xclips != null)
            {
                foreach (FXmlNode xnode in xclips.Nodes)
                {
                    if (xnode.IsName("Clip"))
                    {
                        // 检查参数
                        if (!xnode.Contains("direction_cd"))
                        {
                            continue;
                        }
                        // 加载剪辑信息
                        int             directionCd = xnode.GetInteger("direction_cd");
                        FRsResourceClip clip        = _clips[directionCd];
                        if (clip != null)
                        {
                            clip.LoadConfig(xnode);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        //============================================================
        // <T>根据方向获得帧剪辑。</T>
        //
        // @param direction 方向
        // @return 剪辑
        //============================================================
        public FRsResourceClip SyncClip(int direction)
        {
            FRsResourceClip clip = _clips[direction];

            if (clip == null)
            {
                clip              = new FRsResourceClip();
                clip.Animation    = this;
                clip.DirectionCd  = (ERsDirection)direction;
                _clips[direction] = clip;
            }
            return(clip);
        }
Esempio n. 4
0
        //============================================================
        // <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);
            }
        }
Esempio n. 5
0
        //============================================================
        // <T>序列化动画数据。</T>
        //
        // @param output 输出流
        //============================================================
        public override void Serialize(IOutput output)
        {
            base.Serialize(output);
            // 写入属性
            FRsResourceClip firstClip = FristClip;

            _size.Serialize16(output);
            _validBarycenter.Serialize16(output);
            _mergeSize.Serialize16(output);
            // 写入帧延迟
            if (firstClip != null)
            {
                output.WriteUint16((ushort)firstClip.FrameCount);
            }
            else
            {
                output.WriteUint16((ushort)0);
            }
            if (firstClip != null)
            {
                firstClip.SerializeDelay(output);
            }
            // 写入剪辑集合
            int clipCount = ClipCount;

            output.WriteUint8((byte)clipCount);
            foreach (FRsResourceClip clip in _clips)
            {
                if (clip != null)
                {
                    clip.Serialize(output);
                }
            }
            // 序列化位图
            using (FBitmap bitmap = new FBitmap(_mergeFileName)){
                bitmap.SerializeData(output);
            }
        }