misc UI stuff, gamesession additions, limbs don't have individual health anymore, background music
This commit is contained in:
@@ -272,10 +272,26 @@ namespace Subsurface
|
||||
if (Character.Controlled != null) Character.Controlled.DrawHud(spriteBatch, cam);
|
||||
|
||||
DrawMessages(spriteBatch, (float)deltaTime);
|
||||
|
||||
if (GUIMessageBox.messageBoxes.Count>0)
|
||||
{
|
||||
var messageBox = GUIMessageBox.messageBoxes.Peek();
|
||||
if (messageBox != null) messageBox.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
|
||||
DebugConsole.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public static void Update(float deltaTime)
|
||||
{
|
||||
if (GUIMessageBox.messageBoxes.Count > 0)
|
||||
{
|
||||
var messageBox = GUIMessageBox.messageBoxes.Peek();
|
||||
if (messageBox != null) messageBox.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddMessage(string message, Color color, float lifeTime = 3.0f)
|
||||
{
|
||||
Vector2 currPos = new Vector2(Game1.GraphicsWidth / 2.0f, Game1.GraphicsHeight * 0.7f);
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Subsurface
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled)
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled && (MouseOn == this || IsParentOf(MouseOn)))
|
||||
{
|
||||
state = ComponentState.Hover;
|
||||
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
|
||||
@@ -66,8 +66,7 @@ namespace Subsurface
|
||||
if (OnClicked != null)
|
||||
{
|
||||
if (OnClicked(this, UserData)) state = ComponentState.Selected;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -87,7 +86,7 @@ namespace Subsurface
|
||||
|
||||
DrawChildren(spriteBatch);
|
||||
|
||||
if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f*alpha, true);
|
||||
if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,14 +142,27 @@ namespace Subsurface
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsParentOf(GUIComponent component)
|
||||
{
|
||||
foreach (GUIComponent child in children)
|
||||
{
|
||||
if (child == component) return true;
|
||||
if (child.IsParentOf(component)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Color newColor = color;
|
||||
if (state == ComponentState.Selected) newColor = selectedColor;
|
||||
if (state == ComponentState.Hover) newColor = hoverColor;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, newColor*alpha, true);
|
||||
DrawChildren(spriteBatch);
|
||||
|
||||
//Color newColor = color;
|
||||
//if (state == ComponentState.Selected) newColor = selectedColor;
|
||||
//if (state == ComponentState.Hover) newColor = hoverColor;
|
||||
|
||||
//GUI.DrawRectangle(spriteBatch, rect, newColor*alpha, true);
|
||||
//DrawChildren(spriteBatch);
|
||||
}
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
|
||||
@@ -27,5 +27,17 @@ namespace Subsurface
|
||||
parent.AddChild(this);
|
||||
}
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
Color newColor = color;
|
||||
if (state == ComponentState.Selected) newColor = selectedColor;
|
||||
if (state == ComponentState.Hover) newColor = hoverColor;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, newColor * alpha, true);
|
||||
DrawChildren(spriteBatch);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Subsurface
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
|
||||
scrollBar.Update(deltaTime);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace Subsurface
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
|
||||
base.Draw(spriteBatch);
|
||||
GUI.DrawRectangle(spriteBatch, rect, color*alpha, true);
|
||||
|
||||
int x = rect.X, y = rect.Y;
|
||||
@@ -206,7 +206,6 @@ namespace Subsurface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < children.Count; i++ )
|
||||
{
|
||||
GUIComponent child = children[i];
|
||||
@@ -232,7 +231,7 @@ namespace Subsurface
|
||||
if (CheckSelected() != selected.UserData) selected = null;
|
||||
}
|
||||
}
|
||||
else if (child.Rect.Contains(PlayerInput.GetMouseState.Position) && enabled)
|
||||
else if (enabled && (MouseOn==this || ( MouseOn!=null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.GetMouseState.Position))
|
||||
{
|
||||
child.State = ComponentState.Hover;
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
|
||||
@@ -3,27 +3,29 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class GUIMessageBox
|
||||
class GUIMessageBox : GUIFrame
|
||||
{
|
||||
public static Queue<GUIMessageBox> messageBoxes = new Queue<GUIMessageBox>();
|
||||
|
||||
const int DefaultWidth=400, DefaultHeight=200;
|
||||
|
||||
public delegate bool OnClickedHandler(GUIButton button, object obj);
|
||||
public OnClickedHandler OnClicked;
|
||||
//public delegate bool OnClickedHandler(GUIButton button, object obj);
|
||||
//public OnClickedHandler OnClicked;
|
||||
|
||||
GUIFrame frame;
|
||||
//GUIFrame frame;
|
||||
GUIButton[] buttons;
|
||||
|
||||
public GUIMessageBox(string header, string text)
|
||||
: this(header, text, new string[] {"OK"})
|
||||
{ }
|
||||
|
||||
public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left |Alignment.Top))
|
||||
{
|
||||
frame = new GUIFrame(new Rectangle(Game1.GraphicsWidth/2-DefaultWidth/2, Game1.GraphicsHeight/2-DefaultHeight/2, DefaultWidth, DefaultHeight),
|
||||
GUI.style.backGroundColor, Alignment.CenterX, GUI.style);
|
||||
frame.Padding = GUI.style.smallPadding;
|
||||
this.buttons[0].OnClicked = OkClicked;
|
||||
}
|
||||
|
||||
public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left | Alignment.Top))
|
||||
: base(new Rectangle(Game1.GraphicsWidth / 2 - DefaultWidth / 2, Game1.GraphicsHeight / 2 - DefaultHeight / 2, DefaultWidth, DefaultHeight),
|
||||
GUI.style.backGroundColor, Alignment.CenterX, GUI.style)
|
||||
{
|
||||
Padding = GUI.style.smallPadding;
|
||||
|
||||
if (buttons == null || buttons.Length == 0)
|
||||
{
|
||||
@@ -31,24 +33,25 @@ namespace Subsurface
|
||||
return;
|
||||
}
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 5, 0, 30), header, Color.Transparent, Color.White, textAlignment, frame, true);
|
||||
new GUITextBlock(new Rectangle(0,50,0,DefaultHeight-70),text, Color.Transparent, Color.White, textAlignment, frame, true);
|
||||
new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, this, true);
|
||||
new GUITextBlock(new Rectangle(0, 30, 0, DefaultHeight - 70), text, Color.Transparent, Color.White, textAlignment, this, true);
|
||||
|
||||
int x = 0;
|
||||
this.buttons = new GUIButton[buttons.Length];
|
||||
for (int i=0; i<buttons.Length; i++)
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
this.buttons[i] = new GUIButton(new Rectangle(x,0,150,30), buttons[i], GUI.style, Alignment.Left, frame);
|
||||
this.buttons[i].OnClicked = ButtonClicked;
|
||||
this.buttons[i] = new GUIButton(new Rectangle(x, 0, 150, 30), buttons[i], GUI.style, Alignment.Left | Alignment.Bottom, this);
|
||||
|
||||
x += this.buttons[i].Rect.Width + 20;
|
||||
}
|
||||
|
||||
messageBoxes.Enqueue(this);
|
||||
}
|
||||
|
||||
private bool ButtonClicked(GUIButton button, object obj)
|
||||
private bool OkClicked(GUIButton button, object obj)
|
||||
{
|
||||
if (OnClicked==null) return true;
|
||||
|
||||
return OnClicked(button, obj);
|
||||
messageBoxes.Dequeue();
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user