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
Binary file not shown.
@@ -2,10 +2,39 @@
AssetLoader = null, AssetLoader = null,
Config = null, Config = null,
Importer = "TextureImporter", Importer = "TextureImporter",
ImporterConfig = null, ImporterConfig = (GlitchyEditor.Assets.Importers.TextureImporterConfig){
_isSrgb = false
},
Processor = null, Processor = null,
ProcessorConfig = null, ProcessorConfig = (GlitchyEditor.Assets.Processors.TextureProcessorConfig){
_generateMipMaps = .No,
_samplerStateDescription = {
MinFilter = .Linear,
MagFilter = .Linear,
MipFilter = .Linear,
FilterMode = .Default,
ComparisonFunction = .Never,
AddressModeU = .Clamp,
AddressModeV = .Clamp,
AddressModeW = .Clamp,
MipLODBias = 0,
MipMinLOD = -Infinity,
MipMaxLOD = Infinity,
MaxAnisotropy = 1,
BorderColor = {
R = 1,
G = 1,
B = 1,
A = 1
}
},
_textureType = .Texture,
_sprites = [
]
},
Exporter = null, Exporter = null,
ExporterConfig = null, ExporterConfig = {
_compression = .None
},
AssetHandle = 17408033053158961990 AssetHandle = 17408033053158961990
} }
Binary file not shown.
@@ -116,9 +116,17 @@ namespace GlitchyEditor.EditWindows
bool nodeOpen = ImGui.CollapsingHeader(header.CStr(), .DefaultOpen | .AllowOverlap | .Framed | .SpanFullWidth); 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) 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("...")) 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 (nodeOpen && ImGui.BeginPropertyTable("properties", TableId))
{ {
if (entity.TryGetComponent<TComponent>(let actualComponent)) if (entity.TryGetComponent<TComponent>(let actualComponent))
+16 -8
View File
@@ -11,7 +11,8 @@ namespace GlitchyEditor
{ {
class Editor class Editor
{ {
private Scene _scene; private Scene _activeScene;
private Scene _editorScene;
private EditorContentManager _contentManager; private EditorContentManager _contentManager;
private AssetThumbnailManager _thumbnailManager; private AssetThumbnailManager _thumbnailManager;
@@ -31,17 +32,23 @@ namespace GlitchyEditor
public Scene CurrentScene public Scene CurrentScene
{ {
get => _scene; get => _activeScene;
set set
{ {
if (_scene == value) if (_activeScene == value)
return; return;
_scene = value; _activeScene = value;
_entityHierarchyWindow.SetContext(_scene); _entityHierarchyWindow.SetContext(_activeScene);
} }
} }
public Scene EditorScene
{
get => _editorScene;
set => _editorScene = value;
}
public EditorContentManager ContentManager => _contentManager; public EditorContentManager ContentManager => _contentManager;
public AssetThumbnailManager ThumbnailManager => _thumbnailManager; public AssetThumbnailManager ThumbnailManager => _thumbnailManager;
@@ -73,12 +80,13 @@ namespace GlitchyEditor
public static Editor Instance => s_Instance; public static Editor Instance => s_Instance;
/// Creates a new editor for the given world /// 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."); Log.EngineLogger.AssertDebug(s_Instance == null, "Cannot create a second instance of a singleton.");
s_Instance = this; s_Instance = this;
_scene = scene; _activeScene = activeScene;
_editorScene = editorScene;
_contentManager = contentManager; _contentManager = contentManager;
_thumbnailManager = thumbnailManager; _thumbnailManager = thumbnailManager;
@@ -94,7 +102,7 @@ namespace GlitchyEditor
{ {
_sceneViewportWindow = new EditorViewportWindow(this); _sceneViewportWindow = new EditorViewportWindow(this);
_gameViewportWindow = new GameViewportWindow(this); _gameViewportWindow = new GameViewportWindow(this);
_entityHierarchyWindow = new EntityHierarchyWindow(this, _scene); _entityHierarchyWindow = new EntityHierarchyWindow(this, _activeScene);
_componentEditWindow = new ComponentEditWindow(); _componentEditWindow = new ComponentEditWindow();
_contentBrowserWindow = new ContentBrowserWindow(this, (.)Application.Instance.ContentManager, _thumbnailManager); _contentBrowserWindow = new ContentBrowserWindow(this, (.)Application.Instance.ContentManager, _thumbnailManager);
_inspectorWindow = new InspectorWindow(this); _inspectorWindow = new InspectorWindow(this);
+2
View File
@@ -31,6 +31,7 @@ namespace GlitchyEditor
public SubTexture2D File_Shader ~ _.ReleaseRef(); public SubTexture2D File_Shader ~ _.ReleaseRef();
public SubTexture2D Entity_Visible ~ _.ReleaseRef(); public SubTexture2D Entity_Visible ~ _.ReleaseRef();
public SubTexture2D Entity_Hidden ~ _.ReleaseRef(); public SubTexture2D Entity_Hidden ~ _.ReleaseRef();
public SubTexture2D Save ~ _.ReleaseRef();
public static EditorIcons Instance => _editorIcons; public static EditorIcons Instance => _editorIcons;
@@ -67,6 +68,7 @@ namespace GlitchyEditor
File_Shader = GetNextGridTexture(ref pen, iconSize); File_Shader = GetNextGridTexture(ref pen, iconSize);
Entity_Visible = GetNextGridTexture(ref pen, iconSize); Entity_Visible = GetNextGridTexture(ref pen, iconSize);
Entity_Hidden = GetNextGridTexture(ref pen, iconSize); Entity_Hidden = GetNextGridTexture(ref pen, iconSize);
Save = GetNextGridTexture(ref pen, iconSize);
} }
public ~this() public ~this()
+2 -1
View File
@@ -362,7 +362,7 @@ namespace GlitchyEditor
private void InitEditor() 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.SceneViewportWindow.ViewportSizeChanged.Add(new (s, e) => EditorViewportSizeChanged(s, e));
_editor.GameViewportWindow.ViewportSizeChanged.Add(new (s, e) => GameViewportSizeChanged(s, e)); _editor.GameViewportWindow.ViewportSizeChanged.Add(new (s, e) => GameViewportSizeChanged(s, e));
_editor.CurrentCamera = &_camera; _editor.CurrentCamera = &_camera;
@@ -983,6 +983,7 @@ namespace GlitchyEditor
SetReference!(_editorScene, scene); SetReference!(_editorScene, scene);
_editor.CurrentScene = _editorScene; _editor.CurrentScene = _editorScene;
_editor.EditorScene = _editorScene;
SetReference!(_activeScene, _editorScene); SetReference!(_activeScene, _editorScene);
if (_editorScene != null) if (_editorScene != null)
+2 -2
View File
@@ -216,7 +216,7 @@ namespace GlitchyEngine.World
} }
/// Copy POD components that don't need any extra care. /// Copy POD components that don't need any extra care.
private static void CopyComponent<TComponent>(Entity source, Entity target) where TComponent : struct, new public static void CopyComponent<TComponent>(Entity source, Entity target) where TComponent : struct, new
{ {
if (source.TryGetComponent<TComponent>(let sourceComponent)) if (source.TryGetComponent<TComponent>(let sourceComponent))
{ {
@@ -232,7 +232,7 @@ namespace GlitchyEngine.World
} }
/// Copy components that have custom copy methods. /// Copy components that have custom copy methods.
private static void CopyComponent<TComponent>(Entity source, Entity target) where TComponent : struct, new, ICopyComponent<TComponent> public static void CopyComponent<TComponent>(Entity source, Entity target) where TComponent : struct, new, ICopyComponent<TComponent>
{ {
if (source.TryGetComponent<TComponent>(let sourceComponent)) if (source.TryGetComponent<TComponent>(let sourceComponent))
{ {