Exemplo n.º 1
0
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            var orig = RotateOrigin;

            if (Rotation != 0f && orig == new Vector2(-1, -1))
            {
                orig = new Vector2(Width / 2, Height / 2);
            }
            if (Availablity == AvailablityStates.Enabled && Texture != null)
            {
                spriteBatch.Draw(Texture, BoundingRectangle, null,
                                 Color.Lerp(Mask, Lighting.LightColor, Lighting.LightIntensity),
                                 Rotation, orig, Effects, LayerDepth);
                ShadowHandler.CastShadow(spriteBatch, Location, Scale);
                if (HasPlacementSlots)
                {
                    for (int i = 0; i < PlacementSlots.Count; i++)
                    {
                        var o = GetPlacementSlot(i).Value;
                        if (o != null)
                        {
                            o.LayerDepth = LayerDepth + .01f;
                            o.Rotation   = Rotation;
                            o.Draw(spriteBatch);
                        }
                    }
                }
            }
            if (Main.IsDebugMode)
            {
                if (IsClickable)
                {
                    spriteBatch.Draw(Main.BaseTexture, Location + ScaledCollisionMousePosition, null, IsMouseOver ? Color.Green : Color.Red, 0f, Vector2.Zero, 10, SpriteEffects.None, 1);
                }
                if (HasPlacementSlots)
                {
                    for (int i = 0; i < PlacementSlots.Count; i++)
                    {
                        var s = GetPlacementSlot(i);
                        spriteBatch.Draw(Main.BaseTexture, s.Key.ToVector2(), null, s.Value != null ? Color.DeepSkyBlue : Color.Blue, 0f, Vector2.Zero, 10, SpriteEffects.None, 1);
                    }
                }
                if (Main.DEBUG_HighlightingMode)
                {
                    DEBUG_Highlight = Color.Green;
                }
                spriteBatch.Draw(Main.BaseTexture, BoundingRectangle, null, DEBUG_Highlight * .5f, 0f, Vector2.Zero, Effects, 1);
            }
        }
Exemplo n.º 2
0
        protected override void PostSetupPrefabDuringPatchtime(GameObject prefab)
        {
            ShadowHandler shadowHandler = prefab.transform.Find("Sprite/Shadow").gameObject.AddComponent <ShadowHandler>();

            shadowHandler.shadowDistance     = 0.3f;
            shadowHandler.referenceTransform = prefab.transform;

            ShadowHandler shadowHandler2 = prefab.transform.Find("Sprite/OfficeChair/Shadow").gameObject.AddComponent <ShadowHandler>();

            shadowHandler2.shadowDistance     = 0.1f;
            shadowHandler2.referenceTransform = prefab.transform.Find("Sprite/OfficeChair");

            prefab.transform.Find("Sprite/Desk").GetComponent <SpriteRenderer>().sortingLayerName                      = "BelowObjects";
            prefab.transform.Find("Sprite/Shadow").GetComponent <SpriteRenderer>().sortingLayerName                    = "BelowObjects";
            prefab.transform.Find("Sprite/OfficeChair").GetComponent <SpriteRenderer>().sortingLayerName               = "SeatingObjects";
            prefab.transform.Find("Sprite/OfficeChair/Shadow").GetComponent <SpriteRenderer>().sortingLayerName        = "SeatingObjects";
            prefab.transform.Find("Sprite/DeskItems/Computer").GetComponent <SpriteRenderer>().sortingLayerName        = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Computer (2)").GetComponent <SpriteRenderer>().sortingLayerName    = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Computer (3)").GetComponent <SpriteRenderer>().sortingLayerName    = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Keyboard").GetComponent <SpriteRenderer>().sortingLayerName        = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Phone").GetComponent <SpriteRenderer>().sortingLayerName           = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Lamp").GetComponent <SpriteRenderer>().sortingLayerName            = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Pens/Pen").GetComponent <SpriteRenderer>().sortingLayerName        = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Pens/Pen (3)").GetComponent <SpriteRenderer>().sortingLayerName    = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Pens/Pen (4)").GetComponent <SpriteRenderer>().sortingLayerName    = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Paper/Paper").GetComponent <SpriteRenderer>().sortingLayerName     = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Paper/Paper (2)").GetComponent <SpriteRenderer>().sortingLayerName = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Paper/Paper (4)").GetComponent <SpriteRenderer>().sortingLayerName = "BelowObjects";
            prefab.transform.Find("Sprite/DeskItems/Paper/Paper (5)").GetComponent <SpriteRenderer>().sortingLayerName = "BelowObjects";
            prefab.transform.Find("Overlay/OverlaySprite").GetComponent <SpriteRenderer>().sortingLayerName            = "SpriteOverlay";
            prefab.transform.Find("Overlay/ConstructionOverlay/ConstructionOverlaySprites/WireframeSprite").GetComponent <SpriteRenderer>().sortingLayerName = "SpriteOverlay";

            Shader spriteDefault = Shader.Find("Sprites/Default");

            foreach (SpriteRenderer sr in prefab.GetComponentsInChildren <SpriteRenderer>())
            {
                sr.material.shader = spriteDefault;
            }
        }
