More GUI stuff

This commit is contained in:
2012-10-16 13:22:24 +02:00
parent d38e93dc19
commit 9df0077257
7 changed files with 282 additions and 226 deletions
+2 -15
View File
@@ -92,21 +92,8 @@ namespace DepthsBelow
TestMonster.X = 12; TestMonster.X = 12;
TestMonster.Y = 4; TestMonster.Y = 4;
// Test GUI frames
var frame = new GUI.Button() //frame.Add(text);
{
X = 100,
Width = 48,
Height = 23,
Texture = Content.Load<Texture2D>("images/Enter"),
OnClick = delegate(Point clickPos)
{
Debug.WriteLine("That ugly button was clicked at (" + clickPos.X + "," + clickPos.Y + ")");
}
};
var text = new GUI.Text(Content.Load<SpriteFont>("Arial"));
text.Value = "Hello world!";
frame.Add(text);
} }
/// <summary> /// <summary>
@@ -122,6 +122,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Camera.cs" /> <Compile Include="Camera.cs" />
<Compile Include="Interface.cs" />
<Compile Include="Shot.cs" /> <Compile Include="Shot.cs" />
<Compile Include="Component\Shooting.cs" /> <Compile Include="Component\Shooting.cs" />
<Compile Include="GUIManager.cs" /> <Compile Include="GUIManager.cs" />
+17 -10
View File
@@ -17,16 +17,23 @@ namespace DepthsBelow.GUI
private MouseState lastMouseState; private MouseState lastMouseState;
public Button()
{
}
/*public void OnClick(Point pos) /*public void OnClick(Point pos)
{ {
Debug.WriteLine(this + " was clicked at (" + pos.X + "," + pos.Y + ")"); Debug.WriteLine(this + " was clicked at (" + pos.X + "," + pos.Y + ")");
}*/ }*/
public Button()
: base()
{
}
public Button(Frame parent)
: this()
{
this.Parent = parent;
}
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
base.Update(gameTime); base.Update(gameTime);
@@ -37,14 +44,14 @@ namespace DepthsBelow.GUI
{ {
// HACK: This should be handled globally somewhere else to prevent event bubbling // HACK: This should be handled globally somewhere else to prevent event bubbling
if ( if (
ms.X >= Rectangle.Left ms.X >= AbsoluteRectangle.Left
&& ms.X < Rectangle.Right && ms.X < AbsoluteRectangle.Right
&& ms.Y >= Rectangle.Top && ms.Y >= AbsoluteRectangle.Top
&& ms.Y < Rectangle.Bottom) && ms.Y < AbsoluteRectangle.Bottom)
{ {
if (OnClick != null) if (OnClick != null)
{ {
var clickPos = new Point(ms.X - Rectangle.X, ms.Y - Rectangle.Y); var clickPos = new Point(ms.X - AbsoluteRectangle.X, ms.Y - AbsoluteRectangle.Y);
OnClick(clickPos); OnClick(clickPos);
} }
} }
+17 -1
View File
@@ -31,6 +31,16 @@ namespace DepthsBelow.GUI
} }
public Rectangle Rectangle; public Rectangle Rectangle;
public Rectangle AbsoluteRectangle
{
get
{
if (Parent != null)
return new Rectangle(Parent.Rectangle.X + Rectangle.X, Parent.Rectangle.Y + Rectangle.Y, Rectangle.Width, Rectangle.Height);
else
return Rectangle;
}
}
public Texture2D Texture; public Texture2D Texture;
public Color Color; public Color Color;
public bool Visible = true; public bool Visible = true;
@@ -49,6 +59,12 @@ namespace DepthsBelow.GUI
GUIManager.Add(this); GUIManager.Add(this);
} }
public Frame(Frame parentFrame)
: this()
{
this.Parent = parentFrame;
}
public void Add(Frame childFrame) public void Add(Frame childFrame)
{ {
childFrame.Parent = this; childFrame.Parent = this;
@@ -81,7 +97,7 @@ namespace DepthsBelow.GUI
if (Visible) if (Visible)
{ {
if (Texture != null) if (Texture != null)
spriteBatch.Draw(Texture, Rectangle, Color); spriteBatch.Draw(Texture, AbsoluteRectangle, Color);
foreach (var child in Children) foreach (var child in Children)
child.Draw(spriteBatch); child.Draw(spriteBatch);
+5
View File
@@ -20,6 +20,11 @@ namespace DepthsBelow.GUI
this.Color = Color.Black; this.Color = Color.Black;
} }
public Text(Frame parent, SpriteFont font) : this(font)
{
this.Parent = parent;
}
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
+40
View File
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Diagnostics;
using Microsoft.Xna.Framework.Graphics;
namespace DepthsBelow
{
class Interface
{
Core core;
public Interface(Core core)
{
this.core = core;
// Test GUI frames
var frame = new GUI.Frame()
{
Y = 100
};
var button = new GUI.Button(frame)
{
Width = 48,
Height = 23,
Texture = core.Content.Load<Texture2D>("images/Enter"),
OnClick = delegate(Point clickPos)
{
Debug.WriteLine("That ugly button was clicked at (" + clickPos.X + "," + clickPos.Y + ")");
}
};
var text = new GUI.Text(frame, core.Content.Load<SpriteFont>("Arial"));
text.Value = "Hello world!";
}
}
}
@@ -11,7 +11,7 @@ with.
<!-- <!--
Modify this string to change the font that will be imported. Modify this string to change the font that will be imported.
--> -->
<FontName>Berlin Sans FB</FontName> <FontName>Arial</FontName>
<!-- <!--
Size is a float value, measured in points. Modify this value to change Size is a float value, measured in points. Modify this value to change