예제 #1
0
 private void ShowIcon(int fromTick, SpriteSource sprite, int x, int y)
 {
     if (TickPassed(fromTick))
     {
         _display.Update(sprite, x, y);
     }
 }
예제 #2
0
        List <byte[]> LoadTemplate(string filename, string[] exts, Dictionary <string, ISpriteSource> sourceCache, int[] frames)
        {
            ISpriteSource source;

            if (!sourceCache.ContainsKey(filename))
            {
                using (var s = GlobalFileSystem.OpenWithExts(filename, exts))
                    source = SpriteSource.LoadSpriteSource(s, filename);

                if (source.CacheWhenLoadingTileset)
                {
                    sourceCache.Add(filename, source);
                }
            }
            else
            {
                source = sourceCache[filename];
            }

            if (frames != null)
            {
                var ret       = new List <byte[]>();
                var srcFrames = source.Frames;
                foreach (var i in frames)
                {
                    ret.Add(ExtractSquareTile(srcFrames[i]));
                }

                return(ret);
            }

            return(source.Frames.Select(f => ExtractSquareTile(f)).ToList());
        }
예제 #3
0
        private void DrawToContext(Graphics g, SpriteSource sprite, decimal toCellX, decimal toCellY)
        {
            var x    = (int)((toCellX + 0.5m * (1 - sprite.Size)) * CellSize);
            var y    = (int)((toCellY + 0.5m * (1 - sprite.Size)) * CellSize);
            var size = CellSize * sprite.Size;

            g.DrawImage(_sprites, new Rectangle(x, y, size, size),
                        CellSize * sprite.XPos, CellSize * sprite.YPos, size, size,
                        GraphicsUnit.Pixel);
        }
예제 #4
0
        private void DrawSprite(bool onBuffer, decimal x, decimal y, SpriteSource source)
        {
            x = x + (1 - source.Size) * 0.5m;
            y = y + (1 - source.Size) * 0.5m;
            var size = PixelGrid * source.Size;

            JSData.AddRange(new[]
            {
                onBuffer ? 1 : 0,
                PixelGrid * source.XPos, PixelGrid * source.YPos, size,
                (int)(PixelGrid * x), (int)(PixelGrid * y)
            });
        }
예제 #5
0
        public TestMode(UiSystem uiSystem)
        {
            _display   = uiSystem.Display;
            _spriteSet = uiSystem.SpriteSet;
            _tick      = 0;

            _allSpites = new SpriteSource[10 * 32];
            for (int y = 0; y < 10; y++)
            {
                for (int x = 0; x < 32; x++)
                {
                    _allSpites[y * 32 + x] = new SpriteSource(x, y, 1);
                }
            }
        }
 /// <inheritdoc/>
 public override String ToString() => $"{SpriteAnimationID} {SpriteSource.ToString().ToLowerInvariant()}";
예제 #7
0
 private void DrawSprite(SpriteSource sprite, Location location)
 {
     _display.AddSprite(sprite, location);
 }
예제 #8
0
    public Sprite GetSource(SpawnCode code)
    {
        SpriteSource s = null;

        switch (code)
        {
        case SpawnCode.W001:
        case SpawnCode.W002:
        case SpawnCode.W003:
        case SpawnCode.W004:
        case SpawnCode.W005:
            s = Array.Find(weapon_sword, tmp => tmp.code == code); break;

        case SpawnCode.W101:
        case SpawnCode.W102:
        case SpawnCode.W103:
        case SpawnCode.W104:
        case SpawnCode.W105:
            s = Array.Find(weapon_spear, tmp => tmp.code == code); break;

        case SpawnCode.W201:
        case SpawnCode.W202:
        case SpawnCode.W203:
        case SpawnCode.W204:
        case SpawnCode.W205:
            s = Array.Find(weapon_bow, tmp => tmp.code == code); break;

        case SpawnCode.R001:
        case SpawnCode.R002:
        case SpawnCode.R003:
        case SpawnCode.R004:
        case SpawnCode.R005:
            s = Array.Find(skill_red, tmp => tmp.code == code); break;

        case SpawnCode.G001:
        case SpawnCode.G002:
        case SpawnCode.G003:
        case SpawnCode.G004:
        case SpawnCode.G005:
            s = Array.Find(skill_green, tmp => tmp.code == code); break;

        case SpawnCode.B001:
        case SpawnCode.B002:
        case SpawnCode.B003:
        case SpawnCode.B004:
        case SpawnCode.B005:
            s = Array.Find(skill_blue, tmp => tmp.code == code); break;


        case SpawnCode.A001:
        case SpawnCode.A002:
        case SpawnCode.A003:
        case SpawnCode.A004:
        case SpawnCode.A005:
            s = Array.Find(armor_Amulet, tmp => tmp.code == code); break;

        case SpawnCode.S001:
        case SpawnCode.S002:
        case SpawnCode.S003:
        case SpawnCode.S004:
        case SpawnCode.S005:
            s = Array.Find(armor_Stone, tmp => tmp.code == code); break;

        case SpawnCode.F001:
        case SpawnCode.F002:
        case SpawnCode.F003:
        case SpawnCode.F004:
        case SpawnCode.F005:
            s = Array.Find(food, tmp => tmp.code == code); break;
        }

        if (s == null)
        {
            Debug.LogWarning("SpriteSupplier: " + code.ToString() + " does not found!");
            return(null);
        }

        return(s.source);
    }
