Exemplo n.º 1
0
        public override void CreateCosmeticChildren(ComponentManager manager)
        {
            base.CreateCosmeticChildren(manager);

            var type = Library.GetResourceType(Resource.Type);

            if (type == null)
            {
                type = Library.GetResourceType("Invalid");
            }

            Tinter sprite = null;

            int numSprites = Math.Min(Resource.Count, 3);

            for (int i = 0; i < numSprites; i++)
            {
                // Minor optimization for single layer resources.
                if (type.CompositeLayers.Count == 1)
                {
                    var layer = type.CompositeLayers[0];
                    sprite = AddChild(new SimpleBobber(Manager, "Sprite",
                                                       Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                       new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                                                       layer.Frame, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = SimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                    sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f);
                }
                else
                {
                    var layers = new List <LayeredSimpleSprite.Layer>();

                    foreach (var layer in type.CompositeLayers)
                    {
                        layers.Add(new LayeredSimpleSprite.Layer
                        {
                            Sheet = new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                            Frame = layer.Frame
                        });
                    }

                    sprite = AddChild(new LayeredBobber(Manager, "Sprite",
                                                        Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f),
                                                        layers, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = LayeredSimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                }

                sprite.LightRamp = type.Tint;
                sprite.SetFlag(Flag.ShouldSerialize, false);
            }
        }
Exemplo n.º 2
0
        public override void CreateCosmeticChildren(ComponentManager manager)
        {
            base.CreateCosmeticChildren(manager);

            Resource type = ResourceLibrary.GetResourceByName(Resource.ResourceType);

            Tinter sprite = null;

            if (type.CompositeLayers == null || type.CompositeLayers.Count == 0)
            {
                sprite = AddChild(new SimpleSprite(Manager, "Sprite",
                                                   Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                   false,
                                                   new SpriteSheet(type.Image.AssetName, 32),
                                                   new Point(type.Image.SourceRect.X / 32, type.Image.SourceRect.Y / 32))
                {
                    OrientationType = SimpleSprite.OrientMode.Spherical,
                    WorldHeight     = 0.75f,
                    WorldWidth      = 0.75f,
                }) as Tinter;
                sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f);
            }
            else
            {
                var layers = new List <LayeredSimpleSprite.Layer>();

                foreach (var layer in type.CompositeLayers)
                {
                    if (layer.Value != null)
                    {
                        layers.Add(new LayeredSimpleSprite.Layer
                        {
                            Sheet = new SpriteSheet(layer.Value, 32),
                            Frame = layer.Key
                        });
                    }
                }

                sprite = AddChild(new LayeredSimpleSprite(Manager, "Sprite",
                                                          Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                          false,
                                                          layers)
                {
                    OrientationType = LayeredSimpleSprite.OrientMode.Spherical,
                    WorldHeight     = 0.75f,
                    WorldWidth      = 0.75f,
                }) as Tinter;
            }

            sprite.Tint = type.Tint;
            sprite.SetFlag(Flag.ShouldSerialize, false);

            sprite.AddChild(new Bobber(Manager, 0.05f, 2.0f, MathFunctions.Rand() * 3.0f, sprite.LocalTransform.Translation.Y)).SetFlag(Flag.ShouldSerialize, false);
        }
Exemplo n.º 3
0
        public override void CreateCosmeticChildren(ComponentManager manager)
        {
            base.CreateCosmeticChildren(manager);

            if (Resource.Gui_NewStyle)
            {
                var       sheetName          = String.Format("{0}&{1}-{2}&{3}", Resource.Gui_Graphic.AssetPath, Resource.Gui_Graphic.Frame.X, Resource.Gui_Graphic.Frame.Y, Resource.Gui_Palette);
                var       tiledInstanceGroup = Manager.World.Renderer.InstanceRenderer.GetCombinedTiledInstance();
                Texture2D fixedTex           = null;
                if (!tiledInstanceGroup.DoesInstanceSheetExist(sheetName))
                {
                    if (DwarfSprites.LayerLibrary.FindPalette(Resource.Gui_Palette).HasValue(out var palette))
                    {
                        fixedTex = TextureTool.CropAndColorSprite(manager.World.Renderer.GraphicsDevice, AssetManager.GetContentTexture(Resource.Gui_Graphic.AssetPath),
                                                                  Resource.Gui_Graphic.FrameSize, Resource.Gui_Graphic.Frame, DwarfSprites.LayerLibrary.BasePalette.CachedPalette, palette.CachedPalette);
                    }
                }

                var sheet = new SpriteSheet(fixedTex)
                {
                    FrameWidth  = Resource.Gui_Graphic.FrameSize.X,
                    FrameHeight = Resource.Gui_Graphic.FrameSize.Y,
                    AssetName   = sheetName
                };

                var sprite = AddChild(new SimpleBobber(Manager, "Sprite", Matrix.CreateTranslation(Vector3.UnitY * 0.25f), sheet, Point.Zero, 0.15f,
                                                       MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)) as Tinter;
                sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f);
                sprite.LightRamp      = Resource.Tint;
                sprite.SetFlag(Flag.ShouldSerialize, false);
            }
            else
            {
                var compositeLayers = Resource.CompositeLayers;
                var tint            = Resource.Tint;

                Tinter sprite = null;

                // Minor optimization for single layer resources.
                if (compositeLayers.Count == 1)
                {
                    var layer = compositeLayers[0];
                    sprite = AddChild(new SimpleBobber(Manager, "Sprite",
                                                       Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                       new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                                                       layer.Frame, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = SimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                    sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f);
                }
                else
                {
                    var layers = new List <LayeredSimpleSprite.Layer>();

                    foreach (var layer in compositeLayers)
                    {
                        layers.Add(new LayeredSimpleSprite.Layer
                        {
                            Sheet = new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                            Frame = layer.Frame
                        });
                    }

                    sprite = AddChild(new LayeredBobber(Manager, "Sprite",
                                                        Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f),
                                                        layers, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = LayeredSimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                }

                sprite.LightRamp = tint;
                sprite.SetFlag(Flag.ShouldSerialize, false);
            }
        }