diff --git a/DepthsBelow/DepthsBelow/GUI/Text.cs b/DepthsBelow/DepthsBelow/GUI/Text.cs index 897eb3f..575212a 100755 --- a/DepthsBelow/DepthsBelow/GUI/Text.cs +++ b/DepthsBelow/DepthsBelow/GUI/Text.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace DepthsBelow.GUI @@ -11,25 +12,30 @@ namespace DepthsBelow.GUI { public String Value; public SpriteFont Font; - public Color Color; - public Text(SpriteFont font) + public Text() : base() { - this.Font = font; - this.Color = Color.Black; + this.Color = Color.White; } - public Text(Frame parent, SpriteFont font) : this(font) + public Text(Frame parent) + : this() { this.Parent = parent; } + public void SetFont(string spriteFontName) + { + Font = GameServices.GetService().Load(spriteFontName); + } + public override void Draw(SpriteBatch spriteBatch) { base.Draw(spriteBatch); - spriteBatch.DrawString(Font, Value, new Vector2(Rectangle.X + Parent.Rectangle.X, Rectangle.Y + Parent.Rectangle.Y), Color); + if (Parent.Visible && this.Visible && Font != null) + spriteBatch.DrawString(Font, Value, new Vector2(Rectangle.X + Parent.Rectangle.X, Rectangle.Y + Parent.Rectangle.Y), Color); } } } diff --git a/DepthsBelow/DepthsBelow/Interface.cs b/DepthsBelow/DepthsBelow/Interface.cs index 6e93498..48093e0 100755 --- a/DepthsBelow/DepthsBelow/Interface.cs +++ b/DepthsBelow/DepthsBelow/Interface.cs @@ -17,7 +17,7 @@ namespace DepthsBelow this.core = core; // Test GUI frames - var frame = new GUI.Frame() + /*var frame = new GUI.Frame() { Y = 100 }; @@ -33,8 +33,9 @@ namespace DepthsBelow } }; - var text = new GUI.Text(frame, core.Content.Load("Arial")); - text.Value = "Hello world!"; + var text = new GUI.Text(frame); + text.SetFont("Arial"); + text.Value = "Hello world!";*/ } } } diff --git a/DepthsBelow/DepthsBelow/Lua.cs b/DepthsBelow/DepthsBelow/Lua.cs index 18f8792..d1ff5f0 100755 --- a/DepthsBelow/DepthsBelow/Lua.cs +++ b/DepthsBelow/DepthsBelow/Lua.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using DepthsBelow.GUI; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Input; @@ -28,6 +29,24 @@ namespace DepthsBelow { return new GUI.Button(parent); } + + public static GUI.Text CreateText() + { + return new Text(); + } + public static GUI.Text CreateText(GUI.Frame parent) + { + return new GUI.Text(parent); + } + } + + static class LuaMouse + { + public static Point GetPos() + { + var ms = Mouse.GetState(); + return new Point(ms.X, ms.Y); + } } public class Lua @@ -58,11 +77,17 @@ namespace DepthsBelow lua.RegisterFunction("Console.Write", null, typeof(System.Console).GetMethod("Write", new Type[] { typeof(string) })); lua.RegisterFunction("Console.WriteLine", null, typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) })); + lua.NewTable("Mouse"); + lua.RegisterFunction("Mouse.GetPos", null, typeof(LuaMouse).GetMethod("GetPos")); + // Register GUI creation functions lua.RegisterFunction("_CreateFrame", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { })); lua.RegisterFunction("_CreateFrameAsChild", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { typeof(GUI.Frame) })); lua.RegisterFunction("_CreateButton", null, typeof(LuaGUI).GetMethod("CreateButton", new Type[] { })); lua.RegisterFunction("_CreateButtonAsChild", null, typeof(LuaGUI).GetMethod("CreateButton", new Type[] { typeof(GUI.Frame) })); + lua.RegisterFunction("_CreateText", null, typeof(LuaGUI).GetMethod("CreateText", new Type[] { })); + lua.RegisterFunction("_CreateTextAsChild", null, typeof(LuaGUI).GetMethod("CreateText", new Type[] { typeof(GUI.Frame) })); + lua.NewTable("GUI"); /* * Because Lua can't dynamically call overloads of registered functions, a generic Lua function needs to do the decision making. @@ -107,5 +132,10 @@ namespace DepthsBelow } } + + public T GetObject(string obj) + { + return (T)lua[obj]; + } } } diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index 34211d0..bddd61e 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using Microsoft.Xna.Framework; @@ -24,7 +25,6 @@ namespace DepthsBelow bool checkingDirection = false; bool readjust = false; - public MouseInput(Core core) { @@ -34,7 +34,6 @@ namespace DepthsBelow gridRectangle = Rectangle.Empty; } - public void LoadContent() { selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1); @@ -48,7 +47,34 @@ namespace DepthsBelow { MouseState ms = Mouse.GetState(); Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); + Rectangle mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); KeyboardState ks = Keyboard.GetState(); + + // Tooltip stuff + var tooltip = core.Lua.GetObject("ToolTip"); + if (tooltip != null) + { + tooltip.Visible = false; + foreach(var entity in core.Squad) + { + if (mouseWorldRectangle.Intersects(entity.GetComponent().Rectangle)) + { + tooltip.Visible = true; + break; + } + } + + if (tooltip.Visible) + { + tooltip.X = ms.X + 10; + tooltip.Y = ms.Y + 15; + } + } + else + { + throw new Exception("Tooltip is null D:"); + } + if (core.PlayerTurn == true) { // Selection rectangle diff --git a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj index 97191d5..68b9f15 100755 --- a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj +++ b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj @@ -145,6 +145,12 @@ LuaImporter + + + tooltip + LuaImporter + +