예제 #9
0
 private void DrawToBuffer(SpriteSource sprite, decimal toCellX, decimal toCellY)
 {
     DrawToContext(_gameBufferGraphics, sprite, toCellX, toCellY);
 }
예제 #10
0
 private void DrawToBackground(SpriteSource sprite, decimal toCellX, decimal toCellY)
 {
     DrawToContext(_staticBoardGraphics, sprite, toCellX, toCellY);
 }
예제 #11
0
파일: Command.cs 프로젝트: xbayrockx/OpenRA
        public static void ConvertShpToPng(string[] args)
        {
            var src         = args[1];
            var shadowIndex = new int[] { };

            if (args.Contains("--noshadow"))
            {
                Array.Resize(ref shadowIndex, shadowIndex.Length + 3);
                shadowIndex[shadowIndex.Length - 1] = 1;
                shadowIndex[shadowIndex.Length - 2] = 3;
                shadowIndex[shadowIndex.Length - 3] = 4;
            }

            var palette = Palette.Load(args[2], shadowIndex);

            ISpriteSource source;

            using (var stream = File.OpenRead(src))
                source = SpriteSource.LoadSpriteSource(stream, src);

            // The r8 padding requires external information that we can't access here.
            var usePadding = !(args.Contains("--nopadding") || source is R8Reader);
            var count      = 0;
            var prefix     = Path.GetFileNameWithoutExtension(src);

            foreach (var frame in source.Frames)
            {
                var frameSize = usePadding ? frame.FrameSize : frame.Size;
                var offset    = usePadding ? (frame.Offset - 0.5f * new float2(frame.Size - frame.FrameSize)).ToInt2() : int2.Zero;

                // shp(ts) may define empty frames
                if (frameSize.Width == 0 && frameSize.Height == 0)
                {
                    count++;
                    continue;
                }

                using (var bitmap = new Bitmap(frameSize.Width, frameSize.Height, PixelFormat.Format8bppIndexed))
                {
                    bitmap.Palette = palette.AsSystemPalette();
                    var data = bitmap.LockBits(new Rectangle(0, 0, frameSize.Width, frameSize.Height),
                                               ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                    // Clear the frame
                    if (usePadding)
                    {
                        var clearRow = new byte[data.Stride];
                        for (var i = 0; i < frameSize.Height; i++)
                        {
                            Marshal.Copy(clearRow, 0, new IntPtr(data.Scan0.ToInt64() + i * data.Stride), data.Stride);
                        }
                    }

                    for (var i = 0; i < frame.Size.Height; i++)
                    {
                        var destIndex = new IntPtr(data.Scan0.ToInt64() + (i + offset.Y) * data.Stride + offset.X);
                        Marshal.Copy(frame.Data, i * frame.Size.Width, destIndex, frame.Size.Width);
                    }

                    bitmap.UnlockBits(data);

                    var filename = "{0}-{1:D4}.png".F(prefix, count++);
                    bitmap.Save(filename);
                }
            }

            Console.WriteLine("Saved {0}-[0..{1}].png", prefix, count - 1);
        }
 /// <inheritdoc/>
 public override String ToString()
 {
     return(String.Format("{0} {1}", SpriteAnimationID, SpriteSource.ToString().ToLowerInvariant()));
 }
예제 #13
0
 public bool Equals(SpriteSource spriteSource)
 {
     return((XPos == spriteSource.XPos) &&
            (YPos == spriteSource.YPos) &&
            (Size == spriteSource.Size));
 }
예제 #14
0
 private void DrawBoardSprite(SpriteSource sprite, Location location)
 {
     DrawScreenSprite(sprite, location.Add(0, BoardYOffset));
 }