More GUI stuff
This commit is contained in:
@@ -92,21 +92,8 @@ namespace DepthsBelow
|
||||
|
||||
TestMonster.X = 12;
|
||||
TestMonster.Y = 4;
|
||||
// Test GUI frames
|
||||
var frame = new GUI.Button()
|
||||
{
|
||||
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);
|
||||
|
||||
//frame.Add(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -122,6 +122,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Camera.cs" />
|
||||
<Compile Include="Interface.cs" />
|
||||
<Compile Include="Shot.cs" />
|
||||
<Compile Include="Component\Shooting.cs" />
|
||||
<Compile Include="GUIManager.cs" />
|
||||
|
||||
@@ -17,16 +17,23 @@ namespace DepthsBelow.GUI
|
||||
|
||||
private MouseState lastMouseState;
|
||||
|
||||
public Button()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*public void OnClick(Point pos)
|
||||
{
|
||||
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)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
@@ -37,14 +44,14 @@ namespace DepthsBelow.GUI
|
||||
{
|
||||
// HACK: This should be handled globally somewhere else to prevent event bubbling
|
||||
if (
|
||||
ms.X >= Rectangle.Left
|
||||
&& ms.X < Rectangle.Right
|
||||
&& ms.Y >= Rectangle.Top
|
||||
&& ms.Y < Rectangle.Bottom)
|
||||
ms.X >= AbsoluteRectangle.Left
|
||||
&& ms.X < AbsoluteRectangle.Right
|
||||
&& ms.Y >= AbsoluteRectangle.Top
|
||||
&& ms.Y < AbsoluteRectangle.Bottom)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,16 @@ namespace DepthsBelow.GUI
|
||||
}
|
||||
|
||||
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 Color Color;
|
||||
public bool Visible = true;
|
||||
@@ -49,6 +59,12 @@ namespace DepthsBelow.GUI
|
||||
GUIManager.Add(this);
|
||||
}
|
||||
|
||||
public Frame(Frame parentFrame)
|
||||
: this()
|
||||
{
|
||||
this.Parent = parentFrame;
|
||||
}
|
||||
|
||||
public void Add(Frame childFrame)
|
||||
{
|
||||
childFrame.Parent = this;
|
||||
@@ -81,7 +97,7 @@ namespace DepthsBelow.GUI
|
||||
if (Visible)
|
||||
{
|
||||
if (Texture != null)
|
||||
spriteBatch.Draw(Texture, Rectangle, Color);
|
||||
spriteBatch.Draw(Texture, AbsoluteRectangle, Color);
|
||||
|
||||
foreach (var child in Children)
|
||||
child.Draw(spriteBatch);
|
||||
|
||||
@@ -20,6 +20,11 @@ namespace DepthsBelow.GUI
|
||||
this.Color = Color.Black;
|
||||
}
|
||||
|
||||
public Text(Frame parent, SpriteFont font) : this(font)
|
||||
{
|
||||
this.Parent = parent;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
Executable
+40
@@ -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.
|
||||
-->
|
||||
<FontName>Berlin Sans FB</FontName>
|
||||
<FontName>Arial</FontName>
|
||||
|
||||
<!--
|
||||
Size is a float value, measured in points. Modify this value to change
|
||||
|
||||
Reference in New Issue
Block a user