Merge branch 'master' of https://github.com/Regalis11/Barotrauma
Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs
This commit is contained in:
@@ -549,6 +549,9 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays a message at the center of the screen, automatically preventing overlapping with other centered messages
|
||||
/// </summary>
|
||||
public static void AddMessage(string message, Color color, float lifeTime = 3.0f, bool playSound = true)
|
||||
{
|
||||
if (messages.Count > 0 && messages[messages.Count - 1].Text == message)
|
||||
@@ -558,12 +561,15 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
Vector2 pos = new Vector2(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight * 0.7f);
|
||||
pos.Y += messages.FindAll(m => m.Centered).Count * 30;
|
||||
pos.Y += messages.FindAll(m => m.AutoCenter).Count * 30;
|
||||
|
||||
messages.Add(new GUIMessage(message, color, pos, lifeTime, Alignment.Center, true));
|
||||
if (playSound) PlayUISound(GUISoundType.Message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display and automatically fade out a piece of text at an arbitrary position on the screen
|
||||
/// </summary>
|
||||
public static void AddMessage(string message, Vector2 position, Alignment alignment, Color color, float lifeTime = 3.0f, bool playSound = true)
|
||||
{
|
||||
if (messages.Count > 0 && messages[messages.Count - 1].Text == message)
|
||||
@@ -602,7 +608,7 @@ namespace Barotrauma
|
||||
alpha -= 1.0f - msg.LifeTime;
|
||||
}
|
||||
|
||||
if (msg.Centered)
|
||||
if (msg.AutoCenter)
|
||||
{
|
||||
msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime * 20.0f);
|
||||
currPos.Y += 30.0f;
|
||||
|
||||
@@ -115,10 +115,11 @@ namespace Barotrauma
|
||||
listBox.AddChild(child);
|
||||
}
|
||||
|
||||
public void AddItem(string text, object userData = null)
|
||||
public void AddItem(string text, object userData = null, string toolTip = "")
|
||||
{
|
||||
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, "ListBoxElement", Alignment.TopLeft, Alignment.CenterLeft, listBox);
|
||||
textBlock.UserData = userData;
|
||||
textBlock.ToolTip = toolTip;
|
||||
}
|
||||
|
||||
public override void ClearChildren()
|
||||
|
||||
@@ -171,12 +171,12 @@ namespace Barotrauma
|
||||
{
|
||||
for (int i = 0; i < children.Count; i++)
|
||||
{
|
||||
if (!children[i].UserData.Equals(userData)) continue;
|
||||
|
||||
Select(i, force);
|
||||
|
||||
//if (OnSelected != null) OnSelected(Selected, Selected.UserData);
|
||||
if (!SelectMultiple) return;
|
||||
if ((children[i].UserData != null && children[i].UserData.Equals(userData)) ||
|
||||
(children[i].UserData == null && userData == null))
|
||||
{
|
||||
Select(i, force);
|
||||
if (!SelectMultiple) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,14 +46,21 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool Centered;
|
||||
|
||||
public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool centered)
|
||||
/// <summary>
|
||||
/// Autocentered messages are automatically placed at the center of the screen and prevented from overlapping with each other
|
||||
/// </summary>
|
||||
public bool AutoCenter;
|
||||
|
||||
public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool autoCenter)
|
||||
{
|
||||
coloredText = new ColoredText(text, color, false);
|
||||
pos = position;
|
||||
this.lifeTime = lifeTime;
|
||||
this.Alignment = textAlignment;
|
||||
this.AutoCenter = autoCenter;
|
||||
|
||||
size = GUI.Font.MeasureString(text);
|
||||
|
||||
if (textAlignment.HasFlag(Alignment.Left))
|
||||
Origin.X += size.X * 0.5f;
|
||||
@@ -67,14 +74,10 @@ namespace Barotrauma
|
||||
if (textAlignment.HasFlag(Alignment.Bottom))
|
||||
Origin.Y -= size.Y * 0.5f;
|
||||
|
||||
if (centered)
|
||||
if (autoCenter)
|
||||
{
|
||||
Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y));
|
||||
}
|
||||
else
|
||||
{
|
||||
size = GUI.Font.MeasureString(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,8 @@ namespace Barotrauma
|
||||
{
|
||||
public static List<GUIComponent> MessageBoxes = new List<GUIComponent>();
|
||||
|
||||
const int DefaultWidth=400, DefaultHeight=250;
|
||||
|
||||
//public delegate bool OnClickedHandler(GUIButton button, object obj);
|
||||
//public OnClickedHandler OnClicked;
|
||||
|
||||
//GUIFrame frame;
|
||||
public const int DefaultWidth = 400, DefaultHeight = 250;
|
||||
|
||||
public GUIButton[] Buttons;
|
||||
|
||||
public static GUIComponent VisibleBox
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace Barotrauma
|
||||
{
|
||||
base.Rect = value;
|
||||
|
||||
box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height);
|
||||
text.Rect = new Rectangle(box.Rect.Right, box.Rect.Y + 2, 20, box.Rect.Height);
|
||||
if (box != null) box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height);
|
||||
if (text != null) text.Rect = new Rectangle(box.Rect.Right, box.Rect.Y + 2, 20, box.Rect.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user