GUIStyle improvements & some simple UI graphics, networking bugfixes, separate Random class, some StyleCop cleanup
This commit is contained in:
+29
-18
@@ -7,6 +7,7 @@ namespace Subsurface
|
||||
class GUIButton : GUIComponent
|
||||
{
|
||||
protected GUITextBlock textBlock;
|
||||
protected GUIFrame frame;
|
||||
|
||||
public delegate bool OnClickedHandler(GUIButton button, object obj);
|
||||
public OnClickedHandler OnClicked;
|
||||
@@ -22,33 +23,41 @@ namespace Subsurface
|
||||
set { textBlock.Text = value; }
|
||||
}
|
||||
|
||||
public GUIButton(Rectangle rect, string text, GUIStyle style, Alignment alignment, GUIComponent parent = null)
|
||||
: this(rect, text, style.foreGroundColor, alignment, parent)
|
||||
public GUIButton(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null)
|
||||
: this(rect, text, null, Alignment.Left, style, parent)
|
||||
{
|
||||
hoverColor = style.hoverColor;
|
||||
selectedColor = style.selectedColor;
|
||||
}
|
||||
|
||||
public GUIButton(Rectangle rect, string text, Color color, GUIComponent parent = null)
|
||||
: this(rect, text, color, (Alignment.Left | Alignment.Top), parent)
|
||||
public GUIButton(Rectangle rect, string text, Alignment alignment, GUIStyle style, GUIComponent parent = null)
|
||||
: this(rect, text, null, alignment, style, parent)
|
||||
{
|
||||
}
|
||||
|
||||
public GUIButton(Rectangle rect, string text, Color color, Alignment alignment, GUIComponent parent = null)
|
||||
|
||||
public GUIButton(Rectangle rect, string text, Color? color, GUIStyle 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)
|
||||
:base (style)
|
||||
{
|
||||
this.rect = rect;
|
||||
this.color = color;
|
||||
if (color!=null) this.color = (Color)color;
|
||||
this.alignment = alignment;
|
||||
|
||||
Enabled = true;
|
||||
|
||||
if (parent != null)
|
||||
parent.AddChild(this);
|
||||
|
||||
textBlock = new GUITextBlock(new Rectangle(0,0,0,0), text, Color.Transparent, Color.Black, (Alignment.CenterX | Alignment.CenterY), this);
|
||||
|
||||
frame = new GUIFrame(new Rectangle(0,0,0,0), style, this);
|
||||
if (style!=null) style.Apply(frame, this);
|
||||
|
||||
textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), text,
|
||||
Color.Transparent, (this.style==null) ? Color.Black : this.style.textColor,
|
||||
Alignment.Center, style, this);
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled && (MouseOn == this || IsParentOf(MouseOn)))
|
||||
@@ -74,15 +83,17 @@ namespace Subsurface
|
||||
state = ComponentState.None;
|
||||
}
|
||||
|
||||
Color currColor = color;
|
||||
if (state == ComponentState.Hover) currColor = hoverColor;
|
||||
if (state == ComponentState.Selected) currColor = selectedColor;
|
||||
frame.State = state;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, currColor * alpha, true);
|
||||
//Color currColor = color;
|
||||
//if (state == ComponentState.Hover) currColor = hoverColor;
|
||||
//if (state == ComponentState.Selected) currColor = selectedColor;
|
||||
|
||||
//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, currColor * alpha, true);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.Black * alpha, false);
|
||||
////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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user