Ejemplo n.º 1
0
        //frompath (import) has two varieties: they will take
        // - take a folder containing all elements, each with a char number
        // - take a simple png
        //fromstream (load) will take the png and all the rectangles, and the char maps from stream
        //save will save as .font


        public static new FontSheet Import(string path)
        {
            //get all extra stat from an XML
            if (File.Exists(path + "FontData.xml"))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path + "FontData.xml");
                int spaceWidth = Convert.ToInt32(doc.SelectSingleNode("FontData/SpaceWidth").InnerText);
                int charHeight = Convert.ToInt32(doc.SelectSingleNode("FontData/CharHeight").InnerText);
                int charSpace  = Convert.ToInt32(doc.SelectSingleNode("FontData/CharSpace").InnerText);
                int lineSpace  = Convert.ToInt32(doc.SelectSingleNode("FontData/LineSpace").InnerText);

                HashSet <int> colorlessGlyphs = new HashSet <int>();
                XmlNode       glyphNodes      = doc.SelectSingleNode("FontData/Colorless");
                foreach (XmlNode glyphNode in glyphNodes.SelectNodes("Glyph"))
                {
                    int glyphIdx = Convert.ToInt32(glyphNode.InnerText, 16);
                    colorlessGlyphs.Add(glyphIdx);
                }

                string[]         pngs   = Directory.GetFiles(path, "*.png", SearchOption.TopDirectoryOnly);
                List <ImageInfo> sheets = new List <ImageInfo>();
                foreach (string dir in pngs)
                {
                    int       png      = Convert.ToInt32(Path.GetFileNameWithoutExtension(dir), 16);
                    Texture2D newSheet = null;
                    using (FileStream fileStream = new FileStream(dir, FileMode.Open, FileAccess.Read, FileShare.Read))
                        newSheet = ImportTex(fileStream);

                    sheets.Add(new ImageInfo(png, newSheet));
                }
                if (sheets.Count == 0)
                {
                    return(null);
                }

                Canvas canvas = new Canvas();
                canvas.SetCanvasDimensions(Canvas.INFINITE_SIZE, Canvas.INFINITE_SIZE);
                OptimalMapper mapper = new OptimalMapper(canvas, 0.975f, 10);
                Atlas         atlas  = mapper.Mapping(sheets);

                Rectangle[] rects = new Rectangle[sheets.Count];
                Dictionary <int, GlyphData> chars = new Dictionary <int, GlyphData>();
                Texture2D tex = new Texture2D(device, atlas.Width, atlas.Height);
                for (int ii = 0; ii < atlas.MappedImages.Count; ii++)
                {
                    MappedImageInfo info = atlas.MappedImages[ii];
                    BaseSheet.Blit(info.ImageInfo.Texture, tex, 0, 0, info.ImageInfo.Width, info.ImageInfo.Height, info.X, info.Y);
                    rects[ii] = new Rectangle(info.X, info.Y, info.ImageInfo.Width, info.ImageInfo.Height);
                    chars[info.ImageInfo.ID] = new GlyphData(ii, colorlessGlyphs.Contains(info.ImageInfo.ID));
                    info.ImageInfo.Texture.Dispose();
                }

                return(new FontSheet(tex, rects, spaceWidth, charHeight, charSpace, lineSpace, chars));
            }
            else
            {
                throw new Exception("Error finding XML file in " + path + ".");
            }
        }
