Merge branch 'master' into new-netcode
Conflicts: Subsurface/Properties/AssemblyInfo.cs Subsurface/Source/Characters/AICharacter.cs Subsurface/Source/Characters/Animation/HumanoidAnimController.cs Subsurface/Source/Characters/Character.cs Subsurface/Source/GameMain.cs Subsurface/Source/Items/Components/Signal/Connection.cs Subsurface/Source/Items/Item.cs Subsurface/Source/Networking/GameServer.cs Subsurface/Source/Networking/GameServerLogin.cs Subsurface/Source/Physics/PhysicsBody.cs
This commit is contained in:
@@ -31,11 +31,22 @@ namespace Barotrauma
|
||||
public static GUIStyle Style;
|
||||
|
||||
private static Texture2D t;
|
||||
public static SpriteFont Font, SmallFont, LargeFont;
|
||||
public static ScalableFont Font, SmallFont, LargeFont;
|
||||
|
||||
private static Sprite cursor;
|
||||
|
||||
private static GraphicsDevice graphicsDevice;
|
||||
public static GraphicsDevice GraphicsDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
return graphicsDevice;
|
||||
}
|
||||
set
|
||||
{
|
||||
graphicsDevice = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<GUIMessage> messages = new List<GUIMessage>();
|
||||
|
||||
@@ -68,9 +79,9 @@ namespace Barotrauma
|
||||
|
||||
public static void Init(ContentManager content)
|
||||
{
|
||||
Font = ToolBox.TryLoadFont("SpriteFont1", content);
|
||||
SmallFont = ToolBox.TryLoadFont("SmallFont", content);
|
||||
LargeFont = ToolBox.TryLoadFont("LargeFont", content);
|
||||
Font = new ScalableFont("Content/Exo2-Medium.otf", 14, graphicsDevice);
|
||||
SmallFont = new ScalableFont("Content/Exo2-Light.otf", 12, graphicsDevice);
|
||||
LargeFont = new ScalableFont("Content/Code Pro Bold.otf", 22, graphicsDevice);
|
||||
|
||||
cursor = new Sprite("Content/UI/cursor.png", Vector2.Zero);
|
||||
|
||||
@@ -87,10 +98,8 @@ namespace Barotrauma
|
||||
get { return settingsMenuOpen; }
|
||||
}
|
||||
|
||||
public static void LoadContent(GraphicsDevice graphics, bool loadSounds = true)
|
||||
public static void LoadContent(bool loadSounds = true)
|
||||
{
|
||||
graphicsDevice = graphics;
|
||||
|
||||
if (loadSounds)
|
||||
{
|
||||
sounds = new Sound[Enum.GetValues(typeof(GUISoundType)).Length];
|
||||
@@ -232,7 +241,7 @@ namespace Barotrauma
|
||||
depth);
|
||||
}
|
||||
|
||||
public static void DrawString(SpriteBatch sb, Vector2 pos, string text, Color color, Color? backgroundColor=null, int backgroundPadding=0, SpriteFont font = null)
|
||||
public static void DrawString(SpriteBatch sb, Vector2 pos, string text, Color color, Color? backgroundColor=null, int backgroundPadding=0, ScalableFont font = null)
|
||||
{
|
||||
|
||||
if (font == null) font = Font;
|
||||
@@ -242,7 +251,7 @@ namespace Barotrauma
|
||||
DrawRectangle(sb, pos - Vector2.One * backgroundPadding, textSize + Vector2.One * 2.0f * backgroundPadding, (Color)backgroundColor, true);
|
||||
}
|
||||
|
||||
sb.DrawString(font, text, pos, color);
|
||||
font.DrawString(sb, text, pos, color);
|
||||
}
|
||||
|
||||
public static void DrawRectangle(SpriteBatch sb, Vector2 start, Vector2 size, Color clr, bool isFilled = false, float depth = 0.0f, int thickness = 1)
|
||||
@@ -405,7 +414,7 @@ namespace Barotrauma
|
||||
origin = Vector2.Zero;
|
||||
}
|
||||
|
||||
sb.DrawString(Font, text, new Vector2(rect.Center.X, rect.Center.Y) , Color.White, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f);
|
||||
Font.DrawString(sb, text, new Vector2(rect.Center.X, rect.Center.Y) , Color.White, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f);
|
||||
|
||||
return clicked;
|
||||
}
|
||||
@@ -582,12 +591,12 @@ namespace Barotrauma
|
||||
|
||||
msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime*20.0f);
|
||||
|
||||
spriteBatch.DrawString(Font, msg.Text,
|
||||
Font.DrawString(spriteBatch, msg.Text,
|
||||
new Vector2((int)msg.Pos.X - 1, (int)msg.Pos.Y - 1),
|
||||
Color.Black * alpha*0.5f, 0.0f,
|
||||
new Vector2((int)(0.5f * msg.Size.X), (int)(0.5f * msg.Size.Y)), 1.0f, SpriteEffects.None, 0.0f);
|
||||
|
||||
spriteBatch.DrawString(Font, msg.Text,
|
||||
Font.DrawString(spriteBatch, msg.Text,
|
||||
new Vector2((int)msg.Pos.X, (int)msg.Pos.Y),
|
||||
msg.Color * alpha, 0.0f,
|
||||
new Vector2((int)(0.5f * msg.Size.X), (int)(0.5f * msg.Size.Y)), 1.0f, SpriteEffects.None, 0.0f);
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Barotrauma
|
||||
set { textBlock.TextColor = value; }
|
||||
}
|
||||
|
||||
public override SpriteFont Font
|
||||
public override ScalableFont Font
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -28,7 +28,20 @@ namespace Barotrauma
|
||||
if (!Visible) return;
|
||||
if (ComponentsToUpdate.Contains(this)) return;
|
||||
ComponentsToUpdate.Add(this);
|
||||
children.ForEach(c => c.AddToGUIUpdateList());
|
||||
|
||||
try
|
||||
{
|
||||
List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
|
||||
foreach (GUIComponent c in fixedChildren)
|
||||
{
|
||||
c.AddToGUIUpdateList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.NewMessage("Error in AddToGUIUPdateList! GUIComponent runtime type: "+this.GetType().ToString()+"; children count: "+children.Count.ToString(),Color.Red);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearUpdateList()
|
||||
@@ -86,7 +99,7 @@ namespace Barotrauma
|
||||
protected Color flashColor;
|
||||
protected float flashTimer;
|
||||
|
||||
public virtual SpriteFont Font
|
||||
public virtual ScalableFont Font
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@@ -367,13 +380,21 @@ namespace Barotrauma
|
||||
|
||||
}*/
|
||||
|
||||
//use a fixed list since children can change their order in the main children list
|
||||
//TODO: maybe find a more efficient way of handling changes in list order
|
||||
List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
|
||||
foreach (GUIComponent c in fixedChildren)
|
||||
try
|
||||
{
|
||||
if (!c.Visible) continue;
|
||||
c.Update(deltaTime);
|
||||
//use a fixed list since children can change their order in the main children list
|
||||
//TODO: maybe find a more efficient way of handling changes in list order
|
||||
List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
|
||||
foreach (GUIComponent c in fixedChildren)
|
||||
{
|
||||
if (!c.Visible) continue;
|
||||
c.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.NewMessage("Error in Update! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,6 +461,23 @@ namespace Barotrauma
|
||||
|
||||
public virtual void AddChild(GUIComponent child)
|
||||
{
|
||||
if (child == null) return;
|
||||
if (child.IsParentOf(this))
|
||||
{
|
||||
DebugConsole.ThrowError("Tried to add the parent of a GUIComponent as a child.\n" + Environment.StackTrace);
|
||||
return;
|
||||
}
|
||||
if (child == this)
|
||||
{
|
||||
DebugConsole.ThrowError("Tried to add a GUIComponent as its own child\n" + Environment.StackTrace);
|
||||
return;
|
||||
}
|
||||
if (children.Contains(child))
|
||||
{
|
||||
DebugConsole.ThrowError("Tried to add a the same child twice to a GUIComponent" + Environment.StackTrace);
|
||||
return;
|
||||
}
|
||||
|
||||
child.parent = this;
|
||||
child.UpdateDimensions(this);
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ namespace Barotrauma
|
||||
{
|
||||
public class GUIImage : GUIComponent
|
||||
{
|
||||
Sprite sprite;
|
||||
public float Rotation;
|
||||
|
||||
Rectangle sourceRect;
|
||||
private Sprite sprite;
|
||||
|
||||
private Rectangle sourceRect;
|
||||
|
||||
bool crop;
|
||||
|
||||
@@ -85,7 +87,7 @@ namespace Barotrauma
|
||||
|
||||
if (sprite != null && sprite.Texture != null)
|
||||
{
|
||||
spriteBatch.Draw(sprite.Texture, new Vector2(rect.X, rect.Y), sourceRect, currColor * (currColor.A / 255.0f), 0.0f, Vector2.Zero,
|
||||
spriteBatch.Draw(sprite.Texture, new Vector2(rect.X, rect.Y), sourceRect, currColor * (currColor.A / 255.0f), Rotation, Vector2.Zero,
|
||||
Scale, SpriteEffects.None, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,17 @@ namespace Barotrauma
|
||||
: base(new Rectangle(0,0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
|
||||
Color.Black*0.5f, Alignment.TopLeft, null, parent)
|
||||
{
|
||||
if (height == 0)
|
||||
{
|
||||
string wrappedText = ToolBox.WrapText(text, width, GUI.Font);
|
||||
string[] lines = wrappedText.Split('\n');
|
||||
foreach (string line in lines)
|
||||
{
|
||||
height += (int)GUI.Font.MeasureString(line).Y;
|
||||
}
|
||||
height += 220;
|
||||
}
|
||||
|
||||
var frame = new GUIFrame(new Rectangle(0,0,width,height), null, Alignment.Center, GUI.Style, this);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, GUI.Style, frame, true);
|
||||
|
||||
@@ -103,8 +103,8 @@ namespace Barotrauma
|
||||
{
|
||||
get { return caretPos; }
|
||||
}
|
||||
|
||||
public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent, SpriteFont font)
|
||||
|
||||
public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent, ScalableFont font)
|
||||
: this(rect, text, style, Alignment.TopLeft, Alignment.TopLeft, parent, false, font)
|
||||
{
|
||||
}
|
||||
@@ -142,7 +142,7 @@ namespace Barotrauma
|
||||
if (textColor != null) this.textColor = (Color)textColor;
|
||||
}
|
||||
|
||||
public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, SpriteFont font = null)
|
||||
public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, ScalableFont font = null)
|
||||
:base (style)
|
||||
{
|
||||
this.Font = font == null ? GUI.Font : font;
|
||||
@@ -174,7 +174,7 @@ namespace Barotrauma
|
||||
|
||||
wrappedText = text;
|
||||
|
||||
Vector2 size = MeasureText(text);
|
||||
Vector2 size = MeasureText(text);
|
||||
|
||||
if (Wrap && rect.Width>0)
|
||||
{
|
||||
@@ -184,7 +184,7 @@ namespace Barotrauma
|
||||
|
||||
size = newSize;
|
||||
}
|
||||
|
||||
|
||||
if (LimitText && text.Length>1 && size.Y > rect.Height)
|
||||
{
|
||||
string[] lines = text.Split('\n');
|
||||
@@ -205,7 +205,7 @@ namespace Barotrauma
|
||||
|
||||
if (textAlignment.HasFlag(Alignment.Bottom))
|
||||
origin.Y -= (rect.Height / 2.0f - padding.W) - size.Y / 2;
|
||||
|
||||
|
||||
origin.X = (int)origin.X;
|
||||
origin.Y = (int)origin.Y;
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace Barotrauma
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
spriteBatch.DrawString(Font,
|
||||
Font.DrawString(spriteBatch,
|
||||
Wrap ? wrappedText : text,
|
||||
new Vector2(rect.X, rect.Y) + textPos + offset,
|
||||
textColor * (textColor.A / 255.0f),
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Barotrauma
|
||||
|
||||
bool caretVisible;
|
||||
float caretTimer;
|
||||
|
||||
|
||||
GUITextBlock textBlock;
|
||||
|
||||
public delegate bool OnEnterHandler(GUITextBox textBox, string text);
|
||||
@@ -65,7 +65,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override SpriteFont Font
|
||||
public override ScalableFont Font
|
||||
{
|
||||
set
|
||||
{
|
||||
@@ -131,7 +131,7 @@ namespace Barotrauma
|
||||
|
||||
if (textBlock.Text != "")
|
||||
{
|
||||
//if you attempt to display a Character that is not in your font
|
||||
/*//if you attempt to display a Character that is not in your font
|
||||
//you will get an exception, so we filter the characters
|
||||
//remove the filtering if you're using a default Character in your spritefont
|
||||
String filtered = "";
|
||||
@@ -140,7 +140,7 @@ namespace Barotrauma
|
||||
if (Font.Characters.Contains(c)) filtered += c;
|
||||
}
|
||||
|
||||
textBlock.Text = filtered;
|
||||
textBlock.Text = filtered;*/
|
||||
|
||||
if (!Wrap && Font.MeasureString(textBlock.Text).X > rect.Width)
|
||||
{
|
||||
@@ -182,6 +182,8 @@ namespace Barotrauma
|
||||
|
||||
textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, style, this);
|
||||
|
||||
Font = GUI.Font;
|
||||
|
||||
if (style != null) style.Apply(textBlock, this);
|
||||
textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f);
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Barotrauma
|
||||
{
|
||||
}
|
||||
|
||||
public GUITickBox(Rectangle rect, string label, Alignment alignment, SpriteFont font, GUIComponent parent)
|
||||
public GUITickBox(Rectangle rect, string label, Alignment alignment, ScalableFont font, GUIComponent parent)
|
||||
: base(null)
|
||||
{
|
||||
if (parent != null)
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace Barotrauma
|
||||
|
||||
if (GUI.LargeFont!=null)
|
||||
{
|
||||
spriteBatch.DrawString(GUI.LargeFont, loadText,
|
||||
GUI.LargeFont.DrawString(spriteBatch, loadText,
|
||||
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f),
|
||||
Color.White);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user