Lua tooltips
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace DepthsBelow.GUI
|
namespace DepthsBelow.GUI
|
||||||
@@ -11,25 +12,30 @@ namespace DepthsBelow.GUI
|
|||||||
{
|
{
|
||||||
public String Value;
|
public String Value;
|
||||||
public SpriteFont Font;
|
public SpriteFont Font;
|
||||||
public Color Color;
|
|
||||||
|
|
||||||
public Text(SpriteFont font)
|
public Text()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
this.Font = font;
|
this.Color = Color.White;
|
||||||
this.Color = Color.Black;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text(Frame parent, SpriteFont font) : this(font)
|
public Text(Frame parent)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
this.Parent = parent;
|
this.Parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetFont(string spriteFontName)
|
||||||
|
{
|
||||||
|
Font = GameServices.GetService<ContentManager>().Load<SpriteFont>(spriteFontName);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(SpriteBatch spriteBatch)
|
public override void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
base.Draw(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace DepthsBelow
|
|||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
// Test GUI frames
|
// Test GUI frames
|
||||||
var frame = new GUI.Frame()
|
/*var frame = new GUI.Frame()
|
||||||
{
|
{
|
||||||
Y = 100
|
Y = 100
|
||||||
};
|
};
|
||||||
@@ -33,8 +33,9 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var text = new GUI.Text(frame, core.Content.Load<SpriteFont>("Arial"));
|
var text = new GUI.Text(frame);
|
||||||
text.Value = "Hello world!";
|
text.SetFont("Arial");
|
||||||
|
text.Value = "Hello world!";*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DepthsBelow.GUI;
|
using DepthsBelow.GUI;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
@@ -28,6 +29,24 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
return new GUI.Button(parent);
|
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
|
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.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.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
|
// Register GUI creation functions
|
||||||
lua.RegisterFunction("_CreateFrame", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { }));
|
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("_CreateFrameAsChild", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { typeof(GUI.Frame) }));
|
||||||
lua.RegisterFunction("_CreateButton", null, typeof(LuaGUI).GetMethod("CreateButton", new Type[] { }));
|
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("_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");
|
lua.NewTable("GUI");
|
||||||
/*
|
/*
|
||||||
* Because Lua can't dynamically call overloads of registered functions, a generic Lua function needs to do the decision making.
|
* 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<T>(string obj)
|
||||||
|
{
|
||||||
|
return (T)lua[obj];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
@@ -25,7 +26,6 @@ namespace DepthsBelow
|
|||||||
bool checkingDirection = false;
|
bool checkingDirection = false;
|
||||||
bool readjust = false;
|
bool readjust = false;
|
||||||
|
|
||||||
|
|
||||||
public MouseInput(Core core)
|
public MouseInput(Core core)
|
||||||
{
|
{
|
||||||
this.core = core;
|
this.core = core;
|
||||||
@@ -34,7 +34,6 @@ namespace DepthsBelow
|
|||||||
gridRectangle = Rectangle.Empty;
|
gridRectangle = Rectangle.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void LoadContent()
|
public void LoadContent()
|
||||||
{
|
{
|
||||||
selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1);
|
selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1);
|
||||||
@@ -48,7 +47,34 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
MouseState ms = Mouse.GetState();
|
MouseState ms = Mouse.GetState();
|
||||||
Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
|
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();
|
KeyboardState ks = Keyboard.GetState();
|
||||||
|
|
||||||
|
// Tooltip stuff
|
||||||
|
var tooltip = core.Lua.GetObject<GUI.Frame>("ToolTip");
|
||||||
|
if (tooltip != null)
|
||||||
|
{
|
||||||
|
tooltip.Visible = false;
|
||||||
|
foreach(var entity in core.Squad)
|
||||||
|
{
|
||||||
|
if (mouseWorldRectangle.Intersects(entity.GetComponent<Component.Collision>().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)
|
if (core.PlayerTurn == true)
|
||||||
{
|
{
|
||||||
// Selection rectangle
|
// Selection rectangle
|
||||||
|
|||||||
@@ -145,6 +145,12 @@
|
|||||||
<Importer>LuaImporter</Importer>
|
<Importer>LuaImporter</Importer>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="scripts\tooltip.lua">
|
||||||
|
<Name>tooltip</Name>
|
||||||
|
<Importer>LuaImporter</Importer>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ button:SetTexture('images/Enter');
|
|||||||
button.Width = 100;
|
button.Width = 100;
|
||||||
button.Height = 50;
|
button.Height = 50;
|
||||||
button.OnClick = function(clickPos)
|
button.OnClick = function(clickPos)
|
||||||
Console.WriteLine(clickPos.X .. ' ' .. clickPos.Y);
|
Console.WriteLine(clickPos.X .. ' ' .. clickPos.Y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
ToolTip = CreateFrame("Frame")
|
||||||
|
|
||||||
|
local text = CreateFrame("Text", ToolTip)
|
||||||
|
text:SetFont("Arial")
|
||||||
|
text.Value = "99%"
|
||||||
Reference in New Issue
Block a user