GUIStyle logic changes: instead of having a predetermined GUIComponentStyle for each type of GUIComponent, any GUIComponent can use any style. The GUIComponent constructors take the name of the style as a parameter, and if no style is specified, the default style for the GUIComponent in question will be used.

This commit is contained in:
Regalis
2017-04-07 22:29:07 +03:00
parent 1fe6427c05
commit 3844dd9dac
54 changed files with 484 additions and 475 deletions

View File

@@ -136,15 +136,15 @@ namespace Barotrauma
if (pauseMenuOpen)
{
pauseMenu = new GUIFrame(new Rectangle(0, 0, 200, 300), null, Alignment.Center, Style);
pauseMenu = new GUIFrame(new Rectangle(0, 0, 200, 300), null, Alignment.Center, "");
int y = 0;
var button = new GUIButton(new Rectangle(0, y, 0, 30), "Resume", Alignment.CenterX, Style, pauseMenu);
var button = new GUIButton(new Rectangle(0, y, 0, 30), "Resume", Alignment.CenterX, "", pauseMenu);
button.OnClicked = TogglePauseMenu;
y += 60;
button = new GUIButton(new Rectangle(0, y, 0, 30), "Settings", Alignment.CenterX, Style, pauseMenu);
button = new GUIButton(new Rectangle(0, y, 0, 30), "Settings", Alignment.CenterX, "", pauseMenu);
button.OnClicked = (btn, userData) =>
{
TogglePauseMenu();
@@ -161,7 +161,7 @@ namespace Barotrauma
SinglePlayerMode spMode = GameMain.GameSession.gameMode as SinglePlayerMode;
if (spMode != null)
{
button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, Style, pauseMenu);
button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, "", pauseMenu);
button.OnClicked += TogglePauseMenu;
button.OnClicked += GameMain.GameSession.LoadPrevious;
@@ -174,7 +174,7 @@ namespace Barotrauma
SinglePlayerMode spMode = GameMain.GameSession.gameMode as SinglePlayerMode;
if (spMode != null)
{
button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, Style, pauseMenu);
button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, "", pauseMenu);
button.OnClicked += QuitClicked;
button.OnClicked += TogglePauseMenu;
button.UserData = "save";
@@ -184,7 +184,7 @@ namespace Barotrauma
}
button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, Style, pauseMenu);
button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, "", pauseMenu);
button.OnClicked += QuitClicked;
button.OnClicked += TogglePauseMenu;
}

View File

