(e42047dc1) Tester's build, January 30th 2020
This commit is contained in:
@@ -20,9 +20,7 @@ namespace Barotrauma
|
||||
public OnButtonDownHandler OnButtonDown;
|
||||
|
||||
public bool CanBeSelected = true;
|
||||
|
||||
private Color? defaultTextColor;
|
||||
|
||||
|
||||
public override bool Enabled
|
||||
{
|
||||
get
|
||||
@@ -33,13 +31,7 @@ namespace Barotrauma
|
||||
set
|
||||
{
|
||||
if (value == enabled) { return; }
|
||||
enabled = value;
|
||||
if (color.A == 0)
|
||||
{
|
||||
if (defaultTextColor == null) { defaultTextColor = TextBlock.TextColor; }
|
||||
TextBlock.TextColor = enabled ? defaultTextColor.Value : defaultTextColor.Value * 0.5f;
|
||||
}
|
||||
frame.Color = enabled ? color : Color.Gray * 0.7f;
|
||||
enabled = frame.Enabled = textBlock.Enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +97,11 @@ namespace Barotrauma
|
||||
set { textBlock.TextColor = value; }
|
||||
}
|
||||
|
||||
public Color HoverTextColor
|
||||
{
|
||||
get { return textBlock.HoverTextColor; }
|
||||
set { textBlock.HoverTextColor = value; }
|
||||
}
|
||||
|
||||
public override float FlashTimer
|
||||
{
|
||||
@@ -115,12 +112,12 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
return (textBlock==null) ? GUI.Font : textBlock.Font;
|
||||
return (textBlock == null) ? GUI.Font : textBlock.Font;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Font = value;
|
||||
if (textBlock != null) textBlock.Font = value;
|
||||
if (textBlock != null) textBlock.Font = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,28 +146,28 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public bool Selected { get; set; }
|
||||
|
||||
public GUIButton(RectTransform rectT, string text = "", Alignment textAlignment = Alignment.Center, string style = "", Color? color = null, ScalableFont font = null) : base(style, rectT)
|
||||
public GUIButton(RectTransform rectT, string text = "", Alignment textAlignment = Alignment.Center, string style = "", Color? color = null) : base(style, rectT)
|
||||
{
|
||||
CanBeFocused = true;
|
||||
HoverCursor = CursorState.Hand;
|
||||
|
||||
frame = new GUIFrame(new RectTransform(Vector2.One, rectT), style) { CanBeFocused = false };
|
||||
if (style != null) { GUI.Style.Apply(frame, style == "" ? "GUIButton" : style); }
|
||||
if (color.HasValue)
|
||||
{
|
||||
this.color = color.Value;
|
||||
this.color = frame.Color = color.Value;
|
||||
}
|
||||
frame = new GUIFrame(new RectTransform(Vector2.One, rectT), style) { CanBeFocused = false };
|
||||
if (style != null) GUI.Style.Apply(frame, style == "" ? "GUIButton" : style);
|
||||
textBlock = new GUITextBlock(new RectTransform(Vector2.One, rectT), text, textAlignment: textAlignment, style: null, font: font)
|
||||
textBlock = new GUITextBlock(new RectTransform(Vector2.One, rectT, Anchor.Center), text, textAlignment: textAlignment, style: null)
|
||||
{
|
||||
TextColor = this.style == null ? Color.Black : this.style.textColor,
|
||||
TextColor = this.style == null ? Color.Black : this.style.TextColor,
|
||||
HoverTextColor = this.style == null ? Color.Black : this.style.HoverTextColor,
|
||||
SelectedTextColor = this.style == null ? Color.Black : this.style.SelectedTextColor,
|
||||
CanBeFocused = false
|
||||
};
|
||||
if (rectT.Rect.Height == 0 && !string.IsNullOrEmpty(text))
|
||||
{
|
||||
RectTransform.Resize(new Point(RectTransform.Rect.Width, (int)Font.MeasureString(textBlock.Text).Y));
|
||||
RectTransform.MinSize = textBlock.RectTransform.MinSize = new Point(0, Rect.Height);
|
||||
RectTransform.MinSize = textBlock.RectTransform.MinSize = new Point(0, System.Math.Max(rectT.MinSize.Y, Rect.Height));
|
||||
TextBlock.SetTextPos();
|
||||
}
|
||||
GUI.Style.Apply(textBlock, "", this);
|
||||
@@ -181,12 +178,12 @@ namespace Barotrauma
|
||||
{
|
||||
base.ApplyStyle(style);
|
||||
|
||||
if (frame != null) frame.ApplyStyle(style);
|
||||
if (frame != null) { frame.ApplyStyle(style); }
|
||||
}
|
||||
|
||||
public override void Flash(Color? color = null, float flashDuration = 1.5f, bool useRectangleFlash = false, Vector2? flashRectInflate = null)
|
||||
public override void Flash(Color? color = null, float flashDuration = 1.5f, bool useRectangleFlash = false, bool useCircularFlash = false, Vector2? flashRectInflate = null)
|
||||
{
|
||||
Frame.Flash(color, flashDuration, useRectangleFlash, flashRectInflate);
|
||||
Frame.Flash(color, flashDuration, useRectangleFlash, useCircularFlash, flashRectInflate);
|
||||
}
|
||||
|
||||
protected override void Draw(SpriteBatch spriteBatch)
|
||||
@@ -200,7 +197,9 @@ namespace Barotrauma
|
||||
base.Update(deltaTime);
|
||||
if (Rect.Contains(PlayerInput.MousePosition) && CanBeSelected && CanBeFocused && Enabled && GUI.IsMouseOn(this))
|
||||
{
|
||||
state = ComponentState.Hover;
|
||||
State = Selected ?
|
||||
ComponentState.HoverSelected :
|
||||
ComponentState.Hover;
|
||||
if (PlayerInput.PrimaryMouseButtonDown())
|
||||
{
|
||||
OnButtonDown?.Invoke();
|
||||
@@ -211,12 +210,12 @@ namespace Barotrauma
|
||||
{
|
||||
if (OnPressed())
|
||||
{
|
||||
state = ComponentState.Pressed;
|
||||
State = ComponentState.Pressed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state = ComponentState.Pressed;
|
||||
State = ComponentState.Pressed;
|
||||
}
|
||||
}
|
||||
else if (PlayerInput.PrimaryMouseButtonClicked())
|
||||
@@ -224,28 +223,26 @@ namespace Barotrauma
|
||||
GUI.PlayUISound(GUISoundType.Click);
|
||||
if (OnClicked != null)
|
||||
{
|
||||
if (OnClicked(this, UserData) && CanBeSelected)
|
||||
if (OnClicked(this, UserData))
|
||||
{
|
||||
state = ComponentState.Selected;
|
||||
State = ComponentState.Selected;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Selected = !Selected;
|
||||
// state = state == ComponentState.Selected ? ComponentState.None : ComponentState.Selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state = Selected ? ComponentState.Selected : ComponentState.None;
|
||||
State = Selected ? ComponentState.Selected : ComponentState.None;
|
||||
}
|
||||
|
||||
foreach (GUIComponent child in Children)
|
||||
{
|
||||
child.State = state;
|
||||
child.State = State;
|
||||
}
|
||||
//frame.State = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user