Ejemplo n.º 2
0
        public static void Export(PortraitSheet sheet, string baseDirectory)
        {
            foreach (int emoteIndex in sheet.emoteMap.Keys)
            {
                string emotion = GraphicsManager.Emotions[emoteIndex].Name;

                int ii = sheet.emoteMap[emoteIndex].Position;
                {
                    Texture2D tex = new Texture2D(device, GraphicsManager.PortraitSize, GraphicsManager.PortraitSize);
                    BaseSheet.Blit(sheet.baseTexture, tex, ii % sheet.TotalX * GraphicsManager.PortraitSize, ii / sheet.TotalX * GraphicsManager.PortraitSize, GraphicsManager.PortraitSize, GraphicsManager.PortraitSize, 0, 0);
                    using (Stream stream = new FileStream(baseDirectory + emotion + ".png", FileMode.Create, FileAccess.Write, FileShare.None))
                        ExportTex(stream, tex);
                    tex.Dispose();
                }

                if (sheet.emoteMap[emoteIndex].HasReverse)
                {
                    ii++;
                    Texture2D tex2 = new Texture2D(device, GraphicsManager.PortraitSize, GraphicsManager.PortraitSize);
                    BaseSheet.Blit(sheet.baseTexture, tex2, ii % sheet.TotalX * GraphicsManager.PortraitSize, ii / sheet.TotalX * GraphicsManager.PortraitSize, GraphicsManager.PortraitSize, GraphicsManager.PortraitSize, 0, 0);
                    using (Stream stream = new FileStream(baseDirectory + emotion + "^.png", FileMode.Create, FileAccess.Write, FileShare.None))
                        ExportTex(stream, tex2);
                    tex2.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        //this can inherit tilesheet
        //frompath (import) will take a folder containing all elements
        //fromstream (load) will take the png, the tile height/width, and the emotion maps
        //save will save as .portrait


        public static new PortraitSheet Import(string baseDirectory)
        {
            //load all available tilesets
            //get all frames
            Dictionary <int, PortraitData> animData = new Dictionary <int, PortraitData>();
            List <Texture2D> sheets = new List <Texture2D>();

            for (int ii = 0; ii < GraphicsManager.Emotions.Count; ii++)
            {
                string emotion = GraphicsManager.Emotions[ii].Name;
                if (File.Exists(baseDirectory + emotion + ".png"))
                {
                    bool hasReverse = File.Exists(baseDirectory + emotion + "^.png");
                    {
                        Texture2D newSheet = null;
                        using (FileStream fileStream = new FileStream(baseDirectory + emotion + ".png", FileMode.Open, FileAccess.Read, FileShare.Read))
                            newSheet = ImportTex(fileStream);

                        animData.Add(ii, new PortraitData(sheets.Count, hasReverse));
                        if (newSheet.Width != GraphicsManager.PortraitSize || newSheet.Height != GraphicsManager.PortraitSize)
                        {
                            throw new InvalidOperationException(baseDirectory + emotion + ".png has incorrect dimensions for portrait.");
                        }
                        sheets.Add(newSheet);
                    }

                    if (hasReverse)
                    {
                        Texture2D newSheet = null;
                        using (FileStream fileStream = new FileStream(baseDirectory + emotion + "^.png", FileMode.Open, FileAccess.Read, FileShare.Read))
                            newSheet = ImportTex(fileStream);

                        if (newSheet.Width != GraphicsManager.PortraitSize || newSheet.Height != GraphicsManager.PortraitSize)
                        {
                            throw new InvalidOperationException(baseDirectory + emotion + ".png has incorrect dimensions for portrait.");
                        }
                        sheets.Add(newSheet);
                    }
                }
            }
            if (sheets.Count == 0)
            {
                return(null);
            }

            int fullWidth = (int)Math.Ceiling(Math.Sqrt(sheets.Count));

            Texture2D tex = new Texture2D(device, GraphicsManager.PortraitSize * fullWidth, GraphicsManager.PortraitSize * fullWidth);

            for (int ii = 0; ii < sheets.Count; ii++)
            {
                BaseSheet.Blit(sheets[ii], tex, 0, 0, sheets[ii].Width, sheets[ii].Height, ii % fullWidth * GraphicsManager.PortraitSize, ii / fullWidth * GraphicsManager.PortraitSize);
                sheets[ii].Dispose();
            }
            return(new PortraitSheet(tex, animData));
        }
Ejemplo n.º 4
0
        public static void InitSystem(GraphicsDevice graphics)
        {
            defaultTex = new Texture2D(graphics, 32, 32);
            for (int ii = 0; ii < 16; ii++)
            {
                BaseSheet.BlitColor((ii % 2 == (ii / 4 % 2)) ? Color.Black : new Color(255, 0, 255, 255), defaultTex, 8, 8, ii % 4 * 8, ii / 4 * 8);
            }
            //Set graphics device
            Content.BaseSheet.InitBase(graphics, defaultTex);

            Splash = BaseSheet.Import(UI_PATH + "Splash.png");

            SysFont = LoadFont("system");
        }
Ejemplo n.º 5
0
        //frompath (import) will take a folder containing all elements
        //fromstream (load) will take the png, and the rectangles (head.body/tail are precalculated)
        //save will save as .beam

        public static new BeamSheet Import(string path)
        {
            if (File.Exists(path + "BeamData.xml"))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path + "BeamData.xml");
                int totalFrames = Convert.ToInt32(doc.SelectSingleNode("BeamData/TotalFrames").InnerText);

                List <Texture2D> sheets = new List <Texture2D>();
                Rectangle[]      rects  = new Rectangle[3 * totalFrames];
                int maxWidth            = 0;
                int maxHeight           = 0;

                for (int ii = 0; ii < 3; ii++)
                {
                    using (FileStream fileStream = new FileStream(path + ((BeamFrame)ii).ToString() + ".png", FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        Texture2D newSheet = Texture2D.FromStream(device, fileStream);

                        for (int jj = 0; jj < totalFrames; jj++)
                        {
                            rects[ii * totalFrames + jj] = new Rectangle(newSheet.Width / totalFrames * jj, maxHeight, newSheet.Width / totalFrames, newSheet.Height);
                        }

                        maxWidth   = Math.Max(maxWidth, newSheet.Width);
                        maxHeight += newSheet.Height;
                        sheets.Add(newSheet);
                    }
                }

                Texture2D tex = new Texture2D(device, maxWidth, maxHeight);

                int curHeight = 0;
                for (int ii = 0; ii < sheets.Count; ii++)
                {
                    BaseSheet.Blit(sheets[ii], tex, 0, 0, sheets[ii].Width, sheets[ii].Height, 0, curHeight);
                    curHeight += sheets[ii].Height;
                    sheets[ii].Dispose();
                }

                return(new BeamSheet(tex, rects, totalFrames));
            }
            else
            {
                throw new Exception("Error finding XML file in " + path + ".");
            }
        }
Ejemplo n.º 6
0
        public static BaseSheet GetTile(TileFrame tileTex)
        {
            BaseSheet sheet;

            if (tileCache.TryGetValue(tileTex, out sheet))
            {
                return(sheet);
            }

            long tilePos = TileIndex.GetPosition(tileTex.Sheet, tileTex.TexLoc);

            if (tilePos > 0)
            {
                try
                {
                    using (FileStream stream = new FileStream(String.Format(TILE_PATTERN, tileTex.Sheet), FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (BinaryReader reader = new BinaryReader(stream))
                        {
                            // Seek to the location of the tile
                            reader.BaseStream.Seek(tilePos, SeekOrigin.Begin);

                            sheet = BaseSheet.Load(reader);
                            tileCache.Add(tileTex, sheet);
                            return(sheet);
                        }
                    }
                }
                catch (Exception ex)
                {
                    DiagManager.Instance.LogError(new Exception("Error retrieving tile " + tileTex.TexLoc.X + ", " + tileTex.TexLoc.Y + " from Tileset #" + tileTex.Sheet + "\n", ex));
                }
            }

            BaseSheet newSheet = BaseSheet.LoadError();

            tileCache.Add(tileTex, newSheet);
            return(newSheet);
        }
Ejemplo n.º 7
0
        //frompath (import) will take a folder containing all elements
        //fromstream (load) will take the png and all the rectangles from stream
        //save will save as .atlas

        public static new SpriteSheet Import(string path)
        {
            string[]         pngs   = Directory.GetFiles(path, "*.png", SearchOption.TopDirectoryOnly);
            List <ImageInfo> sheets = new List <ImageInfo>();
            int index = 0;

            foreach (string dir in pngs)
            {
                Texture2D newSheet = null;
                using (FileStream fileStream = new FileStream(dir, FileMode.Open, FileAccess.Read, FileShare.Read))
                    newSheet = ImportTex(fileStream);

                sheets.Add(new ImageInfo(index, newSheet));
                index++;
            }
            if (sheets.Count == 0)
            {
                return(null);
            }

            Canvas canvas = new Canvas();

            canvas.SetCanvasDimensions(Canvas.INFINITE_SIZE, Canvas.INFINITE_SIZE);
            OptimalMapper mapper = new OptimalMapper(canvas);
            Atlas         atlas  = mapper.Mapping(sheets);

            Rectangle[] rects = new Rectangle[sheets.Count];
            Texture2D   tex   = new Texture2D(device, atlas.Width, atlas.Height);

            for (int ii = 0; ii < atlas.MappedImages.Count; ii++)
            {
                MappedImageInfo info = atlas.MappedImages[ii];
                BaseSheet.Blit(info.ImageInfo.Texture, tex, 0, 0, info.ImageInfo.Width, info.ImageInfo.Height, info.X, info.Y);
                rects[info.ImageInfo.ID] = new Rectangle(info.X, info.Y, info.ImageInfo.Width, info.ImageInfo.Height);
                info.ImageInfo.Texture.Dispose();
            }

            return(new SpriteSheet(tex, rects));
        }
Ejemplo n.º 8
0
 public void BlitColor(Color srcColor, int srcW, int srcH, int destX, int destY)
 {
     BaseSheet.BlitColor(srcColor, baseTexture, srcW, srcH, destX, destY);
 }
Ejemplo n.º 9
0
 public static Color[] GetData(BaseSheet source, int srcPx, int srcPy, int srcW, int srcH)
 {
     return(GetData(source.baseTexture, srcPx, srcPy, srcW, srcH));
 }
Ejemplo n.º 10
0
 public static void Blit(BaseSheet source, Texture2D dest, int srcPx, int srcPy, int srcW, int srcH, int destX, int destY)
 {
     BaseSheet.Blit(source.baseTexture, dest, srcPx, srcPy, srcW, srcH, destX, destY);
 }
Ejemplo n.º 11
0
        public static void InitStatic()
        {
            DiagManager.Instance.LoadMsg = "Loading Graphics";

            //load onepixel
            Pixel = new BaseSheet(1, 1);
            Pixel.BlitColor(Color.White, 1, 1, 0, 0);

            //Load divider texture
            DivTex = BaseSheet.Import(UI_PATH + "Divider.png");

            //load menu data
            MenuBG = TileSheet.Import(UI_PATH + "MenuBG.png", 8, 8);

            //load menu data
            MenuBorder = TileSheet.Import(UI_PATH + "MenuBorder.png", 8, 8);

            //load menu data
            PicBorder = TileSheet.Import(UI_PATH + "PortraitBorder.png", 4, 4);

            Arrows = TileSheet.Import(UI_PATH + "Arrows.png", 8, 8);

            Cursor = TileSheet.Import(UI_PATH + "Cursor.png", 11, 11);

            BattleFactors = TileSheet.Import(UI_PATH + "BattleFactors.png", 16, 16);

            Shadows = TileSheet.Import(UI_PATH + "Shadows.png", 32, 16);

            Tiling = TileSheet.Import(UI_PATH + "Tiling.png", TileSize, TileSize);

            Darkness = TileSheet.Import(UI_PATH + "Dark.png", 8, 8);

            Strip = TileSheet.Import(UI_PATH + "Strip.png", 8, 8);

            Buttons = TileSheet.Import(UI_PATH + "Buttons.png", 16, 16);

            HPMenu = TileSheet.Import(UI_PATH + "HP.png", 8, 8);

            MiniHP = BaseSheet.Import(UI_PATH + "MiniHP.png");

            MapSheet = TileSheet.Import(UI_PATH + "Map.png", 4, 4);

            Title = BaseSheet.Import(UI_PATH + "Title.png");

            Subtitle = BaseSheet.Import(UI_PATH + "Enter.png");


            //load font
            TextFont    = LoadFont("text");
            DungeonFont = LoadFont("banner");
            DamageFont  = LoadFont("yellow");
            HealFont    = LoadFont("green");
            EXPFont     = LoadFont("blue");

            Menu.MenuBase.BorderStyle = DiagManager.Instance.CurSettings.Border;

            DiagManager.Instance.LoadMsg = "Loading Headers";

            //initialize caches
            spriteCache = new LRUCache <MonsterID, CharSheet>(CHARA_CACHE_SIZE);
            spriteCache.OnItemRemoved   = DisposeCachedObject;
            portraitCache               = new LRUCache <MonsterID, PortraitSheet>(PORTRAIT_CACHE_SIZE);
            portraitCache.OnItemRemoved = DisposeCachedObject;
            vfxCache = new LRUCache <string, IEffectAnim>(VFX_CACHE_SIZE);
            vfxCache.OnItemRemoved = DisposeCachedObject;
            iconCache = new LRUCache <string, DirSheet>(ICON_CACHE_SIZE);
            iconCache.OnItemRemoved = DisposeCachedObject;
            itemCache = new LRUCache <string, DirSheet>(ITEM_CACHE_SIZE);
            itemCache.OnItemRemoved = DisposeCachedObject;
            tileCache               = new LRUCache <TileFrame, BaseSheet>(TILE_CACHE_SIZE_PIXELS);
            tileCache.ItemCount     = CountPixels;
            tileCache.OnItemRemoved = DisposeCachedObject;
            bgCache = new LRUCache <string, DirSheet>(BG_CACHE_SIZE);
            bgCache.OnItemRemoved     = DisposeCachedObject;
            objectCache               = new LRUCache <string, DirSheet>(OBJECT_CACHE_SIZE);
            objectCache.OnItemRemoved = DisposeCachedObject;

            //load guides
            CharaIndex    = LoadCharaIndices(DiagManager.CONTENT_PATH + "Chara/");
            PortraitIndex = LoadCharaIndices(DiagManager.CONTENT_PATH + "Portrait/");
            TileIndex     = LoadTileIndices(DiagManager.CONTENT_PATH + "Tile/");

            Loaded = true;
            //Notify script engine
            LuaEngine.Instance.OnGraphicsLoad();
        }
Ejemplo n.º 12
0
 public static int CountPixels(BaseSheet obj)
 {
     return(obj.Width * obj.Height);
 }