more GUI stuff

This commit is contained in:
Evil Factory
2021-10-01 19:13:25 -03:00
parent 31fcb5a1e2
commit a5233b4686
3 changed files with 62 additions and 9 deletions
@@ -16,10 +16,20 @@ namespace Barotrauma
env = _env; env = _env;
RectTransform = UserData.CreateStatic<RectTransform>(); RectTransform = UserData.CreateStatic<RectTransform>();
GUILayoutGroup = UserData.CreateStatic<GUILayoutGroup>(); LayoutGroup = UserData.CreateStatic<GUILayoutGroup>();
GUIButton = UserData.CreateStatic<GUIButton>(); Button = UserData.CreateStatic<GUIButton>();
GUITextBox = UserData.CreateStatic<GUITextBox>(); TextBox = UserData.CreateStatic<GUITextBox>();
Canvas = UserData.CreateStatic<GUICanvas>();
Frame = UserData.CreateStatic<GUIFrame>();
TextBlock = UserData.CreateStatic<GUITextBlock>();
TickBox = UserData.CreateStatic<GUITickBox>();
Image = UserData.CreateStatic<GUIImage>();
ListBox = UserData.CreateStatic<GUIListBox>();
Anchor = UserData.CreateStatic<Anchor>(); Anchor = UserData.CreateStatic<Anchor>();
Alignment = UserData.CreateStatic<Alignment>();
Pivot = UserData.CreateStatic<Pivot>();
} }
public ChatBox ChatBox public ChatBox ChatBox
@@ -31,10 +41,20 @@ namespace Barotrauma
} }
public static object RectTransform; public static object RectTransform;
public static object GUILayoutGroup; public static object LayoutGroup;
public static object GUIButton; public static object Button;
public static object GUITextBox; public static object TextBox;
public static object Canvas;
public static object Frame;
public static object TextBlock;
public static object TickBox;
public static object Image;
public static object ListBox;
public static object Pivot;
public static object Anchor; public static object Anchor;
public static object Alignment;
} }
} }
} }
@@ -16,8 +16,19 @@ namespace Barotrauma
RegisterAction<Character>(); RegisterAction<Character>();
RegisterAction<Entity>(); RegisterAction<Entity>();
RegisterAction(); RegisterAction();
#if CLIENT
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(GUIButton.OnClickedHandler), v =>
{
var function = v.Function;
return (GUIButton.OnClickedHandler)((GUIButton a, object b) => new LuaResult(function.Call(a, b)).Bool());
});
#endif
} }
public static void RegisterAction<T>() public static void RegisterAction<T>()
{ {
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Action<T>), v => Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Action<T>), v =>
@@ -27,8 +38,6 @@ namespace Barotrauma
}); });
} }
public static void RegisterAction() public static void RegisterAction()
{ {
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Action), v => Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Action), v =>
@@ -37,5 +46,7 @@ namespace Barotrauma
return (Action)(() => function.Call()); return (Action)(() => function.Call());
}); });
} }
} }
} }
@@ -12,6 +12,10 @@ using System.Linq;
using MoonSharp.Interpreter.Interop; using MoonSharp.Interpreter.Interop;
using System.Reflection; using System.Reflection;
#if CLIENT
using Microsoft.Xna.Framework.Graphics;
#endif
namespace Barotrauma namespace Barotrauma
{ {
partial class LuaSetup partial class LuaSetup
@@ -219,6 +223,8 @@ namespace Barotrauma
public void Stop() public void Stop()
{ {
hook.Call("stop", new object[] { });
hook = new LuaHook(null); hook = new LuaHook(null);
game = new LuaGame(null); game = new LuaGame(null);
networking = new LuaNetworking(null); networking = new LuaNetworking(null);
@@ -229,6 +235,8 @@ namespace Barotrauma
public void Initialize() public void Initialize()
{ {
Stop();
luaSetup = this; luaSetup = this;
PrintMessage("Lua!"); PrintMessage("Lua!");
@@ -241,7 +249,6 @@ namespace Barotrauma
UserData.RegisterType<TraitorMessageType>(); UserData.RegisterType<TraitorMessageType>();
UserData.RegisterType<JobPrefab>(); UserData.RegisterType<JobPrefab>();
UserData.RegisterType<Job>(); UserData.RegisterType<Job>();
UserData.RegisterType<Rectangle>();
UserData.RegisterType<Point>(); UserData.RegisterType<Point>();
UserData.RegisterType<Level.InterestingPosition>(); UserData.RegisterType<Level.InterestingPosition>();
UserData.RegisterType<Level.PositionType>(); UserData.RegisterType<Level.PositionType>();
@@ -337,6 +344,7 @@ namespace Barotrauma
AddCallMetaMember(UserData.RegisterType<Signal>()); AddCallMetaMember(UserData.RegisterType<Signal>());
AddCallMetaMember(UserData.RegisterType<Color>()); AddCallMetaMember(UserData.RegisterType<Color>());
AddCallMetaMember(UserData.RegisterType<Point>()); AddCallMetaMember(UserData.RegisterType<Point>());
AddCallMetaMember(UserData.RegisterType<Rectangle>());
AddCallMetaMember(UserData.RegisterType<SubmarineInfo>()); AddCallMetaMember(UserData.RegisterType<SubmarineInfo>());
#if SERVER #if SERVER
@@ -344,13 +352,24 @@ namespace Barotrauma
#elif CLIENT #elif CLIENT
UserData.RegisterType<LuaGUI>(); UserData.RegisterType<LuaGUI>();
UserData.RegisterType<ChatBox>(); UserData.RegisterType<ChatBox>();
UserData.RegisterType<GUICanvas>();
UserData.RegisterType<Anchor>(); UserData.RegisterType<Anchor>();
UserData.RegisterType<Alignment>();
UserData.RegisterType<Pivot>();
UserData.RegisterType<Texture2D>();
AddCallMetaMember(UserData.RegisterType<Sprite>());
AddCallMetaMember(UserData.RegisterType<GUILayoutGroup>()); AddCallMetaMember(UserData.RegisterType<GUILayoutGroup>());
AddCallMetaMember(UserData.RegisterType<GUITextBox>()); AddCallMetaMember(UserData.RegisterType<GUITextBox>());
AddCallMetaMember(UserData.RegisterType<GUITextBlock>());
AddCallMetaMember(UserData.RegisterType<GUIButton>()); AddCallMetaMember(UserData.RegisterType<GUIButton>());
AddCallMetaMember(UserData.RegisterType<RectTransform>()); AddCallMetaMember(UserData.RegisterType<RectTransform>());
AddCallMetaMember(UserData.RegisterType<GUIFrame>()); AddCallMetaMember(UserData.RegisterType<GUIFrame>());
AddCallMetaMember(UserData.RegisterType<GUITickBox>());
AddCallMetaMember(UserData.RegisterType<GUICustomComponent>());
AddCallMetaMember(UserData.RegisterType<GUIImage>());
AddCallMetaMember(UserData.RegisterType<GUIListBox>());
#endif #endif
lua = new Script(CoreModules.Preset_SoftSandbox); lua = new Script(CoreModules.Preset_SoftSandbox);
@@ -416,11 +435,14 @@ namespace Barotrauma
lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>(); lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>();
lua.Globals["RandSync"] = UserData.CreateStatic<Rand.RandSync>(); lua.Globals["RandSync"] = UserData.CreateStatic<Rand.RandSync>();
lua.Globals["SubmarineInfo"] = UserData.CreateStatic<SubmarineInfo>(); lua.Globals["SubmarineInfo"] = UserData.CreateStatic<SubmarineInfo>();
lua.Globals["Rectangle"] = UserData.CreateStatic<Rectangle>();
#if SERVER #if SERVER
#elif CLIENT #elif CLIENT
lua.Globals["GUI"] = new LuaGUI(this); lua.Globals["GUI"] = new LuaGUI(this);
lua.Globals["Sprite"] = UserData.CreateStatic<Sprite>();
#endif #endif