Basic save component button

This commit is contained in:
Simon Lübeß
2024-06-23 00:27:20 +02:00
parent cd434d64f9
commit 1b130a4bce
8 changed files with 136 additions and 15 deletions
@@ -116,9 +116,17 @@ namespace GlitchyEditor.EditWindows
bool nodeOpen = ImGui.CollapsingHeader(header.CStr(), .DefaultOpen | .AllowOverlap | .Framed | .SpanFullWidth);
ImGui.PushID(header.CStr());
defer { ImGui.PopID(); }
float positionX = ImGui.GetWindowContentRegionMax().x;
float2 buttonSize = (.)ImGui.CalcTextSize("...");
if (showComponentContextMenu != null)
{
ImGui.SameLine(ImGui.GetWindowContentRegionMax().x - ImGui.CalcTextSize("...").x - 2 * ImGui.GetStyle().FramePadding.x);
positionX -= buttonSize.X + 2 * ImGui.GetStyle().FramePadding.x;
ImGui.SameLine(positionX);
if (ImGui.SmallButton("..."))
{
@@ -133,6 +141,79 @@ namespace GlitchyEditor.EditWindows
}
}
if (ImGui.BeginPopupModal("Create new entity?###CopyNewEntityToEditor"))
{
//ImGui.Text("This entity only exists in play mode. Do you want to copy only this component, or all components?");
ImGui.Text("This entity only exists in play mode. Saving will create an entity that only contains this component.");
//if (ImGui.Button("Copy only this component"))
if (ImGui.Button("Ok"))
{
Entity editorEntity = Editor.Instance.EditorScene.CreateEntity(entity.Name, entity.UUID);
Scene.CopyComponent<TComponent>(entity, editorEntity);
if (typeof(TComponent) == typeof(ScriptComponent))
{
// TODO: Copy script data into editor
// TODO: Somehow get the scriptserializer used to serialize the editor scene
//scriptSerializer.SerializeScriptInstance(((ScriptComponent*)component).Instance);
}
ImGui.CloseCurrentPopup();
}
ImGui.SameLine();
// TODO!
/*if (ImGui.Button("Copy all components"))
{
ImGui.CloseCurrentPopup();
}
ImGui.SameLine();
*/
if (ImGui.Button("Cancel"))
{
ImGui.CloseCurrentPopup();
}
ImGui.EndPopup();
}
if (ScriptEngine.ApplicationInfo.IsInPlayMode)
{
positionX -= buttonSize.X + 1 * ImGui.GetStyle().FramePadding.x;
ImGui.SameLine(positionX);
float2 imageButtonSize = (.)buttonSize;
imageButtonSize.X -= ImGui.GetStyle().FramePadding.x * 2;
imageButtonSize.Y -= ImGui.GetStyle().FramePadding.y * 2;
//if (ImGui.ImageButton("save", EditorIcons.Instance.Save, (.)imageButtonSize))
if (ImGui.SmallButton("Save"))
{
if (Entity editorEntity = Editor.Instance.EditorScene.GetEntityByID(entity.UUID))
{
Scene.CopyComponent<TComponent>(entity, editorEntity);
if (typeof(TComponent) == typeof(ScriptComponent))
{
// TODO: Copy script data into editor
// TODO: Somehow get the scriptserializer used to serialize the editor scene
//scriptSerializer.SerializeScriptInstance(((ScriptComponent*)component).Instance);
}
}
else
{
ImGui.OpenPopup("###CopyNewEntityToEditor");
}
}
ImGui.AttachTooltip("Save component to edit mode.");
}
if (nodeOpen && ImGui.BeginPropertyTable("properties", TableId))
{
if (entity.TryGetComponent<TComponent>(let actualComponent))
+16 -8
View File
@@ -11,7 +11,8 @@ namespace GlitchyEditor
{
class Editor
{
private Scene _scene;
private Scene _activeScene;
private Scene _editorScene;
private EditorContentManager _contentManager;
private AssetThumbnailManager _thumbnailManager;
@@ -31,17 +32,23 @@ namespace GlitchyEditor
public Scene CurrentScene
{
get => _scene;
get => _activeScene;
set
{
if (_scene == value)
if (_activeScene == value)
return;
_scene = value;
_entityHierarchyWindow.SetContext(_scene);
_activeScene = value;
_entityHierarchyWindow.SetContext(_activeScene);
}
}
public Scene EditorScene
{
get => _editorScene;
set => _editorScene = value;
}
public EditorContentManager ContentManager => _contentManager;
public AssetThumbnailManager ThumbnailManager => _thumbnailManager;
@@ -73,12 +80,13 @@ namespace GlitchyEditor
public static Editor Instance => s_Instance;
/// Creates a new editor for the given world
public this(Scene scene, EditorContentManager contentManager, AssetThumbnailManager thumbnailManager)
public this(Scene activeScene, Scene editorScene, EditorContentManager contentManager, AssetThumbnailManager thumbnailManager)
{
Log.EngineLogger.AssertDebug(s_Instance == null, "Cannot create a second instance of a singleton.");
s_Instance = this;
_scene = scene;
_activeScene = activeScene;
_editorScene = editorScene;
_contentManager = contentManager;
_thumbnailManager = thumbnailManager;
@@ -94,7 +102,7 @@ namespace GlitchyEditor
{
_sceneViewportWindow = new EditorViewportWindow(this);
_gameViewportWindow = new GameViewportWindow(this);
_entityHierarchyWindow = new EntityHierarchyWindow(this, _scene);
_entityHierarchyWindow = new EntityHierarchyWindow(this, _activeScene);
_componentEditWindow = new ComponentEditWindow();
_contentBrowserWindow = new ContentBrowserWindow(this, (.)Application.Instance.ContentManager, _thumbnailManager);
_inspectorWindow = new InspectorWindow(this);
+2
View File
@@ -31,6 +31,7 @@ namespace GlitchyEditor
public SubTexture2D File_Shader ~ _.ReleaseRef();
public SubTexture2D Entity_Visible ~ _.ReleaseRef();
public SubTexture2D Entity_Hidden ~ _.ReleaseRef();
public SubTexture2D Save ~ _.ReleaseRef();
public static EditorIcons Instance => _editorIcons;
@@ -67,6 +68,7 @@ namespace GlitchyEditor
File_Shader = GetNextGridTexture(ref pen, iconSize);
Entity_Visible = GetNextGridTexture(ref pen, iconSize);
Entity_Hidden = GetNextGridTexture(ref pen, iconSize);
Save = GetNextGridTexture(ref pen, iconSize);
}
public ~this()
+2 -1
View File
@@ -362,7 +362,7 @@ namespace GlitchyEditor
private void InitEditor()
{
_editor = new Editor(_editorScene, _contentManager, _thumbnailManager);
_editor = new Editor(_editorScene, _editorScene, _contentManager, _thumbnailManager);
_editor.SceneViewportWindow.ViewportSizeChanged.Add(new (s, e) => EditorViewportSizeChanged(s, e));
_editor.GameViewportWindow.ViewportSizeChanged.Add(new (s, e) => GameViewportSizeChanged(s, e));
_editor.CurrentCamera = &_camera;
@@ -983,6 +983,7 @@ namespace GlitchyEditor
SetReference!(_editorScene, scene);
_editor.CurrentScene = _editorScene;
_editor.EditorScene = _editorScene;
SetReference!(_activeScene, _editorScene);
if (_editorScene != null)