Client LuaCsForBarotrauma
GUIMessage.cs
1 using Microsoft.Xna.Framework;
2 
3 namespace Barotrauma
4 {
5  class GUIMessage
6  {
7  private ColoredText coloredText;
8  private Vector2 pos;
9 
10  private float lifeTime;
11 
12  private Vector2 size;
13 
14  public readonly bool WorldSpace;
15 
16  public string Text
17  {
18  get { return coloredText.Text; }
19  }
20 
21  public Color Color
22  {
23  get { return coloredText.Color; }
24  }
25 
26  public Vector2 Pos
27  {
28  get { return pos; }
29  set { pos = value; }
30  }
31 
32  public Vector2 Velocity
33  {
34  get;
35  private set;
36  }
37 
38  public Vector2 Size
39  {
40  get { return size; }
41  }
42 
43  public Vector2 Origin;
44 
45  public float Timer;
46 
47  public float LifeTime
48  {
49  get { return lifeTime; }
50  }
51 
52  public GUIFont Font
53  {
54  get;
55  private set;
56  }
57 
59  {
60  get;
61  private set;
62  }
63 
64  public Vector2 DrawPos
65  {
66  get
67  {
68  return Submarine == null ? Pos : Pos + Submarine.DrawPosition;
69  }
70  }
71 
72  public GUIMessage(string text, Color color, float lifeTime, GUIFont font = null)
73  {
74  coloredText = new ColoredText(text, color, false, false);
75  this.lifeTime = lifeTime;
76  Timer = lifeTime;
77 
78  size = font.MeasureString(text);
79  Origin = new Vector2(0, size.Y * 0.5f);
80 
81  Font = font;
82  }
83 
84  public GUIMessage(string text, Color color, Vector2 position, Vector2 velocity, float lifeTime, Alignment textAlignment = Alignment.Center, GUIFont font = null, Submarine sub = null)
85  {
86  coloredText = new ColoredText(text, color, false, false);
87  WorldSpace = true;
88  pos = position;
89  Timer = lifeTime;
90  Velocity = velocity;
91  this.lifeTime = lifeTime;
92 
93  Font = font;
94 
95  size = font.MeasureString(text);
96 
97  Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y));
98  if (textAlignment.HasFlag(Alignment.Left))
99  Origin.X -= size.X * 0.5f;
100 
101  if (textAlignment.HasFlag(Alignment.Right))
102  Origin.X += size.X * 0.5f;
103 
104  if (textAlignment.HasFlag(Alignment.Top))
105  Origin.Y -= size.Y * 0.5f;
106 
107  if (textAlignment.HasFlag(Alignment.Bottom))
108  Origin.Y += size.Y * 0.5f;
109 
110  Submarine = sub;
111  }
112  }
113 }
Vector2 MeasureString(LocalizedString str, bool removeExtraSpacing=false)
Definition: GUIPrefab.cs:284
GUIMessage(string text, Color color, Vector2 position, Vector2 velocity, float lifeTime, Alignment textAlignment=Alignment.Center, GUIFont font=null, Submarine sub=null)
Definition: GUIMessage.cs:84
readonly bool WorldSpace
Definition: GUIMessage.cs:14
GUIMessage(string text, Color color, float lifeTime, GUIFont font=null)
Definition: GUIMessage.cs:72