Exemplo n.º 3
0
        internal void RaiseOnPaint(PaintEventArgs e)
        {
            e.Graphics.Control = this;
            Batches            = 0;

            if (ShadowBox)
            {
                if (ShadowHandler == null)
                {
                    int shX = e.ClipRectangle.X + 6;
                    int shY = e.ClipRectangle.Y + 6;
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(12, 64, 64, 64)), shX + 6, shY + 6, Width - 12, Height - 12);
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(12, 64, 64, 64)), shX + 5, shY + 5, Width - 10, Height - 10);
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(12, 64, 64, 64)), shX + 4, shY + 4, Width - 8, Height - 8);
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(12, 64, 64, 64)), shX + 3, shY + 3, Width - 6, Height - 6);
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(12, 64, 64, 64)), shX + 2, shY + 2, Width - 4, Height - 4);
                }
                else
                {
                    ShadowHandler.Invoke(e);
                }
            }

            if (UserGroup)
            {
                e.Graphics.Group = new Drawing.Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, Width, Height);
                e.Graphics.GroupBegin(this);
            }
            OnPaintBackground(e);
            OnPaint(e);
            if (Controls != null)
            {
                for (int i = 0; i < Controls.Count; i++)
                {
                    if (Application.ControlIsVisible(Controls[i]) == false)
                    {
                        continue;
                    }

                    var currentAbspos = Controls[i].PointToScreen(System.Drawing.Point.Zero);
                    if (currentAbspos.X + Controls[i].Width <0 || currentAbspos.X> UnityEngine.Screen.width ||
                        currentAbspos.Y + Controls[i].Height <0 || currentAbspos.Y> UnityEngine.Screen.height)
                    {
                        continue;
                    }
                    e.Graphics.Control = Controls[i];
                    Controls[i].RaiseOnPaint(e);
                }
            }
            e.Graphics.Control = this;
            if (Application.Debug)
            {
                e.Graphics.DrawString(GetType().Name, Font, Brushes.White, 3, 1, 256, 32);
                e.Graphics.DrawString(GetType().Name, Font, Brushes.White, 5, 3, 256, 32);
                e.Graphics.DrawString(GetType().Name, Font, Brushes.DarkRed, 4, 2, 256, 32);
                e.Graphics.DrawRectangle(Pens.DarkRed, 0, 0, Width, Height);
            }
            OnLatePaint(e);
            if (UserGroup)
            {
                e.Graphics.GroupEnd();
            }
            Batched = true;

            e.Graphics.Control = null;
        }
        protected virtual void AddShadowHandler(GameObject vehicle)
        {
            ShadowHandler shadowHandler = vehicle.transform.Find("Sprite/Shadow").gameObject.AddComponent <ShadowHandler>();

            shadowHandler.shadowDistance = ShadowDistance;
        }
Exemplo n.º 5
0
        internal void RaiseOnPaint(PaintEventArgs e)
        {
            e.Graphics.Control = this;
            Batches            = 0;

            if (ShadowBox)
            {
                if (ShadowHandler == null)
                {
                    ShadowHandler = (pArgs) =>
                    {
                        var psLoc       = PointToScreen(Point.Zero);
                        int shX         = psLoc.X + 6;
                        int shY         = psLoc.Y + 6;
                        var shadowColor = defaultShadowColor;
                        pArgs.Graphics.FillRectangle(shadowColor, shX + 6, shY + 6, Width - 12, Height - 12);
                        pArgs.Graphics.FillRectangle(shadowColor, shX + 5, shY + 5, Width - 10, Height - 10);
                        pArgs.Graphics.FillRectangle(shadowColor, shX + 4, shY + 4, Width - 8, Height - 8);
                        pArgs.Graphics.FillRectangle(shadowColor, shX + 3, shY + 3, Width - 6, Height - 6);
                        pArgs.Graphics.FillRectangle(shadowColor, shX + 2, shY + 2, Width - 4, Height - 4);
                    };
                }

                ShadowHandler.Invoke(e);
            }

            if (AutoGroup)
            {
                int gx = e.ClipRectangle.X;
                int gy = e.ClipRectangle.Y;

                if (gx != 0 && gy != 9) // Reset?
                {
                    e.ClipRectangle = new Rectangle(0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
                }

                e.Graphics.Group = new Drawing.Rectangle(gx, gy, Width, Height);
                e.Graphics.GroupBegin(this);
            }
            OnPaintBackground(e);
            OnPaint(e);
            if (Controls != null)
            {
                for (int i = 0; i < Controls.Count; i++)
                {
                    if (Application.ControlIsVisible(Controls[i]) == false)
                    {
                        continue;
                    }

                    var currentAbspos = Controls[i].PointToScreen(System.Drawing.Point.Zero);
                    if (currentAbspos.X + Controls[i].Width <0 || currentAbspos.X> Screen.PrimaryScreen.WorkingArea.Width ||
                        currentAbspos.Y + Controls[i].Height <0 || currentAbspos.Y> Screen.PrimaryScreen.WorkingArea.Height)
                    {
                        continue;
                    }

                    e.Graphics.Control = Controls[i];
                    Controls[i].RaiseOnPaint(e);
                }
            }
            e.Graphics.Control = this;
            if (Application.Debug)
            {
                e.Graphics.DrawString(GetType().Name, Font, Brushes.White, 3, 1, 256, 32);
                e.Graphics.DrawString(GetType().Name, Font, Brushes.White, 5, 3, 256, 32);
                e.Graphics.DrawString(GetType().Name, Font, Brushes.DarkRed, 4, 2, 256, 32);
                e.Graphics.DrawRectangle(Pens.DarkRed, 0, 0, Width, Height);
            }
            OnLatePaint(e);
            if (AutoGroup)
            {
                e.Graphics.GroupEnd();
            }

            e.Graphics.Control = null;
        }