Improve UI elements (IMGUI)
This commit is contained in:
parent
7f63944a6e
commit
2db7b607f0
11 changed files with 37 additions and 132 deletions
|
@ -24,7 +24,7 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<bool> OnClick;
|
public event EventHandler<bool> OnClick;
|
||||||
|
|
||||||
public void OnGUI()
|
public override void OnGUI()
|
||||||
{
|
{
|
||||||
if (automaticLayout)
|
if (automaticLayout)
|
||||||
{
|
{
|
||||||
|
@ -42,34 +42,15 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The button's unique name.
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to display the button.
|
|
||||||
/// </summary>
|
|
||||||
public bool Enabled { get; set; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize a new button with automatic layout.
|
/// Initialize a new button with automatic layout.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to display on the button.</param>
|
/// <param name="text">The text to display on the button.</param>
|
||||||
/// <param name="name">The button's name.</param>
|
/// <param name="name">The button's name.</param>
|
||||||
public Button(string text, string name = null)
|
public Button(string text, string name = null) : base(text, name)
|
||||||
{
|
{
|
||||||
automaticLayout = true;
|
automaticLayout = true;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
if (name == null)
|
|
||||||
{
|
|
||||||
this.Name = typeof(Button).FullName + "::" + text;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Name = name;
|
|
||||||
}
|
|
||||||
IMGUIManager.AddElement(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -83,10 +64,5 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
automaticLayout = false;
|
automaticLayout = false;
|
||||||
this.Box = box;
|
this.Box = box;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Button()
|
|
||||||
{
|
|
||||||
IMGUIManager.RemoveElement(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rect Box { get; set; }
|
public Rect Box { get; set; }
|
||||||
|
|
||||||
public void OnGUI()
|
public override void OnGUI()
|
||||||
{
|
{
|
||||||
/*if (Constants.Default == null) return;
|
/*if (Constants.Default == null) return;
|
||||||
if (Constants.Default.box == null) return;*/
|
if (Constants.Default.box == null) return;*/
|
||||||
|
@ -60,16 +60,6 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
GUI.EndGroup();
|
GUI.EndGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The group's unique name.
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to display the group and everything in it.
|
|
||||||
/// </summary>
|
|
||||||
public bool Enabled { set; get; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of elements in the group.
|
/// The amount of elements in the group.
|
||||||
|
@ -85,19 +75,10 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// <param name="box">The rectangular area to use in the window.</param>
|
/// <param name="box">The rectangular area to use in the window.</param>
|
||||||
/// <param name="name">Name of the group.</param>
|
/// <param name="name">Name of the group.</param>
|
||||||
/// <param name="automaticLayout">Whether to use automatic UI layout.</param>
|
/// <param name="automaticLayout">Whether to use automatic UI layout.</param>
|
||||||
public Group(Rect box, string name = null, bool automaticLayout = false)
|
public Group(Rect box, string name = null, bool automaticLayout = false) : base(box.ToString().Replace(" ", ""), name)
|
||||||
{
|
{
|
||||||
Box = box;
|
Box = box;
|
||||||
if (name == null)
|
|
||||||
{
|
|
||||||
this.Name = typeof(Group).FullName + "::" + box.ToString().Replace(" ", "");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Name = name;
|
|
||||||
}
|
|
||||||
this.automaticLayout = automaticLayout;
|
this.automaticLayout = automaticLayout;
|
||||||
IMGUIManager.AddElement(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||||
using Svelto.Tasks;
|
using Svelto.Tasks;
|
||||||
using Svelto.Tasks.ExtraLean;
|
using Svelto.Tasks.ExtraLean;
|
||||||
using TechbloxModdingAPI.Tasks;
|
using TechbloxModdingAPI.Tasks;
|
||||||
|
using TechbloxModdingAPI.Utility;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace TechbloxModdingAPI.Interface.IMGUI
|
namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
|
@ -14,9 +15,9 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class IMGUIManager
|
public static class IMGUIManager
|
||||||
{
|
{
|
||||||
internal static OnGuiRunner ImguiScheduler = new OnGuiRunner("TechbloxModdingAPI_IMGUIScheduler");
|
internal static OnGuiRunner ImguiScheduler = new("TechbloxModdingAPI_IMGUIScheduler");
|
||||||
|
|
||||||
private static Dictionary<string, UIElement> _activeElements = new Dictionary<string,UIElement>();
|
private static readonly WeakDictionary<string, UIElement> _activeElements = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add an UIElement instance to be managed by IMGUIManager.
|
/// Add an UIElement instance to be managed by IMGUIManager.
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rect Box { get; set; } = Rect.zero;
|
public Rect Box { get; set; } = Rect.zero;
|
||||||
|
|
||||||
public void OnGUI()
|
public override void OnGUI()
|
||||||
{
|
{
|
||||||
//if (Texture == null) return;
|
//if (Texture == null) return;
|
||||||
if (automaticLayout)
|
if (automaticLayout)
|
||||||
|
@ -32,43 +32,16 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
GUI.Label(Box, Texture, Constants.Default.label);
|
GUI.Label(Box, Texture, Constants.Default.label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The image element's unique name.
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to display the image and everything in it.
|
|
||||||
/// </summary>
|
|
||||||
public bool Enabled { set; get; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Image"/> class with automatic layout.
|
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Image"/> class with automatic layout.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="texture">Image to display.</param>
|
/// <param name="texture">Image to display.</param>
|
||||||
/// <param name="name">The element's name.</param>
|
/// <param name="name">The element's name.</param>
|
||||||
public Image(Texture texture = null, string name = null)
|
public Image(Texture texture = null, string name = null) : base(texture == null ? "" : $"{texture.name}({texture.width}x{texture.height})", name)
|
||||||
{
|
{
|
||||||
automaticLayout = true;
|
automaticLayout = true;
|
||||||
Texture = texture;
|
Texture = texture;
|
||||||
if (name == null)
|
|
||||||
{
|
|
||||||
if (texture == null)
|
|
||||||
{
|
|
||||||
this.Name = typeof(Image).FullName + "::" + texture;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Name = typeof(Image).FullName + "::" + texture.name + "(" + texture.width + "x" + texture.height + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Name = name;
|
|
||||||
}
|
|
||||||
IMGUIManager.AddElement(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rect Box { get; set; } = Rect.zero;
|
public Rect Box { get; set; } = Rect.zero;
|
||||||
|
|
||||||
public void OnGUI()
|
public override void OnGUI()
|
||||||
{
|
{
|
||||||
if (automaticLayout)
|
if (automaticLayout)
|
||||||
{
|
{
|
||||||
|
@ -32,34 +32,15 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The label's unique name.
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to display the label.
|
|
||||||
/// </summary>
|
|
||||||
public bool Enabled { set; get; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Label"/> class with automatic layout.
|
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Label"/> class with automatic layout.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="initialText">Initial string to display on the label.</param>
|
/// <param name="initialText">Initial string to display on the label.</param>
|
||||||
/// <param name="name">The element's name.</param>
|
/// <param name="name">The element's name.</param>
|
||||||
public Label(string initialText = null, string name = null)
|
public Label(string initialText = null, string name = null) : base(initialText, name)
|
||||||
{
|
{
|
||||||
automaticLayout = true;
|
automaticLayout = true;
|
||||||
Text = initialText;
|
Text = initialText;
|
||||||
if (name == null)
|
|
||||||
{
|
|
||||||
this.Name = typeof(Label).FullName + "::" + initialText;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Name = name;
|
|
||||||
}
|
|
||||||
IMGUIManager.AddElement(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<string> OnEdit;
|
public event EventHandler<string> OnEdit;
|
||||||
|
|
||||||
public void OnGUI()
|
public override void OnGUI()
|
||||||
{
|
{
|
||||||
string editedText = null;
|
string editedText = null;
|
||||||
if (automaticLayout)
|
if (automaticLayout)
|
||||||
|
@ -61,36 +61,17 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The text field's unique name.
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to display the text field.
|
|
||||||
/// </summary>
|
|
||||||
public bool Enabled { set; get; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize the text input field with automatic layout.
|
/// Initialize the text input field with automatic layout.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="initialText">Initial text in the input field.</param>
|
/// <param name="initialText">Initial text in the input field.</param>
|
||||||
/// <param name="name">The text field's name.</param>
|
/// <param name="name">The text field's name.</param>
|
||||||
/// <param name="multiline">Allow multiple lines?</param>
|
/// <param name="multiline">Allow multiple lines?</param>
|
||||||
public Text(string initialText = null, string name = null, bool multiline = false)
|
public Text(string initialText = null, string name = null, bool multiline = false) : base(initialText, name)
|
||||||
{
|
{
|
||||||
this.Multiline = multiline;
|
this.Multiline = multiline;
|
||||||
automaticLayout = true;
|
automaticLayout = true;
|
||||||
text = initialText ?? "";
|
text = initialText ?? "";
|
||||||
if (name == null)
|
|
||||||
{
|
|
||||||
this.Name = typeof(Text).FullName + "::" + text;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Name = name;
|
|
||||||
}
|
|
||||||
IMGUIManager.AddElement(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -6,23 +6,34 @@ namespace TechbloxModdingAPI.Interface.IMGUI
|
||||||
/// GUI Element like a text field, button or picture.
|
/// GUI Element like a text field, button or picture.
|
||||||
/// This interface is used to wrap many elements from Unity's IMGUI system.
|
/// This interface is used to wrap many elements from Unity's IMGUI system.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface UIElement
|
public abstract class UIElement
|
||||||
{
|
{
|
||||||
|
protected UIElement(string text, string name)
|
||||||
|
{
|
||||||
|
Name = name ?? GetType().FullName + "::" + text;
|
||||||
|
IMGUIManager.AddElement(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
~UIElement()
|
||||||
|
{
|
||||||
|
IMGUIManager.RemoveElement(this);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GUI operations to perform in the OnGUI scope.
|
/// GUI operations to perform in the OnGUI scope.
|
||||||
/// This is basically equivalent to a MonoBehaviour's OnGUI method.
|
/// This is basically equivalent to a MonoBehaviour's OnGUI method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void OnGUI();
|
public abstract void OnGUI();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The element's name.
|
/// The element's name.
|
||||||
/// This should be unique for every instance of the class.
|
/// This should be unique for every instance of the class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to display the UI element or not.
|
/// Whether to display the UI element or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool Enabled { get; }
|
public bool Enabled { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -195,8 +195,8 @@ namespace TechbloxModdingAPI
|
||||||
/// The player's mass.
|
/// The player's mass.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The mass.</value>
|
/// <value>The mass.</value>
|
||||||
public float Mass =>
|
[Obsolete] // We cannot get it clientside or something
|
||||||
1f / playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().physicsMass.InverseMass;
|
public float Mass => 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The player's latest network ping time.
|
/// The player's latest network ping time.
|
||||||
|
|
|
@ -139,7 +139,7 @@ namespace TechbloxModdingAPI.Players
|
||||||
group = default;
|
group = default;
|
||||||
if (GameState.IsBuildMode())
|
if (GameState.IsBuildMode())
|
||||||
return entitiesDB.QueryEntityOptional<T>(new EGID(playerId, LocalBuildingDrone.BuildGroup));
|
return entitiesDB.QueryEntityOptional<T>(new EGID(playerId, LocalBuildingDrone.BuildGroup));
|
||||||
|
|
||||||
var characterGroups = CharacterExclusiveGroups.AllCharacters;
|
var characterGroups = CharacterExclusiveGroups.AllCharacters;
|
||||||
for (int i = 0; i < characterGroups.count; i++)
|
for (int i = 0; i < characterGroups.count; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,9 +73,10 @@ namespace TechbloxModdingAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete] //Cannot get mass even from UECS
|
||||||
public float Mass
|
public float Mass
|
||||||
{
|
{
|
||||||
get => 0f; //TODO: Get mass from UECS entity
|
get => 0f;
|
||||||
//set => GetStruct().physicsMass.InverseMass = math.rcp(value);
|
//set => GetStruct().physicsMass.InverseMass = math.rcp(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ namespace TechbloxModdingAPI.Tests
|
||||||
/*((FasterList<GuiInputMap.GuiInputMapElement>)AccessTools.Property(typeof(GuiInputMap), "GuiInputsButtonDown").GetValue(null))
|
/*((FasterList<GuiInputMap.GuiInputMapElement>)AccessTools.Property(typeof(GuiInputMap), "GuiInputsButtonDown").GetValue(null))
|
||||||
.Add(new GuiInputMap.GuiInputMapElement(RewiredConsts.Action.ToggleCommandLine, GuiIn))*/
|
.Add(new GuiInputMap.GuiInputMapElement(RewiredConsts.Action.ToggleCommandLine, GuiIn))*/
|
||||||
|
|
||||||
Game.Enter += (sender, e) =>
|
/*Game.Enter += (sender, e) =>
|
||||||
{
|
{
|
||||||
ushort lastKey = ushort.MaxValue;
|
ushort lastKey = ushort.MaxValue;
|
||||||
foreach (var kv in FullGameFields._dataDb.GetValues<CubeListData>()
|
foreach (var kv in FullGameFields._dataDb.GetValues<CubeListData>()
|
||||||
|
@ -299,7 +299,7 @@ namespace TechbloxModdingAPI.Tests
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
.Aggregate((a, b) => a + "\n" + b));
|
.Aggregate((a, b) => a + "\n" + b));
|
||||||
};
|
};*/
|
||||||
|
|
||||||
CommandBuilder.Builder("takeScreenshot", "Enables the screenshot taker")
|
CommandBuilder.Builder("takeScreenshot", "Enables the screenshot taker")
|
||||||
.Action(() =>
|
.Action(() =>
|
||||||
|
@ -368,7 +368,7 @@ namespace TechbloxModdingAPI.Tests
|
||||||
}, () => shouldTestGhostBlock));
|
}, () => shouldTestGhostBlock));
|
||||||
Logging.CommandLog("Test enabled");
|
Logging.CommandLog("Test enabled");
|
||||||
}).Build();
|
}).Build();
|
||||||
|
|
||||||
Client.EnterMenu += (sender, args) => Scheduler.Schedule(new Once(() => Client.Instance.CloseBetaPopup()));
|
Client.EnterMenu += (sender, args) => Scheduler.Schedule(new Once(() => Client.Instance.CloseBetaPopup()));
|
||||||
|
|
||||||
Game.Enter += (sender, args) =>
|
Game.Enter += (sender, args) =>
|
||||||
|
|
Loading…
Reference in a new issue