diff --git a/GlitchyEditor/resources/Textures/EditorIcons.dds b/GlitchyEditor/resources/Textures/EditorIcons.dds index 5781d7a..c28f496 100644 Binary files a/GlitchyEditor/resources/Textures/EditorIcons.dds and b/GlitchyEditor/resources/Textures/EditorIcons.dds differ diff --git a/GlitchyEditor/resources/Textures/EditorIcons.dds.ass b/GlitchyEditor/resources/Textures/EditorIcons.dds.ass index 2e9b553..af9876b 100644 --- a/GlitchyEditor/resources/Textures/EditorIcons.dds.ass +++ b/GlitchyEditor/resources/Textures/EditorIcons.dds.ass @@ -2,10 +2,39 @@ AssetLoader = null, Config = null, Importer = "TextureImporter", - ImporterConfig = null, + ImporterConfig = (GlitchyEditor.Assets.Importers.TextureImporterConfig){ + _isSrgb = false + }, 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, - ExporterConfig = null, + ExporterConfig = { + _compression = .None + }, AssetHandle = 17408033053158961990 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Textures/EditorIcons.psd b/GlitchyEditor/resources/Textures/EditorIcons.psd index ce42cce..5ff9b69 100644 Binary files a/GlitchyEditor/resources/Textures/EditorIcons.psd and b/GlitchyEditor/resources/Textures/EditorIcons.psd differ diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index 2dcd423..00b2972 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -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(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(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(let actualComponent)) diff --git a/GlitchyEditor/src/Editor.bf b/GlitchyEditor/src/Editor.bf index 8dab152..77b250a 100644 --- a/GlitchyEditor/src/Editor.bf +++ b/GlitchyEditor/src/Editor.bf @@ -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); diff --git a/GlitchyEditor/src/EditorIcons.bf b/GlitchyEditor/src/EditorIcons.bf index 4a4f6a1..b073eb9 100644 --- a/GlitchyEditor/src/EditorIcons.bf +++ b/GlitchyEditor/src/EditorIcons.bf @@ -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() diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index b16bb2d..f3a0ee2 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -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) diff --git a/GlitchyEngine/src/World/Scene.bf b/GlitchyEngine/src/World/Scene.bf index bd2a0ab..c9e6550 100644 --- a/GlitchyEngine/src/World/Scene.bf +++ b/GlitchyEngine/src/World/Scene.bf @@ -216,7 +216,7 @@ namespace GlitchyEngine.World } /// Copy POD components that don't need any extra care. - private static void CopyComponent(Entity source, Entity target) where TComponent : struct, new + public static void CopyComponent(Entity source, Entity target) where TComponent : struct, new { if (source.TryGetComponent(let sourceComponent)) { @@ -232,7 +232,7 @@ namespace GlitchyEngine.World } /// Copy components that have custom copy methods. - private static void CopyComponent(Entity source, Entity target) where TComponent : struct, new, ICopyComponent + public static void CopyComponent(Entity source, Entity target) where TComponent : struct, new, ICopyComponent { if (source.TryGetComponent(let sourceComponent)) {