@@ -133,29 +133,29 @@ namespace Barotrauma
public bool Selected { get; set; }
public GUIButton(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null)
public GUIButton(Rectangle rect, string text, string style, GUIComponent parent = null)
: this(rect, text, null, Alignment.Left, style, parent)
{
}
public GUIButton(Rectangle rect, string text, Alignment alignment, GUIStyle style, GUIComponent parent = null)
public GUIButton(Rectangle rect, string text, Alignment alignment, string style, GUIComponent parent = null)
: this(rect, text, null, alignment, style, parent)
{
}
public GUIButton(Rectangle rect, string text, Color? color, GUIStyle style, GUIComponent parent = null)
public GUIButton(Rectangle rect, string text, Color? color, string style, GUIComponent parent = null)
: this(rect, text, color, (Alignment.Left | Alignment.Top), style, parent)
{
}
public GUIButton(Rectangle rect, string text, Color? color, Alignment alignment, GUIStyle style, GUIComponent parent = null)
:this(rect, text, color, alignment, Alignment.Center, style, parent)
public GUIButton(Rectangle rect, string text, Color? color, Alignment alignment, string style = "", GUIComponent parent = null)
: this(rect, text, color, alignment, Alignment.Center, style, parent)
{
}
public GUIButton(Rectangle rect, string text, Color? color, Alignment alignment, Alignment textAlignment, GUIStyle style, GUIComponent parent = null)
:base (style)
public GUIButton(Rectangle rect, string text, Color? color, Alignment alignment, Alignment textAlignment, string style = "", GUIComponent parent = null)
: base (style)
{
this.rect = rect;
if (color!=null) this.color = (Color)color;
@@ -164,7 +164,7 @@ namespace Barotrauma
if (parent != null) parent.AddChild(this);
frame = new GUIFrame(Rectangle.Empty, style, this);
if (style != null) style.Apply(frame, this);
GUI.Style.Apply(frame, style, this);
textBlock = new GUITextBlock(Rectangle.Empty, text,
Color.Transparent, (this.style == null) ? Color.Black : this.style.textColor,

View File

@@ -213,7 +213,7 @@ namespace Barotrauma
get { return keyboardDispatcher; }
}
protected GUIComponent(GUIStyle style)
protected GUIComponent(string style)
{
Visible = true;
@@ -228,7 +228,8 @@ namespace Barotrauma
CanBeFocused = true;
if (style!=null) style.Apply(this);
if (style != null)
GUI.Style.Apply(this, style);
}
public static void Init(GameWindow window)
@@ -294,7 +295,7 @@ namespace Barotrauma
if (currColor.A>0.0f && !sprites.Any()) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
if (sprites != null)
if (sprites != null && currColor.A > 0.0f)
{
foreach (UISprite uiSprite in sprites)
{
@@ -372,7 +373,7 @@ namespace Barotrauma
int width = 400;
if (toolTipBlock==null || (string)toolTipBlock.userData != ToolTip)
{
toolTipBlock = new GUITextBlock(new Rectangle(0,0,width, 18), ToolTip, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, null, true, GUI.SmallFont);
toolTipBlock = new GUITextBlock(new Rectangle(0,0,width, 18), ToolTip, "", Alignment.TopLeft, Alignment.TopLeft, null, true, GUI.SmallFont);
toolTipBlock.padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
toolTipBlock.rect.Width = (int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).X + 20);
toolTipBlock.rect.Height = toolTipBlock.WrappedText.Split('\n').Length * 18;

View File

@@ -74,7 +74,7 @@ namespace Barotrauma
}
}
public GUIDropDown(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null)
public GUIDropDown(Rectangle rect, string text, string style, GUIComponent parent = null)
: base(style)
{
this.rect = rect;
@@ -101,7 +101,7 @@ namespace Barotrauma
public void AddItem(string text, object userData = null)
{
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, GUI.Style, listBox);
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, "", listBox);
textBlock.UserData = userData;
}

View File

@@ -5,18 +5,18 @@ namespace Barotrauma
{
public class GUIFrame : GUIComponent
{
public GUIFrame(Rectangle rect, GUIStyle style = null, GUIComponent parent = null)
public GUIFrame(Rectangle rect, string style = "", GUIComponent parent = null)
: this(rect, null, (Alignment.Left | Alignment.Top), style, parent)
{
}
public GUIFrame(Rectangle rect, Color color, GUIStyle style = null, GUIComponent parent = null)
public GUIFrame(Rectangle rect, Color color, string style = "", GUIComponent parent = null)
: this(rect, color, (Alignment.Left | Alignment.Top), style, parent)
{
}
public GUIFrame(Rectangle rect, Color? color, Alignment alignment, GUIStyle style = null, GUIComponent parent = null)
public GUIFrame(Rectangle rect, Color? color, Alignment alignment, string style = "", GUIComponent parent = null)
: base(style)
{
this.rect = rect;

View File

@@ -107,22 +107,22 @@ namespace Barotrauma
}
}
public GUIListBox(Rectangle rect, GUIStyle style, GUIComponent parent = null)
public GUIListBox(Rectangle rect, string style, GUIComponent parent = null)
: this(rect, style, Alignment.TopLeft, parent)
{
}
public GUIListBox(Rectangle rect, GUIStyle style, Alignment alignment, GUIComponent parent = null)
public GUIListBox(Rectangle rect, string style, Alignment alignment, GUIComponent parent = null)
: this(rect, null, alignment, style, parent, false)
{
}
public GUIListBox(Rectangle rect, Color? color, GUIStyle style = null, GUIComponent parent = null)
public GUIListBox(Rectangle rect, Color? color, string style = null, GUIComponent parent = null)
: this(rect, color, (Alignment.Left | Alignment.Top), style, parent)
{
}
public GUIListBox(Rectangle rect, Color? color, Alignment alignment, GUIStyle style = null, GUIComponent parent = null, bool isHorizontal = false)
public GUIListBox(Rectangle rect, Color? color, Alignment alignment, string style = null, GUIComponent parent = null, bool isHorizontal = false)
: base(style)
{
this.rect = rect;
@@ -140,18 +140,18 @@ namespace Barotrauma
if (isHorizontal)
{
scrollBar = new GUIScrollBar(
new Rectangle(this.rect.X, this.rect.Bottom - 20, this.rect.Width, 20), null, 1.0f, GUI.Style);
new Rectangle(this.rect.X, this.rect.Bottom - 20, this.rect.Width, 20), null, 1.0f, "");
}
else
{
scrollBar = new GUIScrollBar(
new Rectangle(this.rect.Right - 20, this.rect.Y, 20, this.rect.Height), null, 1.0f, GUI.Style);
new Rectangle(this.rect.Right - 20, this.rect.Y, 20, this.rect.Height), null, 1.0f, "");
}
scrollBar.IsHorizontal = isHorizontal;
frame = new GUIFrame(Rectangle.Empty, style, this);
if (style != null) style.Apply(frame, this);
GUI.Style.Apply(frame, "", this);
UpdateScrollBarSize();

