Пример #1
0
        public Dictionary <string, Image> GenerateIcons(WorldConfiguration configuration)
        {
            var result = new Dictionary <string, Image>();

            if (configuration.isCubesProfilesIDInitialized == false)
            {
                _visualWorldParameters.WorldParameters.Configuration = configuration;
                _visualWorldParameters.InitCubesProfiles();
            }

            _iconFactory.Configuration = configuration;
            _iconFactory.LoadContent(_engine.ImmediateContext);

            var iconsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Realms", "Common", "Icons");

            if (!Directory.Exists(iconsDir))
            {
                Directory.CreateDirectory(iconsDir);
            }

            //Create Items icons
            foreach (var visualVoxelModel in _modelManager.Enumerate())
            {
                foreach (var voxelModelState in visualVoxelModel.VoxelModel.States)
                {
                    var iconId = visualVoxelModel.VoxelModel.Name +
                                 (voxelModelState.IsMainState ? "" : ":" + voxelModelState.Name);

                    var fileName = iconId.Replace(':', '_') + ".png";

                    var path = Path.Combine(iconsDir, fileName);

                    if (File.Exists(path))
                    {
                        result.Add(iconId, Image.FromFile(path));
                    }
                    else
                    {
                        using (var dxIcon = _iconFactory.CreateVoxelIcon(visualVoxelModel, IconSize, voxelModelState))
                        {
                            var memStr = new MemoryStream();
                            Resource.ToStream(_engine.ImmediateContext, dxIcon, ImageFileFormat.Png, memStr);
                            memStr.Position = 0;
                            var bmp = new Bitmap(memStr);
                            result.Add(iconId, bmp);
                            memStr.Dispose();

                            bmp.Save(path, ImageFormat.Png);
                        }
                    }
                }
            }

            //Create Blocks icons
            int i = 0;
            List <Texture2D> cubeIcons = _iconFactory.Get3DBlockIcons(_engine.ImmediateContext, IconSize, _cubeTextureView);

            foreach (var cubeprofiles in configuration.GetAllCubesProfiles())
            {
                if (cubeprofiles.Id == WorldConfiguration.CubeId.Air)
                {
                    continue;
                }

                var blockId = "CubeResource_" + cubeprofiles.Name;

                var fileName = blockId.Replace(':', '_') + ".png";

                var path = Path.Combine(iconsDir, fileName);

                if (File.Exists(path))
                {
                    result.Add(blockId, Image.FromFile(path));
                }
                else
                {
                    var memStr = new MemoryStream();
                    Resource.ToStream(_engine.ImmediateContext, cubeIcons[i], ImageFileFormat.Png, memStr);
                    memStr.Position = 0;
                    var bmp = new Bitmap(memStr);
                    result.Add(blockId, bmp);
                    memStr.Dispose();
                    bmp.Save(path, ImageFormat.Png);
                }
                i++;
            }

            //Create texture icons
            foreach (var textureFile in Directory.GetFiles(ClientSettings.TexturePack + @"Terran\", "*.png"))
            {
                //Load Image
                Bitmap img = new Bitmap(textureFile);

                int NbrFrames = img.Height / img.Width;
                //Generate texture ICON
                Bitmap resized = Copy(img, new System.Drawing.Rectangle()
                {
                    X = 0, Y = 0, Width = img.Width, Height = img.Width
                });

                result.Add("TextureCube_" + Path.GetFileNameWithoutExtension(textureFile) + "@" + NbrFrames, resized);
            }

            return(result);
        }