mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Added EditorFlags: Hide entities in hierarchy and editor scene
- Also some Style changes
This commit is contained in:
@@ -5,6 +5,7 @@ Dependencies = {corlib = "*", GlitchLog = "*", GlitchyEngine = "*"}
|
|||||||
Name = "GlitchyEditor"
|
Name = "GlitchyEditor"
|
||||||
TargetType = "BeefGUIApplication"
|
TargetType = "BeefGUIApplication"
|
||||||
StartupObject = "GlitchyEngine.Program"
|
StartupObject = "GlitchyEngine.Program"
|
||||||
|
ProcessorMacros = ["GE_EDITOR_IMGUI_DEMO"]
|
||||||
|
|
||||||
[Configs.Debug.Win64]
|
[Configs.Debug.Win64]
|
||||||
PostBuildCmds = ["CopyFilesIfNewer(\"$(WorkspaceDir)/bin/vswhere.exe\", \"$(TargetDir)\")"]
|
PostBuildCmds = ["CopyFilesIfNewer(\"$(WorkspaceDir)/bin/vswhere.exe\", \"$(TargetDir)\")"]
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -6,6 +6,9 @@ using System.Collections;
|
|||||||
using GlitchyEngine;
|
using GlitchyEngine;
|
||||||
using GlitchyEngine.Core;
|
using GlitchyEngine.Core;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using GlitchyEngine.World.Components;
|
||||||
|
using GlitchyEngine.Renderer;
|
||||||
|
using GlitchyEngine.Math;
|
||||||
|
|
||||||
namespace GlitchyEditor.EditWindows
|
namespace GlitchyEditor.EditWindows
|
||||||
{
|
{
|
||||||
@@ -362,11 +365,76 @@ namespace GlitchyEditor.EditWindows
|
|||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowVisibilityButton(Entity entity)
|
||||||
|
{
|
||||||
|
ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(0, 2));
|
||||||
|
ImGui.PushStyleVar(.ItemInnerSpacing, ImGui.Vec2(0, 0));
|
||||||
|
ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0));
|
||||||
|
|
||||||
|
let colors = ImGui.GetStyle().Colors;
|
||||||
|
|
||||||
|
ImGui.Vec4 hoveredColor = colors[(int)ImGui.Col.ButtonHovered];
|
||||||
|
hoveredColor.w = 0.5f;
|
||||||
|
|
||||||
|
ImGui.Vec4 activeColor = colors[(int)ImGui.Col.ButtonActive];
|
||||||
|
activeColor.w = 0.5f;
|
||||||
|
|
||||||
|
ImGui.PushStyleColor(.ButtonHovered, hoveredColor);
|
||||||
|
ImGui.PushStyleColor(.ButtonActive, activeColor);
|
||||||
|
|
||||||
|
if (entity.TryGetComponent<EditorFlagsComponent>(let flags))
|
||||||
|
{
|
||||||
|
bool hidden = flags.Flags.HasFlag(.HideInScene);
|
||||||
|
|
||||||
|
SubTexture2D icon = hidden ? EditorIcons.Instance.Entity_Hidden : EditorIcons.Instance.Entity_Visible;
|
||||||
|
|
||||||
|
ImGui.Vec4 tintColor = hidden ? *ImGui.GetStyleColorVec4(.TextDisabled) : *ImGui.GetStyleColorVec4(.Text);
|
||||||
|
|
||||||
|
if (ImGui.ImageButtonEx(ImGui.GetID("visibilityToggle"), icon, .(16, 16), .Zero, .Ones, .Zero, tintColor))
|
||||||
|
{
|
||||||
|
flags.Flags ^= .HideInScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.IsItemHovered())
|
||||||
|
{
|
||||||
|
ImGui.BeginTooltip();
|
||||||
|
|
||||||
|
if (hidden)
|
||||||
|
{
|
||||||
|
ImGui.TextUnformatted("Entity is hidden. Click to show the entity.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui.TextUnformatted("Entity is visible. Click to hide the entity.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndTooltip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.PopStyleColor(3);
|
||||||
|
ImGui.PopStyleVar(2);
|
||||||
|
}
|
||||||
|
|
||||||
private void ImGuiPrintEntityTree(TreeNode<Entity> tree)
|
private void ImGuiPrintEntityTree(TreeNode<Entity> tree)
|
||||||
{
|
{
|
||||||
|
Entity entity = tree.Value;
|
||||||
|
|
||||||
|
if (entity.EditorFlags.HasFlag(.HideInHierarchy))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ImGui.PushID(entity.UUID.GetHashCode());
|
||||||
|
|
||||||
|
ImGui.TableNextRow();
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
|
||||||
|
ShowVisibilityButton(entity);
|
||||||
|
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
|
||||||
String name = null;
|
String name = null;
|
||||||
|
|
||||||
var nameComponent = tree.Value.GetComponent<NameComponent>();
|
var nameComponent = entity.GetComponent<NameComponent>();
|
||||||
|
|
||||||
if(nameComponent != null)
|
if(nameComponent != null)
|
||||||
{
|
{
|
||||||
@@ -374,44 +442,42 @@ namespace GlitchyEditor.EditWindows
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
name = scope:: $"Entity {(tree.Value.Handle.[Friend]Index)}";
|
name = scope:: $"Entity {(entity.Handle.[Friend]Index)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.TreeNodeFlags flags = .OpenOnArrow | .DefaultOpen | .SpanAvailWidth | .OpenOnDoubleClick;
|
ImGui.TreeNodeFlags flags = .OpenOnArrow | .DefaultOpen | .SpanAllColumns | .OpenOnDoubleClick;
|
||||||
|
|
||||||
if(tree.Children.Count == 0)
|
if(tree.Children.Count == 0)
|
||||||
flags |= .Leaf;
|
flags |= .Leaf;
|
||||||
|
|
||||||
bool inSelectedList = IsEntitySelected(tree.Value);
|
bool inSelectedList = IsEntitySelected(entity);
|
||||||
|
|
||||||
if(inSelectedList)
|
if(inSelectedList)
|
||||||
flags |= .Selected;
|
flags |= .Selected;
|
||||||
|
|
||||||
if (_entitiesToUnfold.Contains(tree.Value))
|
if (_entitiesToUnfold.Contains(entity))
|
||||||
{
|
{
|
||||||
_entitiesToUnfold.Remove(tree.Value);
|
_entitiesToUnfold.Remove(entity);
|
||||||
|
|
||||||
ImGui.SetNextItemOpen(true, .None);
|
ImGui.SetNextItemOpen(true, .None);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isOpen = ImGui.TreeNodeEx((void*)(uint)tree.Value.Handle.[Friend]Index, flags, $"{name}");
|
bool isOpen = ImGui.TreeNodeEx((void*)(uint)entity.Handle.[Friend]Index, flags, $"{name}");
|
||||||
|
|
||||||
if (_entityToHighlight == tree.Value)
|
if (_entityToHighlight == entity)
|
||||||
{
|
{
|
||||||
ImGui.SetScrollHereY(0);
|
ImGui.SetScrollHereY(0);
|
||||||
_entityToHighlight = .();
|
_entityToHighlight = .();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.PushID((void*)(uint)tree.Value.Handle.[Friend]Index);
|
|
||||||
|
|
||||||
bool deleted = false;
|
bool deleted = false;
|
||||||
|
|
||||||
if (ImGui.BeginPopupContextItem("treeNodePopup"))
|
if (ImGui.BeginPopupContextItem("treeNodePopup"))
|
||||||
{
|
{
|
||||||
// Only select if it isn't already selected, because it otherwise clears the selection when ctrl is released
|
// Only select if it isn't already selected, because it otherwise clears the selection when ctrl is released
|
||||||
if (!IsEntitySelected(tree.Value))
|
if (!IsEntitySelected(entity))
|
||||||
{
|
{
|
||||||
SelectEntity(tree.Value, !ImGui.GetIO().KeyCtrl);
|
SelectEntity(entity, !ImGui.GetIO().KeyCtrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowEntityContextMenu(out deleted);
|
ShowEntityContextMenu(out deleted);
|
||||||
@@ -419,8 +485,6 @@ namespace GlitchyEditor.EditWindows
|
|||||||
ImGui.EndPopup();
|
ImGui.EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.PopID();
|
|
||||||
|
|
||||||
if (deleted)
|
if (deleted)
|
||||||
{
|
{
|
||||||
if (isOpen)
|
if (isOpen)
|
||||||
@@ -435,7 +499,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
{
|
{
|
||||||
isDragged = true;
|
isDragged = true;
|
||||||
|
|
||||||
UUID id = tree.Value.UUID;
|
UUID id = entity.UUID;
|
||||||
ImGui.SetDragDropPayload(.Entity, &id, sizeof(UUID));
|
ImGui.SetDragDropPayload(.Entity, &id, sizeof(UUID));
|
||||||
|
|
||||||
ImGui.Text(name);
|
ImGui.Text(name);
|
||||||
@@ -443,7 +507,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
ImGui.EndDragDropSource();
|
ImGui.EndDragDropSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityDropTarget(tree.Value);
|
EntityDropTarget(entity);
|
||||||
|
|
||||||
bool clicked = ImGui.IsItemClicked() && !ImGui.IsItemToggledOpen();
|
bool clicked = ImGui.IsItemClicked() && !ImGui.IsItemToggledOpen();
|
||||||
bool clickedRight = ImGui.IsItemClicked(.Right);
|
bool clickedRight = ImGui.IsItemClicked(.Right);
|
||||||
@@ -461,17 +525,19 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
if (clicked || clickedRight)
|
if (clicked || clickedRight)
|
||||||
{
|
{
|
||||||
lastClickedEntity = tree.Value;
|
lastClickedEntity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDragged && (hovered && !ImGui.IsMouseDown(.Left) && !ImGui.IsMouseDown(.Right)) && tree.Value == lastClickedEntity)
|
if (!isDragged && (hovered && !ImGui.IsMouseDown(.Left) && !ImGui.IsMouseDown(.Right)) && entity == lastClickedEntity)
|
||||||
{
|
{
|
||||||
if (!inSelectedList)
|
if (!inSelectedList)
|
||||||
{
|
{
|
||||||
SelectEntity(tree.Value, !ImGui.GetIO().KeyCtrl);
|
SelectEntity(entity, !ImGui.GetIO().KeyCtrl);
|
||||||
inSelectedList = true;
|
inSelectedList = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EntityDropTarget(Entity target)
|
private void EntityDropTarget(Entity target)
|
||||||
@@ -565,37 +631,41 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
InsertIntoTree(entity);
|
InsertIntoTree(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ImGui.TreeNodeEx("Scene", .DefaultOpen))
|
ImGui.Rect rect = .();
|
||||||
|
rect.Min = (ImGui.Vec2)((float2)ImGui.GetWindowContentRegionMin() + (float2)ImGui.GetWindowPos());
|
||||||
|
rect.Max = (ImGui.Vec2)((float2)rect.Min + (float2)ImGui.GetContentRegionAvail());
|
||||||
|
|
||||||
|
if(ImGui.BeginDragDropTargetCustom(rect, ImGui.GetID("sceneDropTarget")))
|
||||||
{
|
{
|
||||||
if(ImGui.BeginDragDropTarget())
|
Payload<UUID>? payload = ImGui.AcceptDragDropPayload<UUID>(.Entity);
|
||||||
|
|
||||||
|
if(payload != null)
|
||||||
{
|
{
|
||||||
Payload<UUID>? payload = ImGui.AcceptDragDropPayload<UUID>(.Entity);
|
UUID movedEntityId = payload->Data;
|
||||||
|
|
||||||
|
Entity movedEntity = _editor.CurrentScene.GetEntityByID(movedEntityId);
|
||||||
|
|
||||||
if(payload != null)
|
var transformComponent = movedEntity.GetComponent<TransformComponent>();
|
||||||
{
|
transformComponent.Parent = .InvalidEntity;
|
||||||
UUID movedEntityId = payload->Data;
|
|
||||||
|
|
||||||
Entity movedEntity = _editor.CurrentScene.GetEntityByID(movedEntityId);
|
|
||||||
|
|
||||||
// Also mark transform as dirty
|
|
||||||
var transformComponent = movedEntity.GetComponent<TransformComponent>();
|
|
||||||
transformComponent.Parent = .InvalidEntity;
|
|
||||||
//transformComponent?.IsDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui.EndDragDropTarget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.EndDragDropTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.BeginTable("entityTable", 2, .RowBg | .NoBordersInBody | .SizingFixedFit))
|
||||||
|
{
|
||||||
|
ImGui.TableSetupColumn("Visibility", .IndentDisable | .NoResize);
|
||||||
|
ImGui.TableSetupColumn("Entities", .IndentEnable | .WidthStretch);
|
||||||
|
|
||||||
for(var child in root.Children)
|
for(var child in root.Children)
|
||||||
{
|
{
|
||||||
ImGuiPrintEntityTree(child);
|
ImGuiPrintEntityTree(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.TreePop();
|
ImGui.EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Show search results as flat list
|
// Show search results as flat list
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ namespace GlitchyEditor
|
|||||||
{
|
{
|
||||||
class EditorIcons : RefCounted
|
class EditorIcons : RefCounted
|
||||||
{
|
{
|
||||||
|
private static EditorIcons _editorIcons;
|
||||||
|
|
||||||
AssetHandle<Texture2D> _texture;
|
AssetHandle<Texture2D> _texture;
|
||||||
|
|
||||||
public SubTexture2D DirectionalLight ~ _.ReleaseRef();
|
public SubTexture2D DirectionalLight ~ _.ReleaseRef();
|
||||||
@@ -27,6 +29,10 @@ namespace GlitchyEditor
|
|||||||
public SubTexture2D File_Material ~ _.ReleaseRef();
|
public SubTexture2D File_Material ~ _.ReleaseRef();
|
||||||
public SubTexture2D File_CSharpScript ~ _.ReleaseRef();
|
public SubTexture2D File_CSharpScript ~ _.ReleaseRef();
|
||||||
public SubTexture2D File_Shader ~ _.ReleaseRef();
|
public SubTexture2D File_Shader ~ _.ReleaseRef();
|
||||||
|
public SubTexture2D Entity_Visible ~ _.ReleaseRef();
|
||||||
|
public SubTexture2D Entity_Hidden ~ _.ReleaseRef();
|
||||||
|
|
||||||
|
public static EditorIcons Instance => _editorIcons;
|
||||||
|
|
||||||
public SamplerState SamplerState
|
public SamplerState SamplerState
|
||||||
{
|
{
|
||||||
@@ -36,6 +42,8 @@ namespace GlitchyEditor
|
|||||||
|
|
||||||
public this(String texturePath, float2 iconSize)
|
public this(String texturePath, float2 iconSize)
|
||||||
{
|
{
|
||||||
|
_editorIcons = this;
|
||||||
|
|
||||||
_texture = Content.LoadAsset(texturePath, null, true);
|
_texture = Content.LoadAsset(texturePath, null, true);
|
||||||
|
|
||||||
float2 pen = .();
|
float2 pen = .();
|
||||||
@@ -57,6 +65,13 @@ namespace GlitchyEditor
|
|||||||
File_Material = GetNextGridTexture(ref pen, iconSize);
|
File_Material = GetNextGridTexture(ref pen, iconSize);
|
||||||
File_CSharpScript = GetNextGridTexture(ref pen, iconSize);
|
File_CSharpScript = GetNextGridTexture(ref pen, iconSize);
|
||||||
File_Shader = GetNextGridTexture(ref pen, iconSize);
|
File_Shader = GetNextGridTexture(ref pen, iconSize);
|
||||||
|
Entity_Visible = GetNextGridTexture(ref pen, iconSize);
|
||||||
|
Entity_Hidden = GetNextGridTexture(ref pen, iconSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ~this()
|
||||||
|
{
|
||||||
|
_editorIcons = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SubTexture2D GetNextGridTexture(ref float2 pen, float2 iconSize)
|
private SubTexture2D GetNextGridTexture(ref float2 pen, float2 iconSize)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", FreeType = "*", cg
|
|||||||
|
|
||||||
[Project]
|
[Project]
|
||||||
Name = "GlitchyEngine"
|
Name = "GlitchyEngine"
|
||||||
ProcessorMacros = ["GE_GRAPHICS_DX11", "GE_SHADER_MATRIX_MISMATCH_IS_ERROR", "GE_SHADER_VAR_TYPE_MISMATCH_IS_ERROR", "GE_SHADER_UNUSED_VARIABLE_IS_WARNING", "GE_WINDOWS"]
|
ProcessorMacros = ["GE_GRAPHICS_DX11", "GE_SHADER_MATRIX_MISMATCH_IS_ERROR", "GE_SHADER_VAR_TYPE_MISMATCH_IS_ERROR", "GE_SHADER_UNUSED_VARIABLE_IS_WARNING", "GE_WINDOWS", "GE_EDITOR"]
|
||||||
|
|
||||||
[Configs.Paranoid.Win32]
|
[Configs.Paranoid.Win32]
|
||||||
PreprocessorMacros = ["DEBUG", "PARANOID", "GE_WINDOWS"]
|
PreprocessorMacros = ["DEBUG", "PARANOID", "GE_WINDOWS"]
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace GlitchyEngine.Editor;
|
||||||
|
|
||||||
|
enum EditorFlags
|
||||||
|
{
|
||||||
|
Default = 0,
|
||||||
|
HideInHierarchy = 1,
|
||||||
|
HideInScene = 2,
|
||||||
|
}
|
||||||
@@ -138,7 +138,9 @@ namespace ImGui
|
|||||||
public static void TextUnformatted(StringView text) => TextUnformattedImpl(text.Ptr, text.Ptr + text.Length);
|
public static void TextUnformatted(StringView text) => TextUnformattedImpl(text.Ptr, text.Ptr + text.Length);
|
||||||
|
|
||||||
public static void PushID(StringView id) => PushID(id.Ptr, id.Ptr + id.Length);
|
public static void PushID(StringView id) => PushID(id.Ptr, id.Ptr + id.Length);
|
||||||
|
|
||||||
|
public static void PushID(int id) => PushID((void*)id);
|
||||||
|
|
||||||
/// Releases references that accumulated calls like ImGui::Image
|
/// Releases references that accumulated calls like ImGui::Image
|
||||||
protected internal static extern void CleanupFrame();
|
protected internal static extern void CleanupFrame();
|
||||||
|
|
||||||
|
|||||||
@@ -136,6 +136,8 @@ namespace GlitchyEngine.ImGui
|
|||||||
colors[(.)ImGui.Col.Tab] = ImGui.Vec4(0.473f, 0.519f, 0.580f, 1.00f);
|
colors[(.)ImGui.Col.Tab] = ImGui.Vec4(0.473f, 0.519f, 0.580f, 1.00f);
|
||||||
colors[(.)ImGui.Col.TabUnfocused] = ImGui.Vec4(0.255f, 0.255f, 0.255f, 1.00f);
|
colors[(.)ImGui.Col.TabUnfocused] = ImGui.Vec4(0.255f, 0.255f, 0.255f, 1.00f);
|
||||||
colors[(.)ImGui.Col.CheckMark] = ImGui.Vec4(0.851f, 0.863f, 0.900f, 1.00f);
|
colors[(.)ImGui.Col.CheckMark] = ImGui.Vec4(0.851f, 0.863f, 0.900f, 1.00f);
|
||||||
|
colors[(.)ImGui.Col.TitleBg] = ImGui.Vec4(0.406f, 0.401f, 0.390f, 1.000f);
|
||||||
|
colors[(.)ImGui.Col.TitleBgActive] = ImGui.Vec4(0.196f, 0.192f, 0.182f, 1.000f);
|
||||||
|
|
||||||
/*colors[(.)ImGui.Col.Text] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 1.00f);
|
/*colors[(.)ImGui.Col.Text] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||||
colors[(.)ImGui.Col.TextDisabled] = ImGui.Vec4(0.60f, 0.60f, 0.60f, 1.00f);
|
colors[(.)ImGui.Col.TextDisabled] = ImGui.Vec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ using System.Collections;
|
|||||||
using Box2D;
|
using Box2D;
|
||||||
using GlitchyEngine.Scripting;
|
using GlitchyEngine.Scripting;
|
||||||
using GlitchyEngine.Serialization;
|
using GlitchyEngine.Serialization;
|
||||||
|
using GlitchyEngine.Editor;
|
||||||
|
using GlitchyEngine.World.Components;
|
||||||
|
|
||||||
namespace GlitchyEngine.Scripting;
|
namespace GlitchyEngine.Scripting;
|
||||||
|
|
||||||
@@ -187,6 +189,23 @@ static class ScriptGlue
|
|||||||
component = null;
|
component = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the entity. Returns true, if the entity was found.
|
||||||
|
static bool TryGetEntitySafe(UUID entityId, out Entity entity)
|
||||||
|
{
|
||||||
|
entity = default;
|
||||||
|
|
||||||
|
Result<Entity> foundEntity = ScriptEngine.Context.GetEntityByID(entityId);
|
||||||
|
|
||||||
|
if (foundEntity case .Ok(out entity))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.ClientLogger.Error($"No entity with ID {entityId} found.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Exception Helpers
|
#region Exception Helpers
|
||||||
|
|
||||||
@@ -461,6 +480,25 @@ static class ScriptGlue
|
|||||||
|
|
||||||
Mono.mono_free(rawName);
|
Mono.mono_free(rawName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RegisterCall("ScriptGlue::Entity_GetEditorFlags")]
|
||||||
|
static void Entity_GetEditorFlags(UUID entityId, out EditorFlags editorFlags)
|
||||||
|
{
|
||||||
|
editorFlags = .Default;
|
||||||
|
#if GE_EDITOR
|
||||||
|
if (TryGetEntitySafe(entityId, let entity))
|
||||||
|
editorFlags = entity.EditorFlags;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
[RegisterCall("ScriptGlue::Entity_SetEditorFlags")]
|
||||||
|
static void Entity_SetEditorFlags(UUID entityId, EditorFlags editorFlags)
|
||||||
|
{
|
||||||
|
#if GE_EDITOR
|
||||||
|
if (TryGetEntitySafe(entityId, let entity))
|
||||||
|
entity.EditorFlags = editorFlags;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
using GlitchyEngine.Editor;
|
||||||
|
namespace GlitchyEngine.World.Components;
|
||||||
|
|
||||||
|
struct EditorFlagsComponent
|
||||||
|
{
|
||||||
|
public EditorFlags Flags;
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using GlitchyEngine.Core;
|
using GlitchyEngine.Core;
|
||||||
|
using GlitchyEngine.Editor;
|
||||||
|
using GlitchyEngine.World.Components;
|
||||||
|
|
||||||
using internal GlitchyEngine.World;
|
using internal GlitchyEngine.World;
|
||||||
|
|
||||||
@@ -74,6 +76,22 @@ namespace GlitchyEngine.World
|
|||||||
|
|
||||||
public TransformComponent* Transform => GetComponent<TransformComponent>();
|
public TransformComponent* Transform => GetComponent<TransformComponent>();
|
||||||
|
|
||||||
|
public EditorFlags EditorFlags
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (TryGetComponent<EditorFlagsComponent>(let flagsComponent))
|
||||||
|
return flagsComponent.Flags;
|
||||||
|
|
||||||
|
return .Default;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (TryGetComponent<EditorFlagsComponent>(let flagsComponent))
|
||||||
|
flagsComponent.Flags = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public T* AddComponent<T>(T value = T()) where T: struct, new
|
public T* AddComponent<T>(T value = T()) where T: struct, new
|
||||||
{
|
{
|
||||||
Log.EngineLogger.AssertDebug(!HasComponent<T>(), scope $"Entity already has component.");
|
Log.EngineLogger.AssertDebug(!HasComponent<T>(), scope $"Entity already has component.");
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace GlitchyEngine.Editor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Flags to controls the visibility of the entity in the editor and how it can be interacted with for editing.
|
||||||
|
/// </summary>
|
||||||
|
public enum EditorFlags : byte
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The default behaviour: The entity is visible in the hierarchy and in the scene, and can be interacted with.
|
||||||
|
/// </summary>
|
||||||
|
Default = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// The entity is hidden in the hierarchy.
|
||||||
|
/// </summary>
|
||||||
|
HideInHierarchy = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// The entity is hidden in the scene.
|
||||||
|
/// </summary>
|
||||||
|
HideInScene = 2,
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ using GlitchyEngine.Core;
|
|||||||
using GlitchyEngine.Extensions;
|
using GlitchyEngine.Extensions;
|
||||||
using GlitchyEngine.Physics;
|
using GlitchyEngine.Physics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using GlitchyEngine.Editor;
|
||||||
|
|
||||||
namespace GlitchyEngine;
|
namespace GlitchyEngine;
|
||||||
|
|
||||||
@@ -23,6 +24,19 @@ public class Entity : EngineObject
|
|||||||
get => ScriptGlue.Entity_GetName(_uuid);
|
get => ScriptGlue.Entity_GetName(_uuid);
|
||||||
set => ScriptGlue.Entity_SetName(_uuid, value);
|
set => ScriptGlue.Entity_SetName(_uuid, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the <see cref="EditorFlags"/> of the <see cref="Entity"/>, which specify how the <see cref="Entity"/> is displayed and interacted with in the editor.
|
||||||
|
/// </summary>
|
||||||
|
public EditorFlags EditorFlags
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
ScriptGlue.Entity_GetEditorFlags(_uuid, out EditorFlags flags);
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
set => ScriptGlue.Entity_SetEditorFlags(_uuid, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only to be called by the engine. Don't call this constructor yourself, it will not result in a valid <see cref="Entity"/>.
|
/// Only to be called by the engine. Don't call this constructor yourself, it will not result in a valid <see cref="Entity"/>.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using GlitchyEngine.Core;
|
using GlitchyEngine.Core;
|
||||||
|
using GlitchyEngine.Editor;
|
||||||
using GlitchyEngine.Math;
|
using GlitchyEngine.Math;
|
||||||
using GlitchyEngine.Physics;
|
using GlitchyEngine.Physics;
|
||||||
using GlitchyEngine.Serialization;
|
using GlitchyEngine.Serialization;
|
||||||
@@ -64,6 +65,12 @@ internal static class ScriptGlue
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
public static extern string Entity_SetName(UUID entityId, string name);
|
public static extern string Entity_SetName(UUID entityId, string name);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
|
public static extern void Entity_GetEditorFlags(UUID uuid, out EditorFlags flags);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
|
public static extern void Entity_SetEditorFlags(UUID uuid, EditorFlags editorFlags);
|
||||||
|
|
||||||
#endregion Entity
|
#endregion Entity
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user