View File

@@ -53,20 +53,20 @@ namespace Barotrauma
height += 220;
}
var frame = new GUIFrame(new Rectangle(0,0,width,height), null, Alignment.Center, GUI.Style, this);
var frame = new GUIFrame(new Rectangle(0,0,width,height), null, Alignment.Center, "", this);
new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, GUI.Style, frame, true);
new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, "", frame, true);
if (!string.IsNullOrWhiteSpace(text))
{
new GUITextBlock(new Rectangle(0, 30, 0, height - 70), text,
Color.Transparent, Color.White, textAlignment, GUI.Style, frame, true);
Color.Transparent, Color.White, textAlignment, "", frame, true);
}
int x = 0;
this.Buttons = new 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, GUI.Style, frame);
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;
}

View File

@@ -43,7 +43,7 @@ namespace Barotrauma
}
public GUIProgressBar(Rectangle rect, Color color, GUIStyle style, float barSize, Alignment alignment, GUIComponent parent = null)
public GUIProgressBar(Rectangle rect, Color color, string style, float barSize, Alignment alignment, GUIComponent parent = null)
: base(style)
{
this.rect = rect;
@@ -61,8 +61,6 @@ namespace Barotrauma
this.barSize = barSize;
UpdateRect();
if (style != null) style.Apply(this);
}
public override void ApplyStyle(GUIComponentStyle style)

View File

