- Sliced sprites are scaled instead of tiling (so they work properly even if the UI element is smaller than the sprite)

- Option to use separate sprites for different states of a GUIComponent (e.g. hovered/pressed button)
- Option to configure "child styles" for the individual elements of a GUIComponent (e.g. the background frame and the handle of a scroll bar)
This commit is contained in:
Regalis
2017-04-08 22:22:53 +03:00
parent 3844dd9dac
commit 34f0ae39b6
18 changed files with 296 additions and 182 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 560 KiB

After

Width:  |  Height:  |  Size: 405 KiB

+148 -36
View File
@@ -3,74 +3,169 @@
<GUIFrame
padding="40.0, 40.0, 40.0, 40.0"
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="0.0, 0.0, 0.0, 1.0"
hovercolor="0.8, 0.8, 0.8, 1.0"
selectedcolor="1.0, 0.82, 0.05, 1.0">
textcolor="0.0, 0.0, 0.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="32, 541, 420, 454" slice="87,576,430,960"/>
</GUIFrame>
<GUIFrameTop
padding="40.0, 40.0, 40.0, 40.0"
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="0.0, 0.0, 0.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="32, 576, 420, 454" slice="87,578,430,960"/>
</GUIFrameTop>
<GUIFrameLeft
padding="40.0, 40.0, 40.0, 40.0"
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="0.0, 0.0, 0.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="87, 541, 365, 454" slice="88,576,430,960"/>
</GUIFrameLeft>
<GUIFrameRight
padding="40.0, 40.0, 40.0, 40.0"
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="0.0, 0.0, 0.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="32, 541, 395, 454" slice="87,576,430,960"/>
</GUIFrameRight>
<InnerFrame
padding="40.0, 40.0, 40.0, 40.0"
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="0.0, 0.0, 0.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="466, 660, 275, 166" slice="472,666,737,820"/>
</InnerFrame>
<GUIButton
color="1.0,1.0,1.0,1.0"
textcolor="1.0, 1.0, 1.0, 1.0"
hovercolor="0.88, 0.25, 0.15, 1.0"
selectedcolor="1.0, 0.0, 0.0, 1.0">
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0">
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="888, 91, 129, 41" slice="897, 98, 1009, 125"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="None" sourcerect ="683, 74, 129, 41" slice="687, 78, 808, 109"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Hover" sourcerect ="888, 91, 129, 41" slice="897, 98, 1009, 125"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Selected" sourcerect ="553, 74, 129, 41" slice="557, 78, 676, 109"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Pressed" sourcerect ="553, 74, 129, 41" slice="557, 78, 676, 109"/>
<GUITextBlock
textcolor="0.6, 0.65, 0.7, 1.0"
padding="10.0, 0.0, 10.0, 0.0"/>
</GUIButton>
<GUIButtonLarge
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="1.0, 1.0, 1.0, 1.0"
hovercolor="0.88, 0.25, 0.15, 1.0"
selectedcolor="1.0, 0.0, 0.0, 1.0">
textcolor="1.0, 1.0, 1.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="13, 667, 220, 59" slice="27, 673, 226, 718"/>
</GUIButtonLarge>
<GUITextBlock
textcolor="1.0, 1.0, 1.0, 1.0"
textcolor="0.5, 0.55, 0.6, 1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
padding="10.0, 0.0, 10.0, 0.0">
<Sprite texture="Content/UI/UI_Atlas.png" state="Hover" sourcerect ="474, 544, 266, 52" slice="480, 552, 731, 584"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Selected" sourcerect ="474, 544, 266, 52" slice="480, 552, 731, 584"/>
</GUITextBlock>
<GUIToolTip
textcolor="0.5, 0.55, 0.6, 1.0"
color="1.0,1.0,1.0,0.85"
hovercolor="0.3, 0.3, 0.3, 0.5"
selectedcolor="1.0, 0.6, 0.0, 0.3"
padding="10.0, 0.0, 10.0, 0.0"/>
padding="10.0, 0.0, 10.0, 0.0">
<Sprite texture="Content/UI/UI_Atlas.png" state="None" sourcerect ="746, 704, 120, 120" slice="754, 711, 865, 816"/>
</GUIToolTip>
<GUIListBox
color="0.0, 0.0, 0.0, 1.0"
color="1.0, 1.0, 1.0, 1.0"
textcolor="1.0, 1.0, 1.0, 1.0"
outlinecolor="0.5, 0.57, 0.6, 1.0">
<GUIFrame
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="1.0, 1.0, 1.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="466, 660, 275, 166" slice="472,666,737,820"/>
</GUIFrame>
</GUIListBox>
<GUIScrollBar
color="0.88, 0.25, 0.15, 0.8"
textcolor="1.0, 1.0, 1.0, 1.0"
outlinecolor="0.5, 0.57, 0.6, 1.0">
<Sprite texture="Content/UI/uiBackground.png" size="0.0, 0.0"/>
<GUIScrollBar>
<GUIFrame
color="1.0,1.0,1.0,1.0"
textcolor="1.0, 1.0, 1.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect="986, 874, 11, 148" slice="988, 881, 995, 1014"/>
</GUIFrame>
<GUIButton
color="0.88, 0.25, 0.15, 0.8"
textcolor="1.0, 1.0, 1.0, 1.0"
outlinecolor="0.5, 0.57, 0.6, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" state="Hover" sourcerect="950, 806, 9, 47" slice="953, 810, 956, 849"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="None" sourcerect="843, 350, 9, 47" slice="846, 354, 849, 391"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Pressed" sourcerect="843, 350, 9, 47" slice="846, 354, 849, 391"/>
</GUIButton>
</GUIScrollBar>
<GUIDropDown
color="0.3, 0.3, 0.3, 1.0"
textcolor="1.0, 1.0, 1.0, 1.0"
outlinecolor="0.5, 0.57, 0.6, 1.0">
<Sprite texture="Content/UI/uiBackground.png" size="0.0, 0.0"/>
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="0.5, 0.55, 0.6, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" state="None" sourcerect ="470, 599, 274, 52" slice="480, 610, 731, 640"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Hover" sourcerect ="470, 544, 274, 52" slice="480, 552, 731, 584"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Selected" sourcerect ="470, 544, 274, 52" slice="480, 552, 731, 584"/>
</GUIDropDown>
<GUITextBox
color="1.0, 1.0, 1.0, 1.0"
hovercolor="0.5, 0.5, 0.5, 0.7"
textcolor="1.0, 1.0, 1.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="494, 574, 332, 51" slice="497, 578, 823, 620"/>
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0"
textcolor="0.5, 0.55, 0.6, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" state="None" sourcerect ="470, 599, 274, 52" slice="480, 610, 731, 640"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Hover" sourcerect ="470, 544, 274, 52" slice="480, 552, 731, 584"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Selected" sourcerect ="470, 544, 274, 52" slice="480, 552, 731, 584"/>
</GUITextBox>
<GUITickBox
color="1.0, 1.0, 1.0, 1.0">
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="992, 814, 21, 22" slice="995, 817, 1008, 830"/>
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0" >
<Sprite texture="Content/UI/UI_Atlas.png" state="None" sourcerect ="991, 846, 23, 23" slice="997, 852, 1006, 862"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Pressed" sourcerect ="991, 846, 23, 23" slice="997, 852, 1006, 862"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Hover" sourcerect ="991, 813, 23, 23" slice="997, 818, 1006, 828"/>
<Sprite texture="Content/UI/UI_Atlas.png" state="Selected" sourcerect ="489, 943, 23, 23" slice="494, 947, 506, 960"/>
<GUITextBlock
textcolor="0.5, 0.55, 0.6, 1.0"
hovercolor="0.3, 0.3, 0.3, 0.5"
selectedcolor="1.0, 0.6, 0.0, 0.3"
padding="10.0, 0.0, 10.0, 0.0"/>
</GUITickBox>
<GUIMessageBox
@@ -88,13 +183,30 @@
</GUIMessageBox>
<GUIProgressBar
padding="5.0, 5.0, 5.0, 5.0"
padding="0.0, 0.0, 0.0, 0.0"
color="0.0, 0.0, 0.0, 0.5"
hovercolor="0.0, 0.0, 0.0, 0.5"
selectedcolor="0.0, 0.0, 0.0, 0.5"
outlinecolor="0.5, 0.57, 0.6, 1.0">
<GUIFrame
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0">
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="28, 430, 875, 49" slice="43,436,888,472"/>
</GUIFrame>
<Slider
color="1.0,1.0,1.0,1.0"
hovercolor="1.0,1.0,1.0,1.0"
selectedcolor="1.0,1.0,1.0,1.0">
<Sprite texture="Content/UI/UI_Atlas.png" tile="false" sourcerect ="0, 276, 859, 37"/>
</Slider>
</GUIProgressBar>
</style>
+18 -3
View File
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@@ -57,14 +58,21 @@ namespace Barotrauma
public readonly Color OutlineColor;
public readonly List<UISprite> Sprites;
public readonly Dictionary<GUIComponent.ComponentState, List<UISprite>> Sprites;
public readonly bool TileSprites;
public Dictionary<string, GUIComponentStyle> ChildStyles;
public GUIComponentStyle(XElement element)
{
Sprites = new List<UISprite>();
Sprites = new Dictionary<GUIComponent.ComponentState, List<UISprite>>();
foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
{
Sprites[state] = new List<UISprite>();
}
ChildStyles = new Dictionary<string, GUIComponentStyle>();
Padding = ToolBox.GetAttributeVector4(element, "padding", Vector4.Zero);
@@ -92,6 +100,10 @@ namespace Barotrauma
bool maintainAspect = ToolBox.GetAttributeBool(subElement, "maintainaspectratio",false);
bool tile = ToolBox.GetAttributeBool(subElement, "tile", true);
string stateStr = ToolBox.GetAttributeString(subElement, "state", "None");
GUIComponent.ComponentState spriteState = GUIComponent.ComponentState.None;
Enum.TryParse(stateStr, out spriteState);
UISprite newSprite = new UISprite(sprite, tile, maintainAspect);
Vector4 sliceVec = ToolBox.GetAttributeVector4(subElement, "slice", Vector4.Zero);
@@ -125,7 +137,10 @@ namespace Barotrauma
newSprite.Slices[8] = new Rectangle(newSprite.Slices[2].X, slice.Bottom, newSprite.Slices[2].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
}
Sprites.Add(newSprite);
Sprites[spriteState].Add(newSprite);
break;
default:
ChildStyles.Add(subElement.Name.ToString().ToLowerInvariant(), new GUIComponentStyle(subElement));
break;
}
}
+4 -5
View File
@@ -1,7 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
@@ -10,10 +9,10 @@ namespace Barotrauma
[Flags]
public enum Alignment
{
CenterX = 1, Left = 2, Right = 4, CenterY = 8, Top = 16, Bottom = 32 ,
TopRight = (Top | Right), TopLeft = (Top | Left), TopCenter = (CenterX | Top),
Center = (CenterX | CenterY),
BottomRight = (Bottom | Right), BottomLeft = (Bottom | Left), BottomCenter = (CenterX | Bottom)
CenterX = 1, Left = 2, Right = 4, CenterY = 8, Top = 16, Bottom = 32,
TopLeft = (Top | Left), TopCenter = (CenterX | Top), TopRight = (Top | Right),
CenterLeft = (Left | CenterY), Center = (CenterX | CenterY), CenterRight = (Right | CenterY),
BottomLeft = (Bottom | Left), BottomCenter = (CenterX | Bottom), BottomRight = (Bottom | Right),
}
public enum GUISoundType
+8 -19
View File
@@ -155,41 +155,30 @@ namespace Barotrauma
}
public GUIButton(Rectangle rect, string text, Color? color, Alignment alignment, Alignment textAlignment, string style = "", GUIComponent parent = null)
: base (style)
: base(style)
{
this.rect = rect;
if (color!=null) this.color = (Color)color;
if (color != null) this.color = (Color)color;
this.alignment = alignment;
if (parent != null) parent.AddChild(this);
frame = new GUIFrame(Rectangle.Empty, style, this);
GUI.Style.Apply(frame, style, this);
GUI.Style.Apply(frame, style == "" ? "GUIButton" : style);
textBlock = new GUITextBlock(Rectangle.Empty, text,
Color.Transparent, (this.style == null) ? Color.Black : this.style.textColor,
textAlignment, style, this);
textAlignment, null, this);
GUI.Style.Apply(textBlock, style, this);
Enabled = true;
}
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
//Color currColor = color;
//if (state == ComponentState.Hover) currColor = hoverColor;
//if (state == ComponentState.Selected) currColor = selectedColor;
//GUI.DrawRectangle(spriteBatch, rect, currColor * alpha, true);
////spriteBatch.DrawString(HUD.font, text, new Vector2(rect.X+rect.Width/2, rect.Y+rect.Height/2), Color.Black, 0.0f, new Vector2(0.5f,0.5f), 1.0f, SpriteEffects.None, 0.0f);
//GUI.DrawRectangle(spriteBatch, rect, Color.Black * alpha, false);
DrawChildren(spriteBatch);
//if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true);
}
public override void Update(float deltaTime)
@@ -203,7 +192,7 @@ namespace Barotrauma
{
if (OnPressed != null)
{
if (OnPressed()) state = ComponentState.Selected;
if (OnPressed()) state = ComponentState.Pressed;
}
}
else if (PlayerInput.LeftButtonClicked())
+25 -29
View File
@@ -73,7 +73,7 @@ namespace Barotrauma
protected static KeyboardDispatcher keyboardDispatcher;
public enum ComponentState { None, Hover, Selected};
public enum ComponentState { None, Hover, Pressed, Selected };
protected Alignment alignment;
@@ -119,7 +119,7 @@ namespace Barotrauma
public bool TileSprites;
private GUITextBlock toolTipBlock;
private static GUITextBlock toolTipBlock;
//protected float alpha;
@@ -161,7 +161,7 @@ namespace Barotrauma
get { return CanBeFocused ? rect : Rectangle.Empty; }
}
public List<UISprite> sprites;
public Dictionary<GUIComponent.ComponentState, List<UISprite>> sprites;
//public Alignment SpriteAlignment { get; set; }
//public bool RepeatSpriteX, RepeatSpriteY;
@@ -222,8 +222,7 @@ namespace Barotrauma
OutlineColor = Color.Transparent;
Font = GUI.Font;
sprites = new List<UISprite>();
children = new List<GUIComponent>();
CanBeFocused = true;
@@ -286,42 +285,38 @@ namespace Barotrauma
if (state == ComponentState.Selected) currColor = selectedColor;
if (state == ComponentState.Hover) currColor = hoverColor;
if (flashTimer>0.0f)
if (flashTimer > 0.0f)
{
GUI.DrawRectangle(spriteBatch,
new Rectangle(rect.X-5,rect.Y-5,rect.Width+10,rect.Height+10),
GUI.DrawRectangle(spriteBatch,
new Rectangle(rect.X - 5, rect.Y - 5, rect.Width + 10, rect.Height + 10),
flashColor * (flashTimer / FlashDuration), true);
}
if (currColor.A>0.0f && !sprites.Any()) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
if (currColor.A > 0.0f && (sprites == null || !sprites.Any())) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
if (sprites != null && currColor.A > 0.0f)
if (sprites != null && sprites[state] != null && currColor.A > 0.0f)
{
foreach (UISprite uiSprite in sprites)
foreach (UISprite uiSprite in sprites[state])
{
if (uiSprite.Slice)
{
Vector2 pos = new Vector2(rect.X, rect.Y);
int centerWidth = rect.Width - uiSprite.Slices[0].Width - uiSprite.Slices[2].Width;
int centerHeight = rect.Height - uiSprite.Slices[0].Height - uiSprite.Slices[8].Height;
int centerWidth = Math.Max(rect.Width - uiSprite.Slices[0].Width - uiSprite.Slices[2].Width, 0);
int centerHeight = Math.Max(rect.Height - uiSprite.Slices[0].Height - uiSprite.Slices[8].Height, 0);
for (int x = 0; x<3; x++)
for (int x = 0; x < 3; x++)
{
int width = x == 1 ? centerWidth : uiSprite.Slices[x].Width;
for (int y = 0; y<3; y++)
for (int y = 0; y < 3; y++)
{
int height = y == 1 ? centerHeight : uiSprite.Slices[x + y * 3].Height;
//GUI.DrawString(spriteBatch, pos, x + ", " + y, Color.White);
uiSprite.Sprite.DrawTiled(
spriteBatch,
pos,
new Vector2(width, height),
Vector2.Zero,
spriteBatch.Draw(uiSprite.Sprite.Texture,
new Rectangle((int)pos.X, (int)pos.Y, width, height),
uiSprite.Slices[x + y * 3],
currColor * (currColor.A / 255.0f));
pos.Y += height;
}
pos.X += width;
@@ -366,18 +361,17 @@ namespace Barotrauma
//DrawChildren(spriteBatch);
}
public void DrawToolTip(SpriteBatch spriteBatch)
public void DrawToolTip(SpriteBatch spriteBatch)
{
if (!Visible) return;
int width = 400;
if (toolTipBlock==null || (string)toolTipBlock.userData != ToolTip)
if (toolTipBlock == null || (string)toolTipBlock.userData != ToolTip)
{
toolTipBlock = new GUITextBlock(new Rectangle(0,0,width, 18), ToolTip, "", Alignment.TopLeft, Alignment.TopLeft, null, true, GUI.SmallFont);
toolTipBlock = new GUITextBlock(new Rectangle(0, 0, width, 18), ToolTip, "GUIToolTip", 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;
toolTipBlock.Color = Color.Black * 0.7f;
toolTipBlock.rect.Height = toolTipBlock.WrappedText.Split('\n').Length * 18 + 7;
toolTipBlock.userData = ToolTip;
}
@@ -468,13 +462,15 @@ namespace Barotrauma
}
public virtual void ApplyStyle(GUIComponentStyle style)
{
{
if (style == null) return;
color = style.Color;
hoverColor = style.HoverColor;
selectedColor = style.SelectedColor;
padding = style.Padding;
sprites = new List<UISprite>(style.Sprites);
sprites = style.Sprites;
OutlineColor = style.OutlineColor;
+3 -7
View File
@@ -81,17 +81,13 @@ namespace Barotrauma
if (parent != null) parent.AddChild(this);
button = new GUIButton(this.rect, text, Color.White, Alignment.TopLeft, Alignment.TopLeft, null, null);
button.TextColor = Color.White;
button.Color = Color.Black * 0.8f;
button.HoverColor = Color.DarkGray * 0.8f;
button.OutlineColor = Color.LightGray * 0.8f;
button = new GUIButton(this.rect, text, Color.White, Alignment.TopLeft, Alignment.CenterLeft, "GUIDropDown", null);
GUI.Style.Apply(button, style, this);
button.OnClicked = OnClicked;
listBox = new GUIListBox(new Rectangle(this.rect.X, this.rect.Bottom, this.rect.Width, 200), style, null);
listBox.OnSelected = SelectItem;
//listBox.ScrollBarEnabled = false;
}
public override void AddChild(GUIComponent child)
+1 -1
View File
@@ -45,7 +45,7 @@ namespace Barotrauma
if (state == ComponentState.Selected) currColor = selectedColor;
if (state == ComponentState.Hover) currColor = hoverColor;
if (!sprites.Any()) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A/255.0f), true);
if (sprites == null || !sprites.Any()) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A/255.0f), true);
base.Draw(spriteBatch);
if (OutlineColor != Color.Transparent)
+16 -12
View File
@@ -26,21 +26,21 @@ namespace Barotrauma
set { (children[0].children[1] as GUITextBlock).Text = value; }
}
public GUIMessageBox(string header, string text)
: this(header, text, new string[] {"OK"})
public GUIMessageBox(string headerText, string text)
: this(headerText, text, new string[] {"OK"})
{
this.Buttons[0].OnClicked = Close;
}
public GUIMessageBox(string header, string text, int width, int height)
: this(header, text, new string[] { "OK" }, width, height)
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 header, string text, string[] buttons, int width=DefaultWidth, int height=DefaultHeight, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null)
: base(new Rectangle(0,0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
Color.Black*0.5f, Alignment.TopLeft, null, parent)
public GUIMessageBox(string headerText, string text, string[] buttons, int width = DefaultWidth, int height = DefaultHeight, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null)
: base(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
Color.Black * 0.5f, Alignment.TopLeft, null, parent)
{
if (height == 0)
{
@@ -53,13 +53,17 @@ namespace Barotrauma
height += 220;
}
var frame = new GUIFrame(new Rectangle(0,0,width,height), null, Alignment.Center, "", this);
var frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, "", this);
GUI.Style.Apply(frame, "", this);
var header = new GUITextBlock(new Rectangle(0, 0, 0, 30), headerText, null, null, textAlignment, "", frame, true);
GUI.Style.Apply(header, "", this);
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, "", frame, true);
var textBlock = new GUITextBlock(new Rectangle(0, 30, 0, height - 70), text,
null, null, textAlignment, "", frame, true);
GUI.Style.Apply(textBlock, "", this);
}
int x = 0;
+19 -19
View File
@@ -7,11 +7,9 @@ namespace Barotrauma
{
private bool isHorizontal;
private GUIFrame frame;
private GUIFrame frame, slider;
private float barSize;
private int margin;
public delegate float ProgressGetterHandler();
public ProgressGetterHandler ProgressGetter;
@@ -24,23 +22,23 @@ namespace Barotrauma
public float BarSize
{
get { return barSize; }
set
set
{
float oldBarSize = barSize;
barSize = MathHelper.Clamp(value, 0.0f, 1.0f);
if (barSize!=oldBarSize) UpdateRect();
if (barSize != oldBarSize) UpdateRect();
}
}
public GUIProgressBar(Rectangle rect, Color color, float barSize, GUIComponent parent = null)
: this(rect,color,barSize, (Alignment.Left | Alignment.Top), parent)
: this(rect, color, barSize, (Alignment.Left | Alignment.Top), parent)
{
}
public GUIProgressBar(Rectangle rect, Color color, float barSize, Alignment alignment, GUIComponent parent = null)
: this(rect,color,null, barSize,alignment, parent)
: this(rect, color, null, barSize, alignment, parent)
{
}
public GUIProgressBar(Rectangle rect, Color color, string style, float barSize, Alignment alignment, GUIComponent parent = null)
@@ -51,19 +49,21 @@ namespace Barotrauma
isHorizontal = (rect.Width > rect.Height);
this.alignment = alignment;
margin = 5;
if (parent != null)
parent.AddChild(this);
frame = new GUIFrame(new Rectangle(0, 0, 0, 0), Color.Black, null, this);
frame = new GUIFrame(new Rectangle(0, 0, 0, 0), null, this);
GUI.Style.Apply(frame, "", this);
slider = new GUIFrame(new Rectangle(0, 0, 0, 0), null, this);
GUI.Style.Apply(slider, "Slider", this);
this.barSize = barSize;
UpdateRect();
}
public override void ApplyStyle(GUIComponentStyle style)
/*public override void ApplyStyle(GUIComponentStyle style)
{
if (frame == null) return;
@@ -76,15 +76,15 @@ namespace Barotrauma
frame.OutlineColor = style.OutlineColor;
this.style = style;
}
}*/
private void UpdateRect()
{
rect = new Rectangle(
slider.Rect = new Rectangle(
(int)(frame.Rect.X + padding.X),
(int)(frame.Rect.Y + padding.Y),
isHorizontal ? (int)((frame.Rect.Width - padding.X - padding.Z) * barSize) : (frame.Rect.Width - margin * 2),
isHorizontal ? (int)(frame.Rect.Height - padding.Y - padding.W) : (int)((frame.Rect.Height - margin * 2) * barSize));
isHorizontal ? (int)((frame.Rect.Width - padding.X - padding.Z) * barSize) : frame.Rect.Width,
isHorizontal ? (int)(frame.Rect.Height - padding.Y - padding.W) : (int)(frame.Rect.Height * barSize));
}
public override void Draw(SpriteBatch spriteBatch)
@@ -95,7 +95,7 @@ namespace Barotrauma
DrawChildren(spriteBatch);
GUI.DrawRectangle(spriteBatch, rect, color * (color.A / 255.0f), true);
//GUI.DrawRectangle(spriteBatch, rect, color * (color.A / 255.0f), true);
}
}
+1
View File
@@ -112,6 +112,7 @@ namespace Barotrauma
isHorizontal = (rect.Width > rect.Height);
frame = new GUIFrame(new Rectangle(0,0,0,0), Color.Black*0.8f, style, this);
GUI.Style.Apply(frame, "", this);
//AddChild(frame);
//System.Diagnostics.Debug.WriteLine(frame.rect);
+24 -11
View File
@@ -33,22 +33,35 @@ namespace Barotrauma
public void Apply(GUIComponent targetComponent, string styleName = "", GUIComponent parent = null)
{
if (string.IsNullOrEmpty(styleName))
GUIComponentStyle componentStyle = null;
if (parent != null)
{
styleName = parent == null ? targetComponent.GetType().Name.ToLowerInvariant() : parent.GetType().Name.ToLowerInvariant();
string parentStyleName = parent.GetType().Name.ToLowerInvariant();
GUIComponentStyle parentStyle = null;
if (!componentStyles.TryGetValue(parentStyleName, out parentStyle))
{
DebugConsole.ThrowError("Couldn't find a GUI style \""+ parentStyleName + "\"");
return;
}
string childStyleName = string.IsNullOrEmpty(styleName) ? targetComponent.GetType().Name : styleName;
parentStyle.ChildStyles.TryGetValue(childStyleName.ToLowerInvariant(), out componentStyle);
}
GUIComponentStyle componentStyle = null;
if (!componentStyles.TryGetValue(styleName, out componentStyle))
else
{
DebugConsole.ThrowError("Couldn't find a GUI style \""+ styleName+"\"");
return;
if (string.IsNullOrEmpty(styleName))
{
styleName = targetComponent.GetType().Name;
}
if (!componentStyles.TryGetValue(styleName.ToLowerInvariant(), out componentStyle))
{
DebugConsole.ThrowError("Couldn't find a GUI style \""+ styleName+"\"");
return;
}
}
targetComponent.ApplyStyle(componentStyle);
}
}
}
+3
View File
@@ -150,6 +150,7 @@ namespace Barotrauma
public override void ApplyStyle(GUIComponentStyle style)
{
if (style == null) return;
base.ApplyStyle(style);
textColor = style.textColor;
@@ -174,6 +175,8 @@ namespace Barotrauma
this.alignment = alignment;
this.padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
this.textAlignment = textAlignment;
if (parent != null)
+1 -1
View File
@@ -184,7 +184,7 @@ namespace Barotrauma
Font = GUI.Font;
GUI.Style.Apply(textBlock, "", this);
GUI.Style.Apply(textBlock, style == "" ? "GUITextBox" : style);
textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f);
//previousMouse = PlayerInput.GetMouseState;
+10 -24
View File
@@ -36,7 +36,6 @@ namespace Barotrauma
set
{
enabled = value;
text.TextColor = enabled ? Color.White : Color.White * 0.5f;
}
}
@@ -76,9 +75,10 @@ namespace Barotrauma
box.SelectedColor = Color.DarkGray;
box.CanBeFocused = false;
GUI.Style.Apply(box, "", this);
GUI.Style.Apply(box, "GUITickBox");
text = new GUITextBlock(new Rectangle(rect.Right + 10, rect.Y+2, 20, rect.Height), label, "", this, font);
text = new GUITextBlock(new Rectangle(rect.Right, rect.Y, 20, rect.Height), label, "", Alignment.TopLeft, Alignment.Left | Alignment.CenterY, this, false, font);
GUI.Style.Apply(text, "", this);
this.rect = new Rectangle(box.Rect.X, box.Rect.Y, 240, rect.Height);
@@ -89,15 +89,8 @@ namespace Barotrauma
{
if (!Visible || !Enabled) return;
//if (MouseOn != null && MouseOn != this && !MouseOn.IsParentOf(this)) return;
//if (text.Rect.Contains(PlayerInput.MousePosition)) MouseOn = this;
if (MouseOn==this)//box.Rect.Contains(PlayerInput.MousePosition))
if (MouseOn == this)
{
//ToolTip = this.ToolTip;
//MouseOn = this;
box.State = ComponentState.Hover;
if (PlayerInput.LeftButtonHeld())
@@ -105,7 +98,6 @@ namespace Barotrauma
box.State = ComponentState.Selected;
}
if (PlayerInput.LeftButtonClicked())
{
Selected = !Selected;
@@ -116,24 +108,18 @@ namespace Barotrauma
{
box.State = ComponentState.None;
}
if (selected)
{
box.State = ComponentState.Selected;
}
}
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
DrawChildren(spriteBatch);
float alpha = enabled ? 1.0f : 0.8f;
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 1, box.Rect.Y + 1, box.Rect.Width - 2, box.Rect.Height - 2),
(box.State == ComponentState.Hover ? new Color(50, 50, 50, 255) : Color.Black) * alpha, true);
if (!selected) return;
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 5, box.Rect.Y + 5, box.Rect.Width - 10, box.Rect.Height - 10),
Color.Green * 0.8f * alpha, true);
DrawChildren(spriteBatch);
}
}
}
+10 -10
View File
@@ -31,7 +31,7 @@ namespace Barotrauma
const int PreviouslyUsedCount = 10;
private GUIListBox previouslyUsedList;
GUIDropDown linkedSubBox;
private GUIDropDown linkedSubBox;
//a Character used for picking up and manipulating items
private Character dummyCharacter;
@@ -126,7 +126,7 @@ namespace Barotrauma
selectedTab = -1;
topPanel = new GUIFrame(new Rectangle(0, 0, 0, 31), "");
topPanel = new GUIFrame(new Rectangle(0, 0, 0, 50), "GUIFrameTop");
topPanel.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
hullVolumeFrame = new GUIFrame(new Rectangle(145, 26, 280, 70), "", topPanel);
@@ -153,10 +153,10 @@ namespace Barotrauma
var nameLabel = new GUITextBlock(new Rectangle(170, -4, 150, 20), "", "", topPanel, GUI.LargeFont);
nameLabel.TextGetter = GetSubName;
linkedSubBox = new GUIDropDown(new Rectangle(750,0,200,20), "Add submarine", "", topPanel);
linkedSubBox.ToolTip =
"Places another submarine into the current submarine file. "+
"Can be used for adding things such as smaller vessels, "+
linkedSubBox = new GUIDropDown(new Rectangle(750, 0, 200, 20), "Add submarine", "", topPanel);
linkedSubBox.ToolTip =
"Places another submarine into the current submarine file. " +
"Can be used for adding things such as smaller vessels, " +
"escape pods or detachable sections into the main submarine.";
foreach (Submarine sub in Submarine.SavedSubmarines)
@@ -164,17 +164,17 @@ namespace Barotrauma
linkedSubBox.AddItem(sub.Name, sub);
}
linkedSubBox.OnSelected += SelectLinkedSub;
leftPanel = new GUIFrame(new Rectangle(0, 30, 150, GameMain.GraphicsHeight-30), "");
leftPanel = new GUIFrame(new Rectangle(0, 0, 150, GameMain.GraphicsHeight), "GUIFrameLeft");
leftPanel.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
GUITextBlock itemCount = new GUITextBlock(new Rectangle(0, 30, 0, 20), "", "", leftPanel);
itemCount.TextGetter = GetItemCount;
GUITextBlock structureCount = new GUITextBlock(new Rectangle(0, 50, 0, 20), "", "", leftPanel);
structureCount.TextGetter = GetStructureCount;
GUItabs = new GUIComponent[Enum.GetValues(typeof(MapEntityCategory)).Length];
GUItabs = new GUIComponent[Enum.GetValues(typeof(MapEntityCategory)).Length];
int width = 400, height = 400;
int y = 90;
+3 -3
View File
@@ -170,7 +170,7 @@ namespace Barotrauma
Rectangle panelRect = new Rectangle(0,0,width,height);
menu = new GUIFrame(panelRect, Color.Transparent, Alignment.Center);
menu = new GUIFrame(panelRect, Color.Transparent, Alignment.Center, null);
//menu.Padding = GUI.style.smallPadding;
//server info panel ------------------------------------------------------------
@@ -251,7 +251,7 @@ namespace Barotrauma
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
mode.Name, "",
Alignment.Left, Alignment.Left,
Alignment.TopLeft, Alignment.CenterLeft,
modeList);
textBlock.ToolTip = mode.Description;
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
@@ -674,7 +674,7 @@ namespace Barotrauma
{
var subTextBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25), ToolBox.LimitString(sub.Name, GUI.Font, subList.Rect.Width - 65), "",
Alignment.Left, Alignment.CenterY | Alignment.Left, subList)
Alignment.TopLeft, Alignment.CenterLeft, subList)
{
Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f),
ToolTip = sub.Description,
@@ -176,13 +176,13 @@ namespace Barotrauma
passwordBox.Enabled = false;
passwordBox.UserData = "password";
new GUITextBlock(new Rectangle(columnX[0], 0, 0, 0), serverName, "", serverFrame);
new GUITextBlock(new Rectangle(columnX[0], 0, 0, 0), serverName, "", Alignment.TopLeft, Alignment.CenterLeft, serverFrame);
int playerCount = 0, maxPlayers = 1;
int.TryParse(currPlayersStr, out playerCount);
int.TryParse(maxPlayersStr, out maxPlayers);
new GUITextBlock(new Rectangle(columnX[1], 0, 0, 0), playerCount + "/" + maxPlayers, "", serverFrame);
new GUITextBlock(new Rectangle(columnX[1], 0, 0, 0), playerCount + "/" + maxPlayers, "", Alignment.TopLeft, Alignment.CenterLeft, serverFrame);
var gameStartedBox = new GUITickBox(new Rectangle(columnX[2] + (columnX[3] - columnX[2])/ 2, 0, 20, 20), "", Alignment.TopLeft, serverFrame);
gameStartedBox.Selected = gameStarted == "1";