38f1ddb...178a853: v0.8.9.1, removed content folder

This commit is contained in:
Joonas Rikkonen
2019-03-18 19:46:58 +02:00
parent 38f1ddb6fe
commit 6c0679c297
1054 changed files with 151673 additions and 144931 deletions
@@ -1,5 +1,8 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -9,48 +12,41 @@ namespace Barotrauma
public const int DefaultWidth = 400, DefaultHeight = 250;
public GUIButton[] Buttons;
public static GUIComponent VisibleBox
{
get { return MessageBoxes.Count == 0 ? null : MessageBoxes[0]; }
}
public GUIFrame InnerFrame
{
get { return children[0] as GUIFrame; }
}
public string Text
{
get { return (children[0].children[1] as GUITextBlock).Text; }
set { (children[0].children[1] as GUITextBlock).Text = value; }
}
public List<GUIButton> Buttons { get; private set; } = new List<GUIButton>();
//public GUIFrame BackgroundFrame { get; private set; }
public GUILayoutGroup Content { get; private set; }
public GUIFrame InnerFrame { get; private set; }
public GUITextBlock Header { get; private set; }
public GUITextBlock Text { get; private set; }
public static GUIComponent VisibleBox => MessageBoxes.LastOrDefault();
public GUIMessageBox(string headerText, string text)
: this(headerText, text, new string[] {"OK"}, DefaultWidth, 0)
{
this.Buttons[0].OnClicked = Close;
}
public GUIMessageBox(string headerText, string text, int width, int height)
: this(headerText, text, new string[] { "OK" }, width, height)
{
this.Buttons[0].OnClicked = Close;
}
public GUIMessageBox(string headerText, string text, string[] buttons, int width = DefaultWidth, int height = 0, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null)
: base(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
Color.Black * 0.5f, Alignment.TopLeft, null, parent)
// TODO: allow to use a relative size.
public GUIMessageBox(string headerText, string text, string[] buttons, int width = DefaultWidth, int height = 0, Alignment textAlignment = Alignment.TopLeft)
: base(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: "")
{
int headerHeight = 30;
var frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, "", this);
GUI.Style.Apply(frame, "", this);
InnerFrame = new GUIFrame(new RectTransform(new Point(width, height), RectTransform, Anchor.Center) { IsFixedSize = false }, style: null);
GUI.Style.Apply(InnerFrame, "", this);
Content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), InnerFrame.RectTransform, Anchor.Center)) { AbsoluteSpacing = 5 };
if (height == 0)
{
string wrappedText = ToolBox.WrapText(text, frame.Rect.Width - frame.Padding.X - frame.Padding.Z, GUI.Font);
string wrappedText = ToolBox.WrapText(text, Content.Rect.Width, GUI.Font);
string[] lines = wrappedText.Split('\n');
foreach (string line in lines)
{
@@ -58,33 +54,103 @@ namespace Barotrauma
}
height += string.IsNullOrWhiteSpace(headerText) ? 220 : 220 - headerHeight;
}
frame.Rect = new Rectangle(frame.Rect.X, GameMain.GraphicsHeight / 2 - height/2, frame.Rect.Width, height);
InnerFrame.RectTransform.NonScaledSize = new Point(InnerFrame.Rect.Width, height);
var header = new GUITextBlock(new Rectangle(0, 0, 0, headerHeight), headerText, null, null, textAlignment, "", frame, true);
GUI.Style.Apply(header, "", this);
Header = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), Content.RectTransform),
headerText, textAlignment: Alignment.Center, wrap: true);
GUI.Style.Apply(Header, "", this);
if (!string.IsNullOrWhiteSpace(text))
{
var textBlock = new GUITextBlock(new Rectangle(0, string.IsNullOrWhiteSpace(headerText) ? 0 : headerHeight, 0, height - 70), text,
null, null, textAlignment, "", frame, true);
GUI.Style.Apply(textBlock, "", this);
Text = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), Content.RectTransform),
text, textAlignment: textAlignment, wrap: true);
GUI.Style.Apply(Text, "", this);
}
int x = 0;
this.Buttons = new GUIButton[buttons.Length];
var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), Content.RectTransform, Anchor.BottomCenter),
isHorizontal: true, childAnchor: Anchor.BottomLeft)
{
AbsoluteSpacing = 5,
IgnoreLayoutGroups = true
};
Buttons = new List<GUIButton>(buttons.Length);
for (int i = 0; i < buttons.Length; i++)
{
this.Buttons[i] = new GUIButton(new Rectangle(x, 0, 150, 30), buttons[i], Alignment.Left | Alignment.Bottom, "", frame);
x += this.Buttons[i].Rect.Width + 20;
var button = new GUIButton(new RectTransform(new Vector2(Math.Min(0.9f / buttons.Length, 0.5f), 1.0f), buttonContainer.RectTransform, maxSize: new Point(300, 30)), buttons[i]);
Buttons.Add(button);
}
MessageBoxes.Add(this);
}
///// <summary>
///// This is the new constructor.
///// TODO: for some reason the background does not prohibit input on the elements that are behind the box
///// TODO: allow providing buttons in the constructor
///// </summary>
/*public GUIMessageBox(RectTransform rectT, string headerText, string text, Alignment textAlignment = Alignment.TopCenter)
: base(rectT, "")
{
//BackgroundFrame = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), rectT, Anchor.Center), null, Color.Black * 0.5f);
float headerHeight = 0.2f;
float margin = 0.05f;
InnerFrame = new GUIFrame(rectT);
GUI.Style.Apply(InnerFrame, "", this);
Header = null;
if (!string.IsNullOrWhiteSpace(headerText))
{
Header = new GUITextBlock(new RectTransform(new Vector2(1, headerHeight), InnerFrame.RectTransform, Anchor.TopCenter)
{
RelativeOffset = new Vector2(0, margin)
}, headerText, textAlignment: Alignment.Center);
GUI.Style.Apply(Header, "", this);
}
if (!string.IsNullOrWhiteSpace(text))
{
float offset = headerHeight + margin;
var size = Header == null ? Vector2.One : new Vector2(1 - margin * 2, 1 - offset + margin);
Text = new GUITextBlock(new RectTransform(size, InnerFrame.RectTransform, Anchor.TopCenter)
{
RelativeOffset = new Vector2(0, offset)
}, text, textAlignment: textAlignment, wrap: true);
GUI.Style.Apply(Text, "", this);
}
MessageBoxes.Add(this);
}*/
//public override void AddToGUIUpdateList(bool ignoreChildren = false, bool updateLast = false)
//{
// base.AddToGUIUpdateList(ignoreChildren, updateLast);
//}
//public override void Draw(SpriteBatch spriteBatch, bool drawChildren = true)
//{
// if (RectTransform == null)
// {
// base.Draw(spriteBatch, drawChildren);
// }
// else
// {
// // Custom draw order so that the background is rendered behind the parent.
// if (drawChildren)
// {
// BackgroundFrame?.Draw(spriteBatch);
// }
// base.Draw(spriteBatch, false);
// if (drawChildren)
// {
// InnerFrame?.Draw(spriteBatch);
// Header?.Draw(spriteBatch);
// Text?.Draw(spriteBatch);
// Buttons.ForEach(b => b.Draw(spriteBatch));
// }
// }
//}
public void Close()
{
if (parent != null) parent.RemoveChild(this);
if (Parent != null) Parent.RemoveChild(this);
if (MessageBoxes.Contains(this)) MessageBoxes.Remove(this);
}
@@ -99,5 +165,14 @@ namespace Barotrauma
{
MessageBoxes.Clear();
}
/// <summary>
/// Parent does not matter. It's overridden.
/// </summary>
public void AddButton(RectTransform rectT, string text, GUIButton.OnClickedHandler onClick)
{
rectT.Parent = RectTransform;
Buttons.Add(new GUIButton(rectT, text) { OnClicked = onClick });
}
}
}