@@ -88,18 +88,18 @@ namespace Barotrauma
}
}
public GUIScrollBar(Rectangle rect, GUIStyle style, float barSize, GUIComponent parent = null)
public GUIScrollBar(Rectangle rect, string style, float barSize, GUIComponent parent = null)
: this(rect, null, barSize, style, parent)
{
}
public GUIScrollBar(Rectangle rect, Color? color, float barSize, GUIStyle style = null, GUIComponent parent = null)
public GUIScrollBar(Rectangle rect, Color? color, float barSize, string style = "", GUIComponent parent = null)
: this(rect, color, barSize, Alignment.TopLeft, style, parent)
{
}
public GUIScrollBar(Rectangle rect, Color? color, float barSize, Alignment alignment, GUIStyle style = null, GUIComponent parent = null)
public GUIScrollBar(Rectangle rect, Color? color, float barSize, Alignment alignment, string style = "", GUIComponent parent = null)
: base(style)
{
this.rect = rect;
@@ -118,7 +118,7 @@ namespace Barotrauma
this.barSize = barSize;
bar = new GUIButton(new Rectangle(0, 0, 0, 0), "", color, style, this);
bar = new GUIButton(new Rectangle(0, 0, 0, 0), "", color, "", this);
bar.OnPressed = SelectBar;
//AddChild(bar);

View File

@@ -10,7 +10,6 @@ namespace Barotrauma
public GUIStyle(string file)
{
componentStyles = new Dictionary<string, GUIComponentStyle>();
XDocument doc;
@@ -32,15 +31,18 @@ namespace Barotrauma
}
}
public void Apply(GUIComponent targetComponent, GUIComponent parent = null)
public void Apply(GUIComponent targetComponent, string styleName = "", GUIComponent parent = null)
{
GUIComponentStyle componentStyle = null;
string name = (parent == null) ? targetComponent.GetType().Name.ToLowerInvariant() : parent.GetType().Name.ToLowerInvariant();
componentStyles.TryGetValue(name, out componentStyle);
if (componentStyle==null)
if (string.IsNullOrEmpty(styleName))
{
DebugConsole.ThrowError("Couldn't find a GUI style for "+targetComponent.GetType().Name);
styleName = parent == null ? targetComponent.GetType().Name.ToLowerInvariant() : parent.GetType().Name.ToLowerInvariant();
}
GUIComponentStyle componentStyle = null;
if (!componentStyles.TryGetValue(styleName, out componentStyle))
{
DebugConsole.ThrowError("Couldn't find a GUI style \""+ styleName+"\"");
return;
}

View File

@@ -125,18 +125,18 @@ namespace Barotrauma
get { return caretPos; }
}
public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent, ScalableFont font)
public GUITextBlock(Rectangle rect, string text, string style, GUIComponent parent, ScalableFont font)
: this(rect, text, style, Alignment.TopLeft, Alignment.TopLeft, parent, false, font)
{
}
public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null, bool wrap = false)
public GUITextBlock(Rectangle rect, string text, string style, GUIComponent parent = null, bool wrap = false)
: this(rect, text, style, Alignment.TopLeft, Alignment.TopLeft, parent, wrap)
{
}
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment textAlignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null, bool wrap = false)
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null, bool wrap = false)
: this(rect, text,color, textColor, Alignment.TopLeft, textAlignment, style, parent, wrap)
{
}
@@ -156,15 +156,15 @@ namespace Barotrauma
}
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null, bool wrap = false)
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null, bool wrap = false)
: this (rect, text, style, alignment, textAlignment, parent, wrap, null)
{
if (color != null) this.color = (Color)color;
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, ScalableFont font = null)
:base (style)
public GUITextBlock(Rectangle rect, string text, string 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;
@@ -278,7 +278,7 @@ namespace Barotrauma
Rectangle drawRect = rect;
if (offset != Vector2.Zero) drawRect.Location += offset.ToPoint();
if (currColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
//if (currColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
base.Draw(spriteBatch);

View File

@@ -152,19 +152,19 @@ namespace Barotrauma
}
}
public GUITextBox(Rectangle rect, GUIStyle style = null, GUIComponent parent = null)
public GUITextBox(Rectangle rect, string style = null, GUIComponent parent = null)
: this(rect, null, null, Alignment.Left, Alignment.Left, style, parent)
{
}
public GUITextBox(Rectangle rect, Alignment alignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null)
public GUITextBox(Rectangle rect, Alignment alignment = Alignment.Left, string style = null, GUIComponent parent = null)
: this(rect, null, null, alignment, Alignment.Left, style, parent)
{
}
public GUITextBox(Rectangle rect, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null)
public GUITextBox(Rectangle rect, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null)
: base(style)
{
Enabled = true;
@@ -184,7 +184,7 @@ namespace Barotrauma
Font = GUI.Font;
if (style != null) style.Apply(textBlock, this);
GUI.Style.Apply(textBlock, "", this);
textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f);
//previousMouse = PlayerInput.GetMouseState;

View File

@@ -71,13 +71,15 @@ namespace Barotrauma
if (parent != null)
parent.AddChild(this);
box = new GUIFrame(rect, Color.DarkGray, null, this);
box = new GUIFrame(rect, Color.DarkGray, "", this);
box.HoverColor = Color.Gray;
box.SelectedColor = Color.DarkGray;
box.CanBeFocused = false;
text = new GUITextBlock(new Rectangle(rect.Right + 10, rect.Y+2, 20, rect.Height), label, GUI.Style, this, font);
GUI.Style.Apply(box, "", this);
text = new GUITextBlock(new Rectangle(rect.Right + 10, rect.Y+2, 20, rect.Height), label, "", this, font);
this.rect = new Rectangle(box.Rect.X, box.Rect.Y, 240, rect.Height);
Enabled = true;