Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Items/Components/Planter.cs
1 using System;
2 using System.Linq;
3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
5 
7 {
8  internal partial class Planter
9  {
10  public Vector2 DrawSize => CalculateSize();
11 
12  private Vector2 CalculateSize()
13  {
14  if (GrowableSeeds.All(s => s == null)) { return Vector2.Zero; }
15 
16  Point pos = item.DrawPosition.ToPoint();
17  Rectangle rect = new Rectangle(pos, Point.Zero);
18 
19  for (int i = 0; i < GrowableSeeds.Length; i++)
20  {
21  Growable seed = GrowableSeeds[i];
22  PlantSlot slot = PlantSlots.ContainsKey(i) ? PlantSlots[i] : NullSlot;
23  if (seed == null) { continue; }
24 
25  foreach (VineTile vine in seed.Vines)
26  {
27  Rectangle worldRect = vine.Rect;
28  worldRect.Location += slot.Offset.ToPoint();
29  worldRect.Location += pos;
30  rect = Rectangle.Union(rect, worldRect);
31  }
32  }
33 
34  Vector2 result = new Vector2(MaxDistance(pos.X, rect.Left, rect.Right) * 2, MaxDistance(pos.Y, rect.Top, rect.Bottom) * 2);
35  return result;
36 
37  static float MaxDistance(float origin, float x, float y)
38  {
39  return Math.Max(Math.Abs(origin - x), Math.Abs(origin - y));
40  }
41  }
42 
43  public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
44  {
45  for (var i = 0; i < GrowableSeeds.Length; i++)
46  {
47  Growable growable = GrowableSeeds[i];
48  PlantSlot slot = PlantSlots.ContainsKey(i) ? PlantSlots[i] : NullSlot;
49  growable?.Draw(spriteBatch, this, slot.Offset, itemDepth);
50  }
51  }
52  }
53 }
virtual Vector2 DrawPosition
Definition: Entity.cs:51