1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
9 private float progress;
13 get {
return progress; }
14 set { progress = MathHelper.Clamp(value, 0.0f, 1.0f); }
19 private Color fullColor, emptyColor;
21 private Vector2 worldPosition;
31 worldPosition = value;
32 if (parentSub !=
null)
48 private string textTag;
51 get {
return textTag; }
54 if (textTag == value) {
return; }
56 Text =
string.IsNullOrEmpty(textTag) ?
string.Empty : TextManager.Get(textTag);
61 : this(worldPosition, parentSubmarine, GUIStyle.Red, GUIStyle.Green, textTag)
65 public HUDProgressBar(Vector2 worldPosition,
Submarine parentSubmarine, Color emptyColor, Color fullColor,
string textTag)
67 this.emptyColor = emptyColor;
68 this.fullColor = fullColor;
69 parentSub = parentSubmarine;
71 Size =
new Vector2(100.0f, 20.0f);
73 if (!
string.IsNullOrEmpty(textTag))
75 this.textTag = textTag;
91 if (parentSub !=
null)
93 pos += parentSub.DrawPosition;
97 Color color = Color.Lerp(emptyColor, fullColor, progress);
98 GUI.DrawProgressBar(spriteBatch,
99 new Vector2(pos.X, -pos.Y),
102 Color.White * a * 0.8f);
104 if (!
Text.IsNullOrEmpty())
106 Vector2 textSize = GUIStyle.SmallFont.MeasureString(
Text);
107 Vector2 textPos =
new Vector2(pos.X + (
Size.X - textSize.X) / 2, pos.Y - textSize.Y * 1.2f);
108 GUI.DrawString(spriteBatch, textPos - Vector2.One,
Text, Color.Black * a, font: GUIStyle.SmallFont);
109 GUI.DrawString(spriteBatch, textPos,
Text, Color.White * a, font: GUIStyle.SmallFont);
Vector2 WorldToScreen(Vector2 coords)
HUDProgressBar(Vector2 worldPosition, Submarine parentSubmarine, Color emptyColor, Color fullColor, string textTag)
void Draw(SpriteBatch spriteBatch, Camera cam)
void Update(float deltatime)
HUDProgressBar(Vector2 worldPosition, string textTag, Submarine parentSubmarine=null)
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.