Exemplo n.º 1
0
 public SpriteRenderParameter(SpriteResource sprite, float rotate, RawVector2 rotateOrigin, RawRectangleF location)
 {
     Sprite       = sprite ?? throw new ArgumentNullException(nameof(sprite));
     Rotate       = rotate;
     RotateOrigin = rotateOrigin;
     Location     = location;
 }
Exemplo n.º 2
0
        private void lstSprites_SelectedIndexChanged(object sender, EventArgs e)
        {
            mCurrentSprite = lstSprites.SelectedItem as SpriteResource;

            if (mCurrentSprite == null)
            {
                propertiesPanel.Visible = false;
                return;
            }

            propertiesPanel.Visible = true;

            try
            {
                changingSprite = true;
                UpdateSprite();

                txtName.Text          = mCurrentSprite.Name;
                nudTimePerFrame.Value = (decimal)mCurrentSprite.TimePerFrame;

                FillFrameList(-1);
            }
            finally
            {
                changingSprite = false;
            }
        }
Exemplo n.º 3
0
        private void btnNewSprite_Click(object sender, EventArgs e)
        {
            frmNewSprite frm = new frmNewSprite();

            if (frm.ShowDialog(this, Resources) == DialogResult.Cancel)
            {
                return;
            }

            frmAddSpriteFrames frmAdd = new frmAddSpriteFrames();

            frmAdd.SpriteSize = frm.SpriteFrameSize;

            if (frmAdd.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            SpriteResource res = new SpriteResource(frm.SpriteName);



            Resources.Add(res);

            OnResourcesChanged();
        }
Exemplo n.º 4
0
 /// <summary>
 /// スプライトを描画キューに登録します。
 /// </summary>
 /// <param name="sprite">描画するスプライト</param>
 /// <param name="rect">描画範囲</param>
 /// <param name="rotate">回転</param>
 /// <param name="rotateOrigin">中心回転座標(スプライトに対して0~1で指定する)</param>
 public void Draw(SpriteResource sprite, RawRectangleF rect, float rotate, RawVector2 rotateOrigin)
 {
     if (!Begining)
     {
         throw new InvalidOperationException("描画操作が開始していません。");
     }
     RenderParameters.AddLast(new SpriteRenderParameter(sprite, rotate, rotateOrigin, rect));
 }
Exemplo n.º 5
0
 public Particle(ushort spriteID, Vector3 position, Quaternion orientation, Vector3 velocity, float size)
 {
     Position    = position;
     Orientation = orientation;
     Velocity    = velocity;
     Size        = size;
     Resource    = Resources.GetSprite(spriteID);
     Sector.Redria.ClientObjects.Add(this);
 }
Exemplo n.º 6
0
 public Particle(ushort spriteID, Vector3 position, Quaternion orientation, Vector3 velocity, float size)
 {
     Position = position;
     Orientation = orientation;
     Velocity = velocity;
     Size = size;
     Resource = Resources.GetSprite(spriteID);
     Sector.Redria.ClientObjects.Add(this);
 }
Exemplo n.º 7
0
        private void ShowMultiUI()
        {
            // Fail-safe
            if (currentEntities.Length <= 1 || currentEntities.Length > 4)
            {
                return;
            }

            SpriteResource res = WarFile.GetSpriteResource(race == Race.Humans ? 360 : 359);
        }
Exemplo n.º 8
0
        internal Sprite(SpriteResource resource)
        {
            Performance.Push("Sprite ctor");
            fixedSpriteFrame = 0;
            allAnimations    = new List <SpriteAnimation>();
            CurrentAnimation = null;

            frameData = SpriteFrameData.LoadSpriteFrameData(resource);

            Performance.Pop();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Constructs a sprite from a resource.
        /// </summary>
        /// <param name="resources"></param>
        /// <param name="name"></param>
        public Sprite(AgateResourceCollection resources, string name)
        {
            AgateResource  generic_res = resources[name];
            SpriteResource sprite_res  = generic_res as SpriteResource;

            if (sprite_res == null)
            {
                throw new AgateResourceException("Resource " + generic_res.Name + " is not a sprite.");
            }

            BuildSpriteFromResource(resources, resources.RootDirectory, sprite_res);
        }
Exemplo n.º 10
0
 public override void Generate()
 {
     Timing               = new Timing(Beatmap);
     SpriteResource       = new SpriteResource(this);
     delta                = 1000.0f / fps;
     layer                = GetLayer("");
     BlurredBackground    = SpriteResource.blur(Beatmap.BackgroundPath, 30, 15);
     BlurredSquareFilled  = SpriteResource.blur(Sprites.SquareFilled, 8, 5);
     BlurredSquareOutline = SpriteResource.blur(Sprites.SquareOutline, 8, 5);
     BG(72892, 92997);
     Grid(72892, 92997);
     //Particles(72892, 92997);
     Overlay(72892, 92997);
     //Ring3D(72892, 92997);
 }
Exemplo n.º 11
0
            public State(SpriteResource r)
            {
                FramesCount    = r.FramesCount;
                FrameDelay     = r.FrameDelay;
                ImgboxW        = r.ImgboxW;
                ImgboxH        = r.ImgboxH;
                AxisX          = r.AxisX;
                AxisY          = r.AxisY;
                Angle          = r.Angle;
                VerticalFrames = r.VerticalFrames;
                TextureLink    = r.Texture.Link;

                BackColor    = r.BackColor;
                PointBoundsX = r.PointBoundsX;
                PointBoundsY = r.PointBoundsY;
            }
Exemplo n.º 12
0
        public SpriteControl(string path)
        {
            InitializeComponent();

            FramesNumeric.FixMouseWheel();
            DelayNumeric.FixMouseWheel();
            ImgboxWNumeric.FixMouseWheel();
            ImgboxHNumeric.FixMouseWheel();
            AxisXNumeric.FixMouseWheel();
            AxisYNumeric.FixMouseWheel();
            AngleNumeric.FixMouseWheel();

            MenuTabs = new ToolStripMenuItem[] {
                new ToolStripMenuItem("Link texture", null, LinkTextureMenuItem_Click, Keys.Control | Keys.I),
                new ToolStripMenuItem("Adjust size", null, AdjustSizeMenuItem_Click, Keys.Control | Keys.A),
                new ToolStripMenuItem("Pixel perfect", null, PixelPerfectMenuItem_Click, Keys.Control | Keys.P),
                new ToolStripMenuItem("Background color", null, BackColorMenuItem_Click, Keys.Control | Keys.L),
                new ToolStripMenuItem("Reset position", null, ResetPositionMenuItem_Click, Keys.Control | Keys.R),
            };

            GLSurface.MakeCurrent();
            LoadedResource      = new SpriteResource(path);
            Story               = new StoryItem <State>(new State(LoadedResource));
            Story.ValueChanged += Story_ValueChanged;

            MenuTabs[4].Checked = LoadedResource.PixelPerfect;

            ResourcePath = path;
            ResourceName = Path.GetFileName(path);

            LoadedResource.Texture.SynchronizingObject = this;
            LoadedResource.Texture.Reloaded           += Texture_Reloaded;

            FramesNumeric.Value     = LoadedResource.FramesCount;
            DelayNumeric.Value      = (decimal)LoadedResource.FrameDelay;
            ImgboxWNumeric.Value    = (decimal)LoadedResource.ImgboxW;
            ImgboxHNumeric.Value    = (decimal)LoadedResource.ImgboxH;
            AxisXNumeric.Value      = (decimal)LoadedResource.AxisX;
            AxisYNumeric.Value      = (decimal)LoadedResource.AxisY;
            AngleNumeric.Value      = (decimal)LoadedResource.Angle;
            VFramesCheckBox.Checked = LoadedResource.VerticalFrames;
            LinkTextBox.Text        = LoadedResource.Texture.Link;

            GLSurface.BackColor = Color.FromArgb(LoadedResource.BackColor);

            GLFrameTimer.Start();
        }
Exemplo n.º 13
0
        private void ShowSingleUI()
        {
            // Fail-safe
            if (currentEntities.Length != 1)
            {
                return;
            }

            SpriteResource res     = WarFile.GetSpriteResource(race == Race.Humans ? 360 : 359);
            SpriteResource resUnit = WarFile.GetSpriteResource(361);

            Entity ent = currentEntities[0];

            UISpriteImage unitFrame = new UISpriteImage(new Sprite(res));

            unitFrame.FixedSpriteFrame = ent.Mana > 0 ? 1 : 0;
            unitFrame.X = 0;
            unitFrame.Y = 0;
            AddComponent(unitFrame);

            UISpriteImage unitIcon = new UISpriteImage(new Sprite(resUnit));

            unitIcon.FixedSpriteFrame = ent.IconIndex;
            unitIcon.X = 4;
            unitIcon.Y = 4;
            unitFrame.AddComponent(unitIcon);

            UILabel nameLabel = new UILabel(currentEntities[0].Name);

            nameLabel.TextAlign = TextAlignHorizontal.Left;
            nameLabel.X         = 4;
            nameLabel.Y         = unitIcon.Y + unitIcon.Height + 2;
            unitFrame.AddComponent(nameLabel);

            UIImage img = new UIImage(null);

            img.X               = 35;
            img.Y               = 20;
            img.Height          = 3;
            img.BackgroundColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
            SetHealthbar(img, ent);
            unitFrame.AddComponent(img);

            healthBars.Add(ent, img);
        }
Exemplo n.º 14
0
 public void ToResource(SpriteResource r)
 {
     r.FramesCount    = FramesCount;
     r.FrameDelay     = FrameDelay;
     r.ImgboxW        = ImgboxW;
     r.ImgboxH        = ImgboxH;
     r.AxisX          = AxisX;
     r.AxisY          = AxisY;
     r.Angle          = Angle;
     r.VerticalFrames = VerticalFrames;
     if (r.Texture.Link != TextureLink)
     {
         r.Texture.Link = TextureLink;
     }
     r.BackColor    = BackColor;
     r.PointBoundsX = PointBoundsX;
     r.PointBoundsY = PointBoundsY;
 }
Exemplo n.º 15
0
        public bool Get(string index, out Sprite t2)
        {
            if (m_sprites.TryGetValue(index, out t2))
            {
                return(true);
            }

            SpriteResource resource = Global.ResourceMgr.CreateSpriteResource(index, ePath.UISprite, true);

            if (resource != null)
            {
                t2 = resource.Sprite;

                m_sprites.Add(index, t2);
                return(true);
            }

            return(false);
        }
Exemplo n.º 16
0
        public UnitSprite(SpriteResource resource)
            : base(resource)
        {
            Performance.Push("UnitSprite ctor");

            Performance.Push("ApplyWarriorAnimationSet");
            ApplyWarriorAnimationSet();
            Performance.Pop();

            Performance.Push("SetCurrentAnimationByName");
            SetCurrentAnimationByName("Idle");
            Performance.Pop();

            Performance.Push("Set SpriteOrientation");
            SpriteOrientation = Orientation.NorthWest;
            Performance.Pop();

            Performance.Pop();
        }
Exemplo n.º 17
0
        private void BuildSpriteFromResource(AgateResourceCollection resources,
                                             string root, SpriteResource resource)
        {
            Surface defaultSurface = null;

            if (string.IsNullOrEmpty(resource.Filename) == false)
            {
                defaultSurface = new Surface(resources.LoadSurfaceImpl(resource.Filename));
                mOwnedSurfaces.Add(defaultSurface);
            }

            if (resource.HasSize)
            {
                mSpriteSize = resource.Size;
            }
            else if (defaultSurface != null)
            {
                mSpriteSize = defaultSurface.SurfaceSize;
            }

            for (int i = 0; i < resource.ChildElements.Count; i++)
            {
                SpriteResource.SpriteSubResource child = resource.ChildElements[i];
                Surface thisSurface = defaultSurface;

                if (child is SpriteResource.SpriteFrameResource)
                {
                    SpriteResource.SpriteFrameResource frame = (SpriteResource.SpriteFrameResource)child;
                    if (string.IsNullOrEmpty(frame.Filename) == false)
                    {
                        thisSurface = new Surface(resources.LoadSurfaceImpl(frame.Filename));
                        mOwnedSurfaces.Add(thisSurface);

                        if (i == 0 && defaultSurface == null && resource.HasSize == false)
                        {
                            mSpriteSize = thisSurface.SurfaceSize;
                        }
                    }
                    if (thisSurface == null)
                    {
                        throw new AgateException(string.Format(
                                                     "The surface to create the sprite from in resource {0} was not specified.", resource.Name));
                    }

                    // we pass false to ownSurface here because the surface has already been added to the
                    // owned surfaces list.
                    AddFrame(thisSurface, false, frame.Bounds, frame.Offset);
                }
                else
                {
                    var image = (SpriteResource.SpriteImageResource)child;

                    ImplementationBase.SurfaceImpl thisImpl = resources.LoadSurfaceImpl(image.Filename);
                    if (i == 0 && defaultSurface == null && resource.HasSize == false)
                    {
                        mSpriteSize = thisImpl.SurfaceSize;
                    }

                    if (image.Grids.Count == 0)
                    {
                        AddFrame(new Surface(thisImpl), false,
                                 new Rectangle(0, 0, mSpriteSize.Width, mSpriteSize.Height),
                                 Point.Empty);
                    }
                    else
                    {
                        for (int j = 0; j < image.Grids.Count; j++)
                        {
                            AddFramesFromGrid(resources, thisImpl, image.Grids[j]);
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        private IResource MakeSpriteResource(eResourceType eType, ePath ePath, string name)
        {
            string path = StringUtil.Format("{0}/{1}", m_pathManager.GetPath(ePath), name);

            Sprite[]          allresource       = null;
            Object            obj               = null;
            Object            autotile          = null;
            SpritePackerAsset spritePackerAsset = null;

            if (ePath == Resource.ePath.MapAutoTile)
            {
                obj = Resources.Load(path);
                string autotilepath = m_pathManager.GetPath(ePath) + "AutoTile";
                autotile = Resources.Load(autotilepath);
                if (obj is SpritePackerAsset)
                {
                    spritePackerAsset = (SpritePackerAsset)obj;
                    allresource       = spritePackerAsset.AllSprites;
                }
            }
            if (ePath == Resource.ePath.UISprite)
            {
                obj = Resources.Load(path);
            }
            else if (ePath == Resource.ePath.MapAsset || ePath == Resource.ePath.MapAutoAsset || ePath == Resource.ePath.MapActorAsset)
            {
                obj = Resources.Load(path);
                if (obj is SpritePackerAsset)
                {
                    spritePackerAsset = (SpritePackerAsset)obj;
                    allresource       = spritePackerAsset.AllSprites;
                }
            }
            else
            {
                allresource = Resources.LoadAll <Sprite>(path);
            }

            IResource resource = null;

            if (eType == eResourceType.SpriteAsset)
            {
                if (obj == null)
                {
                    Debug.LogError("TileSprite MakeSpriteResource name error" + name);
                    return(null);
                }

                resource = new SpritePackerResource(spritePackerAsset, spritePackerAsset.AllSprites, false);
            }
            else if (eType == eResourceType.Sprite)
            {
                if (obj == null)
                {
                    Debug.LogError("UISprite MakeSpriteResource name error" + name);
                    return(null);
                }

                resource = new SpriteResource(obj, false);
            }
            else
            {
                if (allresource == null)
                {
                    Debug.LogError("SpriteResource name error" + name);
                    return(null);
                }

                resource = new SpritePackerResource(spritePackerAsset, allresource, false);
            }
            string[] split        = path.Split('/');
            string   resourcename = split[split.Length - 1];

            resource.InitLoad(resourcename, path);
            Dictionary <int, IResource> dicRes = GetDicResource(eType);

            if (dicRes.ContainsKey(resource.GetHashCode()))
            {
                Debug.LogError("MakeSpriteResource name error" + name);
            }
            else
            {
                dicRes.Add(resource.GetHashCode(), resource);
            }
            return(resource);
        }
Exemplo n.º 19
0
 public void Draw(SpriteResource sprite, RawVector2 origin, float rotate, RawVector2 rotateOrigin)
 => Draw(sprite, new RawRectangleF(origin.X, origin.Y, origin.X + (sprite.Rect.Right - sprite.Rect.Left), origin.Y + (sprite.Rect.Bottom - sprite.Rect.Top)), rotate, rotateOrigin);
Exemplo n.º 20
0
        internal static UISpriteImage FromSpriteResource(SpriteResource resource)
        {
            UISpriteImage res = new UISpriteImage(new UnitSprite(resource));

            return(res);
        }
Exemplo n.º 21
0
 public void Draw(SpriteResource sprite, RawVector2 origin, float rotate)
 => Draw(sprite, origin, rotate, new RawVector2(.5f, .5f));
Exemplo n.º 22
0
 public void Draw(SpriteResource sprite, RawVector2 origin)
 => Draw(sprite, origin, 0);
Exemplo n.º 23
0
        private void CompileSprites()
        {
            LogQueue.Put("Compiling sprites...");
            var SpriteTexturePixels  = new List <uint>();
            var SpriteTextureIndexes = new Dictionary <string, int>();

            int id = 0;
            var CompiledSprites = new Compiled.Sprite[SpritesIDTable.LastID + 1];

            foreach (var s in SpritesIDTable.Items)
            {
                int dist = id;
                while (id < s.ID)
                {
                    CompiledSprites[id++] = new Compiled.Sprite();
                }
                dist = id - dist;
                if (dist > 0)
                {
                    LogQueue.Put("IDs skipped: " + dist);
                }

                LogQueue.Put("Compiling [" + s.Path + "]...");
                SpriteResource res = null;
                try { res = new SpriteResource(s.Path); }
                catch
                {
                    LogQueue.Put("Sprite [" + s.Path + "] not found. ID skipped.");
                    CompiledSprites[id] = new Compiled.Sprite();
                    id++;
                    continue;
                }

                CompiledSprites[id].TextureIndex = -1;
                CompiledSprites[id].FramesCount  = res.FramesCount;
                CompiledSprites[id].FrameDelay   = res.FrameDelay;
                CompiledSprites[id].ImgboxW      = res.ImgboxW;
                CompiledSprites[id].ImgboxH      = res.ImgboxH;
                CompiledSprites[id].AxisX        = res.AxisX;
                CompiledSprites[id].AxisY        = res.AxisY;
                CompiledSprites[id].Angle        = res.Angle;

                if (!SpriteTextureIndexes.ContainsKey("~:/" + res.FramesCount + res.VerticalFrames + "\\:~" + res.Texture.Link))
                {
                    try
                    {
                        int ind = SpriteTexturePixels.Count;
                        var tex = res.Texture.Resource.Texture;
                        int tw  = tex.Width;
                        int th  = tex.Height;

                        var pixels = new uint[tw * th];
                        if (res.VerticalFrames)
                        {
                            if (th % res.FramesCount != 0)
                            {
                                LogQueue.Put("Warning: Bad texture proporions.");
                            }
                            th /= res.FramesCount;

                            for (int f = 0; f < res.FramesCount; f++)
                            {
                                for (int y = 0; y < th; y++)
                                {
                                    for (int x = 0; x < tw; x++)
                                    {
                                        var p = tex.GetPixel(x, f * th + th - 1 - y);
                                        pixels[f * tw * th + y * tw + x] = ((uint)p.R << 24) | ((uint)p.G << 16) | ((uint)p.B << 8) | ((uint)p.A << 0);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (tw % res.FramesCount != 0)
                            {
                                LogQueue.Put("Warning: Bad texture proporions.");
                            }
                            tw /= res.FramesCount;

                            for (int f = 0; f < res.FramesCount; f++)
                            {
                                for (int y = 0; y < th; y++)
                                {
                                    for (int x = 0; x < tw; x++)
                                    {
                                        var p = tex.GetPixel(f * tw + x, th - 1 - y);
                                        pixels[f * tw * th + y * tw + x] = ((uint)p.R << 24) | ((uint)p.G << 16) | ((uint)p.B << 8) | ((uint)p.A << 0);
                                    }
                                }
                            }
                        }
                        SpriteTexturePixels.Add((uint)tw);
                        SpriteTexturePixels.Add((uint)th);
                        SpriteTexturePixels.AddRange(pixels);

                        SpriteTextureIndexes.Add("~:/" + res.FramesCount + res.VerticalFrames + "\\:~" + res.Texture.Link, ind);
                        CompiledSprites[id].TextureIndex = SpriteTextureIndexes["~:/" + res.FramesCount + res.VerticalFrames + "\\:~" + res.Texture.Link];
                        LogQueue.Put("Loaded texture [" + res.Texture.Link + "] index [" + CompiledSprites[id].TextureIndex + "].");
                    }
                    catch
                    {
                        CompiledSprites[id].TextureIndex = -1;
                        LogQueue.Put("Texture [" + res.Texture.Link + "] nod found index [" + CompiledSprites[id].TextureIndex + "].");
                    }
                }
                else
                {
                    CompiledSprites[id].TextureIndex = SpriteTextureIndexes["~:/" + res.FramesCount + res.VerticalFrames + "\\:~" + res.Texture.Link];
                    LogQueue.Put("Found texture [" + res.Texture.Link + "] index [" + CompiledSprites[id].TextureIndex + "].");
                }

                LogQueue.Put("Sprite [" + s.Path + "] compiled with id [" + id + "].");
                id++;
            }
            LogQueue.Put("Sprites compiled.");

            Directory.CreateDirectory("../Compilation");
            using (var w = new BinaryWriter(File.Create("../Compilation/Sprites")))
            {
                w.Write(SpriteTexturePixels.Count);
                foreach (var p in SpriteTexturePixels)
                {
                    w.Write(p);
                }
                w.Write(CompiledSprites.Length);
                foreach (var t in CompiledSprites)
                {
                    w.Write(t);
                }
            }
        }